Ejemplo n.º 1
0
        public BannedClientRecord RegisterBan(string source, DateTime currentDate)
        {
            if (string.IsNullOrEmpty(source))
            {
                return(null);
            }

            BannedClientRecord bannedClient;

            //get ban record or register new one
            lock (bannedClients)
            {
                if (!bannedClients.ContainsKey(source))
                {
                    bannedClient = new BannedClientRecord {
                        Source = source
                    };
                    bannedClients[source] = bannedClient;
                }
                else
                {
                    bannedClient = bannedClients[source];
                }
            }
            //update ban counts
            lock (bannedClient)
            {
                if (bannedClient.BanCounts > 0 &&
                    !bannedClient.IsOnProbation(currentDate, singleBanPeriod, boostFactor))    //if probation period is over, but bans count weren't reset
                {
                    bannedClient.BanCounts = 0;
                }

                bannedClient.BanCounts++;
                bannedClient.SetTillDate(currentDate, singleBanPeriod, boostFactor);
            }
            //add ban record to update list
            lock (updatedClientsSyncRoot)
            {
                if (!updatedClients.ContainsKey(bannedClient.Source))
                {
                    updatedClients[bannedClient.Source] = bannedClient;
                }
            }
            return(bannedClient);
        }
Ejemplo n.º 2
0
 public bool TryGetBannedClient(string source, out BannedClientRecord bannedClientRecord)
 {
     lock (bannedClients)
         return(bannedClients.TryGetValue(source, out bannedClientRecord));
 }