コード例 #1
0
        /// <summary>
        /// Handles the message received when the player requests a game move to be made
        /// </summary>
        /// <param name="msg">The message to handle</param>
        private void HandleGameMove(NetIncomingMessage msg)
        {
            // Reads move from the packet
            GameMove move = GameMove.DecodeFromClient(msg, myPlayers);

            // We only handle moves in game
            if (myState == ServerState.InGame)
            {
                // Check that the move came from the right client before handling
                if (move.Player == myPlayers[msg.SenderConnection])
                {
                    HandleMove(move); // Handle the move
                }
                else
                {
                    Log("Bad packet received from \"{0}\" ({1})", myPlayers[msg.SenderConnection].Name, msg.SenderEndPoint);
                }
            }
            else
            {
                // We are not in the right state, notify client
                NotifyBadState(msg.SenderConnection, "Game is not currently running");
                Log("Player \"{0}\" attempted move during non-game state", myPlayers[msg.SenderConnection].Name, msg.SenderEndPoint);
            }
        }