added game server pinging

This commit is contained in:
Matthias Mailänder
2013-04-07 15:06:14 +02:00
parent 5eff33cc65
commit 2a9cfc6203
3 changed files with 74 additions and 6 deletions

View File

@@ -10,6 +10,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
namespace OpenRA.Network
{
@@ -65,5 +66,21 @@ namespace OpenRA.Network
return UsefulMods.All(m => Game.CurrentMods.ContainsKey(m.Key)
&& AreVersionsCompatible(m.Value, Game.CurrentMods[m.Key].Version));
}
public int Latency = -1;
bool hasBeenPinged;
public void Ping()
{
if (!hasBeenPinged)
{
hasBeenPinged = true;
var pingSender = new Ping();
PingReply reply = pingSender.Send(Address.Split(':')[0]);
if (reply != null && reply.Status == IPStatus.Success)
Latency = (int)reply.RoundtripTime;
else
Latency = -1;
}
}
}
}