1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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 ModuleConnFlood(InspIRCd* Me) : Module(Me)
37 virtual ~ModuleConnFlood()
41 virtual Version GetVersion()
43 return Version(1,1,0,0,VF_VENDOR,API_VERSION);
46 void Implements(char* List)
48 List[I_OnRehash] = List[I_OnUserRegister] = 1;
53 /* read configuration variables */
54 conf = new ConfigReader(ServerInstance);
55 /* throttle configuration */
56 seconds = conf->ReadInteger("connflood", "seconds", 0, true);
57 maxconns = conf->ReadInteger("connflood", "maxconns", 0, true);
58 timeout = conf->ReadInteger("connflood", "timeout", 0, true);
59 quitmsg = conf->ReadValue("connflood", "quitmsg", 0);
61 /* seconds to wait when the server just booted */
62 boot_wait = conf->ReadInteger("connflood", "bootwait", 0, true);
64 first = ServerInstance->Time();
67 virtual int OnUserRegister(userrec* user)
69 time_t next = ServerInstance->Time();
71 if ((ServerInstance->startup_time + boot_wait) > next)
74 /* time difference between first and latest connection */
75 time_t tdiff = next - first;
77 /* increase connection count */
82 if (tdiff > seconds + timeout)
86 ServerInstance->WriteOpers("*** Connection throttle deactivated");
89 userrec::QuitUser(ServerInstance, user, quitmsg);
95 if (conns >= maxconns)
98 ServerInstance->WriteOpers("*** Connection throttle activated");
99 userrec::QuitUser(ServerInstance, user, quitmsg);
111 virtual void OnRehash(userrec* user, const std::string ¶meter)
118 MODULE_INIT(ModuleConnFlood)