]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_lockserv.cpp
Merge pull request #1337 from SaberUK/master+merge
[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
28 class CommandLockserv : public Command
29 {
30         std::string& locked;
31
32  public:
33         CommandLockserv(Module* Creator, std::string& lock) : Command(Creator, "LOCKSERV", 0, 1), locked(lock)
34         {
35                 allow_empty_last_param = false;
36                 flags_needed = 'o';
37         }
38
39         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
40         {
41                 if (!locked.empty())
42                 {
43                         user->WriteNotice("The server is already locked.");
44                         return CMD_FAILURE;
45                 }
46
47                 locked = parameters.empty() ? "Server is temporarily closed. Please try again later." : parameters[0];
48                 user->WriteNumeric(988, user->server->GetName(), "Closed for new connections");
49                 ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used LOCKSERV to temporarily disallow new connections", user->nick.c_str());
50                 return CMD_SUCCESS;
51         }
52 };
53
54 class CommandUnlockserv : public Command
55 {
56         std::string& locked;
57
58  public:
59         CommandUnlockserv(Module* Creator, std::string& lock) : Command(Creator, "UNLOCKSERV", 0), locked(lock)
60         {
61                 flags_needed = 'o';
62         }
63
64         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
65         {
66                 if (locked.empty())
67                 {
68                         user->WriteNotice("The server isn't locked.");
69                         return CMD_FAILURE;
70                 }
71
72                 locked.clear();
73                 user->WriteNumeric(989, user->server->GetName(), "Open for new connections");
74                 ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used UNLOCKSERV to allow new connections", user->nick.c_str());
75                 return CMD_SUCCESS;
76         }
77 };
78
79 class ModuleLockserv : public Module
80 {
81         std::string locked;
82         CommandLockserv lockcommand;
83         CommandUnlockserv unlockcommand;
84
85  public:
86         ModuleLockserv() : lockcommand(this, locked), unlockcommand(this, locked)
87         {
88         }
89
90         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
91         {
92                 // Emergency way to unlock
93                 if (!status.srcuser)
94                         locked.clear();
95         }
96
97         ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
98         {
99                 if (!locked.empty())
100                 {
101                         ServerInstance->Users->QuitUser(user, locked);
102                         return MOD_RES_DENY;
103                 }
104                 return MOD_RES_PASSTHRU;
105         }
106
107         ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE
108         {
109                 return !locked.empty() ? MOD_RES_DENY : MOD_RES_PASSTHRU;
110         }
111
112         Version GetVersion() CXX11_OVERRIDE
113         {
114                 return Version("Allows locking of the server to stop all incoming connections until unlocked again", VF_VENDOR);
115         }
116 };
117
118 MODULE_INIT(ModuleLockserv)