fix talk and routing problems to mycall
[spider.git] / perl / DXProt.pm
index f72fe8903a37bbe5c1c17a201b99eb936e69b49c..5f3890a02e0ee751e6ad2f3971facb376835e1a1 100644 (file)
@@ -275,10 +275,8 @@ sub normal
        
 #      print join(',', @field), "\n";
                                                
-       # ignore any lines that don't start with PC
-       return if !$field[0] =~ /^PC/;
        
-       # process PC frames
+       # process PC frames, this will fail unless the frame starts PCnn
        my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
        return unless $pcno;
        return if $pcno < 10 || $pcno > 99;
@@ -318,7 +316,8 @@ sub normal
                        } else {
                                $call = $to = $field[2];
                        }
-                       $dxchan = DXChannel->get($call);
+                       $dxchan = DXChannel->get($main::myalias) if $call eq $main::mycall;
+                       $dxchan = DXChannel->get($call) unless $dxchan;
                        if ($dxchan && $dxchan->is_user) {
                                $field[3] =~ s/\%5E/^/g;
                                $dxchan->talk($field[1], $to, $via, $field[3]);
@@ -423,7 +422,7 @@ sub normal
                                        my $node;
                                        my $to = $user->homenode;
                                        my $last = $user->lastoper || 0;
-                                       if ($send_opernam && $main::systime > $last + $DXUser::lastoperinterval && $to && ($node = Route::Node::get($to)) ) {
+                                       if ($to ne $main::mycall && $send_opernam && $main::systime > $last + $DXUser::lastoperinterval && $to && ($node = Route::Node::get($to)) ) {
                                                my $cmd = "forward/opernam $spot[4]";
                                                # send the rcmd but we aren't interested in the replies...
                                                my $dxchan = $node->dxchan;
@@ -556,15 +555,20 @@ sub normal
                        for ($i = 2; $i < $#field; $i++) {
                                my ($call, $conf, $here) = $field[$i] =~ /^(\S+) (\S) (\d)/o;
                                next unless $call && $conf && defined $here && is_callsign($call);
+                               next if $call eq $main::mycall;
+                               
                                $conf = $conf eq '*';
 
                                my $r = Route::User::get($call);
                                my $flags = Route::here($here)|Route::conf($conf);
                                
-                               if ($r && $r->flags != $flags) {
-                                       $r->flags($flags);
-                                       push @rout, $r;
-                               } elsif (!$r) {
+                               if ($r) {
+                                       if ($r->flags != $flags) {
+                                               $r->flags($flags);
+                                               push @rout, $r;
+                                       }
+                                       $r->addparent($ncall);
+                               } else {
                                        push @rout, $parent->add_user($call, $flags);
                                }
                                
@@ -632,6 +636,11 @@ sub normal
                        # new routing list
                        my @rout;
                        my $parent = Route::Node::get($self->{call});
+                       unless ($parent) {
+                               dbg("DXPROT: my parent $self->{call} has disappeared");
+                               $self->disconnect;
+                               return;
+                       }
 
                        # parse the PC19
                        for ($i = 1; $i < $#field-1; $i += 4) {
@@ -644,6 +653,7 @@ sub normal
                                $ver = 5000 if $ver eq '0000';
                                next if $ver < 5000; # only works with version 5 software
                                next if length $call < 3; # min 3 letter callsigns
+                               next if $call eq $main::mycall;
 
                                # update it if required
                                my $r = Route::Node::get($call);
@@ -664,7 +674,10 @@ sub normal
                                                push @rout, $r unless $ar;
                                        }
                                } else {
-                                       next if $call eq $main::mycall || $call eq $self->{call};
+                                       if ($call eq $self->{call}) {
+                                               dbg("DXPROT: my channel route for $call has disappeared");
+                                               next;
+                                       };
                                        
                                        my $new = Route->new($call);          # throw away
                                    if ($self->in_filter_route($new)) {
@@ -709,7 +722,8 @@ sub normal
                        my @rout;
                        my $parent = Route::Node::get($self->{call});
                        unless ($parent) {
-                               dbg("PCPROT: Route::Node $call not in config") if isdbg('chanerr');
+                               dbg("DXPROT: my parent $self->{call} has disappeared");
+                               $self->disconnect;
                                return;
                        }
                        my $node = Route::Node::get($call);
@@ -785,16 +799,18 @@ sub normal
                
                if ($pcno == 24) {              # set here status
                        my $call = uc $field[1];
-                       my $ref = Route::Node::get($call);
-                       $ref->here($field[2]) if $ref;
-                       $ref = Route::User::get($call);
-                       $ref->here($field[2]) if $ref;
-                       $ref ||= Route->new($call);
+                       my ($nref, $uref);
+                       $nref = Route::Node::get($call);
+                       $uref = Route::User::get($call);
+                       return unless $nref || $uref;   # if we don't know where they are, it's pointless sending it on
                        
-                       # input filter if required
-                       return unless $self->in_filter_route($ref);
-
-                       $self->route_pc24($ref, $field[3]) if $ref && !eph_dup($line);
+                       unless (eph_dup($line)) {
+                               $nref->here($field[2]) if $nref;
+                               $uref->here($field[2]) if $uref;
+                               my $ref = $nref || $uref;
+                               return unless $self->in_filter_route($ref);
+                               $self->route_pc24($ref, $field[3]);
+                       }
                        return;
                }
                
@@ -1449,7 +1465,7 @@ sub send_local_config
                # and are not themselves isolated, this to make sure that isolated nodes
         # don't appear outside of this node
                my @dxchan = grep { $_->call ne $main::mycall && $_->call ne $self->{call} } DXChannel::get_all_nodes();
-               @localnodes = map { Route::Node::get($_->{call}) or die "connot find node $_->{call}" } @dxchan if @dxchan;
+               @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
                my @intcalls = map { $_->nodes } @localnodes if @localnodes;
                my $ref = Route::Node::get($self->{call});
                my @rnodes = $ref->nodes;
@@ -1500,7 +1516,7 @@ sub route
        if ($dxchan) {
                my $routeit = adjust_hops($dxchan, $line);   # adjust its hop count by node name
                if ($routeit) {
-                       $dxchan->send($routeit);
+                       $dxchan->send($routeit) unless $dxchan == $me;
                }
        } else {
                dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
@@ -1678,10 +1694,10 @@ sub addrcmd
        $r->{t} = $main::systime;
        $r->{cmd} = $cmd;
        $rcmds{$to} = $r;
-
+       
        my $ref = Route::Node::get($to);
        my $dxchan = $ref->dxchan;
-    if ($dxchan && $dxchan->is_clx) {
+       if ($dxchan && $dxchan->is_clx) {
                route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
        } else {
                route(undef, $to, pc34($main::mycall, $to, $cmd));