Skip to content
Permalink
Browse files

fix mistake with negative ping, better function names for PingList cl…

…ass.
  • Loading branch information...
UnknownShadow200 committed Jun 25, 2017
1 parent 1fd6528 commit eaa9502907c9e7ca26914d1bfccd77903c570e36
Showing with 11 additions and 10 deletions.
  1. +11 −10 fCraft/Network/PingList.cs
@@ -36,6 +36,7 @@ public struct PingEntry {
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);
}

@@ -48,42 +49,42 @@ public struct PingEntry {
}


/// <summary> Gets best ping in milliseconds, or 0 if no ping measures. </summary>
public double BestPingMilliseconds() {
/// <summary> Gets lowest (best) ping in milliseconds, or 0 if no ping measures. </summary>
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;
}

/// <summary> Gets average ping in milliseconds, or 0 if no ping measures. </summary>
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);
}

/// <summary> Gets worst ping in milliseconds, or 0 if no ping measures. </summary>
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());
}
}
}

0 comments on commit eaa9502

Please sign in to comment.
You can’t perform that action at this time.