]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_lockserv.cpp
Fix IPv6 cloaking in compatability mode (was using the wrong xtab confusor)
[user/henk/code/inspircd.git] / src / modules / m_lockserv.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Allows locking of the server to stop all incoming connections till unlocked again */
17
18 /** Adds numerics
19  * 988 <nick> <servername> :Closed for new connections
20  * 989 <nick> <servername> :Open for new connections
21 */
22
23
24 class CommandLockserv : public Command
25 {
26         bool& locked;
27 public:
28         CommandLockserv(Module* Creator, bool& lock) : Command(Creator, "LOCKSERV", 0), locked(lock)
29         {
30                 flags_needed = 'o'; syntax.clear();
31         }
32
33         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
34         {
35                 locked = true;
36                 user->WriteNumeric(988, "%s %s :Closed for new connections", user->nick.c_str(), user->server.c_str());
37                 ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used LOCKSERV to temporarily close for new connections", user->nick.c_str());
38                 /* Dont send to the network */
39                 return CMD_SUCCESS;
40         }
41 };
42
43 class CommandUnlockserv : public Command
44 {
45 private:
46         bool& locked;
47
48 public:
49         CommandUnlockserv(Module* Creator, bool &lock) : Command(Creator, "UNLOCKSERV", 0), locked(lock)
50         {
51                 flags_needed = 'o'; syntax.clear();
52         }
53
54         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
55         {
56                 locked = false;
57                 user->WriteNumeric(989, "%s %s :Open for new connections", user->nick.c_str(), user->server.c_str());
58                 ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used UNLOCKSERV to allow for new connections", user->nick.c_str());
59                 /* Dont send to the network */
60                 return CMD_SUCCESS;
61         }
62 };
63
64 class ModuleLockserv : public Module
65 {
66 private:
67         bool locked;
68         CommandLockserv lockcommand;
69         CommandUnlockserv unlockcommand;
70
71 public:
72         ModuleLockserv() : lockcommand(this, locked), unlockcommand(this, locked)
73         {
74                 locked = false;
75                 ServerInstance->AddCommand(&lockcommand);
76                 ServerInstance->AddCommand(&unlockcommand);
77                 Implementation eventlist[] = { I_OnUserRegister, I_OnRehash, I_OnCheckReady };
78                 ServerInstance->Modules->Attach(eventlist, this, 3);
79         }
80
81         virtual ~ModuleLockserv()
82         {
83         }
84
85
86         virtual void OnRehash(User* user)
87         {
88                 // Emergency way to unlock
89                 if (!user) locked = false;
90         }
91
92         virtual ModResult OnUserRegister(LocalUser* user)
93         {
94                 if (locked)
95                 {
96                         ServerInstance->Users->QuitUser(user, "Server is temporarily closed. Please try again later.");
97                         return MOD_RES_DENY;
98                 }
99                 return MOD_RES_PASSTHRU;
100         }
101
102         virtual ModResult OnCheckReady(LocalUser* user)
103         {
104                 return locked ? MOD_RES_DENY : MOD_RES_PASSTHRU;
105         }
106
107         virtual Version GetVersion()
108         {
109                 return Version("Allows locking of the server to stop all incoming connections until unlocked again", VF_VENDOR);
110         }
111 };
112
113 MODULE_INIT(ModuleLockserv)