Server checks if midround syncing is needed when a client is in the game (i.e. loaded the sub, etc), not when the client requests the start message. Some clients take longer to start the round than others, and they may miss unique messages even if they were in the lobby when the round started.
Clients also get extra 10 seconds to receive newly created events after the midround syncing is done
This commit is contained in:
@@ -565,7 +565,6 @@ namespace Barotrauma.Networking
|
|||||||
//game already started -> send start message immediately
|
//game already started -> send start message immediately
|
||||||
if (gameStarted)
|
if (gameStarted)
|
||||||
{
|
{
|
||||||
connectedClient.NeedsMidRoundSync = true;
|
|
||||||
SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset, connectedClient);
|
SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset, connectedClient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -655,12 +654,8 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
if (!c.inGame)
|
if (!c.inGame)
|
||||||
{
|
{
|
||||||
if (c.NeedsMidRoundSync)
|
//check if midround syncing is needed due to missed unique events
|
||||||
{
|
entityEventManager.InitClientMidRoundSync(c);
|
||||||
//client joined mid-round and has just started up the game
|
|
||||||
//check which unique messages they've missed
|
|
||||||
entityEventManager.InitClientMidRoundSync(c);
|
|
||||||
}
|
|
||||||
c.inGame = true;
|
c.inGame = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,12 +133,14 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
//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 => NetIdUtils.IdMoreRecent((UInt16)(lastSentToAll + 1), c.lastRecvEntityEventID));
|
List<Client> toKick = inGameClients.FindAll(c =>
|
||||||
|
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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: calculate a reasonable timeout period for midround syncing and/or give the client more time if they're receiving messages
|
|
||||||
var timedOutClients = clients.FindAll(c => c.inGame && c.NeedsMidRoundSync && Timing.TotalTime > c.MidRoundSyncTimeOut);
|
var timedOutClients = clients.FindAll(c => c.inGame && c.NeedsMidRoundSync && Timing.TotalTime > c.MidRoundSyncTimeOut);
|
||||||
if (timedOutClients != null) timedOutClients.ForEach(c => GameMain.Server.DisconnectClient(c, "", "You have been disconnected because syncing your client with the server took too long."));
|
if (timedOutClients != null) timedOutClients.ForEach(c => GameMain.Server.DisconnectClient(c, "", "You have been disconnected because syncing your client with the server took too long."));
|
||||||
|
|
||||||
@@ -248,7 +250,14 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
public void InitClientMidRoundSync(Client client)
|
public void InitClientMidRoundSync(Client client)
|
||||||
{
|
{
|
||||||
if (uniqueEvents.Count > 0)
|
//no need for midround syncing if no events have been created,
|
||||||
|
//or if the first created unique event is still in the event list
|
||||||
|
if (uniqueEvents.Count == 0 || (events.Count > 0 && events[0].ID == uniqueEvents[0].ID))
|
||||||
|
{
|
||||||
|
client.UnreceivedEntityEventCount = 0;
|
||||||
|
client.NeedsMidRoundSync = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
double midRoundSyncTimeOut = uniqueEvents.Count / MaxEventsPerWrite * server.UpdateInterval.TotalSeconds;
|
double midRoundSyncTimeOut = uniqueEvents.Count / MaxEventsPerWrite * server.UpdateInterval.TotalSeconds;
|
||||||
midRoundSyncTimeOut = Math.Max(5.0f, midRoundSyncTimeOut * 1.5f);
|
midRoundSyncTimeOut = Math.Max(5.0f, midRoundSyncTimeOut * 1.5f);
|
||||||
@@ -257,11 +266,6 @@ namespace Barotrauma.Networking
|
|||||||
client.NeedsMidRoundSync = true;
|
client.NeedsMidRoundSync = true;
|
||||||
client.MidRoundSyncTimeOut = Timing.TotalTime + midRoundSyncTimeOut;
|
client.MidRoundSyncTimeOut = Timing.TotalTime + midRoundSyncTimeOut;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
client.UnreceivedEntityEventCount = 0;
|
|
||||||
client.NeedsMidRoundSync = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user