ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/ptasks.C
Revision: 1.6
Committed: Thu Aug 30 19:56:26 2007 UTC (16 years, 9 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.5: +4 -3 lines
Log Message:
- put faultcodes into their own namespace
- removed old files
- limited header garbage in atheme.h
- macros to inline bools for connection_t::is_*
- put some connection_t functions into the connection_t class

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * ptasks.C: Implementation of common protocol tasks.
3 pippijn 1.2 * Rights to this code are documented in doc/pod/license.pod.
4 pippijn 1.1 *
5 pippijn 1.4 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
6 pippijn 1.1 */
7    
8 pippijn 1.6 static char const rcsid[] = "$Id: ptasks.C,v 1.5 2007-08-29 21:01:19 pippijn Exp $";
9 pippijn 1.1
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 pippijn 1.4 #include <common/random.h>
16 pippijn 1.1 #include "uplink.h"
17     #include "pmodule.h"
18     #include "privs.h"
19 pippijn 1.6 #include "connection.h"
20 pippijn 1.1
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 pippijn 1.4 phandler->numeric_sts (me.name, 371, u->nick, ":%s", infotext[i]);
33 pippijn 1.1
34 pippijn 1.4 phandler->numeric_sts (me.name, 374, u->nick, ":End of /INFO list");
35 pippijn 1.1 }
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 pippijn 1.4 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 pippijn 1.1 }
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 pippijn 1.4 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 pippijn 1.1 }
64    
65     static void
66 pippijn 1.4 connection_stats_cb (char const * const line, void *privdata)
67 pippijn 1.1 {
68 pippijn 1.4 phandler->numeric_sts (me.name, 249, ((user_t *) privdata)->nick, "F :%s", line);
69 pippijn 1.1 }
70    
71     void
72     handle_stats (user_t *u, char req)
73     {
74     kline_t *k;
75     node_t *n;
76 pippijn 1.4 kline_vector::iterator klit = klnlist.begin ();
77     kline_vector::iterator klet = klnlist.end ();
78 pippijn 1.1 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 pippijn 1.4 #if 0 // bye for now, dictionaries
90 pippijn 1.1 case 'B':
91     if (!has_priv_user (u, PRIV_SERVER_AUSPEX))
92     break;
93    
94     dictionary_stats (dictionary_stats_cb, u);
95     break;
96 pippijn 1.4 #endif
97 pippijn 1.1
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 pippijn 1.4 phandler->numeric_sts (me.name, 213, u->nick, "C *@127.0.0.1 A %s %d uplink", uplink->name, uplink->port);
107 pippijn 1.1 }
108     break;
109    
110     case 'E':
111     case 'e':
112     if (!has_priv_user (u, PRIV_SERVER_AUSPEX))
113     break;
114    
115 pippijn 1.4 phandler->numeric_sts (me.name, 249, u->nick, "E :Last event to run: %s", last_event_ran);
116 pippijn 1.1
117 pippijn 1.4 phandler->numeric_sts (me.name, 249, u->nick, "E :%-28s %s", "Operation", "Next Execution");
118 pippijn 1.1 for (i = 0; i < MAX_EVENTS; i++)
119     {
120     if (event_table[i].active)
121 pippijn 1.4 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 pippijn 1.1 }
123    
124     break;
125    
126     case 'f':
127     case 'F':
128     if (!has_priv_user (u, PRIV_SERVER_AUSPEX))
129     break;
130    
131 pippijn 1.6 connection_t::stats (connection_stats_cb, u);
132 pippijn 1.1 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 pippijn 1.4 phandler->numeric_sts (me.name, 244, u->nick, "H * * %s", uplink->name);
143 pippijn 1.1 }
144     break;
145    
146     case 'I':
147     case 'i':
148 pippijn 1.4 phandler->numeric_sts (me.name, 215, u->nick, "I * * *@%s 0 nonopered", me.name);
149 pippijn 1.1 break;
150    
151     case 'K':
152     case 'k':
153     if (!has_priv_user (u, PRIV_AKILL))
154     break;
155    
156 pippijn 1.4 while (klit != klet)
157 pippijn 1.1 {
158     k = *klit;
159    
160 pippijn 1.4 phandler->numeric_sts (me.name, 216, u->nick, "K %s * %s :%s", k->host, k->user, k->reason);
161     ++klit;
162 pippijn 1.1 }
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 pippijn 1.4 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 pippijn 1.1 }
185     break;
186    
187     case 'T':
188     case 't':
189     if (!has_priv_user (u, PRIV_SERVER_AUSPEX))
190     break;
191    
192 pippijn 1.4 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 pippijn 1.6 phandler->numeric_sts (me.name, 249, u->nick, "T :connection %7d", connection_t::count ());
195 pippijn 1.4 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 pippijn 1.1
209 pippijn 1.4 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 pippijn 1.1 break;
212    
213     case 'u':
214 pippijn 1.4 phandler->numeric_sts (me.name, 242, u->nick, ":Services Uptime: %s", timediff (NOW - me.start));
215 pippijn 1.1 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 pippijn 1.4 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 pippijn 1.1 break;
226    
227     default:
228     break;
229     }
230    
231 pippijn 1.4 phandler->numeric_sts (me.name, 219, u->nick, "%c :End of /STATS report", req);
232 pippijn 1.1 }
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 pippijn 1.4 phandler->numeric_sts (me.name, 311, u->nick, "%s %s %s * :%s", t->nick, t->user, t->vhost, t->gecos);
247 pippijn 1.1 /* channels purposely omitted */
248 pippijn 1.4 phandler->numeric_sts (me.name, 312, u->nick, "%s %s :%s", t->nick, t->server->name, t->server->desc);
249 pippijn 1.1 if (t->flags & UF_AWAY)
250 pippijn 1.4 phandler->numeric_sts (me.name, 301, u->nick, "%s :Gone", t->nick);
251 pippijn 1.1 if (is_ircop (t))
252 pippijn 1.4 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 pippijn 1.1 if (t->myuser)
254 pippijn 1.4 phandler->numeric_sts (me.name, 330, u->nick, "%s %s :is logged in as", t->nick, t->myuser->name);
255 pippijn 1.1 }
256     else
257 pippijn 1.4 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 pippijn 1.1 }
260    
261     static void
262     single_trace (user_t *u, user_t *t)
263     {
264     if (is_ircop (t))
265 pippijn 1.4 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 pippijn 1.1 else
267 pippijn 1.4 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 pippijn 1.1 }
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 pippijn 1.4 phandler->numeric_sts (me.name, 206, u->nick, "Serv uplink %dS %dC %s *!*@%s 0", cnt.server - 1, nusers, me.actual, me.name);
295 pippijn 1.1 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 pippijn 1.4 phandler->numeric_sts (me.name, 262, u->nick, "%s :End of TRACE", target);
307 pippijn 1.1 }
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 pippijn 1.4 phandler->numeric_sts (me.name, 422, u->nick, ":The MOTD file is unavailable.");
329 pippijn 1.1 return;
330     }
331    
332 pippijn 1.5 snprintf (nebuf, BUFSIZE, "%" PRItime, nicksvs.expiry / 86400);
333     snprintf (cebuf, BUFSIZE, "%" PRItime, chansvs.expiry / 86400);
334 pippijn 1.1 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 pippijn 1.4 phandler->numeric_sts (me.name, 375, u->nick, ":- %s Message of the Day -", me.name);
339 pippijn 1.1
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 pippijn 1.4 phandler->numeric_sts (me.name, 372, u->nick, ":- %s", lbuf);
352 pippijn 1.1 }
353    
354 pippijn 1.4 phandler->numeric_sts (me.name, 376, u->nick, ":End of the message of the day.");
355 pippijn 1.1
356     fclose (f);
357     }
358    
359     void
360 pippijn 1.4 handle_away (user_t *u, char const * const message)
361 pippijn 1.1 {
362     if (message == NULL || *message == '\0')
363     {
364     if (u->flags & UF_AWAY)
365     {
366     u->flags &= ~UF_AWAY;
367 pippijn 1.4 u->callback.away (u);
368 pippijn 1.1 }
369     }
370     else
371     {
372     if (!(u->flags & UF_AWAY))
373     {
374     u->flags |= UF_AWAY;
375 pippijn 1.4 u->callback.away (u);
376 pippijn 1.1 }
377     }
378     }
379    
380     void
381     handle_message (sourceinfo_t *si, char *target, bool is_notice, char *message)
382     {
383     char *vec[3];
384    
385     /* message from server, ignore */
386     if (si->su == NULL)
387     return;
388    
389     /* If target is a channel and fantasy commands are enabled,
390     * this will return chanserv
391     */
392     si->service = find_service (target);
393    
394     if (*target == '#')
395     {
396     /* Call hook here */
397 pippijn 1.4 channel_t *c = channel_find (target);
398 pippijn 1.1 /* No such channel, ignore... */
399 pippijn 1.4 if (c == NULL)
400 pippijn 1.1 return;
401 pippijn 1.4 c->callback.message (c, si->su, message);
402 pippijn 1.1 }
403    
404     if (si->service == NULL)
405     {
406     if (!is_notice && (isalnum (target[0]) || strchr ("[\\]^_`{|}~", target[0])))
407     {
408     /* If it's not a notice and looks like a nick or
409     * user@server, send back an error message */
410     if (strchr (target, '@') || !ircd->uses_uid || (!ircd->uses_p10 && !isdigit (target[0])))
411 pippijn 1.4 phandler->numeric_sts (me.name, 401, si->su->nick, "%s :No such nick", target);
412 pippijn 1.1 else
413 pippijn 1.4 phandler->numeric_sts (me.name, 401, si->su->nick, "* :Target left IRC. Failed to deliver: [%.20s]", message);
414 pippijn 1.1 }
415     return;
416     }
417    
418     /* Run it through flood checks. Channel commands are checked
419     * separately.
420     */
421     if (si->service->me != NULL && *target != '#' && floodcheck (si->su, si->service->me))
422     return;
423    
424     if (!is_notice && config_options.secure && *target != '#' && irccasecmp (target, si->service->disp))
425     {
426 pippijn 1.4 notice (si->service->me->nick, si->su->nick, "For security reasons, \2/msg %s\2 has been disabled."
427     " Use \2/%s%s <command>\2 to send a command.",
428     si->service->me->nick,
429     (ircd->uses_rcommand ? "" : "msg "),
430     si->service->disp);
431 pippijn 1.1 return;
432     }
433    
434     vec[0] = target;
435     vec[1] = message;
436     vec[2] = NULL;
437     if (is_notice)
438     si->service->notice_handler (si, 2, vec);
439     else
440     si->service->handler (si, 2, vec);
441     }
442    
443     void
444 pippijn 1.4 handle_topic_from (sourceinfo_t *si, channel_t *c, char const * const setter, time_t ts, char const *topic)
445 pippijn 1.1 {
446 pippijn 1.4 bool approved = false;
447 pippijn 1.1 if (topic != NULL && topic[0] == '\0')
448     topic = NULL;
449 pippijn 1.4
450 pippijn 1.1 if (topic != NULL ? c->topic == NULL || strcmp (topic, c->topic) : c->topic != NULL)
451 pippijn 1.4 /* Only call the hook if the topic actually changed */
452     approved = c->callback.can_change_topic (c, si->su, si->s, setter, ts, topic);
453    
454     if (approved)
455 pippijn 1.1 {
456 pippijn 1.4 /* Allowed, process the change further */
457     handle_topic (c, setter, ts, topic);
458 pippijn 1.1 }
459     else
460     {
461     /* Not allowed, change it back */
462     if (c->topic != NULL)
463 pippijn 1.4 phandler->topic_sts (c, c->topic_setter, c->topicts, ts, c->topic);
464 pippijn 1.1 else
465 pippijn 1.4 /* Ick, there was no topic */
466     phandler->topic_sts (c, chansvs.nick != NULL ? chansvs.nick : me.name, ts - 1, ts, "");
467 pippijn 1.1 }
468     }
469    
470     void
471 pippijn 1.4 handle_topic (channel_t *c, char const * const setter, time_t ts, char const * const topic)
472 pippijn 1.1 {
473     char newsetter[HOSTLEN], *p;
474    
475     /* setter can be a nick, nick!user@host or server.
476     * strip off !user@host part if it's there
477     * (do we really want this?) */
478     strlcpy (newsetter, setter, sizeof newsetter);
479     p = strchr (newsetter, '!');
480     if (p != NULL)
481     *p = '\0';
482     /* drop identical topics from servers or chanserv, and ones with
483     * identical topicts */
484     if (topic != NULL && c->topic != NULL && !strcmp (topic, c->topic) && (strchr (newsetter, '.') || (chansvs.nick && !irccasecmp (newsetter, chansvs.nick)) || ts == c->topicts))
485     return;
486     if (c->topic != NULL)
487 pippijn 1.4 sfree (c->topic);
488 pippijn 1.1 if (c->topic_setter != NULL)
489 pippijn 1.4 sfree (c->topic_setter);
490 pippijn 1.1 if (topic != NULL && topic[0] != '\0')
491     {
492     c->topic = sstrdup (topic);
493     c->topic_setter = sstrdup (newsetter);
494     }
495     else
496     c->topic = c->topic_setter = NULL;
497     c->topicts = ts;
498    
499 pippijn 1.4 c->callback.topic (c);
500 pippijn 1.1 }
501    
502     void
503     handle_kill (sourceinfo_t *si, char *victim, char const *reason)
504     {
505 pippijn 1.4 char const * const source = get_oper_name (si);
506 pippijn 1.1 user_t *u;
507     static time_t lastkill = 0;
508     static unsigned int killcount = 0;
509    
510     u = user_find (victim);
511     if (u == NULL)
512     slog (LG_DEBUG, "handle_kill(): %s killed unknown user %s (%s)", source, victim, reason);
513     else if (u->server == me.me)
514     {
515     slog (LG_INFO, "handle_kill(): %s killed service %s (%s)", source, u->nick, reason);
516     if (lastkill != NOW && killcount < 5 + me.me->users)
517     killcount = 0, lastkill = NOW;
518     killcount++;
519     if (killcount < 5 + me.me->users)
520     reintroduce_user (u);
521     else
522     {
523     slog (LG_ERROR, "handle_kill(): services kill fight (%s -> %s), shutting down", source, u->nick);
524     wallops (_("Services kill fight (%s -> %s), shutting down!"), source, u->nick);
525     snoop (_("ERROR: Services kill fight (%s -> %s), shutting down!"), source, u->nick);
526     runflags |= RF_SHUTDOWN;
527     }
528     }
529     else
530     {
531     slog (LG_DEBUG, "handle_kill(): %s killed user %s (%s)", source, u->nick, reason);
532     user_delete (u);
533     }
534     }
535    
536     server_t *
537 pippijn 1.4 handle_server (sourceinfo_t *si, char const * const name, char const * const sid, int hops, char const * const desc)
538 pippijn 1.1 {
539     server_t *s = NULL;
540    
541     if (si->s != NULL)
542     {
543     /* A server introducing another server */
544     s = server_add (name, hops, si->s->name, sid, desc);
545     }
546     else if (cnt.server == 1)
547     {
548     /* Our uplink introducing itself */
549     if (irccasecmp (name, curr_uplink->name))
550     slog (LG_ERROR, "handle_server(): uplink %s actually has name %s, continuing anyway", curr_uplink->name, name);
551     s = server_add (name, hops, me.name, sid, desc);
552     me.actual = s->name;
553     me.recvsvr = true;
554     }
555     else
556     slog (LG_ERROR, "handle_server(): unregistered/unknown server attempting to introduce another server %s", name);
557     return s;
558     }
559    
560     void
561     handle_eob (server_t *s)
562     {
563     node_t *n;
564     server_t *s2;
565    
566     if (s == NULL)
567     return;
568     if (s->flags & SF_EOB)
569     return;
570     slog (LG_NETWORK, "handle_eob(): end of burst from %s (%d users)", s->name, s->users);
571 pippijn 1.4 s->callback.eob (s);
572 pippijn 1.1 s->flags |= SF_EOB;
573     /* convert P10 style EOB to ircnet/ratbox style */
574     LIST_FOREACH (n, s->children.head)
575     {
576     s2 = static_cast<server_t *> (n->data);
577     if (s2->flags & SF_EOB2)
578     handle_eob (s2);
579     }
580     /* Reseed RNG now we have a little more data to seed with */
581     if (s->uplink == me.me)
582 pippijn 1.4 init_gen_rand (gen_rand32 () ^ ((NOW << 20) + cnt.user + (cnt.chanuser << 12)) ^ (cnt.chan << 17) ^ ~cnt.bin);
583 pippijn 1.1 }
584    
585     /* Received a message from a user, check if they are flooding
586     * Returns true if the message should be ignored.
587     * u - user sending the message
588     * t - target of the message (to be used in warning the user, may be NULL
589     * to use the server name)
590     */
591     int
592     floodcheck (user_t *u, user_t *t)
593     {
594     char *from;
595 pippijn 1.4 static time_t last_ignore_notice = 0;
596 pippijn 1.1
597     if (t == NULL)
598     from = me.name;
599     else if (t->server == me.me)
600     from = t->nick;
601     else
602     {
603     slog (LG_ERROR, "BUG: tried to floodcheck message to non-service %s", t->nick);
604     return 0;
605     }
606    
607     /* Check if we match a services ignore */
608 pippijn 1.4 if (svsignore_find(u))
609     {
610     if (u->msgs == 0 && last_ignore_notice != NOW)
611     {
612     /* tell them once per session, don't flood */
613     u->msgs = 1;
614     last_ignore_notice = NOW;
615     notice (from, u->nick, _("You are on services ignore. You may not use any service."));
616     }
617     return 1;
618     }
619    
620 pippijn 1.1 if (config_options.flood_msgs)
621     {
622     /* check if they're being ignored */
623     if (u->offenses > 10)
624     {
625     if ((NOW - u->lastmsg) > 30)
626     {
627     u->offenses -= 10;
628     u->lastmsg = NOW;
629     u->msgs = 0;
630     }
631     else
632     return 1;
633     }
634    
635     if ((NOW - u->lastmsg) > config_options.flood_time)
636     {
637     u->lastmsg = NOW;
638     u->msgs = 0;
639     }
640    
641     u->msgs++;
642    
643     if (u->msgs > config_options.flood_msgs)
644     {
645     /* they're flooding. */
646     /* perhaps allowed to? -- jilles */
647     if (has_priv_user (u, PRIV_FLOOD))
648     {
649     u->msgs = 0;
650     return 0;
651     }
652     if (!u->offenses)
653     {
654     /* ignore them the first time */
655     u->lastmsg = NOW;
656     u->msgs = 0;
657     u->offenses = 11;
658    
659     /* ok to use nick here, notice() will
660     * change it to UID if necessary -- jilles */
661     notice (from, u->nick, "You have triggered services flood protection.");
662     notice (from, u->nick, "This is your first offense. You will be ignored for 30 seconds.");
663    
664     snoop ("FLOOD: \2%s\2", u->nick);
665    
666     return 1;
667     }
668    
669     if (u->offenses == 1)
670     {
671     /* ignore them the second time */
672     u->lastmsg = NOW;
673     u->msgs = 0;
674     u->offenses = 12;
675    
676     notice (from, u->nick, "You have triggered services flood protection.");
677     notice (from, u->nick, "This is your last warning. You will be ignored for 30 seconds.");
678    
679     snoop ("FLOOD: \2%s\2", u->nick);
680    
681     return 1;
682     }
683    
684     if (u->offenses == 2)
685     {
686     kline_t *k;
687    
688     /* kline them the third time */
689     k = kline_add ("*", u->host, "ten minute ban: flooding services", 600);
690     k->setby = sstrdup (chansvs.nick);
691    
692     snoop ("FLOOD:KLINE: \2%s\2", u->nick);
693    
694     return 1;
695     }
696     }
697     }
698    
699     return 0;
700     }
701    
702     bool
703     should_reg_umode (user_t *u)
704     {
705     mynick_t *mn;
706    
707     if (nicksvs.me == NULL || nicksvs.no_nick_ownership || u->myuser == NULL || u->myuser->flags & MU_WAITAUTH)
708     return false;
709     mn = mynick_find (u->nick);
710     return mn != NULL && mn->owner == u->myuser;
711     }