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.
This commit is contained in:
Regalis
2017-05-02 22:43:48 +03:00
parent d1c633385b
commit ab4e8cee83
+25 -12
View File
@@ -693,6 +693,7 @@ namespace Barotrauma.Networking
{ {
c.NeedsMidRoundSync = false; c.NeedsMidRoundSync = false;
lastRecvEntityEventID = (UInt16)(c.FirstNewEventID - 1); lastRecvEntityEventID = (UInt16)(c.FirstNewEventID - 1);
c.lastRecvEntityEventID = lastRecvEntityEventID;
} }
else 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 #if DEBUG
//client thinks they've received a msg we haven't sent yet (corrupted packet, msg read/written incorrectly?) else if (lastRecvChatMsgID != c.lastRecvChatMsgID)
if (NetIdUtils.IdMoreRecent(lastRecvChatMsgID, c.lastChatMsgQueueID)) {
DebugConsole.ThrowError("client.lastRecvChatMsgID > lastChatMsgQueueID (" + lastRecvChatMsgID + " > " + c.lastChatMsgQueueID + ")"); DebugConsole.ThrowError(
"Invalid lastRecvChatMsgID " + lastRecvChatMsgID +
if (lastRecvEntityEventID > lastEntityEventID) " (previous: " + c.lastChatMsgQueueID + ", latest: "+c.lastChatMsgQueueID+")");
DebugConsole.ThrowError("client.lastRecvEntityEventID > lastEntityEventID (" + lastRecvEntityEventID + " > " + lastEntityEventID + ")"); }
#endif #endif
if (NetIdUtils.IdMoreRecent(lastRecvChatMsgID, c.lastRecvChatMsgID)) c.lastRecvChatMsgID = lastRecvChatMsgID; if (NetIdUtils.IdMoreRecent(lastRecvEntityEventID, c.lastRecvEntityEventID) &&
if (NetIdUtils.IdMoreRecent(c.lastRecvChatMsgID, c.lastChatMsgQueueID)) c.lastRecvChatMsgID = c.lastChatMsgQueueID; !NetIdUtils.IdMoreRecent(lastRecvEntityEventID, lastEntityEventID))
{
if (NetIdUtils.IdMoreRecent(lastRecvEntityEventID, c.lastRecvEntityEventID)) c.lastRecvEntityEventID = lastRecvEntityEventID; c.lastRecvEntityEventID = lastRecvEntityEventID;
if (NetIdUtils.IdMoreRecent(c.lastRecvEntityEventID, lastEntityEventID)) c.lastRecvEntityEventID = lastEntityEventID; }
#if DEBUG
else if (lastRecvEntityEventID != c.lastRecvEntityEventID)
{
DebugConsole.ThrowError(
"Invalid lastRecvEntityEventID " + lastRecvEntityEventID +
" (previous: " + c.lastRecvEntityEventID + ", latest: " + lastEntityEventID + ")");
}
#endif
break; break;
case ClientNetObject.CHAT_MESSAGE: case ClientNetObject.CHAT_MESSAGE:
ChatMessage.ServerRead(inc, c); ChatMessage.ServerRead(inc, c);