Skip to content

Commit 72c3f00

Browse files
committed
set statistics ping on latency update
1 parent 4cd0421 commit 72c3f00

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Intersect.Network/LiteNetLib/LiteNetLibInterface.cs

+23-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,29 @@ public void OnNetworkLatencyUpdate(NetPeer peer, int latency)
490490
}
491491
#endif
492492

493-
ApplicationContext.Context.Value?.Logger.LogDebug($"LTNC {peer} {latency}ms");
493+
ApplicationContext.CurrentContext.Logger.LogTrace("LATENCY {Peer} {Latency}ms", peer, latency);
494+
495+
if (!_connectionIdLookup.TryGetValue(peer.Id, out var connectionId))
496+
{
497+
ApplicationContext.CurrentContext.Logger.LogWarning("Missing connection for {PeerId}", peer.Id);
498+
return;
499+
}
500+
501+
var genericConnection = _network.FindConnection(connectionId);
502+
if (genericConnection is not LiteNetLibConnection connection)
503+
{
504+
var expectedTypeName = typeof(LiteNetLibConnection).GetName(qualified: true);
505+
var actualTypeName = genericConnection.GetType().GetName(qualified: true);
506+
ApplicationContext.CurrentContext.Logger.LogWarning(
507+
"Connection is not {ExpectedType} for {PeerId}, was {ActualType}",
508+
expectedTypeName,
509+
peer.Id,
510+
actualTypeName
511+
);
512+
return;
513+
}
514+
515+
connection.Statistics.Ping = latency;
494516
}
495517

496518
public void OnConnectionRequest(ConnectionRequest request)

0 commit comments

Comments
 (0)