]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_lockserv.cpp
Remove unneeded ProtocolInterface::Introduce
[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 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.c_str(), user->server);
41                 ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used LOCKSERV to temporarily close for new connections", user->nick.c_str());
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.c_str(), user->server);
64                 ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used UNLOCKSERV to allow for new connections", user->nick.c_str());
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), lockcommand(Me, locked), unlockcommand(Me, locked)
84         {
85                 ResetLocked();
86                 ServerInstance->AddCommand(&lockcommand);
87                 ServerInstance->AddCommand(&unlockcommand);
88                 Implementation eventlist[] = { I_OnUserRegister, I_OnRehash, I_OnCheckReady };
89                 ServerInstance->Modules->Attach(eventlist, this, 3);
90         }
91
92         virtual ~ModuleLockserv()
93         {
94         }
95
96
97         virtual void OnRehash(User* user)
98         {
99                 ResetLocked();
100         }
101
102         virtual int OnUserRegister(User* user)
103         {
104                 if (locked)
105                 {
106                         ServerInstance->Users->QuitUser(user, "Server is temporarily closed. Please try again later.");
107                         return 1;
108                 }
109                 return 0;
110         }
111
112         virtual bool OnCheckReady(User* user)
113         {
114                 return !locked;
115         }
116
117         virtual Version GetVersion()
118         {
119                 return Version("$Id$", VF_VENDOR, API_VERSION);
120         }
121 };
122
123 MODULE_INIT(ModuleLockserv)