/// <summary> Attempts to either parse the message directly as an IP, /// or finds the IP of the account whose name matches the message. </summary> /// <remarks> "@input" can be used to always find IP by matching account name. <br/> /// Warns the player if the input matches both an IP and an account name. </remarks> internal static string FindIP(Player p, string message, string cmd, out string name) { IPAddress ip; name = null; // TryParse returns "0.0.0.123" for "123", we do not want that behaviour if (IPAddress.TryParse(message, out ip) && message.Split('.').Length == 4) { string account = Server.Config.ClassicubeAccountPlus ? message + "+" : message; if (PlayerDB.FindName(account) == null) { return(message); } // Some classicube.net accounts can be parsed as valid IPs, so warn in this case. p.Message("Note: \"{0}\" is both an IP and an account name. " + "If you meant the account, use &T/{1} @{0}", message, cmd); return(message); } if (message[0] == '@') { message = message.Remove(0, 1); } Player who = PlayerInfo.FindMatches(p, message); if (who != null) { name = who.name; return(who.ip); } p.Message("Searching PlayerDB.."); string dbIP; name = PlayerDB.FindOfflineIPMatches(p, message, out dbIP); return(dbIP); }
/// <summary> Attempts to either parse the message directly as an IP, /// or finds the IP of the account whose name matches the message. </summary> /// <remarks> "@input" can be used to always find IP by matching account name. <br/> /// Warns the player if the input matches both an IP and an account name. </remarks> internal static string FindIP(Player p, string message, string cmd, out string name) { IPAddress ip; name = null; if (IPAddress.TryParse(message, out ip) && ValidIP(message)) { string account = Server.FromRawUsername(message); // TODO ip.ToString() if (PlayerDB.FindName(account) == null) { return(message); } // Some classicube.net accounts can be parsed as valid IPs, so warn in this case. p.Message("Note: \"{0}\" is both an IP and an account name. " + "If you meant the account, use &T/{1} @{0}", message, cmd); return(message); } if (message[0] == '@') { message = message.Remove(0, 1); } Player who = PlayerInfo.FindMatches(p, message); if (who != null) { name = who.name; return(who.ip); } p.Message("Searching PlayerDB.."); string dbIP; name = PlayerDB.FindOfflineIPMatches(p, message, out dbIP); return(dbIP); }