Anope IRC Services  Version 2.0
cs_status.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 CommandCSStatus : public Command
15 {
16 public:
17  CommandCSStatus(Module *creator) : Command(creator, "chanserv/status", 1, 2)
18  {
19  this->SetDesc(_("Find a user's status on a channel"));
20  this->SetSyntax(_("\037channel\037 [\037user\037]"));
21  }
22 
23  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
24  {
25  const Anope::string &channel = params[0];
26 
27  ChannelInfo *ci = ChannelInfo::Find(channel);
28  if (ci == NULL)
29  source.Reply(CHAN_X_NOT_REGISTERED, channel.c_str());
30  else if (!source.AccessFor(ci).HasPriv("ACCESS_CHANGE") && !source.HasPriv("chanserv/auspex"))
31  source.Reply(ACCESS_DENIED);
32  else
33  {
34  Anope::string nick = source.GetNick();
35  if (params.size() > 1)
36  nick = params[1];
37 
38  AccessGroup ag;
39  User *u = User::Find(nick, true);
40  NickAlias *na = NULL;
41  if (u != NULL)
42  ag = ci->AccessFor(u);
43  else
44  {
45  na = NickAlias::Find(nick);
46  if (na != NULL)
47  ag = ci->AccessFor(na->nc);
48  }
49 
50  if (ag.super_admin)
51  source.Reply(_("\002%s\002 is a super administrator."), nick.c_str());
52  else if (ag.founder)
53  source.Reply(_("\002%s\002 is the founder of \002%s\002."), nick.c_str(), ci->name.c_str());
54  else if (ag.empty())
55  source.Reply(_("\002%s\002 has no access on \002%s\002."), nick.c_str(), ci->name.c_str());
56  else
57  {
58  source.Reply(_("Access for \002%s\002 on \002%s\002:"), nick.c_str(), ci->name.c_str());
59 
60  for (unsigned i = 0; i < ag.size(); ++i)
61  {
62  ChanAccess *acc = ag[i];
63 
64  source.Reply(_("\002%s\002 matches access entry %s, which has privilege %s."), nick.c_str(), acc->Mask().c_str(), acc->AccessSerialize().c_str());
65  }
66  }
67 
68  for (unsigned j = 0, end = ci->GetAkickCount(); j < end; ++j)
69  {
70  AutoKick *autokick = ci->GetAkick(j);
71 
72  if (autokick->nc)
73  {
74  if (na && *autokick->nc == na->nc)
75  source.Reply(_("\002%s\002 is on the auto kick list of \002%s\002 (%s)."), na->nc->display.c_str(), ci->name.c_str(), autokick->reason.c_str());
76  }
77  else if (u != NULL)
78  {
79  Entry akick_mask("", autokick->mask);
80  if (akick_mask.Matches(u))
81  source.Reply(_("\002%s\002 matches auto kick entry %s on \002%s\002 (%s)."), u->nick.c_str(), autokick->mask.c_str(), ci->name.c_str(), autokick->reason.c_str());
82  }
83  }
84  }
85  }
86 
87  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
88  {
89  this->SendSyntax(source);
90  source.Reply(" ");
91  source.Reply(_("This command tells you what a users access is on a channel\n"
92  "and what access entries, if any, they match. Additionally it\n"
93  "will tell you of any auto kick entries they match. Usage of\n"
94  "this command is limited to users who have the ability to modify\n"
95  "access entries on the channel."));
96  return true;
97  }
98 };
99 
100 class CSStatus : public Module
101 {
103 
104  public:
105  CSStatus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsstatus(this)
106  {
107  }
108 };
109 
Serialize::Reference< NickCore > nc
Definition: account.h:47
static NickAlias * Find(const Anope::string &nick)
Definition: nickalias.cpp:121
bool Matches(User *u, bool full=false) const
Definition: modes.cpp:830
Definition: hashcomp.h:84
unsigned GetAkickCount() const
Definition: regchannel.cpp:562
Anope::string name
Definition: regchannel.h:63
#define ACCESS_DENIED
Definition: language.h:73
CommandCSStatus commandcsstatus
Definition: cs_status.cpp:102
Definition: users.h:34
virtual Anope::string AccessSerialize() const =0
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: cs_status.cpp:23
bool founder
Definition: access.h:150
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
bool super_admin
Definition: access.h:150
static ChannelInfo * Find(const Anope::string &name)
Definition: regchannel.cpp:630
Anope::string reason
Definition: regchannel.h:35
const Anope::string & Mask() const
Definition: access.cpp:196
#define anope_override
Definition: services.h:56
#define MODULE_INIT(x)
Definition: modules.h:45
AutoKick * GetAkick(unsigned index) const
Definition: regchannel.cpp:552
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
AccessGroup AccessFor(const User *u)
Definition: regchannel.cpp:413
#define CHAN_X_NOT_REGISTERED
Definition: language.h:84
Anope::string nick
Definition: users.h:62
CSStatus(const Anope::string &modname, const Anope::string &creator)
Definition: cs_status.cpp:105
static User * Find(const Anope::string &name, bool nick_only=false)
Definition: users.cpp:815
Anope::string mask
Definition: regchannel.h:32
Serialize::Reference< NickCore > nc
Definition: regchannel.h:33
CommandCSStatus(Module *creator)
Definition: cs_status.cpp:17
void SendSyntax(CommandSource &)
Definition: command.cpp:145
const char * c_str() const
Definition: anope.h:117
Definition: modes.h:388
#define _(x)
Definition: services.h:50
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: cs_status.cpp:87