summaryrefslogtreecommitdiff
path: root/modules/pseudoclients/global.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-05-05 01:55:04 -0400
committerAdam <Adam@anope.org>2013-05-05 01:55:04 -0400
commit1d0bb9b26b7ad58ab0bf979ac046f4511b3bf12b (patch)
tree4486f0784bdf050fd7eb225c0cb9df352ce1f45a /modules/pseudoclients/global.cpp
parent781defb7076ddfddf723ca08cd0a518b6657b64f (diff)
Rework the config file reader to be much more flexible and move many configuration directives to the actual modules they are used in.
Diffstat (limited to 'modules/pseudoclients/global.cpp')
-rw-r--r--modules/pseudoclients/global.cpp48
1 files changed, 30 insertions, 18 deletions
diff --git a/modules/pseudoclients/global.cpp b/modules/pseudoclients/global.cpp
index 02b199afa..837200e5d 100644
--- a/modules/pseudoclients/global.cpp
+++ b/modules/pseudoclients/global.cpp
@@ -34,29 +34,24 @@ class MyGlobalService : public GlobalService
Anope::string rmessage;
- if (!source.empty() && !Config->AnonymousGlobal)
+ if (!source.empty() && !Config->GetModule("global")->Get<bool>("anonymousglobal"))
rmessage = "[" + source + "] " + message;
else
rmessage = message;
- this->ServerGlobal(sender, Me->GetLinks().front(), rmessage);
+ this->ServerGlobal(sender, Servers::GetUplink(), rmessage);
}
};
class GlobalCore : public Module
{
- MyGlobalService myglobalservice;
+ MyGlobalService global;
public:
GlobalCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR),
- myglobalservice(this)
+ global(this)
{
-
- Global = BotInfo::Find(Config->Global);
- if (!Global)
- throw ModuleException("No bot named " + Config->Global);
-
- Implementation i[] = { I_OnBotDelete, I_OnRestart, I_OnShutdown, I_OnNewServer, I_OnPreHelp };
+ Implementation i[] = { I_OnReload, I_OnBotDelete, I_OnRestart, I_OnShutdown, I_OnNewServer, I_OnPreHelp };
ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
}
@@ -65,6 +60,20 @@ class GlobalCore : public Module
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");
+
+ BotInfo *bi = BotInfo::Find(glnick, true);
+ if (!bi)
+ throw ConfigException(this->name + ": no bot named " + glnick);
+
+ Global = bi;
+ }
+
void OnBotDelete(BotInfo *bi) anope_override
{
if (bi == Global)
@@ -73,27 +82,30 @@ class GlobalCore : public Module
void OnRestart() anope_override
{
- if (Config->GlobalOnCycle)
- this->myglobalservice.SendGlobal(Global, "", Config->GlobalOnCycleMessage);
+ const Anope::string &gl = Config->GetModule(this)->Get<const Anope::string &>("globaloncycledown");
+ if (!gl.empty())
+ this->global.SendGlobal(Global, "", gl);
}
void OnShutdown() anope_override
{
- if (Config->GlobalOnCycle)
- this->myglobalservice.SendGlobal(Global, "", Config->GlobalOnCycleMessage);
+ const Anope::string &gl = Config->GetModule(this)->Get<const Anope::string &>("globaloncycledown");
+ if (!gl.empty())
+ this->global.SendGlobal(Global, "", gl);
}
void OnNewServer(Server *s) anope_override
{
- if (Config->GlobalOnCycle && !Config->GlobalOnCycleUP.empty())
- s->Notice(Global, Config->GlobalOnCycleUP);
+ const Anope::string &gl = Config->GetModule(this)->Get<const Anope::string &>("globaloncycleup");
+ if (!gl.empty() && !Me->IsSynced())
+ s->Notice(Global, gl);
}
EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
- if (!params.empty() || source.c || source.service->nick != Config->Global)
+ if (!params.empty() || source.c || source.service != Global)
return EVENT_CONTINUE;
- source.Reply(_("%s commands:"), Config->Global.c_str());
+ source.Reply(_("%s commands:"), Global->nick.c_str());
return EVENT_CONTINUE;
}
};