/// <summary> /// Attempts to find whether a Player exists within this specific Collection /// </summary> /// <param name="playerKey"></param> /// <returns></returns> public PlayerInstance FindPlayer(string playerKey) { PlayerInstance result = null; Instances.TryGetValue(playerKey, out result); return(result); }
/// <summary> /// Find Player in SPECIFIC HostInstance /// </summary> /// <param name="hostName"></param> /// <param name="playerValue"></param> /// <returns></returns> public PlayerInstance FindPlayer(string hostName, string playerKey) { PlayerInstance result = null; if (Connected.ContainsKey(hostName)) { result = Connected[hostName].ConnectedPlayers.FindPlayer(playerKey); } return(result); }
/// <summary> /// Find Player in any/all HostInstances /// It will stop checking on first match, so if somehow have duplicates, which you shouldn't, you could /// make this not stop when it finds a match or put in an optional check for all HostInstances /// </summary> /// <param name="playerKey"></param> /// <returns></returns> public PlayerInstance FindPlayer(string playerKey) { PlayerInstance result = null; foreach (var host in Connected) { if ((result = host.Value.ConnectedPlayers.FindPlayer(playerKey)) != null) { break; } } return(result); }
/// <summary> /// Attempts to find whether a Player exists within this specific Collection /// Uses email for lookup. Not efficient but works. /// </summary> /// <param name="playerValue"></param> /// <returns></returns> public PlayerInstance FindPlayerByEmail(string playerValue) { PlayerInstance result = null; foreach (var pl in Instances.Values) { if (pl.PlayerValue.Equals(playerValue)) { result = pl; break; } } return(result); }
/// <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(); } }
/// <summary> /// Remove player from Instances collection /// </summary> /// <param name="playerKey"></param> /// <returns></returns> public PlayerInstance RemovePlayer(string playerKey) { PlayerInstance result = null; if (Instances.TryGetValue(playerKey, out result)) { Instances.Remove(playerKey); Players.CurrentPlayerCount--; } if (MasterServer.ViewDebugMessages) { Debug.Log("<Players> RemovePlayer [" + playerKey + "] " + (result != null? "succes" : "failure")); } return(result); }
/// <summary> /// Update a player's values /// CANNOT change the key. Remove/add new player if this is what you want. /// </summary> /// <param name="playerKey"></param> /// <param name="playerValue"></param> /// <param name="flags"></param> /// <returns></returns> public bool UpdatePlayer(string playerKey, string playerValue, int flags) { bool result = false; PlayerInstance pl = null; foreach (var host in Connected) { if ((pl = host.Value.ConnectedPlayers.FindPlayer(playerKey)) != null) { pl.PlayerValue = playerValue; pl.Flags = flags; result = true; } } return(result); }
/// <summary> /// Add predefined Player instance to the Instances collection /// </summary> /// <param name="p"></param> /// <returns></returns> public bool AddPlayer(PlayerInstance p) { bool result = false; if (!Instances.ContainsKey(p.PlayerKey)) { Instances.Add(p.PlayerKey, p); Players.CurrentPlayerCount++; result = true; if (MasterServer.ViewDebugMessages) { Debug.Log("<Players> AddPlayer [" + p.PlayerKey + "] success"); } } else { Debug.Log("<Players> AddPlayer [" + p.PlayerKey + "] duplicate detected. Failure."); } return(result); }
/// <summary> /// Add Playter to specifc HostInstance /// </summary> /// <param name="hostName"></param> /// <param name="player"></param> /// <returns></returns> public bool AddPlayer(string hostName, PlayerInstance player) { return(Connected[hostName].AddPlayer(player)); }
/// <summary> /// Remove player from a host. It is only checking this HostInstance's Players collection for removal. /// </summary> /// <param name="p"></param> /// <returns></returns> public PlayerInstance RemovePlayer(PlayerInstance p) { return(ConnectedPlayers.RemovePlayer(p.PlayerKey)); }
/// <summary> /// Add an already created player to a host. A player can only exist in one host at a time, /// unless you modify some logic to work around it /// </summary> /// <param name="p"></param> /// <returns></returns> public bool AddPlayer(PlayerInstance p) { return(ConnectedPlayers.AddPlayer(p)); }