diff options
author | Adam <Adam@anope.org> | 2013-05-26 17:13:11 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2013-05-26 17:13:11 -0400 |
commit | 22658d63bdb1e52a66f4514af45fa55ca5891345 (patch) | |
tree | 673304ab19f7e077b489354248247867518331f8 /modules/pseudoclients/global.cpp | |
parent | f2dee1e1d642b07947f59f91dfba9af34ef84685 (diff) |
Get rid of the remaining references in the core to specific services. Move more stuff out of the core to the proper modules.
Diffstat (limited to 'modules/pseudoclients/global.cpp')
-rw-r--r-- | modules/pseudoclients/global.cpp | 51 |
1 files changed, 18 insertions, 33 deletions
diff --git a/modules/pseudoclients/global.cpp b/modules/pseudoclients/global.cpp index 67cb594c5..224cbeea1 100644 --- a/modules/pseudoclients/global.cpp +++ b/modules/pseudoclients/global.cpp @@ -9,12 +9,12 @@ * Based on the original code of Services by Andy Church. */ -/*************************************************************************/ - #include "module.h" -class MyGlobalService : public GlobalService +class GlobalCore : public Module, public GlobalService { + Reference<BotInfo> Global; + void ServerGlobal(const BotInfo *sender, Server *s, const Anope::string &message) { if (s != Me && !s->IsJuped()) @@ -24,12 +24,21 @@ class MyGlobalService : public GlobalService } public: - MyGlobalService(Module *m) : GlobalService(m) { } + GlobalCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR), + GlobalService(this) + { + Implementation i[] = { I_OnReload, I_OnRestart, I_OnShutdown, I_OnNewServer, I_OnPreHelp }; + ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); + } void SendGlobal(const BotInfo *sender, const Anope::string &source, const Anope::string &message) anope_override { if (Me->GetLinks().empty()) return; + if (!sender) + sender = Global; + if (!sender) + return; Anope::string rmessage; @@ -40,57 +49,33 @@ class MyGlobalService : public GlobalService this->ServerGlobal(sender, Servers::GetUplink(), rmessage); } -}; - -class GlobalCore : public Module -{ - MyGlobalService global; - - public: - GlobalCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR), - global(this) - { - Implementation i[] = { I_OnReload, I_OnBotDelete, I_OnRestart, I_OnShutdown, I_OnNewServer, I_OnPreHelp }; - ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - } - - ~GlobalCore() - { - Global = NULL; - } void OnReload(Configuration::Conf *conf) anope_override { const Anope::string &glnick = conf->GetModule(this)->Get<const Anope::string>("client"); if (glnick.empty()) - throw ConfigException(this->name + ": <client> must be defined"); + throw ConfigException(Module::name + ": <client> must be defined"); BotInfo *bi = BotInfo::Find(glnick, true); if (!bi) - throw ConfigException(this->name + ": no bot named " + glnick); + throw ConfigException(Module::name + ": no bot named " + glnick); Global = bi; } - void OnBotDelete(BotInfo *bi) anope_override - { - if (bi == Global) - Global = NULL; - } - void OnRestart() anope_override { const Anope::string &gl = Config->GetModule(this)->Get<const Anope::string>("globaloncycledown"); if (!gl.empty()) - this->global.SendGlobal(Global, "", gl); + this->SendGlobal(Global, "", gl); } void OnShutdown() anope_override { const Anope::string &gl = Config->GetModule(this)->Get<const Anope::string>("globaloncycledown"); if (!gl.empty()) - this->global.SendGlobal(Global, "", gl); + this->SendGlobal(Global, "", gl); } void OnNewServer(Server *s) anope_override @@ -102,7 +87,7 @@ class GlobalCore : public Module EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override { - if (!params.empty() || source.c || source.service != Global) + if (!params.empty() || source.c || source.service != *Global) return EVENT_CONTINUE; source.Reply(_("%s commands:"), Global->nick.c_str()); return EVENT_CONTINUE; |