Anope IRC Services  Version 2.0
os_svs.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 CommandOSSVSNick : public Command
15 {
16  public:
17  CommandOSSVSNick(Module *creator) : Command(creator, "operserv/svsnick", 2, 2)
18  {
19  this->SetDesc(_("Forcefully change a user's nickname"));
20  this->SetSyntax(_("\037nick\037 \037newnick\037"));
21  }
22 
23  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
24  {
25  const Anope::string &nick = params[0];
26  Anope::string newnick = params[1];
27  User *u2;
28 
29  if (!IRCD->CanSVSNick)
30  {
31  source.Reply(_("Your IRCd does not support SVSNICK."));
32  return;
33  }
34 
35  /* Truncate long nicknames to nicklen characters */
36  unsigned nicklen = Config->GetBlock("networkinfo")->Get<unsigned>("nicklen");
37  if (newnick.length() > nicklen)
38  {
39  source.Reply(_("Nick \002%s\002 was truncated to %d characters."), newnick.c_str(), nicklen, newnick.c_str());
40  newnick = params[1].substr(0, nicklen);
41  }
42 
43  /* Check for valid characters */
44  if (!IRCD->IsNickValid(newnick))
45  {
46  source.Reply(_("Nick \002%s\002 is an illegal nickname and cannot be used."), newnick.c_str());
47  return;
48  }
49 
50  /* Check for a nick in use or a forbidden/suspended nick */
51  if (!(u2 = User::Find(nick, true)))
52  source.Reply(NICK_X_NOT_IN_USE, nick.c_str());
53  else if (!nick.equals_ci(newnick) && User::Find(newnick))
54  source.Reply(_("Nick \002%s\002 is currently in use."), newnick.c_str());
55  else
56  {
57  source.Reply(_("The nick \002%s\002 is now being changed to \002%s\002."), nick.c_str(), newnick.c_str());
58  Log(LOG_ADMIN, source, this) << "to change " << nick << " to " << newnick;
60  }
61  return;
62  }
63 
64  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
65  {
66  this->SendSyntax(source);
67  source.Reply(" ");
68  source.Reply(_("Forcefully changes a user's nickname from \037nick\037 to \037newnick\037."));
69  return true;
70  }
71 };
72 
73 class CommandOSSVSJoin : public Command
74 {
75  public:
76  CommandOSSVSJoin(Module *creator) : Command(creator, "operserv/svsjoin", 2, 2)
77  {
78  this->SetDesc(_("Forcefully join a user to a channel"));
79  this->SetSyntax(_("\037nick\037 \037channel\037"));
80  }
81 
82  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
83  {
84  if (!IRCD->CanSVSJoin)
85  {
86  source.Reply(_("Your IRCd does not support SVSJOIN."));
87  return;
88  }
89 
90  User *target = User::Find(params[0], true);
91  Channel *c = Channel::Find(params[1]);
92  if (target == NULL)
93  source.Reply(NICK_X_NOT_IN_USE, params[0].c_str());
94  else if (source.GetUser() != target && (target->IsProtected() || target->server == Me))
95  source.Reply(ACCESS_DENIED);
96  else if (!IRCD->IsChannelValid(params[1]))
97  source.Reply(CHAN_X_INVALID, params[1].c_str());
98  else if (c && c->FindUser(target))
99  source.Reply(_("\002%s\002 is already in \002%s\002."), target->nick.c_str(), c->name.c_str());
100  else
101  {
102  IRCD->SendSVSJoin(*source.service, target, params[1], "");
103  Log(LOG_ADMIN, source, this) << "to force " << target->nick << " to join " << params[1];
104  source.Reply(_("\002%s\002 has been joined to \002%s\002."), target->nick.c_str(), params[1].c_str());
105  }
106  }
107 
108  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
109  {
110  this->SendSyntax(source);
111  source.Reply(" ");
112  source.Reply(_("Forcefully join a user to a channel."));
113  return true;
114  }
115 };
116 
117 class CommandOSSVSPart : public Command
118 {
119  public:
120  CommandOSSVSPart(Module *creator) : Command(creator, "operserv/svspart", 2, 3)
121  {
122  this->SetDesc(_("Forcefully part a user from a channel"));
123  this->SetSyntax(_("\037nick\037 \037channel\037 [\037reason\037]"));
124  }
125 
126  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
127  {
128  if (!IRCD->CanSVSJoin)
129  {
130  source.Reply(_("Your IRCd does not support SVSPART."));
131  return;
132  }
133 
134  User *target = User::Find(params[0], true);
135  Channel *c = Channel::Find(params[1]);
136  const Anope::string &reason = params.size() > 2 ? params[2] : "";
137  if (target == NULL)
138  source.Reply(NICK_X_NOT_IN_USE, params[0].c_str());
139  else if (source.GetUser() != target && (target->IsProtected() || target->server == Me))
140  source.Reply(ACCESS_DENIED);
141  else if (!c)
142  source.Reply(CHAN_X_NOT_IN_USE, params[1].c_str());
143  else if (!c->FindUser(target))
144  source.Reply(_("\002%s\002 is not in \002%s\002."), target->nick.c_str(), c->name.c_str());
145  else
146  {
147  IRCD->SendSVSPart(*source.service, target, params[1], reason);
148  if (!reason.empty())
149  Log(LOG_ADMIN, source, this) << "to force " << target->nick << " to part " << c->name << " with reason " << reason;
150  else
151  Log(LOG_ADMIN, source, this) << "to force " << target->nick << " to part " << c->name;
152  source.Reply(_("\002%s\002 has been parted from \002%s\002."), target->nick.c_str(), c->name.c_str());
153  }
154  }
155 
156  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
157  {
158  this->SendSyntax(source);
159  source.Reply(" ");
160  source.Reply(_("Forcefully part a user from a channel."));
161  return true;
162  }
163 };
164 
165 class OSSVS : public Module
166 {
170 
171  public:
172  OSSVS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
173  commandossvsnick(this), commandossvsjoin(this), commandossvspart(this)
174  {
175  }
176 };
177 
#define CHAN_X_INVALID
Definition: language.h:102
#define CHAN_X_NOT_IN_USE
Definition: language.h:85
CommandOSSVSJoin(Module *creator)
Definition: os_svs.cpp:76
#define ACCESS_DENIED
Definition: language.h:73
Definition: users.h:34
CommandOSSVSJoin commandossvsjoin
Definition: os_svs.cpp:168
virtual void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &param)
Definition: protocol.h:170
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: os_svs.cpp:126
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: os_svs.cpp:64
CommandOSSVSPart(Module *creator)
Definition: os_svs.cpp:120
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
bool equals_ci(const char *_str) const
Definition: anope.h:78
CommandOSSVSNick commandossvsnick
Definition: os_svs.cpp:167
Anope::string name
Definition: channels.h:44
CoreExport time_t CurTime
Definition: main.cpp:41
#define NICK_X_NOT_IN_USE
Definition: language.h:80
string substr(size_type pos=0, size_type n=npos) const
Definition: anope.h:277
bool IsProtected()
Definition: users.cpp:724
virtual void SendForceNickChange(User *u, const Anope::string &newnick, time_t when)
Definition: protocol.cpp:324
size_type length() const
Definition: anope.h:131
Definition: Config.cs:26
bool CanSVSNick
Definition: protocol.h:49
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: os_svs.cpp:82
CommandOSSVSPart commandossvspart
Definition: os_svs.cpp:169
CommandOSSVSNick(Module *creator)
Definition: os_svs.cpp:17
virtual bool IsNickValid(const Anope::string &)
Definition: protocol.cpp:349
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: os_svs.cpp:108
#define anope_override
Definition: services.h:56
bool empty() const
Definition: anope.h:126
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: os_svs.cpp:156
CoreExport IRCDProto * IRCD
Definition: protocol.cpp:23
#define MODULE_INIT(x)
Definition: modules.h:45
Server * server
Definition: users.h:77
ChanUserContainer * FindUser(User *u) const
Definition: channels.cpp:173
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
Anope::string nick
Definition: users.h:62
virtual bool IsChannelValid(const Anope::string &)
Definition: protocol.cpp:372
static User * Find(const Anope::string &name, bool nick_only=false)
Definition: users.cpp:815
static Channel * Find(const Anope::string &name)
Definition: channels.cpp:920
CoreExport Server * Me
Definition: servers.cpp:24
void SendSyntax(CommandSource &)
Definition: command.cpp:145
const char * c_str() const
Definition: anope.h:117
Definition: logger.h:53
OSSVS(const Anope::string &modname, const Anope::string &creator)
Definition: os_svs.cpp:172
bool CanSVSJoin
Definition: protocol.h:51
virtual void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &param)
Definition: protocol.h:178
#define _(x)
Definition: services.h:50
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: os_svs.cpp:23