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;
31 ModuleConnFlood(InspIRCd* Me) : Module(Me)
35 Implementation eventlist[] = { I_OnRehash, I_OnUserRegister };
36 ServerInstance->Modules->Attach(eventlist, this, 2);
39 virtual ~ModuleConnFlood()
43 virtual Version GetVersion()
45 return Version("$Id$", VF_VENDOR,API_VERSION);
50 /* read configuration variables */
51 conf = new ConfigReader(ServerInstance);
52 /* throttle configuration */
53 seconds = conf->ReadInteger("connflood", "seconds", 0, true);
54 maxconns = conf->ReadInteger("connflood", "maxconns", 0, true);
55 timeout = conf->ReadInteger("connflood", "timeout", 0, true);
56 quitmsg = conf->ReadValue("connflood", "quitmsg", 0);
58 /* seconds to wait when the server just booted */
59 boot_wait = conf->ReadInteger("connflood", "bootwait", 0, true);
61 first = ServerInstance->Time();
64 virtual int OnUserRegister(User* user)
66 time_t next = ServerInstance->Time();
68 if ((ServerInstance->startup_time + boot_wait) > next)
71 /* time difference between first and latest connection */
72 time_t tdiff = next - first;
74 /* increase connection count */
79 if (tdiff > seconds + timeout)
83 ServerInstance->SNO->WriteGlobalSno('a', "Connection throttle deactivated");
87 ServerInstance->Users->QuitUser(user, quitmsg);
93 if (conns >= maxconns)
96 ServerInstance->SNO->WriteGlobalSno('a', "Connection throttle activated");
97 ServerInstance->Users->QuitUser(user, quitmsg);
109 virtual void OnRehash(User* user, const std::string ¶meter)
116 MODULE_INIT(ModuleConnFlood)