Skip to content

Commit b6b407b

Browse files
authored
fix: update ping information (AscensionGameDev#2247)
1 parent 742be8e commit b6b407b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Intersect.Network/ClientNetwork.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Concurrent;
22
using System.Net;
3+
using System.Net.NetworkInformation;
34
using System.Security.Cryptography;
45
using Intersect.Core;
56
using Intersect.Logging;
@@ -55,7 +56,17 @@ RSAParameters rsaParameters
5556

5657
public bool IsServerOnline => IsConnected;
5758

58-
public int Ping => (int)(Connections.FirstOrDefault()?.Statistics.Ping ?? -1);
59+
public int Ping
60+
{
61+
get
62+
{
63+
// Send a ping to the server. Timeout: 5000ms (5 seconds). Packet size: 32 bytes. TTL: 64. Don't fragment.
64+
var reply = new Ping().Send(Configuration.Host, 5000, new byte[32], new PingOptions(64, true));
65+
66+
// Return the roundtrip time in milliseconds (ms) as an integer value (no decimals).
67+
return reply?.Status == IPStatus.Success ? (int)reply.RoundtripTime : 999999;
68+
}
69+
}
5970

6071
public bool Connect()
6172
{

0 commit comments

Comments
 (0)