Update client.UnreceivedEntityEventCount on every event write
I noticed that if the main event IDs went over 10000 and there were more than 450 unique events, the server would sometimes skip the next event the client needed. Sometimes the client would also not realize that the last event it received was the final init event, so it would reject all further events because of a huge ID discrepancy. The init events will likely need to be reworked, but updating UnreceivedEntityEventCount seems to help somewhat.
This commit is contained in:
@@ -570,6 +570,7 @@ namespace Barotrauma.Networking
|
||||
case "You have been banned from the server":
|
||||
case "You have been kicked from the server":
|
||||
case "You have been disconnected because of excessive desync":
|
||||
case "You have been disconnected because syncing your client with the server took too long.":
|
||||
var msgBox = new GUIMessageBox("CONNECTION LOST", disconnectMsg);
|
||||
msgBox.Buttons[0].OnClicked += ReturnToServerList;
|
||||
break;
|
||||
|
||||
@@ -684,7 +684,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
//last msgs we've created/sent, the client IDs should never be higher than these
|
||||
UInt16 lastEntityEventID = entityEventManager.Events.Count == 0 ? (UInt16)0 : entityEventManager.Events.Last().ID;
|
||||
|
||||
|
||||
if (c.NeedsMidRoundSync)
|
||||
{
|
||||
//received all the old events -> client in sync, we can switch to normal behavior
|
||||
@@ -1628,9 +1628,11 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
log.LogFrame.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
|
||||
if (!ShowNetStats) return;
|
||||
|
||||
GUI.Font.DrawString(spriteBatch, "Unique Events: " + entityEventManager.UniqueEvents.Count, new Vector2(10, 50), Color.White);
|
||||
|
||||
int width = 200, height = 300;
|
||||
int x = GameMain.GraphicsWidth - width, y = (int)(GameMain.GraphicsHeight * 0.3f);
|
||||
|
||||
@@ -1643,7 +1645,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black * 0.7f, true);
|
||||
GUI.Font.DrawString(spriteBatch, "Network statistics:", new Vector2(x + 10, y + 10), Color.White);
|
||||
|
||||
|
||||
GUI.SmallFont.DrawString(spriteBatch, "Connections: "+server.ConnectionsCount, new Vector2(x + 10, y + 30), Color.White);
|
||||
GUI.SmallFont.DrawString(spriteBatch, "Received bytes: " + MathUtils.GetBytesReadable(server.Statistics.ReceivedBytes), new Vector2(x + 10, y + 45), Color.White);
|
||||
GUI.SmallFont.DrawString(spriteBatch, "Received packets: " + server.Statistics.ReceivedPackets, new Vector2(x + 10, y + 60), Color.White);
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (thisEventID != lastReceivedID + 1)
|
||||
{
|
||||
DebugConsole.NewMessage("received msg " + thisEventID, 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);
|
||||
}
|
||||
else if (entity == null)
|
||||
{
|
||||
|
||||
@@ -20,6 +20,11 @@ namespace Barotrauma.Networking
|
||||
get { return events; }
|
||||
}
|
||||
|
||||
public List<ServerEntityEvent> UniqueEvents
|
||||
{
|
||||
get { return uniqueEvents; }
|
||||
}
|
||||
|
||||
private class BufferedEvent
|
||||
{
|
||||
public readonly Client Sender;
|
||||
@@ -208,12 +213,14 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
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);
|
||||
|
||||
Write(msg, eventsToSync, client);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user