anope

- supernets anope source code & configuration
git clone git://git.acid.vegas/anope.git
Log | Files | Refs | Archive | README

os_shutdown.cpp (2977B)

      1 /* OperServ core functions
      2  *
      3  * (C) 2003-2022 Anope Team
      4  * Contact us at team@anope.org
      5  *
      6  * Please read COPYING and README for further details.
      7  *
      8  * Based on the original code of Epona by Lara.
      9  * Based on the original code of Services by Andy Church.
     10  */
     11 
     12 #include "module.h"
     13 
     14 class CommandOSQuit : public Command
     15 {
     16  public:
     17 	CommandOSQuit(Module *creator) : Command(creator, "operserv/quit", 0, 0)
     18 	{
     19 		this->SetDesc(_("Terminate Services WITHOUT saving"));
     20 	}
     21 
     22 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     23 	{
     24 		Log(LOG_ADMIN, source, this);
     25 		Anope::QuitReason = source.command + " command received from " + source.GetNick();
     26 		Anope::Quitting = true;
     27 		return;
     28 	}
     29 
     30 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
     31 	{
     32 		this->SendSyntax(source);
     33 		source.Reply(" ");
     34 		source.Reply(_("Causes Services to do an immediate shutdown; databases are\n"
     35 				"\002not\002 saved.  This command should not be used unless\n"
     36 				"damage to the in-memory copies of the databases is feared\n"
     37 				"and they should not be saved."));
     38 		return true;
     39 	}
     40 };
     41 
     42 class CommandOSRestart : public Command
     43 {
     44  public:
     45 	CommandOSRestart(Module *creator) : Command(creator, "operserv/restart", 0, 0)
     46 	{
     47 		this->SetDesc(_("Save databases and restart Services"));
     48 	}
     49 
     50 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     51 	{
     52 		Log(LOG_ADMIN, source, this);
     53 		Anope::QuitReason = source.command + " command received from " + source.GetNick();
     54 		Anope::Quitting = Anope::Restarting = true;
     55 		Anope::SaveDatabases();
     56 		return;
     57 	}
     58 
     59 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
     60 	{
     61 		this->SendSyntax(source);
     62 		source.Reply(_("Causes Services to save all databases and then restart\n"
     63 				"(i.e. exit and immediately re-run the executable)."));
     64 		return true;
     65 	}
     66 };
     67 
     68 class CommandOSShutdown : public Command
     69 {
     70  public:
     71 	CommandOSShutdown(Module *creator) : Command(creator, "operserv/shutdown", 0, 0)
     72 	{
     73 		this->SetDesc(_("Terminate services with save"));
     74 	}
     75 
     76 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     77 	{
     78 		Log(LOG_ADMIN, source, this);
     79 		Anope::QuitReason = source.command + " command received from " + source.GetNick();
     80 		Anope::Quitting = true;
     81 		Anope::SaveDatabases();
     82 		return;
     83 	}
     84 
     85 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
     86 	{
     87 		this->SendSyntax(source);
     88 		source.Reply(" ");
     89 		source.Reply(_("Causes Services to save all databases and then shut down."));
     90 		return true;
     91 	}
     92 };
     93 
     94 class OSShutdown : public Module
     95 {
     96 	CommandOSQuit commandosquit;
     97 	CommandOSRestart commandosrestart;
     98 	CommandOSShutdown commandosshutdown;
     99 
    100  public:
    101 	OSShutdown(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
    102 		commandosquit(this), commandosrestart(this), commandosshutdown(this)
    103 	{
    104 
    105 	}
    106 };
    107 
    108 MODULE_INIT(OSShutdown)