1 |
/* |
2 |
* ptasks.C: Implementation of common protocol tasks. |
3 |
* Rights to this code are documented in doc/pod/license.pod. |
4 |
* |
5 |
* Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
6 |
*/ |
7 |
|
8 |
static char const rcsid[] = "$Id"; |
9 |
|
10 |
#include "atheme.h" |
11 |
#include <account/myuser.h> |
12 |
#include <account/mynick.h> |
13 |
#include <account/kline.h> |
14 |
#include <account/svsignore.h> |
15 |
#include "uplink.h" |
16 |
#include "pmodule.h" |
17 |
#include "privs.h" |
18 |
|
19 |
void |
20 |
handle_info (user_t *u) |
21 |
{ |
22 |
unsigned int i; |
23 |
|
24 |
if (u == NULL) |
25 |
return; |
26 |
if (floodcheck (u, NULL)) |
27 |
return; |
28 |
|
29 |
for (i = 0; infotext[i]; i++) |
30 |
numeric_sts (me.name, 371, u->nick, ":%s", infotext[i]); |
31 |
|
32 |
numeric_sts (me.name, 374, u->nick, ":End of /INFO list"); |
33 |
} |
34 |
|
35 |
void |
36 |
handle_version (user_t *u) |
37 |
{ |
38 |
|
39 |
if (u == NULL) |
40 |
return; |
41 |
if (floodcheck (u, NULL)) |
42 |
return; |
43 |
|
44 |
numeric_sts (me.name, 351, u->nick, ":" PACKAGE_NAME "-%s. %s %s%s%s%s%s%s%s%s%s%s [%s]", version, me.name, (match_mapping) ? "A" : "", log_debug_enabled ()? "d" : "", (me.auth) ? "e" : "", (config_options.flood_msgs) ? "F" : "", (config_options.leave_chans) ? "l" : "", (config_options.join_chans) ? "j" : "", (chansvs.changets) ? "t" : "", (!match_mapping) ? "R" : "", (config_options.raw) ? "r" : "", (runflags & RF_LIVE) ? "n" : "", ircd->ircdname); |
45 |
numeric_sts (me.name, 351, u->nick, ":Compile time: %s, build %s", creation, generation); |
46 |
} |
47 |
|
48 |
void |
49 |
handle_admin (user_t *u) |
50 |
{ |
51 |
|
52 |
if (u == NULL) |
53 |
return; |
54 |
|
55 |
if (floodcheck (u, NULL)) |
56 |
return; |
57 |
|
58 |
numeric_sts (me.name, 256, u->nick, ":Administrative info about %s", me.name); |
59 |
numeric_sts (me.name, 257, u->nick, ":%s", me.adminname); |
60 |
numeric_sts (me.name, 258, u->nick, ":Ermyth IRC Services (" PACKAGE_NAME "-%s)", version); |
61 |
numeric_sts (me.name, 259, u->nick, ":<%s>", me.adminemail); |
62 |
} |
63 |
|
64 |
static void |
65 |
dictionary_stats_cb (const char *line, void *privdata) |
66 |
{ |
67 |
|
68 |
numeric_sts (me.name, 249, ((user_t *) privdata)->nick, "B :%s", line); |
69 |
} |
70 |
|
71 |
static void |
72 |
connection_stats_cb (const char *line, void *privdata) |
73 |
{ |
74 |
|
75 |
numeric_sts (me.name, 249, ((user_t *) privdata)->nick, "F :%s", line); |
76 |
} |
77 |
|
78 |
void |
79 |
handle_stats (user_t *u, char req) |
80 |
{ |
81 |
kline_t *k; |
82 |
kline_vector::iterator klit, klit_end; |
83 |
node_t *n; |
84 |
uplink_t *uplink; |
85 |
soper_t *soper; |
86 |
int i, j; |
87 |
char fl[10]; |
88 |
|
89 |
if (floodcheck (u, NULL)) |
90 |
return; |
91 |
logcommand_user (NULL, u, CMDLOG_GET, "STATS %c", req); |
92 |
|
93 |
switch (req) |
94 |
{ |
95 |
case 'B': |
96 |
if (!has_priv_user (u, PRIV_SERVER_AUSPEX)) |
97 |
break; |
98 |
|
99 |
dictionary_stats (dictionary_stats_cb, u); |
100 |
break; |
101 |
|
102 |
case 'C': |
103 |
case 'c': |
104 |
if (!has_priv_user (u, PRIV_SERVER_AUSPEX)) |
105 |
break; |
106 |
|
107 |
LIST_FOREACH (n, uplinks.head) |
108 |
{ |
109 |
uplink = (uplink_t *) n->data; |
110 |
numeric_sts (me.name, 213, u->nick, "C *@127.0.0.1 A %s %d uplink", uplink->name, uplink->port); |
111 |
} |
112 |
break; |
113 |
|
114 |
case 'E': |
115 |
case 'e': |
116 |
if (!has_priv_user (u, PRIV_SERVER_AUSPEX)) |
117 |
break; |
118 |
|
119 |
numeric_sts (me.name, 249, u->nick, "E :Last event to run: %s", last_event_ran); |
120 |
|
121 |
numeric_sts (me.name, 249, u->nick, "E :%-28s %s", "Operation", "Next Execution"); |
122 |
for (i = 0; i < MAX_EVENTS; i++) |
123 |
{ |
124 |
if (event_table[i].active) |
125 |
numeric_sts (me.name, 249, u->nick, "E :%-28s %4d seconds (%d)", event_table[i].name, event_table[i].when - NOW, event_table[i].frequency); |
126 |
} |
127 |
|
128 |
break; |
129 |
|
130 |
case 'f': |
131 |
case 'F': |
132 |
if (!has_priv_user (u, PRIV_SERVER_AUSPEX)) |
133 |
break; |
134 |
|
135 |
connection_stats (connection_stats_cb, u); |
136 |
break; |
137 |
|
138 |
case 'H': |
139 |
case 'h': |
140 |
if (!has_priv_user (u, PRIV_SERVER_AUSPEX)) |
141 |
break; |
142 |
|
143 |
LIST_FOREACH (n, uplinks.head) |
144 |
{ |
145 |
uplink = (uplink_t *) n->data; |
146 |
numeric_sts (me.name, 244, u->nick, "H * * %s", uplink->name); |
147 |
} |
148 |
break; |
149 |
|
150 |
case 'I': |
151 |
case 'i': |
152 |
numeric_sts (me.name, 215, u->nick, "I * * *@%s 0 nonopered", me.name); |
153 |
break; |
154 |
|
155 |
case 'K': |
156 |
case 'k': |
157 |
if (!has_priv_user (u, PRIV_AKILL)) |
158 |
break; |
159 |
|
160 |
for (klit = klnlist.begin (), klit_end = klnlist.end (); klit != klit_end; ++klit) |
161 |
{ |
162 |
k = *klit; |
163 |
|
164 |
numeric_sts (me.name, 216, u->nick, "K %s * %s :%s", k->host, k->user, k->reason); |
165 |
} |
166 |
|
167 |
break; |
168 |
|
169 |
case 'o': |
170 |
case 'O': |
171 |
if (!has_priv_user (u, PRIV_VIEWPRIVS)) |
172 |
break; |
173 |
|
174 |
LIST_FOREACH (n, soperlist.head) |
175 |
{ |
176 |
soper = static_cast<soper_t *> (n->data); |
177 |
|
178 |
j = 0; |
179 |
if (!(soper->flags & SOPER_CONF)) |
180 |
fl[j++] = 'D'; |
181 |
if (soper->operclass != NULL && soper->operclass->flags & OPERCLASS_NEEDOPER) |
182 |
fl[j++] = 'O'; |
183 |
if (j == 0) |
184 |
fl[j++] = '*'; |
185 |
fl[j] = '\0'; |
186 |
numeric_sts (me.name, 243, u->nick, "O *@* %s %s %s %s", fl, soper->myuser ? soper->myuser->name : soper->name, soper->operclass ? soper->operclass->name : soper->classname, "-1"); |
187 |
} |
188 |
break; |
189 |
|
190 |
case 'T': |
191 |
case 't': |
192 |
if (!has_priv_user (u, PRIV_SERVER_AUSPEX)) |
193 |
break; |
194 |
|
195 |
numeric_sts (me.name, 249, u->nick, "T :event %7d", claro_state.event); |
196 |
numeric_sts (me.name, 249, u->nick, "T :node %7d", claro_state.node); |
197 |
numeric_sts (me.name, 249, u->nick, "T :connection %7d", connection_count ()); |
198 |
numeric_sts (me.name, 249, u->nick, "T :operclass %7d", cnt.operclass); |
199 |
numeric_sts (me.name, 249, u->nick, "T :soper %7d", cnt.soper); |
200 |
numeric_sts (me.name, 249, u->nick, "T :tld %7d", cnt.tld); |
201 |
numeric_sts (me.name, 249, u->nick, "T :kline %7d", cnt.kline); |
202 |
numeric_sts (me.name, 249, u->nick, "T :server %7d", cnt.server); |
203 |
numeric_sts (me.name, 249, u->nick, "T :user %7d", cnt.user); |
204 |
numeric_sts (me.name, 249, u->nick, "T :chan %7d", cnt.chan); |
205 |
numeric_sts (me.name, 249, u->nick, "T :chanuser %7d", cnt.chanuser); |
206 |
numeric_sts (me.name, 249, u->nick, "T :myuser %7d", cnt.myuser); |
207 |
numeric_sts (me.name, 249, u->nick, "T :myuser_acc %7d", cnt.myuser_access); |
208 |
numeric_sts (me.name, 249, u->nick, "T :mynick %7d", cnt.mynick); |
209 |
numeric_sts (me.name, 249, u->nick, "T :mychan %7d", cnt.mychan); |
210 |
numeric_sts (me.name, 249, u->nick, "T :chanacs %7d", cnt.chanacs); |
211 |
|
212 |
numeric_sts (me.name, 249, u->nick, "T :bytes sent %7.2f%s", bytes (cnt.bout), sbytes (cnt.bout)); |
213 |
numeric_sts (me.name, 249, u->nick, "T :bytes recv %7.2f%s", bytes (cnt.bin), sbytes (cnt.bin)); |
214 |
break; |
215 |
|
216 |
case 'u': |
217 |
numeric_sts (me.name, 242, u->nick, ":Services Uptime: %s", timediff (NOW - me.start)); |
218 |
break; |
219 |
|
220 |
case 'V': |
221 |
case 'v': |
222 |
if (!has_priv_user (u, PRIV_SERVER_AUSPEX)) |
223 |
break; |
224 |
|
225 |
/* we received this command from the uplink, so, |
226 |
* hmm, it is not idle */ |
227 |
numeric_sts (me.name, 249, u->nick, "V :%s (AutoConn.!*@*) Idle: 0 SendQ: ? Connected: %s", curr_uplink->name, timediff (NOW - curr_uplink->conn->first_recv)); |
228 |
break; |
229 |
|
230 |
default: |
231 |
break; |
232 |
} |
233 |
|
234 |
numeric_sts (me.name, 219, u->nick, "%c :End of /STATS report", req); |
235 |
} |
236 |
|
237 |
void |
238 |
handle_whois (user_t *u, char *target) |
239 |
{ |
240 |
user_t *t = user_find_named (target); |
241 |
|
242 |
if (u == NULL) |
243 |
return; |
244 |
if (floodcheck (u, NULL)) |
245 |
return; |
246 |
|
247 |
if (t != NULL) |
248 |
{ |
249 |
numeric_sts (me.name, 311, u->nick, "%s %s %s * :%s", t->nick, t->user, t->vhost, t->gecos); |
250 |
/* channels purposely omitted */ |
251 |
numeric_sts (me.name, 312, u->nick, "%s %s :%s", t->nick, t->server->name, t->server->desc); |
252 |
if (t->flags & UF_AWAY) |
253 |
numeric_sts (me.name, 301, u->nick, "%s :Gone", t->nick); |
254 |
if (is_ircop (t)) |
255 |
numeric_sts (me.name, 313, u->nick, "%s :%s", t->nick, is_internal_client (t) ? "is a Network Service" : "is an IRC Operator"); |
256 |
if (t->myuser) |
257 |
numeric_sts (me.name, 330, u->nick, "%s %s :is logged in as", t->nick, t->myuser->name); |
258 |
} |
259 |
else |
260 |
numeric_sts (me.name, 401, u->nick, "%s :No such nick", target); |
261 |
numeric_sts (me.name, 318, u->nick, "%s :End of WHOIS", target); |
262 |
} |
263 |
|
264 |
static void |
265 |
single_trace (user_t *u, user_t *t) |
266 |
{ |
267 |
if (is_ircop (t)) |
268 |
numeric_sts (me.name, 204, u->nick, "Oper service %s[%s@%s] (255.255.255.255) 0 0", t->nick, t->user, t->vhost); |
269 |
else |
270 |
numeric_sts (me.name, 205, u->nick, "User service %s[%s@%s] (255.255.255.255) 0 0", t->nick, t->user, t->vhost); |
271 |
} |
272 |
|
273 |
/* target -> object to trace |
274 |
* dest -> server to execute command on |
275 |
*/ |
276 |
void |
277 |
handle_trace (user_t *u, char *target, char *dest) |
278 |
{ |
279 |
user_t *t; |
280 |
node_t *n; |
281 |
int nusers; |
282 |
|
283 |
if (u == NULL) |
284 |
return; |
285 |
if (floodcheck (u, NULL)) |
286 |
return; |
287 |
if (!match (target, me.name) || !irccasecmp (target, ME)) |
288 |
{ |
289 |
nusers = cnt.user; |
290 |
LIST_FOREACH (n, me.me->userlist.head) |
291 |
{ |
292 |
t = static_cast<user_t *> (n->data); |
293 |
single_trace (u, t); |
294 |
nusers--; |
295 |
} |
296 |
if (has_priv_user (u, PRIV_SERVER_AUSPEX)) |
297 |
numeric_sts (me.name, 206, u->nick, "Serv uplink %dS %dC %s *!*@%s 0", cnt.server - 1, nusers, me.actual, me.name); |
298 |
target = me.name; |
299 |
} |
300 |
else |
301 |
{ |
302 |
t = dest != NULL ? user_find_named (target) : user_find (target); |
303 |
if (t != NULL && t->server == me.me) |
304 |
{ |
305 |
single_trace (u, t); |
306 |
target = t->nick; |
307 |
} |
308 |
} |
309 |
numeric_sts (me.name, 262, u->nick, "%s :End of TRACE", target); |
310 |
} |
311 |
|
312 |
void |
313 |
handle_motd (user_t *u) |
314 |
{ |
315 |
FILE *f; |
316 |
char lbuf[BUFSIZE]; |
317 |
char nebuf[BUFSIZE]; |
318 |
char cebuf[BUFSIZE]; |
319 |
char ubuf[BUFSIZE]; |
320 |
char cbuf[BUFSIZE]; |
321 |
char nbuf[BUFSIZE]; |
322 |
|
323 |
if (u == NULL) |
324 |
return; |
325 |
if (floodcheck (u, NULL)) |
326 |
return; |
327 |
|
328 |
f = fopen (SYSCONFDIR "/" PACKAGE_NAME ".motd", "r"); |
329 |
if (!f) |
330 |
{ |
331 |
numeric_sts (me.name, 422, u->nick, ":The MOTD file is unavailable."); |
332 |
return; |
333 |
} |
334 |
|
335 |
snprintf (nebuf, BUFSIZE, TTP, nicksvs.expiry / 86400); |
336 |
snprintf (cebuf, BUFSIZE, TTP, chansvs.expiry / 86400); |
337 |
snprintf (ubuf, BUFSIZE, "%d", cnt.myuser); |
338 |
snprintf (nbuf, BUFSIZE, "%d", nicksvs.no_nick_ownership ? 0 : cnt.mynick); |
339 |
snprintf (cbuf, BUFSIZE, "%d", cnt.mychan); |
340 |
|
341 |
numeric_sts (me.name, 375, u->nick, ":- %s Message of the Day -", me.name); |
342 |
|
343 |
while (fgets (lbuf, BUFSIZE, f)) |
344 |
{ |
345 |
strip (lbuf); |
346 |
|
347 |
replace (lbuf, BUFSIZE, "&network&", me.netname); |
348 |
replace (lbuf, BUFSIZE, "&nickexpiry&", nebuf); |
349 |
replace (lbuf, BUFSIZE, "&chanexpiry&", cebuf); |
350 |
replace (lbuf, BUFSIZE, "&myusers&", ubuf); |
351 |
replace (lbuf, BUFSIZE, "&mynicks&", nbuf); |
352 |
replace (lbuf, BUFSIZE, "&mychans&", cbuf); |
353 |
|
354 |
numeric_sts (me.name, 372, u->nick, ":- %s", lbuf); |
355 |
} |
356 |
|
357 |
numeric_sts (me.name, 376, u->nick, ":End of the message of the day."); |
358 |
|
359 |
fclose (f); |
360 |
} |
361 |
|
362 |
void |
363 |
handle_away (user_t *u, const char *message) |
364 |
{ |
365 |
if (message == NULL || *message == '\0') |
366 |
{ |
367 |
if (u->flags & UF_AWAY) |
368 |
{ |
369 |
u->flags &= ~UF_AWAY; |
370 |
hook_call_event ("user_away", u); |
371 |
} |
372 |
} |
373 |
else |
374 |
{ |
375 |
if (!(u->flags & UF_AWAY)) |
376 |
{ |
377 |
u->flags |= UF_AWAY; |
378 |
hook_call_event ("user_away", u); |
379 |
} |
380 |
} |
381 |
} |
382 |
|
383 |
void |
384 |
handle_message (sourceinfo_t *si, char *target, bool is_notice, char *message) |
385 |
{ |
386 |
char *vec[3]; |
387 |
hook_cmessage_data_t cdata; |
388 |
|
389 |
/* message from server, ignore */ |
390 |
if (si->su == NULL) |
391 |
return; |
392 |
|
393 |
/* If target is a channel and fantasy commands are enabled, |
394 |
* this will return chanserv |
395 |
*/ |
396 |
si->service = find_service (target); |
397 |
|
398 |
if (*target == '#') |
399 |
{ |
400 |
/* Call hook here */ |
401 |
cdata.u = si->su; |
402 |
cdata.c = channel_find (target); |
403 |
cdata.msg = message; |
404 |
/* No such channel, ignore... */ |
405 |
if (cdata.c == NULL) |
406 |
return; |
407 |
hook_call_event ("channel_message", &cdata); |
408 |
} |
409 |
|
410 |
if (si->service == NULL) |
411 |
{ |
412 |
if (!is_notice && (isalnum (target[0]) || strchr ("[\\]^_`{|}~", target[0]))) |
413 |
{ |
414 |
/* If it's not a notice and looks like a nick or |
415 |
* user@server, send back an error message */ |
416 |
if (strchr (target, '@') || !ircd->uses_uid || (!ircd->uses_p10 && !isdigit (target[0]))) |
417 |
numeric_sts (me.name, 401, si->su->nick, "%s :No such nick", target); |
418 |
else |
419 |
numeric_sts (me.name, 401, si->su->nick, "* :Target left IRC. Failed to deliver: [%.20s]", message); |
420 |
} |
421 |
return; |
422 |
} |
423 |
|
424 |
/* Run it through flood checks. Channel commands are checked |
425 |
* separately. |
426 |
*/ |
427 |
if (si->service->me != NULL && *target != '#' && floodcheck (si->su, si->service->me)) |
428 |
return; |
429 |
|
430 |
if (!is_notice && config_options.secure && *target != '#' && irccasecmp (target, si->service->disp)) |
431 |
{ |
432 |
notice (si->service->me->nick, si->su->nick, "For security reasons, \2/msg %s\2 has been disabled." " Use \2/%s%s <command>\2 to send a command.", si->service->me->nick, (ircd->uses_rcommand ? "" : "msg "), si->service->disp); |
433 |
return; |
434 |
} |
435 |
|
436 |
vec[0] = target; |
437 |
vec[1] = message; |
438 |
vec[2] = NULL; |
439 |
if (is_notice) |
440 |
si->service->notice_handler (si, 2, vec); |
441 |
else |
442 |
si->service->handler (si, 2, vec); |
443 |
} |
444 |
|
445 |
void |
446 |
handle_topic_from (sourceinfo_t *si, channel_t *c, char *setter, time_t ts, char *topic) |
447 |
{ |
448 |
hook_channel_topic_check_t hdata; |
449 |
|
450 |
if (topic != NULL && topic[0] == '\0') |
451 |
topic = NULL; |
452 |
hdata.u = si->su; |
453 |
hdata.s = si->s; |
454 |
hdata.c = c; |
455 |
hdata.setter = setter; |
456 |
hdata.ts = ts; |
457 |
hdata.topic = topic; |
458 |
hdata.approved = 0; |
459 |
if (topic != NULL ? c->topic == NULL || strcmp (topic, c->topic) : c->topic != NULL) |
460 |
{ |
461 |
/* Only call the hook if the topic actually changed */ |
462 |
hook_call_event ("channel_can_change_topic", &hdata); |
463 |
} |
464 |
if (hdata.approved == 0) |
465 |
{ |
466 |
if (topic == hdata.topic || !strcmp (topic, hdata.topic)) |
467 |
/* Allowed, process the change further */ |
468 |
handle_topic (c, setter, ts, topic); |
469 |
else |
470 |
{ |
471 |
/* Allowed, but topic tweaked */ |
472 |
handle_topic (c, setter, ts, hdata.topic); |
473 |
topic_sts (c, setter, ts, ts, hdata.topic); |
474 |
} |
475 |
} |
476 |
else |
477 |
{ |
478 |
/* Not allowed, change it back */ |
479 |
if (c->topic != NULL) |
480 |
topic_sts (c, c->topic_setter, c->topicts, ts, c->topic); |
481 |
else |
482 |
{ |
483 |
/* Ick, there was no topic */ |
484 |
topic_sts (c, chansvs.nick != NULL ? chansvs.nick : me.name, ts - 1, ts, ""); |
485 |
} |
486 |
} |
487 |
} |
488 |
|
489 |
void |
490 |
handle_topic (channel_t *c, char *setter, time_t ts, char *topic) |
491 |
{ |
492 |
char newsetter[HOSTLEN], *p; |
493 |
|
494 |
/* setter can be a nick, nick!user@host or server. |
495 |
* strip off !user@host part if it's there |
496 |
* (do we really want this?) */ |
497 |
strlcpy (newsetter, setter, sizeof newsetter); |
498 |
p = strchr (newsetter, '!'); |
499 |
if (p != NULL) |
500 |
*p = '\0'; |
501 |
/* drop identical topics from servers or chanserv, and ones with |
502 |
* identical topicts */ |
503 |
if (topic != NULL && c->topic != NULL && !strcmp (topic, c->topic) && (strchr (newsetter, '.') || (chansvs.nick && !irccasecmp (newsetter, chansvs.nick)) || ts == c->topicts)) |
504 |
return; |
505 |
if (c->topic != NULL) |
506 |
free (c->topic); |
507 |
if (c->topic_setter != NULL) |
508 |
free (c->topic_setter); |
509 |
if (topic != NULL && topic[0] != '\0') |
510 |
{ |
511 |
c->topic = sstrdup (topic); |
512 |
c->topic_setter = sstrdup (newsetter); |
513 |
} |
514 |
else |
515 |
c->topic = c->topic_setter = NULL; |
516 |
c->topicts = ts; |
517 |
|
518 |
hook_call_event ("channel_topic", c); |
519 |
} |
520 |
|
521 |
void |
522 |
handle_kill (sourceinfo_t *si, char *victim, char const *reason) |
523 |
{ |
524 |
const char *source; |
525 |
user_t *u; |
526 |
static time_t lastkill = 0; |
527 |
static unsigned int killcount = 0; |
528 |
|
529 |
source = get_oper_name (si); |
530 |
|
531 |
u = user_find (victim); |
532 |
if (u == NULL) |
533 |
slog (LG_DEBUG, "handle_kill(): %s killed unknown user %s (%s)", source, victim, reason); |
534 |
else if (u->server == me.me) |
535 |
{ |
536 |
slog (LG_INFO, "handle_kill(): %s killed service %s (%s)", source, u->nick, reason); |
537 |
if (lastkill != NOW && killcount < 5 + me.me->users) |
538 |
killcount = 0, lastkill = NOW; |
539 |
killcount++; |
540 |
if (killcount < 5 + me.me->users) |
541 |
reintroduce_user (u); |
542 |
else |
543 |
{ |
544 |
slog (LG_ERROR, "handle_kill(): services kill fight (%s -> %s), shutting down", source, u->nick); |
545 |
wallops (_("Services kill fight (%s -> %s), shutting down!"), source, u->nick); |
546 |
snoop (_("ERROR: Services kill fight (%s -> %s), shutting down!"), source, u->nick); |
547 |
runflags |= RF_SHUTDOWN; |
548 |
} |
549 |
} |
550 |
else |
551 |
{ |
552 |
slog (LG_DEBUG, "handle_kill(): %s killed user %s (%s)", source, u->nick, reason); |
553 |
user_delete (u); |
554 |
} |
555 |
} |
556 |
|
557 |
server_t * |
558 |
handle_server (sourceinfo_t *si, const char *name, const char *sid, int hops, const char *desc) |
559 |
{ |
560 |
server_t *s = NULL; |
561 |
|
562 |
if (si->s != NULL) |
563 |
{ |
564 |
/* A server introducing another server */ |
565 |
s = server_add (name, hops, si->s->name, sid, desc); |
566 |
} |
567 |
else if (cnt.server == 1) |
568 |
{ |
569 |
/* Our uplink introducing itself */ |
570 |
if (irccasecmp (name, curr_uplink->name)) |
571 |
slog (LG_ERROR, "handle_server(): uplink %s actually has name %s, continuing anyway", curr_uplink->name, name); |
572 |
s = server_add (name, hops, me.name, sid, desc); |
573 |
me.actual = s->name; |
574 |
me.recvsvr = true; |
575 |
} |
576 |
else |
577 |
slog (LG_ERROR, "handle_server(): unregistered/unknown server attempting to introduce another server %s", name); |
578 |
return s; |
579 |
} |
580 |
|
581 |
void |
582 |
handle_eob (server_t *s) |
583 |
{ |
584 |
node_t *n; |
585 |
server_t *s2; |
586 |
|
587 |
if (s == NULL) |
588 |
return; |
589 |
if (s->flags & SF_EOB) |
590 |
return; |
591 |
slog (LG_NETWORK, "handle_eob(): end of burst from %s (%d users)", s->name, s->users); |
592 |
hook_call_event ("server_eob", s); |
593 |
s->flags |= SF_EOB; |
594 |
/* convert P10 style EOB to ircnet/ratbox style */ |
595 |
LIST_FOREACH (n, s->children.head) |
596 |
{ |
597 |
s2 = static_cast<server_t *> (n->data); |
598 |
if (s2->flags & SF_EOB2) |
599 |
handle_eob (s2); |
600 |
} |
601 |
/* Reseed RNG now we have a little more data to seed with */ |
602 |
if (s->uplink == me.me) |
603 |
srand (rand () ^ ((NOW << 20) + cnt.user + (cnt.chanuser << 12)) ^ (cnt.chan << 17) ^ ~cnt.bin); |
604 |
} |
605 |
|
606 |
/* Received a message from a user, check if they are flooding |
607 |
* Returns true if the message should be ignored. |
608 |
* u - user sending the message |
609 |
* t - target of the message (to be used in warning the user, may be NULL |
610 |
* to use the server name) |
611 |
*/ |
612 |
int |
613 |
floodcheck (user_t *u, user_t *t) |
614 |
{ |
615 |
char *from; |
616 |
|
617 |
if (t == NULL) |
618 |
from = me.name; |
619 |
else if (t->server == me.me) |
620 |
from = t->nick; |
621 |
else |
622 |
{ |
623 |
slog (LG_ERROR, "BUG: tried to floodcheck message to non-service %s", t->nick); |
624 |
return 0; |
625 |
} |
626 |
|
627 |
/* Check if we match a services ignore */ |
628 |
if (svsignore_find (u)) |
629 |
return 1; |
630 |
|
631 |
if (config_options.flood_msgs) |
632 |
{ |
633 |
/* check if they're being ignored */ |
634 |
if (u->offenses > 10) |
635 |
{ |
636 |
if ((NOW - u->lastmsg) > 30) |
637 |
{ |
638 |
u->offenses -= 10; |
639 |
u->lastmsg = NOW; |
640 |
u->msgs = 0; |
641 |
} |
642 |
else |
643 |
return 1; |
644 |
} |
645 |
|
646 |
if ((NOW - u->lastmsg) > config_options.flood_time) |
647 |
{ |
648 |
u->lastmsg = NOW; |
649 |
u->msgs = 0; |
650 |
} |
651 |
|
652 |
u->msgs++; |
653 |
|
654 |
if (u->msgs > config_options.flood_msgs) |
655 |
{ |
656 |
/* they're flooding. */ |
657 |
/* perhaps allowed to? -- jilles */ |
658 |
if (has_priv_user (u, PRIV_FLOOD)) |
659 |
{ |
660 |
u->msgs = 0; |
661 |
return 0; |
662 |
} |
663 |
if (!u->offenses) |
664 |
{ |
665 |
/* ignore them the first time */ |
666 |
u->lastmsg = NOW; |
667 |
u->msgs = 0; |
668 |
u->offenses = 11; |
669 |
|
670 |
/* ok to use nick here, notice() will |
671 |
* change it to UID if necessary -- jilles */ |
672 |
notice (from, u->nick, "You have triggered services flood protection."); |
673 |
notice (from, u->nick, "This is your first offense. You will be ignored for 30 seconds."); |
674 |
|
675 |
snoop ("FLOOD: \2%s\2", u->nick); |
676 |
|
677 |
return 1; |
678 |
} |
679 |
|
680 |
if (u->offenses == 1) |
681 |
{ |
682 |
/* ignore them the second time */ |
683 |
u->lastmsg = NOW; |
684 |
u->msgs = 0; |
685 |
u->offenses = 12; |
686 |
|
687 |
notice (from, u->nick, "You have triggered services flood protection."); |
688 |
notice (from, u->nick, "This is your last warning. You will be ignored for 30 seconds."); |
689 |
|
690 |
snoop ("FLOOD: \2%s\2", u->nick); |
691 |
|
692 |
return 1; |
693 |
} |
694 |
|
695 |
if (u->offenses == 2) |
696 |
{ |
697 |
kline_t *k; |
698 |
|
699 |
/* kline them the third time */ |
700 |
k = kline_add ("*", u->host, "ten minute ban: flooding services", 600); |
701 |
k->setby = sstrdup (chansvs.nick); |
702 |
|
703 |
snoop ("FLOOD:KLINE: \2%s\2", u->nick); |
704 |
|
705 |
return 1; |
706 |
} |
707 |
} |
708 |
} |
709 |
|
710 |
return 0; |
711 |
} |
712 |
|
713 |
bool |
714 |
should_reg_umode (user_t *u) |
715 |
{ |
716 |
mynick_t *mn; |
717 |
|
718 |
if (nicksvs.me == NULL || nicksvs.no_nick_ownership || u->myuser == NULL || u->myuser->flags & MU_WAITAUTH) |
719 |
return false; |
720 |
mn = mynick_find (u->nick); |
721 |
return mn != NULL && mn->owner == u->myuser; |
722 |
} |