implemented autoinvite (invite to all channels enabled this feature, when a user...
authorpk910 <philipp@zoelle1.de>
Fri, 9 Dec 2011 15:57:06 +0000 (16:57 +0100)
committerpk910 <philipp@zoelle1.de>
Fri, 9 Dec 2011 16:16:18 +0000 (17:16 +0100)
src/event_neonserv_join.c

index c2a8634099453800ca2cd197aeac6a416369b5e9..f307b42a630de25959bc6c5ce6d7152cfb07ff31 100644 (file)
@@ -172,8 +172,59 @@ static void neonserv_event_join_async1(struct ClientSocket *client, struct ChanU
         }
     }
     //AUTOINVITE
-    if(chanuserrow && !strcmp(chanuserrow[3], "0") && time(0) - atol(chanuserrow[3]) >= 30) {
-        //TODO: autoinvite
+    if(!chanuserrow || !strcmp(chanuserrow[3], "0") || time(0) - atol(chanuserrow[3]) >= 30) {
+        //check if it's the first channel, the user is seen by the bot (IMPORTANT: ignore other bot's channel!)
+        char first_chan = 1;
+        char bot_in_chan;
+        struct ChanUser *cchanuser, *bchanuser;
+        struct ClientSocket *bot;
+        for(cchanuser = getUserChannels(user, NULL); cchanuser; cchanuser = getUserChannels(user, cchanuser)) {
+            if(chanuser == cchanuser) continue; //ignore this one ;)
+            //check if this bot is in the specific channel
+            bot_in_chan = 0;
+            for(bchanuser = getChannelUsers(cchanuser->chan, NULL); bchanuser; bchanuser = getChannelUsers(cchanuser->chan, bchanuser)) {
+                if(bchanuser->user->flags & USERFLAG_ISBOT) {
+                    //get the botid
+                    for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
+                        if(bot->user == bchanuser->user) {
+                            if(bot->botid == client->botid)
+                                bot_in_chan = 1;
+                            break;
+                        }
+                    }
+                    if(bot_in_chan) break;
+                }
+            }
+            if(!bot_in_chan) continue;
+            first_chan = 0;
+            break;
+        }
+        if(first_chan) {
+            //autoinvite :)
+            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();
+            int getinvite;
+            while((chanuserrow = mysql_fetch_row(res)) != NULL) {
+                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(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);
+                }
+                getinvite = atoi((chanuserrow[3] ? chanuserrow[3] : defaultrow[0]));
+                if(atoi(chanuserrow[0]) >= getinvite) {
+                    putsock(bot, "INVITE %s %s", user->nick, chan->name);
+                }
+            }
+        }
     }
 }