fix: local id tracking added for issues caused by commit 08f52e9b72a09eed7db46fa9a97b7fee862b19fc
This commit is contained in:
parent
e9ca71b87e
commit
a76905f31e
@ -18,6 +18,8 @@ public abstract class LiteNetLibCommunicatorBase : Behaviour, INetworkCommunicat
|
||||
private readonly Dictionary<Type, Event<IConnection, object>> listeners = [];
|
||||
private readonly Dictionary<string, IConnection> _connections = [];
|
||||
|
||||
private readonly Dictionary<int, IConnection> localPeerIdToConnectionDictionary = [];
|
||||
|
||||
protected ILogger? logger = null;
|
||||
|
||||
public IReadOnlyDictionary<string, IConnection> Connections => _connections;
|
||||
@ -51,7 +53,7 @@ public abstract class LiteNetLibCommunicatorBase : Behaviour, INetworkCommunicat
|
||||
if (!listeners.TryGetValue(typeof(T), out Event<IConnection, object>? @event))
|
||||
return;
|
||||
|
||||
@event.Invoke(Connections[peer.Id.ToString()], packet);
|
||||
@event.Invoke(localPeerIdToConnectionDictionary[peer.Id], packet);
|
||||
}
|
||||
|
||||
private void NetworkReceiveEvent(NetPeer peer, NetPacketReader reader, byte channel, DeliveryMethod deliveryMethod)
|
||||
@ -64,7 +66,10 @@ public abstract class LiteNetLibCommunicatorBase : Behaviour, INetworkCommunicat
|
||||
private void ConnectionEstablished(NetPeer peer)
|
||||
{
|
||||
IConnection connection = GetConnection(peer);
|
||||
|
||||
localPeerIdToConnectionDictionary.Add(peer.Id, connection);
|
||||
_connections.Add(connection.Id, connection);
|
||||
|
||||
logger?.Log(this, $"Connection established with ip '{peer.Address}' and id '{connection.Id}'");
|
||||
OnConnectionEstablished.Invoke(this, connection);
|
||||
}
|
||||
@ -72,10 +77,12 @@ public abstract class LiteNetLibCommunicatorBase : Behaviour, INetworkCommunicat
|
||||
|
||||
private void ConnectionAbolished(NetPeer peer, DisconnectInfo disconnectInfo)
|
||||
{
|
||||
if (!_connections.TryGetValue(peer.Id.ToString(), out var connection))
|
||||
if (!localPeerIdToConnectionDictionary.TryGetValue(peer.Id, out var connection))
|
||||
return;
|
||||
|
||||
localPeerIdToConnectionDictionary.Remove(peer.Id);
|
||||
_connections.Remove(connection.Id);
|
||||
|
||||
logger?.Log(this, $"Connection abolished with ip '{peer.Address}' and id '{connection.Id}'");
|
||||
OnConnectionAbolished.Invoke(this, connection);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user