From a868131e63a2c8f06b7d9f48daa2650afff98924 Mon Sep 17 00:00:00 2001 From: Richard Fox Date: Sat, 4 May 2024 02:59:05 -0700 Subject: [PATCH] feat(logging): add some more logging around recieving and NAT This is at LogLevel.Trace so won't show up unless people opt in. --- LiteNetLib/NetManager.cs | 3 +++ LiteNetLib/NetPeer.cs | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/LiteNetLib/NetManager.cs b/LiteNetLib/NetManager.cs index b5a3725b..6c8bf623 100644 --- a/LiteNetLib/NetManager.cs +++ b/LiteNetLib/NetManager.cs @@ -781,8 +781,10 @@ private void ProcessConnectRequest( private void OnMessageReceived(NetPacket packet, IPEndPoint remoteEndPoint) { + NetDebug.Write($"[NM] Recieved Packet, from:{remoteEndPoint}, it is: {packet.Size} long. Property: {packet.Property}"); if (packet.Size == 0) { + NetDebug.Write($"[NM] Discarding packet with size 0"); PoolRecycle(packet); return; } @@ -890,6 +892,7 @@ private void DebugMessageReceived(NetPacket packet, IPEndPoint remoteEndPoint) CreateEvent(NetEvent.EType.ReceiveUnconnected, remoteEndPoint: remoteEndPoint, readerSource: packet); return; case PacketProperty.NatMessage: + NetDebug.Write($"[NM] Processing NAT Message from {remoteEndPoint}"); if (NatPunchEnabled) NatPunchModule.ProcessMessage(remoteEndPoint, packet); return; diff --git a/LiteNetLib/NetPeer.cs b/LiteNetLib/NetPeer.cs index 251c6a96..f45dee09 100644 --- a/LiteNetLib/NetPeer.cs +++ b/LiteNetLib/NetPeer.cs @@ -400,9 +400,10 @@ internal NetPeer(NetManager netManager, IPEndPoint remoteEndPoint, int id, byte _connectRequestPacket.ConnectionNumber = connectNum; //Send request - NetManager.SendRaw(_connectRequestPacket, this); + var success = NetManager.SendRaw(_connectRequestPacket, this); + - NetDebug.Write(NetLogLevel.Trace, $"[CC] ConnectId: {_connectTime}, ConnectNum: {connectNum}, Endpoint: {remoteEndPoint}"); + NetDebug.Write(NetLogLevel.Trace, $"[CC] ConnectId: {_connectTime}, ConnectNum: {connectNum}, Endpoint: {remoteEndPoint}, ConnectRequestSuccess: {success}"); } //"Accept" incoming constructor @@ -1347,9 +1348,9 @@ internal void Update(int deltaTime) return; } - NetDebug.Write($"[Update] Connected ID: {_connectTime} Sending another connection request, this is attempt {_connectAttempts}."); //else send connect again - NetManager.SendRaw(_connectRequestPacket, this); + var success = NetManager.SendRaw(_connectRequestPacket, this); + NetDebug.Write($"[Update] Connected ID: {_connectTime} Sending another connection request, this is attempt {_connectAttempts}. Send result: {success}"); } return;