fix the nasty feature in perl 5.6 with my $ref = $foo if $bar for
[spider.git] / perl / Thingy / Ping.pm
index 60c68078452abdec6529be9c6d3094ce3f490f72..de295c556c939909dbe062793842867e9942ba2a 100644 (file)
@@ -55,13 +55,20 @@ sub gen_DXProt
                # {user} as well as a true user and also it may not
                # have originated here.
 
-               my $from = $thing->{o};
-           $from ||= $thing->{user} if Route::Node::get($thing->{user});
-               $from ||= $thing->{origin};
-               my $to = $thing->{touser} if Route::Node::get($thing->{touser});
-               $to ||= $thing->{group};
-
-               
+               my ($from, $to);
+               if ($thing->{out}) {
+                       $from = $thing->{o};
+                       $from ||= $thing->{user} unless Route::User::get($thing->{user});
+                       $from ||= $thing->{origin};
+                       $to = $thing->{touser} unless Route::User::get($thing->{touser});
+                       $to ||= $thing->{group};
+               } else {
+                       $from ||= $thing->{user} unless Route::User::get($thing->{user});
+                       $from ||= $thing->{origin};
+                       $to = $thing->{o};
+                       $to ||= $thing->{touser} unless Route::User::get($thing->{touser});
+                       $to ||= $thing->{group};
+               }
                $thing->{DXProt} = DXProt::pc51($to, $from, $thing->{out});
        }
        return $thing->{DXProt};
@@ -72,7 +79,9 @@ sub gen_DXCommandmode
        my $thing = shift;
        my $dxchan = shift;
        my $buf;
-
+       if ($dxchan->{call} eq $thing->{touser}) {
+               $buf = $dxchan->msg('pingi', ($thing->{user} || $thing->{origin}), $thing->{ft}, $thing->{fave});
+       }
        return $buf;
 }
 
@@ -82,12 +91,13 @@ sub from_DXProt
        my $thing = ref $_[0] ? shift : $_[0]->SUPER::new(origin=>$main::mycall);
        my $dxchan = shift;
        $thing->{DXProt} = shift;
+       shift;                                          # PC51
        $thing->{group} = shift;        # to call
        my $from = shift;
        $thing->{out} = shift;          # 1 = ping, 0 = pong;
        $thing->{user} = $dxchan->{call};
        $thing->{o} = $from unless $from eq $dxchan->{call};
-       $thing->remember if $thing->{out};
+       $thing->remember if $thing->{out} && $thing->{group} ne $main::mycall;
        return $thing;
 }
 
@@ -107,8 +117,9 @@ sub handle
                } else {
 
                        # it's a reply, look in the ping list for this one
-                       my $ref = $ping{$thing->{id}} if exists $thing->{id};
-                       $ref ||= find(($thing->{user}||$thing->{origin}), ($thing->{touser}||$thing->{group}));
+                       my $ref;
+                       $ref = $ping{$thing->{id}} if exists $thing->{id};
+                       $ref = find(($thing->{user}||$thing->{origin}), ($thing->{touser}||$thing->{group})) unless $ref;
                        if ($ref) {
                                my $t = tv_interval($ref->{t}, [ gettimeofday ]);
                                my $tochan = DXChannel::get($ref->{touser} || $ref->{group});
@@ -131,17 +142,14 @@ sub handle
                                        $tochan->{nopings} = $nopings; # pump up the timer
                                }
                                if (my $dxc = DXChannel::get($ref->{user} || $ref->{origin})) {
-                                       if ($dxc->is_user) {
-                                               my $s = sprintf "%.2f", $t; 
-                                               my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
-                                               $dxc->send($dxc->msg('pingi', ($ref->{touser} || $ref->{group}), $s, $ave))
-                                       } 
+                                       $thing->{ft} = sprintf "%.2f", $t;
+                                       $thing->{fave} = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
+                                       $thing->send($dxc);
                                }
                                delete $ping{$ref->{id}};
                        }
                }
        } else {
-               $thing->{route} = $thing->{o} if $thing->{o};
                $thing->broadcast($dxchan);
        }
 }