summaryrefslogtreecommitdiff
path: root/src/irc/flood/flood.c
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@irssi.org>2009-02-28 12:43:00 +0000
committerjilles <jilles@dbcabf3a-b0e7-0310-adc4-f8d773084564>2009-02-28 12:43:00 +0000
commit2dd265ef395db11173d19a4f026bc6076ababf00 (patch)
tree1d27b2a7cc95545097de4c31181068dacd1dc857 /src/irc/flood/flood.c
parentc57f58dea5dbbd9b5b1e8861d9a37dfa1c62b98a (diff)
downloadirssi-2dd265ef395db11173d19a4f026bc6076ababf00.zip
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
Diffstat (limited to 'src/irc/flood/flood.c')
-rw-r--r--src/irc/flood/flood.c18
1 files changed, 15 insertions, 3 deletions
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);