remove timed out bans from the channel ban list
authorpk910 <philipp@zoelle1.de>
Thu, 15 Sep 2011 22:30:20 +0000 (00:30 +0200)
committerpk910 <philipp@zoelle1.de>
Thu, 15 Sep 2011 22:30:20 +0000 (00:30 +0200)
bot_NeonServ.c

index 24441fb84104b7dc9b774433781630d0f7aa9490..ef45cfc4c92510ee4a136a89c7cc0a18cd399984 100644 (file)
@@ -338,10 +338,21 @@ static TIMEQ_CALLBACK(channel_ban_timeout) {
     char *str_banid = data;
     MYSQL_RES *res;
     MYSQL_ROW row;
-    printf_mysql_query("SELECT `ban_mask` FROM `bans` WHERE `ban_id` = '%s'", str_banid);
+    printf_mysql_query("SELECT `ban_mask`, `channel_name` FROM `bans` LEFT JOIN `channels` ON `ban_channel` = `channel_id` WHERE `ban_id` = '%s'", str_banid);
     res = mysql_use();
-    if((row = mysql_fetch_row(res)) != NULL) {
-        //TODO: unban if mask is still banned
+    struct ChanNode *chan;
+    if((row = mysql_fetch_row(res)) != NULL && (chan = getChanByName(row[1])) != NULL) {
+        struct ClientSocket *bot, *use_bot = NULL;
+        struct ChanUser *chanuser;
+        for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
+            if((chanuser = getChanUser(bot->user, chan)) != NULL && (chanuser->flags & CHANUSERFLAG_OPPED)) {
+                use_bot = bot;
+                if(bot->flags & SOCKET_FLAG_PREFERRED) break;
+            }
+        }
+        if(use_bot) {
+            putsock(use_bot, "MODE %s -b %s", chan->name, row[0]);
+        }
         printf_mysql_query("DELETE FROM `bans` WHERE `ban_id` = '%s'", str_banid);
     }
     free(str_banid);