]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_lockserv.cpp
Fix some warnings in m_httpd on older versions of GCC.
[user/henk/code/inspircd.git] / src / modules / m_lockserv.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2006-2007 Dennis Friis <peavey@inspircd.org>
5  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
6  *
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.
10  *
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
14  * details.
15  *
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/>.
18  */
19
20
21 #include "inspircd.h"
22
23 /** Adds numerics
24  * 988 <nick> <servername> :Closed for new connections
25  * 989 <nick> <servername> :Open for new connections
26  */
27 enum
28 {
29         // InspIRCd-specific.
30         RPL_SERVLOCKON = 988,
31         RPL_SERVLOCKOFF = 989
32 };
33
34 class CommandLockserv : public Command
35 {
36         std::string& locked;
37
38  public:
39         CommandLockserv(Module* Creator, std::string& lock) : Command(Creator, "LOCKSERV", 0, 1), locked(lock)
40         {
41                 allow_empty_last_param = false;
42                 flags_needed = 'o';
43         }
44
45         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
46         {
47                 if (!locked.empty())
48                 {
49                         user->WriteNotice("The server is already locked.");
50                         return CMD_FAILURE;
51                 }
52
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());
56                 return CMD_SUCCESS;
57         }
58 };
59
60 class CommandUnlockserv : public Command
61 {
62         std::string& locked;
63
64  public:
65         CommandUnlockserv(Module* Creator, std::string& lock) : Command(Creator, "UNLOCKSERV", 0), locked(lock)
66         {
67                 flags_needed = 'o';
68         }
69
70         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
71         {
72                 if (locked.empty())
73                 {
74                         user->WriteNotice("The server isn't locked.");
75                         return CMD_FAILURE;
76                 }
77
78                 locked.clear();
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());
81                 return CMD_SUCCESS;
82         }
83 };
84
85 class ModuleLockserv : public Module
86 {
87         std::string locked;
88         CommandLockserv lockcommand;
89         CommandUnlockserv unlockcommand;
90
91  public:
92         ModuleLockserv() : lockcommand(this, locked), unlockcommand(this, locked)
93         {
94         }
95
96         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
97         {
98                 // Emergency way to unlock
99                 if (!status.srcuser)
100                         locked.clear();
101         }
102
103         void OnModuleRehash(User* user, const std::string& param) CXX11_OVERRIDE
104         {
105                 if (irc::equals(param, "lockserv") && !locked.empty())
106                         locked.clear();
107         }
108
109         ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
110         {
111                 if (!locked.empty())
112                 {
113                         ServerInstance->Users->QuitUser(user, locked);
114                         return MOD_RES_DENY;
115                 }
116                 return MOD_RES_PASSTHRU;
117         }
118
119         ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE
120         {
121                 return !locked.empty() ? MOD_RES_DENY : MOD_RES_PASSTHRU;
122         }
123
124         Version GetVersion() CXX11_OVERRIDE
125         {
126                 return Version("Provides the LOCKSERV and UNLOCKSERV commands to lock the server and block all incoming connections until unlocked again", VF_VENDOR);
127         }
128 };
129
130 MODULE_INIT(ModuleLockserv)