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 * ---------------------------------------------------
26 /* $ModDesc: Connection throttle */
28 int conns = 0, throttled = 0;
30 class ModuleConnFlood : public Module
33 int seconds, maxconns, timeout, boot_wait;
41 ModuleConnFlood(InspIRCd* Me) : Module::Module(Me)
47 virtual ~ModuleConnFlood()
51 virtual Version GetVersion()
53 return Version(1,0,0,0,0);
56 void Implements(char* List)
58 List[I_OnRehash] = List[I_OnUserRegister] = 1;
63 /* read configuration variables */
64 conf = new ConfigReader(ServerInstance);
65 /* throttle configuration */
66 seconds = conf->ReadInteger("connflood", "seconds", 0, true);
67 maxconns = conf->ReadInteger("connflood", "maxconns", 0, true);
68 timeout = conf->ReadInteger("connflood", "timeout", 0, true);
69 quitmsg = conf->ReadValue("connflood", "quitmsg", 0);
71 /* seconds to wait when the server just booted */
72 boot_wait = conf->ReadInteger("connflood", "bootwait", 0, true);
74 first = ServerInstance->Time();
77 virtual void OnUserRegister(userrec* user)
79 time_t next = ServerInstance->Time();
81 first = next - boot_wait;
83 /* time difference between first and latest connection */
84 time_t tdiff = next - first;
86 /* increase connection count */
91 if (tdiff > seconds + timeout)
95 ServerInstance->WriteOpers("*** Connection throttle deactivated");
98 userrec::QuitUser(ServerInstance, user, quitmsg);
102 if (tdiff <= seconds)
104 if (conns >= maxconns)
107 ServerInstance->WriteOpers("*** Connection throttle activated");
108 userrec::QuitUser(ServerInstance, user, quitmsg);
119 virtual void OnRehash(const std::string ¶meter)
127 class ModuleConnFloodFactory : public ModuleFactory
130 ModuleConnFloodFactory()
134 ~ModuleConnFloodFactory()
138 virtual Module * CreateModule(InspIRCd* Me)
140 return new ModuleConnFlood(Me);
145 extern "C" void * init_module( void )
147 return new ModuleConnFloodFactory;