From 9a3c990b3720debc49136ef00df80be6b2223839 Mon Sep 17 00:00:00 2001 From: pk910 Date: Sun, 23 Sep 2012 21:33:19 +0200 Subject: [PATCH] added "all" argument to inviteme to invite users to all channels they have autoinvite enabled --- .../NeonServ.mod/cmd_neonserv_inviteme.c | 50 +++++++++++++++---- .../NeonServ.mod/event_neonserv_join.c | 6 +-- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/modules/NeonServ.mod/cmd_neonserv_inviteme.c b/src/modules/NeonServ.mod/cmd_neonserv_inviteme.c index bbe7a30..f7f2a82 100644 --- a/src/modules/NeonServ.mod/cmd_neonserv_inviteme.c +++ b/src/modules/NeonServ.mod/cmd_neonserv_inviteme.c @@ -22,15 +22,45 @@ */ CMD_BIND(neonserv_cmd_inviteme) { - if(getChanUser(user, chan)) { - reply(textclient, user, "NS_INVITEME_ON_CHAN", chan->name); - /* BUG - This check does not work if the user is invisible (CHMODE +D/+d) - to fix this we'd need to request the full userlist... - this is really senseless to invite a simple user so we simply mark this bug as unsolvable. - */ - return; + if(argc && !stricmp(argv[0], "all")) { + //invite to all channels where autoinvite is enabled + MYSQL_RES *res, *res2; + MYSQL_ROW chanuserrow, defaultrow = NULL; + printf_mysql_query("SELECT `chanuser_access`, `chanuser_flags`, `channel_name`, `channel_getinvite` FROM `chanusers` LEFT JOIN `channels` ON `chanuser_cid` = `channel_id` LEFT JOIN `users` ON `chanuser_uid` = `user_id` WHERE `user_user` = '%s' AND `chanuser_flags` >= '%d'", escape_string(user->auth), DB_CHANUSER_AUTOINVITE); + res = mysql_use(); + struct ChanUser *bchanuser; + struct ClientSocket *bot; + while((chanuserrow = mysql_fetch_row(res)) != NULL) { + int userflags = atoi(chanuserrow[1]); + if(!(userflags & DB_CHANUSER_AUTOINVITE)) continue; + if(!(chan = getChanByName(chanuserrow[2]))) continue; //no bot is in the channel + if((bchanuser = getChanUser(client->user, chan)) && (bchanuser->flags & CHANUSERFLAG_OPPED)) + bot = client; + else { + bot = getBotForChannel(chan); + } + if(getChanUser(user, chan)) continue; //user is already in the channel + if(chanuserrow[3] == NULL && defaultrow == NULL) { + printf_mysql_query("SELECT `channel_getinvite` FROM `channels` WHERE `channel_name` = 'defaults'"); + res2 = mysql_use(); + defaultrow = mysql_fetch_row(res2); + } + if(atoi(chanuserrow[0]) >= atoi((chanuserrow[3] ? chanuserrow[3] : defaultrow[0]))) { + putsock(bot, "INVITE %s %s", user->nick, chan->name); + reply(textclient, user, "NS_INVITEME_DONE", chan->name); + } + } + } else { + if(getChanUser(user, chan)) { + reply(textclient, user, "NS_INVITEME_ON_CHAN", chan->name); + /* BUG + This check does not work if the user is invisible (CHMODE +D/+d) + to fix this we'd need to request the full userlist... + this is really senseless to invite a simple user so we simply mark this bug as unsolvable. + */ + return; + } + putsock(client, "INVITE %s %s", user->nick, chan->name); + reply(textclient, user, "NS_INVITEME_DONE", chan->name); } - putsock(client, "INVITE %s %s", user->nick, chan->name); - reply(textclient, user, "NS_INVITEME_DONE", chan->name); } diff --git a/src/modules/NeonServ.mod/event_neonserv_join.c b/src/modules/NeonServ.mod/event_neonserv_join.c index ba12f16..8903959 100644 --- a/src/modules/NeonServ.mod/event_neonserv_join.c +++ b/src/modules/NeonServ.mod/event_neonserv_join.c @@ -76,7 +76,7 @@ static void neonserv_event_join_async1(struct ClientSocket *client, struct ChanU struct UserNode *user = chanuser->user; struct ModeBuffer *modeBuf; int with_halfops = get_int_field("General.have_halfop"); - MYSQL_RES *res; + MYSQL_RES *res, *res2; MYSQL_ROW row, chanuserrow, defaultrow = NULL; printf_mysql_query("SELECT `channel_maxusers`, `channel_greeting`, `channel_usergreeting`, `channel_getop`, `channel_getvoice`, `channel_userinfo`, `channel_dynlimit`, `channel_gethalfop` FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id); res = mysql_use(); @@ -219,8 +219,8 @@ static void neonserv_event_join_async1(struct ClientSocket *client, struct ChanU } if(chanuserrow[3] == NULL && defaultrow == NULL) { printf_mysql_query("SELECT `channel_getinvite` FROM `channels` WHERE `channel_name` = 'defaults'"); - res = mysql_use(); - defaultrow = mysql_fetch_row(res); + res2 = mysql_use(); + defaultrow = mysql_fetch_row(res2); } getinvite = atoi((chanuserrow[3] ? chanuserrow[3] : defaultrow[0])); if(atoi(chanuserrow[0]) >= getinvite) { -- 2.20.1