2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class ModuleConnFlood : public Module
26 int seconds, timeout, boot_wait;
28 unsigned int maxconns;
35 : conns(0), throttled(false)
39 void init() CXX11_OVERRIDE
44 Version GetVersion() CXX11_OVERRIDE
46 return Version("Connection throttle", VF_VENDOR);
51 /* read configuration variables */
52 ConfigTag* tag = ServerInstance->Config->ConfValue("connflood");
53 /* throttle configuration */
54 seconds = tag->getInt("seconds");
55 maxconns = tag->getInt("maxconns");
56 timeout = tag->getInt("timeout");
57 quitmsg = tag->getString("quitmsg");
59 /* seconds to wait when the server just booted */
60 boot_wait = tag->getInt("bootwait");
62 first = ServerInstance->Time();
65 ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
68 return MOD_RES_PASSTHRU;
70 time_t next = ServerInstance->Time();
72 if ((ServerInstance->startup_time + boot_wait) > next)
73 return MOD_RES_PASSTHRU;
75 /* time difference between first and latest connection */
76 time_t tdiff = next - first;
78 /* increase connection count */
83 if (tdiff > seconds + timeout)
87 ServerInstance->SNO->WriteGlobalSno('a', "Connection throttle deactivated");
88 return MOD_RES_PASSTHRU;
91 ServerInstance->Users->QuitUser(user, quitmsg);
97 if (conns >= maxconns)
100 ServerInstance->SNO->WriteGlobalSno('a', "Connection throttle activated");
101 ServerInstance->Users->QuitUser(user, quitmsg);
110 return MOD_RES_PASSTHRU;
113 void OnRehash(User* user) CXX11_OVERRIDE
120 MODULE_INIT(ModuleConnFlood)