From dfd24045f8f3034a371238bdb44c2febd795dc67 Mon Sep 17 00:00:00 2001 From: Regalis Date: Fri, 24 Mar 2017 19:12:09 +0200 Subject: [PATCH] EntityEventManagers send an empty event if the entity doesn't exist anymore when writing the message (may happen, for example, when a client is still waiting for some message about the item when it's destroyed in a deconstructor). Not sending the events at all would be a better solution, but then we'd need to shift the IDs of all the consecutive events and make sure it doesn't mess anything up with any of the clients. Not necessarily worth the effort, considering how rare these "empty events" are. --- .../ClientEntityEventManager.cs | 8 ++++++++ .../NetEntityEvent/NetEntityEventManager.cs | 19 ++++++++++--------- .../ServerEntityEventManager.cs | 8 ++++++++ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Subsurface/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs b/Subsurface/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs index 8d78081b3..367d05aa7 100644 --- a/Subsurface/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs +++ b/Subsurface/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs @@ -119,6 +119,14 @@ namespace Barotrauma.Networking { UInt16 thisEventID = (UInt16)(firstEventID + (UInt16)i); UInt16 entityID = msg.ReadUInt16(); + + if (entityID == 0) + { + msg.ReadPadBits(); + lastReceivedID++; + continue; + } + byte msgLength = msg.ReadByte(); IServerSerializable entity = Entity.FindEntityByID(entityID) as IServerSerializable; diff --git a/Subsurface/Source/Networking/NetEntityEvent/NetEntityEventManager.cs b/Subsurface/Source/Networking/NetEntityEvent/NetEntityEventManager.cs index b304b8cc1..b2a7187b6 100644 --- a/Subsurface/Source/Networking/NetEntityEvent/NetEntityEventManager.cs +++ b/Subsurface/Source/Networking/NetEntityEvent/NetEntityEventManager.cs @@ -45,18 +45,19 @@ namespace Barotrauma.Networking tempBuffer.LengthBytes < 128, "Maximum EntityEvent size exceeded when serializing \""+e.Entity+"\"!"); -#if DEBUG if (Entity.FindEntityByID(e.Entity.ID) != e.Entity) { - DebugConsole.ThrowError("Error in NetEntityEventManager.Write (FindEntityByID(e.Entity.ID) != e.Entity)"); + //DebugConsole.ThrowError("Error in NetEntityEventManager.Write (FindEntityByID(e.Entity.ID) != e.Entity)"); + msg.Write((UInt16)0); + msg.WritePadBits(); + } + else + { + msg.Write((UInt16)e.Entity.ID); + msg.Write((byte)tempBuffer.LengthBytes); + msg.Write(tempBuffer); + msg.WritePadBits(); } -#endif - - - msg.Write((UInt16)e.Entity.ID); - msg.Write((byte)tempBuffer.LengthBytes); - msg.Write(tempBuffer); - msg.WritePadBits(); } } diff --git a/Subsurface/Source/Networking/NetEntityEvent/ServerEntityEventManager.cs b/Subsurface/Source/Networking/NetEntityEvent/ServerEntityEventManager.cs index f07a0a1b3..e923b7b4b 100644 --- a/Subsurface/Source/Networking/NetEntityEvent/ServerEntityEventManager.cs +++ b/Subsurface/Source/Networking/NetEntityEvent/ServerEntityEventManager.cs @@ -291,6 +291,14 @@ namespace Barotrauma.Networking { UInt16 thisEventID = (UInt16)(firstEventID + (UInt16)i); UInt16 entityID = msg.ReadUInt16(); + + if (entityID == 0) + { + msg.ReadPadBits(); + sender.lastSentEntityEventID++; + continue; + } + byte msgLength = msg.ReadByte(); IClientSerializable entity = Entity.FindEntityByID(entityID) as IClientSerializable;