ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/ptasks.C
Revision: 1.7
Committed: Tue Sep 4 11:13:26 2007 UTC (16 years, 9 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.6: +45 -15 lines
Log Message:
- fixed bug in crypto
- merged with upstream

File Contents

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