From d2a6781e7e933321603dca2fb6182d54f56243cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Thu, 18 Apr 2013 17:09:51 +0200 Subject: [PATCH] set dynamic order lag when client with highest latency leaves hide Ping again from the players, write it to server.log instead just make everything silently work to not discriminate clients --- OpenRA.Game/Server/Server.cs | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index 1b2a0633de..f04deb1b39 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -336,21 +336,15 @@ namespace OpenRA.Server OpenRA.Network.Session.Client clientAdmin = lobbyInfo.Clients.Where(c1 => c1.IsAdmin).Single(); - Log.Write("server", "Client {0}: Accepted connection from {1}", - newConn.PlayerIndex, newConn.socket.RemoteEndPoint); + Log.Write("server", "Client {0}: Accepted connection from {1} with {2} ms ping latency.", + newConn.PlayerIndex, newConn.socket.RemoteEndPoint, newConn.Latency); foreach (var t in ServerTraits.WithInterface()) 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; + SendChat(newConn, "has joined the game."); + SetDynamicOrderLag(); SyncLobbyInfo(); if (File.Exists("{0}motd_{1}.txt".F(Platform.SupportDir, lobbyInfo.GlobalSettings.Mods[0]))) @@ -370,8 +364,6 @@ 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); } } @@ -545,7 +537,8 @@ namespace OpenRA.Server } } - //TODO: if (highestLatency == toDrop.Latency) then find the new highestLatency + if (highestLatency == toDrop.Latency) + SetDynamicOrderLag(); DispatchOrders( toDrop, toDrop.MostRecentFrame, new byte[] { 0xbf } ); @@ -562,6 +555,23 @@ namespace OpenRA.Server catch { } } + public void SetDynamicOrderLag() + { + foreach (var conn in conns) + { + if (conn.Latency > highestLatency) + highestLatency = conn.Latency; + } + + Log.Write("server", "Measured {0} ms as the highest connection round trip time.".F(highestLatency)); + + lobbyInfo.GlobalSettings.OrderLatency = highestLatency / 40; // 1 frame is 40 ms + if (lobbyInfo.GlobalSettings.OrderLatency < 1) // should never be 0 + lobbyInfo.GlobalSettings.OrderLatency = 1; + + Log.Write("server", "Order lag has been adjusted to {0} frames.".F(lobbyInfo.GlobalSettings.OrderLatency)); + } + public void SyncLobbyInfo() { if (State != ServerState.GameStarted) /* don't do this while the game is running, it breaks things. */