Anope IRC Services  Version 2.0
cs_getkey.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 CommandCSGetKey : public Command
15 {
16  public:
17  CommandCSGetKey(Module *creator) : Command(creator, "chanserv/getkey", 1, 1)
18  {
19  this->SetDesc(_("Returns the key of the given channel"));
20  this->SetSyntax(_("\037channel\037"));
21  }
22 
23  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
24  {
25  const Anope::string &chan = params[0];
26 
27  ChannelInfo *ci = ChannelInfo::Find(params[0]);
28  if (ci == NULL)
29  {
30  source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
31  return;
32  }
33 
34  if (!source.AccessFor(ci).HasPriv("GETKEY") && !source.HasCommand("chanserv/getkey"))
35  {
36  source.Reply(ACCESS_DENIED);
37  return;
38  }
39 
40  Anope::string key;
41  if (!ci->c || !ci->c->GetParam("KEY", key))
42  {
43  source.Reply(_("Channel \002%s\002 has no key."), chan.c_str());
44  return;
45  }
46 
47  bool override = !source.AccessFor(ci).HasPriv("GETKEY");
48  Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci);
49 
50  source.Reply(_("Key for channel \002%s\002 is \002%s\002."), chan.c_str(), key.c_str());
51  }
52 
53  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
54  {
55  this->SendSyntax(source);
56  source.Reply(" ");
57  source.Reply(_("Returns the key of the given channel."));
58  return true;
59  }
60 };
61 
62 class CSGetKey : public Module
63 {
65 
66  public:
67  CSGetKey(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsgetkey(this)
68  {
69 
70  }
71 };
72 
Definition: hashcomp.h:84
#define ACCESS_DENIED
Definition: language.h:73
CommandCSGetKey commandcsgetkey
Definition: cs_getkey.cpp:64
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
bool GetParam(const Anope::string &name, Anope::string &target) const
Definition: channels.cpp:513
static ChannelInfo * Find(const Anope::string &name)
Definition: regchannel.cpp:630
CSGetKey(const Anope::string &modname, const Anope::string &creator)
Definition: cs_getkey.cpp:67
CommandCSGetKey(Module *creator)
Definition: cs_getkey.cpp:17
Channel * c
Definition: regchannel.h:79
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: cs_getkey.cpp:53
#define anope_override
Definition: services.h:56
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: cs_getkey.cpp:23
#define MODULE_INIT(x)
Definition: modules.h:45
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
#define CHAN_X_NOT_REGISTERED
Definition: language.h:84
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