1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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)
35 Implementation eventlist[] = { I_OnRehash, I_OnUserRegister };
36 ServerInstance->Modules->Attach(eventlist, this, 2);
39 virtual ~ModuleConnFlood()
43 virtual Version GetVersion()
45 return Version(1,2,0,0,VF_VENDOR,API_VERSION);
51 /* read configuration variables */
52 conf = new ConfigReader(ServerInstance);
53 /* throttle configuration */
54 seconds = conf->ReadInteger("connflood", "seconds", 0, true);
55 maxconns = conf->ReadInteger("connflood", "maxconns", 0, true);
56 timeout = conf->ReadInteger("connflood", "timeout", 0, true);
57 quitmsg = conf->ReadValue("connflood", "quitmsg", 0);
59 /* seconds to wait when the server just booted */
60 boot_wait = conf->ReadInteger("connflood", "bootwait", 0, true);
62 first = ServerInstance->Time();
65 virtual int OnUserRegister(User* user)
67 time_t next = ServerInstance->Time();
69 if ((ServerInstance->startup_time + boot_wait) > next)
72 /* time difference between first and latest connection */
73 time_t tdiff = next - first;
75 /* increase connection count */
80 if (tdiff > seconds + timeout)
84 ServerInstance->SNO->WriteToSnoMask('A', "Connection throttle deactivated");
88 ServerInstance->Users->QuitUser(user, quitmsg);
94 if (conns >= maxconns)
97 ServerInstance->SNO->WriteToSnoMask('A', "Connection throttle activated");
98 ServerInstance->Users->QuitUser(user, quitmsg);
110 virtual void OnRehash(User* user, const std::string ¶meter)
117 MODULE_INIT(ModuleConnFlood)