The server keeps track of which ID a client is going to switch to when midround syncing is done, and switches the ID immediately when the client is in sync (instead of waiting for the client to report the new ID).
Fixes clients occasionally getting kicked out the moment they're in sync, because their latest received ID is still set to the ID of the last unique event and the server thinks they're requesting some old event that doesn't necessarily exist anymore. + added a debug command that creates a ton of entity events
This commit is contained in:
@@ -708,6 +708,39 @@ namespace Barotrauma
|
||||
|
||||
GameMain.Server.ShowNetStats = !GameMain.Server.ShowNetStats;
|
||||
break;
|
||||
#if DEBUG
|
||||
case "spamevents":
|
||||
foreach (Item item in Item.ItemList)
|
||||
{
|
||||
for (int i = 0; i<item.components.Count; i++)
|
||||
{
|
||||
if (item.components[i] is IServerSerializable)
|
||||
{
|
||||
GameMain.Server.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.ComponentState, i });
|
||||
}
|
||||
var itemContainer = item.GetComponent<ItemContainer>();
|
||||
if (itemContainer != null)
|
||||
{
|
||||
GameMain.Server.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.InventoryState });
|
||||
}
|
||||
|
||||
GameMain.Server.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.Status });
|
||||
|
||||
item.NeedsPositionUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Character c in Character.CharacterList)
|
||||
{
|
||||
GameMain.Server.CreateEntityEvent(c, new object[] { NetEntityEvent.Type.Status });
|
||||
}
|
||||
|
||||
foreach (Structure wall in Structure.WallList)
|
||||
{
|
||||
GameMain.Server.CreateEntityEvent(wall);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case "cleanbuild":
|
||||
GameMain.Config.MusicVolume = 0.5f;
|
||||
GameMain.Config.SoundVolume = 0.5f;
|
||||
|
||||
@@ -50,6 +50,7 @@ namespace Barotrauma.Networking
|
||||
public bool NeedsMidRoundSync;
|
||||
//how many unique events the client missed before joining the server
|
||||
public UInt16 UnreceivedEntityEventCount;
|
||||
public UInt16 FirstNewEventID;
|
||||
|
||||
private List<Client> kickVoters;
|
||||
|
||||
|
||||
@@ -692,6 +692,7 @@ namespace Barotrauma.Networking
|
||||
c.UnreceivedEntityEventCount == 0)
|
||||
{
|
||||
c.NeedsMidRoundSync = false;
|
||||
lastRecvEntityEventID = (UInt16)(c.FirstNewEventID - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -212,15 +212,16 @@ namespace Barotrauma.Networking
|
||||
if (client.NeedsMidRoundSync)
|
||||
{
|
||||
msg.Write((byte)ServerNetObject.ENTITY_EVENT_INITIAL);
|
||||
|
||||
//how many (unique) events the clients had missed before joining
|
||||
client.UnreceivedEntityEventCount = (UInt16)uniqueEvents.Count;
|
||||
msg.Write(client.UnreceivedEntityEventCount);
|
||||
|
||||
//ID of the first event sent after the client joined
|
||||
//(after the client has been synced they'll switch their lastReceivedID
|
||||
//to the one before this, and the eventmanagers will start to function "normally")
|
||||
msg.Write(events.Count == 0 ? (UInt16)0 : events[events.Count - 1].ID);
|
||||
client.FirstNewEventID = events.Count == 0 ? (UInt16)0 : events[events.Count - 1].ID;
|
||||
|
||||
msg.Write(client.UnreceivedEntityEventCount);
|
||||
msg.Write(client.FirstNewEventID);
|
||||
Write(msg, eventsToSync, client);
|
||||
}
|
||||
else
|
||||
@@ -273,14 +274,16 @@ namespace Barotrauma.Networking
|
||||
if (uniqueEvents.Count == 0 || (events.Count > 0 && events[0].ID == uniqueEvents[0].ID))
|
||||
{
|
||||
client.UnreceivedEntityEventCount = 0;
|
||||
client.FirstNewEventID = 0;
|
||||
client.NeedsMidRoundSync = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
double midRoundSyncTimeOut = uniqueEvents.Count / MaxEventsPerWrite * server.UpdateInterval.TotalSeconds;
|
||||
midRoundSyncTimeOut = Math.Max(5.0f, midRoundSyncTimeOut * 1.5f);
|
||||
midRoundSyncTimeOut = Math.Max(5.0f, midRoundSyncTimeOut * 2.0f);
|
||||
|
||||
client.UnreceivedEntityEventCount = (UInt16)uniqueEvents.Count;
|
||||
client.FirstNewEventID = 0;
|
||||
client.NeedsMidRoundSync = true;
|
||||
client.MidRoundSyncTimeOut = Timing.TotalTime + midRoundSyncTimeOut;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user