fix hexstamps
[spider.git] / perl / Route.pm
index 0e9b61395da39891f3bcf0a1957e7a6e8abdd87a..b6671154186afb71a943be119a739c16cf71c4eb 100644 (file)
@@ -37,7 +37,7 @@ use vars qw(%list %valid $filterdef);
                  cq => '0,CQ Zone',
                  state => '0,State',
                  city => '0,City',
-                 lastseen => 'Last Seen,atime',
+                 lastseen => '0,Last Seen,atime',
                 );
 
 $filterdef = bless ([
@@ -152,7 +152,8 @@ sub here
        my $r = shift;
        return $self ? 2 : 0 unless ref $self;
        return ($self->{flags} & 2) ? 1 : 0 unless defined $r;
-       $self->{flags} = (($self->{flags} & ~2) | ($r ? 2 : 0));
+       $self->{flags} &= ~2;
+       $self->{flags} |= $r ? 2 : 0;
        return $r ? 1 : 0;
 }
 
@@ -162,10 +163,51 @@ sub conf
        my $r = shift;
        return $self ? 1 : 0 unless ref $self;
        return ($self->{flags} & 1) ? 1 : 0 unless defined $r;
-       $self->{flags} = (($self->{flags} & ~1) | ($r ? 1 : 0));
+       $self->{flags} &= ~1;
+       $self->{flags} |= $r ? 1 : 0;
        return $r ? 1 : 0;
 }
 
+#
+# pc59 entity encoding and decoding
+#
+sub enc_pc59
+{
+       my $self = shift;
+       my $sort = shift || 'N';
+       my $out = "$sort$self->{flag}$self->{call}";
+       if ($self->{build}) {
+               $out .= "b$self->{build}";
+       } elsif ($self->{version}) {
+               $out .= "v$self->{version}"; 
+       }
+}
+
+sub dec_pc59
+{
+       my $node = shift;
+       my $s = ref($node) ? shift : $node;
+       $node = undef;
+       
+       my ($sort, $here, $call) = unpack "A A A*", $s;
+       return unless is_callsign($call);
+       return unless $here =~ /^[0123]$/;
+       return unless $sort =~ /^[NUE]$/;
+       if ($sort eq 'E' || $sort eq 'N') {
+               $node = Route::Node::get($call) || Route::Node->new($call);
+               if ($s =~ /b([\d\.])/) {
+                       $node->{build} = $1;
+               }
+               if ($s =~ /v([\d\.])/) {
+                       $node->{version} = $1;
+               }
+       } elsif ($sort eq 'U') {
+               $node = Route::User::get($call) || Route::User->new($call);
+       }
+       $node->flags = $here;
+       return $node;
+}
+
 # 
 # display routines
 #
@@ -199,8 +241,8 @@ sub config
                
                # recursion detector
                if ((DXChannel->get($self->{call}) && $level > 1) || grep $self->{call} eq $_, @$seen) {
-                       $line .= ' ...';
-                       push @out, $line;
+#                      $line .= ' ...';
+#                      push @out, $line;
                        return @out;
                }
                push @$seen, $self->{call};
@@ -269,20 +311,35 @@ sub get
        return Route::Node::get($call) || Route::User::get($call);
 }
 
+sub get_all
+{
+       return (Route::Node::get_all(), Route::User::get_all());
+}
+
 # find all the possible dxchannels which this object might be on
 sub alldxchan
 {
        my $self = shift;
-       my @dxchan;
-#      dbg("Trying node $self->{call}") if isdbg('routech');
 
        my $dxchan = DXChannel->get($self->{call});
-       push @dxchan, $dxchan if $dxchan;
+       if ($dxchan) {
+               dbg("alldxchan for $self->{call} = $dxchan->{call}") if isdbg('routelow');
+               return $dxchan if $dxchan;
+       }
+       
+       my @nodes;
+       if ($self->isa('Route::User')) {
+               push @nodes, map{Route::Node::get($_)} @{$self->{nodes}};
+       } elsif ($self->isa('Route::Node')) {
+               push @nodes, $self;
+       }
        
        # it isn't, build up a list of dxchannels and possible ping times 
        # for all the candidates.
-       unless (@dxchan) {
-               foreach my $p (@{$self->{dxchan}}) {
+       my @dxchan;
+       foreach my $nref (@nodes) {
+               next unless $nref;
+               foreach my $p (@{$nref->{dxchan}}) {
 #                      dbg("Trying dxchan $p") if isdbg('routech');
                        next if $p eq $main::mycall; # the root
                        my $dxchan = DXChannel->get($p);
@@ -296,7 +353,7 @@ sub alldxchan
                        }
                }
        }
-#      dbg('routech', "Got dxchan: " . join(',', (map{ $_->call } @dxchan)) );
+       dbg("alldxchan for $self->{call} = (" . join(',', @dxchan) . ")") if isdbg('routelow');
        return @dxchan;
 }
 
@@ -308,47 +365,12 @@ sub bestdxchan
        my $dxchan = DXChannel->get($self->call);
        return $dxchan if $dxchan;
        
-       my @dxchan = $self->alldxchan;
+       my @dxchan = sort { ($a->pingave || 9999999) <=> ($b->pingave || 9999999) } $self->alldxchan;
        return undef unless @dxchan;
        
-       # determine the minimum ping channel
-       my $minping = 99999999;
-       foreach my $dxc (@dxchan) {
-               my $p = $dxc->pingave;
-               if (defined $p  && $p < $minping) {
-                       $minping = $p;
-                       $dxchan = $dxc;
-               }
-       }
-       $dxchan = shift @dxchan unless $dxchan;
-       return $dxchan;
-}
-
-sub _adddxchan
-{
-       my $self = shift;
-    return $self->_addlist('dxchan', @_);
-}
-
-sub _deldxchan
-{
-       my $self = shift;
-    return $self->_dellist('dxchan', @_);
-}
-
-sub _addnode
-{
-       my $self = shift;
-    return $self->_addlist('nodes', @_);
+       return shift @dxchan;
 }
 
-sub _delnode
-{
-       my $self = shift;
-    return $self->_dellist('nodes', @_);
-}
-
-
 #
 # track destruction
 #