ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/ptasks.C
Revision: 1.9
Committed: Sun Sep 9 20:05:52 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.8: +6 -5 lines
Log Message:
- changed configurations to the c++ stdlib
- more #defines to enum
- removed getopt.h and link.h from the system as they were unused
- reworked logstreams
- added an itoa with old syntax
- made klines objects
- moved some global variables into appropriate classes
- fixed boost.foreach's compiler workaround #if's
- allow other files to add exceptions with ADD_EXCEPTION
- changed mynick_t to c++ object
- moved servers.h out of atheme.h
- corrected PING from inspircd 1.2

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.8 2007-09-05 11:23:15 pippijn Exp $";
9
10 #include "atheme.h"
11 #include "servers.h"
12 #include <account/myuser.h>
13 #include <account/mynick.h>
14 #include <account/kline.h>
15 #include <account/svsignore.h>
16 #include <common/random.h>
17 #include "uplink.h"
18 #include "pmodule.h"
19 #include "privs.h"
20 #include "connection.h"
21
22 void
23 handle_info (user_t *u)
24 {
25 unsigned int i;
26
27 if (u == NULL)
28 return;
29 if (floodcheck (u, NULL))
30 return;
31
32 for (i = 0; infotext[i]; i++)
33 phandler->numeric_sts (me.name, 371, u->nick, ":%s", infotext[i]);
34
35 phandler->numeric_sts (me.name, 374, u->nick, ":End of /INFO list");
36 }
37
38 void
39 handle_version (user_t *u)
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_t::list_type::iterator klit = kline_t::list.begin ();
77 kline_t::list_type::iterator klet = kline_t::list.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 (si->service->chanmsg == false)
410 continue;
411
412 if (is_notice)
413 si->service->notice_handler (si, 2, vec);
414 else
415 si->service->handler (si, 2, vec);
416 }
417 }
418
419 void
420 handle_message (sourceinfo_t *si, char *target, bool is_notice, char *message)
421 {
422 char *vec[3];
423
424 /* message from server, ignore */
425 if (si->su == NULL)
426 return;
427
428 /* if this is a channel, handle it differently. */
429 if (*target == '#')
430 {
431 handle_channel_message (si, target, is_notice, message);
432 return;
433 }
434
435 si->service = find_service (target);
436
437 if (si->service == NULL)
438 {
439 if (!is_notice && (isalnum (target[0]) || strchr ("[\\]^_`{|}~", target[0])))
440 {
441 /* If it's not a notice and looks like a nick or
442 * user@server, send back an error message */
443 if (strchr (target, '@') || !ircd->uses_uid || (!ircd->uses_p10 && !isdigit (target[0])))
444 phandler->numeric_sts (me.name, 401, si->su->nick, "%s :No such nick", target);
445 else
446 phandler->numeric_sts (me.name, 401, si->su->nick, "* :Target left IRC. Failed to deliver: [%.20s]", message);
447 }
448 return;
449 }
450
451 /* Run it through flood checks. Channel commands are checked
452 * separately.
453 */
454 if (si->service->me != NULL && floodcheck (si->su, si->service->me))
455 return;
456
457 if (!is_notice && config_options.secure && irccasecmp (target, si->service->disp))
458 {
459 notice (si->service->me->nick, si->su->nick, "For security reasons, \2/msg %s\2 has been disabled."
460 " Use \2/%s%s <command>\2 to send a command.",
461 si->service->me->nick,
462 ircd->uses_rcommand ? "" : "msg ",
463 si->service->disp);
464 return;
465 }
466
467 vec[0] = target;
468 vec[1] = message;
469 vec[2] = NULL;
470 if (is_notice)
471 si->service->notice_handler (si, 2, vec);
472 else
473 si->service->handler (si, 2, vec);
474 }
475
476 void
477 handle_topic_from (sourceinfo_t *si, channel_t *c, char const * const setter, time_t ts, char const *topic)
478 {
479 bool approved = false;
480 if (topic != NULL && topic[0] == '\0')
481 topic = NULL;
482
483 if (topic != NULL ? c->topic == NULL || strcmp (topic, c->topic) : c->topic != NULL)
484 /* Only call the hook if the topic actually changed */
485 approved = c->callback.can_change_topic (c, si->su, si->s, setter, ts, topic);
486
487 if (approved)
488 {
489 /* Allowed, process the change further */
490 handle_topic (c, setter, ts, topic);
491 }
492 else
493 {
494 /* Not allowed, change it back */
495 if (c->topic != NULL)
496 phandler->topic_sts (c, c->topic_setter, c->topicts, ts, c->topic);
497 else
498 /* Ick, there was no topic */
499 phandler->topic_sts (c, chansvs.nick != NULL ? chansvs.nick : me.name, ts - 1, ts, "");
500 }
501 }
502
503 void
504 handle_topic (channel_t *c, char const * const setter, time_t ts, char const * const topic)
505 {
506 char newsetter[HOSTLEN], *p;
507
508 /* setter can be a nick, nick!user@host or server.
509 * strip off !user@host part if it's there
510 * (do we really want this?) */
511 strlcpy (newsetter, setter, sizeof newsetter);
512 p = strchr (newsetter, '!');
513 if (p != NULL)
514 *p = '\0';
515 /* drop identical topics from servers or chanserv, and ones with
516 * identical topicts */
517 if (topic != NULL && c->topic != NULL && !strcmp (topic, c->topic) && (strchr (newsetter, '.') || (chansvs.nick && !irccasecmp (newsetter, chansvs.nick)) || ts == c->topicts))
518 return;
519 if (c->topic != NULL)
520 sfree (c->topic);
521 if (c->topic_setter != NULL)
522 sfree (c->topic_setter);
523 if (topic != NULL && topic[0] != '\0')
524 {
525 c->topic = sstrdup (topic);
526 c->topic_setter = sstrdup (newsetter);
527 }
528 else
529 c->topic = c->topic_setter = NULL;
530 c->topicts = ts;
531
532 c->callback.topic (c);
533 }
534
535 void
536 handle_kill (sourceinfo_t *si, char *victim, char const *reason)
537 {
538 char const * const source = get_oper_name (si);
539 user_t *u;
540 static time_t lastkill = 0;
541 static unsigned int killcount = 0;
542
543 u = user_find (victim);
544 if (u == NULL)
545 slog (LG_DEBUG, "handle_kill(): %s killed unknown user %s (%s)", source, victim, reason);
546 else if (u->server == me.me)
547 {
548 slog (LG_INFO, "handle_kill(): %s killed service %s (%s)", source, u->nick, reason);
549 if (lastkill != NOW && killcount < 5 + me.me->users)
550 killcount = 0, lastkill = NOW;
551 killcount++;
552 if (killcount < 5 + me.me->users)
553 reintroduce_user (u);
554 else
555 {
556 slog (LG_ERROR, "handle_kill(): services kill fight (%s -> %s), shutting down", source, u->nick);
557 wallops (_("Services kill fight (%s -> %s), shutting down!"), source, u->nick);
558 snoop (_("ERROR: Services kill fight (%s -> %s), shutting down!"), source, u->nick);
559 runflags |= RF_SHUTDOWN;
560 }
561 }
562 else
563 {
564 slog (LG_DEBUG, "handle_kill(): %s killed user %s (%s)", source, u->nick, reason);
565 user_delete (u);
566 }
567 }
568
569 server_t *
570 handle_server (sourceinfo_t *si, char const * const name, char const * const sid, int hops, char const * const desc)
571 {
572 server_t *s = NULL;
573
574 if (si->s != NULL)
575 {
576 /* A server introducing another server */
577 s = server_add (name, hops, si->s->name, sid, desc);
578 }
579 else if (cnt.server == 1)
580 {
581 /* Our uplink introducing itself */
582 if (irccasecmp (name, curr_uplink->name))
583 slog (LG_ERROR, "handle_server(): uplink %s actually has name %s, continuing anyway", curr_uplink->name, name);
584 s = server_add (name, hops, me.name, sid, desc);
585 me.actual = s->name;
586 me.recvsvr = true;
587 }
588 else
589 slog (LG_ERROR, "handle_server(): unregistered/unknown server attempting to introduce another server %s", name);
590 return s;
591 }
592
593 void
594 handle_eob (server_t *s)
595 {
596 node_t *n;
597 server_t *s2;
598
599 if (s == NULL)
600 return;
601 if (s->flags & SF_EOB)
602 return;
603 slog (LG_NETWORK, "handle_eob(): end of burst from %s (%d users)", s->name, s->users);
604 s->callback.eob (s);
605 s->flags |= SF_EOB;
606 /* convert P10 style EOB to ircnet/ratbox style */
607 LIST_FOREACH (n, s->children.head)
608 {
609 s2 = static_cast<server_t *> (n->data);
610 if (s2->flags & SF_EOB2)
611 handle_eob (s2);
612 }
613 /* Reseed RNG now we have a little more data to seed with */
614 if (s->uplink == me.me)
615 init_gen_rand (gen_rand32 () ^ ((NOW << 20) + cnt.user + (cnt.chanuser << 12)) ^ (cnt.chan << 17) ^ ~cnt.bin);
616 }
617
618 /* Received a message from a user, check if they are flooding
619 * Returns true if the message should be ignored.
620 * u - user sending the message
621 * t - target of the message (to be used in warning the user, may be NULL
622 * to use the server name)
623 */
624 int
625 floodcheck (user_t *u, user_t *t)
626 {
627 char *from;
628 static time_t last_ignore_notice = 0;
629
630 if (t == NULL)
631 from = me.name;
632 else if (t->server == me.me)
633 from = t->nick;
634 else
635 {
636 slog (LG_ERROR, "BUG: tried to floodcheck message to non-service %s", t->nick);
637 return 0;
638 }
639
640 /* Check if we match a services ignore */
641 if (svsignore_find(u))
642 {
643 if (u->msgs == 0 && last_ignore_notice != NOW)
644 {
645 /* tell them once per session, don't flood */
646 u->msgs = 1;
647 last_ignore_notice = NOW;
648 notice (from, u->nick, _("You are on services ignore. You may not use any service."));
649 }
650 return 1;
651 }
652
653 if (config_options.flood_msgs)
654 {
655 /* check if they're being ignored */
656 if (u->offenses > 10)
657 {
658 if ((NOW - u->lastmsg) > 30)
659 {
660 u->offenses -= 10;
661 u->lastmsg = NOW;
662 u->msgs = 0;
663 }
664 else
665 return 1;
666 }
667
668 if ((NOW - u->lastmsg) > config_options.flood_time)
669 {
670 u->lastmsg = NOW;
671 u->msgs = 0;
672 }
673
674 u->msgs++;
675
676 if (u->msgs > config_options.flood_msgs)
677 {
678 /* they're flooding. */
679 /* perhaps allowed to? -- jilles */
680 if (has_priv_user (u, PRIV_FLOOD))
681 {
682 u->msgs = 0;
683 return 0;
684 }
685 if (!u->offenses)
686 {
687 /* ignore them the first time */
688 u->lastmsg = NOW;
689 u->msgs = 0;
690 u->offenses = 11;
691
692 /* ok to use nick here, notice() will
693 * change it to UID if necessary -- jilles */
694 notice (from, u->nick, "You have triggered services flood protection.");
695 notice (from, u->nick, "This is your first offense. You will be ignored for 30 seconds.");
696
697 snoop ("FLOOD: \2%s\2", u->nick);
698
699 return 1;
700 }
701
702 if (u->offenses == 1)
703 {
704 /* ignore them the second time */
705 u->lastmsg = NOW;
706 u->msgs = 0;
707 u->offenses = 12;
708
709 notice (from, u->nick, "You have triggered services flood protection.");
710 notice (from, u->nick, "This is your last warning. You will be ignored for 30 seconds.");
711
712 snoop ("FLOOD: \2%s\2", u->nick);
713
714 return 1;
715 }
716
717 if (u->offenses == 2)
718 {
719 kline_t *k;
720
721 /* kline them the third time */
722 k = kline_t::create ("*", u->host, "ten minute ban: flooding services", 600);
723 k->setby = sstrdup (chansvs.nick);
724
725 snoop ("FLOOD:KLINE: \2%s\2", u->nick);
726
727 return 1;
728 }
729 }
730 }
731
732 return 0;
733 }
734
735 bool
736 should_reg_umode (user_t *u)
737 {
738 mynick_t *mn;
739
740 if (nicksvs.me == NULL || nicksvs.no_nick_ownership || u->myuser == NULL || u->myuser->flags & MU_WAITAUTH)
741 return false;
742 mn = mynick_t::find (u->nick);
743 return mn != NULL && mn->owner == u->myuser;
744 }