From 2dd265ef395db11173d19a4f026bc6076ababf00 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Sat, 28 Feb 2009 12:43:00 +0000 Subject: Check for stale flood entries when lines come in, avoiding a 0.5 second timeout. The timeout is now every 5 seconds and serves to remove entries that do not send messages anymore. git-svn-id: file:///var/www/svn.irssi.org/SVN/irssi/trunk@5024 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/irc/flood/flood.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/irc/flood/flood.c') diff --git a/src/irc/flood/flood.c b/src/irc/flood/flood.c index ebb07d2c..677d739b 100644 --- a/src/irc/flood/flood.c +++ b/src/irc/flood/flood.c @@ -186,7 +186,8 @@ static void flood_newmsg(IRC_SERVER_REC *server, int level, const char *nick, MODULE_SERVER_REC *mserver; FLOOD_REC *flood; FLOOD_ITEM_REC *rec; - time_t *ttime; + time_t now, *ttime; + GSList *times, *tnext; g_return_if_fail(server != NULL); g_return_if_fail(nick != NULL); @@ -196,8 +197,19 @@ static void flood_newmsg(IRC_SERVER_REC *server, int level, const char *nick, rec = flood == NULL ? NULL : flood_find(flood, level, target); if (rec != NULL) { + now = time(NULL); + for (times = rec->msgtimes; times != NULL; times = tnext) { + time_t *data = times->data; + tnext = times->next; + + if (now - *data >= flood_timecheck) { + rec->msgtimes = g_slist_remove(rec->msgtimes, data); + g_free(data); + } else + break; + } ttime = g_new(time_t, 1); - *ttime = time(NULL); + *ttime = now; rec->msgtimes = g_slist_append(rec->msgtimes, ttime); if (g_slist_length(rec->msgtimes) > flood_max_msgs) { /* flooding! */ @@ -287,7 +299,7 @@ static void read_settings(void) if (flood_timecheck > 0 && flood_max_msgs > 0) { if (flood_tag == -1) { - flood_tag = g_timeout_add(500, (GSourceFunc) flood_timeout, NULL); + flood_tag = g_timeout_add(5000, (GSourceFunc) flood_timeout, NULL); signal_add("event privmsg", (SIGNAL_FUNC) flood_privmsg); signal_add("event notice", (SIGNAL_FUNC) flood_notice); -- cgit v1.2.3