private void OnDisconnected(int socketId, int connectionId) { if (NetUsers.ContainsKey(connectionId) == false) { Debug.LogError($"@OnDisconnected -> Try to remove userId[{connectionId}] but it doesn't exist"); return; } // Remove user and user's instance NetUsers.Remove(connectionId); NetPlayer pInstance = PlayerInstances[connectionId]; PlayerInstances.Remove(connectionId); Destroy(pInstance.gameObject); // Notify all users about thje disconnection ByteStream stream = new ByteStream(); stream.Encode ( (byte)NetMessageType.USER_DISCONNECT, connectionId ); BroadcastNetMessage(ReliableChannel, stream.ToArray(), connectionId); Debug.Log($"receiver.Disconnect -> Socket[{socketId}], userId[{connectionId}]"); }
public override void Client_ReceiveMessage(ByteStream data, LLClient client) { try { int conId = data.PopInt32(); if (client.NetUsers.ContainsKey(conId) == false) { Debug.LogError("@Client -> @UserDisconnected: Trying to remove an Id that didn't exist"); return; } client.NetUsers.Remove(conId); NetPlayer pInstance = client.PlayerInstances[conId]; client.PlayerInstances.Remove(conId); Destroy(pInstance.gameObject); } catch (Exception e) { Debug.LogError($"@Client -> @UserDisconnected: [{e.Message}]"); } }