/* this file contains all functions to process incoming ircd messages */ #include "ircd.h" int do_on_privmsg(char *source, int ac, char **av) { User *u = finduser(source); Channel *c; char *cmd, *target, *target_; if (*av[0] == '#') { /* is it a channel msg ? */ if (!av[1]) return MOD_CONT; // this should never happen cmd = myStrGetToken(av[1],' ',0); // get the command target = myStrGetToken(av[1],' ',1); // get the option if (cmd && target && !stricmp(cmd,SEENCOMMAND)) { if (s_BotServ && (c = findchan(av[0]))) { if (!(c->ci->flags & CI_VERBOTEN) && c->ci->c && c->ci->bi) { /* Some paranoia checks */ /* strip all control characters and colors from the string */ target_ = normalizeBuffer(target); do_seen(u, c->ci, target_); free(target_); } } free(cmd);free(target); return MOD_STOP; } free(cmd);free(target); } return MOD_CONT; } /***************************************************************************************************/ int do_on_connect(int argc, char **argv) { User *u; char *nick, *vident, *vhost, *host; time_t now = time(NULL); int len; if (!(u = finduser(argv[0]))) return MOD_CONT; nick = quote(argv[0]); // we have to free() it later if (u->vident) vident = u->vident; else vident = u->username; len = strlen(u->host)+strlen(u->username)+2; host = malloc(len); // we have to free() it later snprintf(host,len,"%s@%s", u->username, u->host); len = strlen(u->vhost)+strlen(vident)+2; vhost = malloc(len); // we have to free() it later snprintf(vhost,len,"%s@%s", vident, u->vhost ? u->vhost : u->host); do_query("INSERT INTO "DBNAME" " "(`nick`, `type`, `host`, `vhost`, `last`) " "VALUES ('%s', 1, '%s', '%s', '%lu') " "ON DUPLICATE KEY UPDATE " "type=VALUES(type), host=VALUES(host), vhost=VALUES(vhost), " "last=VALUES(last);", nick, host, vhost, now); free(nick); free(host); free(vhost); return MOD_CONT; } /***************************************************************************************************/ int do_on_nickchange(char *source, int ac, char **av) { User *u; int len; time_t now = time(NULL); char *nick, *oldnick, *vident, *vhost, *host; if (ac == 2) { // nickchange if (!(u = finduser(av[0]))) return MOD_CONT; nick = quote(av[0]); // we have to free() it later oldnick = quote(source); // we have to free() it later if (u->vident) vident = u->vident; else vident = u->username; len = strlen(u->host)+strlen(u->username)+2; host = malloc(len); // we have to free() it later snprintf(host,len,"%s@%s", u->username, u->host); len = strlen(u->vhost)+strlen(vident)+2; vhost = malloc(len); // we have to free() it later snprintf(vhost,len,"%s@%s", vident, u->vhost ? u->vhost : u->host); /* update old nick */ do_query("INSERT INTO "DBNAME" " "(`nick`, `type`, `host`, `vhost`, `last`, `spent`, `newnick`) " "VALUES ('%s', 2, '%s', '%s', '%lu', '0', '%s') " "ON DUPLICATE KEY UPDATE " "type=VALUES(type), host=VALUES(host), vhost=VALUES(vhost), " "last=VALUES(last), spent=VALUES(spent), newnick=VALUES(newnick);", oldnick, host, vhost, now, nick); /* update new nick */ do_query("INSERT INTO "DBNAME" " "(`nick`, `type`, `host`, `vhost`, `last`, `spent`, `newnick`) " "VALUES ('%s', 3, '%s', '%s', '%lu', '0', '%s') " "ON DUPLICATE KEY UPDATE " "type=VALUES(type), host=VALUES(host), vhost=VALUES(vhost), " "last=VALUES(last), spent=VALUES(spent), newnick=VALUES(newnick);", nick, host, vhost, now, oldnick); free(oldnick); free(nick); free(vhost); free(host); } /* if (ac == 2) */ return MOD_CONT; } /***************************************************************************************************/ int do_on_join(int argc, char **argv) { User *u; time_t now = time(NULL); char *host, *vhost, *vident, *channel, *nick; int len; if (!argc == 3) return MOD_CONT; if (!stricmp(argv[0], EVENT_STOP)) return MOD_CONT; if (!(u = finduser(argv[1]))) return MOD_CONT; nick = quote(argv[1]); // we have to free() it later channel = quote(argv[2]); // we have to free() it later if (u->vident) vident = u->vident; else vident = u->username; len = strlen(u->host)+strlen(u->username)+2; host = malloc(len); // we have to free() it later snprintf(host,len,"%s@%s", u->username, u->host); len = strlen(u->vhost)+strlen(vident)+2; vhost = malloc(len); // we have to free() it later snprintf(vhost,len,"%s@%s", vident, u->vhost ? u->vhost : u->host); do_query("INSERT INTO "DBNAME" " "(nick, type, host, vhost, last, chan) " "VALUES ('%s', 4, '%s', '%s', '%lu', '%s') " "ON DUPLICATE KEY UPDATE " "type=VALUES(type), host=VALUES(host), vhost=VALUES(vhost), " "last=VALUES(last), chan=VALUES(chan);", nick, host, vhost, now, channel); free(channel); free(nick); free(vhost); free(host); return MOD_CONT; } /***************************************************************************************************/ int do_on_kick(char *source, int ac, char **av) { User *u; time_t now = time(NULL); char *victim, *host, *vhost, *vident, *channel, *msg; int len; if (!(u = finduser(av[1]))) return MOD_CONT; /* something went wrong - stop processing */ source = quote(source); // we have to free() it later channel = quote(av[0]); // we have to free() it later victim = quote(av[1]); // we have to free() it later msg = av[2] ? quote(av[2]) : quote(""); /* to mysql_real_escape() an empty string seems useless, but we need the allocated memory to free() it later */ if (u->vident) vident = u->vident; else vident = u->username; len = strlen(u->host)+strlen(u->username)+2; host = malloc(len); snprintf(host,len,"%s@%s", u->username, u->host); len = strlen(u->vhost)+strlen(vident)+2; vhost = malloc(len); snprintf(vhost,len,"%s@%s", vident, u->vhost ? u->vhost : u->host); do_query("INSERT INTO "DBNAME" " "(nick, type, host, vhost, last, chan, msg, newnick) " "VALUES ('%s', 7, '%s', '%s', '%lu', '%s', '%s', '%s') " "ON DUPLICATE KEY UPDATE " "type=VALUES(type), host=VALUES(host), vhost=VALUES(vhost), " "last=VALUES(last), chan=VALUES(chan), msg=VALUES(msg), newnick=VALUES(newnick);", victim, host, vhost, now, channel, msg, source); free(msg); free(source); free(victim); free(vhost); free(host); return MOD_CONT; } /*************************************************************************************** EVENT_PART_CHANNEL A user parts a channel. av[0] EVENT_START or EVENT_STOP. EVENT_START when the user is about to be removed from the channel internally, EVENT_STOP when this has been done. av[1] The nickname of the user parting the channel. av[2] The name of the channel the user has parted. av[3] The reason the user parted the channel, this is not always sent so check the count to make sure it was passed. (ac == 4) ******************************************************************************************/ int do_on_part(int argc, char **argv) { User *u; time_t now = time(NULL); char *host, *vhost, *vident, *channel, *msg, *nick; int len; if (!stricmp(argv[0], EVENT_STOP)) return MOD_CONT; if (!(u = finduser(argv[1]))) return MOD_CONT; nick = quote(argv[1]); // we have to free() it later channel = quote(argv[2]); // we have to free() it later msg = argv[3] ? quote(argv[3]) : quote(""); // we have to free() it later if (u->vident) vident = u->vident; else vident = u->username; len = strlen(u->host)+strlen(u->username)+2; host = malloc(len); snprintf(host,len,"%s@%s", u->username, u->host); len = strlen(u->vhost)+strlen(vident)+2; vhost = malloc(len); snprintf(vhost,len,"%s@%s", vident, u->vhost ? u->vhost : u->host); do_query("INSERT INTO "DBNAME" " "(nick, type, host, vhost, last, chan, msg) " "VALUES ('%s', 5, '%s', '%s', '%lu', '%s', '%s') " "ON DUPLICATE KEY UPDATE " "type=VALUES(type), host=VALUES(host), vhost=VALUES(vhost), " "last=VALUES(last), chan=VALUES(chan), msg=VALUES(msg);", nick, host, vhost, now, channel, msg); free(msg); free(nick); free(channel); free(vhost); free(host); return MOD_CONT; } /***************************************************************************************/ int do_on_quit(char *source, int ac, char **av) { User *u; time_t now = time(NULL); char *host, *vhost, *vident, *msg; int len; if (!(u = finduser(source))) return MOD_CONT; // something went wrong source = quote(source); // we have to free() it later msg = av[0] ? quote(av[0]) : quote(""); // we have to free() it later if (u->vident) vident = u->vident; else vident = u->username; len = strlen(u->host)+strlen(u->username)+2; host = malloc(len); // we have to free() it later snprintf(host,len,"%s@%s", u->username, u->host); len = strlen(u->vhost)+strlen(vident)+2; vhost = malloc(len); // we have to free() it later snprintf(vhost,len,"%s@%s", vident, u->vhost ? u->vhost : u->host); do_query("INSERT INTO "DBNAME" " "(nick, type, host, vhost, last, msg) " "VALUES ('%s', 6, '%s', '%s', '%lu', '%s') " "ON DUPLICATE KEY UPDATE " "type=VALUES(type), host=VALUES(host), vhost=VALUES(vhost), " "last=VALUES(last), msg=VALUES(msg);", source, host, vhost, now, msg); free(msg); free(source); free(vhost); free(host); return MOD_CONT; }