ptlink.c

Go to the documentation of this file.
00001 /* PTLink IRCD functions
00002  *
00003  * (C) 2003-2007 Anope Team
00004  * Contact us at info@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church. 
00010  * 
00011  *
00012  */
00013 
00014 #include "services.h"
00015 #include "pseudo.h"
00016 #include "ptlink.h"
00017 
00018 IRCDVar myIrcd[] = {
00019     {"PTlink 6.15.*+",          /* ircd name */
00020      "+o",                      /* nickserv mode */
00021      "+o",                      /* chanserv mode */
00022      "+o",                      /* memoserv mode */
00023      "+o",                      /* hostserv mode */
00024      "+io",                     /* operserv mode */
00025      "+o",                      /* botserv mode  */
00026      "+h",                      /* helpserv mode */
00027      "+i",                      /* Dev/Null mode */
00028      "+io",                     /* Global mode   */
00029      "+o",                      /* nickserv alias mode */
00030      "+o",                      /* chanserv alias mode */
00031      "+o",                      /* memoserv alias mode */
00032      "+io",                     /* hostserv alias mode */
00033      "+io",                     /* operserv alias mode */
00034      "+o",                      /* botserv alias mode  */
00035      "+h",                      /* helpserv alias mode */
00036      "+i",                      /* Dev/Null alias mode */
00037      "+io",                     /* Global alias mode   */
00038      "+",                       /* Used by BotServ Bots */
00039      2,                         /* Chan Max Symbols     */
00040      "-inpsmtCRKOASdcqBNl",     /* Modes to Remove */
00041      "+ao",                     /* Channel Umode used by Botserv bots */
00042      1,                         /* SVSNICK */
00043      1,                         /* Vhost  */
00044      0,                         /* Has Owner */
00045      NULL,                      /* Mode to set for an owner */
00046      NULL,                      /* Mode to unset for an owner */
00047      "+a",                      /* Mode to set for chan admin */
00048      "-a",                      /* Mode to unset for chan admin */
00049      "+r",                      /* Mode On Reg          */
00050      NULL,                      /* Mode on ID for Roots */
00051      NULL,                      /* Mode on ID for Admins */
00052      NULL,                      /* Mode on ID for Opers */
00053      "-r",                      /* Mode on UnReg        */
00054      NULL,                      /* Mode on Nick Change  */
00055      1,                         /* Supports SGlines     */
00056      1,                         /* Supports SQlines     */
00057      1,                         /* Supports SZlines     */
00058      0,                         /* Supports Halfop +h   */
00059      4,                         /* Number of server args */
00060      0,                         /* Join 2 Set           */
00061      0,                         /* Join 2 Message       */
00062      1,                         /* Has exceptions +e    */
00063      0,                         /* TS Topic Forward     */
00064      0,                         /* TS Topci Backward    */
00065      0,                         /* Protected Umode      */
00066      0,                         /* Has Admin            */
00067      0,                         /* Chan SQlines         */
00068      0,                         /* Quit on Kill         */
00069      0,                         /* SVSMODE unban        */
00070      1,                         /* Has Protect          */
00071      0,                         /* Reverse              */
00072      1,                         /* Chan Reg             */
00073      CMODE_r,                   /* Channel Mode         */
00074      1,                         /* vidents              */
00075      0,                         /* svshold              */
00076      0,                         /* time stamp on mode   */
00077      0,                         /* NICKIP               */
00078      0,                         /* O:LINE               */
00079      1,                         /* UMODE                */
00080      1,                         /* VHOST ON NICK        */
00081      0,                         /* Change RealName      */
00082      CMODE_K,                   /* No Knock             */
00083      CMODE_A,                   /* Admin Only           */
00084      DEFAULT_MLOCK,             /* Default MLOCK        */
00085      UMODE_VH,                  /* Vhost Mode           */
00086      1,                         /* +f                   */
00087      0,                         /* +L                   */
00088      CMODE_f,
00089      0,
00090      1,
00091      1,                         /* No Knock requires +i */
00092      NULL,                      /* CAPAB Chan Modes             */
00093      0,                         /* We support TOKENS */
00094      1,                         /* TOKENS are CASE inSensitive */
00095      0,                         /* TIME STAMPS are BASE64 */
00096      0,                         /* +I support */
00097      0,                         /* SJOIN ban char */
00098      0,                         /* SJOIN except char */
00099      0,                         /* SJOIN invite char */
00100      0,                         /* Can remove User Channel Modes with SVSMODE */
00101      0,                         /* Sglines are not enforced until user reconnects */
00102      NULL,                      /* vhost char */
00103      0,                         /* ts6 */
00104      1,                         /* support helper umode */
00105      0,                         /* p10 */
00106      NULL,                      /* character set */
00107      0,                         /* reports sync state */
00108      }
00109     ,
00110     {NULL}
00111 };
00112 
00113 IRCDCAPAB myIrcdcap[] = {
00114     {
00115      0,                         /* NOQUIT       */
00116      0,                         /* TSMODE       */
00117      0,                         /* UNCONNECT    */
00118      0,                         /* NICKIP       */
00119      0,                         /* SJOIN        */
00120      CAPAB_ZIP,                 /* ZIP          */
00121      0,                         /* BURST        */
00122      0,                         /* TS5          */
00123      0,                         /* TS3          */
00124      0,                         /* DKEY         */
00125      CAPAB_PT4,                 /* PT4          */
00126      CAPAB_SCS,                 /* SCS          */
00127      CAPAB_QS,                  /* QS           */
00128      0,                         /* UID          */
00129      0,                         /* KNOCK        */
00130      0,                         /* CLIENT       */
00131      0,                         /* IPV6         */
00132      0,                         /* SSJ5         */
00133      0,                         /* SN2          */
00134      0,                         /* TOKEN        */
00135      0,                         /* VHOST        */
00136      0,                         /* SSJ3         */
00137      0,                         /* NICK2        */
00138      0,                         /* UMODE2       */
00139      0,                         /* VL           */
00140      0,                         /* TLKEXT       */
00141      0,                         /* DODKEY       */
00142      0,                         /* DOZIP        */
00143      0, 0, 0}
00144 };
00145 
00146 
00147 unsigned long umodes[128] = {
00148     0, 0, 0,                    /* Unused */
00149     0, 0, 0,                    /* Unused */
00150     0, 0, 0,                    /* Unused, Unused, Horzontal Tab */
00151     0, 0, 0,                    /* Line Feed, Unused, Unused */
00152     0, 0, 0,                    /* Carriage Return, Unused, Unused */
00153     0, 0, 0,                    /* Unused */
00154     0, 0, 0,                    /* Unused */
00155     0, 0, 0,                    /* Unused */
00156     0, 0, 0,                    /* Unused */
00157     0, 0, 0,                    /* Unused */
00158     0, 0, 0,                    /* Unused, Unused, Space */
00159     0, 0, 0,                    /* ! " #  */
00160     0, 0, 0,                    /* $ % &  */
00161     0, 0, 0,                    /* ! ( )  */
00162     0, 0, 0,                    /* * + ,  */
00163     0, 0, 0,                    /* - . /  */
00164     0, 0,                       /* 0 1 */
00165     0, 0,                       /* 2 3 */
00166     0, 0,                       /* 4 5 */
00167     0, 0,                       /* 6 7 */
00168     0, 0,                       /* 8 9 */
00169     0, 0,                       /* : ; */
00170     0, 0, 0,                    /* < = > */
00171     0, 0,                       /* ? @ */
00172     UMODE_A, UMODE_B, 0,        /* A B C */
00173     0, 0, 0,                    /* D E F */
00174     0, UMODE_H, 0,              /* G H I */
00175     0, 0, 0,                    /* J K L */
00176     0, UMODE_N, UMODE_O,        /* M N O */
00177     0, 0, UMODE_R,              /* P Q R */
00178     UMODE_S, UMODE_T, 0,        /* S T U */
00179     0, 0, 0,                    /* V W X */
00180     0,                          /* Y */
00181     0,                          /* Z */
00182     0, 0, 0,                    /* [ \ ] */
00183     0, 0, 0,                    /* ^ _ ` */
00184     UMODE_a, 0, 0,              /* a b c */
00185     0, 0, 0,                    /* d e f */
00186     0, UMODE_h, UMODE_i,        /* g h i */
00187     0, 0, 0,                    /* j k l */
00188     0, 0, UMODE_o,              /* m n o */
00189     UMODE_p, 0, UMODE_r,        /* p q r */
00190     UMODE_s, 0, 0,              /* s t u */
00191     UMODE_v, UMODE_w, 0,        /* v w x */
00192     UMODE_y,                    /* y */
00193     UMODE_z,                    /* z */
00194     0, 0, 0,                    /* { | } */
00195     0, 0                        /* ~ ‚ */
00196 };
00197 
00198 char myCsmodes[128] = {
00199     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00200     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00201 
00202     0,
00203     0,
00204     0, 0, 0,
00205     0,
00206     0, 0, 0, 0,
00207     0,
00208 
00209     'v', 0, 0, 'a', 0,
00210     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00211 
00212     'o', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00213     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00214 
00215     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00216     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
00217 };
00218 
00219 
00220 CMMode myCmmodes[128] = {
00221     {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL},
00222     {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL},
00223     {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL},
00224     {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL},
00225     {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL},
00226     {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL},
00227     {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL},
00228     {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL},
00229     {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL},
00230     {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL},
00231     {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL},
00232     {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL},
00233     {NULL},
00234     {NULL},
00235     {add_ban, del_ban},
00236     {NULL},
00237     {NULL},
00238     {add_exception, del_exception},
00239     {NULL},
00240     {NULL},
00241     {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL},
00242     {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL},
00243     {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}, {NULL}
00244 };
00245 
00246 
00247 CBMode myCbmodes[128] = {
00248     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00249     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00250     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00251     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00252     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00253     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00254     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00255     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00256     {0},
00257     {CMODE_A, 0, NULL, NULL},   /* A */
00258     {CMODE_B, 0, NULL, NULL},   /* B */
00259     {CMODE_C, 0, NULL, NULL},   /* C */
00260     {0},                        /* D */
00261     {0},                        /* E */
00262     {0},                        /* F */
00263     {0},                        /* G */
00264     {0},                        /* H */
00265     {0},                        /* I */
00266     {0},                        /* J */
00267     {CMODE_K, 0, NULL, NULL},   /* K */
00268     {0},                        /* L */
00269     {0},                        /* M */
00270     {CMODE_N, 0, NULL, NULL},   /* N */
00271     {CMODE_O, 0, NULL, NULL},   /* O */
00272     {0},                        /* P */
00273     {0},                        /* Q */
00274     {CMODE_R, 0, NULL, NULL},   /* R */
00275     {CMODE_S, 0, NULL, NULL},   /* S */
00276     {0},                        /* T */
00277     {0},                        /* U */
00278     {0},                        /* V */
00279     {0},                        /* W */
00280     {0},                        /* X */
00281     {0},                        /* Y */
00282     {0},                        /* Z */
00283     {0}, {0}, {0}, {0}, {0}, {0},
00284     {0},                        /* a */
00285     {0},                        /* b */
00286     {CMODE_c, 0, NULL, NULL},
00287     {CMODE_d, 0, NULL, NULL},
00288     {0},                        /* e */
00289     {CMODE_f, 0, set_flood, cs_set_flood},
00290     {0},                        /* g */
00291     {0},                        /* h */
00292     {CMODE_i, 0, NULL, NULL},
00293     {0},                        /* j */
00294     {CMODE_k, 0, chan_set_key, cs_set_key},
00295     {CMODE_l, CBM_MINUS_NO_ARG, set_limit, cs_set_limit},
00296     {CMODE_m, 0, NULL, NULL},
00297     {CMODE_n, 0, NULL, NULL},
00298     {0},                        /* o */
00299     {CMODE_p, 0, NULL, NULL},
00300     {CMODE_q, 0, NULL, NULL},
00301     {CMODE_r, CBM_NO_MLOCK, NULL, NULL},
00302     {CMODE_s, 0, NULL, NULL},
00303     {CMODE_t, 0, NULL, NULL},
00304     {0},
00305     {0},                        /* v */
00306     {0},                        /* w */
00307     {0},                        /* x */
00308     {0},                        /* y */
00309     {0},                        /* z */
00310     {0}, {0}, {0}, {0}
00311 };
00312 
00313 CBModeInfo myCbmodeinfos[] = {
00314     {'c', CMODE_c, 0, NULL, NULL},
00315     {'d', CMODE_d, 0, NULL, NULL},
00316     {'f', CMODE_f, 0, get_flood, cs_get_flood},
00317     {'i', CMODE_i, 0, NULL, NULL},
00318     {'k', CMODE_k, 0, get_key, cs_get_key},
00319     {'l', CMODE_l, CBM_MINUS_NO_ARG, get_limit, cs_get_limit},
00320     {'m', CMODE_m, 0, NULL, NULL},
00321     {'n', CMODE_n, 0, NULL, NULL},
00322     {'p', CMODE_p, 0, NULL, NULL},
00323     {'q', CMODE_q, 0, NULL, NULL},
00324     {'r', CMODE_r, 0, NULL, NULL},
00325     {'s', CMODE_s, 0, NULL, NULL},
00326     {'t', CMODE_t, 0, NULL, NULL},
00327     {'A', CMODE_A, 0, NULL, NULL},
00328     {'B', CMODE_B, 0, NULL, NULL},
00329     {'C', CMODE_C, 0, NULL, NULL},
00330     {'K', CMODE_K, 0, NULL, NULL},
00331     {'N', CMODE_N, 0, NULL, NULL},
00332     {'O', CMODE_O, 0, NULL, NULL},
00333     {'R', CMODE_R, 0, NULL, NULL},
00334     {'S', CMODE_S, 0, NULL, NULL},
00335     {0}
00336 };
00337 
00338 CUMode myCumodes[128] = {
00339     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00340     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00341     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00342     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00343 
00344     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00345     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00346     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00347     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00348 
00349     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00350     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00351     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00352     {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
00353 
00354     {0},
00355 
00356     {0},                        /* a */
00357     {0},                        /* b */
00358     {0},                        /* c */
00359     {0},                        /* d */
00360     {0},                        /* e */
00361     {0},                        /* f */
00362     {0},                        /* g */
00363     {0},                        /* h */
00364     {0},                        /* i */
00365     {0},                        /* j */
00366     {0},                        /* k */
00367     {0},                        /* l */
00368     {0},                        /* m */
00369     {0},                        /* n */
00370     {CUS_OP, CUF_PROTECT_BOTSERV, check_valid_op},
00371     {0},                        /* p */
00372     {0},                        /* q */
00373     {0},                        /* r */
00374     {0},                        /* s */
00375     {0},                        /* t */
00376     {0},                        /* u */
00377     {CUS_VOICE, 0, NULL},
00378     {0},                        /* w */
00379     {0},                        /* x */
00380     {0},                        /* y */
00381     {0},                        /* z */
00382     {0}, {0}, {0}, {0}, {0}
00383 };
00384 
00385 
00386 
00387 void ptlink_cmd_bot_chan_mode(char *nick, char *chan)
00388 {
00389     anope_cmd_mode(s_ChanServ, chan, "%s %s %s", ircd->botchanumode, nick,
00390                    nick);
00391 }
00392 
00393 /*
00394   :%s SJOIN %lu %s %s %s :%s
00395     parv[0] = sender
00396     parv[1] = channel TS (channel creation time)
00397     parv[2] = channel
00398     parv[3] = modes + n arguments (key and/or limit) 
00399     ... [n]  = if(key and/or limit) mode arguments
00400     parv[4+n] = flags+nick list (all in one parameter)
00401     NOTE: ignore channel modes if we already have the channel with a gr
00402 */
00403 int anope_event_sjoin(char *source, int ac, char **av)
00404 {
00405     do_sjoin(source, ac, av);
00406     return MOD_CONT;
00407 }
00408 
00409 /*
00410  * Note: This function has no validation whatsoever. Also, as of PTlink6.15.1
00411  * when you /deoper you get to keep your vindent, but you lose your vhost. In
00412  * that case serives will *NOT* modify it's internal record for the vhost. We
00413  * need to address this in the future.
00414  */
00415 /*
00416   :%s NEWMASK %s
00417     parv[0] = sender
00418     parv[1] = new mask (if no '@', hostname is assumed)
00419 */
00420 int anope_event_newmask(char *source, int ac, char **av)
00421 {
00422     User *u;
00423     char *newhost = NULL, *newuser = NULL;
00424     int tofree = 0;
00425 
00426     if (ac != 1)
00427         return MOD_CONT;
00428     u = finduser(source);
00429 
00430     if (!u) {
00431         if (debug) {
00432             alog("debug: NEWMASK for nonexistent user %s", av[0]);
00433         }
00434         return MOD_CONT;
00435     }
00436 
00437     if ((u->mode & (UMODE_NM | UMODE_VH)) == (UMODE_NM | UMODE_VH)) {
00438         /* This NEWMASK should be discarded because it's sent due to a +r by
00439          * someone with a ptlink-masked host. PTlink has our correct host, so
00440          * we can just ignore this :) Or we'll get ptlink's old host which is
00441          * not what we want. -GD
00442          */
00443         u->mode &= ~UMODE_NM;
00444         if (debug)
00445             alog("debug: Ignoring NEWMASK because it's send because of SVSMODE +r");
00446         return MOD_CONT;
00447     }
00448 
00449     newuser = myStrGetOnlyToken(av[0], '@', 0);
00450     if (newuser) {
00451         newhost = myStrGetTokenRemainder(av[0], '@', 1);
00452         tofree = 1;
00453         change_user_username(u, newuser);
00454         free(newuser);
00455     } else {
00456         newhost = av[0];
00457     }
00458 
00459     if (newhost && *newhost == '@')
00460         newhost++;
00461 
00462     u->mode |= UMODE_VH;
00463 
00464     if (newhost)
00465         change_user_host(u, newhost);
00466 
00467     if (tofree)
00468         free(newhost);
00469 
00470     return MOD_CONT;
00471 }
00472 
00473 /*
00474  NICK %s %d %lu %s %s %s %s %s :%s
00475     parv[0] = nickname
00476     parv[1] = hopcount 
00477     parv[2] = nick TS (nick introduction time)
00478     parv[3] = umodes
00479     parv[4] = username
00480     parv[5] = hostname
00481     parv[6] = spoofed hostname
00482     parv[7] = server
00483     parv[8] = nick info
00484 */
00485 /*
00486  Change NICK
00487     parv[0] = old nick
00488     parv[1] = new nick
00489     parv[2] = TS (timestamp from user's server when nick changed was received)
00490 */
00491 /*
00492  NICK xpto 2 561264 +rw irc num.myisp.pt mask.myisp.pt uc.ptlink.net :Just me
00493        0   1  2      3   4   5            6              7             8
00494 
00495 */
00496 int anope_event_nick(char *source, int ac, char **av)
00497 {
00498     User *user;
00499 
00500     if (ac != 2) {
00501         user = do_nick(source, av[0], av[4], av[5], av[7], av[8],
00502                        strtoul(av[2], NULL, 10), 0, 0, av[6], NULL);
00503         if (user)
00504             anope_set_umode(user, 1, &av[3]);
00505     } else {
00506         do_nick(source, av[0], NULL, NULL, NULL, NULL,
00507                 strtoul(av[1], NULL, 10), 0, 0, NULL, NULL);
00508     }
00509     return MOD_CONT;
00510 }
00511 
00512 /*
00513   :%s SERVER %s %d %s :%s
00514     parv[0] = server from where the server was introduced to us 
00515     parv[1] = server name
00516     parv[2] = hop count (1 wen are directly connected)
00517     parv[3] = server version
00518     parv[4] = server description
00519 */
00520 int anope_event_server(char *source, int ac, char **av)
00521 {
00522     if (!stricmp(av[1], "1")) {
00523         uplink = sstrdup(av[0]);
00524     }
00525     do_server(source, av[0], av[1], av[3], NULL);
00526     return MOD_CONT;
00527 }
00528 
00529 int anope_event_436(char *source, int ac, char **av)
00530 {
00531     if (ac < 1)
00532         return MOD_CONT;
00533 
00534     m_nickcoll(av[0]);
00535     return MOD_CONT;
00536 }
00537 
00538 
00539 void moduleAddIRCDMsgs(void)
00540 {
00541     Message *m;
00542 
00543     updateProtectDetails("PROTECT", "PROTECTME", "protect", "deprotect",
00544                          "AUTOPROTECT", "+a", "-a");
00545 
00546     m = createMessage("401", anope_event_null);
00547     addCoreMessage(IRCD, m);
00548     m = createMessage("402", anope_event_null);
00549     addCoreMessage(IRCD, m);
00550     m = createMessage("436", anope_event_436);
00551     addCoreMessage(IRCD, m);
00552     m = createMessage("461", anope_event_null);
00553     addCoreMessage(IRCD, m);
00554     m = createMessage("AWAY", anope_event_away);
00555     addCoreMessage(IRCD, m);
00556     m = createMessage("INVITE", anope_event_invite);
00557     addCoreMessage(IRCD, m);
00558     m = createMessage("JOIN", anope_event_join);
00559     addCoreMessage(IRCD, m);
00560     m = createMessage("KICK", anope_event_kick);
00561     addCoreMessage(IRCD, m);
00562     m = createMessage("KILL", anope_event_kill);
00563     addCoreMessage(IRCD, m);
00564     m = createMessage("MODE", anope_event_mode);
00565     addCoreMessage(IRCD, m);
00566     m = createMessage("MOTD", anope_event_motd);
00567     addCoreMessage(IRCD, m);
00568     m = createMessage("NICK", anope_event_nick);
00569     addCoreMessage(IRCD, m);
00570     m = createMessage("NOTICE", anope_event_notice);
00571     addCoreMessage(IRCD, m);
00572     m = createMessage("PART", anope_event_part);
00573     addCoreMessage(IRCD, m);
00574     m = createMessage("PASS", anope_event_pass);
00575     addCoreMessage(IRCD, m);
00576     m = createMessage("PING", anope_event_ping);
00577     addCoreMessage(IRCD, m);
00578     m = createMessage("PRIVMSG", anope_event_privmsg);
00579     addCoreMessage(IRCD, m);
00580     m = createMessage("QUIT", anope_event_quit);
00581     addCoreMessage(IRCD, m);
00582     m = createMessage("SERVER", anope_event_server);
00583     addCoreMessage(IRCD, m);
00584     m = createMessage("SQUIT", anope_event_squit);
00585     addCoreMessage(IRCD, m);
00586     m = createMessage("TOPIC", anope_event_topic);
00587     addCoreMessage(IRCD, m);
00588     m = createMessage("USER", anope_event_null);
00589     addCoreMessage(IRCD, m);
00590     m = createMessage("WALLOPS", anope_event_null);
00591     addCoreMessage(IRCD, m);
00592     m = createMessage("WHOIS", anope_event_whois);
00593     addCoreMessage(IRCD, m);
00594     m = createMessage("AKILL", anope_event_null);
00595     addCoreMessage(IRCD, m);
00596     m = createMessage("GLOBOPS", anope_event_null);
00597     addCoreMessage(IRCD, m);
00598     m = createMessage("GNOTICE", anope_event_null);
00599     addCoreMessage(IRCD, m);
00600     m = createMessage("GOPER", anope_event_null);
00601     addCoreMessage(IRCD, m);
00602     m = createMessage("RAKILL", anope_event_null);
00603     addCoreMessage(IRCD, m);
00604     m = createMessage("SILENCE", anope_event_null);
00605     addCoreMessage(IRCD, m);
00606     m = createMessage("SVSKILL", anope_event_null);
00607     addCoreMessage(IRCD, m);
00608     m = createMessage("SVSMODE", anope_event_null);
00609     addCoreMessage(IRCD, m);
00610     m = createMessage("SVSNICK", anope_event_null);
00611     addCoreMessage(IRCD, m);
00612     m = createMessage("SVSNOOP", anope_event_null);
00613     addCoreMessage(IRCD, m);
00614     m = createMessage("SQLINE", anope_event_null);
00615     addCoreMessage(IRCD, m);
00616     m = createMessage("UNSQLINE", anope_event_null);
00617     addCoreMessage(IRCD, m);
00618     m = createMessage("NEWMASK", anope_event_newmask);
00619     addCoreMessage(IRCD, m);
00620     m = createMessage("CAPAB", anope_event_capab);
00621     addCoreMessage(IRCD, m);
00622     m = createMessage("SVINFO", anope_event_svinfo);
00623     addCoreMessage(IRCD, m);
00624     m = createMessage("SVSINFO", anope_event_svsinfo);
00625     addCoreMessage(IRCD, m);
00626     m = createMessage("SJOIN", anope_event_sjoin);
00627     addCoreMessage(IRCD, m);
00628     m = createMessage("REHASH", anope_event_rehash);
00629     addCoreMessage(IRCD, m);
00630     m = createMessage("ADMIN", anope_event_admin);
00631     addCoreMessage(IRCD, m);
00632     m = createMessage("CREDITS", anope_event_credits);
00633     addCoreMessage(IRCD, m);
00634     m = createMessage("ERROR", anope_event_error);
00635     addCoreMessage(IRCD, m);
00636     m = createMessage("NJOIN", anope_event_sjoin);
00637     addCoreMessage(IRCD, m);
00638     m = createMessage("NNICK", anope_event_nick);
00639     addCoreMessage(IRCD, m);
00640     m = createMessage("ZLINE", anope_event_null);
00641     addCoreMessage(IRCD, m);
00642     m = createMessage("UNZLINE", anope_event_null);
00643     addCoreMessage(IRCD, m);
00644 }
00645 
00646 int anope_event_svsinfo(char *source, int ac, char **av)
00647 {
00648     return MOD_CONT;
00649 }
00650 
00651 int anope_event_svinfo(char *source, int ac, char **av)
00652 {
00653     return MOD_CONT;
00654 }
00655 
00656 /* Event: PROTOCTL */
00657 int anope_event_capab(char *source, int ac, char **av)
00658 {
00659     capab_parse(ac, av);
00660     return MOD_CONT;
00661 }
00662 
00663 /*
00664    :%s SQLINE %s :%s
00665     parv[0] = sender 
00666     parv[1] = sqlined nick/mask
00667     parv[2] = reason
00668 */
00669 void ptlink_cmd_sqline(char *mask, char *reason)
00670 {
00671     send_cmd(ServerName, "SQLINE %s :%s", mask, reason);
00672 }
00673 
00674 /*
00675   :%s SVSADMIN %s :%s
00676     parv[0] = sender (services client)
00677     parv[1] = target server
00678     parv[2] = operation
00679       operations:
00680         noopers - remove existing opers and disable o:lines
00681 */
00682 void ptlink_cmd_svsnoop(char *server, int set)
00683 {
00684     send_cmd(NULL, "SVSADMIN %s :%s", server, set ? "noopers" : "rehash");
00685 }
00686 
00687 void ptlink_cmd_svsadmin(char *server, int set)
00688 {
00689     ptlink_cmd_svsnoop(server, set);
00690 }
00691 
00692 /*
00693   :%s UNGLINE %s
00694     parv[0] = sender (server if on network synchronization)
00695     parv[1] = glined usert@host mask or ALL to remove all glines
00696 */
00697 void ptlink_cmd_remove_akill(char *user, char *host)
00698 {
00699     send_cmd(NULL, "UNGLINE %s@%s", user, host);
00700 }
00701 
00702 
00703 void anope_part(char *nick, char *chan)
00704 {
00705     send_cmd(nick, "PART %s", chan);
00706 }
00707 void anope_topic(char *whosets, char *chan, char *whosetit, char *topic,
00708                  time_t when)
00709 {
00710     send_cmd(whosets, "TOPIC %s %s %lu :%s", chan, whosetit,
00711              (unsigned long int) when, topic);
00712 }
00713 
00714 /*
00715  :%s UNSQLINE %s
00716     parv[0] = sender 
00717     parv[1] = sqlined nick/mask
00718 */
00719 void ptlink_cmd_unsqline(char *user)
00720 {
00721     send_cmd(NULL, "UNSQLINE %s", user);
00722 }
00723 
00724 void ptlink_cmd_join(char *user, char *channel, time_t chantime)
00725 {
00726     send_cmd(ServerName, "SJOIN %ld %s + :%s", (long int) chantime,
00727              channel, user);
00728 }
00729 
00730 /*
00731    :%s GLINE %s %lu %s %s
00732     parv[0] = sender (server if on network synchronization)
00733     parv[1] = glined usert@host mask
00734     parv[2] = gline duration time (seconds)
00735     parv[3] = who added the gline 
00736     parv[4] = reason
00737 */
00738 void ptlink_cmd_akill(char *user, char *host, char *who, time_t when,
00739                       time_t expires, char *reason)
00740 {
00741     send_cmd(ServerName, "GLINE %s@%s %i %s :%s", user, host, 86400 * 2,
00742              who, reason);
00743 }
00744 
00745 
00746 void ptlink_cmd_svskill(char *source, char *user, char *buf)
00747 {
00748     if (!buf) {
00749         return;
00750     }
00751 
00752     if (!source || !user) {
00753         return;
00754     }
00755 
00756     send_cmd(source, "KILL %s :%s", user, buf);
00757 }
00758 
00759 /*
00760   :%s SVSMODE %s %s :%s
00761     parv[0] = sender (services client)
00762     parv[1] = target client nick
00763     parv[2] = mode changes
00764     parv[3] = extra parameter ( if news setting mode(+n) )
00765   e.g.: :NickServ SVSMODE Lamego +rn 1991234
00766 */
00767 void ptlink_cmd_svsmode(User * u, int ac, char **av)
00768 {
00769     send_cmd(ServerName, "SVSMODE %s %s%s%s", u->nick, av[0],
00770              (ac == 2 ? " " : ""), (ac == 2 ? av[1] : ""));
00771 
00772     /* If we set +r on someone +NRah (1 or more of those modes), PTlink will
00773      * send us a NEWMASK with their ptlink-masked-host. If we want HostServ
00774      * to work for them, we will need to send our NEWMASK after we receive
00775      * theirs. Thus we make a hack and store in moduleData that we need to
00776      * look out for that.
00777      */
00778     if ((strchr(av[0], 'r')
00779          && ((u->mode & UMODE_N) || (u->mode & UMODE_R)
00780              || (u->mode & UMODE_a) || (u->mode & UMODE_h))))
00781         u->mode |= UMODE_NM;
00782 }
00783 
00784 int anope_event_error(char *source, int ac, char **av)
00785 {
00786     if (ac >= 1) {
00787         if (debug) {
00788             alog("debug: %s", av[0]);
00789         }
00790     }
00791     return MOD_CONT;
00792 }
00793 
00794 void ptlink_cmd_squit(char *servname, char *message)
00795 {
00796     send_cmd(NULL, "SQUIT %s :%s", servname, message);
00797 }
00798 
00799 /* PONG */
00800 void ptlink_cmd_pong(char *servname, char *who)
00801 {
00802     send_cmd(servname, "PONG %s", who);
00803 }
00804 
00805 /*
00806   SVINFO %d %d
00807     parv[0] = server name
00808     parv[1] = current supported protocol version
00809     parv[2] = minimum supported protocol version
00810 
00811   See the ptlink.h for information on PTLINK_TS_CURRENT, and
00812   PTLINK_TS_MIN
00813 */
00814 void ptlink_cmd_svinfo()
00815 {
00816 #if defined(PTLINK_TS_CURRENT) && defined(PTLINK_TS_MIN)
00817     send_cmd(NULL, "SVINFO %d %d %lu", PTLINK_TS_CURRENT, PTLINK_TS_MIN,
00818              (unsigned long int) time(NULL));
00819 #else
00820     /* hardwired if the defs some how go missing */
00821     send_cmd(NULL, "SVINFO 6 3 %lu", (unsigned long int) time(NULL));
00822 #endif
00823 }
00824 
00825 /*
00826   SVSINFO %lu %d
00827     parv[0] = sender (server name)
00828     parv[1] = local services data TS
00829     parv[1] = max global users
00830 */
00831 void ptlink_cmd_svsinfo()
00832 {
00833     send_cmd(NULL, "SVSINFO %lu %d", (unsigned long int) time(NULL),
00834              maxusercnt);
00835 }
00836 
00837 /*
00838   PASS %s :TS
00839     parv[1] = connection password 
00840     (TS indicates this is server uses TS protocol and SVINFO will be sent 
00841     for protocol compatibility checking)
00842 */
00843 void ptlink_cmd_pass(char *pass)
00844 {
00845     send_cmd(NULL, "PASS %s :TS", pass);
00846 }
00847 
00848 /*
00849   CAPAB :%s
00850     parv[1] = capability list 
00851 */
00852 void ptlink_cmd_capab()
00853 {
00854     send_cmd(NULL, "CAPAB :QS PTS4");
00855 }
00856 
00857 
00858 void ptlink_cmd_server(char *servname, int hop, char *descript)
00859 {
00860     send_cmd(NULL, "SERVER %s %d Anope.Services%s :%s", servname, hop,
00861              version_number_dotted, descript);
00862 }
00863 void ptlink_cmd_connect(int servernum)
00864 {
00865     me_server =
00866         new_server(NULL, ServerName, ServerDesc, SERVER_ISME, NULL);
00867 
00868     if (servernum == 1)
00869         ptlink_cmd_pass(RemotePassword);
00870     else if (servernum == 2)
00871         ptlink_cmd_pass(RemotePassword2);
00872     else if (servernum == 3)
00873         ptlink_cmd_pass(RemotePassword3);
00874 
00875     ptlink_cmd_capab();
00876     ptlink_cmd_server(ServerName, 1, ServerDesc);
00877     ptlink_cmd_svinfo();
00878     ptlink_cmd_svsinfo();
00879 }
00880 
00881 
00882 
00883 int anope_event_privmsg(char *source, int ac, char **av)
00884 {
00885     if (ac != 2)
00886         return MOD_CONT;
00887     m_privmsg(source, av[0], av[1]);
00888     return MOD_CONT;
00889 }
00890 
00891 int anope_event_part(char *source, int ac, char **av)
00892 {
00893     if (ac < 1 || ac > 2)
00894         return MOD_CONT;
00895     do_part(source, ac, av);
00896     return MOD_CONT;
00897 }
00898 
00899 int anope_event_whois(char *source, int ac, char **av)
00900 {
00901     if (source && ac >= 1) {
00902         m_whois(source, av[0]);
00903     }
00904     return MOD_CONT;
00905 }
00906 
00907 /*
00908   :%s TOPIC %s %s %lu :%s
00909     parv[0] = sender prefix
00910     parv[1] = channel
00911     parv[2] = topic nick
00912     parv[3] = topic time
00913     parv[4] = topic text
00914 */
00915 int anope_event_topic(char *source, int ac, char **av)
00916 {
00917     if (ac != 4)
00918         return MOD_CONT;
00919     do_topic(source, ac, av);
00920     return MOD_CONT;
00921 }
00922 
00923 int anope_event_squit(char *source, int ac, char **av)
00924 {
00925     if (ac != 2)
00926         return MOD_CONT;
00927     do_squit(source, ac, av);
00928     return MOD_CONT;
00929 }
00930 
00931 int anope_event_quit(char *source, int ac, char **av)
00932 {
00933     if (ac != 1)
00934         return MOD_CONT;
00935     do_quit(source, ac, av);
00936     return MOD_CONT;
00937 }
00938 
00939 /*
00940   :%s MODE %s :%s
00941     parv[0] = sender
00942     parv[1] = target nick (==sender)
00943     parv[2] = mode change string
00944 */
00945 int anope_event_mode(char *source, int ac, char **av)
00946 {
00947     if (ac < 2)
00948         return MOD_CONT;
00949 
00950     if (*av[0] == '#' || *av[0] == '&') {
00951         do_cmode(source, ac, av);
00952     } else {
00953         do_umode(source, ac, av);
00954     }
00955     return MOD_CONT;
00956 }
00957 
00958 
00959 int anope_event_kill(char *source, int ac, char **av)
00960 {
00961     if (ac != 2)
00962         return MOD_CONT;
00963 
00964     m_kill(av[0], av[1]);
00965     return MOD_CONT;
00966 }
00967 
00968 int anope_event_kick(char *source, int ac, char **av)
00969 {
00970     if (ac != 3)
00971         return MOD_CONT;
00972     do_kick(source, ac, av);
00973     return MOD_CONT;
00974 }
00975 
00976 
00977 int anope_event_join(char *source, int ac, char **av)
00978 {
00979     if (ac != 1)
00980         return MOD_CONT;
00981     do_join(source, ac, av);
00982     return MOD_CONT;
00983 }
00984 
00985 int anope_event_motd(char *source, int ac, char **av)
00986 {
00987     if (!source) {
00988         return MOD_CONT;
00989     }
00990 
00991     m_motd(source);
00992     return MOD_CONT;
00993 }
00994 
00995 void ptlink_cmd_notice_ops(char *source, char *dest, char *buf)
00996 {
00997     if (!buf) {
00998         return;
00999     }
01000 
01001     send_cmd(NULL, "NOTICE @%s :%s", dest, buf);
01002 }
01003 
01004 
01005 void ptlink_cmd_notice(char *source, char *dest, char *buf)
01006 {
01007     if (!buf) {
01008         return;
01009     }
01010 
01011     if (NSDefFlags & NI_MSG) {
01012         ptlink_cmd_privmsg2(source, dest, buf);
01013     } else {
01014         send_cmd(source, "NOTICE %s :%s", dest, buf);
01015     }
01016 }
01017 
01018 void ptlink_cmd_notice2(char *source, char *dest, char *msg)
01019 {
01020     send_cmd(source, "NOTICE %s :%s", dest, msg);
01021 }
01022 
01023 void ptlink_cmd_privmsg(char *source, char *dest, char *buf)
01024 {
01025     if (!buf) {
01026         return;
01027     }
01028 
01029     send_cmd(source, "PRIVMSG %s :%s", dest, buf);
01030 }
01031 
01032 void ptlink_cmd_privmsg2(char *source, char *dest, char *msg)
01033 {
01034     send_cmd(source, "PRIVMSG %s :%s", dest, msg);
01035 }
01036 
01037 void ptlink_cmd_serv_notice(char *source, char *dest, char *msg)
01038 {
01039     send_cmd(source, "NOTICE $%s :%s", dest, msg);
01040 }
01041 
01042 void ptlink_cmd_serv_privmsg(char *source, char *dest, char *msg)
01043 {
01044     send_cmd(source, "PRIVMSG $%s :%s", dest, msg);
01045 }
01046 
01047 /* GLOBOPS */
01048 void ptlink_cmd_global(char *source, char *buf)
01049 {
01050     if (!buf) {
01051         return;
01052     }
01053 
01054     send_cmd(source ? source : ServerName, "GLOBOPS :%s", buf);
01055 }
01056 
01057 /* 391 */
01058 void ptlink_cmd_391(char *source, cha