Reimplement pinging via the orders channel.
This commit is contained in:
@@ -199,7 +199,12 @@ namespace OpenRA
|
||||
{
|
||||
return new Order("HandshakeResponse", null, false) { IsImmediate = true, TargetString = text };
|
||||
}
|
||||
|
||||
|
||||
public static Order Pong(string pingTime)
|
||||
{
|
||||
return new Order("Pong", null, false) { IsImmediate = true, TargetString = pingTime };
|
||||
}
|
||||
|
||||
public static Order PauseGame(bool paused)
|
||||
{
|
||||
return new Order("PauseGame", null, false) { TargetString = paused ? "Pause" : "UnPause" };
|
||||
|
||||
@@ -62,6 +62,8 @@ namespace OpenRA.Network
|
||||
public bool IsReady { get { return State == ClientState.Ready; } }
|
||||
public bool IsObserver { get { return Slot == null; } }
|
||||
public int Ping = -1;
|
||||
public int PingJitter = -1;
|
||||
public int[] PingHistory = {};
|
||||
}
|
||||
|
||||
public class Slot
|
||||
|
||||
@@ -190,6 +190,11 @@ namespace OpenRA.Network
|
||||
Game.Debug("{0} has reciprocated",targetPlayer.PlayerName);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case "Ping":
|
||||
{
|
||||
orderManager.IssueOrder(Order.Pong(order.TargetString));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -290,8 +290,9 @@ namespace OpenRA.Server
|
||||
SyncClientToPlayerReference(client, Map.Players[client.Slot]);
|
||||
|
||||
lobbyInfo.Clients.Add(client);
|
||||
//Assume that first validated client is server admin
|
||||
if(lobbyInfo.Clients.Where(c1 => c1.Bot == null).Count()==1)
|
||||
|
||||
// Assume that first validated client is server admin
|
||||
if (lobbyInfo.Clients.Where(c1 => c1.Bot == null).Count() == 1)
|
||||
client.IsAdmin=true;
|
||||
|
||||
OpenRA.Network.Session.Client clientAdmin = lobbyInfo.Clients.Where(c1 => c1.IsAdmin).Single();
|
||||
@@ -305,6 +306,9 @@ namespace OpenRA.Server
|
||||
SyncLobbyInfo();
|
||||
SendChat(newConn, "has joined the game.");
|
||||
|
||||
// Send initial ping
|
||||
SendOrderTo(newConn, "Ping", Environment.TickCount.ToString());
|
||||
|
||||
if (File.Exists("{0}motd_{1}.txt".F(Platform.SupportDir, lobbyInfo.GlobalSettings.Mods[0])))
|
||||
{
|
||||
var motd = System.IO.File.ReadAllText("{0}motd_{1}.txt".F(Platform.SupportDir, lobbyInfo.GlobalSettings.Mods[0]));
|
||||
@@ -456,6 +460,31 @@ namespace OpenRA.Server
|
||||
foreach (var c in conns.Except(conn).ToArray())
|
||||
DispatchOrdersToClient(c, fromIndex, 0, so.Serialize());
|
||||
break;
|
||||
case "Pong":
|
||||
{
|
||||
int pingSent;
|
||||
if (!int.TryParse(so.Data, out pingSent))
|
||||
{
|
||||
Log.Write("server", "Invalid order pong payload: {0}", so.Data);
|
||||
break;
|
||||
}
|
||||
|
||||
var history = fromClient.PingHistory.ToList();
|
||||
history.Add(Environment.TickCount - pingSent);
|
||||
|
||||
// Cap ping history at 5 values (25 seconds)
|
||||
if (history.Count > 5)
|
||||
history.RemoveRange(0, history.Count - 5);
|
||||
|
||||
fromClient.Ping = history.Sum() / history.Count;
|
||||
fromClient.PingJitter = (history.Max() - history.Min())/2;
|
||||
fromClient.PingHistory = history.ToArray();
|
||||
|
||||
if (State == ServerState.WaitingPlayers)
|
||||
SyncLobbyInfo();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user