Exemplo n.º 1
0
        /// <summary>
        /// Disconnect the player.
        /// Exceptions:
        ///     Throws any exceptions except the "GameStateException.Code == INVALID_PLAYER_INDEX".
        /// </summary>
        /// <param name="player"></param>
        public void DisconnectPlayer(CPlayer player)
        {
            if (player.State != EPlayerState.CLOSED)
            {
                // TODO: send the dced spawn in the visible area around the player.
                // TODO: proceed removind the player of all the game state: mob grid, spawned mobs, etc.

                player.State = EPlayerState.CLOSED;

                W2Log.Write($"The player {player.Index} was disconnected from the server.", ELogType.GAME_EVENT);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Process the player requests.
        /// This method fires the <see cref="OnProcessPacket"/> event to be hooked up by plugins.
        /// </summary>
        public EPlayerRequestResult ProcessPlayerRequest(CPlayer player)
        {
            EPlayerRequestResult result = EPlayerRequestResult.NO_ERROR;

            foreach (DProcessPacket target in OnProcessPacket.GetInvocationList())
            {
                result = target(this, player);

                if (result != EPlayerRequestResult.NO_ERROR && result != EPlayerRequestResult.PACKET_NOT_HANDLED)
                {
                    W2Log.Write("eita", ELogType.CRITICAL_ERROR);
                    break;
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Insert the player in the game state. This method must be called when the player just stablishes a connection by sending the INIT_CODE to the server.
        /// </summary>
        public bool TryInsertPlayer(CPlayer player)
        {
            short i;

            for (i = 1; i < NetworkBasics.MAX_PLAYER; i++)
            {
                if (Players[i] == null || Players[i].State == EPlayerState.CLOSED)
                {
                    break;
                }
            }

            if (i >= NetworkBasics.MAX_PLAYER)
            {
                return(false);
            }

            player.Index = i;

            return(true);
        }