Anope IRC Services  Version 2.0
global.cpp
Go to the documentation of this file.
1 /* Global core functions
2  *
3  * (C) 2003-2014 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 {
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  void SendGlobal(BotInfo *sender, const Anope::string &source, const Anope::string &message) anope_override
33  {
34  if (Me->GetLinks().empty())
35  return;
36  if (!sender)
37  sender = Global;
38  if (!sender)
39  return;
40 
41  Anope::string rmessage;
42 
43  if (!source.empty() && !Config->GetModule("global")->Get<bool>("anonymousglobal"))
44  rmessage = "[" + source + "] " + message;
45  else
46  rmessage = message;
47 
48  this->ServerGlobal(sender, Servers::GetUplink(), rmessage);
49  }
50 
52  {
53  const Anope::string &glnick = conf->GetModule(this)->Get<const Anope::string>("client");
54 
55  if (glnick.empty())
56  throw ConfigException(Module::name + ": <client> must be defined");
57 
58  BotInfo *bi = BotInfo::Find(glnick, true);
59  if (!bi)
60  throw ConfigException(Module::name + ": no bot named " + glnick);
61 
62  Global = bi;
63  }
64 
66  {
67  const Anope::string &gl = Config->GetModule(this)->Get<const Anope::string>("globaloncycledown");
68  if (!gl.empty())
69  this->SendGlobal(Global, "", gl);
70  }
71 
73  {
74  const Anope::string &gl = Config->GetModule(this)->Get<const Anope::string>("globaloncycledown");
75  if (!gl.empty())
76  this->SendGlobal(Global, "", gl);
77  }
78 
80  {
81  const Anope::string &gl = Config->GetModule(this)->Get<const Anope::string>("globaloncycleup");
82  if (!gl.empty() && !Me->IsSynced())
83  s->Notice(Global, gl);
84  }
85 
86  EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
87  {
88  if (!params.empty() || source.c || source.service != *Global)
89  return EVENT_CONTINUE;
90  source.Reply(_("%s commands:"), Global->nick.c_str());
91  return EVENT_CONTINUE;
92  }
93 };
94 
96 
Definition: bots.h:24
Reference< BotInfo > Global
Definition: global.cpp:16
void Notice(BotInfo *source, const Anope::string &message)
Definition: servers.cpp:329
Definition: servers.h:42
Anope::string name
Definition: modules.h:221
bool IsSynced() const
Definition: servers.cpp:298
GlobalCore(const Anope::string &modname, const Anope::string &creator)
Definition: global.cpp:27
void OnNewServer(Server *s) anope_override
Definition: global.cpp:79
bool IsJuped() const
Definition: servers.cpp:319
EventReturn OnPreHelp(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: global.cpp:86
CoreExport Server * GetUplink()
Definition: servers.cpp:355
void OnReload(Configuration::Conf *conf) anope_override
Definition: global.cpp:51
Definition: Config.cs:26
void OnShutdown() anope_override
Definition: global.cpp:72
#define anope_override
Definition: services.h:56
bool empty() const
Definition: anope.h:126
EventReturn
Definition: modules.h:129
#define MODULE_INIT(x)
Definition: modules.h:45
const std::vector< Server * > & GetLinks() const
Definition: servers.cpp:216
Anope::string nick
Definition: users.h:62
CoreExport Server * Me
Definition: servers.cpp:24
const char * c_str() const
Definition: anope.h:117
void SendGlobal(BotInfo *sender, const Anope::string &source, const Anope::string &message) anope_override
Definition: global.cpp:32
void OnRestart() anope_override
Definition: global.cpp:65
#define _(x)
Definition: services.h:50
static BotInfo * Find(const Anope::string &nick, bool nick_only=false)
Definition: bots.cpp:249
void ServerGlobal(BotInfo *sender, Server *s, const Anope::string &message)
Definition: global.cpp:18