Beispiel #1
0
        static string DefaultRealmOwner(string map)
        {
            bool plus = Server.Config.ClassicubeAccountPlus;

            // Early out when accounts have + and map doesn't.
            if (plus && map.IndexOf('+') == -1)
            {
                return(null);
            }

            string name = null, origMap = map;

            while (map.Length > 0 && Char.IsNumber(map[map.Length - 1]))
            {
                // If the server does not have account with +, we have to account for the
                // that say Player123's second level is Player1232, and the realm owner is Player123
                name = plus ? null : PlayerDB.FindName(map);
                if (name != null)
                {
                    break;
                }
                map = map.Substring(0, map.Length - 1);
            }

            if (name == null)
            {
                name = PlayerDB.FindName(map);
            }
            if (name != null && !LevelInfo.IsRealmOwner(name, origMap))
            {
                return(null);
            }
            return(name);
        }
Beispiel #2
0
        static string GetName(Player p, string name)
        {
            if (!Formatter.ValidName(p, name, "player"))
            {
                return(null);
            }
            if (PlayerInfo.FindExact(name) != null)
            {
                p.Message("\"{0}\" must be offline to use &T/InfoSwap", name); return(null);
            }

            string match = PlayerDB.FindName(name);

            if (match == null)
            {
                p.Message("\"{0}\" was not found in the database.", name); return(null);
            }
            return(match);
        }
Beispiel #3
0
        /// <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);
        }
Beispiel #4
0
        /// <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);
        }