Anope IRC Services  Version 2.0
operserv.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 
15 {
16  public:
17  SGLineManager(Module *creator) : XLineManager(creator, "xlinemanager/sgline", 'G') { }
18 
20  {
21  this->Send(u, x);
22  }
23 
24  void OnExpire(const XLine *x) anope_override
25  {
26  Log(Config->GetClient("OperServ"), "expire/akill") << "AKILL on \002" << x->mask << "\002 has expired";
27  }
28 
30  {
31  IRCD->SendAkill(u, x);
32  }
33 
35  {
36  IRCD->SendAkillDel(x);
37  }
38 
39  bool Check(User *u, const XLine *x) anope_override
40  {
41  if (x->regex)
42  {
43  Anope::string uh = u->GetIdent() + "@" + u->host, nuhr = u->nick + "!" + uh + "#" + u->realname;
44  return x->regex->Matches(uh) || x->regex->Matches(nuhr);
45  }
46 
47  if (!x->GetNick().empty() && !Anope::Match(u->nick, x->GetNick()))
48  return false;
49 
50  if (!x->GetUser().empty() && !Anope::Match(u->GetIdent(), x->GetUser()))
51  return false;
52 
53  if (!x->GetReal().empty() && !Anope::Match(u->realname, x->GetReal()))
54  return false;
55 
56  if (x->c && x->c->match(u->ip))
57  return true;
58 
59  if (x->GetHost().empty() || Anope::Match(u->host, x->GetHost()) || Anope::Match(u->ip.addr(), x->GetHost()))
60  return true;
61 
62  return false;
63  }
64 };
65 
67 {
69 
70  public:
71  SQLineManager(Module *creator) : XLineManager(creator, "xlinemanager/sqline", 'Q'), nickserv("NickServService", "NickServ") { }
72 
74  {
75  this->Send(u, x);
76  }
77 
78  void OnExpire(const XLine *x) anope_override
79  {
80  Log(Config->GetClient("OperServ"), "expire/sqline") << "SQLINE on \002" << x->mask << "\002 has expired";
81  }
82 
84  {
85  if (!IRCD->CanSQLine)
86  {
87  if (!u)
88  ;
89  else if (nickserv)
90  nickserv->Collide(u, NULL);
91  else
92  u->Kill(Config->GetClient("OperServ"), "Q-Lined: " + x->reason);
93  }
94  else if (x->IsRegex())
95  ;
96  else if (x->mask[0] != '#' || IRCD->CanSQLineChannel)
97  IRCD->SendSQLine(u, x);
98  }
99 
101  {
102  if (!IRCD->CanSQLine || x->IsRegex())
103  ;
104  else if (x->mask[0] != '#' || IRCD->CanSQLineChannel)
105  IRCD->SendSQLineDel(x);
106  }
107 
108  bool Check(User *u, const XLine *x) anope_override
109  {
110  if (x->regex)
111  return x->regex->Matches(u->nick);
112  return Anope::Match(u->nick, x->mask);
113  }
114 
116  {
117  for (std::vector<XLine *>::const_iterator it = this->GetList().begin(), it_end = this->GetList().end(); it != it_end; ++it)
118  {
119  XLine *x = *it;
120  if (x->regex)
121  {
122  if (x->regex->Matches(c->name))
123  return x;
124  }
125  else if (Anope::Match(c->name, x->mask, false, true))
126  return x;
127  }
128  return NULL;
129  }
130 };
131 
133 {
134  public:
135  SNLineManager(Module *creator) : XLineManager(creator, "xlinemanager/snline", 'N') { }
136 
138  {
139  this->Send(u, x);
140  }
141 
143  {
144  Log(Config->GetClient("OperServ"), "expire/snline") << "SNLINE on \002" << x->mask << "\002 has expired";
145  }
146 
148  {
149  if (IRCD->CanSNLine && !x->IsRegex())
150  IRCD->SendSGLine(u, x);
151 
152  if (u)
153  u->Kill(Config->GetClient("OperServ"), "SNLined: " + x->reason);
154  }
155 
157  {
158  if (IRCD->CanSNLine && !x->IsRegex())
159  IRCD->SendSGLineDel(x);
160  }
161 
162  bool Check(User *u, const XLine *x) anope_override
163  {
164  if (x->regex)
165  return x->regex->Matches(u->realname);
166  return Anope::Match(u->realname, x->mask, false, true);
167  }
168 };
169 
170 class OperServCore : public Module
171 {
176 
177  public:
178  OperServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR),
179  sglines(this), sqlines(this), snlines(this)
180  {
181 
182  /* Yes, these are in this order for a reason. Most violent->least violent. */
186  }
187 
189  {
190  this->sglines.Clear();
191  this->sqlines.Clear();
192  this->snlines.Clear();
193 
197  }
198 
200  {
201  const Anope::string &osnick = conf->GetModule(this)->Get<const Anope::string>("client");
202 
203  if (osnick.empty())
204  throw ConfigException(this->name + ": <client> must be defined");
205 
206  BotInfo *bi = BotInfo::Find(osnick, true);
207  if (!bi)
208  throw ConfigException(this->name + ": no bot named " + osnick);
209 
210  OperServ = bi;
211  }
212 
214  {
215  if (bi == OperServ && !u->HasMode("OPER") && Config->GetModule(this)->Get<bool>("opersonly"))
216  {
217  u->SendMessage(bi, ACCESS_DENIED);
218  Log(bi, "bados") << "Denied access to " << bi->nick << " from " << u->GetMask() << " (non-oper)";
219  return EVENT_STOP;
220  }
221 
222  return EVENT_CONTINUE;
223  }
224 
226  {
227  if (server->IsJuped())
228  Log(server, "squit", OperServ) << "Received SQUIT for juped server " << server->GetName();
229  }
230 
231  void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) anope_override
232  {
233  if (mname == "OPER")
234  Log(u, "oper", OperServ) << "is now an IRC operator.";
235  }
236 
237  void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) anope_override
238  {
239  if (mname == "OPER")
240  Log(u, "oper", OperServ) << "is no longer an IRC operator";
241  }
242 
243  void OnUserConnect(User *u, bool &exempt) anope_override
244  {
245  if (!u->Quitting() && !exempt)
247  }
248 
250  {
251  if (!u->HasMode("OPER"))
252  this->sqlines.CheckAllXLines(u);
253  }
254 
256  {
257  XLine *x = this->sqlines.CheckChannel(c);
258  if (x)
259  {
260  this->sqlines.OnMatch(u, x);
261  reason = x->reason;
262  return EVENT_STOP;
263  }
264 
265  return EVENT_CONTINUE;
266  }
267 
268  EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
269  {
270  if (!params.empty() || source.c || source.service != *OperServ)
271  return EVENT_CONTINUE;
272  source.Reply(_("%s commands:"), OperServ->nick.c_str());
273  return EVENT_CONTINUE;
274  }
275 
277  {
278  if (l->type == LOG_SERVER)
279  l->bi = OperServ;
280  }
281 };
282 
284 
Definition: bots.h:24
bool HasMode(const Anope::string &name) const
Definition: users.cpp:513
SQLineManager(Module *creator)
Definition: operserv.cpp:71
virtual void SendSGLine(User *, const XLine *)
Definition: protocol.h:112
static void UnregisterXLineManager(XLineManager *xlm)
Definition: xline.cpp:215
Definition: servers.h:42
Anope::string name
Definition: modules.h:221
Anope::string reason
Definition: xline.h:29
bool CanSNLine
Definition: protocol.h:55
void Send(User *u, XLine *x) anope_override
Definition: operserv.cpp:29
Anope::string mask
Definition: xline.h:24
bool CanSQLineChannel
Definition: protocol.h:59
void OnMatch(User *u, XLine *x) anope_override
Definition: operserv.cpp:19
static void CheckAll(User *u)
Definition: xline.cpp:223
void OnExpire(const XLine *x) anope_override
Definition: operserv.cpp:142
virtual void SendSGLineDel(const XLine *)
Definition: protocol.h:113
Reference< BotInfo > OperServ
Definition: operserv.cpp:172
SGLineManager(Module *creator)
Definition: operserv.cpp:17
void Clear()
Definition: xline.cpp:332
#define ACCESS_DENIED
Definition: language.h:73
SQLineManager sqlines
Definition: operserv.cpp:174
SNLineManager snlines
Definition: operserv.cpp:175
bool Check(User *u, const XLine *x) anope_override
Definition: operserv.cpp:39
Definition: users.h:34
virtual void SendAkill(User *, XLine *)=0
void SendDel(XLine *x) anope_override
Definition: operserv.cpp:156
virtual void SendSQLine(User *, const XLine *x)
Definition: protocol.h:120
virtual void SendSQLineDel(const XLine *x)
Definition: protocol.h:121
void OnMatch(User *u, XLine *x) anope_override
Definition: operserv.cpp:137
Anope::string name
Definition: channels.h:44
bool Check(User *u, const XLine *x) anope_override
Definition: operserv.cpp:162
ServiceReference< NickServService > nickserv
Definition: operserv.cpp:68
XLine * CheckChannel(Channel *c)
Definition: operserv.cpp:115
bool CanSQLine
Definition: protocol.h:57
Definition: Config.cs:26
CoreExport bool Match(const string &str, const string &mask, bool case_sensitive=false, bool use_regex=false)
Definition: misc.cpp:407
void OnUserNickChange(User *u, const Anope::string &oldnick) anope_override
Definition: operserv.cpp:249
SGLineManager sglines
Definition: operserv.cpp:173
Regex * regex
Definition: xline.h:25
bool Check(User *u, const XLine *x) anope_override
Definition: operserv.cpp:108
const std::vector< XLine * > & GetList() const
Definition: xline.cpp:281
void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) anope_override
Definition: operserv.cpp:237
void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) anope_override
Definition: operserv.cpp:231
void OnReload(Configuration::Conf *conf) anope_override
Definition: operserv.cpp:199
void SendDel(XLine *x) anope_override
Definition: operserv.cpp:100
#define anope_override
Definition: services.h:56
bool empty() const
Definition: anope.h:126
void OnServerQuit(Server *server) anope_override
Definition: operserv.cpp:225
EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) anope_override
Definition: operserv.cpp:255
void OnExpire(const XLine *x) anope_override
Definition: operserv.cpp:24
void Send(User *u, XLine *x) anope_override
Definition: operserv.cpp:83
CoreExport IRCDProto * IRCD
Definition: protocol.cpp:23
EventReturn
Definition: modules.h:129
#define MODULE_INIT(x)
Definition: modules.h:45
void Send(User *u, XLine *x) anope_override
Definition: operserv.cpp:147
virtual bool Matches(const Anope::string &str)=0
void OnExpire(const XLine *x) anope_override
Definition: operserv.cpp:78
EventReturn OnPreHelp(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: operserv.cpp:268
void OnMatch(User *u, XLine *x) anope_override
Definition: operserv.cpp:73
Anope::string nick
Definition: users.h:62
OperServCore(const Anope::string &modname, const Anope::string &creator)
Definition: operserv.cpp:178
EventReturn OnBotPrivmsg(User *u, BotInfo *bi, Anope::string &message) anope_override
Definition: operserv.cpp:213
virtual void SendAkillDel(const XLine *)=0
Definition: xline.h:18
const char * c_str() const
Definition: anope.h:117
Definition: logger.h:53
SNLineManager(Module *creator)
Definition: operserv.cpp:135
void SendDel(XLine *x) anope_override
Definition: operserv.cpp:34
XLine * CheckAllXLines(User *u)
Definition: xline.cpp:415
#define _(x)
Definition: services.h:50
static BotInfo * Find(const Anope::string &nick, bool nick_only=false)
Definition: bots.cpp:249
static void RegisterXLineManager(XLineManager *xlm)
Definition: xline.cpp:210
void OnUserConnect(User *u, bool &exempt) anope_override
Definition: operserv.cpp:243
void OnLog(Log *l) anope_override
Definition: operserv.cpp:276