Skip to content

Commit e77633a

Browse files
fix PingList not including self
1 parent 7bcc3bc commit e77633a

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

fCraft/Commands/InfoCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2098,7 +2098,7 @@ static void PingListHandler(Player player, CommandReader cmd) {
20982098
int offset = 0;
20992099
if (!int.TryParse(offsetStr, out offset)) offset = 0;
21002100

2101-
Player[] candidates = Server.Players.CanBeSeen(player)
2101+
Player[] candidates = Server.Players.CanBeSeen(player).Union(player)
21022102
.Where(p => p.AveragePingMilliseconds() != 0)
21032103
.OrderBy(p => p.AveragePingMilliseconds()).Reverse().ToArray();
21042104
if (candidates.Length < 1) {

fCraft/Network/Player.Networking.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -327,19 +327,21 @@ ushort NextTwoWayPingData() {
327327
if( PingList[i].TimeSent.Ticks != 0 ) continue;
328328

329329
ushort prev = i > 0 ? PingList[i - 1].Data : (ushort)0;
330-
PingList[i].Data = (ushort)(prev + 1);
331-
PingList[i].TimeSent = DateTime.UtcNow;
332-
return (ushort)(prev + 1);
333-
}
334-
335-
// Remove oldest ping slot
336-
for( int i = 0; i < PingList.Length - 1; i++ ) {
337-
PingList[i] = PingList[i + 1];
338-
}
339-
340-
PingList[PingList.Length - 1].Data++;
341-
PingList[PingList.Length - 1].TimeSent = DateTime.UtcNow;
342-
return PingList[PingList.Length - 1].Data;
330+
return SetTwoWayPing( i, prev );
331+
}
332+
333+
// Remove oldest ping slot
334+
for( int i = 0; i < PingList.Length - 1; i++ ) {
335+
PingList[i] = PingList[i + 1];
336+
}
337+
int j = PingList.Length - 1;
338+
return SetTwoWayPing( j, PingList[j].Data );
339+
}
340+
341+
ushort SetTwoWayPing( int i, ushort prev ) {
342+
PingList[i].Data = (ushort)(prev + 1);
343+
PingList[i].TimeSent = DateTime.UtcNow;
344+
return (ushort)(prev + 1);
343345
}
344346

345347
void ProcessPingPacket() {

0 commit comments

Comments
 (0)