]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_lockserv.cpp
58f468c502cd2853e06b01a06c2082932895e4ad
[user/henk/code/inspircd.git] / src / modules / m_lockserv.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 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         virtual void ResetLocked()
72         {
73                 locked = false;
74         }
75
76 public:
77         ModuleLockserv() : lockcommand(this, locked), unlockcommand(this, locked)
78         {
79                 ResetLocked();
80                 ServerInstance->AddCommand(&lockcommand);
81                 ServerInstance->AddCommand(&unlockcommand);
82                 Implementation eventlist[] = { I_OnUserRegister, I_OnRehash, I_OnCheckReady };
83                 ServerInstance->Modules->Attach(eventlist, this, 3);
84         }
85
86         virtual ~ModuleLockserv()
87         {
88         }
89
90
91         virtual void OnRehash(User* user)
92         {
93                 ResetLocked();
94         }
95
96         virtual ModResult OnUserRegister(LocalUser* user)
97         {
98                 if (locked)
99                 {
100                         ServerInstance->Users->QuitUser(user, "Server is temporarily closed. Please try again later.");
101                         return MOD_RES_DENY;
102                 }
103                 return MOD_RES_PASSTHRU;
104         }
105
106         virtual ModResult OnCheckReady(LocalUser* user)
107         {
108                 return locked ? MOD_RES_DENY : MOD_RES_PASSTHRU;
109         }
110
111         virtual Version GetVersion()
112         {
113                 return Version("Allows locking of the server to stop all incoming connections till unlocked again", VF_VENDOR);
114         }
115 };
116
117 MODULE_INIT(ModuleLockserv)