]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_lockserv.cpp
More AddModes fixes
[user/henk/code/inspircd.git] / src / modules / m_lockserv.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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 char** parameters, int pcnt, User *user)
38         {
39                 locked = true;
40                 user->WriteServ("988 %s %s :Closed for new connections", user->nick, user->server);
41                 ServerInstance->WriteOpers("*** 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 char** parameters, int pcnt, User *user)
61         {
62                 locked = false;
63                 user->WriteServ("989 %s %s :Open for new connections", user->nick, user->server);
64                 ServerInstance->WriteOpers("*** 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         }
92
93         virtual ~ModuleLockserv()
94         {
95         }
96
97         void Implements(char* List)
98         {
99                 List[I_OnUserRegister] = List[I_OnRehash] = List[I_OnCheckReady] = 1;
100         }
101
102         virtual void OnRehash(User* user, const std::string &parameter)
103         {
104                 ResetLocked();
105         }
106
107         virtual int OnUserRegister(User* user)
108         {
109                 if (locked)
110                 {
111                         User::QuitUser(ServerInstance, user, "Server is temporarily closed. Please try again later.");
112                         return 1;
113                 }
114                 return 0;
115         }
116
117         virtual bool OnCheckReady(User* user)
118         {
119                 return !locked;
120         }
121
122         virtual Version GetVersion()
123         {
124                 return Version(1, 0, 0, 1, VF_VENDOR, API_VERSION);
125         }
126 };
127
128 MODULE_INIT(ModuleLockserv)