Пример #1
0
        /// <summary>
        /// Event Handler for Application Event RemovePlayer
        /// Unlike AddPlayer, RemovePlayer does not require a HostPassword
        /// It is assumed that by now you're trusted and you can remove the player
        /// Also, this allows us to CYA by removing a player from ALL hosts if necessary
        /// </summary>
        /// <param name="netMsg"></param>
        void OnRemovePlayer(NetworkMessage netMsg)
        {
            if (IsConnectionVerified(netMsg.conn))
            {
                var  msg    = netMsg.ReadMessage <MessageTypes.RemovePlayerMessage>();
                bool result = false;

                if (!string.IsNullOrEmpty(msg.playerKey))
                {
                    result = (ConnectedHosts.RemovePlayer(msg.playerKey) != null);
                }

                if (MasterServer.ViewDebugMessages)
                {
                    Debug.Log("<MasterServer> OnRemovePlayer result: " + result);
                }

                var response = new MessageTypes.RemovePlayerResponseMessage();
                response.result    = result;
                response.playerKey = msg.playerKey;
                netMsg.conn.Send(MessageTypes.RemovePlayerResponse, response);

                UpdateUI();
            }
        }
Пример #2
0
        /// <summary>
        /// Event Handler for Application Event PlayerChangeHost
        /// </summary>
        /// <param name="netMsg"></param>
        void OnUpdatePlayerHost(NetworkMessage netMsg)
        {
            if (IsConnectionVerified(netMsg.conn))
            {
                var msg = netMsg.ReadMessage <MessageTypes.UpdatePlayerHostMessage>();
                MessageTypes.CustomEventType result = MessageTypes.CustomEventType.UnknownError;

                if (string.IsNullOrEmpty(msg.playerKey))
                {
                    result = MessageTypes.CustomEventType.KeyEmpty;
                }
                else if (!string.IsNullOrEmpty(msg.hostName) && ConnectedHosts.Connected.ContainsKey(msg.hostName))
                {
                    PlayerInstance player = null;
                    // check given host first for quick check, then check all hosts
                    if (!ConnectedHosts.Connected[msg.hostName].VerifyPassword(msg.hostPassword))
                    {
                        result = MessageTypes.CustomEventType.HostPasswordFail;
                    }
                    else if ((player = ConnectedHosts.RemovePlayer(msg.playerKey)) != null)
                    {
                        // successful removal, now add to new Host
                        player.HostLocation  = ConnectedHosts.Connected[msg.hostName];
                        player.HostLoginTime = System.DateTime.UtcNow;
                        ConnectedHosts.AddPlayer(msg.hostName, player);
                        result = MessageTypes.CustomEventType.NoError;
                    }
                    else
                    {
                        result = MessageTypes.CustomEventType.DuplicateDetected;
                    }
                }
                else
                {
                    result = MessageTypes.CustomEventType.HostUnknown;
                }

                if (MasterServer.ViewDebugMessages)
                {
                    Debug.Log("<MasterServer> OnUpdatePlayerHost result: " + result);
                }
                var response = new MessageTypes.UpdatePlayerHostResponseMessage();
                response.resultCode = (int)result;
                response.playerKey  = msg.playerKey;
                netMsg.conn.Send((short)MessageTypes.UpdatePlayerHostResponse, response);

                UpdateUI();
            }
        }