From f8e44b792f80a40c0cfbb98e2177b612516a780f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 7 Apr 2013 22:22:42 +0200 Subject: [PATCH] adjust order latency dynamically by client ping, closes #2990 --- OpenRA.Game/Network/Session.cs | 2 +- OpenRA.Game/Network/UnitOrders.cs | 3 +-- OpenRA.Game/Server/Server.cs | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/OpenRA.Game/Network/Session.cs b/OpenRA.Game/Network/Session.cs index ffa6be46dc..ae65c4c277 100644 --- a/OpenRA.Game/Network/Session.cs +++ b/OpenRA.Game/Network/Session.cs @@ -82,7 +82,7 @@ namespace OpenRA.Network public string Map; public string[] Ban; public string[] Mods = { "ra" }; // mod names - public int OrderLatency = 3; + public int OrderLatency = 3; // x 40 = ms public int RandomSeed = 0; public bool FragileAlliances = false; // Allow diplomatic stance changes after game start. public bool AllowCheats = false; diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs index 24583688aa..8fda65b014 100755 --- a/OpenRA.Game/Network/UnitOrders.cs +++ b/OpenRA.Game/Network/UnitOrders.cs @@ -164,8 +164,7 @@ namespace OpenRA.Network && !orderManager.GameStarted) { orderManager.FramesAhead = orderManager.LobbyInfo.GlobalSettings.OrderLatency; - Game.Debug( - "Order lag is now {0} frames.".F(orderManager.LobbyInfo.GlobalSettings.OrderLatency)); + Game.Debug("Order lag is now {0} frames.".F(orderManager.LobbyInfo.GlobalSettings.OrderLatency)); } Game.SyncLobbyInfo(); break; diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index e9de70762a..1b2a0633de 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -64,6 +64,8 @@ namespace OpenRA.Server public Map Map; XTimer gameTimeout; + int highestLatency; + protected volatile ServerState pState = new ServerState(); public ServerState State { @@ -341,6 +343,14 @@ namespace OpenRA.Server t.ClientJoined(this, newConn); SendChat(newConn, "has joined the game. Ping: {0} ms".F(newConn.Latency)); + + if (newConn.Latency > highestLatency) + highestLatency = newConn.Latency; + + lobbyInfo.GlobalSettings.OrderLatency = highestLatency / 40; // 1 frame is 40 ms + if (lobbyInfo.GlobalSettings.OrderLatency < 1) // should never be 0 + lobbyInfo.GlobalSettings.OrderLatency = 1; + SyncLobbyInfo(); if (File.Exists("{0}motd_{1}.txt".F(Platform.SupportDir, lobbyInfo.GlobalSettings.Mods[0]))) @@ -360,6 +370,8 @@ namespace OpenRA.Server if (mods.Any(m => m.Contains("{DEV_VERSION}"))) SendChat(newConn, "is running a non-versioned development build, "+ "and may cause desync if it contains any incompatible changes."); + + Game.Debug("Order lag has been adjusted to {0} frames.".F(lobbyInfo.GlobalSettings.OrderLatency)); } catch (Exception) { DropClient(newConn); } } @@ -532,7 +544,9 @@ namespace OpenRA.Server SendChat(toDrop, "Admin left! {0} is a new admin now!".F(lastClient.Name)); } } - + + //TODO: if (highestLatency == toDrop.Latency) then find the new highestLatency + DispatchOrders( toDrop, toDrop.MostRecentFrame, new byte[] { 0xbf } ); if (conns.Count != 0 || lobbyInfo.GlobalSettings.Dedicated)