Exemple #1
0
        public string BanValue(string value, int ban_type, string reason, int days)
        {
            if (IsValueBannedWithType(value, ban_type))
            {
                return(null);
            }
            if (!Enum.IsDefined(typeof(BanType), ban_type))
            {
                return(null);
            }

            if (string.IsNullOrEmpty(reason))
            {
                reason = "No reason given.";
            }

            string ban_ID = string.Empty;

            do
            {
                ban_ID = RandomIdGenerator.GetBase36(6);
            } while (IsIDInUse(ban_ID));

            if (days < 1)
            {
                Bans.Add(new Ban(ban_ID, ban_type, value, reason, null));
            }
            else
            {
                Bans.Add(new Ban(ban_ID, ban_type, value, reason, DateTime.Now.AddDays(days)));
            }

            SaveBans();
            return(ban_ID);
        }
Exemple #2
0
        public string BanPlayer(Client player, int ban_type, string reason, int days)
        {
            if (IsPlayerBanned(player))
            {
                return(null);
            }
            if (!Enum.IsDefined(typeof(BanType), ban_type))
            {
                return(null);
            }

            string value        = player.name;
            bool   check_others = false;

            switch ((BanType)ban_type)
            {
            case BanType.Name:
                value = player.name;
                break;

            case BanType.SocialClubName:
                value = player.socialClubName;
                if (!API.getServerSocialClubDuplicateSetting())
                {
                    check_others = true;
                }
                break;

            case BanType.IP:
                value        = player.address;
                check_others = true;
                break;

            case BanType.HWID:
                value = player.uniqueHardwareId;
                if (!API.getServerHwidDuplicateSetting())
                {
                    check_others = true;
                }
                break;
            }

            if (string.IsNullOrEmpty(reason))
            {
                reason = "No reason given.";
            }

            string ban_ID = string.Empty;

            do
            {
                ban_ID = RandomIdGenerator.GetBase36(6);
            } while (IsIDInUse(ban_ID));

            if (days < 1)
            {
                Bans.Add(new Ban(ban_ID, ban_type, value, reason, null));
            }
            else
            {
                Bans.Add(new Ban(ban_ID, ban_type, value, reason, DateTime.Now.AddDays(days)));
            }

            if (check_others)
            {
                List <Client> players = new List <Client>();

                switch ((BanType)ban_type)
                {
                case BanType.SocialClubName:
                    players = API.getAllPlayers().Where(p => p.socialClubName == value).ToList();
                    break;

                case BanType.IP:
                    players = API.getAllPlayers().Where(p => p.address == value).ToList();
                    break;

                case BanType.HWID:
                    players = API.getAllPlayers().Where(p => p.uniqueHardwareId == value).ToList();
                    break;
                }

                foreach (Client p in players)
                {
                    p.kick(string.Format("You're banned.~n~~n~~b~Ban ID: ~w~{0}~n~~b~Reason: ~w~{1}~n~~b~Ends On: ~w~{2}", ban_ID, reason, ((days < 1) ? "Permanent" : DateTime.Now.AddDays(days).ToString("dd/MM/yyyy HH:mm:ss"))));
                }
            }
            else
            {
                player.kick(string.Format("You're banned.~n~~n~~b~Ban ID: ~w~{0}~n~~b~Reason: ~w~{1}~n~~b~Ends On: ~w~{2}", ban_ID, reason, ((days < 1) ? "Permanent" : DateTime.Now.AddDays(days).ToString("dd/MM/yyyy HH:mm:ss"))));
            }

            SaveBans();
            return(ban_ID);
        }