1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * --- This module contributed by pippijn ---
12 * Written by Craig Edwards, Craig McLure, and others.
13 * This program is free but copyrighted software; see
14 * the file COPYING for details.
16 * ---------------------------------------------------
24 /* $ModDesc: Connection throttle */
26 int conns = 0, throttled = 0;
29 class ModuleConnFlood : public Module
32 int seconds, maxconns, timeout, boot_wait;
40 ModuleConnFlood(Server* Me) : Module::Module(Me)
46 virtual ~ModuleConnFlood()
50 virtual Version GetVersion()
52 return Version(1,0,0,0,0);
55 void Implements(char* List)
57 List[I_OnRehash] = List[I_OnUserRegister] = 1;
62 /* read configuration variables */
63 conf = new ConfigReader;
64 /* throttle configuration */
65 seconds = conf->ReadInteger("connflood", "seconds", 0, true);
66 maxconns = conf->ReadInteger("connflood", "maxconns", 0, true);
67 timeout = conf->ReadInteger("connflood", "timeout", 0, true);
68 quitmsg = conf->ReadValue("connflood", "quitmsg", 0);
70 /* seconds to wait when the server just booted */
71 boot_wait = conf->ReadInteger("connflood", "bootwait", 0, true);
76 virtual void OnUserRegister(userrec* user)
80 first = next - boot_wait;
82 /* time difference between first and latest connection */
83 time_t tdiff = next - first;
85 /* increase connection count */
90 if (tdiff > seconds + timeout)
94 Srv->SendOpers("*** Connection throttle deactivated");
97 Srv->QuitUser(user, quitmsg);
101 if (tdiff <= seconds)
103 if (conns >= maxconns)
106 Srv->SendOpers("*** Connection throttle activated");
107 Srv->QuitUser(user, quitmsg);
118 virtual void OnRehash(const std::string ¶meter)
126 class ModuleConnFloodFactory : public ModuleFactory
129 ModuleConnFloodFactory()
133 ~ModuleConnFloodFactory()
137 virtual Module * CreateModule(Server* Me)
139 return new ModuleConnFlood(Me);
144 extern "C" void * init_module( void )
146 return new ModuleConnFloodFactory;