Anope IRC Services  Version 2.0
cs_unban.cpp
Go to the documentation of this file.
1 /* ChanServ 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 CommandCSUnban : public Command
15 {
16  public:
17  CommandCSUnban(Module *creator) : Command(creator, "chanserv/unban", 0, 2)
18  {
19  this->SetDesc(_("Remove all bans preventing a user from entering a channel"));
20  this->SetSyntax(_("\037channel\037 [\037nick\037]"));
21  }
22 
23  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
24  {
26  if (!cm)
27  return;
28 
29  std::vector<ChannelMode *> modes = cm->listeners;
30  modes.push_back(cm);
31 
32  if (params.empty())
33  {
34  if (!source.GetUser())
35  return;
36 
37  std::deque<ChannelInfo *> queue;
38  source.GetAccount()->GetChannelReferences(queue);
39 
40  unsigned count = 0;
41  for (unsigned i = 0; i < queue.size(); ++i)
42  {
43  ChannelInfo *ci = queue[i];
44 
45  if (!ci->c || !source.AccessFor(ci).HasPriv("UNBAN"))
46  continue;
47 
48  for (unsigned j = 0; j < modes.size(); ++j)
49  if (ci->c->Unban(source.GetUser(), modes[j]->name, true))
50  ++count;
51  }
52 
53  Log(LOG_COMMAND, source, this, NULL) << "on all channels";
54  source.Reply(_("You have been unbanned from %d channels."), count);
55 
56  return;
57  }
58 
59  ChannelInfo *ci = ChannelInfo::Find(params[0]);
60  if (ci == NULL)
61  {
62  source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
63  return;
64  }
65 
66  if (ci->c == NULL)
67  {
68  source.Reply(CHAN_X_NOT_IN_USE, ci->name.c_str());
69  return;
70  }
71 
72  if (!source.AccessFor(ci).HasPriv("UNBAN") && !source.HasPriv("chanserv/kick"))
73  {
74  source.Reply(ACCESS_DENIED);
75  return;
76  }
77 
78  User *u2 = source.GetUser();
79  if (params.size() > 1)
80  u2 = User::Find(params[1], true);
81 
82  if (!u2)
83  {
84  source.Reply(NICK_X_NOT_IN_USE, params[1].c_str());
85  return;
86  }
87 
88  bool override = !source.AccessFor(ci).HasPriv("UNBAN") && source.HasPriv("chanserv/kick");
89  Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to unban " << u2->nick;
90 
91  for (unsigned i = 0; i < modes.size(); ++i)
92  ci->c->Unban(u2, modes[i]->name, source.GetUser() == u2);
93  if (u2 == source.GetUser())
94  source.Reply(_("You have been unbanned from \002%s\002."), ci->c->name.c_str());
95  else
96  source.Reply(_("\002%s\002 has been unbanned from \002%s\002."), u2->nick.c_str(), ci->c->name.c_str());
97  }
98 
99  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
100  {
101  this->SendSyntax(source);
102  source.Reply(" ");
103  source.Reply(_("Tells %s to remove all bans preventing you or the given\n"
104  "user from entering the given channel. If no channel is\n"
105  "given, all bans affecting you in channels you have access\n"
106  "in are removed.\n"
107  " \n"
108  "By default, limited to AOPs or those with level 5 and above\n"
109  "on the channel."), source.service->nick.c_str());
110  return true;
111  }
112 };
113 
114 class CSUnban : public Module
115 {
117 
118  public:
119  CSUnban(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
120  commandcsunban(this)
121  {
122 
123  }
124 };
125 
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: cs_unban.cpp:23
static ChannelMode * FindChannelModeByName(const Anope::string &name)
Definition: modes.cpp:542
Definition: hashcomp.h:84
Anope::string name
Definition: regchannel.h:63
#define CHAN_X_NOT_IN_USE
Definition: language.h:85
CommandCSUnban commandcsunban
Definition: cs_unban.cpp:116
#define ACCESS_DENIED
Definition: language.h:73
Definition: users.h:34
CommandCSUnban(Module *creator)
Definition: cs_unban.cpp:17
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
Anope::string name
Definition: channels.h:44
static ChannelInfo * Find(const Anope::string &name)
Definition: regchannel.cpp:630
std::vector< ChannelMode * > listeners
Definition: modes.h:100
#define NICK_X_NOT_IN_USE
Definition: language.h:80
bool Unban(User *u, const Anope::string &mode, bool full=false)
Definition: channels.cpp:868
Channel * c
Definition: regchannel.h:79
bool HasPriv(const Anope::string &privstr)
Definition: users.cpp:487
static Anope::map< std::pair< bool, Anope::string > > modes
Definition: cs_mode.cpp:745
#define anope_override
Definition: services.h:56
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: cs_unban.cpp:99
#define MODULE_INIT(x)
Definition: modules.h:45
CSUnban(const Anope::string &modname, const Anope::string &creator)
Definition: cs_unban.cpp:119
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
#define CHAN_X_NOT_REGISTERED
Definition: language.h:84
Anope::string nick
Definition: users.h:62
static User * Find(const Anope::string &name, bool nick_only=false)
Definition: users.cpp:815
void SendSyntax(CommandSource &)
Definition: command.cpp:145
const char * c_str() const
Definition: anope.h:117
Definition: logger.h:53
#define _(x)
Definition: services.h:50