]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_lockserv.cpp
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / src / modules / m_lockserv.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 2016-2018 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2012-2013 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2010 Craig Edwards <brain@inspircd.org>
8  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
9  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
10  *   Copyright (C) 2006-2007 Dennis Friis <peavey@inspircd.org>
11  *
12  * This file is part of InspIRCd.  InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24
25
26 #include "inspircd.h"
27
28 /** Adds numerics
29  * 988 <nick> <servername> :Closed for new connections
30  * 989 <nick> <servername> :Open for new connections
31  */
32 enum
33 {
34         // InspIRCd-specific.
35         RPL_SERVLOCKON = 988,
36         RPL_SERVLOCKOFF = 989
37 };
38
39 class CommandLockserv : public Command
40 {
41         std::string& locked;
42
43  public:
44         CommandLockserv(Module* Creator, std::string& lock) : Command(Creator, "LOCKSERV", 0, 1), locked(lock)
45         {
46                 allow_empty_last_param = false;
47                 flags_needed = 'o';
48         }
49
50         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
51         {
52                 if (!locked.empty())
53                 {
54                         user->WriteNotice("The server is already locked.");
55                         return CMD_FAILURE;
56                 }
57
58                 locked = parameters.empty() ? "Server is temporarily closed. Please try again later." : parameters[0];
59                 user->WriteNumeric(RPL_SERVLOCKON, user->server->GetName(), "Closed for new connections");
60                 ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used LOCKSERV to temporarily disallow new connections", user->nick.c_str());
61                 return CMD_SUCCESS;
62         }
63 };
64
65 class CommandUnlockserv : public Command
66 {
67         std::string& locked;
68
69  public:
70         CommandUnlockserv(Module* Creator, std::string& lock) : Command(Creator, "UNLOCKSERV", 0), locked(lock)
71         {
72                 flags_needed = 'o';
73         }
74
75         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
76         {
77                 if (locked.empty())
78                 {
79                         user->WriteNotice("The server isn't locked.");
80                         return CMD_FAILURE;
81                 }
82
83                 locked.clear();
84                 user->WriteNumeric(RPL_SERVLOCKOFF, user->server->GetName(), "Open for new connections");
85                 ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used UNLOCKSERV to allow new connections", user->nick.c_str());
86                 return CMD_SUCCESS;
87         }
88 };
89
90 class ModuleLockserv : public Module
91 {
92         std::string locked;
93         CommandLockserv lockcommand;
94         CommandUnlockserv unlockcommand;
95
96  public:
97         ModuleLockserv() : lockcommand(this, locked), unlockcommand(this, locked)
98         {
99         }
100
101         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
102         {
103                 // Emergency way to unlock
104                 if (!status.srcuser)
105                         locked.clear();
106         }
107
108         void OnModuleRehash(User* user, const std::string& param) CXX11_OVERRIDE
109         {
110                 if (irc::equals(param, "lockserv") && !locked.empty())
111                         locked.clear();
112         }
113
114         ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
115         {
116                 if (!locked.empty())
117                 {
118                         ServerInstance->Users->QuitUser(user, locked);
119                         return MOD_RES_DENY;
120                 }
121                 return MOD_RES_PASSTHRU;
122         }
123
124         ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE
125         {
126                 return !locked.empty() ? MOD_RES_DENY : MOD_RES_PASSTHRU;
127         }
128
129         Version GetVersion() CXX11_OVERRIDE
130         {
131                 return Version("Adds the /LOCKSERV and /UNLOCKSERV commands which allows server operators to control whether users can connect to the local server.", VF_VENDOR);
132         }
133 };
134
135 MODULE_INIT(ModuleLockserv)