/// <summary> /// Event Handler for Application Event AddPlayer /// If a HostPassword is set on the HostInstance, it is required to add a new player to that host /// </summary> /// <param name="netMsg"></param> void OnAddPlayer(NetworkMessage netMsg) { if (IsConnectionVerified(netMsg.conn)) { MessageTypes.CustomEventType result = MessageTypes.CustomEventType.UnknownError; var msg = netMsg.ReadMessage <MessageTypes.AddPlayerMessage>(); if (string.IsNullOrEmpty(msg.playerKey)) { result = MessageTypes.CustomEventType.KeyEmpty; } else if (!Players.IsPlayerCountValid(MaxPlayerLimitForAllHosts)) { result = MessageTypes.CustomEventType.MaxPlayersExceeded; } else if (!string.IsNullOrEmpty(msg.hostName) && ConnectedHosts.Connected.ContainsKey(msg.hostName)) { // check given host first for quick check, then check all hosts if (ConnectedHosts.FindPlayer(msg.hostName, msg.playerKey) != null) { result = MessageTypes.CustomEventType.DuplicateDetected; } else if (ConnectedHosts.FindPlayer(msg.playerKey) != null) { result = MessageTypes.CustomEventType.DuplicateDetected; } else if (!ConnectedHosts.Connected[msg.hostName].VerifyPassword(msg.hostPassword)) { result = MessageTypes.CustomEventType.HostPasswordFail; } else { result = MessageTypes.CustomEventType.NoError; ConnectedHosts.AddPlayer(msg.hostName, msg.playerKey, msg.playerValue, msg.flags); } } else { result = MessageTypes.CustomEventType.HostUnknown; } if (MasterServer.ViewDebugMessages) { Debug.Log("<MasterServer> OnAddPlayer result: " + result); } var response = new MessageTypes.AddPlayerResponseMessage(); response.resultCode = (int)result; response.playerKey = msg.playerKey; netMsg.conn.Send(MessageTypes.AddPlayerResponse, response); UpdateUI(); } }
/// <summary> /// Event Handler for Application Event IsPlayerConnected /// </summary> /// <param name="netMsg"></param> void OnIsPlayerConnected(NetworkMessage netMsg) { if (IsConnectionVerified(netMsg.conn)) { var msg = netMsg.ReadMessage <MessageTypes.IsPlayerConnectedMessage>(); bool result = (ConnectedHosts.FindPlayer(msg.playerKey) != null); if (MasterServer.ViewDebugMessages) { Debug.Log("<MasterServer> OnIsPlayerConnected result: " + result); } var response = new MessageTypes.IsPlayerConnectedResponseMessage(); response.result = result; response.playerKey = msg.playerKey; netMsg.conn.Send((short)MessageTypes.IsPlayerConnectedResponse, response); } }