Anope IRC Services  Version 2.0
hs_group.cpp
Go to the documentation of this file.
1 /* HostServ 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 CommandHSGroup : public Command
15 {
16  bool setting;
17 
18  public:
19  void Sync(const NickAlias *na)
20  {
21  if (setting)
22  return;
23 
24  if (!na || !na->HasVhost())
25  return;
26 
27  setting = true;
28  for (unsigned i = 0; i < na->nc->aliases->size(); ++i)
29  {
30  NickAlias *nick = na->nc->aliases->at(i);
31  if (nick)
32  {
33  nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator());
34  FOREACH_MOD(OnSetVhost, (nick));
35  }
36  }
37  setting = false;
38  }
39 
40  CommandHSGroup(Module *creator) : Command(creator, "hostserv/group", 0, 0), setting(false)
41  {
42  this->SetDesc(_("Syncs the vhost for all nicks in a group"));
43  }
44 
45  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
46  {
47  if (Anope::ReadOnly)
48  {
49  source.Reply(READ_ONLY_MODE);
50  return;
51  }
52 
53  NickAlias *na = NickAlias::Find(source.GetNick());
54  if (na && source.GetAccount() == na->nc && na->HasVhost())
55  {
56  this->Sync(na);
57  if (!na->GetVhostIdent().empty())
58  source.Reply(_("All vhost's in the group \002%s\002 have been set to \002%s\002@\002%s\002."), source.nc->display.c_str(), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str());
59  else
60  source.Reply(_("All vhost's in the group \002%s\002 have been set to \002%s\002."), source.nc->display.c_str(), na->GetVhostHost().c_str());
61  }
62  else
63  source.Reply(HOST_NOT_ASSIGNED);
64 
65  return;
66  }
67 
68  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
69  {
70  this->SendSyntax(source);
71  source.Reply(" ");
72  source.Reply(_("This command allows users to set the vhost of their\n"
73  "CURRENT nick to be the vhost for all nicks in the same\n"
74  "group."));
75  return true;
76  }
77 };
78 
79 class HSGroup : public Module
80 {
83  bool synconset;
84 
85  public:
86  HSGroup(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
87  commandhsgroup(this)
88  {
89  }
90 
92  {
93  if (!synconset)
94  return;
95 
96  commandhsgroup.Sync(na);
97  }
98 
100  {
101  if (!syncongroup)
102  return;
103 
104  commandhsgroup.Sync(na);
105  }
106 
108  {
109  Configuration::Block *block = conf->GetModule(this);
110  syncongroup = block->Get<bool>("syncongroup");
111  synconset = block->Get<bool>("synconset");
112  }
113 };
114 
Serialize::Reference< NickCore > nc
Definition: account.h:47
CoreExport bool ReadOnly
Definition: main.cpp:28
void OnSetVhost(NickAlias *na) anope_override
Definition: hs_group.cpp:91
static NickAlias * Find(const Anope::string &nick)
Definition: nickalias.cpp:121
CommandHSGroup(Module *creator)
Definition: hs_group.cpp:40
const Anope::string & GetVhostHost() const
Definition: nickalias.cpp:106
bool HasVhost() const
Definition: nickalias.cpp:96
void OnNickGroup(User *u, NickAlias *na) anope_override
Definition: hs_group.cpp:99
Definition: users.h:34
bool synconset
Definition: hs_group.cpp:83
#define READ_ONLY_MODE
Definition: language.h:71
HSGroup(const Anope::string &modname, const Anope::string &creator)
Definition: hs_group.cpp:86
void Sync(const NickAlias *na)
Definition: hs_group.cpp:19
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: hs_group.cpp:45
#define FOREACH_MOD(ename, args)
Definition: modules.h:62
bool syncongroup
Definition: hs_group.cpp:82
#define HOST_NOT_ASSIGNED
Definition: language.h:127
void OnReload(Configuration::Conf *conf) anope_override
Definition: hs_group.cpp:107
CommandHSGroup commandhsgroup
Definition: hs_group.cpp:81
#define anope_override
Definition: services.h:56
bool empty() const
Definition: anope.h:126
#define MODULE_INIT(x)
Definition: modules.h:45
const Anope::string & GetVhostCreator() const
Definition: nickalias.cpp:111
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: hs_group.cpp:68
void SendSyntax(CommandSource &)
Definition: command.cpp:145
const char * c_str() const
Definition: anope.h:117
void SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created=Anope::CurTime)
Definition: nickalias.cpp:80
T Get(const Anope::string &tag)
Definition: config.h:44
#define _(x)
Definition: services.h:50
const Anope::string & GetVhostIdent() const
Definition: nickalias.cpp:101