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/>.
24 * 988 <nick> <servername> :Closed for new connections
25 * 989 <nick> <servername> :Open for new connections
34 class CommandLockserv : public Command
39 CommandLockserv(Module* Creator, std::string& lock) : Command(Creator, "LOCKSERV", 0, 1), locked(lock)
41 allow_empty_last_param = false;
45 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
49 user->WriteNotice("The server is already locked.");
53 locked = parameters.empty() ? "Server is temporarily closed. Please try again later." : parameters[0];
54 user->WriteNumeric(RPL_SERVLOCKON, user->server->GetName(), "Closed for new connections");
55 ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used LOCKSERV to temporarily disallow new connections", user->nick.c_str());
60 class CommandUnlockserv : public Command
65 CommandUnlockserv(Module* Creator, std::string& lock) : Command(Creator, "UNLOCKSERV", 0), locked(lock)
70 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
74 user->WriteNotice("The server isn't locked.");
79 user->WriteNumeric(RPL_SERVLOCKOFF, user->server->GetName(), "Open for new connections");
80 ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used UNLOCKSERV to allow new connections", user->nick.c_str());
85 class ModuleLockserv : public Module
88 CommandLockserv lockcommand;
89 CommandUnlockserv unlockcommand;
92 ModuleLockserv() : lockcommand(this, locked), unlockcommand(this, locked)
96 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
98 // Emergency way to unlock
103 void OnModuleRehash(User* user, const std::string& param) CXX11_OVERRIDE
105 if (irc::equals(param, "lockserv") && !locked.empty())
109 ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
113 ServerInstance->Users->QuitUser(user, locked);
116 return MOD_RES_PASSTHRU;
119 ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE
121 return !locked.empty() ? MOD_RES_DENY : MOD_RES_PASSTHRU;
124 Version GetVersion() CXX11_OVERRIDE
126 return Version("Provides the LOCKSERV and UNLOCKSERV commands to lock the server and block all incoming connections until unlocked again", VF_VENDOR);
130 MODULE_INIT(ModuleLockserv)