From ab4e8cee8306d76c5c2eee258d16291f73db8e12 Mon Sep 17 00:00:00 2001 From: Regalis Date: Tue, 2 May 2017 22:43:48 +0300 Subject: [PATCH] The server ignores lastRecvIDs in SYNC_IDS messages if the IDs aren't valid (earlier than the client's previous ID, or more recent than the newest ID). Should be safer than clamping to the valid range - an incorrectly read packet or a message sent just before switching from midround syncing to normal won't cause the IDs to jump to the newest ID and prevent clients from receiving further msgs/events. --- Subsurface/Source/Networking/GameServer.cs | 37 +++++++++++++++------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 8ab844e9e..a4622a6b5 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -693,6 +693,7 @@ namespace Barotrauma.Networking { c.NeedsMidRoundSync = false; lastRecvEntityEventID = (UInt16)(c.FirstNewEventID - 1); + c.lastRecvEntityEventID = lastRecvEntityEventID; } else { @@ -700,21 +701,33 @@ namespace Barotrauma.Networking } } + if (NetIdUtils.IdMoreRecent(lastRecvChatMsgID, c.lastRecvChatMsgID) && //more recent than the last ID received by the client + !NetIdUtils.IdMoreRecent(lastRecvChatMsgID, c.lastChatMsgQueueID)) //NOT more recent than the latest existing ID + { + c.lastRecvChatMsgID = lastRecvChatMsgID; + } #if DEBUG - //client thinks they've received a msg we haven't sent yet (corrupted packet, msg read/written incorrectly?) - if (NetIdUtils.IdMoreRecent(lastRecvChatMsgID, c.lastChatMsgQueueID)) - DebugConsole.ThrowError("client.lastRecvChatMsgID > lastChatMsgQueueID (" + lastRecvChatMsgID + " > " + c.lastChatMsgQueueID + ")"); - - if (lastRecvEntityEventID > lastEntityEventID) - DebugConsole.ThrowError("client.lastRecvEntityEventID > lastEntityEventID (" + lastRecvEntityEventID + " > " + lastEntityEventID + ")"); + else if (lastRecvChatMsgID != c.lastRecvChatMsgID) + { + DebugConsole.ThrowError( + "Invalid lastRecvChatMsgID " + lastRecvChatMsgID + + " (previous: " + c.lastChatMsgQueueID + ", latest: "+c.lastChatMsgQueueID+")"); + } #endif - if (NetIdUtils.IdMoreRecent(lastRecvChatMsgID, c.lastRecvChatMsgID)) c.lastRecvChatMsgID = lastRecvChatMsgID; - if (NetIdUtils.IdMoreRecent(c.lastRecvChatMsgID, c.lastChatMsgQueueID)) c.lastRecvChatMsgID = c.lastChatMsgQueueID; - - if (NetIdUtils.IdMoreRecent(lastRecvEntityEventID, c.lastRecvEntityEventID)) c.lastRecvEntityEventID = lastRecvEntityEventID; - if (NetIdUtils.IdMoreRecent(c.lastRecvEntityEventID, lastEntityEventID)) c.lastRecvEntityEventID = lastEntityEventID; - + if (NetIdUtils.IdMoreRecent(lastRecvEntityEventID, c.lastRecvEntityEventID) && + !NetIdUtils.IdMoreRecent(lastRecvEntityEventID, lastEntityEventID)) + { + c.lastRecvEntityEventID = lastRecvEntityEventID; + } +#if DEBUG + else if (lastRecvEntityEventID != c.lastRecvEntityEventID) + { + DebugConsole.ThrowError( + "Invalid lastRecvEntityEventID " + lastRecvEntityEventID + + " (previous: " + c.lastRecvEntityEventID + ", latest: " + lastEntityEventID + ")"); + } +#endif break; case ClientNetObject.CHAT_MESSAGE: ChatMessage.ServerRead(inc, c);