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 * ---------------------------------------------------
23 #include "helperfuncs.h"
26 /* $ModDesc: Connection throttle */
28 int conns = 0, throttled = 0;
31 extern InspIRCd* ServerInstance;
33 class ModuleConnFlood : public Module
36 int seconds, maxconns, timeout, boot_wait;
44 ModuleConnFlood(Server* Me) : Module::Module(Me)
50 virtual ~ModuleConnFlood()
54 virtual Version GetVersion()
56 return Version(1,0,0,0,0);
59 void Implements(char* List)
61 List[I_OnRehash] = List[I_OnUserRegister] = 1;
66 /* read configuration variables */
67 conf = new ConfigReader;
68 /* throttle configuration */
69 seconds = conf->ReadInteger("connflood", "seconds", 0, true);
70 maxconns = conf->ReadInteger("connflood", "maxconns", 0, true);
71 timeout = conf->ReadInteger("connflood", "timeout", 0, true);
72 quitmsg = conf->ReadValue("connflood", "quitmsg", 0);
74 /* seconds to wait when the server just booted */
75 boot_wait = conf->ReadInteger("connflood", "bootwait", 0, true);
80 virtual void OnUserRegister(userrec* user)
84 first = next - boot_wait;
86 /* time difference between first and latest connection */
87 time_t tdiff = next - first;
89 /* increase connection count */
94 if (tdiff > seconds + timeout)
98 ServerInstance->WriteOpers("*** Connection throttle deactivated");
101 userrec::QuitUser(ServerInstance, user, quitmsg);
105 if (tdiff <= seconds)
107 if (conns >= maxconns)
110 ServerInstance->WriteOpers("*** Connection throttle activated");
111 userrec::QuitUser(ServerInstance, user, quitmsg);
122 virtual void OnRehash(const std::string ¶meter)
130 class ModuleConnFloodFactory : public ModuleFactory
133 ModuleConnFloodFactory()
137 ~ModuleConnFloodFactory()
141 virtual Module * CreateModule(Server* Me)
143 return new ModuleConnFlood(Me);
148 extern "C" void * init_module( void )
150 return new ModuleConnFloodFactory;