Anope IRC Services  Version 2.0
os_noop.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 class CommandOSNOOP : public Command
15 {
16  public:
17  CommandOSNOOP(Module *creator) : Command(creator, "operserv/noop", 2, 2)
18  {
19  this->SetDesc(_("Remove all operators from a server remotely"));
20  this->SetSyntax(_("SET \037server\037"));
21  this->SetSyntax(_("REVOKE \037server\037"));
22  }
23 
24  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
25  {
26  const Anope::string &cmd = params[0];
27  const Anope::string &server = params[1];
28 
29  Server *s = Server::Find(server, true);
30  if (s == NULL)
31  source.Reply(_("Server %s does not exist."), server.c_str());
32  else if (s == Me || s->IsJuped())
33  source.Reply(_("You can not NOOP Services."));
34  else if (cmd.equals_ci("SET"))
35  {
36  /* Remove the O:lines */
37  IRCD->SendSVSNOOP(s, true);
38  s->Extend<Anope::string>("noop", source.GetNick());
39 
40  Log(LOG_ADMIN, source, this) << "SET on " << s->GetName();
41  source.Reply(_("All operators from \002%s\002 have been removed."), s->GetName().c_str());
42 
43  Anope::string reason = "NOOP command used by " + source.GetNick();
44  /* Kill all the IRCops of the server */
45  for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
46  {
47  User *u2 = it->second;
48 
49  if (u2->server == s && u2->HasMode("OPER"))
50  u2->Kill(source.service->nick, reason);
51  }
52  }
53  else if (cmd.equals_ci("REVOKE"))
54  {
55  s->Shrink<Anope::string>("noop");
56  IRCD->SendSVSNOOP(s, false);
57  Log(LOG_ADMIN, source, this) << "REVOKE on " << s->GetName();
58  source.Reply(_("All O:lines of \002%s\002 have been reset."), s->GetName().c_str());
59  }
60  else
61  this->OnSyntaxError(source, "");
62  }
63 
64  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
65  {
66  this->SendSyntax(source);
67  source.Reply(" ");
68  source.Reply(_("\002SET\002 kills all operators from the given\n"
69  "\002server\002 and prevents operators from opering\n"
70  "up on the given server. \002REVOKE\002 removes this\n"
71  "restriction."));
72  return true;
73  }
74 };
75 
76 class OSNOOP : public Module
77 {
80 
81  public:
82  OSNOOP(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
83  commandosnoop(this), noop(this, "noop")
84  {
85 
86  }
87 
89  {
90  Anope::string *setter;
91  if (mname == "OPER" && (setter = noop.Get(u->server)))
92  {
93  Anope::string reason = "NOOP command used by " + *setter;
94  BotInfo *OperServ = Config->GetClient("OperServ");
95  u->Kill(OperServ ? OperServ->nick : "", reason);
96  }
97  }
98 };
99 
Definition: bots.h:24
bool HasMode(const Anope::string &name) const
Definition: users.cpp:513
Definition: servers.h:42
void Kill(const MessageSource &source, const Anope::string &reason)
Definition: users.cpp:729
PrimitiveExtensibleItem< Anope::string > noop
Definition: os_noop.cpp:79
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: os_noop.cpp:64
void OnUserModeSet(const MessageSource &, User *u, const Anope::string &mname) anope_override
Definition: os_noop.cpp:88
Definition: users.h:34
T * Extend(const Anope::string &name, const T &what)
Definition: extensible.h:224
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: os_noop.cpp:24
bool IsJuped() const
Definition: servers.cpp:319
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
bool equals_ci(const char *_str) const
Definition: anope.h:78
Definition: Config.cs:26
void Shrink(const Anope::string &name)
Definition: extensible.h:253
virtual void OnSyntaxError(CommandSource &source, const Anope::string &subcommand)
Definition: command.cpp:191
virtual void SendSVSNOOP(const Server *s, bool mode)
Definition: protocol.h:86
#define anope_override
Definition: services.h:56
static Server * Find(const Anope::string &name, bool name_only=false)
Definition: servers.cpp:337
CoreExport IRCDProto * IRCD
Definition: protocol.cpp:23
#define MODULE_INIT(x)
Definition: modules.h:45
Server * server
Definition: users.h:77
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
CommandOSNOOP commandosnoop
Definition: os_noop.cpp:78
Anope::string nick
Definition: users.h:62
const Anope::string & GetName() const
Definition: servers.cpp:175
T * Get(const Extensible *obj) const
Definition: extensible.h:103
CoreExport Server * Me
Definition: servers.cpp:24
CoreExport user_map UserListByNick
Definition: users.cpp:28
void SendSyntax(CommandSource &)
Definition: command.cpp:145
const char * c_str() const
Definition: anope.h:117
Definition: logger.h:53
CommandOSNOOP(Module *creator)
Definition: os_noop.cpp:17
#define _(x)
Definition: services.h:50
OSNOOP(const Anope::string &modname, const Anope::string &creator)
Definition: os_noop.cpp:82