2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2006-2007 Dennis Friis <peavey@inspircd.org>
5 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 /* $ModDesc: Allows locking of the server to stop all incoming connections till unlocked again */
26 * 988 <nick> <servername> :Closed for new connections
27 * 989 <nick> <servername> :Open for new connections
31 class CommandLockserv : public Command
35 CommandLockserv(Module* Creator, bool& lock) : Command(Creator, "LOCKSERV", 0), locked(lock)
40 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
44 user->WriteServ("NOTICE %s :The server is already locked.", user->nick.c_str());
49 user->WriteNumeric(988, "%s %s :Closed for new connections", user->nick.c_str(), user->server.c_str());
50 ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used LOCKSERV to temporarily disallow new connections", user->nick.c_str());
55 class CommandUnlockserv : public Command
61 CommandUnlockserv(Module* Creator, bool &lock) : Command(Creator, "UNLOCKSERV", 0), locked(lock)
66 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
70 user->WriteServ("NOTICE %s :The server isn't locked.", user->nick.c_str());
75 user->WriteNumeric(989, "%s %s :Open for new connections", user->nick.c_str(), user->server.c_str());
76 ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used UNLOCKSERV to allow new connections", user->nick.c_str());
81 class ModuleLockserv : public Module
85 CommandLockserv lockcommand;
86 CommandUnlockserv unlockcommand;
89 ModuleLockserv() : lockcommand(this, locked), unlockcommand(this, locked)
92 ServerInstance->AddCommand(&lockcommand);
93 ServerInstance->AddCommand(&unlockcommand);
94 Implementation eventlist[] = { I_OnUserRegister, I_OnRehash, I_OnCheckReady };
95 ServerInstance->Modules->Attach(eventlist, this, 3);
98 virtual ~ModuleLockserv()
103 virtual void OnRehash(User* user)
105 // Emergency way to unlock
106 if (!user) locked = false;
109 virtual ModResult OnUserRegister(LocalUser* user)
113 ServerInstance->Users->QuitUser(user, "Server is temporarily closed. Please try again later.");
116 return MOD_RES_PASSTHRU;
119 virtual ModResult OnCheckReady(LocalUser* user)
121 return locked ? MOD_RES_DENY : MOD_RES_PASSTHRU;
124 virtual Version GetVersion()
126 return Version("Allows locking of the server to stop all incoming connections until unlocked again", VF_VENDOR);
130 MODULE_INIT(ModuleLockserv)