Event ID wraparound fixes

This commit is contained in:
Regalis
2017-05-02 22:18:36 +03:00
parent 06db2fed86
commit d0b52d92fe
2 changed files with 7 additions and 9 deletions
@@ -145,9 +145,9 @@ namespace Barotrauma.Networking
IServerSerializable entity = Entity.FindEntityByID(entityID) as IServerSerializable; IServerSerializable entity = Entity.FindEntityByID(entityID) as IServerSerializable;
//skip the event if we've already received it or if the entity isn't found //skip the event if we've already received it or if the entity isn't found
if (thisEventID != lastReceivedID + 1 || entity == null) if (thisEventID != (UInt16)(lastReceivedID + 1) || entity == null)
{ {
if (thisEventID != lastReceivedID + 1) if (thisEventID != (UInt16)(lastReceivedID + 1))
{ {
DebugConsole.NewMessage("received msg " + thisEventID + " (waiting for "+ (lastReceivedID+1) + ")", thisEventID<lastReceivedID+1 ? Microsoft.Xna.Framework.Color.Yellow : Microsoft.Xna.Framework.Color.Red); DebugConsole.NewMessage("received msg " + thisEventID + " (waiting for "+ (lastReceivedID+1) + ")", thisEventID<lastReceivedID+1 ? Microsoft.Xna.Framework.Color.Yellow : Microsoft.Xna.Framework.Color.Red);
} }
@@ -144,14 +144,12 @@ namespace Barotrauma.Networking
lastSentToAll = inGameClients[0].lastRecvEntityEventID; lastSentToAll = inGameClients[0].lastRecvEntityEventID;
inGameClients.ForEach(c => { if (NetIdUtils.IdMoreRecent(lastSentToAll, c.lastRecvEntityEventID)) lastSentToAll = c.lastRecvEntityEventID; }); inGameClients.ForEach(c => { if (NetIdUtils.IdMoreRecent(lastSentToAll, c.lastRecvEntityEventID)) lastSentToAll = c.lastRecvEntityEventID; });
ServerEntityEvent firstEventToResend = events.Find(e => e.ID == (lastSentToAll + 1)); ServerEntityEvent firstEventToResend = events.Find(e => e.ID == (ushort)(lastSentToAll + 1));
if (firstEventToResend != null && (Timing.TotalTime - firstEventToResend.CreateTime) > 10.0f) if (firstEventToResend != null && (Timing.TotalTime - firstEventToResend.CreateTime) > 10.0f)
{ {
//it's been 10 seconds since this event was created //it's been 10 seconds since this event was created
//kick everyone that hasn't received it yet, this is way too old //kick everyone that hasn't received it yet, this is way too old
List<Client> toKick = inGameClients.FindAll(c => List<Client> toKick = inGameClients.FindAll(c => NetIdUtils.IdMoreRecent((UInt16)(lastSentToAll + 1), c.lastRecvEntityEventID));
NetIdUtils.IdMoreRecent((UInt16)(lastSentToAll + 1), c.lastRecvEntityEventID) &&
(Timing.TotalTime - c.MidRoundSyncTimeOut) > 10.0f); //give mid-round joining players extra 10 seconds to receive the events
if (toKick != null) toKick.ForEach(c => server.DisconnectClient(c, "", "You have been disconnected because of excessive desync")); if (toKick != null) toKick.ForEach(c => server.DisconnectClient(c, "", "You have been disconnected because of excessive desync"));
} }
@@ -322,9 +320,9 @@ namespace Barotrauma.Networking
IClientSerializable entity = Entity.FindEntityByID(entityID) as IClientSerializable; IClientSerializable entity = Entity.FindEntityByID(entityID) as IClientSerializable;
//skip the event if we've already received it or if the entity isn't found //skip the event if we've already received it or if the entity isn't found
if (thisEventID != sender.lastSentEntityEventID + 1 || entity == null) if (thisEventID != (UInt16)(sender.lastSentEntityEventID + 1) || entity == null)
{ {
if (thisEventID != sender.lastSentEntityEventID + 1) if (thisEventID != (UInt16)(sender.lastSentEntityEventID + 1))
{ {
DebugConsole.NewMessage("received msg " + thisEventID, Microsoft.Xna.Framework.Color.Red); DebugConsole.NewMessage("received msg " + thisEventID, Microsoft.Xna.Framework.Color.Red);
} }