Пример #1
0
        public override void Update(Server server, float dt)
        {
            if (!loaded)
            {
                loaded = true;
                LoadBanlist(server);
            }

            if (server.banlist.ClearTimeBans() > 0)
            {
                SaveBanlist(server);
            }

            foreach (KeyValuePair <int, ClientOnServer> k in server.clients)
            {
                int            clientId = k.Key;
                ClientOnServer c        = k.Value;
                IPEndPointCi   iep1     = c.socket.RemoteEndPoint();

                if (server.banlist.IsIPBanned(iep1.AddressToString()))
                {
                    IPEntry entry  = server.banlist.GetIPEntry(iep1.AddressToString());
                    string  reason = entry.Reason;
                    if (string.IsNullOrEmpty(reason))
                    {
                        reason = "";
                    }
                    server.SendPacket(clientId, ServerPackets.DisconnectPlayer(string.Format(server.language.ServerIPBanned(), reason)));
                    Console.WriteLine(string.Format("Banned IP {0} tries to connect.", iep1.AddressToString()));
                    server.ServerEventLog(string.Format("Banned IP {0} tries to connect.", iep1.AddressToString()));
                    server.KillPlayer(clientId);
                    continue;
                }

                string username = c.playername;
                if (server.banlist.IsUserBanned(username))
                {
                    UserEntry entry  = server.banlist.GetUserEntry(username);
                    string    reason = entry.Reason;
                    if (string.IsNullOrEmpty(reason))
                    {
                        reason = "";
                    }
                    server.SendPacket(clientId, ServerPackets.DisconnectPlayer(string.Format(server.language.ServerUsernameBanned(), reason)));
                    Console.WriteLine(string.Format("{0} fails to join (banned username: {1}).", (c.socket.RemoteEndPoint()).AddressToString(), username));
                    server.ServerEventLog(string.Format("{0} fails to join (banned username: {1}).", (c.socket.RemoteEndPoint()).AddressToString(), username));
                    server.KillPlayer(clientId);
                    continue;
                }
            }
        }
Пример #2
0
        public bool UnbanIP(string ip)
        {
            bool exists = false;

            for (int i = BannedIPs.Count - 1; i >= 0; i--)
            {
                IPEntry bannedip = BannedIPs[i];
                if (bannedip.IPAdress.Equals(ip, StringComparison.InvariantCultureIgnoreCase))
                {
                    exists = true;
                    BannedIPs.RemoveAt(i);
                    break;
                }
            }
            return(exists);
        }
Пример #3
0
        public bool TimeBanIP(string ipadress, string bannedby, string reason, int intervalMinutes)
        {
            if (IsIPBanned(ipadress))
            {
                return(false);
            }
            IPEntry newBan = new IPEntry();

            newBan.IPAdress = ipadress;
            newBan.BannedBy = bannedby;
            if (intervalMinutes > 0)
            {
                newBan.BannedUntil = DateTime.UtcNow + TimeSpan.FromMinutes(intervalMinutes);
            }
            if (!string.IsNullOrEmpty(reason))
            {
                newBan.Reason = reason;
            }
            BannedIPs.Add(newBan);
            return(true);
        }