public void Disconnect() { MDLog.Info(LOG_CAT, "Disconnected from server"); IsSessionStarted = false; foreach (int PeerId in Players.Keys) { MDPlayerInfo Player = Players[PeerId]; OnPlayerLeftEvent(PeerId); Player.RemoveAndFree(); } NetworkedMultiplayerENet peer = GetPeer(); if (peer != null) { peer.CloseConnection(); SetNetworkPeer(null); } StopUPNP(); Players.Clear(); ClearNetworkedNodes(); OnSessionEndedEvent(); SceneBuffer.Clear(); }
// Removes the MDPlayerInfo belonging to the PeerId private void RemovePlayerObject(int PeerId) { if (Players.ContainsKey(PeerId)) { MDPlayerInfo Player = Players[PeerId]; PreparePlayerInfoForRemoval(Player); Player.RemoveAndFree(); Players.Remove(PeerId); } }