only add ban timers with a duration lower than 7 days to the timeq (prevent counter...
authorpk910 <philipp@zoelle1.de>
Wed, 22 Aug 2012 00:49:18 +0000 (02:49 +0200)
committerpk910 <philipp@zoelle1.de>
Wed, 22 Aug 2012 01:08:38 +0000 (03:08 +0200)
src/bots.c
src/modules/NeonServ.mod/cmd_neonserv_addtimeban.c
src/timeq.c

index ef55ef656e1b78b4a3c4c7c9255f647496559e80..4875b5a5c987e97036c6084b704c2ddb58a58362 100644 (file)
@@ -117,16 +117,11 @@ static void zero_bots_bot_ready(struct ClientSocket *client) {
     }
 }
 
-void init_bots() {
-    set_bot_alias(0, "0");
-    start_zero_bots();
-    set_trigger_callback(0, 0, zero_bots_trigger_callback);
-       bind_bot_ready(zero_bots_bot_ready, 0);
-    
+static TIMEQ_CALLBACK(load_timed_bans) {
     MYSQL_RES *res;
     MYSQL_ROW row;
-    //load all timed bans
-    printf_mysql_query("SELECT `ban_id`, `ban_timeout` FROM `bans` WHERE `ban_timeout` > 0");
+    //load all timed bans for the next 7 days
+    printf_mysql_query("SELECT `ban_id`, `ban_timeout` FROM `bans` WHERE `ban_timeout` > 0 AND `ban_timeout` < (UNIX_TIMESTAMP() + (86400 * 7))");
     res = mysql_use();
     char nameBuf[20];
     while ((row = mysql_fetch_row(res)) != NULL) {
@@ -138,6 +133,17 @@ void init_bots() {
             printf_mysql_query("DELETE FROM `bans` WHERE `ban_id` = '%s'", row[0]);
         }
     }
+    timeq_add(86400*7, 0, load_timed_bans, NULL);
+}
+
+void init_bots() {
+    set_bot_alias(0, "0");
+    start_zero_bots();
+    set_trigger_callback(0, 0, zero_bots_trigger_callback);
+       bind_bot_ready(zero_bots_bot_ready, 0);
+    
+    timeq_add(10, 0, load_timed_bans, NULL);
+    
 }
 
 struct ClientSocket *getChannelBot(struct ChanNode *chan, int botid) {
index 38ce3804cb4a016f4a3a53293d7b0de64cefaa5c..8df4b39edd73be3eeaf15c881f78ea478bf79453 100644 (file)
@@ -129,10 +129,12 @@ static void neonserv_cmd_addtimeban_async1(struct ClientSocket *client, struct C
         }
     }
     char nameBuf[MAXLEN];
-    char banidBuf[20];
-    sprintf(nameBuf, "ban_%d", banid);
-    sprintf(banidBuf, "%d", banid);
-    timeq_add_name(nameBuf, duration, module_id, channel_ban_timeout, strdup(banidBuf));
+    if(duration < 86400*7) {
+        char banidBuf[20];
+        sprintf(nameBuf, "ban_%d", banid);
+        sprintf(banidBuf, "%d", banid);
+        timeq_add_name(nameBuf, duration, module_id, channel_ban_timeout, strdup(banidBuf));
+    }
     reply(textclient, user, "NS_TIMEBAN_DONE", mask, chan->name, timeToStr(user, duration, 2, nameBuf), match_count);
     logEvent(event);
 }
index 335032519f52a837b01c9f5e58bce5cc88face4e..7689b316f0fb35d2614c47d1b9ac212d31baa981 100644 (file)
@@ -29,6 +29,7 @@ static IOHANDLER_CALLBACK(timeq_callback) {
     switch(event->type) {
     case IOEVENT_TIMEOUT:
         entry->callback(entry->data);
+        entry->iofd = NULL;
         timeq_del(entry);
         break;
     default:
@@ -92,7 +93,8 @@ int timeq_del(struct timeq_entry* entry) {
         timeq_events = entry->next;
     if(entry->name)
         free(entry->name);
-    iohandler_close(entry->iofd);
+    if(entry->iofd)
+        iohandler_close(entry->iofd);
     free(entry);
     DESYNCHRONIZE(synchronized);
     return 1;