From 38e7de9f41f53881ec7c8d2787edf9e7e3169785 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 21 Jun 2010 11:04:07 +0000 Subject: [PATCH] Correct bug from refactoring AntiFlood.pm previously; no longer crashes on pruning message history --- PBot/AntiFlood.pm | 33 ++++++++++++--------------------- PBot/VERSION.pm | 2 +- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/PBot/AntiFlood.pm b/PBot/AntiFlood.pm index a2261d10..af7c1099 100644 --- a/PBot/AntiFlood.pm +++ b/PBot/AntiFlood.pm @@ -87,24 +87,16 @@ sub add_message { # PART or QUIT # check QUIT message for netsplits, and decrement joinwatch if found if($text =~ /^QUIT .*\.net .*\.split/) { - foreach my $ch (keys %{ $self->message_history->{$account} }) { - next if $ch eq 'hostmask'; # TODO: move channels into {channel} subkey - next if $ch !~ /^#/; - ${ $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}{join_watch}--; + ${ $self->message_history }{$account}{$channel}{join_watch} = 0 if ${ $self->message_history }{$account}{$channel}{join_watch} < 0; + $self->{pbot}->logger->log("$account $channel joinwatch adjusted: ${ $self->message_history }{$account}{$channel}{join_watch}\n"); $self->message_history->{$account}{$channel}{messages}->[$length - 1]{mode} = $self->{FLOOD_IGNORE}; } # check QUIT message for Ping timeout elsif($text =~ /^QUIT Ping timeout/) { # deal with ping timeouts agressively - foreach my $ch (keys %{ $self->message_history->{$account} }) { - next if $ch eq 'hostmask'; # TODO: move channels into {channel} subkey - 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"); - } + ${ $self->message_history }{$account}{$channel}{join_watch}++; + $self->{pbot}->logger->log("$account $channel joinwatch adjusted: ${ $self->message_history }{$account}{$channel}{join_watch}\n"); } else { # some other type of QUIT or PART $self->message_history->{$account}{$channel}{messages}->[$length - 1]{mode} = $self->{FLOOD_IGNORE}; @@ -147,13 +139,6 @@ sub check_flood { $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 # (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) @@ -177,6 +162,13 @@ sub check_flood { 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); return if not defined $length; @@ -204,7 +196,6 @@ sub check_flood { last if ++$count >= 4; } $i = 0 if $i < 0; - print "using $i\n"; %msg = %{ @{ ${ $self->message_history }{$account}{$channel}{messages} }[$i] }; } diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index a0051817..d90aa43e 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,7 +13,7 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 188, + BUILD_REVISION => 189, BUILD_DATE => "2010-06-21", };