From 93b79b1f9f7d5cb4b4dab87e198a1b3d748b95d3 Mon Sep 17 00:00:00 2001 From: Richard Fox Date: Wed, 24 Apr 2024 01:06:17 -0700 Subject: [PATCH] chore(logging): additional trace level diagnostic logs --- LiteNetLib/ConnectionRequest.cs | 5 +++++ LiteNetLib/NetManager.Socket.cs | 9 ++++++++- LiteNetLib/NetManager.cs | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/LiteNetLib/ConnectionRequest.cs b/LiteNetLib/ConnectionRequest.cs index 4a2cdd93..ee4ba508 100644 --- a/LiteNetLib/ConnectionRequest.cs +++ b/LiteNetLib/ConnectionRequest.cs @@ -62,9 +62,14 @@ public NetPeer AcceptIfKey(string key) { NetDebug.WriteError("[AC] Invalid incoming data"); } + if (Result == ConnectionRequestResult.Accept) + { + NetDebug.Write("[AC] Accepting incoming connection."); return _listener.OnConnectionSolved(this, null, 0, 0); + } + NetDebug.Write($"[AC] Invalid key for: {RemoteEndPoint}."); Result = ConnectionRequestResult.Reject; _listener.OnConnectionSolved(this, null, 0, 0); return null; diff --git a/LiteNetLib/NetManager.Socket.cs b/LiteNetLib/NetManager.Socket.cs index 61f5024d..d936b17a 100644 --- a/LiteNetLib/NetManager.Socket.cs +++ b/LiteNetLib/NetManager.Socket.cs @@ -530,7 +530,10 @@ internal int SendRaw(byte[] message, int start, int length, IPEndPoint remoteEnd { socket = _udpSocketv6; if (socket == null) + { + NetDebug.Write($"[S] No Socket for: {remoteEndPoint}"); return 0; + } } int result; @@ -554,7 +557,7 @@ internal int SendRaw(byte[] message, int start, int length, IPEndPoint remoteEnd result = socket.SendTo(message, start, length, SocketFlags.None, remoteEndPoint); #endif } - //NetDebug.WriteForce("[S]Send packet to {0}, result: {1}", remoteEndPoint, result); + NetDebug.Write($"[S]Send packet to {remoteEndPoint}, result: {result}"); } catch (SocketException ex) { @@ -562,6 +565,7 @@ internal int SendRaw(byte[] message, int start, int length, IPEndPoint remoteEnd { case SocketError.NoBufferSpaceAvailable: case SocketError.Interrupted: + NetDebug.Write($"[S] Interrupted {ex}"); return 0; case SocketError.MessageSize: NetDebug.Write(NetLogLevel.Trace, $"[SRD] 10040, datalen: {length}"); @@ -569,6 +573,7 @@ internal int SendRaw(byte[] message, int start, int length, IPEndPoint remoteEnd case SocketError.HostUnreachable: case SocketError.NetworkUnreachable: + NetDebug.Write($"[S] Network/Host Unreachable {ex}"); if (DisconnectOnUnreachable && remoteEndPoint is NetPeer peer) { DisconnectPeerForce( @@ -584,6 +589,7 @@ internal int SendRaw(byte[] message, int start, int length, IPEndPoint remoteEnd return -1; case SocketError.Shutdown: + NetDebug.Write($"[S] Shutdown {ex}"); CreateEvent(NetEvent.EType.Error, remoteEndPoint: remoteEndPoint, errorCode: ex.SocketErrorCode); return -1; @@ -603,6 +609,7 @@ internal int SendRaw(byte[] message, int start, int length, IPEndPoint remoteEnd PoolRecycle(expandedPacket); } + // TODO: Why are we hiding failure? if (result <= 0) return 0; diff --git a/LiteNetLib/NetManager.cs b/LiteNetLib/NetManager.cs index 737f616f..b5a3725b 100644 --- a/LiteNetLib/NetManager.cs +++ b/LiteNetLib/NetManager.cs @@ -695,6 +695,7 @@ internal NetPeer OnConnectionSolved(ConnectionRequest request, byte[] rejectData if (TryGetPeer(request.RemoteEndPoint, out netPeer)) { //already have peer + NetDebug.Write($"[NM] Duplicate peer for {request.RemoteEndPoint}, ignoring."); } else if (request.Result == ConnectionRequestResult.Reject) {