From b8dea9a093938cde0cf7e29cfcac05595435b968 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 25 Jun 2017 14:10:55 +1000 Subject: [PATCH] fix mistake with negative ping, better function names for PingList class. --- MCGalaxy/Network/Utils/PingList.cs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/MCGalaxy/Network/Utils/PingList.cs b/MCGalaxy/Network/Utils/PingList.cs index 7fc401718..5473916b2 100644 --- a/MCGalaxy/Network/Utils/PingList.cs +++ b/MCGalaxy/Network/Utils/PingList.cs @@ -52,6 +52,7 @@ namespace MCGalaxy.Network { ushort SetTwoWayPing(int i, ushort prev) { Entries[i].Data = (ushort)(prev + 1); Entries[i].TimeSent = DateTime.UtcNow; + Entries[i].TimeReceived = default(DateTime); return (ushort)(prev + 1); } @@ -64,42 +65,42 @@ namespace MCGalaxy.Network { } - /// Gets best ping in milliseconds, or 0 if no ping measures. - public double BestPingMilliseconds() { + /// Gets lowest (best) ping in milliseconds, or 0 if no ping measures. + public int LowestPingMilliseconds() { double totalMs = 100000000; foreach (PingEntry ping in Entries) { if (ping.TimeSent.Ticks == 0 || ping.TimeReceived.Ticks == 0) continue; totalMs = Math.Min(totalMs, ping.Latency); } - return totalMs; + return (int)totalMs; } /// Gets average ping in milliseconds, or 0 if no ping measures. - public double AveragePingMilliseconds() { + public int AveragePingMilliseconds() { double totalMs = 0; int measures = 0; foreach (PingEntry ping in Entries) { if (ping.TimeSent.Ticks == 0 || ping.TimeReceived.Ticks == 0) continue; totalMs += ping.Latency; measures++; } - return measures == 0 ? 0 : (totalMs / measures); + return measures == 0 ? 0 : (int)(totalMs / measures); } /// Gets worst ping in milliseconds, or 0 if no ping measures. - public double WorstPingMilliseconds() { + public double HighestPingMilliseconds() { double totalMs = 0; foreach (PingEntry ping in Entries) { if (ping.TimeSent.Ticks == 0 || ping.TimeReceived.Ticks == 0) continue; totalMs = Math.Max(totalMs, ping.Latency); } - return totalMs; + return (int)totalMs; } public string Format() { return String.Format("Lowest ping {0}ms, average {1}ms, highest {2}ms", - (int)BestPingMilliseconds(), - (int)AveragePingMilliseconds(), - (int)WorstPingMilliseconds()); + LowestPingMilliseconds(), + AveragePingMilliseconds(), + HighestPingMilliseconds()); } } -} +} \ No newline at end of file