Get() private method

private Get ( [ address ) : IPBanInfo
address [
return IPBanInfo
Beispiel #1
0
 static bool PlayerIsInactive([NotNull] IDictionary <IPAddress, List <PlayerInfo> > playersByIP, [NotNull] PlayerInfo player, bool checkIP)
 {
     if (playersByIP == null)
     {
         throw new ArgumentNullException("playersByIP");
     }
     if (player == null)
     {
         throw new ArgumentNullException("player");
     }
     if (player.BanStatus != BanStatus.NotBanned || player.UnbanDate != DateTime.MinValue ||
         player.IsFrozen || player.IsMuted || player.TimesKicked != 0 ||
         player.Rank != RankManager.DefaultRank || player.PreviousRank != null)
     {
         return(false);
     }
     if (player.TotalTime.TotalMinutes > 30 || player.TimeSinceLastSeen.TotalDays < 30)
     {
         return(false);
     }
     if (IPBanList.Get(player.LastIP) != null)
     {
         return(false);
     }
     if (checkIP)
     {
         return(playersByIP[player.LastIP].All(other => (other == player) || PlayerIsInactive(playersByIP, other, false)));
     }
     return(true);
 }
Beispiel #2
0
 static bool PlayerIsInactive(PlayerInfo player, bool checkIP)
 {
     if (player == null)
     {
         throw new ArgumentNullException("player");
     }
     if (player.Banned || !String.IsNullOrEmpty(player.UnbannedBy) || player.IsFrozen || player.IsMuted || player.TimesKicked != 0 || !String.IsNullOrEmpty(player.RankChangedBy))
     {
         return(false);
     }
     if (player.TotalTime.TotalMinutes > 30 || player.TimeSinceLastSeen.TotalDays < 30)
     {
         return(false);
     }
     if (IPBanList.Get(player.LastIP) != null)
     {
         return(false);
     }
     if (checkIP)
     {
         return(playersByIP[player.LastIP].All(other => (other == player) || PlayerIsInactive(other, false)));
     }
     return(true);
 }
Beispiel #3
0
 internal static void RecoverIPBans()
 {
     PlayerInfo[] playerInfoListCache = PlayerInfoList;
     for (int i = 0; i < playerInfoListCache.Length; i++)
     {
         PlayerInfo p = playerInfoListCache[i];
         if (p.Banned && p.BanReason.EndsWith("~BanAll", StringComparison.OrdinalIgnoreCase) && IPBanList.Get(p.LastIP) == null)
         {
             IPBanList.Add(new IPBanInfo(p.LastIP, p.Name, p.BannedBy, p.BanReason));
             Logger.Log("PlayerDB.RecoverIPBans: Banned {0} by association with {1}. Banned by {2}. Reason: {3}", LogType.SystemActivity,
                        p.LastIP, p.Name, p.BannedBy, p.BanReason);
         }
     }
 }
Beispiel #4
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);
                }
            }
        }
Beispiel #5
0
        public static void PrintPlayerInfo(Player player, PlayerInfo info)
        {
            Player target = Server.FindPlayerExact(info.Name);

            // hide online status when hidden
            if (target != null && !player.CanSee(target))
            {
                target = null;
            }

            if (info.LastIP.Equals(IPAddress.None))
            {
                player.Message("About {0}&S: Never seen before.", info.GetClassyName());
            }
            else
            {
                if (target != null)
                {
                    if (target.IsHidden)
                    {
                        if (player.Can(Permission.ViewPlayerIPs))
                        {
                            player.Message("About {0}&S: HIDDEN. Online from {1}",
                                           info.GetClassyName(),
                                           info.LastIP);
                        }
                        else
                        {
                            player.Message("About {0}&S: HIDDEN.",
                                           info.GetClassyName());
                        }
                    }
                    else
                    {
                        if (player.Can(Permission.ViewPlayerIPs))
                        {
                            player.Message("About {0}&S: Online now from {1}",
                                           info.GetClassyName(),
                                           info.LastIP);
                        }
                        else
                        {
                            player.Message("About {0}&S: Online now.",
                                           info.GetClassyName());
                        }
                    }
                }
                else
                {
                    if (player.Can(Permission.ViewPlayerIPs))
                    {
                        player.Message("About {0}&S: Last seen {1} ago from {2}",
                                       info.GetClassyName(),
                                       info.TimeSinceLastSeen.ToMiniString(),
                                       info.LastIP);
                    }
                    else
                    {
                        player.Message("About {0}&S: Last seen {1} ago.",
                                       info.GetClassyName(),
                                       info.TimeSinceLastSeen.ToMiniString());
                    }
                }
                // Show login information
                player.Message("  Logged in {0} time(s) since {1:d MMM yyyy}.",
                               info.TimesVisited,
                               info.FirstLoginDate);
            }


            // Show ban information
            IPBanInfo ipBan = IPBanList.Get(info.LastIP);

            if (ipBan != null && info.Banned)
            {
                player.Message("  Both name and IP are {0}BANNED&S. See &H/baninfo", Color.Red);
            }
            else if (ipBan != null)
            {
                player.Message("  IP is {0}BANNED&S (but nick isn't). See &H/baninfo", Color.Red);
            }
            else if (info.Banned)
            {
                player.Message("  Nick is {0}BANNED&S (but IP isn't). See &H/baninfo", Color.Red);
            }


            if (info.LastIP.ToString() != IPAddress.None.ToString())
            {
                // Show alts
                List <PlayerInfo> altNames = new List <PlayerInfo>();
                int bannedAltCount         = 0;
                foreach (PlayerInfo playerFromSameIP in PlayerDB.FindPlayers(info.LastIP, 25))
                {
                    if (playerFromSameIP != info)
                    {
                        altNames.Add(playerFromSameIP);
                        if (playerFromSameIP.Banned)
                        {
                            bannedAltCount++;
                        }
                    }
                }

                if (altNames.Count > 0)
                {
                    if (bannedAltCount > 0)
                    {
                        player.Message("  {0} accounts ({1} banned) share this IP: {2}",
                                       altNames.Count,
                                       bannedAltCount,
                                       altNames.ToArray().JoinToClassyString());
                    }
                    else
                    {
                        player.Message("  {0} accounts share this IP: {1}",
                                       altNames.Count,
                                       altNames.ToArray().JoinToClassyString());
                    }
                }
            }


            // Stats
            if (info.BlocksDrawn > 500000000)
            {
                player.Message("  Built {0} and deleted {1} blocks, drew {2}M blocks, wrote {3} messages.",
                               info.BlocksBuilt,
                               info.BlocksDeleted,
                               info.BlocksDrawn / 1000000,
                               info.LinesWritten);
            }
            else if (info.BlocksDrawn > 500000)
            {
                player.Message("  Built {0} and deleted {1} blocks, drew {2}K blocks, wrote {3} messages.",
                               info.BlocksBuilt,
                               info.BlocksDeleted,
                               info.BlocksDrawn / 1000,
                               info.LinesWritten);
            }
            else if (info.BlocksDrawn > 0)
            {
                player.Message("  Built {0} and deleted {1} blocks, drew {2} blocks, wrote {3} messages.",
                               info.BlocksBuilt,
                               info.BlocksDeleted,
                               info.BlocksDrawn,
                               info.LinesWritten);
            }
            else
            {
                player.Message("  Built {0} and deleted {1} blocks, wrote {2} messages.",
                               info.BlocksBuilt,
                               info.BlocksDeleted,
                               info.LinesWritten);
            }


            // More stats
            if (info.TimesBannedOthers > 0 || info.TimesKickedOthers > 0)
            {
                player.Message("  Kicked {0} and banned {1} players.", info.TimesKickedOthers, info.TimesBannedOthers);
            }

            if (info.TimesKicked > 0)
            {
                if (info.LastKickDate != DateTime.MinValue)
                {
                    player.Message("  Got kicked {0} times. Last kick {1} ago by {2}",
                                   info.TimesKicked,
                                   info.TimeSinceLastKick.ToMiniString(),
                                   info.LastKickBy);
                    if (info.LastKickReason.Length > 0)
                    {
                        player.Message("  Last kick reason: {0}", info.LastKickReason);
                    }
                }
                else
                {
                    player.Message("  Got kicked {0} times", info.TimesKicked);
                }
            }


            // Promotion/demotion
            if (!String.IsNullOrEmpty(info.RankChangedBy))
            {
                if (info.PreviousRank == null)
                {
                    player.Message("  Promoted to {0}&S by {1} {2} ago.",
                                   info.Rank.GetClassyName(),
                                   info.RankChangedBy,
                                   info.TimeSinceRankChange.ToMiniString());
                }
                else if (info.PreviousRank < info.Rank)
                {
                    player.Message("  Promoted from {0}&S to {1}&S by {2} {3} ago.",
                                   info.PreviousRank.GetClassyName(),
                                   info.Rank.GetClassyName(),
                                   info.RankChangedBy,
                                   info.TimeSinceRankChange.ToMiniString());
                    if (!string.IsNullOrEmpty(info.RankChangeReason))
                    {
                        player.Message("  Promotion reason: {0}", info.RankChangeReason);
                    }
                }
                else
                {
                    player.Message("  Demoted from {0}&S to {1}&S by {2} {3} ago.",
                                   info.PreviousRank.GetClassyName(),
                                   info.Rank.GetClassyName(),
                                   info.RankChangedBy,
                                   info.TimeSinceRankChange.ToMiniString());
                    if (info.RankChangeReason.Length > 0)
                    {
                        player.Message("  Demotion reason: {0}", info.RankChangeReason);
                    }
                }
            }
            else
            {
                player.Message("  Rank is {0}&S (default).",
                               info.Rank.GetClassyName());
            }

            if (info.LastIP.ToString() != IPAddress.None.ToString())
            {
                // Time on the server
                TimeSpan totalTime = info.TotalTime;
                if (target != null)
                {
                    totalTime = totalTime.Add(info.TimeSinceLastLogin);
                }
                player.Message("  Spent a total of {0:F1} hours ({1:F1} minutes) here.",
                               totalTime.TotalHours,
                               totalTime.TotalMinutes);
            }
        }