ItemInventories don't have own ID's anymore but rely on owner ID, relaying reliablemessages through server
This commit is contained in:
@@ -95,8 +95,8 @@ namespace Barotrauma
|
|||||||
message.Write(LargeUpdateTimer <= 0);
|
message.Write(LargeUpdateTimer <= 0);
|
||||||
|
|
||||||
message.Write(AnimController.TargetDir == Direction.Right);
|
message.Write(AnimController.TargetDir == Direction.Right);
|
||||||
message.Write(AnimController.TargetMovement.X);
|
message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.X, -10.0f, 10.0f), -10.0f, 10.0f, 16);
|
||||||
message.Write(AnimController.TargetMovement.Y);
|
message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.Y, -10.0f, 10.0f), -10.0f, 10.0f, 16);
|
||||||
|
|
||||||
if (LargeUpdateTimer <= 0)
|
if (LargeUpdateTimer <= 0)
|
||||||
{
|
{
|
||||||
@@ -165,8 +165,8 @@ namespace Barotrauma
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
targetDir = message.ReadBoolean();
|
targetDir = message.ReadBoolean();
|
||||||
targetMovement.X = message.ReadFloat();
|
targetMovement.X = message.ReadRangedSingle(-10.0f, 10.0f, 8);
|
||||||
targetMovement.Y = message.ReadFloat();
|
targetMovement.Y = message.ReadRangedSingle(-10.0f, 10.0f, 8);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|||||||
@@ -1100,6 +1100,11 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (type == NetworkEventType.InventoryUpdate)
|
||||||
|
{
|
||||||
|
if (inventory == null) return false;
|
||||||
|
return inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data);
|
||||||
|
}
|
||||||
|
|
||||||
var hasInputs =
|
var hasInputs =
|
||||||
(GetInputState(InputType.Left) ||
|
(GetInputState(InputType.Left) ||
|
||||||
@@ -1229,6 +1234,12 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if (type == NetworkEventType.InventoryUpdate)
|
||||||
|
{
|
||||||
|
if (inventory == null) return;
|
||||||
|
inventory.ReadNetworkData(NetworkEventType.InventoryUpdate, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool actionKeyState = false;
|
bool actionKeyState = false;
|
||||||
bool secondaryKeyState = false;
|
bool secondaryKeyState = false;
|
||||||
@@ -1393,8 +1404,6 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (GameMain.Client!=null && GameMain.Client.Character == this) GameMain.Client.Character = null;
|
if (GameMain.Client!=null && GameMain.Client.Character == this) GameMain.Client.Character = null;
|
||||||
|
|
||||||
if (inventory != null) inventory.Remove();
|
|
||||||
|
|
||||||
if (aiTarget != null)
|
if (aiTarget != null)
|
||||||
aiTarget.Remove();
|
aiTarget.Remove();
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace Barotrauma
|
|||||||
private Vector2[] slotPositions;
|
private Vector2[] slotPositions;
|
||||||
|
|
||||||
public CharacterInventory(int capacity, Character character)
|
public CharacterInventory(int capacity, Character character)
|
||||||
: base(capacity)
|
: base(character, capacity)
|
||||||
{
|
{
|
||||||
this.character = character;
|
this.character = character;
|
||||||
|
|
||||||
@@ -33,7 +33,6 @@ namespace Barotrauma
|
|||||||
|
|
||||||
slotPositions = new Vector2[limbSlots.Length];
|
slotPositions = new Vector2[limbSlots.Length];
|
||||||
|
|
||||||
|
|
||||||
int rectWidth = 40, rectHeight = 40;
|
int rectWidth = 40, rectHeight = 40;
|
||||||
int spacing = 10;
|
int spacing = 10;
|
||||||
for (int i = 0; i < slotPositions.Length; i++)
|
for (int i = 0; i < slotPositions.Length; i++)
|
||||||
@@ -123,16 +122,19 @@ namespace Barotrauma
|
|||||||
if (allowedSlots.HasFlag(limbSlots[i]) && items[i]!=null) return false;
|
if (allowedSlots.HasFlag(limbSlots[i]) && items[i]!=null) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool placed = false;
|
||||||
for (int i = 0; i < capacity; i++)
|
for (int i = 0; i < capacity; i++)
|
||||||
{
|
{
|
||||||
if (allowedSlots.HasFlag(limbSlots[i]) && items[i] == null)
|
if (allowedSlots.HasFlag(limbSlots[i]) && items[i] == null)
|
||||||
{
|
{
|
||||||
PutItem(item, i, createNetworkEvent);
|
PutItem(item, i, createNetworkEvent, !placed);
|
||||||
item.Equip(character);
|
item.Equip(character);
|
||||||
return true;
|
placed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (placed) return true;
|
||||||
|
|
||||||
if (allowedSlots.HasFlag(LimbSlot.BothHands)) TryPutItem(item, 3, createNetworkEvent);
|
if (allowedSlots.HasFlag(LimbSlot.BothHands)) TryPutItem(item, 3, createNetworkEvent);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -158,7 +160,7 @@ namespace Barotrauma
|
|||||||
Inventory otherInventory = items[i].inventory;
|
Inventory otherInventory = items[i].inventory;
|
||||||
if (otherInventory!=null)
|
if (otherInventory!=null)
|
||||||
{
|
{
|
||||||
new Networking.NetworkEvent(Networking.NetworkEventType.InventoryUpdate, otherInventory.ID, true);
|
new Networking.NetworkEvent(Networking.NetworkEventType.InventoryUpdate, otherInventory.Owner.ID, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
combined = true;
|
combined = true;
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ namespace Barotrauma.Items.Components
|
|||||||
public ItemContainer(Item item, XElement element)
|
public ItemContainer(Item item, XElement element)
|
||||||
: base (item, element)
|
: base (item, element)
|
||||||
{
|
{
|
||||||
inventory = new ItemInventory(this, capacity, hudPos, slotsPerRow);
|
inventory = new ItemInventory(item, this, capacity, hudPos, slotsPerRow);
|
||||||
containableItems = new List<RelatedItem>();
|
containableItems = new List<RelatedItem>();
|
||||||
|
|
||||||
foreach (XElement subElement in element.Elements())
|
foreach (XElement subElement in element.Elements())
|
||||||
|
|||||||
@@ -8,11 +8,13 @@ using System;
|
|||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
class Inventory : Entity
|
class Inventory
|
||||||
{
|
{
|
||||||
public static Item draggingItem;
|
public static Item draggingItem;
|
||||||
public static Item doubleClickedItem;
|
public static Item doubleClickedItem;
|
||||||
|
|
||||||
|
public readonly Entity Owner;
|
||||||
|
|
||||||
private int slotsPerRow;
|
private int slotsPerRow;
|
||||||
|
|
||||||
public int SlotsPerRow
|
public int SlotsPerRow
|
||||||
@@ -39,10 +41,12 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public Item[] items;
|
public Item[] items;
|
||||||
|
|
||||||
public Inventory(int capacity, Vector2? centerPos = null, int slotsPerRow=5)
|
public Inventory(Entity owner, int capacity, Vector2? centerPos = null, int slotsPerRow=5)
|
||||||
{
|
{
|
||||||
this.capacity = capacity;
|
this.capacity = capacity;
|
||||||
|
|
||||||
|
this.Owner = owner;
|
||||||
|
|
||||||
this.slotsPerRow = slotsPerRow;
|
this.slotsPerRow = slotsPerRow;
|
||||||
|
|
||||||
items = new Item[capacity];
|
items = new Item[capacity];
|
||||||
@@ -95,6 +99,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public virtual bool TryPutItem(Item item, int i, bool createNetworkEvent = true)
|
public virtual bool TryPutItem(Item item, int i, bool createNetworkEvent = true)
|
||||||
{
|
{
|
||||||
|
if (Owner == null) return false;
|
||||||
if (CanBePut(item,i))
|
if (CanBePut(item,i))
|
||||||
{
|
{
|
||||||
PutItem(item, i, createNetworkEvent);
|
PutItem(item, i, createNetworkEvent);
|
||||||
@@ -108,6 +113,8 @@ namespace Barotrauma
|
|||||||
|
|
||||||
protected void PutItem(Item item, int i, bool createNetworkEvent, bool removeItem = true)
|
protected void PutItem(Item item, int i, bool createNetworkEvent, bool removeItem = true)
|
||||||
{
|
{
|
||||||
|
if (Owner == null) return;
|
||||||
|
|
||||||
if (item.inventory != null && removeItem)
|
if (item.inventory != null && removeItem)
|
||||||
{
|
{
|
||||||
item.Drop();
|
item.Drop();
|
||||||
@@ -121,7 +128,7 @@ namespace Barotrauma
|
|||||||
item.body.Enabled = false;
|
item.body.Enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (createNetworkEvent) new NetworkEvent(NetworkEventType.InventoryUpdate, ID, true);
|
if (createNetworkEvent) new NetworkEvent(NetworkEventType.InventoryUpdate, Owner.ID, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveItem(Item item)
|
public void RemoveItem(Item item)
|
||||||
@@ -136,7 +143,6 @@ namespace Barotrauma
|
|||||||
|
|
||||||
protected virtual void DropItem(Item item)
|
protected virtual void DropItem(Item item)
|
||||||
{
|
{
|
||||||
|
|
||||||
item.Drop(null, false);
|
item.Drop(null, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -185,8 +191,11 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int[] data = { draggingItem.ID, -1 };
|
if (Owner!=null)
|
||||||
new NetworkEvent(NetworkEventType.InventoryUpdate, ID, true, data);
|
{
|
||||||
|
int[] data = { draggingItem.ID, -1 };
|
||||||
|
new NetworkEvent(NetworkEventType.InventoryUpdate, Owner.ID, true, data);
|
||||||
|
}
|
||||||
|
|
||||||
DropItem(draggingItem);
|
DropItem(draggingItem);
|
||||||
}
|
}
|
||||||
@@ -279,7 +288,7 @@ namespace Barotrauma
|
|||||||
spriteBatch.DrawString(GUI.Font, (int)item.Condition + " %", new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), Color.Red);
|
spriteBatch.DrawString(GUI.Font, (int)item.Condition + " %", new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), Color.Red);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool FillNetworkData(NetworkEventType type, NetOutgoingMessage message, object data)
|
public bool FillNetworkData(NetworkEventType type, NetOutgoingMessage message, object data)
|
||||||
{
|
{
|
||||||
for (int i = 0; i<capacity; i++)
|
for (int i = 0; i<capacity; i++)
|
||||||
{
|
{
|
||||||
@@ -289,7 +298,7 @@ namespace Barotrauma
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message)
|
public void ReadNetworkData(NetworkEventType type, NetIncomingMessage message)
|
||||||
{
|
{
|
||||||
int[] newItemIDs = new int[capacity];
|
int[] newItemIDs = new int[capacity];
|
||||||
|
|
||||||
@@ -315,7 +324,7 @@ namespace Barotrauma
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Item item = FindEntityByID(newItemIDs[i]) as Item;
|
Item item = Entity.FindEntityByID(newItemIDs[i]) as Item;
|
||||||
if (item == null) continue;
|
if (item == null) continue;
|
||||||
|
|
||||||
TryPutItem(item, i, false);
|
TryPutItem(item, i, false);
|
||||||
|
|||||||
@@ -1169,6 +1169,10 @@ namespace Barotrauma
|
|||||||
message.Write(body.SimPosition.Y);
|
message.Write(body.SimPosition.Y);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case NetworkEventType.InventoryUpdate:
|
||||||
|
var itemContainer = GetComponent<ItemContainer>();
|
||||||
|
if (itemContainer == null || itemContainer.inventory == null) return false;
|
||||||
|
return itemContainer.inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data);
|
||||||
case NetworkEventType.UpdateComponent:
|
case NetworkEventType.UpdateComponent:
|
||||||
|
|
||||||
int componentIndex = (int)data;
|
int componentIndex = (int)data;
|
||||||
@@ -1233,6 +1237,11 @@ namespace Barotrauma
|
|||||||
SetTransform(newSimPos, body.Rotation);
|
SetTransform(newSimPos, body.Rotation);
|
||||||
Drop(null, false);
|
Drop(null, false);
|
||||||
break;
|
break;
|
||||||
|
case NetworkEventType.InventoryUpdate:
|
||||||
|
var itemContainer = GetComponent<ItemContainer>();
|
||||||
|
if (itemContainer == null || itemContainer.inventory == null) return;
|
||||||
|
itemContainer.inventory.ReadNetworkData(NetworkEventType.DropItem, message);
|
||||||
|
break;
|
||||||
case NetworkEventType.UpdateComponent:
|
case NetworkEventType.UpdateComponent:
|
||||||
int componentIndex = message.ReadByte();
|
int componentIndex = message.ReadByte();
|
||||||
if (componentIndex < 0 || componentIndex > components.Count - 1) return;
|
if (componentIndex < 0 || componentIndex > components.Count - 1) return;
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
ItemContainer container;
|
ItemContainer container;
|
||||||
|
|
||||||
public ItemInventory(ItemContainer container, int capacity, Vector2? centerPos = null, int slotsPerRow = 5)
|
public ItemInventory(Item owner, ItemContainer container, int capacity, Vector2? centerPos = null, int slotsPerRow = 5)
|
||||||
: base(capacity, centerPos, slotsPerRow)
|
: base(owner, capacity, centerPos, slotsPerRow)
|
||||||
{
|
{
|
||||||
this.container = container;
|
this.container = container;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -649,7 +649,6 @@ namespace Barotrauma.Networking
|
|||||||
string newName = inc.ReadString();
|
string newName = inc.ReadString();
|
||||||
int ID = inc.ReadInt32();
|
int ID = inc.ReadInt32();
|
||||||
bool isFemale = inc.ReadBoolean();
|
bool isFemale = inc.ReadBoolean();
|
||||||
int inventoryID = inc.ReadInt32();
|
|
||||||
|
|
||||||
int headSpriteID = inc.ReadInt32();
|
int headSpriteID = inc.ReadInt32();
|
||||||
|
|
||||||
@@ -683,7 +682,6 @@ namespace Barotrauma.Networking
|
|||||||
new Character(ch, closestWaypoint, !isMyCharacter);
|
new Character(ch, closestWaypoint, !isMyCharacter);
|
||||||
|
|
||||||
character.ID = ID;
|
character.ID = ID;
|
||||||
character.Inventory.ID = inventoryID;
|
|
||||||
|
|
||||||
character.GiveJobItems(closestWaypoint);
|
character.GiveJobItems(closestWaypoint);
|
||||||
|
|
||||||
|
|||||||
@@ -282,10 +282,10 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
ReadMessage(inc);
|
ReadMessage(inc);
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
DebugConsole.ThrowError("Failed to read incoming message");
|
DebugConsole.ThrowError("Failed to read incoming message", e);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@@ -440,10 +440,13 @@ namespace Barotrauma.Networking
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isReliable = false;
|
||||||
if (packetType == (byte)PacketTypes.ReliableMessage)
|
if (packetType == (byte)PacketTypes.ReliableMessage)
|
||||||
{
|
{
|
||||||
if (!dataSender.ReliableChannel.CheckMessage(inc)) return;
|
if (!dataSender.ReliableChannel.CheckMessage(inc)) return;
|
||||||
packetType = inc.ReadByte();
|
packetType = inc.ReadByte();
|
||||||
|
|
||||||
|
isReliable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (packetType)
|
switch (packetType)
|
||||||
@@ -452,21 +455,40 @@ namespace Barotrauma.Networking
|
|||||||
if (!gameStarted) break;
|
if (!gameStarted) break;
|
||||||
if (!NetworkEvent.ReadData(inc)) break;
|
if (!NetworkEvent.ReadData(inc)) break;
|
||||||
|
|
||||||
outmsg = server.CreateMessage();
|
List<Client> recipients = connectedClients.FindAll(c => c.Connection != inc.SenderConnection && c.inGame);
|
||||||
outmsg.Write(inc);
|
|
||||||
|
|
||||||
List<NetConnection> recipients = new List<NetConnection>();
|
|
||||||
|
|
||||||
foreach (Client client in connectedClients)
|
|
||||||
{
|
|
||||||
if (client.Connection == inc.SenderConnection) continue;
|
|
||||||
if (!client.inGame) continue;
|
|
||||||
|
|
||||||
recipients.Add(client.Connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (recipients.Count == 0) break;
|
if (recipients.Count == 0) break;
|
||||||
server.SendMessage(outmsg, recipients, inc.DeliveryMethod, 0);
|
|
||||||
|
//foreach (Client client in connectedClients)
|
||||||
|
//{
|
||||||
|
// if (client.Connection == inc.SenderConnection) continue;
|
||||||
|
// if (!client.inGame) continue;
|
||||||
|
|
||||||
|
// recipients.Add(client.Connection);
|
||||||
|
//}
|
||||||
|
|
||||||
|
if (isReliable)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("receiver reliable networkevent");
|
||||||
|
foreach (Client c in recipients)
|
||||||
|
{
|
||||||
|
var reliableMessage = c.ReliableChannel.CreateMessage();
|
||||||
|
inc.Position = 8+16;
|
||||||
|
byte[] messageBytes = inc.ReadBytes(inc.LengthBytes-3);
|
||||||
|
reliableMessage.InnerMessage.Write(messageBytes);
|
||||||
|
|
||||||
|
c.ReliableChannel.SendMessage(reliableMessage, c.Connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
outmsg = server.CreateMessage();
|
||||||
|
outmsg.Write(inc);
|
||||||
|
|
||||||
|
List<NetConnection> recipientConnections = new List<NetConnection>();
|
||||||
|
foreach (Client c in recipients) recipientConnections.Add(c.Connection);
|
||||||
|
|
||||||
|
server.SendMessage(outmsg, recipientConnections, inc.DeliveryMethod, 0);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case (byte)PacketTypes.Chatmessage:
|
case (byte)PacketTypes.Chatmessage:
|
||||||
@@ -628,36 +650,35 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
if (recipients.Count == 0) return;
|
if (recipients.Count == 0) return;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach (NetworkEvent networkEvent in NetworkEvent.events)
|
foreach (NetworkEvent networkEvent in NetworkEvent.events)
|
||||||
{
|
{
|
||||||
Entity e = Entity.FindEntityByID(networkEvent.ID);
|
NetOutgoingMessage message = server.CreateMessage();
|
||||||
if (e == null) continue;
|
message.Write((byte)PacketTypes.NetworkEvent);
|
||||||
|
//if (!networkEvent.IsClient) continue;
|
||||||
|
|
||||||
|
if (!networkEvent.FillData(message))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Entity e = Entity.FindEntityByID(networkEvent.ID);
|
||||||
|
//if (e == null) continue;
|
||||||
if (networkEvent.IsImportant)
|
if (networkEvent.IsImportant)
|
||||||
{
|
{
|
||||||
foreach (Client c in recipients)
|
foreach (Client c in recipients)
|
||||||
{
|
{
|
||||||
ReliableMessage reliableMessage = c.ReliableChannel.CreateMessage();
|
ReliableMessage reliableMessage = c.ReliableChannel.CreateMessage();
|
||||||
reliableMessage.InnerMessage.Write((byte)PacketTypes.NetworkEvent);
|
message.Position = 0;
|
||||||
|
reliableMessage.InnerMessage.Write(message.ReadBytes(message.LengthBytes));
|
||||||
if (!networkEvent.FillData(reliableMessage.InnerMessage))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
c.ReliableChannel.SendMessage(reliableMessage, c.Connection);
|
c.ReliableChannel.SendMessage(reliableMessage, c.Connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NetOutgoingMessage message = server.CreateMessage();
|
|
||||||
message.Write((byte)PacketTypes.NetworkEvent);
|
|
||||||
//if (!networkEvent.IsClient) continue;
|
|
||||||
|
|
||||||
if (!networkEvent.FillData(message))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (server.ConnectionsCount>0)
|
if (server.ConnectionsCount>0)
|
||||||
{
|
{
|
||||||
@@ -1050,7 +1071,6 @@ namespace Barotrauma.Networking
|
|||||||
message.Write(name);
|
message.Write(name);
|
||||||
message.Write(character.ID);
|
message.Write(character.ID);
|
||||||
message.Write(character.Info.Gender == Gender.Female);
|
message.Write(character.Info.Gender == Gender.Female);
|
||||||
message.Write(character.Inventory.ID);
|
|
||||||
|
|
||||||
message.Write(character.Info.HeadSpriteId);
|
message.Write(character.Info.HeadSpriteId);
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ namespace Barotrauma.Networking
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.Diagnostics.Debug.WriteLine("Networkevent entity: "+e.ToString());
|
//System.Diagnostics.Debug.WriteLine("Networkevent entity: "+e.ToString());
|
||||||
|
|
||||||
//System.Diagnostics.Debug.WriteLine("new message: " + eventType +" - "+e);
|
//System.Diagnostics.Debug.WriteLine("new message: " + eventType +" - "+e);
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -79,16 +79,14 @@ namespace Barotrauma.Networking.ReliableMessages
|
|||||||
|
|
||||||
public ReliableMessage CreateMessage()
|
public ReliableMessage CreateMessage()
|
||||||
{
|
{
|
||||||
if (messageCount == ushort.MaxValue) messageCount = 0;
|
ushort messageID = (messageCount==ushort.MaxValue) ? (ushort)0 : (ushort)(messageCount + 1);
|
||||||
messageCount++;
|
|
||||||
|
|
||||||
NetOutgoingMessage message = sender.CreateMessage();
|
NetOutgoingMessage message = sender.CreateMessage();
|
||||||
|
|
||||||
var reliableMessage = new ReliableMessage(message, messageCount);
|
var reliableMessage = new ReliableMessage(message, messageID);
|
||||||
messageBuffer.Add(reliableMessage.ID, reliableMessage);
|
|
||||||
|
|
||||||
message.Write((byte)PacketTypes.ReliableMessage);
|
message.Write((byte)PacketTypes.ReliableMessage);
|
||||||
message.Write(messageCount);
|
message.Write(messageID);
|
||||||
|
|
||||||
int bufferSize=100;
|
int bufferSize=100;
|
||||||
if (messageBuffer.Count>bufferSize)
|
if (messageBuffer.Count>bufferSize)
|
||||||
@@ -118,9 +116,6 @@ namespace Barotrauma.Networking.ReliableMessages
|
|||||||
if (i == ushort.MaxValue) break;
|
if (i == ushort.MaxValue) break;
|
||||||
Debug.WriteLine("removing message " + i);
|
Debug.WriteLine("removing message " + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return reliableMessage;
|
return reliableMessage;
|
||||||
@@ -133,6 +128,11 @@ namespace Barotrauma.Networking.ReliableMessages
|
|||||||
ackInterval = 0.0f;
|
ackInterval = 0.0f;
|
||||||
ackTimer = connection.AverageRoundtripTime;
|
ackTimer = connection.AverageRoundtripTime;
|
||||||
|
|
||||||
|
messageBuffer.Add(message.ID, message);
|
||||||
|
|
||||||
|
if (messageCount == ushort.MaxValue) messageCount = 0;
|
||||||
|
messageCount++;
|
||||||
|
|
||||||
message.SaveInnerMessage();
|
message.SaveInnerMessage();
|
||||||
|
|
||||||
sender.SendMessage(message.InnerMessage, connection, NetDeliveryMethod.Unreliable, 0);
|
sender.SendMessage(message.InnerMessage, connection, NetDeliveryMethod.Unreliable, 0);
|
||||||
@@ -172,7 +172,7 @@ namespace Barotrauma.Networking.ReliableMessages
|
|||||||
|
|
||||||
if (ackTimer > 0.0f) return;
|
if (ackTimer > 0.0f) return;
|
||||||
|
|
||||||
Debug.WriteLine("Sending ack message: "+messageCount);
|
//Debug.WriteLine("Sending ack message: "+messageCount);
|
||||||
|
|
||||||
NetOutgoingMessage message = sender.CreateMessage();
|
NetOutgoingMessage message = sender.CreateMessage();
|
||||||
message.Write((byte)PacketTypes.Ack);
|
message.Write((byte)PacketTypes.Ack);
|
||||||
@@ -337,7 +337,7 @@ namespace Barotrauma.Networking.ReliableMessages
|
|||||||
//id matches, all good
|
//id matches, all good
|
||||||
if (messageId == lastMessageID)
|
if (messageId == lastMessageID)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Received ack message: " + messageId + ", all good");
|
//Debug.WriteLine("Received ack message: " + messageId + ", all good");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user