anope

- supernets anope source code & configuration
git clone git://git.acid.vegas/anope.git
Log | Files | Refs | Archive | README

global.cpp (2646B)

      1 /* Global core functions
      2  *
      3  * (C) 2003-2022 Anope Team
      4  * Contact us at team@anope.org
      5  *
      6  * Please read COPYING and README for further details.
      7  *
      8  * Based on the original code of Epona by Lara.
      9  * Based on the original code of Services by Andy Church.
     10  */
     11 
     12 #include "module.h"
     13 
     14 class GlobalCore : public Module, public GlobalService
     15 {
     16 	Reference<BotInfo> Global;
     17 
     18 	void ServerGlobal(BotInfo *sender, Server *s, const Anope::string &message)
     19 	{
     20 		if (s != Me && !s->IsJuped())
     21 			s->Notice(sender, message);
     22 		for (unsigned i = 0, j = s->GetLinks().size(); i < j; ++i)
     23 			this->ServerGlobal(sender, s->GetLinks()[i], message);
     24 	}
     25 
     26  public:
     27 	GlobalCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR),
     28 		GlobalService(this)
     29 	{
     30 	}
     31 
     32 	Reference<BotInfo> GetDefaultSender() anope_override
     33 	{
     34 		return Global;
     35 	}
     36 
     37 	void SendGlobal(BotInfo *sender, const Anope::string &source, const Anope::string &message) anope_override
     38 	{
     39 		if (Me->GetLinks().empty())
     40 			return;
     41 		if (!sender)
     42 			sender = Global;
     43 		if (!sender)
     44 			return;
     45 
     46 		Anope::string rmessage;
     47 
     48 		if (!source.empty() && !Config->GetModule("global")->Get<bool>("anonymousglobal"))
     49 			rmessage = "[" + source + "] " + message;
     50 		else
     51 			rmessage = message;
     52 
     53 		this->ServerGlobal(sender, Servers::GetUplink(), rmessage);
     54 	}
     55 
     56 	void OnReload(Configuration::Conf *conf) anope_override
     57 	{
     58 		const Anope::string &glnick = conf->GetModule(this)->Get<const Anope::string>("client");
     59 
     60 		if (glnick.empty())
     61 			throw ConfigException(Module::name + ": <client> must be defined");
     62 
     63 		BotInfo *bi = BotInfo::Find(glnick, true);
     64 		if (!bi)
     65 			throw ConfigException(Module::name + ": no bot named " + glnick);
     66 
     67 		Global = bi;
     68 	}
     69 
     70 	void OnRestart() anope_override
     71 	{
     72 		const Anope::string &gl = Config->GetModule(this)->Get<const Anope::string>("globaloncycledown");
     73 		if (!gl.empty())
     74 			this->SendGlobal(Global, "", gl);
     75 	}
     76 
     77 	void OnShutdown() anope_override
     78 	{
     79 		const Anope::string &gl = Config->GetModule(this)->Get<const Anope::string>("globaloncycledown");
     80 		if (!gl.empty())
     81 			this->SendGlobal(Global, "", gl);
     82 	}
     83 
     84 	void OnNewServer(Server *s) anope_override
     85 	{
     86 		const Anope::string &gl = Config->GetModule(this)->Get<const Anope::string>("globaloncycleup");
     87 		if (!gl.empty() && !Me->IsSynced())
     88 			s->Notice(Global, gl);
     89 	}
     90 
     91 	EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     92 	{
     93 		if (!params.empty() || source.c || source.service != *Global)
     94 			return EVENT_CONTINUE;
     95 		source.Reply(_("%s commands:"), Global->nick.c_str());
     96 		return EVENT_CONTINUE;
     97 	}
     98 };
     99 
    100 MODULE_INIT(GlobalCore)