ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/ptasks.C
Revision: 1.5
Committed: Wed Aug 29 21:01:19 2007 UTC (16 years, 9 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.4: +3 -3 lines
Log Message:
- reduced ifdefs by moving __GNUC__ and friends to svsconfig.h
- #define to enum { } in tools.h
- corrected log levels a bit
- made timersub an inline function instead of a macro
- added a simple garbage collection mechanism for postponed freeing of lost
  memory chunks
- enhanced type_traits
- merged inspircd1.2 support with upstream
- reformatting
- renamed TTP to a more "standard" PRItime and STP to PRIsize

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