diff options
| author | Adam <Adam@anope.org> | 2015-12-14 16:52:24 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2015-12-14 16:52:24 -0500 |
| commit | 6302f980fe6dad83aab7d2dc1046dadea5ffd939 (patch) | |
| tree | 4c27d33f55fc32ce34827977932dac4b3e5ceedd /modules/global | |
| parent | 64dac60071fab652745a6e7a06cf6b7bdbbd3625 (diff) | |
New source tree structure for modules. From commands/cs_access => chanserv/access etc.
Diffstat (limited to 'modules/global')
| -rw-r--r-- | modules/global/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | modules/global/global.cpp | 58 | ||||
| -rw-r--r-- | modules/global/main/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | modules/global/main/global.cpp | 107 |
4 files changed, 167 insertions, 0 deletions
diff --git a/modules/global/CMakeLists.txt b/modules/global/CMakeLists.txt new file mode 100644 index 000000000..cd225a94d --- /dev/null +++ b/modules/global/CMakeLists.txt @@ -0,0 +1 @@ +build_modules(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/modules/global/global.cpp b/modules/global/global.cpp new file mode 100644 index 000000000..d6106b2be --- /dev/null +++ b/modules/global/global.cpp @@ -0,0 +1,58 @@ +/* Global core functions + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +#include "module.h" +#include "modules/global.h" + +class CommandGLGlobal : public Command +{ + public: + CommandGLGlobal(Module *creator) : Command(creator, "global/global", 1, 1) + { + this->SetDesc(_("Send a message to all users")); + this->SetSyntax(_("\037message\037")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + const Anope::string &msg = params[0]; + + if (!Global::service) + { + source.Reply("No global reference, is global loaded?"); + return; + } + + Log(LOG_ADMIN, source, this); + Global::service->SendGlobal(NULL, source.GetNick(), msg); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Allows Services Operators to send a message to all users on the network." + " The message will be sent from \002{0}\002."), source.service->nick); + return true; + } +}; + +class GLGlobal : public Module +{ + CommandGLGlobal commandglglobal; + + public: + GLGlobal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandglglobal(this) + { + + } +}; + +MODULE_INIT(GLGlobal) diff --git a/modules/global/main/CMakeLists.txt b/modules/global/main/CMakeLists.txt new file mode 100644 index 000000000..781f0ef1f --- /dev/null +++ b/modules/global/main/CMakeLists.txt @@ -0,0 +1 @@ +build_subdir(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/modules/global/main/global.cpp b/modules/global/main/global.cpp new file mode 100644 index 000000000..f31605acb --- /dev/null +++ b/modules/global/main/global.cpp @@ -0,0 +1,107 @@ +/* Global core functions + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +#include "module.h" +#include "modules/help.h" +#include "modules/global.h" + +class GlobalCore : public Module + , public Global::GlobalService + , public EventHook<Event::Restart> + , public EventHook<Event::Shutdown> + , public EventHook<Event::NewServer> + , public EventHook<Event::Help> +{ + Reference<ServiceBot> Global; + + void ServerGlobal(ServiceBot *sender, Server *s, const Anope::string &message) + { + if (s != Me && !s->IsJuped()) + s->Notice(sender, message); + for (unsigned i = 0, j = s->GetLinks().size(); i < j; ++i) + this->ServerGlobal(sender, s->GetLinks()[i], message); + } + + public: + GlobalCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , GlobalService(this) + { + } + + void SendGlobal(ServiceBot *sender, const Anope::string &source, const Anope::string &message) override + { + if (Me->GetLinks().empty()) + return; + if (!sender) + sender = Global; + if (!sender) + return; + + Anope::string rmessage; + + if (!source.empty() && !Config->GetModule("global")->Get<bool>("anonymousglobal")) + rmessage = "[" + source + "] " + message; + else + rmessage = message; + + this->ServerGlobal(sender, Servers::GetUplink(), rmessage); + } + + void OnReload(Configuration::Conf *conf) override + { + const Anope::string &glnick = conf->GetModule(this)->Get<Anope::string>("client"); + + if (glnick.empty()) + throw ConfigException(Module::name + ": <client> must be defined"); + + ServiceBot *bi = ServiceBot::Find(glnick, true); + if (!bi) + throw ConfigException(Module::name + ": no bot named " + glnick); + + Global = bi; + } + + void OnRestart() override + { + const Anope::string &gl = Config->GetModule(this)->Get<Anope::string>("globaloncycledown"); + if (!gl.empty()) + this->SendGlobal(Global, "", gl); + } + + void OnShutdown() override + { + const Anope::string &gl = Config->GetModule(this)->Get<Anope::string>("globaloncycledown"); + if (!gl.empty()) + this->SendGlobal(Global, "", gl); + } + + void OnNewServer(Server *s) override + { + const Anope::string &gl = Config->GetModule(this)->Get<Anope::string>("globaloncycleup"); + if (!gl.empty() && !Me->IsSynced()) + s->Notice(Global, gl); + } + + EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + if (!params.empty() || source.c || source.service != *Global) + return EVENT_CONTINUE; + source.Reply(_("%s commands:"), Global->nick.c_str()); + return EVENT_CONTINUE; + } + + void OnPostHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + } +}; + +MODULE_INIT(GlobalCore) + |
