Increase server ping timeout from 2s to 3s and do up to 3 attempts, do not count 0 as valid ping

This commit is contained in:
N00MKRAD
2024-11-25 20:22:24 +01:00
parent 1657117a27
commit a09b290f9a

View File

@@ -36,6 +36,8 @@ namespace Flowframes.Data
await Task.Run(() => Init()); await Task.Run(() => Init());
} }
private const int _defaultPing = 10000;
public static void Init(ComboBox comboBox = null) public static void Init(ComboBox comboBox = null)
{ {
Dictionary<string[], long> serversPings = new Dictionary<string[], long>(); Dictionary<string[], long> serversPings = new Dictionary<string[], long>();
@@ -44,15 +46,29 @@ namespace Flowframes.Data
{ {
try try
{ {
Ping p = new Ping(); long ping = _defaultPing;
PingReply replyEur = p.Send(server.host, 2000); int attempts = 0;
serversPings[new string[] { server.name, server.host, server.pattern }] = replyEur.RoundtripTime;
Logger.Log($"[Servers] Ping to {server.host}: {replyEur.RoundtripTime} ms", true); while(ping == _defaultPing && attempts < 3)
{
Ping p = new Ping();
PingReply pReply = p.Send(server.host, 3000);
if(pReply.RoundtripTime > 0)
{
ping = pReply.RoundtripTime;
}
attempts++;
}
serversPings[new string[] { server.name, server.host, server.pattern }] = ping;
Logger.Log($"[Servers] Ping to {server.host}: {ping} ms", true);
} }
catch (Exception e) catch (Exception e)
{ {
Logger.Log($"[Servers] Failed to ping {server.host}: {e.Message}", true); Logger.Log($"[Servers] Failed to ping {server.host}: {e.Message}", true);
serversPings[new string[] { server.name, server.host, server.pattern }] = 10000; serversPings[new string[] { server.name, server.host, server.pattern }] = _defaultPing;
} }
} }