Anope IRC Services  Version 2.0
os_chankill.cpp
Go to the documentation of this file.
1 /* OperServ 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 static ServiceReference<XLineManager> akills("XLineManager", "xlinemanager/sgline");
15 
16 class CommandOSChanKill : public Command
17 {
18  public:
19  CommandOSChanKill(Module *creator) : Command(creator, "operserv/chankill", 2, 3)
20  {
21  this->SetDesc(_("AKILL all users on a specific channel"));
22  this->SetSyntax(_("[+\037expiry\037] \037channel\037 \037reason\037"));
23  }
24 
25  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
26  {
27  if (!akills)
28  return;
29 
30  Anope::string expiry, channel;
31  unsigned last_param = 1;
32  Channel *c;
33 
34  channel = params[0];
35  if (!channel.empty() && channel[0] == '+')
36  {
37  expiry = channel;
38  channel = params[1];
39  last_param = 2;
40  }
41 
42  time_t expires = !expiry.empty() ? Anope::DoTime(expiry) : Config->GetModule("operserv")->Get<time_t>("autokillexpiry", "30d");
43  if (!expiry.empty() && isdigit(expiry[expiry.length() - 1]))
44  expires *= 86400;
45  if (expires && expires < 60)
46  {
47  source.Reply(BAD_EXPIRY_TIME);
48  return;
49  }
50  else if (expires > 0)
51  expires += Anope::CurTime;
52 
53  if (params.size() <= last_param)
54  {
55  this->OnSyntaxError(source, "");
56  return;
57  }
58 
59  Anope::string reason = params[last_param];
60  if (params.size() > last_param + 1)
61  reason += params[last_param + 1];
62  if (!reason.empty())
63  {
64  Anope::string realreason;
65  if (Config->GetModule("operserv")->Get<bool>("addakiller") && !source.GetNick().empty())
66  realreason = "[" + source.GetNick() + "] " + reason;
67  else
68  realreason = reason;
69 
70  if ((c = Channel::Find(channel)))
71  {
72  for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it)
73  {
74  ChanUserContainer *uc = it->second;
75 
76  if (uc->user->server == Me || uc->user->HasMode("OPER"))
77  continue;
78 
79  XLine *x = new XLine("*@" + uc->user->host, source.GetNick(), expires, realreason, XLineManager::GenerateUID());
80  akills->AddXLine(x);
81  akills->OnMatch(uc->user, x);
82  }
83 
84  Log(LOG_ADMIN, source, this) << "on " << c->name << " (" << realreason << ")";
85  }
86  else
87  source.Reply(CHAN_X_NOT_IN_USE, channel.c_str());
88  }
89  return;
90  }
91 
92  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
93  {
94  this->SendSyntax(source);
95  source.Reply(" ");
96  source.Reply(_("Puts an AKILL for every nick on the specified channel. It\n"
97  "uses the entire real ident@host for every nick, and\n"
98  "then enforces the AKILL."));
99  return true;
100  }
101 };
102 
103 class OSChanKill : public Module
104 {
106 
107  public:
108  OSChanKill(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
109  commandoschankill(this)
110  {
111 
112  }
113 };
114 
bool HasMode(const Anope::string &name) const
Definition: users.cpp:513
#define CHAN_X_NOT_IN_USE
Definition: language.h:85
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: os_chankill.cpp:92
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
Anope::string name
Definition: channels.h:44
CoreExport time_t CurTime
Definition: main.cpp:41
size_type length() const
Definition: anope.h:131
Definition: Config.cs:26
virtual void OnSyntaxError(CommandSource &source, const Anope::string &subcommand)
Definition: command.cpp:191
CoreExport time_t DoTime(const Anope::string &s)
Definition: misc.cpp:275
#define anope_override
Definition: services.h:56
OSChanKill(const Anope::string &modname, const Anope::string &creator)
bool empty() const
Definition: anope.h:126
Anope::string host
Definition: users.h:65
#define MODULE_INIT(x)
Definition: modules.h:45
Server * server
Definition: users.h:77
ChanUserList users
Definition: channels.h:56
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
static Channel * Find(const Anope::string &name)
Definition: channels.cpp:920
Definition: xline.h:18
CoreExport Server * Me
Definition: servers.cpp:24
void SendSyntax(CommandSource &)
Definition: command.cpp:145
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: os_chankill.cpp:25
const char * c_str() const
Definition: anope.h:117
Definition: logger.h:53
#define BAD_EXPIRY_TIME
Definition: language.h:69
CommandOSChanKill commandoschankill
static Anope::string GenerateUID()
Definition: xline.cpp:234
static ServiceReference< XLineManager > akills("XLineManager","xlinemanager/sgline")
#define _(x)
Definition: services.h:50
CommandOSChanKill(Module *creator)
Definition: os_chankill.cpp:19