2000-04-26 04:03:38 -04:00
|
|
|
/*
|
|
|
|
autoignore.c : irssi
|
|
|
|
|
2001-03-03 18:27:07 -05:00
|
|
|
Copyright (C) 1999-2001 Timo Sirainen
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "modules.h"
|
|
|
|
#include "signals.h"
|
|
|
|
#include "commands.h"
|
|
|
|
#include "levels.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "settings.h"
|
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
#include "irc-servers.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "ignore.h"
|
|
|
|
|
2001-02-22 01:09:48 -05:00
|
|
|
void autoignore_update(IGNORE_REC *rec, int level)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-02-22 01:09:48 -05:00
|
|
|
rec->level |= level;
|
2001-03-03 18:27:07 -05:00
|
|
|
rec->unignore_time = time(NULL)+settings_get_int("autoignore_time");
|
2000-09-27 20:25:14 -04:00
|
|
|
|
2001-02-22 01:09:48 -05:00
|
|
|
ignore_update_rec(rec);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-02-22 01:09:48 -05:00
|
|
|
void autoignore_add(IRC_SERVER_REC *server, char *mask, int level)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-02-22 01:09:48 -05:00
|
|
|
IGNORE_REC *rec;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-02-22 01:09:48 -05:00
|
|
|
rec = g_new0(IGNORE_REC, 1);
|
2001-03-03 18:27:07 -05:00
|
|
|
|
|
|
|
rec->mask = g_strdup(mask);
|
2001-02-22 01:09:48 -05:00
|
|
|
rec->servertag = g_strdup(server->tag);
|
2000-04-26 04:03:38 -04:00
|
|
|
rec->level = level;
|
2001-03-03 18:27:07 -05:00
|
|
|
rec->unignore_time = time(NULL)+settings_get_int("autoignore_time");
|
|
|
|
|
2001-02-22 01:09:48 -05:00
|
|
|
ignore_add_rec(rec);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
static void sig_flood(IRC_SERVER_REC *server, const char *nick, const char *host, gpointer levelp)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-02-22 01:09:48 -05:00
|
|
|
IGNORE_REC *rec;
|
2001-03-03 18:27:07 -05:00
|
|
|
char *mask;
|
|
|
|
int level, check_level;
|
2001-02-22 01:09:48 -05:00
|
|
|
|
2000-10-01 12:17:12 -04:00
|
|
|
g_return_if_fail(IS_IRC_SERVER(server));
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
level = GPOINTER_TO_INT(levelp);
|
2001-02-22 05:52:01 -05:00
|
|
|
check_level = level2bits(settings_get_str("autoignore_level"));
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-03-03 18:27:07 -05:00
|
|
|
mask = g_strdup_printf("%s!%s", nick, host);
|
2001-02-22 01:09:48 -05:00
|
|
|
if (level & check_level) {
|
2001-03-03 18:27:07 -05:00
|
|
|
rec = ignore_find(server->tag, mask, NULL);
|
2001-02-22 01:09:48 -05:00
|
|
|
if (rec == NULL)
|
2001-03-03 18:27:07 -05:00
|
|
|
autoignore_add(server, mask, level);
|
2001-02-22 01:09:48 -05:00
|
|
|
else
|
|
|
|
autoignore_update(rec, level);
|
2000-06-14 13:52:03 -04:00
|
|
|
}
|
2001-03-03 18:27:07 -05:00
|
|
|
g_free(mask);
|
2000-06-14 13:52:03 -04:00
|
|
|
}
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
void autoignore_init(void)
|
|
|
|
{
|
|
|
|
settings_add_int("flood", "autoignore_time", 300);
|
2001-02-22 05:52:01 -05:00
|
|
|
settings_add_str("flood", "autoignore_level", "");
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-02-22 01:09:48 -05:00
|
|
|
signal_add("flood", (SIGNAL_FUNC) sig_flood);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void autoignore_deinit(void)
|
|
|
|
{
|
|
|
|
signal_remove("flood", (SIGNAL_FUNC) sig_flood);
|
|
|
|
}
|