mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-18 11:48:33 -04:00
Show proper message when can't measure ping
This commit is contained in:
parent
4da395f5b6
commit
0fee516c91
@ -30,18 +30,20 @@ namespace MCGalaxy.Commands.Chatting {
|
|||||||
if (p.IsSuper) { p.Message("Super users cannot measure their own ping."); return; }
|
if (p.IsSuper) { p.Message("Super users cannot measure their own ping."); return; }
|
||||||
|
|
||||||
if (!p.hasTwoWayPing) {
|
if (!p.hasTwoWayPing) {
|
||||||
p.Message("Your client does not support measuring ping. You may need to update it.");
|
p.Message("Your client does not support measuring ping.");
|
||||||
|
} else if (p.Ping.Measures() == 0) {
|
||||||
|
p.Message("No ping measurements yet. Try again in a bit.");
|
||||||
} else {
|
} else {
|
||||||
p.Message(p.Ping.Format());
|
p.Message(p.Ping.Format());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!CheckExtraPerm(p, data, 1)) return;
|
if (!CheckExtraPerm(p, data, 1)) return;
|
||||||
Player[] players = PlayerInfo.Online.Items;
|
Player[] players = PlayerInfo.Online.Items;
|
||||||
p.Message("Ping/latency list for online players:");
|
p.Message("Ping/latency list for online players:");
|
||||||
|
|
||||||
foreach (Player pl in players) {
|
foreach (Player pl in players) {
|
||||||
if (!Entities.CanSee(data, p, pl)) continue;
|
if (!Entities.CanSee(data, p, pl)) continue;
|
||||||
if (pl.Ping.AveragePingMilliseconds() == 0) continue;
|
if (pl.Ping.Measures() == 0) continue;
|
||||||
p.Message(pl.ColoredName + " %S- " + pl.Ping.Format());
|
p.Message(pl.ColoredName + " %S- " + pl.Ping.Format());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,42 +65,47 @@ namespace MCGalaxy.Network {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary> Gets lowest (best) ping in milliseconds, or 0 if no ping measures. </summary>
|
bool Valid(int i) {
|
||||||
public int LowestPingMilliseconds() {
|
PingEntry e = Entries[i];
|
||||||
double totalMs = 100000000;
|
return e.TimeSent.Ticks != 0 && e.TimeReceived.Ticks != 0;
|
||||||
foreach (PingEntry ping in Entries) {
|
|
||||||
if (ping.TimeSent.Ticks == 0 || ping.TimeReceived.Ticks == 0) continue;
|
|
||||||
totalMs = Math.Min(totalMs, ping.Latency);
|
|
||||||
}
|
|
||||||
return (int)totalMs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Gets average ping in milliseconds, or 0 if no ping measures. </summary>
|
public int Measures() {
|
||||||
public int AveragePingMilliseconds() {
|
|
||||||
double totalMs = 0;
|
|
||||||
int measures = 0;
|
int measures = 0;
|
||||||
foreach (PingEntry ping in Entries) {
|
for (int i = 0; i < Entries.Length; i++) {
|
||||||
if (ping.TimeSent.Ticks == 0 || ping.TimeReceived.Ticks == 0) continue;
|
if (Valid(i)) measures++;
|
||||||
totalMs += ping.Latency; measures++;
|
|
||||||
}
|
}
|
||||||
return measures == 0 ? 0 : (int)(totalMs / measures);
|
return measures;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Gets worst ping in milliseconds, or 0 if no ping measures. </summary>
|
public int LowestPing() {
|
||||||
public double HighestPingMilliseconds() {
|
double ms = 100000000;
|
||||||
double totalMs = 0;
|
for (int i = 0; i < Entries.Length; i++) {
|
||||||
foreach (PingEntry ping in Entries) {
|
if (Valid(i)) { ms = Math.Min(ms, Entries[i].Latency); }
|
||||||
if (ping.TimeSent.Ticks == 0 || ping.TimeReceived.Ticks == 0) continue;
|
|
||||||
totalMs = Math.Max(totalMs, ping.Latency);
|
|
||||||
}
|
}
|
||||||
return (int)totalMs;
|
return (int)ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int AveragePing() {
|
||||||
|
double ms = 0;
|
||||||
|
int measures = 0;
|
||||||
|
for (int i = 0; i < Entries.Length; i++) {
|
||||||
|
if (Valid(i)) { ms += Entries[i].Latency; measures++; }
|
||||||
|
}
|
||||||
|
return measures == 0 ? 0 : (int)(ms / measures);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int HighestPing() {
|
||||||
|
double ms = 0;
|
||||||
|
for (int i = 0; i < Entries.Length; i++) {
|
||||||
|
if (Valid(i)) { ms = Math.Max(ms, Entries[i].Latency); }
|
||||||
|
}
|
||||||
|
return (int)ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Format() {
|
public string Format() {
|
||||||
return string.Format("Lowest ping {0}ms, average {1}ms, highest {2}ms",
|
return string.Format("Lowest ping {0}ms, average {1}ms, highest {2}ms",
|
||||||
LowestPingMilliseconds(),
|
LowestPing(), AveragePing(), HighestPing());
|
||||||
AveragePingMilliseconds(),
|
|
||||||
HighestPingMilliseconds());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user