Skip to content

Commit

Permalink
Merge pull request #3 from Yellow-Dog-Man/prime/logging
Browse files Browse the repository at this point in the history
chore(logging): additional trace level diagnostic logs
  • Loading branch information
ProbablePrime authored Apr 24, 2024
2 parents fb8c269 + 93b79b1 commit faab50e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions LiteNetLib/ConnectionRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion LiteNetLib/NetManager.Socket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -554,21 +557,23 @@ 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)
{
switch (ex.SocketErrorCode)
{
case SocketError.NoBufferSpaceAvailable:
case SocketError.Interrupted:
NetDebug.Write($"[S] Interrupted {ex}");
return 0;
case SocketError.MessageSize:
NetDebug.Write(NetLogLevel.Trace, $"[SRD] 10040, datalen: {length}");
return 0;

case SocketError.HostUnreachable:
case SocketError.NetworkUnreachable:
NetDebug.Write($"[S] Network/Host Unreachable {ex}");
if (DisconnectOnUnreachable && remoteEndPoint is NetPeer peer)
{
DisconnectPeerForce(
Expand All @@ -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;

Expand All @@ -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;

Expand Down
1 change: 1 addition & 0 deletions LiteNetLib/NetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit faab50e

Please sign in to comment.