diff --git a/Subsurface/Source/Networking/Client.cs b/Subsurface/Source/Networking/Client.cs index 8ccfbed3b..ea148d322 100644 --- a/Subsurface/Source/Networking/Client.cs +++ b/Subsurface/Source/Networking/Client.cs @@ -42,6 +42,7 @@ namespace Barotrauma.Networking public UInt32 lastRecvEntitySpawnID = 0; public List chatMsgQueue = new List(); + public UInt32 lastChatMsgQueueID; public float ChatSpamSpeed; public float ChatSpamTimer; public int ChatSpamCount; diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index aaf4ef17c..d9f19a33c 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -441,7 +441,7 @@ namespace Barotrauma.Networking continue; } } - + // if 30ms has passed if (updateTimer < DateTime.Now) { @@ -530,6 +530,8 @@ namespace Barotrauma.Networking ClientReadLobby(inc); break; case ClientPacketHeader.UPDATE_INGAME: + if (!gameStarted) return; + ClientReadIngame(inc); break; } @@ -596,8 +598,8 @@ namespace Barotrauma.Networking { case ClientNetObject.SYNC_IDS: //TODO: might want to use a clever class for this - c.lastRecvGeneralUpdate = Math.Max(c.lastRecvGeneralUpdate, inc.ReadUInt32()); - c.lastRecvChatMsgID = Math.Max(c.lastRecvChatMsgID, inc.ReadUInt32()); + c.lastRecvGeneralUpdate = Math.Min(Math.Max(c.lastRecvGeneralUpdate, inc.ReadUInt32()), GameMain.NetLobbyScreen.LastUpdateID); + c.lastRecvChatMsgID = Math.Min(Math.Max(c.lastRecvChatMsgID, inc.ReadUInt32()), c.lastChatMsgQueueID); break; case ClientNetObject.CHAT_MESSAGE: ChatMessage.ServerRead(inc, c); @@ -627,11 +629,31 @@ namespace Barotrauma.Networking { case ClientNetObject.SYNC_IDS: //TODO: might want to use a clever class for this + + UInt32 lastRecvChatMsgID = inc.ReadUInt32(); + UInt32 lastRecvEntitySpawnID = inc.ReadUInt32(); + UInt32 lastRecvEntityEventID = inc.ReadUInt32(); + + //last msgs we've created/sent, the client IDs should never be higher than these + UInt32 lastEntitySpawnID = Entity.Spawner.NetStateID; + UInt32 lastEntityEventID = entityEventManager.Events.Count() == 0 ? 0 : entityEventManager.Events.Last().ID; + +#if DEBUG + //client thinks they've received a msg we haven't sent yet (corrupted packet, msg read/written incorrectly?) + if (lastRecvChatMsgID > c.lastChatMsgQueueID) + DebugConsole.ThrowError("client.lastRecvChatMsgID > lastChatMsgQueueID"); + + if (lastRecvEntitySpawnID > lastEntitySpawnID) + DebugConsole.ThrowError("client.lastRecvEntitySpawnID > lastEntitySpawnID"); + + if (lastRecvEntityEventID > lastEntityEventID) + DebugConsole.ThrowError("client.lastRecvEntityEventID > lastEntityEventID"); +#endif + + c.lastRecvChatMsgID = Math.Min(Math.Max(c.lastRecvChatMsgID, lastRecvChatMsgID), c.lastChatMsgQueueID); + c.lastRecvEntitySpawnID = Math.Min(Math.Max(c.lastRecvEntitySpawnID, lastRecvEntitySpawnID), lastEntitySpawnID); + c.lastRecvEntityEventID = Math.Min(Math.Max(c.lastRecvEntityEventID, lastRecvEntityEventID), lastEntityEventID); - //c.lastRecvGeneralUpdate = Math.Max(c.lastRecvGeneralUpdate, inc.ReadUInt32()); - c.lastRecvChatMsgID = Math.Max(c.lastRecvChatMsgID, inc.ReadUInt32()); - c.lastRecvEntitySpawnID = Math.Max(c.lastRecvEntitySpawnID, inc.ReadUInt32()); - c.lastRecvEntityEventID = Math.Max(c.lastRecvEntityEventID, inc.ReadUInt32()); break; case ClientNetObject.CHAT_MESSAGE: @@ -1342,6 +1364,7 @@ namespace Barotrauma.Networking client.lastRecvChatMsgID+1; client.chatMsgQueue.Add(chatMsg); + client.lastChatMsgQueueID = chatMsg.NetStateID; } string myReceivedMessage = message; diff --git a/Subsurface/Source/Networking/GameServerLogin.cs b/Subsurface/Source/Networking/GameServerLogin.cs index 9cd42c99a..712650868 100644 --- a/Subsurface/Source/Networking/GameServerLogin.cs +++ b/Subsurface/Source/Networking/GameServerLogin.cs @@ -201,7 +201,8 @@ namespace Barotrauma.Networking unauthenticatedClients.Remove(unauthClient); unauthClient = null; ConnectedClients.Add(newClient); - return; + + AddChatMessage(clName+" has joined the server.", ChatMessageType.Server); } } } diff --git a/Subsurface/Source/Networking/NetEntityEvent/ServerEntityEventManager.cs b/Subsurface/Source/Networking/NetEntityEvent/ServerEntityEventManager.cs index 2d02d3b9f..b8ca51f11 100644 --- a/Subsurface/Source/Networking/NetEntityEvent/ServerEntityEventManager.cs +++ b/Subsurface/Source/Networking/NetEntityEvent/ServerEntityEventManager.cs @@ -11,6 +11,11 @@ namespace Barotrauma.Networking { private List events; + public List Events + { + get { return events; } + } + private UInt32 ID; private GameServer server;