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