3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-23 19:22:40 +01:00

Fix chanop command execution, kick ban evaders

This commit is contained in:
Pragmatic Software 2014-04-19 10:38:16 +00:00
parent b642460d84
commit 8cd59b25da
3 changed files with 20 additions and 9 deletions

View File

@ -54,6 +54,7 @@ sub initialize {
$self->{ENTER_ABUSE_MAX_LINES} = 4;
$self->{ENTER_ABUSE_MAX_OFFENSES} = 3;
$self->{ENTER_ABUSE_MAX_SECONDS} = 20;
$self->load_message_history;
$self->{channels} = {}; # per-channel statistics, e.g. for optimized tracking of last spoken nick, etc
@ -305,7 +306,7 @@ sub check_flood {
my %msg = %{ @{ $self->message_history->{$account}->{channels}->{$channel}{messages} }[$length - 2] };
my %last = %{ @{ $self->message_history->{$account}->{channels}->{$channel}{messages} }[$length - 1] };
if($last{timestamp} - $msg{timestamp} <= 10) {
if($last{timestamp} - $msg{timestamp} <= $self->{ENTER_ABUSE_MAX_SECONDS}) {
if(++$self->message_history->{$account}->{channels}->{$channel}{enter_abuse} >= $self->{ENTER_ABUSE_MAX_LINES} - 1) {
$self->message_history->{$account}->{channels}->{$channel}{enter_abuse} = $self->{ENTER_ABUSE_MAX_LINES} / 2 - 1;
if(++$self->message_history->{$account}->{channels}->{$channel}{enter_abuses} >= $self->{ENTER_ABUSE_MAX_OFFENSES}) {
@ -315,14 +316,19 @@ sub check_flood {
$ban_length = duration($ban_length);
$self->{pbot}->logger->log("$nick $channel enter abuse offense " . $self->message_history->{$account}->{channels}->{$channel}{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.");
} else {
$self->{pbot}->logger->log("$nick $channel enter abuses counter incremented to " . $self->message_history->{$account}->{channels}->{$channel}{enter_abuses} . "\n");
}
} else {
$self->{pbot}->logger->log("$nick $channel enter abuse counter incremented to " . $self->message_history->{$account}->{channels}->{$channel}{enter_abuse} . "\n");
}
} else {
# $self->{pbot}->logger->log("$nick $channel more than 10 seconds since last message, enter abuse counter reset\n");
$self->message_history->{$account}->{channels}->{$channel}{enter_abuse} = 0;
$self->{pbot}->logger->log("$nick $channel more than $self->{ENTER_ABUSE_MAX_SECONDS} seconds since last message, enter abuse counter reset\n");
$self->message_history->{$account}->{channels}->{$channel}{enter_abuse} = 0;
}
} else {
$self->{channels}->{$channel}->{last_spoken_nick} = $nick;
$self->{pbot}->logger->log("$nick $channel enter abuse counter reset\n") if defined $self->message_history->{$account}->{channels}->{$channel}{enter_abuse} and $self->message_history->{$account}->{channels}->{$channel}{enter_abuse} > 0;
$self->message_history->{$account}->{channels}->{$channel}{enter_abuse} = 0;
}
}
@ -694,6 +700,8 @@ sub check_bans {
foreach my $baninfo (@$bans) {
$self->{pbot}->logger->log("anti-flood: [check-bans] $mask evaded $baninfo->{banmask} banned in $baninfo->{channel} by $baninfo->{owner}, banning $banmask\n");
my ($bannick) = $banmask =~ m/^([^!]+)/;
$self->{pbot}->chanops->add_op_command($baninfo->{channel}, "kick $bannick $baninfo->{channel} Ban evasion");
$self->{pbot}->chanops->ban_user_timed($banmask, $baninfo->{channel}, 60 * 60 * 12);
$self->message_history->{$mask}->{channels}->{$channel}{validated} = 0;
return;

View File

@ -12,7 +12,6 @@ use vars qw($VERSION);
$VERSION = $PBot::PBot::VERSION;
use Time::HiRes qw(gettimeofday);
use PBot::HashObject;
sub new {
if(ref($_[1]) eq 'HASH') {
@ -61,12 +60,17 @@ sub lose_ops {
$self->{pbot}->conn->privmsg("chanserv", "op $channel -" . $self->{pbot}->botnick);
}
sub add_op_command {
my ($self, $channel, $command) = @_;
push @{ $self->{op_commands}->{$channel} }, $command;
}
sub perform_op_commands {
my $self = shift;
my $channel = shift;
$self->{pbot}->logger->log("Performing op commands...\n");
foreach my $command (@{ $self->{op_commands}->{$channel} }) {
while(my $command = shift @{ $self->{op_commands}->{$channel} }) {
if($command =~ /^mode (.*?) (.*)/i) {
$self->{pbot}->conn->mode($1, $2);
$self->{pbot}->logger->log(" executing mode $1 $2\n");
@ -74,7 +78,6 @@ sub perform_op_commands {
$self->{pbot}->conn->kick($1, $2, $3) unless $1 =~ /\Q$self->{pbot}->botnick\E/i;
$self->{pbot}->logger->log(" executing kick on $1 $2 $3\n");
}
shift(@{ $self->{op_commands}->{$channel} });
}
$self->{pbot}->logger->log("Done.\n");
}
@ -83,7 +86,7 @@ sub ban_user {
my $self = shift;
my ($mask, $channel) = @_;
unshift @{ $self->{op_commands}->{$channel} }, "mode $channel +b $mask";
$self->add_op_command($channel, "mode $channel +b $mask");
$self->gain_ops($channel);
}
@ -95,7 +98,7 @@ sub unban_user {
$self->{unban_timeout}->hash->{$channel}->{$mask}{timeout} = gettimeofday + 7200; # try again in 2 hours if unban doesn't immediately succeed
$self->{unban_timeout}->save;
}
unshift @{ $self->{op_commands}->{$channel} }, "mode $channel -b $mask";
$self->add_op_command($channel, "mode $channel -b $mask");
$self->gain_ops($channel);
}

View File

@ -13,7 +13,7 @@ use warnings;
# These are set automatically by the build/commit script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 547,
BUILD_REVISION => 548,
BUILD_DATE => "2014-04-19",
};