1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 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;
31 Implementation eventlist[] = { I_OnRehash, I_OnUserRegister };
32 ServerInstance->Modules->Attach(eventlist, this, 2);
35 virtual ~ModuleConnFlood()
39 virtual Version GetVersion()
41 return Version("Connection throttle", VF_VENDOR);
46 /* read configuration variables */
48 /* throttle configuration */
49 seconds = conf.ReadInteger("connflood", "seconds", 0, true);
50 maxconns = conf.ReadInteger("connflood", "maxconns", 0, true);
51 timeout = conf.ReadInteger("connflood", "timeout", 0, true);
52 quitmsg = conf.ReadValue("connflood", "quitmsg", 0);
54 /* seconds to wait when the server just booted */
55 boot_wait = conf.ReadInteger("connflood", "bootwait", 0, true);
57 first = ServerInstance->Time();
60 virtual ModResult OnUserRegister(LocalUser* user)
62 time_t next = ServerInstance->Time();
64 if ((ServerInstance->startup_time + boot_wait) > next)
65 return MOD_RES_PASSTHRU;
67 /* time difference between first and latest connection */
68 time_t tdiff = next - first;
70 /* increase connection count */
75 if (tdiff > seconds + timeout)
79 ServerInstance->SNO->WriteGlobalSno('a', "Connection throttle deactivated");
80 return MOD_RES_PASSTHRU;
83 ServerInstance->Users->QuitUser(user, quitmsg);
89 if (conns >= maxconns)
92 ServerInstance->SNO->WriteGlobalSno('a', "Connection throttle activated");
93 ServerInstance->Users->QuitUser(user, quitmsg);
102 return MOD_RES_PASSTHRU;
105 virtual void OnRehash(User* user)
112 MODULE_INIT(ModuleConnFlood)