예제 #1
0
 public void RemovePlayer(Identifier <Player> playerIdentifier)
 {
     if (!PlayerDictionary.ContainsKey(playerIdentifier))
     {
         throw new PlayerNotExistsException(playerIdentifier.GetPlayerName());
     }
     if (!PlayerDictionary.TryRemove(playerIdentifier, out _))
     {
         throw new OperationFailedException("remove player");                                                       //TODO i18n
     }
     EventManager.TriggerEvent <PlayerRemoved>(this, playerIdentifier);
 }
예제 #2
0
        /// <summary>
        /// Returns true if player has disconnected from the room
        /// </summary>
        public bool DisconnectPlayer(long id, int reason)
        {
            if (!players.TryRemove(id, out TPlayer player))
            {
                if (logger.Log(LogType.Debug))
                {
                    logger.Debug($"Failed to remove player from the array on disconnect. (id: {player.ID}, remoteEndPoint: {player.RemoteEndPoint}, reason: {reason}, roomID: {id})");
                }

                return(false);
            }

            if (player.RemoteEndPoint != null)
            {
                var response = new DisconnectUdpResponse(reason);
                Send(response, player.RemoteEndPoint);

                if (!playerDatabase.TryUpdate(player))
                {
                    if (logger.Log(LogType.Error))
                    {
                        logger.Error($"Failed to update player in the database on disconnect. (id: {player.ID}, remoteEndPoint: {player.RemoteEndPoint}, reason: {reason}, rommID: {id})");
                    }
                }

                if (logger.Log(LogType.Info))
                {
                    logger.Info($"Disconnected server player. (id: {player.ID}, remoteEndPoint: {player.RemoteEndPoint}, reason: {reason}, rommID: {id})");
                }
            }
            else
            {
                if (logger.Log(LogType.Info))
                {
                    logger.Info($"Disconnected server player. (id: {player.ID}, reason: {reason}, rommID: {id})");
                }
            }

            return(true);
        }