Esempio n. 1
0
 public bool HandleFlood(EndPoint id)
 {
     if (floods.ContainsKey(id))
     {
         FloodCounter counter = floods[id];
         counter.PacketCount += 1;
         floods[id] = counter;
         if (counter.StopWatch.ElapsedMilliseconds > msecTime)
         {
             floods.Remove(id);
         }
         else if (counter.PacketCount > maxPacketASecond)
         {
             floods.Remove(id);
             return false;
         }
     }
     else
     {
         FloodCounter counter = new FloodCounter();
         counter.PacketCount = 1;
         counter.StopWatch = Stopwatch.StartNew();
         floods.Add(id, counter);
     }
     return true;
 }
Esempio n. 2
0
        protected internal virtual bool CheckCounters(IClient user, IPacket packet)
        {
            DateTime now = DateTime.Now;

            foreach (var rule in flood_rules.Where((s) => s.Id == packet.Id))
            {
                if (!user.Counters.TryGetValue(packet.Id, out IFloodCounter counter))
                {
                    counter = new FloodCounter(0, now);
                    user.Counters.Add(packet.Id, counter);
                }

                if (now.Subtract(counter.Last).TotalMilliseconds > rule.Timeout)
                {
                    counter.Count = 0;
                }

                if (++counter.Count >= rule.Count)
                {
                    Stats.FloodsTriggered++;

                    if (!PluginHost.OnFlood(user, rule, packet))
                    {
                        return(false);
                    }
                }
                else
                {
                    counter.Last = now;
                }
            }

            return(true);
        }
 public bool HandleFlood(EndPoint id)
 {
     if (floods.ContainsKey(id))
     {
         FloodCounter counter = floods[id];
         counter.PacketCount += 1;
         floods[id]           = counter;
         if (counter.StopWatch.ElapsedMilliseconds > msecTime)
         {
             floods.Remove(id);
         }
         else if (counter.PacketCount > maxPacketASecond)
         {
             floods.Remove(id);
             return(false);
         }
     }
     else
     {
         FloodCounter counter = new FloodCounter();
         counter.PacketCount = 1;
         counter.StopWatch   = Stopwatch.StartNew();
         floods.Add(id, counter);
     }
     return(true);
 }
Esempio n. 4
0
        protected internal virtual bool CheckCounters(IClient user, IPacket packet)
        {
            var rules = flood_rules.FindAll((s) => s.Id == packet.Id);

            foreach (var rule in rules)
            {
                IFloodCounter counter = null;
                DateTime      now     = DateTime.Now;

                if (!user.Counters.ContainsKey(packet.Id))
                {
                    counter = new FloodCounter(0, now);
                    user.Counters.Add(packet.Id, counter);
                }
                else
                {
                    counter = user.Counters[packet.Id];

                    if (now.Subtract(counter.Last).TotalMilliseconds > rule.Timeout)
                    {
                        counter.Count = 0;
                    }
                }

                if (++counter.Count >= rule.Count)
                {
                    Stats.FloodsTriggered++;

                    if (!PluginHost.OnFlood(user, rule, packet))
                    {
                        return(false);
                    }
                }
                else
                {
                    counter.Last = now;
                }
            }

            return(true);
        }