Пример #1
0
        internal static void Info(Player player, Command cmd)
        {
            string name = cmd.Next();

            if (name == null)
            {
                name = player.Name;
            }
            else if (!player.Can(Permission.ViewOthersInfo))
            {
                player.NoAccessMessage(Permission.ViewOthersInfo);
                return;
            }

            IPAddress ip;

            PlayerInfo[] infos;
            if (Server.IsIP(name) && IPAddress.TryParse(name, out ip))
            {
                // find players by IP
                infos = PlayerDB.FindPlayers(ip, PlayerDB.NumberOfMatchesToPrint);
            }
            else if (name.Contains("*") || name.Contains("."))
            {
                // find players by regex/wildcard
                string regexString = "^" + RegexNonNameChars.Replace(name, "").Replace("*", ".*") + "$";
                Regex  regex       = new Regex(regexString, RegexOptions.IgnoreCase | RegexOptions.Compiled);
                infos = PlayerDB.FindPlayers(regex, PlayerDB.NumberOfMatchesToPrint);
            }
            else
            {
                // find players by partial matching
                PlayerInfo tempInfo;
                if (!PlayerDB.FindPlayerInfo(name, out tempInfo))
                {
                    infos = PlayerDB.FindPlayers(name, PlayerDB.NumberOfMatchesToPrint);
                }
                else if (tempInfo == null)
                {
                    player.NoPlayerMessage(name);
                    return;
                }
                else
                {
                    infos = new[] { tempInfo };
                }
            }

            if (infos.Length == 1)
            {
                PrintPlayerInfo(player, infos[0]);
            }
            else if (infos.Length > 1)
            {
                player.ManyMatchesMessage("player", infos);
                if (infos.Length == PlayerDB.NumberOfMatchesToPrint)
                {
                    player.Message("NOTE: Only first {0} matches are shown.", PlayerDB.NumberOfMatchesToPrint);
                }
            }
            else
            {
                player.NoPlayerMessage(name);
            }
        }
Пример #2
0
        internal static void BanInfo(Player player, Command cmd)
        {
            string    name = cmd.Next();
            IPAddress address;

            if (name == null)
            {
                name = player.Name;
            }
            else if (!player.Can(Permission.ViewOthersInfo))
            {
                player.NoAccessMessage(Permission.ViewOthersInfo);
                return;
            }

            if (Server.IsIP(name) && IPAddress.TryParse(name, out address))
            {
                IPBanInfo info = IPBanList.Get(address);
                if (info != null)
                {
                    player.Message("{0} was banned by {1} on {2:dd MMM yyyy}.",
                                   info.Address,
                                   info.BannedBy,
                                   info.BanDate);
                    if (!String.IsNullOrEmpty(info.PlayerName))
                    {
                        player.Message("  IP ban was banned by association with {0}",
                                       info.PlayerName);
                    }
                    if (info.Attempts > 0)
                    {
                        player.Message("  There have been {0} attempts to log in, most recently", info.Attempts);
                        player.Message("  on {0:dd MMM yyyy} by {1}.",
                                       info.LastAttemptDate,
                                       info.LastAttemptName);
                    }
                    if (info.BanReason.Length > 0)
                    {
                        player.Message("  Ban reason: {0}", info.BanReason);
                    }
                }
                else
                {
                    player.Message("{0} is currently NOT banned.", address);
                }
            }
            else
            {
                PlayerInfo info;
                if (!PlayerDB.FindPlayerInfo(name, out info))
                {
                    player.Message("More than one player found matching \"{0}\"", name);
                }
                else if (info != null)
                {
                    if (info.Banned)
                    {
                        player.Message("Player {0}&S is &WBANNED", info.GetClassyName());
                    }
                    else
                    {
                        player.Message("Player {0}&S is NOT banned.", info.GetClassyName());
                    }
                    if (!String.IsNullOrEmpty(info.BannedBy))
                    {
                        player.Message("  Last ban by {0} on {1:dd MMM yyyy} ({2} ago).",
                                       info.BannedBy,
                                       info.BanDate,
                                       info.TimeSinceBan.ToMiniString());
                        if (info.BanReason.Length > 0)
                        {
                            player.Message("  Last ban reason: {0}", info.BanReason);
                        }
                    }
                    if (!String.IsNullOrEmpty(info.UnbannedBy))
                    {
                        player.Message("  Unbanned by {0} on {1:dd MMM yyyy} ({2} ago).",
                                       info.UnbannedBy,
                                       info.UnbanDate,
                                       info.TimeSinceUnban.ToMiniString());
                        if (info.UnbanReason.Length > 0)
                        {
                            player.Message("  Last unban reason: {0}", info.UnbanReason);
                        }
                    }
                    if (info.BanDate != DateTime.MinValue)
                    {
                        TimeSpan banDuration;
                        if (info.Banned)
                        {
                            banDuration = info.TimeSinceBan;
                        }
                        else
                        {
                            banDuration = info.UnbanDate.Subtract(info.BanDate);
                        }
                        player.Message("  Last ban duration: {0} days and {1:F1} hours.",
                                       (int)banDuration.TotalDays,
                                       banDuration.TotalHours);
                    }
                }
                else
                {
                    player.NoPlayerMessage(name);
                }
            }
        }