Skip to content

Commit

Permalink
feat(logging): add some more logging around recieving and NAT
Browse files Browse the repository at this point in the history
This is at LogLevel.Trace so won't show up unless people opt in.
  • Loading branch information
ProbablePrime committed May 4, 2024
1 parent 93b79b1 commit a868131
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions LiteNetLib/NetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions LiteNetLib/NetPeer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit a868131

Please sign in to comment.