1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Connection throttle */
18 int conns = 0, throttled = 0;
20 class ModuleConnFlood : public Module
23 int seconds, maxconns, timeout, boot_wait;
34 Implementation eventlist[] = { I_OnRehash, I_OnUserRegister };
35 ServerInstance->Modules->Attach(eventlist, this, 2);
38 virtual ~ModuleConnFlood()
42 virtual Version GetVersion()
44 return Version("Connection throttle", VF_VENDOR);
49 /* read configuration variables */
50 conf = new ConfigReader;
51 /* throttle configuration */
52 seconds = conf->ReadInteger("connflood", "seconds", 0, true);
53 maxconns = conf->ReadInteger("connflood", "maxconns", 0, true);
54 timeout = conf->ReadInteger("connflood", "timeout", 0, true);
55 quitmsg = conf->ReadValue("connflood", "quitmsg", 0);
57 /* seconds to wait when the server just booted */
58 boot_wait = conf->ReadInteger("connflood", "bootwait", 0, true);
60 first = ServerInstance->Time();
63 virtual ModResult OnUserRegister(User* user)
65 time_t next = ServerInstance->Time();
67 if ((ServerInstance->startup_time + boot_wait) > next)
68 return MOD_RES_PASSTHRU;
70 /* time difference between first and latest connection */
71 time_t tdiff = next - first;
73 /* increase connection count */
78 if (tdiff > seconds + timeout)
82 ServerInstance->SNO->WriteGlobalSno('a', "Connection throttle deactivated");
83 return MOD_RES_PASSTHRU;
86 ServerInstance->Users->QuitUser(user, quitmsg);
92 if (conns >= maxconns)
95 ServerInstance->SNO->WriteGlobalSno('a', "Connection throttle activated");
96 ServerInstance->Users->QuitUser(user, quitmsg);
105 return MOD_RES_PASSTHRU;
108 virtual void OnRehash(User* user)
115 MODULE_INIT(ModuleConnFlood)