Anope IRC Services  Version 2.0
hs_del.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 CommandHSDel : public Command
15 {
16  public:
17  CommandHSDel(Module *creator) : Command(creator, "hostserv/del", 1, 1)
18  {
19  this->SetDesc(_("Delete the vhost of another user"));
20  this->SetSyntax(_("\037nick\037"));
21  }
22 
23  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
24  {
25  if (Anope::ReadOnly)
26  {
27  source.Reply(READ_ONLY_MODE);
28  return;
29  }
30 
31  const Anope::string &nick = params[0];
32  NickAlias *na = NickAlias::Find(nick);
33  if (na)
34  {
35  Log(LOG_ADMIN, source, this) << "for user " << na->nick;
36  FOREACH_MOD(OnDeleteVhost, (na));
37  na->RemoveVhost();
38  source.Reply(_("Vhost for \002%s\002 removed."), nick.c_str());
39  }
40  else
41  source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
42  }
43 
44  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
45  {
46  this->SendSyntax(source);
47  source.Reply(" ");
48  source.Reply(_("Deletes the vhost assigned to the given nick from the\n"
49  "database."));
50  return true;
51  }
52 };
53 
54 class CommandHSDelAll : public Command
55 {
56  public:
57  CommandHSDelAll(Module *creator) : Command(creator, "hostserv/delall", 1, 1)
58  {
59  this->SetDesc(_("Delete the vhost for all nicks in a group"));
60  this->SetSyntax(_("\037nick\037"));
61  }
62 
63  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
64  {
65  if (Anope::ReadOnly)
66  {
67  source.Reply(READ_ONLY_MODE);
68  return;
69  }
70 
71  const Anope::string &nick = params[0];
72  NickAlias *na = NickAlias::Find(nick);
73  if (na)
74  {
75  FOREACH_MOD(OnDeleteVhost, (na));
76  const NickCore *nc = na->nc;
77  for (unsigned i = 0; i < nc->aliases->size(); ++i)
78  {
79  na = nc->aliases->at(i);
80  na->RemoveVhost();
81  }
82  Log(LOG_ADMIN, source, this) << "for all nicks in group " << nc->display;
83  source.Reply(_("vhosts for group \002%s\002 have been removed."), nc->display.c_str());
84  }
85  else
86  source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
87  }
88 
89  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
90  {
91  this->SendSyntax(source);
92  source.Reply(" ");
93  source.Reply(_("Deletes the vhost for all nicks in the same group as\n"
94  "that of the given nick."));
95  return true;
96  }
97 };
98 
99 class HSDel : public Module
100 {
103 
104  public:
105  HSDel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
106  commandhsdel(this), commandhsdelall(this)
107  {
108 
109  }
110 };
111 
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: hs_del.cpp:23
Serialize::Reference< NickCore > nc
Definition: account.h:47
CoreExport bool ReadOnly
Definition: main.cpp:28
static NickAlias * Find(const Anope::string &nick)
Definition: nickalias.cpp:121
Serialize::Checker< std::vector< NickAlias * > > aliases
Definition: account.h:128
CommandHSDel commandhsdel
Definition: hs_del.cpp:101
HSDel(const Anope::string &modname, const Anope::string &creator)
Definition: hs_del.cpp:105
Anope::string nick
Definition: account.h:37
Definition: hs_del.cpp:99
#define NICK_X_NOT_REGISTERED
Definition: language.h:79
#define READ_ONLY_MODE
Definition: language.h:71
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
CommandHSDelAll(Module *creator)
Definition: hs_del.cpp:57
#define FOREACH_MOD(ename, args)
Definition: modules.h:62
Anope::string display
Definition: account.h:113
#define anope_override
Definition: services.h:56
CommandHSDelAll commandhsdelall
Definition: hs_del.cpp:102
#define MODULE_INIT(x)
Definition: modules.h:45
void RemoveVhost()
Definition: nickalias.cpp:88
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: hs_del.cpp:89
CommandHSDel(Module *creator)
Definition: hs_del.cpp:17
void SendSyntax(CommandSource &)
Definition: command.cpp:145
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: hs_del.cpp:63
const char * c_str() const
Definition: anope.h:117
Definition: logger.h:53
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: hs_del.cpp:44
#define _(x)
Definition: services.h:50