Esempio n. 1
0
        /// <summary>
        /// Handles all logic when player disconnects
        /// </summary>
        /// <param name="netId"></param>
        public static void DisconnectPlayer(ShortGuid netId)
        {
            bool removed = false;

            lock (Players)
            {
                if (Players.ContainsKey(netId))
                {
                    removed = true;
                    var player = Players[netId];
                    //player.ClearAllInvites();
                    LobbyServer.LeaveLobby(player);
                    if (player.IsInGame && player.PlayerState == PlayerState.IN_GAME)
                    {
                        var gamePlayer = player.Game.GetPlayer(player);
                        GameServer.EndGame(gamePlayer.Opponent, gamePlayer, GameResult.PLAYER_DISCONNECTED);
                    }
                    try
                    {
                        Players[netId].Connection.CloseConnection(false);
                    }
                    catch { }
                    Players.Remove(netId);
                }
            }
            if (removed)
            {
                LobbyServer.BroadcastPlayerCount();
            }
        }