3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-19 10:29:30 +01:00

Users: Fix issue with exact-match hostmasks

This commit is contained in:
Pragmatic Software 2020-04-24 23:27:06 -07:00
parent 599dab7ef6
commit 3f2158cab2

View File

@ -16,7 +16,6 @@ use feature 'unicode_strings';
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{users} = PBot::HashObject->new(name => 'Users', filename => $conf{filename}, pbot => $conf{pbot}); $self->{users} = PBot::HashObject->new(name => 'Users', filename => $conf{filename}, pbot => $conf{pbot});
$self->load;
$self->{pbot}->{commands}->register(sub { $self->logincmd(@_) }, "login", 0); $self->{pbot}->{commands}->register(sub { $self->logincmd(@_) }, "login", 0);
$self->{pbot}->{commands}->register(sub { $self->logoutcmd(@_) }, "logout", 0); $self->{pbot}->{commands}->register(sub { $self->logoutcmd(@_) }, "logout", 0);
@ -43,7 +42,7 @@ sub initialize {
$self->{user_index} = {}; $self->{user_index} = {};
$self->{user_cache} = {}; $self->{user_cache} = {};
$self->rebuild_user_index; $self->load;
} }
sub on_join { sub on_join {
@ -138,6 +137,7 @@ sub load {
my $self = shift; my $self = shift;
$self->{users}->load; $self->{users}->load;
$self->rebuild_user_index;
my $i = 0; my $i = 0;
foreach my $name (sort $self->{users}->get_keys) { foreach my $name (sort $self->{users}->get_keys) {
@ -228,8 +228,6 @@ sub find_user_account {
foreach my $search_channel (@search_channels) { foreach my $search_channel (@search_channels) {
if (exists $self->{user_index}->{$search_channel}) { if (exists $self->{user_index}->{$search_channel}) {
foreach my $mask (keys %{$self->{user_index}->{$search_channel}}) { foreach my $mask (keys %{$self->{user_index}->{$search_channel}}) {
if ($mask =~ m/[*?]/) {
# contains * or ? so it's converted to a regex
my $mask_quoted = quotemeta $mask; my $mask_quoted = quotemeta $mask;
$mask_quoted =~ s/\\\*/.*?/g; $mask_quoted =~ s/\\\*/.*?/g;
$mask_quoted =~ s/\\\?/./g; $mask_quoted =~ s/\\\?/./g;
@ -239,7 +237,6 @@ sub find_user_account {
} }
} }
} }
}
return (undef, $hostmask); return (undef, $hostmask);
} }
@ -628,7 +625,7 @@ sub idcmd {
my ($u, $name) = $self->find_user($from, $hostmask, 1); my ($u, $name) = $self->find_user($from, $hostmask, 1);
my $result = "$nick ($hostmask): user id: $message_account; "; my $result = "$target ($hostmask): user id: $message_account; ";
if ($message_account != $ancestor_id) { if ($message_account != $ancestor_id) {
$result .= "parent user id: $ancestor_id; "; $result .= "parent user id: $ancestor_id; ";