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