3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-24 11:42:35 +01:00

Correct bug from refactoring AntiFlood.pm previously; no longer crashes on pruning message history

This commit is contained in:
Pragmatic Software 2010-06-21 11:04:07 +00:00
parent f9ab0c7e77
commit 38e7de9f41
2 changed files with 13 additions and 22 deletions

View File

@ -87,24 +87,16 @@ sub add_message {
# PART or QUIT # PART or QUIT
# check QUIT message for netsplits, and decrement joinwatch if found # check QUIT message for netsplits, and decrement joinwatch if found
if($text =~ /^QUIT .*\.net .*\.split/) { if($text =~ /^QUIT .*\.net .*\.split/) {
foreach my $ch (keys %{ $self->message_history->{$account} }) { ${ $self->message_history }{$account}{$channel}{join_watch}--;
next if $ch eq 'hostmask'; # TODO: move channels into {channel} subkey ${ $self->message_history }{$account}{$channel}{join_watch} = 0 if ${ $self->message_history }{$account}{$channel}{join_watch} < 0;
next if $ch !~ /^#/; $self->{pbot}->logger->log("$account $channel joinwatch adjusted: ${ $self->message_history }{$account}{$channel}{join_watch}\n");
${ $self->message_history }{$account}{$ch}{join_watch}--;
${ $self->message_history }{$account}{$ch}{join_watch} = 0 if ${ $self->message_history }{$account}{$ch}{join_watch} < 0;
$self->{pbot}->logger->log("$account $ch joinwatch adjusted: ${ $self->message_history }{$account}{$ch}{join_watch}\n");
}
$self->message_history->{$account}{$channel}{messages}->[$length - 1]{mode} = $self->{FLOOD_IGNORE}; $self->message_history->{$account}{$channel}{messages}->[$length - 1]{mode} = $self->{FLOOD_IGNORE};
} }
# check QUIT message for Ping timeout # check QUIT message for Ping timeout
elsif($text =~ /^QUIT Ping timeout/) { elsif($text =~ /^QUIT Ping timeout/) {
# deal with ping timeouts agressively # deal with ping timeouts agressively
foreach my $ch (keys %{ $self->message_history->{$account} }) { ${ $self->message_history }{$account}{$channel}{join_watch}++;
next if $ch eq 'hostmask'; # TODO: move channels into {channel} subkey $self->{pbot}->logger->log("$account $channel joinwatch adjusted: ${ $self->message_history }{$account}{$channel}{join_watch}\n");
next if $ch !~ /^#/;
${ $self->message_history }{$account}{$ch}{join_watch}++;
$self->{pbot}->logger->log("$account $ch joinwatch adjusted: ${ $self->message_history }{$account}{$ch}{join_watch}\n");
}
} else { } else {
# some other type of QUIT or PART # some other type of QUIT or PART
$self->message_history->{$account}{$channel}{messages}->[$length - 1]{mode} = $self->{FLOOD_IGNORE}; $self->message_history->{$account}{$channel}{messages}->[$length - 1]{mode} = $self->{FLOOD_IGNORE};
@ -147,13 +139,6 @@ sub check_flood {
$account = $nick; $account = $nick;
} }
if(not exists ${ $self->message_history }{$account}{$channel}) {
#$self->{pbot}->logger->log("adding new channel for existing nick\n");
${ $self->message_history }{$account}{$channel}{offenses} = 0;
${ $self->message_history }{$account}{$channel}{join_watch} = 0;
${ $self->message_history }{$account}{$channel}{messages} = [];
}
# handle QUIT events # handle QUIT events
# (these events come from $channel nick!user@host, not a specific channel or nick, # (these events come from $channel nick!user@host, not a specific channel or nick,
# so they need to be dispatched to all channels the bot exists on) # so they need to be dispatched to all channels the bot exists on)
@ -177,6 +162,13 @@ sub check_flood {
return; return;
} }
if(not exists ${ $self->message_history }{$account}{$channel}) {
#$self->{pbot}->logger->log("adding new channel for existing nick\n");
${ $self->message_history }{$account}{$channel}{offenses} = 0;
${ $self->message_history }{$account}{$channel}{join_watch} = 0;
${ $self->message_history }{$account}{$channel}{messages} = [];
}
my $length = $self->add_message($account, $channel, $text, $mode); my $length = $self->add_message($account, $channel, $text, $mode);
return if not defined $length; return if not defined $length;
@ -204,7 +196,6 @@ sub check_flood {
last if ++$count >= 4; last if ++$count >= 4;
} }
$i = 0 if $i < 0; $i = 0 if $i < 0;
print "using $i\n";
%msg = %{ @{ ${ $self->message_history }{$account}{$channel}{messages} }[$i] }; %msg = %{ @{ ${ $self->message_history }{$account}{$channel}{messages} }[$i] };
} }

View File

@ -13,7 +13,7 @@ use warnings;
# These are set automatically by the build/commit script # These are set automatically by the build/commit script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 188, BUILD_REVISION => 189,
BUILD_DATE => "2010-06-21", BUILD_DATE => "2010-06-21",
}; };