display ping when player joins lobby, closes #2124
This commit is contained in:
@@ -12,6 +12,8 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using System.Net.NetworkInformation;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace OpenRA.Server
|
namespace OpenRA.Server
|
||||||
{
|
{
|
||||||
@@ -22,8 +24,9 @@ namespace OpenRA.Server
|
|||||||
public ReceiveState State = ReceiveState.Header;
|
public ReceiveState State = ReceiveState.Header;
|
||||||
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;
|
||||||
@@ -97,7 +100,36 @@ namespace OpenRA.Server
|
|||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}
|
||||||
|
|
||||||
|
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 };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -251,6 +251,9 @@ 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)
|
||||||
@@ -302,8 +305,7 @@ namespace OpenRA.Server
|
|||||||
// Check if IP is banned
|
// Check if IP is banned
|
||||||
if (lobbyInfo.GlobalSettings.Ban != null)
|
if (lobbyInfo.GlobalSettings.Ban != null)
|
||||||
{
|
{
|
||||||
var remote_addr = ((IPEndPoint)newConn.socket.RemoteEndPoint).Address.ToString();
|
if (lobbyInfo.GlobalSettings.Ban.Contains(newConn.RemoteAddress))
|
||||||
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.",
|
||||||
@@ -338,16 +340,16 @@ namespace OpenRA.Server
|
|||||||
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));
|
||||||
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])))
|
||||||
{
|
{
|
||||||
var motd = System.IO.File.ReadAllText("{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]));
|
||||||
SendChatTo(newConn, motd);
|
SendChatTo(newConn, motd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( lobbyInfo.GlobalSettings.Dedicated )
|
if (lobbyInfo.GlobalSettings.Dedicated)
|
||||||
{
|
{
|
||||||
if (client.IsAdmin)
|
if (client.IsAdmin)
|
||||||
SendChatTo(newConn, " You are admin now!");
|
SendChatTo(newConn, " You are admin now!");
|
||||||
@@ -578,7 +580,7 @@ namespace OpenRA.Server
|
|||||||
t.GameStarted(this);
|
t.GameStarted(this);
|
||||||
|
|
||||||
// Check TimeOut
|
// Check TimeOut
|
||||||
if ( Settings.TimeOut > 10000 )
|
if (Settings.TimeOut > 10000)
|
||||||
{
|
{
|
||||||
gameTimeout = new XTimer(Settings.TimeOut);
|
gameTimeout = new XTimer(Settings.TimeOut);
|
||||||
gameTimeout.Elapsed += (_,e) =>
|
gameTimeout.Elapsed += (_,e) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user