]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_lockserv.cpp
872678502ab45fd5175c63e8895c21205f216e22
[user/henk/code/inspircd.git] / src / modules / m_lockserv.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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 private:
27         bool& locked;
28
29 public:
30         CommandLockserv (InspIRCd* Instance, bool &lock)
31         : Command(Instance, "LOCKSERV", "o", 0), locked(lock)
32         {
33                 this->source = "m_lockserv.so";
34                 syntax.clear();
35         }
36
37         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
38         {
39                 locked = true;
40                 user->WriteNumeric(988, "%s %s :Closed for new connections", user->nick, user->server);
41                 ServerInstance->SNO->WriteToSnoMask('A', "Oper %s used LOCKSERV to temporarily close for new connections", user->nick);
42                 /* Dont send to the network */
43                 return CMD_LOCALONLY;
44         }
45 };
46
47 class CommandUnlockserv : public Command
48 {
49 private:
50         bool& locked;
51
52 public:
53         CommandUnlockserv (InspIRCd* Instance, bool &lock)
54         : Command(Instance, "UNLOCKSERV", "o", 0), locked(lock)
55         {
56                 this->source = "m_lockserv.so";
57                 syntax.clear();
58         }
59
60         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
61         {
62                 locked = false;
63                 user->WriteNumeric(989, "%s %s :Open for new connections", user->nick, user->server);
64                 ServerInstance->SNO->WriteToSnoMask('A', "Oper %s used UNLOCKSERV to allow for new connections", user->nick);
65                 /* Dont send to the network */
66                 return CMD_LOCALONLY;
67         }
68 };
69
70 class ModuleLockserv : public Module
71 {
72 private:
73         bool locked;
74         CommandLockserv* lockcommand;
75         CommandUnlockserv* unlockcommand;
76
77         virtual void ResetLocked()
78         {
79                 locked = false;
80         }
81
82 public:
83         ModuleLockserv(InspIRCd* Me) : Module(Me)
84         {
85                 ResetLocked();
86                 lockcommand = new CommandLockserv(ServerInstance, locked);
87                 ServerInstance->AddCommand(lockcommand);
88
89                 unlockcommand = new CommandUnlockserv(ServerInstance, locked);
90                 ServerInstance->AddCommand(unlockcommand);
91                 Implementation eventlist[] = { I_OnUserRegister, I_OnRehash, I_OnCheckReady };
92                 ServerInstance->Modules->Attach(eventlist, this, 3);
93         }
94
95         virtual ~ModuleLockserv()
96         {
97         }
98
99
100         virtual void OnRehash(User* user, const std::string &parameter)
101         {
102                 ResetLocked();
103         }
104
105         virtual int OnUserRegister(User* user)
106         {
107                 if (locked)
108                 {
109                         ServerInstance->Users->QuitUser(user, "Server is temporarily closed. Please try again later.");
110                         return 1;
111                 }
112                 return 0;
113         }
114
115         virtual bool OnCheckReady(User* user)
116         {
117                 return !locked;
118         }
119
120         virtual Version GetVersion()
121         {
122                 return Version(1, 0, 0, 1, VF_VENDOR, API_VERSION);
123         }
124 };
125
126 MODULE_INIT(ModuleLockserv)