added "all" argument to inviteme to invite users to all channels they have autoinvite...
authorpk910 <philipp@zoelle1.de>
Sun, 23 Sep 2012 19:33:19 +0000 (21:33 +0200)
committerpk910 <philipp@zoelle1.de>
Sun, 23 Sep 2012 19:33:19 +0000 (21:33 +0200)
src/modules/NeonServ.mod/cmd_neonserv_inviteme.c
src/modules/NeonServ.mod/event_neonserv_join.c

index bbe7a3070b221fbd9c0915fe293c8269365890d4..f7f2a82794ec22723e7c6c7c51d9e0d6dcdb3751 100644 (file)
 */
 
 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);
 }
index ba12f166e74e4679f40e738d096e4496972fbd95..8903959038ec3b33ab637577be51b76e1963efb3 100644 (file)
@@ -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) {