Skip to content

Commit

Permalink
fix mistake with negative ping, better function names for PingList cl…
Browse files Browse the repository at this point in the history
…ass.
  • Loading branch information
UnknownShadow200 committed Jun 25, 2017
1 parent 1fd6528 commit eaa9502
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions fCraft/Network/PingList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public ushort NextTwoWayPingData() {
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);
}

Expand All @@ -48,42 +49,42 @@ public void Update(ushort data) {
}


/// <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.