1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

Fixed some flood detection, ignoring and autoignoring bugs.

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@339 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-06-14 17:52:03 +00:00 committed by cras
parent 6d77cdc8b7
commit 47fd84c5bc
5 changed files with 41 additions and 11 deletions

View File

@ -155,7 +155,7 @@ static void cmd_ignore(const char *data)
args = "pattern channels"; args = "pattern channels";
params = cmd_get_params(data, 5 | PARAM_FLAG_MULTIARGS | PARAM_FLAG_GETREST, params = cmd_get_params(data, 5 | PARAM_FLAG_MULTIARGS | PARAM_FLAG_GETREST,
&args, &patternarg, &chanarg, &mask, &levels); &args, &patternarg, &chanarg, &mask, &levels);
if (levels == 0) cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); if (*levels == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
if (ischannel(*mask)) { if (ischannel(*mask)) {
chanarg = mask; chanarg = mask;

View File

@ -29,7 +29,7 @@ FORMAT_REC fecommon_irc_flood_formats[] =
{ NULL, "Autoignore", 0 }, { NULL, "Autoignore", 0 },
{ "autoignore", "Flood detected from %_$0%_, autoignoring for %_$1%_ minutes", 2, { 0, 1 } }, { "autoignore", "Flood detected from %_$0%_, autoignoring for %_$1%_ minutes", 2, { 0, 1 } },
{ "autounignore", "Unignoring %_$0", 1, { 0 } }, { "autounignore", "Removed autoignore from %_$0", 1, { 0 } },
{ NULL, NULL, 0 } { NULL, NULL, 0 }
}; };

View File

@ -248,11 +248,14 @@ void ignore_add_rec(IGNORE_REC *rec)
{ {
ignores = g_slist_append(ignores, rec); ignores = g_slist_append(ignores, rec);
ignore_set_config(rec); ignore_set_config(rec);
signal_emit("ignore created", 1, rec);
} }
static void ignore_destroy(IGNORE_REC *rec) static void ignore_destroy(IGNORE_REC *rec)
{ {
ignores = g_slist_remove(ignores, rec); ignores = g_slist_remove(ignores, rec);
signal_emit("ignore destroyed", 1, rec);
if (rec->channels != NULL) g_strfreev(rec->channels); if (rec->channels != NULL) g_strfreev(rec->channels);
g_free_not_null(rec->mask); g_free_not_null(rec->mask);
@ -274,6 +277,8 @@ void ignore_update_rec(IGNORE_REC *rec)
ignores = g_slist_append(ignores, rec); ignores = g_slist_append(ignores, rec);
ignore_set_config(rec); ignore_set_config(rec);
signal_emit("ignore changed", 1, rec);
} }
} }

View File

@ -230,6 +230,32 @@ static void sig_flood(IRC_SERVER_REC *server, const char *nick, const char *host
autoignore_add(server, nick, level); autoignore_add(server, nick, level);
} }
static void autoignore_remove_level(const char *nick, int level)
{
AUTOIGNORE_REC *rec;
GSList *tmp;
for (tmp = servers; tmp != NULL; tmp = tmp->next) {
IRC_SERVER_REC *server = tmp->data;
rec = autoignore_find(server, nick);
if (rec != NULL && (rec->level & level)) {
rec->level &= ~level;
if (rec->level == 0) autoignore_remove_rec(server, rec);
}
}
}
static void sig_ignore_destroyed(IGNORE_REC *ignore)
{
autoignore_remove_level(ignore->mask, MSGLEVEL_ALL);
}
static void sig_ignore_changed(IGNORE_REC *ignore)
{
autoignore_remove_level(ignore->mask, ~ignore->level);
}
void autoignore_init(void) void autoignore_init(void)
{ {
settings_add_int("flood", "autoignore_time", 300); settings_add_int("flood", "autoignore_time", 300);
@ -240,6 +266,8 @@ void autoignore_init(void)
signal_add("server connected", (SIGNAL_FUNC) autoignore_init_server); signal_add("server connected", (SIGNAL_FUNC) autoignore_init_server);
signal_add("server disconnected", (SIGNAL_FUNC) autoignore_deinit_server); signal_add("server disconnected", (SIGNAL_FUNC) autoignore_deinit_server);
signal_add("flood", (SIGNAL_FUNC) sig_flood); signal_add("flood", (SIGNAL_FUNC) sig_flood);
signal_add("ignore destroyed", (SIGNAL_FUNC) sig_ignore_destroyed);
signal_add("ignore changed", (SIGNAL_FUNC) sig_ignore_changed);
} }
void autoignore_deinit(void) void autoignore_deinit(void)
@ -249,4 +277,6 @@ void autoignore_deinit(void)
signal_remove("server connected", (SIGNAL_FUNC) autoignore_init_server); signal_remove("server connected", (SIGNAL_FUNC) autoignore_init_server);
signal_remove("server disconnected", (SIGNAL_FUNC) autoignore_deinit_server); signal_remove("server disconnected", (SIGNAL_FUNC) autoignore_deinit_server);
signal_remove("flood", (SIGNAL_FUNC) sig_flood); signal_remove("flood", (SIGNAL_FUNC) sig_flood);
signal_remove("ignore destroyed", (SIGNAL_FUNC) sig_ignore_destroyed);
signal_remove("ignore changed", (SIGNAL_FUNC) sig_ignore_changed);
} }

View File

@ -167,6 +167,7 @@ static void flood_newmsg(IRC_SERVER_REC *server, int level, const char *nick, co
if (rec != NULL) { if (rec != NULL) {
if (++rec->msgcount > flood_max_msgs) { if (++rec->msgcount > flood_max_msgs) {
/* flooding! */ /* flooding! */
rec->first = 0;
signal_emit("flood", 5, server, nick, host, GINT_TO_POINTER(rec->level), target); signal_emit("flood", 5, server, nick, host, GINT_TO_POINTER(rec->level), target);
} }
return; return;
@ -242,22 +243,16 @@ static void flood_ctcp(const char *data, IRC_SERVER_REC *server, const char *nic
static void read_settings(void) static void read_settings(void)
{ {
int time;
flood_timecheck = settings_get_int("flood_timecheck"); flood_timecheck = settings_get_int("flood_timecheck");
flood_max_msgs = settings_get_int("flood_max_msgs"); flood_max_msgs = settings_get_int("flood_max_msgs");
time = flood_timecheck > 500 ? 500 :
(flood_timecheck > 0 && flood_timecheck < 100) ? 100 :
flood_timecheck;
if (flood_tag != -1) { if (flood_tag != -1) {
g_source_remove(flood_tag); g_source_remove(flood_tag);
flood_tag = -1; flood_tag = -1;
} }
if (time > 0 && flood_max_msgs > 0) { if (time > 0 && flood_max_msgs > 0) {
flood_tag = g_timeout_add(time, (GSourceFunc) flood_timeout, NULL); flood_tag = g_timeout_add(500, (GSourceFunc) flood_timeout, NULL);
signal_add("event privmsg", (SIGNAL_FUNC) flood_privmsg); signal_add("event privmsg", (SIGNAL_FUNC) flood_privmsg);
signal_add("event notice", (SIGNAL_FUNC) flood_notice); signal_add("event notice", (SIGNAL_FUNC) flood_notice);
signal_add("ctcp msg", (SIGNAL_FUNC) flood_ctcp); signal_add("ctcp msg", (SIGNAL_FUNC) flood_ctcp);
@ -267,8 +262,8 @@ static void read_settings(void)
void irc_flood_init(void) void irc_flood_init(void)
{ {
settings_add_int("flood", "flood_timecheck", 8000); settings_add_int("flood", "flood_timecheck", 8);
settings_add_int("flood", "flood_max_msgs", 5); settings_add_int("flood", "flood_max_msgs", 4);
flood_tag = -1; flood_tag = -1;
read_settings(); read_settings();