]> git.vpit.fr Git - perl/scripts/xchat.git/blobdiff - clones.pl
Stop adding wrong clones when there was a nick change or a kick before the first...
[perl/scripts/xchat.git] / clones.pl
index a8b01fb24b868f6c3f29bd9502c0ea5d69bfd5fd..421bbd40116d471ec8687358794db64dc0c3b70e 100755 (executable)
--- a/clones.pl
+++ b/clones.pl
@@ -45,8 +45,7 @@ sub clone_list_str {
 
 sub host {
  my $userhost = lc $_[0];
- my ($host) = $userhost =~ /@([^@]+)$/;
- return $host || $userhost;
+ return $userhost =~ /@([^@]+)$/ ? $1 : $userhost;
 }
 
 sub add {
@@ -179,10 +178,13 @@ hook_server 'KICK', sub {
  my $chan = lc $_[0][2];
  if (nickcmp get_info('nick'), $nick) {
   my $userinfo = user_info $nick;
-  return EAT_NONE unless $userinfo;
   my $userhost = $userinfo->{host};
-  my $clones = remove $nick, host($userhost), $serv, $chan;
-  print $ph clone_leave_str $userhost, $nick, $clones if $clones > 0;
+  if (defined $userhost and length $userhost) {
+   # If this isn't true, the kick happened before the first WHO response was
+   # received and the nick isn't in the database yet.
+   my $clones = remove $nick, host($userhost), $serv, $chan;
+   print $ph clone_leave_str $userhost, $nick, $clones if $clones > 0;
+  }
  } else {
   flush $serv, $chan;
  }
@@ -237,8 +239,16 @@ hook_print 'Disconnected', sub {
 sub nick_cb {
  my ($old, $new) = @{$_[0]};
  my $userinfo = user_info $new;
- replace $old => $new, host($userinfo->{host}),
-                       get_info('server'), lc get_info('channel') if $userinfo;
+ $userinfo    = user_info $old unless defined $userinfo;
+ my $userhost = $userinfo->{host};
+ if (defined $userhost and length $userhost) {
+  # If the host isn't defined, the first WHO response hasn't been received yet,
+  # so the old nick isn't even in our database.
+  # Otherwise, the new nick would be added right now, and the old one would be
+  # when the WHO responses arrives (which may still refer to the old nick).
+  replace $old => $new, host($userhost),
+                        get_info('server'), lc get_info('channel');
+ }
  return EAT_NONE;
 }
 
@@ -256,12 +266,14 @@ hook_command 'CLSCAN', sub {
  help_text => 'Scan for clones in the current channel'
 };
 
-$ph = new Xchat::XPI name   => 'Clones scanner',
-                     tag    => 'Clones',
-                     desc   => 'Automatic & on-demand clones scanner',
-                     author => 'Vincent Pit (VPIT)',
-                     email  => 'perl@profvince.com',
-                     url    => 'http://www.profvince.com',
-                     unload => sub { undef %users };
+$ph = Xchat::XPI->new(
+ name   => 'Clones scanner',
+ tag    => 'Clones',
+ desc   => 'Automatic & on-demand clones scanner',
+ author => 'Vincent Pit (VPIT)',
+ email  => 'perl@profvince.com',
+ url    => 'http://www.profvince.com',
+ unload => sub { undef %users },
+);
 
 1;