forked from PsychoticNinja/irssi
fixes, hopefully works correctly finally :) patch by fuchs.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1420 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
62dae68191
commit
eba784876e
@ -36,8 +36,7 @@ typedef struct {
|
|||||||
char *target;
|
char *target;
|
||||||
int level;
|
int level;
|
||||||
|
|
||||||
int msgcount;
|
GSList *msgtimes;
|
||||||
time_t first;
|
|
||||||
} FLOOD_ITEM_REC;
|
} FLOOD_ITEM_REC;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -51,7 +50,7 @@ static int flood_max_msgs, flood_timecheck;
|
|||||||
static int flood_hash_check_remove(const char *key, FLOOD_REC *flood,
|
static int flood_hash_check_remove(const char *key, FLOOD_REC *flood,
|
||||||
time_t *now)
|
time_t *now)
|
||||||
{
|
{
|
||||||
GSList *tmp, *next;
|
GSList *tmp, *next, *times, *tnext;
|
||||||
|
|
||||||
g_return_val_if_fail(key != NULL, FALSE);
|
g_return_val_if_fail(key != NULL, FALSE);
|
||||||
g_return_val_if_fail(flood != NULL, FALSE);
|
g_return_val_if_fail(flood != NULL, FALSE);
|
||||||
@ -60,7 +59,16 @@ static int flood_hash_check_remove(const char *key, FLOOD_REC *flood,
|
|||||||
FLOOD_ITEM_REC *rec = tmp->data;
|
FLOOD_ITEM_REC *rec = tmp->data;
|
||||||
|
|
||||||
next = tmp->next;
|
next = tmp->next;
|
||||||
if (*now-rec->first >= flood_timecheck) {
|
/* remove old time entries for current rec item */
|
||||||
|
for (times = rec->msgtimes; times != NULL; times = tnext) {
|
||||||
|
tnext = times->next;
|
||||||
|
if (*now-*((time_t *) times->data) >= flood_timecheck) {
|
||||||
|
rec->msgtimes = g_slist_remove(rec->msgtimes, times->data);
|
||||||
|
g_free(times->data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* if no more time entries remove rec item */
|
||||||
|
if (rec->msgtimes == NULL) {
|
||||||
flood->items = g_slist_remove(flood->items, rec);
|
flood->items = g_slist_remove(flood->items, rec);
|
||||||
g_free(rec->target);
|
g_free(rec->target);
|
||||||
g_free(rec);
|
g_free(rec);
|
||||||
@ -119,6 +127,8 @@ static void flood_hash_destroy(const char *key, FLOOD_REC *flood)
|
|||||||
while (flood->items != NULL) {
|
while (flood->items != NULL) {
|
||||||
FLOOD_ITEM_REC *rec = flood->items->data;
|
FLOOD_ITEM_REC *rec = flood->items->data;
|
||||||
|
|
||||||
|
g_slist_foreach(rec->msgtimes, (GFunc) g_free, NULL);
|
||||||
|
g_slist_free(rec->msgtimes);
|
||||||
g_free(rec->target);
|
g_free(rec->target);
|
||||||
g_free(rec);
|
g_free(rec);
|
||||||
|
|
||||||
@ -173,6 +183,7 @@ static void flood_newmsg(IRC_SERVER_REC *server, int level, const char *nick,
|
|||||||
MODULE_SERVER_REC *mserver;
|
MODULE_SERVER_REC *mserver;
|
||||||
FLOOD_REC *flood;
|
FLOOD_REC *flood;
|
||||||
FLOOD_ITEM_REC *rec;
|
FLOOD_ITEM_REC *rec;
|
||||||
|
time_t *ttime;
|
||||||
|
|
||||||
g_return_if_fail(server != NULL);
|
g_return_if_fail(server != NULL);
|
||||||
g_return_if_fail(nick != NULL);
|
g_return_if_fail(nick != NULL);
|
||||||
@ -182,9 +193,11 @@ static void flood_newmsg(IRC_SERVER_REC *server, int level, const char *nick,
|
|||||||
|
|
||||||
rec = flood == NULL ? NULL : flood_find(flood, level, target);
|
rec = flood == NULL ? NULL : flood_find(flood, level, target);
|
||||||
if (rec != NULL) {
|
if (rec != NULL) {
|
||||||
if (++rec->msgcount > flood_max_msgs) {
|
ttime = g_new(time_t, 1);
|
||||||
|
*ttime = time(NULL);
|
||||||
|
rec->msgtimes = g_slist_append(rec->msgtimes, ttime);
|
||||||
|
if (g_slist_length(rec->msgtimes) > flood_max_msgs) {
|
||||||
/* flooding! */
|
/* flooding! */
|
||||||
rec->first = 0;
|
|
||||||
signal_emit("flood", 5, server, nick, host,
|
signal_emit("flood", 5, server, nick, host,
|
||||||
GINT_TO_POINTER(rec->level), target);
|
GINT_TO_POINTER(rec->level), target);
|
||||||
}
|
}
|
||||||
@ -199,8 +212,10 @@ static void flood_newmsg(IRC_SERVER_REC *server, int level, const char *nick,
|
|||||||
|
|
||||||
rec = g_new0(FLOOD_ITEM_REC, 1);
|
rec = g_new0(FLOOD_ITEM_REC, 1);
|
||||||
rec->level = level;
|
rec->level = level;
|
||||||
rec->first = time(NULL);
|
rec->msgtimes = NULL;
|
||||||
rec->msgcount = 1;
|
ttime = g_new(time_t, 1);
|
||||||
|
*ttime = time(NULL);
|
||||||
|
rec->msgtimes = g_slist_append(rec->msgtimes, ttime);
|
||||||
rec->target = g_strdup(target);
|
rec->target = g_strdup(target);
|
||||||
|
|
||||||
flood->items = g_slist_append(flood->items, rec);
|
flood->items = g_slist_append(flood->items, rec);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user