From 9921b4a73a989eb4858499f4c61bb3367c1b0fe4 Mon Sep 17 00:00:00 2001 From: pk910 Date: Wed, 22 Aug 2012 02:49:18 +0200 Subject: [PATCH] only add ban timers with a duration lower than 7 days to the timeq (prevent counter overflows) --- src/bots.c | 22 ++++++++++++------- .../NeonServ.mod/cmd_neonserv_addtimeban.c | 10 +++++---- src/timeq.c | 4 +++- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/bots.c b/src/bots.c index ef55ef6..4875b5a 100644 --- a/src/bots.c +++ b/src/bots.c @@ -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) { diff --git a/src/modules/NeonServ.mod/cmd_neonserv_addtimeban.c b/src/modules/NeonServ.mod/cmd_neonserv_addtimeban.c index 38ce380..8df4b39 100644 --- a/src/modules/NeonServ.mod/cmd_neonserv_addtimeban.c +++ b/src/modules/NeonServ.mod/cmd_neonserv_addtimeban.c @@ -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); } diff --git a/src/timeq.c b/src/timeq.c index 3350325..7689b31 100644 --- a/src/timeq.c +++ b/src/timeq.c @@ -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; -- 2.20.1