From 9330bd08defbd6846fb88f5831941ea00250527c Mon Sep 17 00:00:00 2001 From: Regalis Date: Thu, 6 Apr 2017 21:52:24 +0300 Subject: [PATCH] Clients don't switch from init events to normal until they receive the first normal event update (instead of switching when they receive the last init event they know about). Otherwise the client may switch to normal events too early, if the server has created new unique events the client doesn't know about yet. --- .../ClientEntityEventManager.cs | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Subsurface/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs b/Subsurface/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs index c4a9d7a2b..de0dd1538 100644 --- a/Subsurface/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs +++ b/Subsurface/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs @@ -97,19 +97,30 @@ namespace Barotrauma.Networking msg.Write((byte)ClientNetObject.ENTITY_STATE); Write(msg, eventsToSync); } - + + private UInt16? firstNewID; + /// /// Read the events from the message, ignoring ones we've already received /// public void Read(ServerNetObject type, NetIncomingMessage msg, float sendingTime) { UInt16 unreceivedEntityEventCount = 0; - UInt16 firstNewID = 0; if (type == ServerNetObject.ENTITY_EVENT_INITIAL) { unreceivedEntityEventCount = msg.ReadUInt16(); firstNewID = msg.ReadUInt16(); + + DebugConsole.NewMessage("received midround syncing msg, unreceived: "+unreceivedEntityEventCount+", first new ID: "+firstNewID, Microsoft.Xna.Framework.Color.Yellow); + + } + else if (firstNewID != null) + { + DebugConsole.NewMessage("midround syncing complete, switching to ID "+ (UInt16)(firstNewID - 1), Microsoft.Xna.Framework.Color.Yellow); + + lastReceivedID = (UInt16)(firstNewID - 1); + firstNewID = null; } UInt16 firstEventID = msg.ReadUInt16(); @@ -165,15 +176,6 @@ namespace Barotrauma.Networking } msg.ReadPadBits(); } - - if (type == ServerNetObject.ENTITY_EVENT_INITIAL) - { - if (lastReceivedID == unreceivedEntityEventCount - 1 || - unreceivedEntityEventCount == 0) - { - lastReceivedID = (UInt16)(firstNewID - 1); - } - } } protected override void WriteEvent(NetBuffer buffer, NetEntityEvent entityEvent, Client recipient = null) @@ -195,6 +197,8 @@ namespace Barotrauma.Networking lastReceivedID = 0; + firstNewID = null; + events.Clear(); eventLastSent.Clear(); }