Improve handling of Nickserv accounts in check-bans and unbanme

This commit is contained in:
Pragmatic Software 2015-03-27 04:08:47 -07:00
parent 377cf99d35
commit 7f87730de8
2 changed files with 43 additions and 8 deletions

View File

@ -447,6 +447,8 @@ sub unbanme {
my $message_account = $self->{pbot}->{messagehistory}->{database}->get_message_account($nick, $user, $host);
my @nickserv_accounts = $self->{pbot}->{messagehistory}->{database}->get_nickserv_accounts($message_account);
push @nickserv_accounts, undef;
foreach my $nickserv_account (@nickserv_accounts) {
my $baninfos = $self->{pbot}->{bantracker}->get_baninfo("$nick!$user\@$host", $channel, $nickserv_account);
@ -554,17 +556,22 @@ sub check_bans {
my $hostmasks = $self->{pbot}->{messagehistory}->{database}->get_hostmasks_for_channel($channel);
foreach my $nickserv_account (@nickserv_accounts) {
my $nickserv_hostmasks = $self->{pbot}->{messagehistory}->{database}->get_hostmasks_for_nickserv($nickserv_account);
push @$hostmasks, @$nickserv_hostmasks;
}
my ($do_not_validate, $bans);
foreach my $hostmask (@$hostmasks) {
my $check_ban = 0;
# check if nickserv accounts match
foreach my $nickserv_account (@nickserv_accounts) {
if($hostmask->{nickserv} eq $nickserv_account) {
$self->{pbot}->{logger}->log("anti-flood: [check-bans] nickserv account for $hostmask->{hostmask} matches $nickserv_account\n") if $debug_checkban;
$check_ban = 1;
goto CHECKBAN;
}
if (exists $hostmask->{nickserv}) {
$self->{pbot}->{logger}->log("anti-flood: [check-bans] nickserv account for $hostmask->{hostmask} matches $hostmask->{nickserv}\n") if $debug_checkban;
$check_ban = 1;
goto CHECKBAN;
} else {
$hostmask->{nickserv} = undef;
}
# check if hosts match
@ -597,7 +604,7 @@ sub check_bans {
next;
}
$self->{pbot}->{logger}->log("anti-flood: [check-bans] checking for bans in $channel on $hostmask->{hostmask} using $hostmask->{nickserv}\n") if $debug_checkban >= 4;
$self->{pbot}->{logger}->log("anti-flood: [check-bans] checking for bans in $channel on $hostmask->{hostmask} using account " . (defined $hostmask->{nickserv} ? $hostmask->{nickserv} : "[undefined]") . "\n") if $debug_checkban >= 4;
my $baninfos = $self->{pbot}->{bantracker}->get_baninfo($hostmask->{hostmask}, $channel, $hostmask->{nickserv});
if(defined $baninfos) {

View File

@ -386,11 +386,25 @@ sub update_hostmask_data {
$self->{pbot}->{logger}->log($@) if $@;
}
sub get_nickserv_accounts_for_hostmask {
my ($self, $hostmask) = @_;
my $nickservs = eval {
my $sth = $self->{dbh}->prepare('SELECT nickserv FROM Hostmasks, Nickserv WHERE nickserv.id = hostmasks.id AND hostmasks.hostmask = ?');
$sth->bind_param(1, $hostmask);
$sth->execute();
return $sth->fetchall_arrayref();
};
$self->{pbot}->{logger}->log($@) if $@;
return map {$_->[0]} @$nickservs;
}
sub get_hostmasks_for_channel {
my ($self, $channel) = @_;
my $hostmasks = eval {
my $sth = $self->{dbh}->prepare('SELECT hostmasks.id, hostmask, nickserv FROM Hostmasks, Nickserv, Channels WHERE nickserv.id = hostmasks.id AND channels.id = hostmasks.id AND channel = ?');
my $sth = $self->{dbh}->prepare('SELECT hostmasks.id, hostmask FROM Hostmasks, Channels WHERE channels.id = hostmasks.id AND channel = ?');
$sth->bind_param(1, $channel);
$sth->execute();
return $sth->fetchall_arrayref({});
@ -400,6 +414,20 @@ sub get_hostmasks_for_channel {
return $hostmasks;
}
sub get_hostmasks_for_nickserv {
my ($self, $nickserv) = @_;
my $hostmasks = eval {
my $sth = $self->{dbh}->prepare('SELECT hostmasks.id, hostmask, nickserv FROM Hostmasks, Nickserv WHERE nickserv.id = hostmasks.id AND nickserv = ?');
$sth->bind_param(1, $nickserv);
$sth->execute();
return $sth->fetchall_arrayref({});
};
$self->{pbot}->{logger}->log($@) if $@;
return $hostmasks;
}
sub add_message {
my ($self, $id, $mask, $channel, $message) = @_;