From 484160eb4ed560eeda97c94a42dd8e31431ab251 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 24 Jan 2024 12:34:03 +0000 Subject: Shuffle modules around a bit. --- modules/global/gl_global.cpp | 68 +++++++++++++++++++++++++++++ modules/global/global.cpp | 102 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 modules/global/gl_global.cpp create mode 100644 modules/global/global.cpp (limited to 'modules/global') diff --git a/modules/global/gl_global.cpp b/modules/global/gl_global.cpp new file mode 100644 index 000000000..edfaa21a5 --- /dev/null +++ b/modules/global/gl_global.cpp @@ -0,0 +1,68 @@ +/* Global core functions + * + * (C) 2003-2024 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" + +class CommandGLGlobal final + : public Command +{ + ServiceReference GService; + +public: + CommandGLGlobal(Module *creator) : Command(creator, "global/global", 1, 1), GService("GlobalService", "Global") + { + this->SetDesc(_("Send a message to all users")); + this->SetSyntax(_("\037message\037")); + } + + void Execute(CommandSource &source, const std::vector ¶ms) override + { + const Anope::string &msg = params[0]; + + if (!GService) + source.Reply("No global reference, is global loaded?"); + else + { + Log(LOG_ADMIN, source, this); + GService->SendGlobal(NULL, source.GetNick(), msg); + } + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + Reference sender; + if (GService) + sender = GService->GetDefaultSender(); + if (!sender) + sender = source.service; + + this->SendSyntax(source); + source.Reply(" "); + source.Reply(_("Allows Administrators to send messages to all users on the\n" + "network. The message will be sent from the nick \002%s\002."), sender->nick.c_str()); + return true; + } +}; + +class GLGlobal final + : 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/global.cpp b/modules/global/global.cpp new file mode 100644 index 000000000..a5288d754 --- /dev/null +++ b/modules/global/global.cpp @@ -0,0 +1,102 @@ +/* Global core functions + * + * (C) 2003-2024 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" + +class GlobalCore final + : public Module + , public GlobalService +{ + Reference Global; + + void ServerGlobal(BotInfo *sender, Server *s, const Anope::string &message) + { + if (s != Me && !s->IsJuped()) + s->Notice(sender, message); + for (auto *link : s->GetLinks()) + this->ServerGlobal(sender, link, message); + } + +public: + GlobalCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR), + GlobalService(this) + { + } + + Reference GetDefaultSender() override + { + return Global; + } + + void SendGlobal(BotInfo *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("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("client"); + + if (glnick.empty()) + throw ConfigException(Module::name + ": must be defined"); + + BotInfo *bi = BotInfo::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("globaloncycledown"); + if (!gl.empty()) + this->SendGlobal(Global, "", gl); + } + + void OnShutdown() override + { + const Anope::string &gl = Config->GetModule(this)->Get("globaloncycledown"); + if (!gl.empty()) + this->SendGlobal(Global, "", gl); + } + + void OnNewServer(Server *s) override + { + const Anope::string &gl = Config->GetModule(this)->Get("globaloncycleup"); + if (!gl.empty() && !Me->IsSynced()) + s->Notice(Global, gl); + } + + EventReturn OnPreHelp(CommandSource &source, const std::vector ¶ms) override + { + if (!params.empty() || source.c || source.service != *Global) + return EVENT_CONTINUE; + source.Reply(_("%s commands:"), Global->nick.c_str()); + return EVENT_CONTINUE; + } +}; + +MODULE_INIT(GlobalCore) -- cgit