Exemplo n.º 1
0
        protected virtual bool CheckCounters(AresClient user, IPacket packet)
        {
            var rules = flood_rules.FindAll((s) => s.Id == packet.Id);

            foreach (var rule in rules)
            {
                FloodCounter counter = null;
                DateTime     now     = TimeBank.CurrentTime;

                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.ResetTimeout)
                    {
                        counter.Count = 0;
                    }
                }

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

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

            return(true);
        }
Exemplo n.º 2
0
        private bool CheckFloodCounter(IPAddress address)
        {
            FloodCounter counter = null;
            DateTime     now     = TimeBank.CurrentTime;

            TimeSpan span = TimeSpan.FromMinutes(5);

            if (!counters.TryGetValue(address, out counter))
            {
                counter = new FloodCounter(0, now);
                counters.Add(address, counter);
            }

            if (now.Subtract(counter.Last) > span)
            {
                counter.Count = 0;
            }

            else if (++counter.Count >= 10)
            {
                Logging.WriteLines(new[] {
                    "----------",
                    String.Format("UDP Flood Detected From: {0} ({1})", address, counter.Count),
                    "----------"
                });

                //BAN SERVER
                //lock (banned) banned.Add(address);
            }
            else
            {
                counter.Last = now;
            }

            return(true);
        }