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<Type, Event<IConnection, object>> listeners = [];
|
||||||
private readonly Dictionary<string, IConnection> _connections = [];
|
private readonly Dictionary<string, IConnection> _connections = [];
|
||||||
|
|
||||||
|
private readonly Dictionary<int, IConnection> localPeerIdToConnectionDictionary = [];
|
||||||
|
|
||||||
protected ILogger? logger = null;
|
protected ILogger? logger = null;
|
||||||
|
|
||||||
public IReadOnlyDictionary<string, IConnection> Connections => _connections;
|
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))
|
if (!listeners.TryGetValue(typeof(T), out Event<IConnection, object>? @event))
|
||||||
return;
|
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)
|
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)
|
private void ConnectionEstablished(NetPeer peer)
|
||||||
{
|
{
|
||||||
IConnection connection = GetConnection(peer);
|
IConnection connection = GetConnection(peer);
|
||||||
|
|
||||||
|
localPeerIdToConnectionDictionary.Add(peer.Id, connection);
|
||||||
_connections.Add(connection.Id, connection);
|
_connections.Add(connection.Id, connection);
|
||||||
|
|
||||||
logger?.Log(this, $"Connection established with ip '{peer.Address}' and id '{connection.Id}'");
|
logger?.Log(this, $"Connection established with ip '{peer.Address}' and id '{connection.Id}'");
|
||||||
OnConnectionEstablished.Invoke(this, connection);
|
OnConnectionEstablished.Invoke(this, connection);
|
||||||
}
|
}
|
||||||
@ -72,10 +77,12 @@ public abstract class LiteNetLibCommunicatorBase : Behaviour, INetworkCommunicat
|
|||||||
|
|
||||||
private void ConnectionAbolished(NetPeer peer, DisconnectInfo disconnectInfo)
|
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;
|
return;
|
||||||
|
|
||||||
|
localPeerIdToConnectionDictionary.Remove(peer.Id);
|
||||||
_connections.Remove(connection.Id);
|
_connections.Remove(connection.Id);
|
||||||
|
|
||||||
logger?.Log(this, $"Connection abolished with ip '{peer.Address}' and id '{connection.Id}'");
|
logger?.Log(this, $"Connection abolished with ip '{peer.Address}' and id '{connection.Id}'");
|
||||||
OnConnectionAbolished.Invoke(this, connection);
|
OnConnectionAbolished.Invoke(this, connection);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user