summaryrefslogtreecommitdiff
path: root/modules/pseudoclients/gl_main.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-08-05 05:35:31 -0400
committerAdam <Adam@anope.org>2011-08-05 05:35:31 -0400
commite66063e6304538d34c40460ca0aa2be5ddb6bdec (patch)
treef50fe31097160f8f794669809e4f4ef87f477672 /modules/pseudoclients/gl_main.cpp
parent9ec18a3b020932eee6242c878149c484f49b13cb (diff)
Rewrote the example configurations and split them
up into seperate files for each pseudo client. Also reorganized how the modules are stored, and made most of the old "extra" modules "core"
Diffstat (limited to 'modules/pseudoclients/gl_main.cpp')
-rw-r--r--modules/pseudoclients/gl_main.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/modules/pseudoclients/gl_main.cpp b/modules/pseudoclients/gl_main.cpp
new file mode 100644
index 000000000..c7ccf9209
--- /dev/null
+++ b/modules/pseudoclients/gl_main.cpp
@@ -0,0 +1,93 @@
+/* Global core functions
+ *
+ * (C) 2003-2011 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 "global.h"
+
+class MyGlobalService : public GlobalService
+{
+ void ServerGlobal(Server *s, const Anope::string &message)
+ {
+ if (s != Me && !s->HasFlag(SERVER_JUPED))
+ notice_server(Config->Global, s, "%s", message.c_str());
+ for (unsigned i = 0, j = s->GetLinks().size(); i < j; ++i)
+ this->ServerGlobal(s->GetLinks()[i], message);
+ }
+
+ public:
+ MyGlobalService(Module *m) : GlobalService(m) { }
+
+ void SendGlobal(BotInfo *sender, const Anope::string &source, const Anope::string &message)
+ {
+ if (Me->GetLinks().empty())
+ return;
+
+ Anope::string rmessage;
+
+ if (!source.empty() && !Config->AnonymousGlobal)
+ rmessage = "[" + source + "] " + message;
+ else
+ rmessage = message;
+
+ this->ServerGlobal(Me->GetLinks().front(), rmessage);
+ }
+};
+
+class GlobalCore : public Module
+{
+ MyGlobalService myglobalservice;
+
+ public:
+ GlobalCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
+ myglobalservice(this)
+ {
+ this->SetAuthor("Anope");
+
+ BotInfo *Global = findbot(Config->Global);
+ if (Global == NULL)
+ throw ModuleException("No bot named " + Config->Global);
+
+ ModuleManager::RegisterService(&this->myglobalservice);
+
+ Implementation i[] = { I_OnRestart, I_OnShutdown, I_OnNewServer, I_OnPreHelp };
+ ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
+ }
+
+ void OnRestart()
+ {
+ if (Config->GlobalOnCycle)
+ global->SendGlobal(findbot(Config->Global), "", Config->GlobalOnCycleMessage);
+ }
+
+ void OnShutdown()
+ {
+ if (Config->GlobalOnCycle)
+ global->SendGlobal(findbot(Config->Global), "", Config->GlobalOnCycleMessage);
+ }
+
+ void OnNewServer(Server *s)
+ {
+ if (Config->GlobalOnCycle && !Config->GlobalOnCycleUP.empty())
+ notice_server(Config->Global, s, "%s", Config->GlobalOnCycleUP.c_str());
+ }
+
+ void OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ if (!params.empty() || source.owner->nick != Config->Global)
+ return;
+ source.Reply(_("%s commands:\n"), Config->Global.c_str());
+ }
+};
+
+MODULE_INIT(GlobalCore)
+