From 4ad373294c96723c2c6f4c0d55d01984b3036918 Mon Sep 17 00:00:00 2001 From: juanjp600 Date: Thu, 6 Apr 2017 12:37:38 -0300 Subject: [PATCH] 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. --- Subsurface/Source/Networking/GameClient.cs | 1 + Subsurface/Source/Networking/GameServer.cs | 8 +++++--- .../Networking/NetEntityEvent/ClientEntityEventManager.cs | 2 +- .../Networking/NetEntityEvent/ServerEntityEventManager.cs | 7 +++++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Subsurface/Source/Networking/GameClient.cs b/Subsurface/Source/Networking/GameClient.cs index dcbda50f0..e5ebaa5fa 100644 --- a/Subsurface/Source/Networking/GameClient.cs +++ b/Subsurface/Source/Networking/GameClient.cs @@ -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; diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 9931b4029..eca34753f 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -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); diff --git a/Subsurface/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs b/Subsurface/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs index 8aac6cf7b..c4a9d7a2b 100644 --- a/Subsurface/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs +++ b/Subsurface/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs @@ -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 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