chore: added litenetlib logs

This commit is contained in:
2025-06-18 18:29:43 +03:00
parent 0047111244
commit 43c4eb6e4c
3 changed files with 32 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ using LiteNetLib;
using LiteNetLib.Utils;
using Syntriax.Engine.Core;
using Syntriax.Engine.Core.Debug;
namespace Syntriax.Engine.Network;
@@ -21,13 +22,17 @@ public class LiteNetLibServer : LiteNetLibCommunicatorBase, INetworkCommunicator
MaxConnectionCount = maxConnectionCount;
Port = port;
Listener.ConnectionRequestEvent += request =>
{
if (Manager.ConnectedPeersCount < maxConnectionCount)
request.AcceptIfKey(Password);
else
request.Reject();
};
Listener.ConnectionRequestEvent += OnConnectionRequest;
}
private void OnConnectionRequest(ConnectionRequest request)
{
logger?.Log(this, $"Connection request from ip {request.RemoteEndPoint}");
logger?.Log(this, $"Current connection count: {Connections.Count}");
if (Manager.ConnectedPeersCount < MaxConnectionCount)
request.AcceptIfKey(Password);
else
request.Reject();
}
public INetworkCommunicatorServer Start(int port, int maxConnectionCount, string? password = null)
@@ -39,7 +44,8 @@ public class LiteNetLibServer : LiteNetLibCommunicatorBase, INetworkCommunicator
MaxConnectionCount = maxConnectionCount;
Port = port;
Manager.Start(8888);
logger?.Log(this, $"Starting server on port '{port}' with password '{Password}' and max connection count '{maxConnectionCount}'");
logger?.Log(this, $"Server status: {(Manager.Start(port) ? "Active" : "Failed")}");
return this;
}