ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/protocol/inspircd11.C
Revision: 1.2
Committed: Sat Jul 21 01:29:09 2007 UTC (19 years, 4 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.1: +2 -2 lines
Log Message:
- moved to new documentation system
- fixed small build error

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * Copyright © 2005-2006 Atheme Development Group
3 pippijn 1.2 * Rights to this code are documented in doc/pod/license.pod.
4 pippijn 1.1 *
5     * This file contains protocol support for spanning tree 1.1 branch inspircd.
6     *
7 pippijn 1.2 * $Id: inspircd11.C,v 1.1 2007-07-19 08:24:55 pippijn Exp $
8 pippijn 1.1 */
9    
10     #include "atheme.h"
11     #include <account/mychan.h>
12     #include <account/myuser.h>
13     #include "uplink.h"
14     #include "pmodule.h"
15     #include "protocol/inspircd.h"
16    
17     static char const rcsid[] = "$Id";
18    
19     struct inspircd11_listeners : callback::has_listeners
20     {
21     };
22    
23     inspircd11_listeners listeners;
24    
25     DECLARE_MODULE_V1 ("protocol/inspircd", true, _modinit, NULL, rcsid, "InspIRCd Core Team <http://www.inspircd.org/>");
26    
27     /* *INDENT-OFF* */
28    
29     ircd_t InspIRCd = {
30     "InspIRCd 1.1.x", /* IRCd name */
31     "$", /* TLD Prefix, used by Global. */
32     false, /* Whether or not we use IRCNet/TS6 UID */
33     false, /* Whether or not we use RCOMMAND */
34     true, /* Whether or not we support channel owners. */
35     true, /* Whether or not we support channel protection. */
36     true, /* Whether or not we support halfops. */
37     false, /* Whether or not we use P10 */
38     true, /* Whether or not we use vHosts. */
39     CMODE_OPERONLY, /* Oper-only cmodes */
40     CMODE_OWNER, /* Integer flag for owner channel flag. */
41     CMODE_PROTECT, /* Integer flag for protect channel flag. */
42     CMODE_HALFOP, /* Integer flag for halfops. */
43     "+q", /* Mode we set for owner. */
44     "+a", /* Mode we set for protect. */
45     "+h", /* Mode we set for halfops. */
46     PROTOCOL_INSPIRCD, /* Protocol type */
47     0, /* Permanent cmodes */
48     "beIg", /* Ban-like cmodes */
49     'e', /* Except mchar */
50     'I', /* Invex mchar */
51     IRCD_CIDR_BANS /* Flags */
52     };
53    
54     cmode_t inspircd_mode_list[] = {
55     { 'i', CMODE_INVITE },
56     { 'm', CMODE_MOD },
57     { 'n', CMODE_NOEXT },
58     { 'p', CMODE_PRIV },
59     { 's', CMODE_SEC },
60     { 't', CMODE_TOPIC },
61     { 'c', CMODE_NOCOLOR },
62     { 'M', CMODE_MODREG },
63     { 'R', CMODE_REGONLY },
64     { 'O', CMODE_OPERONLY },
65     { 'S', CMODE_STRIP },
66     { 'K', CMODE_NOKNOCK },
67     { 'V', CMODE_NOINVITE },
68     { 'C', CMODE_NOCTCP },
69     { 'N', CMODE_STICKY },
70     { 'G', CMODE_CENSOR },
71     { 'P', CMODE_NOCAPS },
72     { 'z', CMODE_SSLONLY },
73     { 'T', CMODE_NONOTICE },
74     { '\0', 0 }
75     };
76    
77     static bool check_flood(const char *, channel_t *, mychan_t *, user_t *, myuser_t *);
78     static bool check_jointhrottle(const char *, channel_t *, mychan_t *, user_t *, myuser_t *);
79     static bool check_forward(const char *, channel_t *, mychan_t *, user_t *, myuser_t *);
80     static bool check_rejoindelay(const char *, channel_t *, mychan_t *, user_t *, myuser_t *);
81    
82     extmode inspircd_ignore_mode_list[] = {
83     { 'f', check_flood },
84     { 'j', check_jointhrottle },
85     { 'L', check_forward },
86     { 'J', check_rejoindelay },
87     { '\0', 0 }
88     };
89    
90     cmode_t inspircd_status_mode_list[] = {
91     { 'q', CMODE_OWNER },
92     { 'a', CMODE_PROTECT },
93     { 'o', CMODE_OP },
94     { 'h', CMODE_HALFOP },
95     { 'v', CMODE_VOICE },
96     { '\0', 0 }
97     };
98    
99     cmode_t inspircd_prefix_mode_list[] = {
100     { '~', CMODE_OWNER },
101     { '&', CMODE_PROTECT },
102     { '@', CMODE_OP },
103     { '%', CMODE_HALFOP },
104     { '+', CMODE_VOICE },
105     { '\0', 0 }
106     };
107    
108     /* CAPABilities */
109     static bool has_servicesmod = false;
110     static bool has_globopsmod = false;
111     static bool has_svshold = false;
112     static int has_protocol = 0;
113    
114     #define PROTOCOL_SNONOTICE 1102 /* has SNONOTICE and OPERNOTICE commands */
115     #define PROTOCOL_NEWTS 1104 /* does not send "confirming" FMODEs on TS changes and uses clear/ignore semantics also for FMODE */
116    
117     /* *INDENT-ON* */
118    
119     static bool
120     check_flood (const char *value, channel_t *c, mychan_t *mc, user_t *u, myuser_t *mu)
121     {
122    
123     return *value == '*' ? check_jointhrottle (value + 1, c, mc, u, mu) : check_jointhrottle (value, c, mc, u, mu);
124     }
125    
126     static bool
127     check_jointhrottle (const char *value, channel_t *c, mychan_t *mc, user_t *u, myuser_t *mu)
128     {
129     const char *p, *arg2;
130    
131     p = value, arg2 = NULL;
132     while (*p != '\0')
133     {
134     if (*p == ':')
135     {
136     if (arg2 != NULL)
137     return false;
138     arg2 = p + 1;
139     }
140     else if (!isdigit (*p))
141     return false;
142     p++;
143     }
144     if (arg2 == NULL)
145     return false;
146     if (p - arg2 > 10 || arg2 - value - 1 > 10 || !atoi (value) || !atoi (arg2))
147     return false;
148     return true;
149     }
150    
151     static bool
152     check_forward (const char *value, channel_t *c, mychan_t *mc, user_t *u, myuser_t *mu)
153     {
154     channel_t *target_c;
155     mychan_t *target_mc;
156    
157     if (*value != '#' || strlen (value) > 50)
158     return false;
159     if (u == NULL && mu == NULL)
160     return true;
161     target_c = channel_find (value);
162     target_mc = mychan_find (value);
163     if (target_c == NULL && target_mc == NULL)
164     return false;
165     return true;
166     }
167    
168     static bool
169     check_rejoindelay (const char *value, channel_t *c, mychan_t *mc, user_t *u, myuser_t *mu)
170     {
171     const char *ch = value;
172    
173     while (*ch)
174     {
175     if (!isdigit (*ch))
176     return false;
177     ch++;
178     }
179    
180     if (atoi (value) <= 0)
181     {
182     return false;
183     }
184     else
185     {
186     return true;
187     }
188     }
189    
190    
191     /* login to our uplink */
192     static unsigned int
193     inspircd_server_login (void)
194     {
195     int ret;
196    
197     /* XXX This is a horrible hack, but I don't know how else */
198     sleep (3);
199    
200     ret = sts ("SERVER %s %s 0 :%s", me.name, curr_uplink->pass, me.desc);
201     if (ret == 1)
202     return 1;
203    
204     me.bursting = true;
205     sts ("BURST");
206     /* XXX: Being able to get this data as a char* would be nice - Brain */
207     sts (":%s VERSION :" PACKAGE_NAME "-%s. %s %s%s%s%s%s%s%s%s%s%s", me.name, 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" : "");
208     services_init ();
209     return 0;
210     }
211    
212     /* introduce a client */
213     static void
214     inspircd_introduce_nick (user_t *u)
215     {
216     /* :services-dev.chatspike.net NICK 1133994664 OperServ chatspike.net chatspike.net services +oii 0.0.0.0 :Operator Server */
217     sts (":%s NICK %ld %s %s %s %s +%s 0.0.0.0 :%s", me.name, u->ts, u->nick, u->host, u->host, u->user, "io", u->gecos);
218     sts (":%s OPERTYPE Services", u->nick);
219     }
220    
221     static void
222     inspircd_quit_sts (user_t *u, const char *reason)
223     {
224     if (!me.connected)
225     return;
226    
227     sts (":%s QUIT :%s", u->nick, reason);
228     }
229    
230     /* WALLOPS wrapper */
231     static void
232     inspircd_wallops_sts (const char *text)
233     {
234     char *sendernick = NULL;
235     user_t *u;
236     node_t *n;
237    
238     if (has_protocol >= PROTOCOL_SNONOTICE)
239     {
240     /* XXX */
241     if (has_globopsmod)
242     sts (":%s SNONOTICE g :%s", me.name, text);
243     else
244     sts (":%s OPERNOTICE :%s", me.name, text);
245     return;
246     }
247    
248     if (me.me == NULL)
249     return;
250    
251     if (is_internal_client (user_find_named (opersvs.nick)))
252     {
253     sendernick = opersvs.nick;
254     }
255     else
256     {
257     LIST_FOREACH (n, me.me->userlist.head)
258     {
259     u = (user_t *) n->data;
260    
261     sendernick = u->nick;
262     break;
263     }
264     }
265    
266     if (sendernick == NULL)
267     {
268     /*
269     * this means we have no pseudoclients -- under present inspircd, servers cannot globops, and
270     * thus, we will need to bail -- slog, and let them know. --w00t
271     */
272     slog (LG_ERROR, "wallops_sts(): InspIRCD requires at least one pseudoclient module to be loaded to send wallops.");
273     return;
274     }
275    
276     sts (":%s GLOBOPS :%s", sendernick, text);
277     }
278    
279     /* join a channel */
280     static void
281     inspircd_join_sts (channel_t *c, user_t *u, bool isnew, char *modes)
282     {
283     if (isnew)
284     {
285     sts (":%s FJOIN %s %ld :@,%s", me.name, c->name, c->ts, u->nick);
286     if (modes[0] && modes[1])
287     sts (":%s FMODE %s %ld %s", me.name, c->name, c->ts, modes);
288     }
289     else
290     {
291     sts (":%s FJOIN %s %ld :@,%s", me.name, c->name, c->ts, u->nick);
292     }
293     }
294    
295     static void
296     inspircd_chan_lowerts (channel_t *c, user_t *u)
297     {
298     slog (LG_DEBUG, "inspircd_chan_lowerts(): lowering TS for %s to %ld", c->name, (long) c->ts);
299    
300     sts (":%s FJOIN %s %ld :@,%s", me.name, c->name, c->ts, u->nick);
301     sts (":%s FMODE %s %ld %s", me.name, c->name, c->ts, channel_modes (c, true));
302     }
303    
304     /* kicks a user from a channel */
305     static void
306     inspircd_kick (char *from, char *channel, char *to, char *reason)
307     {
308     channel_t *chan = channel_find (channel);
309     user_t *user = user_find (to);
310    
311     if (!chan || !user)
312     return;
313    
314     sts (":%s KICK %s %s :%s", from, channel, to, reason);
315    
316     chanuser_delete (chan, user);
317     }
318    
319     /* PRIVMSG wrapper */
320     static void
321     inspircd_msg (const char *from, const char *target, const char *fmt, ...)
322     {
323     va_list ap;
324     char buf[BUFSIZE];
325    
326     va_start (ap, fmt);
327     vsnprintf (buf, BUFSIZE, fmt, ap);
328     va_end (ap);
329    
330     sts (":%s PRIVMSG %s :%s", from, target, buf);
331     }
332    
333     /* NOTICE wrapper */
334     static void
335     inspircd_notice_user_sts (user_t *from, user_t *target, const char *text)
336     {
337     sts (":%s NOTICE %s :%s", from ? from->nick : me.name, target->nick, text);
338     }
339    
340     static void
341     inspircd_notice_global_sts (user_t *from, const char *mask, const char *text)
342     {
343     sts (":%s NOTICE %s%s :%s", from ? from->nick : me.name, ircd->tldprefix, mask, text);
344     }
345    
346     static void
347     inspircd_notice_channel_sts (user_t *from, channel_t *target, const char *text)
348     {
349     sts (":%s NOTICE %s :%s", from ? from->nick : me.name, target->name, text);
350     }
351    
352     static void
353     inspircd_numeric_sts (char *from, int numeric, char *target, char *fmt, ...)
354     {
355     va_list ap;
356     char buf[BUFSIZE];
357    
358     va_start (ap, fmt);
359     vsnprintf (buf, BUFSIZE, fmt, ap);
360     va_end (ap);
361    
362     sts (":%s PUSH %s ::%s %d %s %s", me.name, target, from, numeric, target, buf);
363     }
364    
365     /* KILL wrapper */
366     static void
367     inspircd_skill (char *from, char *nick, char *fmt, ...)
368     {
369     va_list ap;
370     char buf[BUFSIZE];
371    
372     va_start (ap, fmt);
373     vsnprintf (buf, BUFSIZE, fmt, ap);
374     va_end (ap);
375    
376     sts (":%s KILL %s :[%s] Killed (%s (%s))", from, nick, me.name, from, buf);
377     }
378    
379     /* PART wrapper */
380     static void
381     inspircd_part_sts (channel_t *c, user_t *u)
382     {
383     sts (":%s PART %s :Leaving", u->nick, c->name);
384     }
385    
386     /* server-to-server KLINE wrapper */
387     static void
388     inspircd_kline_sts (char *server, char *user, char *host, long duration, char *reason)
389     {
390     if (!me.connected)
391     return;
392    
393     /* :services-dev.chatspike.net ADDLINE G test@test.com Brain 1133994664 0 :You are banned from this network */
394     sts (":%s ADDLINE G %s@%s %s %ld %ld :%s", me.name, user, host, opersvs.nick, time (NULL), duration, reason);
395     }
396    
397     /* server-to-server UNKLINE wrapper */
398     static void
399     inspircd_unkline_sts (char *server, char *user, char *host)
400     {
401     if (!me.connected)
402     return;
403    
404     /* I know this looks wrong, but it's really not. Trust me. --w00t */
405     sts (":%s GLINE %s@%s", opersvs.nick, user, host);
406     }
407    
408     /* topic wrapper */
409     static void
410     inspircd_topic_sts (channel_t *c, const char *setter, time_t ts, time_t prevts, const char *topic)
411     {
412     if (!me.connected || !c)
413     return;
414    
415     /* If possible, try to use FTOPIC
416     * Note that because TOPIC does not contain topicTS, it may be
417     * off a few seconds on other servers, hence the 60 seconds here.
418     * -- jilles */
419     /* Restoring old topic */
420     if (ts > prevts + 60 || prevts == 0)
421     {
422     sts (":%s FTOPIC %s %ld %s :%s", chansvs.nick, c->name, ts, setter, topic);
423     return;
424     }
425     /* Tweaking a topic */
426     else if (ts == prevts)
427     {
428     ts += 60;
429     sts (":%s FTOPIC %s %ld %s :%s", chansvs.nick, c->name, ts, setter, topic);
430     c->topicts = ts;
431     return;
432     }
433     sts (":%s TOPIC %s :%s", chansvs.nick, c->name, topic);
434     c->topicts = NOW;
435     }
436    
437     /* mode wrapper */
438     static void
439     inspircd_mode_sts (char *sender, channel_t *target, char *modes)
440     {
441     if (!me.connected)
442     return;
443    
444     if (has_protocol >= PROTOCOL_NEWTS)
445     {
446     /* FMODE from user is ok, use it */
447     sts (":%s FMODE %s %ld %s", sender, target->name, target->ts, modes);
448     }
449     else
450     {
451     sts (":%s MODE %s %s", sender, target->name, modes);
452     }
453     }
454    
455     /* ping wrapper */
456     static void
457     inspircd_ping_sts (void)
458     {
459     if (!me.connected)
460     return;
461    
462     sts (":%s PING :%s", me.name, curr_uplink->name);
463     }
464    
465     /* protocol-specific stuff to do on login */
466     static void
467     inspircd_on_login (char *origin, char *user, char *wantedhost)
468     {
469     if (!me.connected)
470     return;
471    
472     sts (":%s METADATA %s accountname :%s", me.name, origin, user);
473     }
474    
475     /* protocol-specific stuff to do on logout */
476     static bool
477     inspircd_on_logout (char *origin, char *user, char *wantedhost)
478     {
479     if (!me.connected)
480     return false;
481    
482     sts (":%s METADATA %s accountname :", me.name, origin);
483     return false;
484     }
485    
486     static void
487     inspircd_jupe (const char *server, const char *reason)
488     {
489     server_t *s;
490     if (!me.connected)
491     return;
492    
493     s = server_find (server);
494     if (s != NULL)
495     {
496     /* We need to wait for the RSQUIT to be processed -- jilles */
497     sts (":%s RSQUIT :%s", opersvs.nick, server);
498     s->flags |= SF_JUPE_PENDING;
499     }
500     else
501     {
502     /* Remove any previous jupe first */
503     sts (":%s SQUIT %s :%s", me.name, server, reason);
504     sts (":%s SERVER %s * 1 :%s", me.name, server, reason);
505     }
506     }
507    
508     static void
509     inspircd_sethost_sts (char *source, char *target, char *host)
510     {
511     if (!me.connected)
512     return;
513    
514     notice (source, target, "Setting your host to \2%s\2.", host);
515     sts (":%s CHGHOST %s %s", source, target, host);
516     }
517    
518     static void
519     inspircd_fnc_sts (user_t *source, user_t *u, char *newnick, int type)
520     {
521     /* svsnick can only be sent by a server */
522     sts (":%s SVSNICK %s %s %lu", me.name, u->nick, newnick, (unsigned long) (NOW - 60));
523     }
524    
525    
526     /* invite a user to a channel */
527     static void
528     inspircd_invite_sts (user_t *sender, user_t *target, channel_t *channel)
529     {
530     sts (":%s INVITE %s %s", sender->nick, target->nick, channel->name);
531     }
532    
533     static void
534     inspircd_holdnick_sts (user_t *source, int duration, const char *nick, myuser_t *account)
535     {
536     if (duration == 0)
537     {
538     /* remove SVSHOLD */
539     sts (":%s SVSHOLD %s", source->nick, nick);
540     }
541     else
542     {
543     sts (":%s SVSHOLD %s %ds :Registered nickname.", source->nick, nick, duration);
544     }
545     }
546    
547     static void
548     m_topic (sourceinfo_t *si, int parc, char *parv[])
549     {
550     channel_t *c = channel_find (parv[0]);
551    
552     if (!c)
553     return;
554    
555     handle_topic_from (si, c, si->su->nick, time (NULL), parv[1]);
556     }
557    
558     static void
559     m_ftopic (sourceinfo_t *si, int parc, char *parv[])
560     {
561     channel_t *c = channel_find (parv[0]);
562     time_t ts = atol (parv[1]);
563    
564     if (!c)
565     return;
566    
567     if (c->topic != NULL && c->topicts >= ts)
568     {
569     slog (LG_DEBUG, "m_ftopic(): ignoring older topic on %s", c->name);
570     return;
571     }
572    
573     handle_topic_from (si, c, parv[2], ts, parv[3]);
574     }
575    
576     static void
577     m_ping (sourceinfo_t *si, int parc, char *parv[])
578     {
579     /* reply to PING's */
580     sts (":%s PONG %s", me.name, parv[0]);
581     }
582    
583     static void
584     m_pong (sourceinfo_t *si, int parc, char *parv[])
585     {
586     handle_eob (si->s);
587    
588     if (irccasecmp (me.actual, si->s->name))
589     return;
590     me.uplinkpong = NOW;
591    
592     /* -> :test.projectxero.net PONG test.projectxero.net :shrike.malkier.net */
593     if (me.bursting)
594     {
595     #ifdef HAVE_GETTIMEOFDAY
596     e_time (burstime, &burstime);
597    
598     slog (LG_INFO, "m_pong(): finished synching with uplink (%d %s)", (tv2ms (&burstime) > 1000) ? (tv2ms (&burstime) / 1000) : tv2ms (&burstime), (tv2ms (&burstime) > 1000) ? "s" : "ms");
599    
600     wallops ("Finished synching to network in %d %s.", (tv2ms (&burstime) > 1000) ? (tv2ms (&burstime) / 1000) : tv2ms (&burstime), (tv2ms (&burstime) > 1000) ? "s" : "ms");
601     #else
602     slog (LG_INFO, "m_pong(): finished synching with uplink");
603     wallops ("Finished synching to network.");
604     #endif
605    
606     me.bursting = false;
607     }
608     }
609    
610     static void
611     m_privmsg (sourceinfo_t *si, int parc, char *parv[])
612     {
613     if (parc != 2)
614     return;
615    
616     handle_message (si, parv[0], false, parv[1]);
617     }
618    
619     static void
620     m_notice (sourceinfo_t *si, int parc, char *parv[])
621     {
622     if (parc != 2)
623     return;
624    
625     handle_message (si, parv[0], true, parv[1]);
626     }
627    
628     static void
629     m_fjoin (sourceinfo_t *si, int parc, char *parv[])
630     {
631     /* FJOIN #flaps 1234 :@,fanny +%,arse ,tits ,breasts &~,poontang */
632     channel_t *c;
633     unsigned int userc;
634     unsigned int i;
635     unsigned int j;
636     unsigned int nlen;
637     bool prefix = true;
638     bool keep_new_modes = true;
639     char *userv[256];
640     char prefixandnick[51];
641     time_t ts;
642    
643     c = channel_find (parv[0]);
644     ts = atol (parv[1]);
645    
646     if (!c)
647     {
648     slog (LG_DEBUG, "m_fjoin(): new channel: %s", parv[0]);
649     c = channel_add (parv[0], ts, si->s);
650     return_if_fail (c != NULL);
651     /* Tell the core to check mode locks now,
652     * otherwise it may only happen after the next
653     * mode change.
654     * Inspircd does not allow any redundant modes
655     * so this will not look ugly. -- jilles */
656     /* As discussed with Brain, if this is in a burst,
657     * an FMODE with the simple modes will follow so we
658     * can skip this. -- jilles */
659     if (!me.bursting)
660     channel_mode_va (NULL, c, 1, "+");
661     }
662    
663     if (ts < c->ts)
664     {
665     chanuser_t *cu;
666     node_t *n;
667    
668     /* the TS changed. a TS change requires us to do
669     * bugger all except update the TS, because in InspIRCd
670     * remote servers enforce the TS change - Brain
671     *
672     * This is no longer the case with 1.1, we need to bounce their modes
673     * as well as lowering the channel ts. Do both. -- w00t
674     */
675    
676     if (has_protocol >= PROTOCOL_NEWTS)
677     {
678     clear_simple_modes (c);
679     chanban_clear (c);
680     }
681     LIST_FOREACH (n, c->members.head)
682     {
683     cu = (chanuser_t *) n->data;
684     if (cu->user->server == me.me)
685     {
686     /* it's a service, reop */
687     sts (":%s FMODE %s %ld +o %s", me.name, c->name, ts, cu->user->nick);
688     cu->modes = CMODE_OP;
689     }
690     else
691     cu->modes = 0;
692     }
693    
694     c->ts = ts;
695     hook_call_event ("channel_tschange", c);
696     }
697     else if (ts > c->ts)
698     {
699     keep_new_modes = false; /* ignore statuses */
700     }
701    
702     /*
703     * ok, here's the difference from 1.0 -> 1.1:
704     * 1.0 sent p[3] and up as individual users, prefixed with their 'highest' prefix, @, % or +
705     * in 1.1, this is more complex. All prefixes are sent, with the additional caveat that modules
706     * can add their own prefixes (dangerous!) - therefore, don't just chanuser_add(), split the prefix
707     * out and ignore unknown prefixes (probably the safest option). --w00t
708     */
709     userc = sjtoken (parv[parc - 1], ' ', userv);
710    
711     /* loop over all the users in this fjoin */
712     for (i = 0; i < userc; i++)
713     {
714     nlen = 0;
715     prefix = true;
716    
717     slog (LG_DEBUG, "m_fjoin(): processing user: %s", userv[i]);
718    
719     /*
720     * ok, now look at the chars in the nick.. we have something like "@%,w00t", but need @%w00t.. and
721     * we also want to ignore unknown prefixes.. loop through the chars
722     */
723     for (; *userv[i]; userv[i]++)
724     {
725     /* does this char match a known prefix? */
726     for (j = 0; prefix_mode_list[j].mode; j++)
727     {
728     /* yup. add it to the 'final' combination (@%w00t) */
729     if (*userv[i] == prefix_mode_list[j].mode)
730     {
731     prefixandnick[nlen++] = *userv[i];
732     continue;
733     }
734     }
735    
736     /* it's not a known prefix char, have we reached the end of the prefixes? */
737     if (*userv[i] == ',')
738     {
739     /* yup, skip over the comma */
740     userv[i]++;
741    
742     /* if we're ignoring status (keep_new_modes is false) then just add them to chan here.. */
743     if (keep_new_modes == false)
744     {
745     /* This ignores the @%, and just adds 'w00t' to the chan */
746     chanuser_add (c, userv[i]);
747     }
748     else
749     {
750     /* else, we do care about their prefixes.. add '@%w00t' to the chan */
751     strlcpy (prefixandnick + nlen, userv[i], sizeof (prefixandnick) - nlen);
752     chanuser_add (c, prefixandnick);
753     }
754    
755     /* added them.. break out of this loop, which will move us to the next user */
756     break;
757     }
758     else
759     {
760     /* unknown prefix char */
761     }
762     }
763    
764     /* go to the next user */
765     }
766    
767     if (c->nummembers == 0 && !(c->modes & ircd->perm_mode))
768     channel_delete (c);
769     }
770    
771     static void
772     m_part (sourceinfo_t *si, int parc, char *parv[])
773     {
774     int chanc;
775     char *chanv[256];
776     int i;
777    
778     chanc = sjtoken (parv[0], ',', chanv);
779     for (i = 0; i < chanc; i++)
780     {
781     slog (LG_DEBUG, "m_part(): user left channel: %s -> %s", si->su->nick, chanv[i]);
782    
783     chanuser_delete (channel_find (chanv[i]), si->su);
784     }
785     }
786    
787     static void
788     m_nick (sourceinfo_t *si, int parc, char *parv[])
789     {
790     user_t *u;
791    
792     /* :services-dev.chatspike.net NICK 1133994664 DevNull chatspike.net chatspike.net services +i 0.0.0.0 :/dev/null -- message sink */
793     if (parc == 8)
794     {
795     slog (LG_DEBUG, "m_nick(): new user on `%s': %s", si->s->name, parv[1]);
796    
797     /* char *nick, char *user, char *host, char *vhost, char *ip, char *uid, char *gecos, server_t *server, unsigned int ts */
798     u = user_add (parv[1], parv[4], parv[2], parv[3], parv[6], NULL, parv[7], si->s, atol (parv[0]));
799     user_mode (u, parv[5]);
800    
801     /* If server is not yet EOB we will do this later.
802     * This avoids useless "please identify" -- jilles */
803     if (si->s->flags & SF_EOB)
804     handle_nickchange (u);
805     }
806     /* if it's only 1 then it's a nickname change */
807     else if (parc == 1)
808     {
809     if (!si->su)
810     {
811     slog (LG_DEBUG, "m_nick(): server trying to change nick: %s", si->s != NULL ? si->s->name : "<none>");
812     return;
813     }
814    
815     slog (LG_DEBUG, "m_nick(): nickname change from `%s': %s", si->su->nick, parv[0]);
816    
817     /* No TS here for some reason, hmm */
818     user_changenick (si->su, parv[0], si->su->ts);
819    
820     /* It could happen that our PING arrived late and the
821     * server didn't acknowledge EOB yet even though it is
822     * EOB; don't send double notices in that case -- jilles */
823     if (si->su->server->flags & SF_EOB)
824     handle_nickchange (si->su);
825     }
826     else
827     {
828     int i;
829     slog (LG_DEBUG, "m_nick(): got NICK with wrong number of params");
830    
831     for (i = 0; i < parc; i++)
832     slog (LG_DEBUG, "m_nick(): parv[%d] = %s", i, parv[i]);
833     }
834     }
835    
836     static void
837     m_quit (sourceinfo_t *si, int parc, char *parv[])
838     {
839     slog (LG_DEBUG, "m_quit(): user leaving: %s", si->su->nick);
840    
841     /* user_delete() takes care of removing channels and so forth */
842     user_delete (si->su);
843     }
844    
845     static void
846     m_saquit (sourceinfo_t *si, int parc, char *parv[])
847     {
848     user_t *u = user_find (parv[0]);
849    
850     slog (LG_DEBUG, "m_saquit(): user leaving: %s", parv[0]);
851    
852     /* user_delete() takes care of removing channels and so forth */
853     user_delete (u);
854     }
855    
856     static void
857     m_mode (sourceinfo_t *si, int parc, char *parv[])
858     {
859     if (*parv[0] == '#')
860     channel_mode (NULL, channel_find (parv[0]), parc - 1, &parv[1]);
861     else
862     user_mode (user_find (parv[0]), parv[1]);
863     }
864    
865     static void
866     m_fmode (sourceinfo_t *si, int parc, char *parv[])
867     {
868     channel_t *c;
869     bool onlydeop;
870     time_t ts;
871     const char *p;
872    
873     /* :server.moo FMODE #blarp tshere +ntsklLg keymoo 1337 secks */
874     if (*parv[0] == '#')
875     {
876     c = channel_find (parv[0]);
877     if (c == NULL)
878     {
879     slog (LG_DEBUG, "m_fmode(): nonexistant channel: %s", parv[0]);
880     return;
881     }
882     ts = atoi (parv[1]);
883     if (ts == c->ts && has_protocol < PROTOCOL_NEWTS)
884     {
885     onlydeop = true;
886     p = parv[2];
887     while (*p != '\0')
888     {
889     if (!strchr ("-qaohv", *p))
890     onlydeop = false;
891     p++;
892     }
893     if (onlydeop && si->s != NULL)
894     {
895     /* ignore redundant deops generated
896     * if we lower the TS of a channel
897     * scenario: user with autoop privs recreates
898     * channel
899     * XXX could this ignore other stuff too?
900     * -- jilles */
901     slog (LG_DEBUG, "m_fmode(): ignoring %s %s: incoming TS %ld is equal to our TS %ld, and only deops", parv[0], parv[2], ts, c->ts);
902     return;
903     }
904     }
905     else if (ts > c->ts)
906     {
907     if (has_protocol < PROTOCOL_NEWTS)
908     slog (LG_DEBUG, "m_fmode(): accepting but should bounce %s %s: incoming TS %ld is newer than our TS %ld", parv[0], parv[2], ts, c->ts);
909     else
910     return;
911     }
912     else if (ts < c->ts)
913     slog (LG_DEBUG, "m_fmode(): %s %s: incoming TS %ld is older than our TS %ld, possible desync", parv[0], parv[2], ts, c->ts);
914     channel_mode (NULL, c, parc - 2, &parv[2]);
915     }
916     else
917     user_mode (user_find (parv[0]), parv[2]);
918     }
919    
920     static void
921     m_kick (sourceinfo_t *si, int parc, char *parv[])
922     {
923     user_t *u = user_find (parv[1]);
924     channel_t *c = channel_find (parv[0]);
925    
926     /* -> :rakaur KICK #shrike rintaun :test */
927     slog (LG_DEBUG, "m_kick(): user was kicked: %s -> %s", parv[1], parv[0]);
928    
929     if (!u)
930     {
931     slog (LG_DEBUG, "m_kick(): got kick for nonexistant user %s", parv[1]);
932     return;
933     }
934    
935     if (!c)
936     {
937     slog (LG_DEBUG, "m_kick(): got kick in nonexistant channel: %s", parv[0]);
938     return;
939     }
940    
941     if (!chanuser_find (c, u))
942     {
943     slog (LG_DEBUG, "m_kick(): got kick for %s not in %s", u->nick, c->name);
944     return;
945     }
946    
947     chanuser_delete (c, u);
948    
949     /* if they kicked us, let's rejoin */
950     if (is_internal_client (u))
951     {
952     slog (LG_DEBUG, "m_kick(): %s got kicked from %s; rejoining", u->nick, parv[0]);
953     join (parv[0], u->nick);
954     }
955     }
956    
957     static void
958     m_kill (sourceinfo_t *si, int parc, char *parv[])
959     {
960     handle_kill (si, parv[0], parc > 1 ? parv[1] : "<No reason given>");
961     }
962    
963     static void
964     m_squit (sourceinfo_t *si, int parc, char *parv[])
965     {
966     slog (LG_DEBUG, "m_squit(): server leaving: %s", parv[0]);
967     server_delete (parv[0]);
968     }
969    
970     static void
971     m_server (sourceinfo_t *si, int parc, char *parv[])
972     {
973     server_t *s;
974    
975     slog (LG_DEBUG, "m_server(): new server: %s", parv[0]);
976     s = handle_server (si, parv[0], NULL, atoi (parv[2]), parv[3]);
977    
978     if (s != NULL && s->uplink != me.me)
979     {
980     /* elicit PONG for EOB detection; pinging uplink is
981     * already done elsewhere -- jilles
982     */
983     sts (":%s PING %s %s", me.name, me.name, s->name);
984     }
985     }
986    
987     static void
988     m_stats (sourceinfo_t *si, int parc, char *parv[])
989     {
990     handle_stats (si->su, parv[0][0]);
991     }
992    
993     static void
994     m_motd (sourceinfo_t *si, int parc, char *parv[])
995     {
996     handle_motd (si->su);
997     }
998    
999     static void
1000     m_admin (sourceinfo_t *si, int parc, char *parv[])
1001     {
1002     handle_admin (si->su);
1003     }
1004    
1005     static void
1006     m_away (sourceinfo_t *si, int parc, char *parv[])
1007     {
1008     handle_away (si->su, parc >= 1 ? parv[0] : NULL);
1009     }
1010    
1011     static void
1012     m_join (sourceinfo_t *si, int parc, char *parv[])
1013     {
1014     channel_t *c;
1015    
1016     c = channel_find (parv[0]);
1017     if (!c)
1018     {
1019     slog (LG_DEBUG, "m_join(): new channel: %s (modes lost)", parv[0]);
1020     c = channel_add (parv[0], parc > 1 ? atol (parv[1]) : NOW, si->su->server);
1021     return_if_fail (c != NULL);
1022     channel_mode_va (NULL, c, 1, "+");
1023     }
1024     chanuser_add (c, si->su->nick);
1025     }
1026    
1027     static void
1028     m_sajoin (sourceinfo_t *si, int parc, char *parv[])
1029     {
1030     si->su = user_find (parv[0]);
1031     if (si->su == NULL)
1032     return;
1033     m_join (si, 1, &parv[1]);
1034     }
1035    
1036     static void
1037     m_sapart (sourceinfo_t *si, int parc, char *parv[])
1038     {
1039     si->su = user_find (parv[0]);
1040     if (si->su == NULL)
1041     return;
1042     m_part (si, 1, &parv[1]);
1043     }
1044    
1045     static void
1046     m_sanick (sourceinfo_t *si, int parc, char *parv[])
1047     {
1048     si->su = user_find (parv[0]);
1049     if (si->su == NULL)
1050     return;
1051     m_nick (si, 1, &parv[1]);
1052     }
1053    
1054     static void
1055     m_samode (sourceinfo_t *si, int parc, char *parv[])
1056     {
1057     /* note that SAMODE is not checked in any way before propagation,
1058     * and only works on channels, not users */
1059     channel_mode (NULL, channel_find (parv[0]), parc - 1, &parv[1]);
1060     }
1061    
1062     static void
1063     m_error (sourceinfo_t *si, int parc, char *parv[])
1064     {
1065     slog (LG_INFO, "m_error(): error from server: %s", parv[0]);
1066     }
1067    
1068     static void
1069     m_idle (sourceinfo_t *si, int parc, char *parv[])
1070     {
1071     if (parc == 1 && si->su != NULL)
1072     {
1073     sts (":%s IDLE %s %ld 0", parv[0], si->su->nick, NOW);
1074     }
1075     else
1076     {
1077     slog (LG_INFO, "m_idle(): Received an IDLE response but we didn't WHOIS anybody!");
1078     }
1079     }
1080    
1081     static void
1082     m_opertype (sourceinfo_t *si, int parc, char *parv[])
1083     {
1084     /*
1085     * Hope this works.. InspIRCd OPERTYPE means user is an oper, mark them so
1086     * Later, we may want to look at saving their OPERTYPE for informational
1087     * purposes, or not. --w00t
1088     */
1089     user_mode (si->su, "+o");
1090     }
1091    
1092     static void
1093     m_fhost (sourceinfo_t *si, int parc, char *parv[])
1094     {
1095     strlcpy (si->su->vhost, parv[0], HOSTLEN);
1096     }
1097    
1098     /*
1099     * :<source server> METADATA <channel|user> <key> :<value>
1100     * The sole piece of metadata we're interested in is 'accountname', set by Services,
1101     * and kept by ircd.
1102     *
1103     * :services.barafranca METADATA w00t accountname :w00t
1104     */
1105    
1106     static void
1107     m_metadata (sourceinfo_t *si, int parc, char *parv[])
1108     {
1109     user_t *u;
1110    
1111     if (!irccasecmp (parv[1], "accountname"))
1112     {
1113     /* find user */
1114     u = user_find (parv[0]);
1115    
1116     if (u == NULL)
1117     return;
1118    
1119     handle_burstlogin (u, parv[2]);
1120     }
1121     }
1122    
1123     /*
1124     * rsquit:
1125     * remote/request squit
1126     * when squitting a remote server, inspircd sends RSQUIT along the tree until it reaches the server that has
1127     * the server to be squit as a local connection, which should then close it's connection and send SQUIT back
1128     * to the rest of the network.
1129     */
1130     static void
1131     m_rsquit (sourceinfo_t *si, int parc, char *parv[])
1132     {
1133     sts (":%s SQUIT %s :Jupe removed by %s", me.name, parv[0], si->su->nick);
1134     }
1135    
1136     static void
1137     m_capab (sourceinfo_t *si, int parc, char *parv[])
1138     {
1139     int i, varc;
1140     char *varv[256];
1141    
1142     if (strcasecmp (parv[0], "START") == 0)
1143     {
1144     /* reset all our previously recieved CAPAB stuff */
1145     has_servicesmod = false;
1146     has_globopsmod = false;
1147     has_svshold = false;
1148     has_protocol = 0;
1149     }
1150     else if (strcasecmp (parv[0], "CAPABILITIES") == 0 && parc > 1)
1151     {
1152     varc = sjtoken (parv[1], ' ', varv);
1153     for (i = 0; i < varc; i++)
1154     {
1155     if (!strncmp (varv[i], "PROTOCOL=", 9))
1156     has_protocol = atoi (varv[i] + 9);
1157     /* XXX check/store HALFOP/CHANMAX/IDENTMAX */
1158     }
1159     }
1160     else if (strcasecmp (parv[0], "MODULES") == 0 && parc > 1)
1161     {
1162     if (strstr (parv[1], "m_services_account.so"))
1163     {
1164     has_servicesmod = true;
1165     }
1166     if (strstr (parv[1], "m_globops.so"))
1167     {
1168     has_globopsmod = true;
1169     }
1170     if (strstr (parv[1], "m_svshold.so"))
1171     {
1172     has_svshold = true;
1173     }
1174     }
1175     else if (strcasecmp (parv[0], "END") == 0)
1176     {
1177     if (has_globopsmod == false && has_protocol < PROTOCOL_SNONOTICE)
1178     {
1179     slog (LG_ERROR, "m_capab(): you didn't load m_globops into inspircd. " PACKAGE_NAME " support requires this module. exiting.");
1180     exit (EXIT_FAILURE);
1181     }
1182    
1183     if (has_servicesmod == false)
1184     {
1185     slog (LG_ERROR, "m_capab(): you didn't load m_services_account into inspircd. " PACKAGE_NAME " support requires this module. exiting.");
1186     exit (EXIT_FAILURE);
1187     }
1188    
1189     if (has_svshold == false)
1190     {
1191     slog (LG_INFO, "m_capab(): you didn't load m_svshold into inspircd. nickname enforcers will not work.");
1192     }
1193     }
1194     else
1195     {
1196     slog (LG_DEBUG, "m_capab(): unknown CAPAB type %s - out of date protocol module?", parv[0]);
1197     }
1198     }
1199    
1200     /* Server ended their burst: warn all their users if necessary -- jilles */
1201     static void
1202     server_eob (server_t *s)
1203     {
1204     node_t *n;
1205    
1206     LIST_FOREACH (n, s->userlist.head)
1207     {
1208     handle_nickchange ((user_t *) n->data);
1209     }
1210     }
1211    
1212     void
1213     _modinit (module_t *m)
1214     {
1215     /* Symbol relocation voodoo. */
1216     server_login = &inspircd_server_login;
1217     introduce_nick = &inspircd_introduce_nick;
1218     quit_sts = &inspircd_quit_sts;
1219     wallops_sts = &inspircd_wallops_sts;
1220     join_sts = &inspircd_join_sts;
1221     chan_lowerts = &inspircd_chan_lowerts;
1222     kick = &inspircd_kick;
1223     msg = &inspircd_msg;
1224     notice_user_sts = &inspircd_notice_user_sts;
1225     notice_global_sts = &inspircd_notice_global_sts;
1226     notice_channel_sts = &inspircd_notice_channel_sts;
1227     numeric_sts = &inspircd_numeric_sts;
1228     skill = &inspircd_skill;
1229     part_sts = &inspircd_part_sts;
1230     kline_sts = &inspircd_kline_sts;
1231     unkline_sts = &inspircd_unkline_sts;
1232     topic_sts = &inspircd_topic_sts;
1233     mode_sts = &inspircd_mode_sts;
1234     ping_sts = &inspircd_ping_sts;
1235     ircd_on_login = &inspircd_on_login;
1236     ircd_on_logout = &inspircd_on_logout;
1237     jupe = &inspircd_jupe;
1238     sethost_sts = &inspircd_sethost_sts;
1239     fnc_sts = &inspircd_fnc_sts;
1240     invite_sts = &inspircd_invite_sts;
1241     holdnick_sts = &inspircd_holdnick_sts;
1242    
1243     mode_list = inspircd_mode_list;
1244     ignore_mode_list = inspircd_ignore_mode_list;
1245     status_mode_list = inspircd_status_mode_list;
1246     prefix_mode_list = inspircd_prefix_mode_list;
1247    
1248     ircd = &InspIRCd;
1249    
1250     pcommand_add ("PING", m_ping, 1, MSRC_USER | MSRC_SERVER);
1251     pcommand_add ("PONG", m_pong, 1, MSRC_SERVER);
1252     pcommand_add ("PRIVMSG", m_privmsg, 2, MSRC_USER);
1253     pcommand_add ("NOTICE", m_notice, 2, MSRC_USER | MSRC_SERVER);
1254     pcommand_add ("FJOIN", m_fjoin, 3, MSRC_SERVER);
1255     pcommand_add ("PART", m_part, 1, MSRC_USER);
1256     pcommand_add ("NICK", m_nick, 1, MSRC_USER | MSRC_SERVER);
1257     pcommand_add ("QUIT", m_quit, 1, MSRC_USER);
1258     pcommand_add ("MODE", m_mode, 2, MSRC_USER | MSRC_SERVER);
1259     pcommand_add ("FMODE", m_fmode, 3, MSRC_USER | MSRC_SERVER);
1260     pcommand_add ("SAMODE", m_samode, 2, MSRC_USER);
1261     pcommand_add ("SAJOIN", m_sajoin, 2, MSRC_USER);
1262     pcommand_add ("SAPART", m_sapart, 2, MSRC_USER);
1263     pcommand_add ("SANICK", m_sanick, 2, MSRC_USER);
1264     pcommand_add ("SAQUIT", m_saquit, 1, MSRC_USER);
1265     pcommand_add ("KICK", m_kick, 2, MSRC_USER | MSRC_SERVER);
1266     pcommand_add ("KILL", m_kill, 1, MSRC_USER | MSRC_SERVER);
1267     pcommand_add ("SQUIT", m_squit, 1, MSRC_USER | MSRC_SERVER);
1268     pcommand_add ("RSQUIT", m_rsquit, 1, MSRC_USER);
1269     pcommand_add ("SERVER", m_server, 4, MSRC_UNREG | MSRC_SERVER);
1270     pcommand_add ("STATS", m_stats, 2, MSRC_USER);
1271     pcommand_add ("MOTD", m_motd, 1, MSRC_USER);
1272     pcommand_add ("ADMIN", m_admin, 1, MSRC_USER);
1273     pcommand_add ("FTOPIC", m_ftopic, 4, MSRC_SERVER);
1274     pcommand_add ("JOIN", m_join, 1, MSRC_USER);
1275     pcommand_add ("ERROR", m_error, 1, MSRC_UNREG | MSRC_SERVER);
1276     pcommand_add ("TOPIC", m_topic, 2, MSRC_USER);
1277     pcommand_add ("FHOST", m_fhost, 1, MSRC_USER);
1278     pcommand_add ("IDLE", m_idle, 1, MSRC_USER);
1279     pcommand_add ("AWAY", m_away, 0, MSRC_USER);
1280     pcommand_add ("OPERTYPE", m_opertype, 1, MSRC_USER);
1281     pcommand_add ("METADATA", m_metadata, 3, MSRC_SERVER);
1282     pcommand_add ("CAPAB", m_capab, 1, MSRC_UNREG | MSRC_SERVER);
1283    
1284     hook_add_event ("server_eob");
1285     hook_add_hook ("server_eob", (void (*)(void *)) server_eob);
1286    
1287     m->mflags = MODTYPE_CORE;
1288    
1289     pmodule_loaded = true;
1290     }
1291    
1292     /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
1293     * vim:ts=8
1294     * vim:sw=8
1295     * vim:noexpandtab
1296     */