Anope IRC Services  Version 2.0
cs_drop.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 CommandCSDrop : public Command
15 {
16  public:
17  CommandCSDrop(Module *creator) : Command(creator, "chanserv/drop", 1, 2)
18  {
19  this->SetDesc(_("Cancel the registration of a channel"));
20  this->SetSyntax(_("\037channel\037 \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  if (Anope::ReadOnly && !source.HasPriv("chanserv/administration"))
28  {
29  source.Reply(_("Sorry, channel de-registration is temporarily disabled.")); // XXX: READ_ONLY_MODE?
30  return;
31  }
32 
34  if (ci == NULL)
35  {
36  source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
37  return;
38  }
39 
40  if (params.size() < 2 || !chan.equals_ci(params[1]))
41  {
42  source.Reply(_("You must enter the channel name twice as a confirmation that you wish to drop \002%s\002."), chan.c_str());
43  return;
44  }
45 
46  if ((ci->HasExt("SECUREFOUNDER") ? !source.IsFounder(ci) : !source.AccessFor(ci).HasPriv("FOUNDER")) && !source.HasCommand("chanserv/drop"))
47  {
48  source.Reply(ACCESS_DENIED);
49  return;
50  }
51 
52  EventReturn MOD_RESULT;
53  FOREACH_RESULT(OnChanDrop, MOD_RESULT, (source, ci));
54  if (MOD_RESULT == EVENT_STOP)
55  return;
56 
57  bool override = (ci->HasExt("SECUREFOUNDER") ? !source.IsFounder(ci) : !source.AccessFor(ci).HasPriv("FOUNDER"));
58  Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "(founder was: " << (ci->GetFounder() ? ci->GetFounder()->display : "none") << ")";
59 
60  Reference<Channel> c = ci->c;
61  delete ci;
62 
63  source.Reply(_("Channel \002%s\002 has been dropped."), chan.c_str());
64 
65  if (c)
66  c->CheckModes();
67  }
68 
69  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
70  {
71  this->SendSyntax(source);
72  source.Reply(" ");
73  if (source.IsServicesOper())
74  source.Reply(_("Unregisters the named channel. Only \002Services Operators\002\n"
75  "can drop a channel of which they are not the founder."));
76  else
77  source.Reply(_("Unregisters the named channel. Can only be used by\n"
78  "the \002channel founder\002."));
79 
80  return true;
81  }
82 };
83 
84 class CSDrop : public Module
85 {
87 
88  public:
89  CSDrop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsdrop(this)
90  {
91 
92  }
93 };
94 
CoreExport bool ReadOnly
Definition: main.cpp:28
Definition: hashcomp.h:84
#define ACCESS_DENIED
Definition: language.h:73
CommandCSDrop(Module *creator)
Definition: cs_drop.cpp:17
CommandCSDrop commandcsdrop
Definition: cs_drop.cpp:86
#define FOREACH_RESULT(ename, ret, args)
Definition: modules.h:95
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
bool equals_ci(const char *_str) const
Definition: anope.h:78
CSDrop(const Anope::string &modname, const Anope::string &creator)
Definition: cs_drop.cpp:89
static ChannelInfo * Find(const Anope::string &name)
Definition: regchannel.cpp:630
void CheckModes()
Definition: channels.cpp:105
NickCore * GetFounder() const
Definition: regchannel.cpp:364
Channel * c
Definition: regchannel.h:79
Anope::string display
Definition: account.h:113
#define anope_override
Definition: services.h:56
EventReturn
Definition: modules.h:129
#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
bool HasExt(const Anope::string &name) const
Definition: extensible.cpp:31
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: cs_drop.cpp:69
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: cs_drop.cpp:23