#ifdef LEAF /* * servmsg.c -- part of server.mod * */ #ifdef S_NODELAY #include #endif #define msgop CFG_MSGOP.ldata ? CFG_MSGOP.ldata : CFG_MSGOP.gdata ? CFG_MSGOP.gdata : "" #define msgpass CFG_MSGPASS.ldata ? CFG_MSGPASS.ldata : CFG_MSGPASS.gdata ? CFG_MSGPASS.gdata : "" #define msginvite CFG_MSGINVITE.ldata ? CFG_MSGINVITE.ldata : CFG_MSGINVITE.gdata ? CFG_MSGINVITE.gdata : "" #define msgident CFG_MSGIDENT.ldata ? CFG_MSGIDENT.ldata : CFG_MSGIDENT.gdata ? CFG_MSGIDENT.gdata : "" char cursrvname[120] = ""; char curnetwork[120] = ""; static time_t last_ctcp = (time_t) 0L; static int count_ctcp = 0; static char altnick_char = 0; /* We try to change to a preferred unique nick here. We always first try the * specified alternate nick. If that failes, we repeatedly modify the nick * until it gets accepted. * * sent nick: * "" * ^--- additional count character: 1-9^-_\\[]`a-z * ^--------- given, alternate nick * * The last added character is always saved in altnick_char. At the very first * attempt (were altnick_char is 0), we try the alternate nick without any * additions. * * fixed by guppy (1999/02/24) and Fabian (1999/11/26) */ int rolls = 0; static int gotfake433(char *from) { int l = strlen(botname) - 1; int use_chr = 1; char *altchrs = "-_\\`^[]"; /* First run? */ if (altnick_char == 0) { altnick_char = altchrs[0]; /* the nick is already as long as it can be. */ if (l + 1 == nick_len) { /* make the last char the altnick_char */ botname[l] = altnick_char; } else { /* tack it on to the end */ botname[++l] = altnick_char; botname[l + 1] = 0; } } else { char *p = NULL; if ((p = strchr(altchrs, altnick_char))) p++; if (!p || (p && !*p)) { /* fun BX style rolling, WEEEE */ if (rolls < 10) { char tmp; if (rolls == 0) strcpy(botname, origbotname); tmp = botname[8]; if (strchr(BADNICKCHARS, tmp)) tmp = '_'; altnick_char = 0; use_chr = 0; rolls++; botname[8] = botname[7]; botname[7] = botname[6]; botname[6] = botname[5]; botname[5] = botname[4]; botname[4] = botname[3]; botname[3] = botname[2]; botname[2] = botname[1]; botname[1] = botname[0]; botname[0] = tmp; } else { /* when we run out of 'altchrs', then make altnick_char a random alpha */ altnick_char = 'a' + randint(26); } } else { /* else, make altnick_char the 'oknick' */ altnick_char = (*p); } if (use_chr) botname[l] = altnick_char; } putlog(LOG_SERV, "*", IRC_BOTNICKINUSE, botname); dprintf(DP_SERVER, "NICK %s\n", botname); return 0; } /* Check for tcl-bound msg command, return 1 if found * * msg: proc-name */ static void check_bind_msg(char *cmd, char *nick, char *uhost, struct userrec *u, char *args) { struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0}; int x; get_user_flagrec(u, &fr, NULL); x = check_bind(BT_msg, cmd, &fr, nick, uhost, u, args); if (x & BIND_RET_LOG) putlog(LOG_CMDS, "*", "(%s!%s) !%s! %s %s", nick, uhost, u ? u->handle : "*" , cmd, args); else if (x == 0) putlog(LOG_MSGS, "*", "[%s!%s] %s %s", nick, uhost, cmd, args); } #ifdef S_AUTHCMDS static int check_bind_msgc(char *cmd, char *nick, char *from, struct userrec *u, char *args) { struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0}; int x = 0; get_user_flagrec(u, &fr, NULL); x = check_bind(BT_msgc, cmd, &fr, nick, from, u, NULL, args); if (x & BIND_RET_LOG) putlog(LOG_CMDS, "*", "(%s!%s) !%s! %c%s %s", nick, from, u ? u->handle : "*", cmdprefix, cmd, args); if (x & BIND_RET_BREAK) return(1); return(0); } #endif /* S_AUTHCMDS */ /* Return 1 if processed. */ static int check_bind_raw(char *from, char *code, char *msg) { char *p1 = NULL, *p2 = NULL, *myfrom = NULL, *mymsg = NULL; int ret = 0; myfrom = p1 = strdup(from); mymsg = p2 = strdup(msg); ret = check_bind(BT_raw, code, NULL, myfrom, mymsg); free(p1); free(p2); return ret; } int check_bind_ctcpr(char *nick, char *uhost, struct userrec *u, char *dest, char *keyword, char *args, bind_table_t *table) { struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0}; get_user_flagrec(u, &fr, NULL); return check_bind(table, keyword, &fr, nick, uhost, u, dest, keyword, args); } __inline__ int match_my_nick(char *nick) { return (!rfc_casecmp(nick, botname)); } /* 001: welcome to IRC (use it to fix the server name) */ static int got001(char *from, char *msg) { struct server_list *x = NULL; int i; struct chanset_t *chan = NULL; /* Ok...param #1 of 001 = what server thinks my nick is */ server_online = now; checked_hostmask = 0; fixcolon(msg); strncpyz(botname, msg, NICKLEN); altnick_char = 0; strncpyz(cursrvname, from, sizeof(cursrvname)); dprintf(DP_SERVER, "WHOIS %s\n", botname); /* get user@host */ dprintf(DP_SERVER, "MODE %s +iws\n", botname); x = serverlist; if (x == NULL) return 0; /* Uh, no server list */ /* Only join if the IRC module is loaded. */ for (chan = chanset; chan; chan = chan->next) { chan->status &= ~(CHAN_ACTIVE | CHAN_PEND); if (shouldjoin(chan)) dprintf(DP_SERVER, "JOIN %s %s\n", (chan->name[0]) ? chan->name : chan->dname, chan->channel.key[0] ? chan->channel.key : chan->key_prot); } if (egg_strcasecmp(from, dcc[servidx].host)) { putlog(LOG_MISC, "*", "(%s claims to be %s; updating server list)", dcc[servidx].host, from); for (i = curserv; i > 0 && x != NULL; i--) x = x->next; if (x == NULL) { putlog(LOG_MISC, "*", "Invalid server list!"); return 0; } if (x->realname) free(x->realname); if (strict_servernames == 1) { x->realname = NULL; if (x->name) free(x->name); x->name = strdup(from); } else { x->realname = strdup(from); } } return 0; } /* 005