only add ban timers with a duration lower than 7 days to the timeq (prevent counter...
[NeonServV5.git] / src / bots.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) {