/* * You need to execute the following mysql query before loading this module: CREATE TABLE `ab_ns_autojoin` ( `nc_id` int(11) NOT NULL, `chan` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; * */ #include "module.h" #define AUTHOR "Alek" #define VERSION "0.1A" int ns_autojoin(User *u); int ns_identify(User *u); int do_autojoin(User *u, int nc_id); void AnopeInit(void) { Command *c; c = createCommand("autojoin", ns_autojoin, nick_identified, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_TAIL); c = createCommand("identify", ns_identify, nick_identified, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_TAIL); moduleAddAuthor(AUTHOR); moduleAddVersion(VERSION); } void AnopeFini(void) { } int ns_autojoin(User *u) { MYSQL_ROW row; MYSQL_RES *res; char *cmd = strtok(NULL, " "); char *channel = strtok(NULL, ""); int nc_id = get_nc_id(u->na_id), i = 0; if (!cmd){ do_autojoin(u, nc_id); } else if (!stricmp(cmd, "ADD")){ char *chan; if (!channel) return MOD_CONT; channel = strnrepl(channel, MAX_SQL_BUF, " ", ""); for (i = 0; (chan = myStrGetToken(channel, ',', i)); i++){ res = dbQuery("select * from ab_ns_autojoin where nc_id = '%d' && chan = '%s'", nc_id, chan); if (numRows(res) < 1) dbQuery("insert into ab_ns_autojoin values ('%d', '%s')", nc_id, chan); } notice(s_NickServ, u->nick, "Channels %s added to your autojoin list", channel); } else if (!stricmp(cmd, "DEL")){ char *chan; if (!channel) return MOD_CONT; channel = strnrepl(channel, MAX_SQL_BUF, " ", ""); for (i = 0; (chan = myStrGetToken(channel, ',', i)); i++){ res = dbQuery("select * from ab_ns_autojoin where nc_id = '%d' && chan = '%s'", nc_id, chan); if (numRows(res) == 1) dbQuery("delete from ab_ns_autojoin where nc_id = '%d' && chan = '%s'", nc_id, chan); } notice(s_NickServ, u->nick, "Channels %s deleted from your autojoin list", channel); } else if (!stricmp(cmd, "LIST")){ res = dbQuery("select * from ab_ns_autojoin where nc_id = '%d'", nc_id); if (numRows(res) > 0) notice(s_NickServ, u->nick, "Channels on autojoin list"); else notice(s_NickServ, u->nick, "No channels on your autojoin list"); while ((row = mysql_fetch_row(res))) notice(s_NickServ, u->nick, "%s", row[1]); } return MOD_CONT; } int ns_identify(User *u) { int nc_id = get_nc_id(u->na_id); if (!nick_identified(u)) return MOD_CONT; do_autojoin(u, nc_id); return MOD_CONT; } int do_autojoin(User *u, int nc_id) { MYSQL_RES *res; MYSQL_ROW row; res = dbQuery("select * from ab_ns_autojoin where nc_id = '%d'", nc_id); while ((row = mysql_fetch_row(res))){ send_cmd(NULL, "SVSJOIN %s %s", u->nick, row[1]); } return MOD_CONT; }