Remove ICMP based pinger
This commit is contained in:
@@ -25,8 +25,6 @@ namespace OpenRA.Server
|
|||||||
public int ExpectLength = 8;
|
public int ExpectLength = 8;
|
||||||
public int Frame = 0;
|
public int Frame = 0;
|
||||||
public int MostRecentFrame = 0;
|
public int MostRecentFrame = 0;
|
||||||
public string RemoteAddress;
|
|
||||||
public int Latency = -1;
|
|
||||||
|
|
||||||
/* client data */
|
/* client data */
|
||||||
public int PlayerIndex;
|
public int PlayerIndex;
|
||||||
@@ -101,34 +99,6 @@ namespace OpenRA.Server
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasBeenPinged;
|
|
||||||
public void Ping()
|
|
||||||
{
|
|
||||||
if (!hasBeenPinged)
|
|
||||||
{
|
|
||||||
hasBeenPinged = true;
|
|
||||||
var pingSender = new Ping();
|
|
||||||
pingSender.PingCompleted += new PingCompletedEventHandler(pongRecieved);
|
|
||||||
AutoResetEvent waiter = new AutoResetEvent(false);
|
|
||||||
pingSender.SendAsync(RemoteAddress, waiter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void pongRecieved(object sender, PingCompletedEventArgs e)
|
|
||||||
{
|
|
||||||
if (e.Cancelled || e.Error != null)
|
|
||||||
Latency = -1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PingReply pong = e.Reply;
|
|
||||||
if (pong != null && pong.Status == IPStatus.Success)
|
|
||||||
Latency = (int)pong.RoundtripTime;
|
|
||||||
else
|
|
||||||
Latency = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ReceiveState { Header, Data };
|
public enum ReceiveState { Header, Data };
|
||||||
|
|||||||
@@ -59,8 +59,6 @@ namespace OpenRA.Server
|
|||||||
public Map Map;
|
public Map Map;
|
||||||
XTimer gameTimeout;
|
XTimer gameTimeout;
|
||||||
|
|
||||||
int highestLatency;
|
|
||||||
|
|
||||||
protected volatile ServerState pState = new ServerState();
|
protected volatile ServerState pState = new ServerState();
|
||||||
public ServerState State
|
public ServerState State
|
||||||
{
|
{
|
||||||
@@ -217,9 +215,6 @@ namespace OpenRA.Server
|
|||||||
DispatchOrdersToClient(newConn, 0, 0, new ServerOrder("HandshakeRequest", request.Serialize()).Serialize());
|
DispatchOrdersToClient(newConn, 0, 0, new ServerOrder("HandshakeRequest", request.Serialize()).Serialize());
|
||||||
}
|
}
|
||||||
catch (Exception) { DropClient(newConn); }
|
catch (Exception) { DropClient(newConn); }
|
||||||
|
|
||||||
newConn.RemoteAddress = ((IPEndPoint)newConn.socket.RemoteEndPoint).Address.ToString();
|
|
||||||
newConn.Ping();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValidateClient(Connection newConn, string data)
|
void ValidateClient(Connection newConn, string data)
|
||||||
@@ -271,7 +266,8 @@ namespace OpenRA.Server
|
|||||||
// Check if IP is banned
|
// Check if IP is banned
|
||||||
if (lobbyInfo.GlobalSettings.Ban != null)
|
if (lobbyInfo.GlobalSettings.Ban != null)
|
||||||
{
|
{
|
||||||
if (lobbyInfo.GlobalSettings.Ban.Contains(newConn.RemoteAddress))
|
var remote_addr = ((IPEndPoint)newConn.socket.RemoteEndPoint).Address.ToString();
|
||||||
|
if (lobbyInfo.GlobalSettings.Ban.Contains(remote_addr))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Rejected connection from "+client.Name+"("+newConn.socket.RemoteEndPoint+"); Banned.");
|
Console.WriteLine("Rejected connection from "+client.Name+"("+newConn.socket.RemoteEndPoint+"); Banned.");
|
||||||
Log.Write("server", "Rejected connection from {0}; Banned.",
|
Log.Write("server", "Rejected connection from {0}; Banned.",
|
||||||
@@ -286,8 +282,6 @@ namespace OpenRA.Server
|
|||||||
preConns.Remove(newConn);
|
preConns.Remove(newConn);
|
||||||
conns.Add(newConn);
|
conns.Add(newConn);
|
||||||
|
|
||||||
client.Ping = newConn.Latency;
|
|
||||||
|
|
||||||
// Enforce correct PlayerIndex and Slot
|
// Enforce correct PlayerIndex and Slot
|
||||||
client.Index = newConn.PlayerIndex;
|
client.Index = newConn.PlayerIndex;
|
||||||
client.Slot = lobbyInfo.FirstEmptySlot();
|
client.Slot = lobbyInfo.FirstEmptySlot();
|
||||||
@@ -302,16 +296,14 @@ 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} with {2} ms ping latency.",
|
Log.Write("server", "Client {0}: Accepted connection from {1}.",
|
||||||
newConn.PlayerIndex, newConn.socket.RemoteEndPoint, newConn.Latency);
|
newConn.PlayerIndex, newConn.socket.RemoteEndPoint);
|
||||||
|
|
||||||
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.");
|
|
||||||
|
|
||||||
SetDynamicOrderLag();
|
|
||||||
SyncLobbyInfo();
|
SyncLobbyInfo();
|
||||||
|
SendChat(newConn, "has joined the game.");
|
||||||
|
|
||||||
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])))
|
||||||
{
|
{
|
||||||
@@ -503,9 +495,6 @@ namespace OpenRA.Server
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (highestLatency == toDrop.Latency)
|
|
||||||
SetDynamicOrderLag();
|
|
||||||
|
|
||||||
DispatchOrders( toDrop, toDrop.MostRecentFrame, new byte[] { 0xbf } );
|
DispatchOrders( toDrop, toDrop.MostRecentFrame, new byte[] { 0xbf } );
|
||||||
|
|
||||||
if (conns.Count != 0 || lobbyInfo.GlobalSettings.Dedicated)
|
if (conns.Count != 0 || lobbyInfo.GlobalSettings.Dedicated)
|
||||||
@@ -521,23 +510,6 @@ 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 / 120;
|
|
||||||
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. */
|
||||||
|
|||||||
Reference in New Issue
Block a user