chore: added debug entry for logs

This commit is contained in:
2026-04-14 10:07:51 +03:00
parent 7e7b910dd3
commit 3295701664
5 changed files with 21 additions and 30 deletions

View File

@@ -9,7 +9,7 @@ using LiteNetLib.Utils;
namespace Engine.Systems.Network;
public abstract class LiteNetLibCommunicatorBase : Behaviour, IEnterUniverse, IExitUniverse, INetworkCommunicator
public abstract class LiteNetLibCommunicatorBase : Behaviour, IExitUniverse, INetworkCommunicator
{
protected readonly NetPacketProcessor netPacketProcessor = new();
protected readonly PacketCryptor cryptor = new("At4ywW9PGoWH3g==", "NmpMFTvd3pvUbA=="); // TODO implement public key exchange
@@ -19,8 +19,6 @@ public abstract class LiteNetLibCommunicatorBase : Behaviour, IEnterUniverse, IE
private readonly Dictionary<int, IConnection> localPeerIdToConnectionDictionary = [];
protected ILogger? logger = null;
public IReadOnlyDictionary<string, IConnection> Connections => _connections;
public EventBasedNetListener Listener { get; private set; } = null!;
public NetManager Manager { get; private set; } = null!;
@@ -34,16 +32,7 @@ public abstract class LiteNetLibCommunicatorBase : Behaviour, IEnterUniverse, IE
return this;
}
public virtual void EnterUniverse(IUniverse universe)
{
logger = universe.FindBehaviour<ILogger>();
}
public virtual void ExitUniverse(IUniverse universe)
{
logger = null;
Stop();
}
public virtual void ExitUniverse(IUniverse universe) => Stop();
protected virtual void OnPacketArrived<T>(T packet, NetPeer peer) where T : INetworkPacket
{
@@ -69,7 +58,7 @@ public abstract class LiteNetLibCommunicatorBase : Behaviour, IEnterUniverse, IE
netPacketProcessor.ReadAllPackets(reader, peer);
}
catch (Exception exception) { logger?.LogException(this, exception, force: true); }
catch (Exception exception) { ILogger.Shared.LogException(this, exception, force: true); }
}
protected abstract IConnection GetConnection(NetPeer peer);
@@ -80,7 +69,7 @@ public abstract class LiteNetLibCommunicatorBase : Behaviour, IEnterUniverse, IE
localPeerIdToConnectionDictionary.Add(peer.Id, connection);
_connections.Add(connection.Id, connection);
logger?.Log(this, $"Connection established with ip '{peer.Address}' and id '{connection.Id}'");
ILogger.Shared.LogInfo(this, $"Connection established with ip '{peer.Address}' and id '{connection.Id}'");
OnConnectionEstablished.Invoke(this, connection);
}
@@ -92,7 +81,7 @@ public abstract class LiteNetLibCommunicatorBase : Behaviour, IEnterUniverse, IE
localPeerIdToConnectionDictionary.Remove(peer.Id);
_connections.Remove(connection.Id);
logger?.Log(this, $"Connection abolished with ip '{peer.Address}' and id '{connection.Id}'");
ILogger.Shared.LogInfo(this, $"Connection abolished with ip '{peer.Address}' and id '{connection.Id}'");
OnConnectionAbolished.Invoke(this, connection);
}