From 12aebf3cc9324ebbf273a61e11e9ebf8be8498e0 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 25 Dec 2018 21:24:45 +0200 Subject: [PATCH] Allow the server to skip over EntityEvents sent by clients if the entity does not exist. The clients may create events for removed entities if they for example use an item repeatedly and cause events to be created before the client is notified of the item being removed. Closes #973 --- .../ServerEntityEventManager.cs | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Networking/NetEntityEvent/ServerEntityEventManager.cs b/Barotrauma/BarotraumaShared/Source/Networking/NetEntityEvent/ServerEntityEventManager.cs index 543da0c9c..2fbc5ed0f 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/NetEntityEvent/ServerEntityEventManager.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/NetEntityEvent/ServerEntityEventManager.cs @@ -349,24 +349,29 @@ namespace Barotrauma.Networking IClientSerializable entity = Entity.FindEntityByID(entityID) as IClientSerializable; - //skip the event if we've already received it or if the entity isn't found - if (thisEventID != (UInt16)(sender.LastSentEntityEventID + 1) || entity == null) + //skip the event if we've already received it + if (thisEventID != (UInt16)(sender.LastSentEntityEventID + 1)) { if (GameSettings.VerboseLogging) { - if (thisEventID != (UInt16) (sender.LastSentEntityEventID + 1)) - { - DebugConsole.NewMessage("received msg " + thisEventID, Microsoft.Xna.Framework.Color.Red); - } - else if (entity == null) - { - DebugConsole.NewMessage( - "received msg " + thisEventID + ", entity " + entityID + " not found", - Microsoft.Xna.Framework.Color.Red); - } + DebugConsole.NewMessage("received msg " + thisEventID, Microsoft.Xna.Framework.Color.Red); } msg.Position += msgLength * 8; } + else if (entity == null) + { + //entity not found -> consider the even read and skip over it + //(can happen, for example, when a client uses a medical item repeatedly + //and creates an event for it before receiving the event about it being removed) + if (GameSettings.VerboseLogging) + { + DebugConsole.NewMessage( + "received msg " + thisEventID + ", entity " + entityID + " not found", + Microsoft.Xna.Framework.Color.Orange); + } + sender.LastSentEntityEventID++; + msg.Position += msgLength * 8; + } else { if (GameSettings.VerboseLogging)