Server ignores UPDATE_INGAME messages if the game isn't running, server doesn't set any of the clients' lastRecvIDs above the ID of the latest chatMsg/event/etc (clients can't have received something the server hasn't sent yet)

This commit is contained in:
Regalis
2017-01-13 18:07:00 +02:00
parent fecb7bee9a
commit 9b03b2bcc1
4 changed files with 38 additions and 8 deletions

View File

@@ -42,6 +42,7 @@ namespace Barotrauma.Networking
public UInt32 lastRecvEntitySpawnID = 0;
public List<ChatMessage> chatMsgQueue = new List<ChatMessage>();
public UInt32 lastChatMsgQueueID;
public float ChatSpamSpeed;
public float ChatSpamTimer;
public int ChatSpamCount;

View File

@@ -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;

View File

@@ -201,7 +201,8 @@ namespace Barotrauma.Networking
unauthenticatedClients.Remove(unauthClient);
unauthClient = null;
ConnectedClients.Add(newClient);
return;
AddChatMessage(clName+" has joined the server.", ChatMessageType.Server);
}
}
}

View File

@@ -11,6 +11,11 @@ namespace Barotrauma.Networking
{
private List<ServerEntityEvent> events;
public List<ServerEntityEvent> Events
{
get { return events; }
}
private UInt32 ID;
private GameServer server;