mirror of https://github.com/pragma-/pbot.git
Improve handling of nick-change flood
This commit is contained in:
parent
9ec50d8f5d
commit
7970018777
|
@ -196,7 +196,6 @@ sub check_flood {
|
||||||
$mask = "$newnick!$user\@$host";
|
$mask = "$newnick!$user\@$host";
|
||||||
$account = $self->{pbot}->{messagehistory}->get_message_account($newnick, $user, $host);
|
$account = $self->{pbot}->{messagehistory}->get_message_account($newnick, $user, $host);
|
||||||
$nick = $newnick;
|
$nick = $newnick;
|
||||||
|
|
||||||
$self->{nickflood}->{$account}->{changes}++;
|
$self->{nickflood}->{$account}->{changes}++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -218,218 +217,210 @@ sub check_flood {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $channels;
|
||||||
|
|
||||||
if($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) {
|
if($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) {
|
||||||
my @channels = $self->{pbot}->{messagehistory}->{database}->get_channels($account);
|
$channels = $self->{pbot}->{nicklist}->get_channels($nick);
|
||||||
return if not @channels;
|
|
||||||
$channel = undef;
|
|
||||||
foreach my $chan (@channels) {
|
|
||||||
if($chan =~ m/^#/) {
|
|
||||||
$channel = $chan;
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return if not defined $channel;
|
|
||||||
} else {
|
} else {
|
||||||
$self->check_join_watch($account, $channel, $text, $mode);
|
$self->check_join_watch($account, $channel, $text, $mode);
|
||||||
|
push @$channels, $channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
# do not do flood processing for bot messages
|
# do not do flood processing for bot messages
|
||||||
if($nick eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) {
|
if($nick eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) {
|
||||||
$self->{channels}->{$channel}->{last_spoken_nick} = $nick;
|
foreach my $channel (@$channels) {
|
||||||
|
$self->{channels}->{$channel}->{last_spoken_nick} = $nick;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# do not do flood processing if channel is not in bot's channel list or bot is not set as chanop for the channel
|
foreach my $channel (@$channels) {
|
||||||
return if ($channel =~ /^#/) and (not exists $self->{pbot}->{channels}->{channels}->hash->{$channel} or $self->{pbot}->{channels}->{channels}->hash->{$channel}{chanop} == 0);
|
# do not do flood processing if channel is not in bot's channel list or bot is not set as chanop for the channel
|
||||||
|
next if ($channel =~ /^#/) and (not exists $self->{pbot}->{channels}->{channels}->hash->{$channel} or $self->{pbot}->{channels}->{channels}->hash->{$channel}{chanop} == 0);
|
||||||
|
|
||||||
if($channel =~ /^#/ and $mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) {
|
if($channel =~ /^#/ and $mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) {
|
||||||
# remove validation on PART or KICK so we check for ban-evasion when user returns at a later time
|
# remove validation on PART or KICK so we check for ban-evasion when user returns at a later time
|
||||||
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'validated');
|
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'validated');
|
||||||
if($channel_data->{validated} & $self->{NICKSERV_VALIDATED}) {
|
if($channel_data->{validated} & $self->{NICKSERV_VALIDATED}) {
|
||||||
$channel_data->{validated} &= ~$self->{NICKSERV_VALIDATED};
|
$channel_data->{validated} &= ~$self->{NICKSERV_VALIDATED};
|
||||||
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
|
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
|
||||||
|
}
|
||||||
|
next;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if($max_messages > $self->{pbot}->{registry}->get_value('messagehistory', 'max_messages')) {
|
if($max_messages > $self->{pbot}->{registry}->get_value('messagehistory', 'max_messages')) {
|
||||||
$self->{pbot}->{logger}->log("Warning: max_messages greater than max_messages limit; truncating.\n");
|
$self->{pbot}->{logger}->log("Warning: max_messages greater than max_messages limit; truncating.\n");
|
||||||
$max_messages = $self->{pbot}->{registry}->get_value('messagehistory', 'max_messages');
|
$max_messages = $self->{pbot}->{registry}->get_value('messagehistory', 'max_messages');
|
||||||
}
|
|
||||||
|
|
||||||
# check for ban evasion if channel begins with # (not private message) and hasn't yet been validated against ban evasion
|
|
||||||
if($channel =~ m/^#/ and not $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'validated')->{'validated'} & $self->{NICKSERV_VALIDATED}) {
|
|
||||||
if($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) {
|
|
||||||
# don't check for evasion on PART/KICK
|
|
||||||
} elsif ($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) {
|
|
||||||
$self->{pbot}->{conn}->whois($nick);
|
|
||||||
} else {
|
|
||||||
$self->{pbot}->{conn}->whois($nick);
|
|
||||||
$self->check_bans($account, $mask, $channel);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
# do not do flood enforcement for this event if bot is lagging
|
# check for ban evasion if channel begins with # (not private message) and hasn't yet been validated against ban evasion
|
||||||
if($self->{pbot}->{lagchecker}->lagging) {
|
if($channel =~ m/^#/ and not $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'validated')->{'validated'} & $self->{NICKSERV_VALIDATED}) {
|
||||||
$self->{pbot}->{logger}->log("Disregarding enforcement of anti-flood due to lag: " . $self->{pbot}->{lagchecker}->lagstring . "\n");
|
if($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) {
|
||||||
return;
|
# don't check for evasion on PART/KICK
|
||||||
}
|
} elsif ($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) {
|
||||||
|
$self->{pbot}->{conn}->whois($nick);
|
||||||
|
} else {
|
||||||
|
$self->{pbot}->{conn}->whois($nick);
|
||||||
|
$self->check_bans($account, $mask, $channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# do not do flood enforcement for logged in bot admins
|
# do not do flood enforcement for this event if bot is lagging
|
||||||
return if $self->{pbot}->{admins}->loggedin($channel, "$nick!$user\@$host");
|
if($self->{pbot}->{lagchecker}->lagging) {
|
||||||
|
$self->{pbot}->{logger}->log("Disregarding enforcement of anti-flood due to lag: " . $self->{pbot}->{lagchecker}->lagstring . "\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
# check for enter abuse
|
# do not do flood enforcement for logged in bot admins
|
||||||
if($mode == $self->{pbot}->{messagehistory}->{MSG_CHAT} and $channel =~ m/^#/) {
|
next if $self->{pbot}->{admins}->loggedin($channel, "$nick!$user\@$host");
|
||||||
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'enter_abuse', 'enter_abuses', 'offenses');
|
|
||||||
my $other_offenses = delete $channel_data->{offenses};
|
|
||||||
|
|
||||||
if(defined $self->{channels}->{$channel}->{last_spoken_nick} and $nick eq $self->{channels}->{$channel}->{last_spoken_nick}) {
|
# check for enter abuse
|
||||||
my $messages = $self->{pbot}->{messagehistory}->{database}->get_recent_messages($account, $channel, 2, $self->{pbot}->{messagehistory}->{MSG_CHAT});
|
if($mode == $self->{pbot}->{messagehistory}->{MSG_CHAT} and $channel =~ m/^#/) {
|
||||||
|
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'enter_abuse', 'enter_abuses', 'offenses');
|
||||||
|
my $other_offenses = delete $channel_data->{offenses};
|
||||||
|
|
||||||
my $enter_abuse_threshold = $self->{pbot}->{registry}->get_value('antiflood', 'enter_abuse_threshold');
|
if(defined $self->{channels}->{$channel}->{last_spoken_nick} and $nick eq $self->{channels}->{$channel}->{last_spoken_nick}) {
|
||||||
my $enter_abuse_time_threshold = $self->{pbot}->{registry}->get_value('antiflood', 'enter_abuse_time_threshold');
|
my $messages = $self->{pbot}->{messagehistory}->{database}->get_recent_messages($account, $channel, 2, $self->{pbot}->{messagehistory}->{MSG_CHAT});
|
||||||
my $enter_abuse_max_offenses = $self->{pbot}->{registry}->get_value('antiflood', 'enter_abuse_max_offenses');
|
|
||||||
|
|
||||||
if($messages->[1]->{timestamp} - $messages->[0]->{timestamp} <= $enter_abuse_time_threshold) {
|
my $enter_abuse_threshold = $self->{pbot}->{registry}->get_value('antiflood', 'enter_abuse_threshold');
|
||||||
if(++$channel_data->{enter_abuse} >= $enter_abuse_threshold - 1) {
|
my $enter_abuse_time_threshold = $self->{pbot}->{registry}->get_value('antiflood', 'enter_abuse_time_threshold');
|
||||||
$channel_data->{enter_abuse} = $enter_abuse_threshold / 2 - 1;
|
my $enter_abuse_max_offenses = $self->{pbot}->{registry}->get_value('antiflood', 'enter_abuse_max_offenses');
|
||||||
if(++$channel_data->{enter_abuses} >= $enter_abuse_max_offenses) {
|
|
||||||
if($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) {
|
if($messages->[1]->{timestamp} - $messages->[0]->{timestamp} <= $enter_abuse_time_threshold) {
|
||||||
my $offenses = $channel_data->{enter_abuses} - $enter_abuse_max_offenses + 1 + $other_offenses;
|
if(++$channel_data->{enter_abuse} >= $enter_abuse_threshold - 1) {
|
||||||
my $ban_length = $self->{pbot}->{registry}->get_array_value('antiflood', 'enter_abuse_punishment', $offenses - 1);
|
$channel_data->{enter_abuse} = $enter_abuse_threshold / 2 - 1;
|
||||||
$self->{pbot}->{chanops}->ban_user_timed("*!$user\@$host", $channel, $ban_length);
|
if(++$channel_data->{enter_abuses} >= $enter_abuse_max_offenses) {
|
||||||
$ban_length = duration($ban_length);
|
if($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) {
|
||||||
$self->{pbot}->{logger}->log("$nick $channel enter abuse offense " . $channel_data->{enter_abuses} . " earned $ban_length ban\n");
|
my $offenses = $channel_data->{enter_abuses} - $enter_abuse_max_offenses + 1 + $other_offenses;
|
||||||
$self->{pbot}->{conn}->privmsg($nick, "You have been muted due to abusing the enter key. Please do not split your sentences over multiple messages. You will be allowed to speak again in $ban_length.");
|
my $ban_length = $self->{pbot}->{registry}->get_array_value('antiflood', 'enter_abuse_punishment', $offenses - 1);
|
||||||
$channel_data->{last_offense} = gettimeofday;
|
$self->{pbot}->{chanops}->ban_user_timed("*!$user\@$host", $channel, $ban_length);
|
||||||
|
$ban_length = duration($ban_length);
|
||||||
|
$self->{pbot}->{logger}->log("$nick $channel enter abuse offense " . $channel_data->{enter_abuses} . " earned $ban_length ban\n");
|
||||||
|
$self->{pbot}->{conn}->privmsg($nick, "You have been muted due to abusing the enter key. Please do not split your sentences over multiple messages. You will be allowed to speak again in $ban_length.");
|
||||||
|
$channel_data->{last_offense} = gettimeofday;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#$self->{pbot}->{logger}->log("$nick $channel enter abuses counter incremented to " . $channel_data->{enter_abuses} . "\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#$self->{pbot}->{logger}->log("$nick $channel enter abuses counter incremented to " . $channel_data->{enter_abuses} . "\n");
|
#$self->{pbot}->{logger}->log("$nick $channel enter abuse counter incremented to " . $channel_data->{enter_abuse} . "\n");
|
||||||
}
|
}
|
||||||
|
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
|
||||||
} else {
|
} else {
|
||||||
#$self->{pbot}->{logger}->log("$nick $channel enter abuse counter incremented to " . $channel_data->{enter_abuse} . "\n");
|
if($channel_data->{enter_abuse} > 0) {
|
||||||
|
#$self->{pbot}->{logger}->log("$nick $channel more than $enter_abuse_time_threshold seconds since last message, enter abuse counter reset\n");
|
||||||
|
$channel_data->{enter_abuse} = 0;
|
||||||
|
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
|
|
||||||
} else {
|
} else {
|
||||||
|
$self->{channels}->{$channel}->{last_spoken_nick} = $nick;
|
||||||
if($channel_data->{enter_abuse} > 0) {
|
if($channel_data->{enter_abuse} > 0) {
|
||||||
#$self->{pbot}->{logger}->log("$nick $channel more than $enter_abuse_time_threshold seconds since last message, enter abuse counter reset\n");
|
#$self->{pbot}->{logger}->log("$nick $channel enter abuse counter reset\n");
|
||||||
$channel_data->{enter_abuse} = 0;
|
$channel_data->{enter_abuse} = 0;
|
||||||
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
|
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
$self->{channels}->{$channel}->{last_spoken_nick} = $nick;
|
|
||||||
if($channel_data->{enter_abuse} > 0) {
|
# check for chat/join/private message flooding
|
||||||
#$self->{pbot}->{logger}->log("$nick $channel enter abuse counter reset\n");
|
if($max_messages > 0 and $self->{pbot}->{messagehistory}->{database}->get_max_messages($account, $channel) >= $max_messages) {
|
||||||
$channel_data->{enter_abuse} = 0;
|
my $msg;
|
||||||
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
|
if($mode == $self->{pbot}->{messagehistory}->{MSG_CHAT}) {
|
||||||
|
$msg = $self->{pbot}->{messagehistory}->{database}->recall_message_by_count($account, $channel, $max_messages - 1)
|
||||||
|
}
|
||||||
|
elsif($mode == $self->{pbot}->{messagehistory}->{MSG_JOIN}) {
|
||||||
|
my $joins = $self->{pbot}->{messagehistory}->{database}->get_recent_messages($account, $channel, $max_messages, $self->{pbot}->{messagehistory}->{MSG_JOIN});
|
||||||
|
$msg = $joins->[0];
|
||||||
|
}
|
||||||
|
elsif($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) {
|
||||||
|
my $nickchanges = $self->{pbot}->{messagehistory}->{database}->get_recent_messages($account, $channel, $max_messages, $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE});
|
||||||
|
$msg = $nickchanges->[0];
|
||||||
|
}
|
||||||
|
elsif($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) {
|
||||||
|
# no flood checks to be done for departure events
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$self->{pbot}->{logger}->log("Unknown flood mode [$mode] ... aborting flood enforcement.\n");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# check for chat/join/private message flooding
|
my $last = $self->{pbot}->{messagehistory}->{database}->recall_message_by_count($account, $channel, 0);
|
||||||
if($max_messages > 0 and $self->{pbot}->{messagehistory}->{database}->get_max_messages($account, $channel) >= $max_messages) {
|
|
||||||
my $msg;
|
|
||||||
if($mode == $self->{pbot}->{messagehistory}->{MSG_CHAT}) {
|
|
||||||
$msg = $self->{pbot}->{messagehistory}->{database}->recall_message_by_count($account, $channel, $max_messages - 1)
|
|
||||||
}
|
|
||||||
elsif($mode == $self->{pbot}->{messagehistory}->{MSG_JOIN}) {
|
|
||||||
my $joins = $self->{pbot}->{messagehistory}->{database}->get_recent_messages($account, $channel, $max_messages, $self->{pbot}->{messagehistory}->{MSG_JOIN});
|
|
||||||
$msg = $joins->[0];
|
|
||||||
}
|
|
||||||
elsif($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) {
|
|
||||||
my $nickchanges = $self->{pbot}->{messagehistory}->{database}->get_recent_messages($account, $channel, $max_messages, $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE});
|
|
||||||
$msg = $nickchanges->[0];
|
|
||||||
}
|
|
||||||
elsif($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) {
|
|
||||||
# no flood checks to be done for departure events
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$self->{pbot}->{logger}->log("Unknown flood mode [$mode] ... aborting flood enforcement.\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $last = $self->{pbot}->{messagehistory}->{database}->recall_message_by_count($account, $channel, 0);
|
#$self->{pbot}->{logger}->log(" msg: [$msg->{timestamp}] $msg->{msg}\n");
|
||||||
|
#$self->{pbot}->{logger}->log("last: [$last->{timestamp}] $last->{msg}\n");
|
||||||
|
#$self->{pbot}->{logger}->log("Comparing message timestamps $last->{timestamp} - $msg->{timestamp} = " . ($last->{timestamp} - $msg->{timestamp}) . " against max_time $max_time\n");
|
||||||
|
|
||||||
#$self->{pbot}->{logger}->log(" msg: [$msg->{timestamp}] $msg->{msg}\n");
|
if ($last->{timestamp} - $msg->{timestamp} <= $max_time) {
|
||||||
#$self->{pbot}->{logger}->log("last: [$last->{timestamp}] $last->{msg}\n");
|
if($mode == $self->{pbot}->{messagehistory}->{MSG_JOIN}) {
|
||||||
#$self->{pbot}->{logger}->log("Comparing message timestamps $last->{timestamp} - $msg->{timestamp} = " . ($last->{timestamp} - $msg->{timestamp}) . " against max_time $max_time\n");
|
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'offenses', 'last_offense', 'join_watch');
|
||||||
|
#$self->{pbot}->{logger}->log("$account offenses $channel_data->{offenses}, join watch $channel_data->{join_watch}, max messages $max_messages\n");
|
||||||
|
if($channel_data->{join_watch} >= $max_messages) {
|
||||||
|
$channel_data->{offenses}++;
|
||||||
|
$channel_data->{last_offense} = gettimeofday;
|
||||||
|
|
||||||
if ($last->{timestamp} - $msg->{timestamp} <= $max_time) {
|
if($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) {
|
||||||
if($mode == $self->{pbot}->{messagehistory}->{MSG_JOIN}) {
|
my $timeout = $self->{pbot}->{registry}->get_array_value('antiflood', 'join_flood_punishment', $channel_data->{offenses} - 1);
|
||||||
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'offenses', 'last_offense', 'join_watch');
|
my $duration = duration($timeout);
|
||||||
#$self->{pbot}->{logger}->log("$account offenses $channel_data->{offenses}, join watch $channel_data->{join_watch}, max messages $max_messages\n");
|
my $banmask = address_to_mask($host);
|
||||||
if($channel_data->{join_watch} >= $max_messages) {
|
|
||||||
$channel_data->{offenses}++;
|
|
||||||
$channel_data->{last_offense} = gettimeofday;
|
|
||||||
|
|
||||||
if($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) {
|
$self->{pbot}->{chanops}->ban_user_timed("*!$user\@$banmask\$##stop_join_flood", $channel, $timeout);
|
||||||
my $timeout = $self->{pbot}->{registry}->get_array_value('antiflood', 'join_flood_punishment', $channel_data->{offenses} - 1);
|
$self->{pbot}->{logger}->log("$nick!$user\@$banmask banned for $duration due to join flooding (offense #" . $channel_data->{offenses} . ").\n");
|
||||||
my $duration = duration($timeout);
|
$self->{pbot}->{conn}->privmsg($nick, "You have been banned from $channel due to join flooding. If your connection issues have been fixed, or this was an accident, you may request an unban at any time by responding to this message with: unbanme $channel, otherwise you will be automatically unbanned in $duration.");
|
||||||
my $banmask = address_to_mask($host);
|
}
|
||||||
|
$channel_data->{join_watch} = $max_messages - 2; # give them a chance to rejoin
|
||||||
$self->{pbot}->{chanops}->ban_user_timed("*!$user\@$banmask\$##stop_join_flood", $channel, $timeout);
|
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
|
||||||
$self->{pbot}->{logger}->log("$nick!$user\@$banmask banned for $duration due to join flooding (offense #" . $channel_data->{offenses} . ").\n");
|
|
||||||
$self->{pbot}->{conn}->privmsg($nick, "You have been banned from $channel due to join flooding. If your connection issues have been fixed, or this was an accident, you may request an unban at any time by responding to this message with: unbanme $channel, otherwise you will be automatically unbanned in $duration.");
|
|
||||||
}
|
}
|
||||||
$channel_data->{join_watch} = $max_messages - 2; # give them a chance to rejoin
|
} elsif($mode == $self->{pbot}->{messagehistory}->{MSG_CHAT}) {
|
||||||
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
|
if($channel =~ /^#/) { #channel flood (opposed to private message or otherwise)
|
||||||
}
|
# don't increment offenses again if already banned
|
||||||
} elsif($mode == $self->{pbot}->{messagehistory}->{MSG_CHAT}) {
|
next if $self->{pbot}->{chanops}->{unban_timeout}->find_index($channel, "*!$user\@$host");
|
||||||
if($channel =~ /^#/) { #channel flood (opposed to private message or otherwise)
|
|
||||||
# don't increment offenses again if already banned
|
|
||||||
return if $self->{pbot}->{chanops}->{unban_timeout}->find_index($channel, "*!$user\@$host");
|
|
||||||
|
|
||||||
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'offenses', 'last_offense');
|
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'offenses', 'last_offense');
|
||||||
$channel_data->{offenses}++;
|
$channel_data->{offenses}++;
|
||||||
$channel_data->{last_offense} = gettimeofday;
|
$channel_data->{last_offense} = gettimeofday;
|
||||||
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
|
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
|
||||||
|
|
||||||
|
if($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) {
|
||||||
|
my $length = $self->{pbot}->{registry}->get_array_value('antiflood', 'chat_flood_punishment', $channel_data->{offenses} - 1);
|
||||||
|
|
||||||
|
$self->{pbot}->{chanops}->ban_user_timed("*!$user\@$host", $channel, $length);
|
||||||
|
$length = duration($length);
|
||||||
|
$self->{pbot}->{logger}->log("$nick $channel flood offense " . $channel_data->{offenses} . " earned $length ban\n");
|
||||||
|
$self->{pbot}->{conn}->privmsg($nick, "You have been muted due to flooding. Please use a web paste service such as http://codepad.org for lengthy pastes. You will be allowed to speak again in $length.");
|
||||||
|
}
|
||||||
|
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
|
||||||
|
}
|
||||||
|
else { # private message flood
|
||||||
|
next if exists ${ $self->{pbot}->{ignorelist}->{ignore_list} }{"$nick!$user\@$host"}{$channel};
|
||||||
|
|
||||||
|
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'offenses', 'last_offense');
|
||||||
|
$channel_data->{offenses}++;
|
||||||
|
$channel_data->{last_offense} = gettimeofday;
|
||||||
|
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
|
||||||
|
|
||||||
if($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) {
|
|
||||||
my $length = $self->{pbot}->{registry}->get_array_value('antiflood', 'chat_flood_punishment', $channel_data->{offenses} - 1);
|
my $length = $self->{pbot}->{registry}->get_array_value('antiflood', 'chat_flood_punishment', $channel_data->{offenses} - 1);
|
||||||
|
|
||||||
|
$self->{pbot}->{ignorelist}->{commands}->ignore_user("", "floodcontrol", "", "", "$nick!$user\@$host $channel $length");
|
||||||
|
$length = duration($length);
|
||||||
|
$self->{pbot}->{logger}->log("$nick msg flood offense " . $channel_data->{offenses} . " earned $length ignore\n");
|
||||||
|
$self->{pbot}->{conn}->privmsg($nick, "You have used too many commands in too short a time period, you have been ignored for $length.");
|
||||||
|
}
|
||||||
|
} elsif($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE} and $self->{nickflood}->{$account}->{changes} >= $max_messages) {
|
||||||
|
($nick) = $text =~ m/NICKCHANGE (.*)/;
|
||||||
|
|
||||||
|
$self->{nickflood}->{$account}->{offenses}++;
|
||||||
|
$self->{nickflood}->{$account}->{changes} = $max_messages - 2; # allow 1 more change (to go back to original nick)
|
||||||
|
$self->{nickflood}->{$account}->{timestamp} = gettimeofday;
|
||||||
|
|
||||||
|
if($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) {
|
||||||
|
my $length = $self->{pbot}->{registry}->get_array_value('antiflood', 'nick_flood_punishment', $self->{nickflood}->{$account}->{offenses} - 1);
|
||||||
$self->{pbot}->{chanops}->ban_user_timed("*!$user\@$host", $channel, $length);
|
$self->{pbot}->{chanops}->ban_user_timed("*!$user\@$host", $channel, $length);
|
||||||
$length = duration($length);
|
$length = duration($length);
|
||||||
$self->{pbot}->{logger}->log("$nick $channel flood offense " . $channel_data->{offenses} . " earned $length ban\n");
|
$self->{pbot}->{logger}->log("$nick nickchange flood offense " . $self->{nickflood}->{$account}->{offenses} . " earned $length ban\n");
|
||||||
$self->{pbot}->{conn}->privmsg($nick, "You have been muted due to flooding. Please use a web paste service such as http://codepad.org for lengthy pastes. You will be allowed to speak again in $length.");
|
$self->{pbot}->{conn}->privmsg($nick, "You have been temporarily banned due to nick-change flooding. You will be unbanned in $length.");
|
||||||
}
|
}
|
||||||
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
|
|
||||||
}
|
|
||||||
else { # private message flood
|
|
||||||
return if exists ${ $self->{pbot}->{ignorelist}->{ignore_list} }{"$nick!$user\@$host"}{$channel};
|
|
||||||
|
|
||||||
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'offenses', 'last_offense');
|
|
||||||
$channel_data->{offenses}++;
|
|
||||||
$channel_data->{last_offense} = gettimeofday;
|
|
||||||
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
|
|
||||||
|
|
||||||
my $length = $self->{pbot}->{registry}->get_array_value('antiflood', 'chat_flood_punishment', $channel_data->{offenses} - 1);
|
|
||||||
|
|
||||||
$self->{pbot}->{ignorelist}->{commands}->ignore_user("", "floodcontrol", "", "", "$nick!$user\@$host $channel $length");
|
|
||||||
$length = duration($length);
|
|
||||||
$self->{pbot}->{logger}->log("$nick msg flood offense " . $channel_data->{offenses} . " earned $length ignore\n");
|
|
||||||
$self->{pbot}->{conn}->privmsg($nick, "You have used too many commands in too short a time period, you have been ignored for $length.");
|
|
||||||
}
|
|
||||||
} elsif($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE} and $self->{nickflood}->{$account}->{changes} >= $max_messages) {
|
|
||||||
($nick) = $text =~ m/NICKCHANGE (.*)/;
|
|
||||||
|
|
||||||
$self->{nickflood}->{$account}->{offenses}++;
|
|
||||||
$self->{nickflood}->{$account}->{changes} = $max_messages - 2; # allow 1 more change (to go back to original nick)
|
|
||||||
$self->{nickflood}->{$account}->{timestamp} = gettimeofday;
|
|
||||||
|
|
||||||
if($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) {
|
|
||||||
my $length = $self->{pbot}->{registry}->get_array_value('antiflood', 'nick_flood_punishment', $self->{nickflood}->{$account}->{offenses} - 1);
|
|
||||||
|
|
||||||
my $channels = $self->{pbot}->{nicklist}->get_channels($oldnick);
|
|
||||||
foreach my $chan (@$channels) {
|
|
||||||
next if $chan !~ /^#/;
|
|
||||||
next if not exists $self->{pbot}->{channels}->{channels}->hash->{$chan} or $self->{pbot}->{channels}->{channels}->hash->{$chan}{chanop} == 0;
|
|
||||||
$self->{pbot}->{chanops}->ban_user_timed("*!$user\@$host", $chan, $length);
|
|
||||||
}
|
|
||||||
|
|
||||||
$length = duration($length);
|
|
||||||
$self->{pbot}->{logger}->log("$nick nickchange flood offense " . $self->{nickflood}->{$account}->{offenses} . " earned $length ban\n");
|
|
||||||
$self->{pbot}->{conn}->privmsg($nick, "You have been temporarily banned due to nick-change flooding. You will be unbanned in $length.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -762,13 +753,13 @@ sub adjust_offenses {
|
||||||
my $last_offense = delete $channel_data->{last_offense};
|
my $last_offense = delete $channel_data->{last_offense};
|
||||||
if(gettimeofday - $last_offense >= 60 * 60 * 24) {
|
if(gettimeofday - $last_offense >= 60 * 60 * 24) {
|
||||||
$channel_data->{enter_abuses}--;
|
$channel_data->{enter_abuses}--;
|
||||||
$self->{pbot}->{logger}->log("[adjust-offenses] [$id][$channel] decreasing enter abuse offenses to $channel_data->{enter_abuses}\n");
|
#$self->{pbot}->{logger}->log("[adjust-offenses] [$id][$channel] decreasing enter abuse offenses to $channel_data->{enter_abuses}\n");
|
||||||
$self->{pbot}->{messagehistory}->{database}->update_channel_data($id, $channel, $channel_data);
|
$self->{pbot}->{messagehistory}->{database}->update_channel_data($id, $channel, $channel_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $account (keys %{ $self->{nickflood} }) {
|
foreach my $account (keys %{ $self->{nickflood} }) {
|
||||||
if($self->{nickflood}->{$account}->{offenses} and gettimeofday - $self->{nickflood}->{$account}->{timestamp} >= 60 * 60 * 48) {
|
if($self->{nickflood}->{$account}->{offenses} and gettimeofday - $self->{nickflood}->{$account}->{timestamp} >= 60 * 60 * 24) {
|
||||||
$self->{nickflood}->{$account}->{offenses}--;
|
$self->{nickflood}->{$account}->{offenses}--;
|
||||||
|
|
||||||
if($self->{nickflood}->{$account}->{offenses} == 0) {
|
if($self->{nickflood}->{$account}->{offenses} == 0) {
|
||||||
|
|
|
@ -308,7 +308,7 @@ sub on_nickchange {
|
||||||
|
|
||||||
my $message_account = $self->{pbot}->{messagehistory}->{database}->get_message_account($nick, $user, $host);
|
my $message_account = $self->{pbot}->{messagehistory}->{database}->get_message_account($nick, $user, $host);
|
||||||
$self->{pbot}->{messagehistory}->{database}->devalidate_all_channels($message_account, $self->{pbot}->{antiflood}->{NEEDS_CHECKBAN});
|
$self->{pbot}->{messagehistory}->{database}->devalidate_all_channels($message_account, $self->{pbot}->{antiflood}->{NEEDS_CHECKBAN});
|
||||||
my $channels = $self->{pbot}->{nicklist}->get_channels($nick);
|
my $channels = $self->{pbot}->{nicklist}->get_channels($newnick);
|
||||||
foreach my $channel (@$channels) {
|
foreach my $channel (@$channels) {
|
||||||
next if $channel !~ m/^#/;
|
next if $channel !~ m/^#/;
|
||||||
$self->{pbot}->{messagehistory}->add_message($message_account, "$nick!$user\@$host", $channel, "NICKCHANGE $newnick", $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE});
|
$self->{pbot}->{messagehistory}->add_message($message_account, "$nick!$user\@$host", $channel, "NICKCHANGE $newnick", $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE});
|
||||||
|
|
Loading…
Reference in New Issue