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
This commit is contained in:
Matthias Mailänder
2013-04-18 17:09:51 +02:00
parent f8e44b792f
commit d2a6781e7e

View File

@@ -336,21 +336,15 @@ namespace OpenRA.Server
OpenRA.Network.Session.Client clientAdmin = lobbyInfo.Clients.Where(c1 => c1.IsAdmin).Single(); OpenRA.Network.Session.Client clientAdmin = lobbyInfo.Clients.Where(c1 => c1.IsAdmin).Single();
Log.Write("server", "Client {0}: Accepted connection from {1}", Log.Write("server", "Client {0}: Accepted connection from {1} with {2} ms ping latency.",
newConn.PlayerIndex, newConn.socket.RemoteEndPoint); newConn.PlayerIndex, newConn.socket.RemoteEndPoint, newConn.Latency);
foreach (var t in ServerTraits.WithInterface<IClientJoined>()) foreach (var t in ServerTraits.WithInterface<IClientJoined>())
t.ClientJoined(this, newConn); t.ClientJoined(this, newConn);
SendChat(newConn, "has joined the game. Ping: {0} ms".F(newConn.Latency)); SendChat(newConn, "has joined the game.");
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;
SetDynamicOrderLag();
SyncLobbyInfo(); SyncLobbyInfo();
if (File.Exists("{0}motd_{1}.txt".F(Platform.SupportDir, lobbyInfo.GlobalSettings.Mods[0]))) 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}"))) if (mods.Any(m => m.Contains("{DEV_VERSION}")))
SendChat(newConn, "is running a non-versioned development build, "+ SendChat(newConn, "is running a non-versioned development build, "+
"and may cause desync if it contains any incompatible changes."); "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); } 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 } ); DispatchOrders( toDrop, toDrop.MostRecentFrame, new byte[] { 0xbf } );
@@ -562,6 +555,23 @@ namespace OpenRA.Server
catch { } 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() public void SyncLobbyInfo()
{ {
if (State != ServerState.GameStarted) /* don't do this while the game is running, it breaks things. */ if (State != ServerState.GameStarted) /* don't do this while the game is running, it breaks things. */