Example #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);
 }
Example #2
0
        public void cmdIpUnBan(string message)
        {
            IPAddress ban = null;

            if (message == "" || !IPAddress.TryParse(message, out ban))
            {
                sendToUser("Syntax: ipunban <ip address>", true, false, false);
            }
            else
            {
                IPBanList = loadIPBans();
                for (int i = IPBanList.Count - 1; i >= 0; i--)
                {
                    if (IPBanList[i].Equals(ban))
                    {
                        IPBanList.RemoveAt(i);
                        sendToUser("IP Address " + ban.ToString() + " removed from ban list", true, false, false);
                        saveIPBans();
                        return;
                    }
                }
                sendToUser("IP Address " + ban.ToString() + " not in ban list", true, false, false);
            }
        }
Example #3
0
        public void cmdIpBan(string message)
        {
            IPAddress ban = null;

            if (message == "" || !IPAddress.TryParse(message, out ban))
            {
                sendToUser("Syntax: ipban <ip address>", true, false, false);
            }
            else
            {
                IPBanList = loadIPBans();
                foreach (IPAddress i in IPBanList)
                {
                    if (i == ban)
                    {
                        sendToUser("IP Address " + ban.ToString() + " already in ban list", true, false, false);
                        return;
                    }
                }
                IPBanList.Add(ban);
                saveIPBans();
                sendToUser("IP Address " + ban.ToString() + " added to ban list", true, false, false);
            }
        }
Example #4
0
 public bool IpIsBanned(IPAddress check)
 {
     IPBanList = loadIPBans();
     return(IPBanList.IndexOf(check) > -1);
 }
Example #5
0
        private void SetPlayerInfoText(PlayerInfo info)
        {
            textBox1.Text    = "";
            PlayerLabel.Text = player.Name;
            SetTextRankColor(Color.GetName(player.Rank.Color));
            if (info.LastIP.Equals(System.Net.IPAddress.None))
            {
                textBox1.Text += String.Format("About {0}&S: Never seen before.\r\n", info.ClassyName);
            }
            else
            {
                if (info != null)
                {
                    TimeSpan idle = info.PlayerObject.IdleTime;
                    if (info.IsHidden)
                    {
                        if (idle.TotalMinutes > 2)
                        {
                            if (player.Can(Permission.ViewPlayerIPs))
                            {
                                textBox1.Text += String.Format("About {0}&S: HIDDEN from {1} (idle {2})\r\n",
                                                               info.ClassyName,
                                                               info.LastIP,
                                                               idle.ToMiniString());
                            }
                            else
                            {
                                textBox1.Text += String.Format("About {0}&S: HIDDEN (idle {1})\r\n",
                                                               info.ClassyName,
                                                               idle.ToMiniString());
                            }
                        }
                        else
                        {
                            if (player.Can(Permission.ViewPlayerIPs))
                            {
                                textBox1.Text += String.Format("About {0}&S: HIDDEN. Online from {1}\r\n",
                                                               info.ClassyName,
                                                               info.LastIP);
                            }
                            else
                            {
                                textBox1.Text += String.Format("About {0}&S: HIDDEN.\r\n",
                                                               info.ClassyName);
                            }
                        }
                    }
                    else
                    {
                        if (idle.TotalMinutes > 1)
                        {
                            if (player.Can(Permission.ViewPlayerIPs))
                            {
                                textBox1.Text += String.Format("About {0}&S: Online now from {1} (idle {2})\r\n",
                                                               info.ClassyName,
                                                               info.LastIP,
                                                               idle.ToMiniString());
                            }
                            else
                            {
                                textBox1.Text += String.Format("About {0}&S: Online now (idle {1})\r\n",
                                                               info.ClassyName,
                                                               idle.ToMiniString());
                            }
                        }
                        else
                        {
                            if (player.Can(Permission.ViewPlayerIPs))
                            {
                                textBox1.Text += String.Format("About {0}&S: Online now from {1}\r\n",
                                                               info.ClassyName,
                                                               info.LastIP);
                            }
                            else
                            {
                                textBox1.Text += String.Format("About {0}&S: Online now.\r\n",
                                                               info.ClassyName);
                            }
                        }
                    }
                }
                else
                {
                    if (player.Can(Permission.ViewPlayerIPs))
                    {
                        if (info.LeaveReason != LeaveReason.Unknown)
                        {
                            textBox1.Text += String.Format("About {0}&S: Last seen {1} ago from {2} ({3}).\r\n",
                                                           info.ClassyName,
                                                           info.TimeSinceLastSeen.ToMiniString(),
                                                           info.LastIP,
                                                           info.LeaveReason);
                        }
                        else
                        {
                            textBox1.Text += String.Format("About {0}&S: Last seen {1} ago from {2}.\r\n",
                                                           info.ClassyName,
                                                           info.TimeSinceLastSeen.ToMiniString(),
                                                           info.LastIP);
                        }
                    }
                    else
                    {
                        if (info.LeaveReason != LeaveReason.Unknown)
                        {
                            textBox1.Text += String.Format("About {0}&S: Last seen {1} ago ({2}).\r\n",
                                                           info.ClassyName,
                                                           info.TimeSinceLastSeen.ToMiniString(),
                                                           info.LeaveReason);
                        }
                        else
                        {
                            textBox1.Text += String.Format("About {0}&S: Last seen {1} ago.\r\n",
                                                           info.ClassyName,
                                                           info.TimeSinceLastSeen.ToMiniString());
                        }
                    }
                }
                // Show login information
                textBox1.Text += String.Format("  Logged in {0} time(s) since {1:d MMM yyyy}.\r\n",
                                               info.TimesVisited,
                                               info.FirstLoginDate);
            }

            if (info.IsFrozen)
            {
                textBox1.Text += String.Format("  Frozen {0} ago by {1}\r\n",
                                               info.TimeSinceFrozen.ToMiniString(),
                                               info.FrozenByClassy);
            }

            if (info.IsMuted)
            {
                textBox1.Text += String.Format("  Muted for {0} by {1}\r\n",
                                               info.TimeMutedLeft.ToMiniString(),
                                               info.MutedByClassy);
                float blocks = ((info.BlocksBuilt + info.BlocksDrawn) - info.BlocksDeleted);
                if (blocks < 0)
                {
                    textBox1.Text += String.Format("  &CWARNING! {0}&S has deleted more than built!\r\n", info.ClassyName);  //<---- GlennMR on Au70 Galaxy
                }
            }

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

            switch (info.BanStatus)
            {
            case BanStatus.Banned:
                if (ipBan != null)
                {
                    textBox1.Text += String.Format("  Account and IP are &CBANNED&S. See &H/BanInfo\r\n");
                }
                else
                {
                    textBox1.Text += String.Format("  Account is &CBANNED&S. See &H/BanInfo\r\n");
                }
                break;

            case BanStatus.IPBanExempt:
                if (ipBan != null)
                {
                    textBox1.Text += String.Format("  IP is &CBANNED&S, but account is exempt. See &H/BanInfo\r\n");
                }
                else
                {
                    textBox1.Text += String.Format("  IP is not banned, and account is exempt. See &H/BanInfo\r\n");
                }
                break;

            case BanStatus.NotBanned:
                if (ipBan != null)
                {
                    textBox1.Text += String.Format("  IP is &CBANNED&S. See &H/BanInfo\r\n");
                }
                break;
            }

            if (!info.LastIP.Equals(System.Net.IPAddress.None))
            {
                // Show alts
                List <PlayerInfo> altNames = new List <PlayerInfo>();
                int bannedAltCount         = 0;
                foreach (PlayerInfo playerFromSameIP in PlayerDB.FindPlayers(info.LastIP))
                {
                    if (playerFromSameIP == info)
                    {
                        continue;
                    }
                    altNames.Add(playerFromSameIP);
                    if (playerFromSameIP.IsBanned)
                    {
                        bannedAltCount++;
                    }
                }

                // Stats
                if (info.BlocksDrawn > 500000000)
                {
                    textBox1.Text += String.Format("  Built {0} and deleted {1} blocks, drew {2}M blocks, wrote {3} messages.\r\n",
                                                   info.BlocksBuilt,
                                                   info.BlocksDeleted,
                                                   info.BlocksDrawn / 1000000,
                                                   info.MessagesWritten);
                }
                else if (info.BlocksDrawn > 500000)
                {
                    textBox1.Text += String.Format("  Built {0} and deleted {1} blocks, drew {2}K blocks, wrote {3} messages.\r\n",
                                                   info.BlocksBuilt,
                                                   info.BlocksDeleted,
                                                   info.BlocksDrawn / 1000,
                                                   info.MessagesWritten);
                }
                else if (info.BlocksDrawn > 0)
                {
                    textBox1.Text += String.Format("  Built {0} and deleted {1} blocks, drew {2} blocks, wrote {3} messages.\r\n",
                                                   info.BlocksBuilt,
                                                   info.BlocksDeleted,
                                                   info.BlocksDrawn,
                                                   info.MessagesWritten);
                }
                else
                {
                    textBox1.Text += String.Format("  Built {0} and deleted {1} blocks, wrote {2} messages.\r\n",
                                                   info.BlocksBuilt,
                                                   info.BlocksDeleted,
                                                   info.MessagesWritten);
                }

                // More stats
                if (info.TimesBannedOthers > 0 || info.TimesKickedOthers > 0 || info.PromoCount > 0)
                {
                    textBox1.Text += String.Format("  Kicked {0}, Promoted {1} and banned {2} players.\r\n", info.TimesKickedOthers, info.PromoCount, info.TimesBannedOthers);
                }

                if (info.TimesKicked > 0)
                {
                    if (info.LastKickDate != DateTime.MinValue)
                    {
                        textBox1.Text += String.Format("  Got kicked {0} times. Last kick {1} ago by {2}\r\n",
                                                       info.TimesKicked,
                                                       info.TimeSinceLastKick.ToMiniString(),
                                                       info.LastKickByClassy);
                    }
                    else
                    {
                        textBox1.Text += String.Format("  Got kicked {0} times.\r\n", info.TimesKicked);
                    }
                    if (info.LastKickReason != null)
                    {
                        textBox1.Text += String.Format("  Kick reason: {0}\r\n", info.LastKickReason);
                    }
                }

                // Promotion/demotion
                if (info.PreviousRank == null)
                {
                    if (info.RankChangedBy == null)
                    {
                        textBox1.Text += String.Format("  Rank is {0}&S (default).\r\n",
                                                       info.Rank.ClassyName);
                    }
                    else
                    {
                        textBox1.Text += String.Format("  Promoted to {0}&S by {1}&S {2} ago.\r\n",
                                                       info.Rank.ClassyName,
                                                       info.RankChangedByClassy,
                                                       info.TimeSinceRankChange.ToMiniString());
                        if (info.RankChangeReason != null)
                        {
                            textBox1.Text += String.Format("  Promotion reason: {0}\r\n", info.RankChangeReason);
                        }
                    }
                }
                else if (info.PreviousRank <= info.Rank)
                {
                    textBox1.Text += String.Format("  Promoted from {0}&S to {1}&S by {2}&S {3} ago.\r\n",
                                                   info.PreviousRank.ClassyName,
                                                   info.Rank.ClassyName,
                                                   info.RankChangedByClassy,
                                                   info.TimeSinceRankChange.ToMiniString());
                    if (info.RankChangeReason != null)
                    {
                        textBox1.Text += String.Format("  Promotion reason: {0}\r\n", info.RankChangeReason);
                    }
                }
                else
                {
                    textBox1.Text += String.Format("  Demoted from {0}&S to {1}&S by {2}&S {3} ago.\r\n",
                                                   info.PreviousRank.ClassyName,
                                                   info.Rank.ClassyName,
                                                   info.RankChangedByClassy,
                                                   info.TimeSinceRankChange.ToMiniString());
                    if (info.RankChangeReason != null)
                    {
                        textBox1.Text += String.Format("  Demotion reason: {0}\r\n", info.RankChangeReason);
                    }
                }

                if (!info.LastIP.Equals(System.Net.IPAddress.None))
                {
                    // Time on the server
                    TimeSpan totalTime = info.TotalTime;
                    totalTime      = totalTime.Add(info.TimeSinceLastLogin);
                    textBox1.Text += String.Format("  Spent a total of {0:F1} hours ({1:F1} minutes) here.\r\n",
                                                   totalTime.TotalHours,
                                                   totalTime.TotalMinutes);
                }
                textBox1.Text = Color.StripColors(textBox1.Text);
            }
        }