diff --git a/PBot/AntiFlood.pm b/PBot/AntiFlood.pm index 0c59f11a..2d5dd5e9 100644 --- a/PBot/AntiFlood.pm +++ b/PBot/AntiFlood.pm @@ -168,10 +168,12 @@ sub check_flood { ${ $self->message_history }{$account}{$channel}{offenses}++; my $timeout = (2 ** (($self->message_history->{$account}{$channel}{offenses} + 6) < 10 ? ${ $self->message_history }{$account}{$channel}{offenses} + 6 : 10)); + + my $banmask = address_to_mask($host); + + $self->{pbot}->chanops->quiet_user_timed("*!$user\@$banmask\$##fix_your_connection", $channel, $timeout * 60 * 60); - $self->{pbot}->chanops->quiet_user_timed("*!$user\@$host\$##fix_your_connection", $channel, $timeout * 60 * 60); - - $self->{pbot}->logger->log("$nick!$user\@$host banned for $timeout hours due to join flooding (offense #${ $self->message_history }{$account}{$channel}{offenses}).\n"); + $self->{pbot}->logger->log("$nick!$user\@$banmask banned for $timeout hours due to join flooding (offense #${ $self->message_history }{$account}{$channel}{offenses}).\n"); $timeout = "several" if($timeout > 8); @@ -252,7 +254,9 @@ sub unbanme { return "/msg $nick Usage: unbanme "; } - my $mask = "*!$user\@$host\$##fix_your_connection"; + my $banmask = address_to_mask($host); + + my $mask = "*!$user\@$banmask\$##fix_your_connection"; if(not exists $self->{pbot}->{chanops}->{quieted_masks}->{$mask}) { return "/msg $nick There is no temporary ban set for $mask in channel $channel."; @@ -284,6 +288,26 @@ sub unbanme { return "/msg $nick You have been unbanned from $channel."; } +sub address_to_mask { + my $address = shift; + my $banmask; + + if($address =~ m/^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/) { + my ($a, $b, $c, $d) = ($1, $2, $3, $4); + given($a) { + when($_ <= 127) { $banmask = "$a.*"; } + when($_ <= 191) { $banmask = "$a.$b.*"; } + default { $banmask = "$a.$b.$c.*"; } + } + } elsif($address =~ m/[^.]+\.([^.]+\.[^.]+)$/) { + $banmask = "*.$1"; + } else { + $banmask = $address; + } + + return $banmask; +} + # based on Guy Malachi's code sub generate_random_string { my $length_of_randomstring = shift; diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 5218711f..bb29dfc0 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 => 171, + BUILD_REVISION => 172, BUILD_DATE => "2010-06-17", }; diff --git a/config/channels b/config/channels index 0511fb28..324c3df7 100644 --- a/config/channels +++ b/config/channels @@ -2,4 +2,5 @@ channel: #pbot2 chanop: 1 enabled: 1 +owner: pragma_ -