]> git.vpit.fr Git - perl/scripts/xchat.git/blobdiff - clones.pl
For AID/AGHOST, skip contextes not found
[perl/scripts/xchat.git] / clones.pl
index 5e385959a4b390729152b24c436adf8e91ed7fe4..fded636bd38c8aee60a92426d5ddb911972026ab 100755 (executable)
--- a/clones.pl
+++ b/clones.pl
@@ -10,6 +10,7 @@ use Xchat qw<:all>;
 use lib get_info 'xchatdir';
 use Xchat::XPI;
 use Xchat::XPI::Events qw<delay>;
+use Xchat::XPI::Utils  qw<save_context local_context>;
 
 use constant {
  JOIN_DELAY => 1000,
@@ -168,11 +169,10 @@ hook_server '315', sub { # WHO end
 
  return EAT_NONE if $fetched{$serv}{$chan};
 
- my $oldctxt = get_context;
- set_context $chan, $serv or return EAT_NONE;
- fetch $serv, $chan;
- scan  $serv, $chan;
- set_context $oldctxt;
+ local_context $chan, $serv => sub {
+  fetch $serv, $chan;
+  scan  $serv, $chan;
+ };
 
  return EAT_NONE;
 };
@@ -186,20 +186,18 @@ hook_server 'JOIN', sub {
  my $chan = lc substr $_[0][2], 1; # starts with colon
 
  my $clones = add $nick, host($userhost), $serv, $chan;
- if ($clones > 0) {
-  my $oldctxt = get_context;
-  if (set_context $chan, $serv) {
-   print $ph clone_enter_str $userhost, $nick, $clones;
-   set_context $oldctxt;
-  } else {
-   delay JOIN_DELAY, sub {
-    my $oldctxt = get_context;
-    return unless set_context $chan, $serv;
+ return EAT_NONE unless $clones > 0;
+
+ local_context $chan, $serv => sub {
+  print $ph clone_enter_str $userhost, $nick, $clones;
+  1
+ } or do {
+  delay JOIN_DELAY, sub {
+   local_context $chan, $serv => sub {
     print $ph clone_enter_str $userhost, $nick, $clones;
-    set_context $oldctxt;
-   };
+   }
   }
- }
+ };
 
  return EAT_NONE;
 };
@@ -248,8 +246,8 @@ hook_server 'QUIT', sub {
                get_list 'channels';
 
  if (nickcmp get_info('nick'), $nick) {
-  my $oldctxt = get_context;
-  my $host    = host $userhost;
+  my $guard = save_context;
+  my $host  = host $userhost;
   for (@chans) {
    my $clones = remove $nick, $host, $serv, $_->[0];
    if ($clones > 0) {
@@ -257,7 +255,6 @@ hook_server 'QUIT', sub {
     print $ph clone_leave_str $userhost, $nick, $clones;
    }
   }
-  set_context $oldctxt;
  } else {
   flush $serv, $_->[0] for @chans;
  }
@@ -266,9 +263,9 @@ hook_server 'QUIT', sub {
 };
 
 hook_print 'Disconnected', sub {
- my %servers = map { $_->{server} => 1 }
-                grep { $_->{flags} & 9 and not($_->{flags} & 2) }
-                 get_list 'channels';
+ my %servers;
+ $servers{$_->{server}} = 1 for grep +($_->{flags} & 0b1011) == 0b1001,
+                                 get_list 'channels';
 
  delete @users{  grep !$servers{$_}, keys %users};
  delete @fetched{grep !$servers{$_}, keys %fetched};