The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

m_lockserv.cpp

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #include "inspircd.h"
00015 
00016 /* $ModDesc: Allows locking of the server to stop all incoming connections till unlocked again */
00017 
00024 class CommandLockserv : public Command
00025 {
00026 private:
00027         bool& locked;
00028 
00029 public:
00030         CommandLockserv (InspIRCd* Instance, bool &lock)
00031         : Command(Instance, "LOCKSERV", "o", 0), locked(lock)
00032         {
00033                 this->source = "m_lockserv.so";
00034                 syntax.clear();
00035         }
00036 
00037         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
00038         {
00039                 locked = true;
00040                 user->WriteNumeric(988, "%s %s :Closed for new connections", user->nick.c_str(), user->server);
00041                 ServerInstance->SNO->WriteToSnoMask('A', "Oper %s used LOCKSERV to temporarily close for new connections", user->nick.c_str());
00042                 /* Dont send to the network */
00043                 return CMD_LOCALONLY;
00044         }
00045 };
00046 
00047 class CommandUnlockserv : public Command
00048 {
00049 private:
00050         bool& locked;
00051 
00052 public:
00053         CommandUnlockserv (InspIRCd* Instance, bool &lock)
00054         : Command(Instance, "UNLOCKSERV", "o", 0), locked(lock)
00055         {
00056                 this->source = "m_lockserv.so";
00057                 syntax.clear();
00058         }
00059 
00060         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
00061         {
00062                 locked = false;
00063                 user->WriteNumeric(989, "%s %s :Open for new connections", user->nick.c_str(), user->server);
00064                 ServerInstance->SNO->WriteToSnoMask('A', "Oper %s used UNLOCKSERV to allow for new connections", user->nick.c_str());
00065                 /* Dont send to the network */
00066                 return CMD_LOCALONLY;
00067         }
00068 };
00069 
00070 class ModuleLockserv : public Module
00071 {
00072 private:
00073         bool locked;
00074         CommandLockserv* lockcommand;
00075         CommandUnlockserv* unlockcommand;
00076 
00077         virtual void ResetLocked()
00078         {
00079                 locked = false;
00080         }
00081 
00082 public:
00083         ModuleLockserv(InspIRCd* Me) : Module(Me)
00084         {
00085                 ResetLocked();
00086                 lockcommand = new CommandLockserv(ServerInstance, locked);
00087                 ServerInstance->AddCommand(lockcommand);
00088 
00089                 unlockcommand = new CommandUnlockserv(ServerInstance, locked);
00090                 ServerInstance->AddCommand(unlockcommand);
00091                 Implementation eventlist[] = { I_OnUserRegister, I_OnRehash, I_OnCheckReady };
00092                 ServerInstance->Modules->Attach(eventlist, this, 3);
00093         }
00094 
00095         virtual ~ModuleLockserv()
00096         {
00097         }
00098 
00099 
00100         virtual void OnRehash(User* user, const std::string &parameter)
00101         {
00102                 ResetLocked();
00103         }
00104 
00105         virtual int OnUserRegister(User* user)
00106         {
00107                 if (locked)
00108                 {
00109                         ServerInstance->Users->QuitUser(user, "Server is temporarily closed. Please try again later.");
00110                         return 1;
00111                 }
00112                 return 0;
00113         }
00114 
00115         virtual bool OnCheckReady(User* user)
00116         {
00117                 return !locked;
00118         }
00119 
00120         virtual Version GetVersion()
00121         {
00122                 return Version("$Id: m_lockserv.cpp 10291 2008-08-25 20:35:51Z w00t $", VF_VENDOR, API_VERSION);
00123         }
00124 };
00125 
00126 MODULE_INIT(ModuleLockserv)