change touser login in gen_DXProt
[spider.git] / perl / Thingy / Ping.pm
index 02fc5cef51bea6caf1176bce93e4a98d4729d08a..902347dc30ec3a8f176bf9c30189d56407acc7b0 100644 (file)
@@ -22,10 +22,12 @@ use Spot;
 use Time::HiRes qw(gettimeofday tv_interval);
 
 
-use vars qw(@ISA %ping);
+use vars qw(@ISA %ping $ping_ttl);
 @ISA = qw(Thingy);
 
 my $id;
+$ping_ttl = 300;                               # default ping ttl
+
 
 sub gen_Aranea
 {
@@ -53,10 +55,11 @@ sub gen_DXProt
                # {user} as well as a true user and also it may not
                # have originated here.
 
-               my $from = $thing->{o};
+               my $from = $thing->{o} if $thing->{out};
            $from ||= $thing->{user} if Route::Node::get($thing->{user});
                $from ||= $thing->{origin};
-               my $to = $thing->{touser} if Route::Node::get($thing->{touser});
+               my $to = $thing->{o} unless $thing->{out};
+               $to ||= $thing->{touser} unless Route::User::get($thing->{touser});
                $to ||= $thing->{group};
 
                
@@ -70,18 +73,25 @@ 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;
 }
 
+# called with the dxchan, line and the split out arguments
 sub from_DXProt
 {
-       my $thing = ref $_[0] ? shift : $_[0]->SUPER::new();
-       
-       while (@_) {
-               my $k = shift;
-               $thing->{$k} = shift;
-       }
+       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->{group} ne $main::mycall;
        return $thing;
 }
 
@@ -125,17 +135,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);
        }
 }