add an RBN line to progress
[spider.git] / perl / DXProtHandle.pm
index 4e55b9402c534a512a530362d26f380c9c2218b8..f5b7508b6300d8ad38835bf58657daf52a2c30e4 100644 (file)
@@ -158,17 +158,21 @@ sub handle_11
 
        # if this is a 'nodx' node then ignore it
        if ($badnode->in($pc->[7])) {
-               dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
+               dbg("PCPROT: Bad Node $pc->[7], dropped") if isdbg('chanerr');
                return;
        }
 
-       # if this is a 'bad spotter' user then ignore it
+       # if this is a 'bad spotter' or an unknown user then ignore it. BUT if it's got an IP address then allow it through
        my $nossid = $pc->[6];
        $nossid =~ s/-\d+$//;
        if ($badspotter->in($nossid)) {
-               dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
+               dbg("PCPROT: Bad Spotter $pc->[6], dropped") if isdbg('chanerr');
                return;
        }
+#      unless (is_ipaddr($pc->[8]) || DXUser::get_current($pc->[6])) {
+#              dbg("PCPROT: Unknown Spotter $pc->[6], dropped") if isdbg('chanerr');
+#              return;
+#      }
 
        # convert the date to a unix date
        my $d = cltounix($pc->[3], $pc->[4]);
@@ -220,6 +224,18 @@ sub handle_11
        # add it
        Spot::add(@spot);
 
+       my $ip = '';
+       $ip ||= $spot[14] if exists $spot[14];
+       if (isdbg('progress')) {
+               my $sip = $ip ? sprintf "($ip)" : '' unless $ip =~ m|[\(\)\*]|;
+               $sip ||= '';
+               my $d = ztime($spot[2]);
+               my $s = "SPOT: $spot[1] on $spot[0] \@ $d by $spot[4]$sip\@$spot[7]";
+               $s .= $spot[3] ? " '$spot[3]'" : q{ ''};
+               $s .=  " route: $origin";
+               dbg($s);
+       }
+       
        #
        # @spot at this point contains:-
        # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
@@ -236,7 +252,7 @@ sub handle_11
                        my $long = $user->long;
                        if (defined $lat && defined $long) {
                                $user->qra(DXBearing::lltoqra($lat, $long));
-                               $user->put;
+                               $user->put unless $self->{_nospawn};
                        }
                }
 
@@ -269,7 +285,7 @@ sub handle_11
                                        }
                                }
                                $user->lastoper($main::systime);
-                               $user->put;
+                               $user->put unless $self->{_nospawn};
                        }
                }
        }
@@ -496,7 +512,7 @@ sub handle_16
                $user->homenode($parent->call) if !$user->homenode;
                $user->node($parent->call);
                $user->lastin($main::systime) unless DXChannel::get($call);
-               $user->put;
+               $user->put unless $self->{_nospawn};
 
                # send info to all logged in thingies
                $self->tell_login('loginu', "$ncall: $call") if $user->is_local_node;
@@ -608,16 +624,16 @@ sub handle_18
                $self->{build} = 0 + $build;
                $self->user->build(0 + $build);
                $parent->build(0 + $build);
-               dbg("DXSpider version $version build $build");
+               dbg("$self->{call} = DXSpider version $version build $build");
                unless ($self->is_spider) {
                        dbg("Change U " . $self->user->sort . " C $self->{sort} -> S");
                        $self->user->sort('S');
-                       $self->user->put;
+                       $self->user->put unless $self->{_nospawn};
                        $self->sort('S');
                }
 #              $self->{handle_xml}++ if DXXml::available() && $pc->[1] =~ /\bxml/;
        } else {
-               dbg("Unknown software");
+               dbg("$self->{call} = Unknown software ($pc->[1] $pc->[2])");
                $self->version(50.0);
                $self->version($pc->[2] / 100) if $pc->[2] && $pc->[2] =~ /^\d+$/;
                $self->user->version($self->version);
@@ -625,12 +641,12 @@ sub handle_18
 
        if ($pc->[1] =~ /\bpc9x/) {
                if ($self->{isolate}) {
-                       dbg("pc9x recognised, but $self->{call} is isolated, using old protocol");
+                       dbg("$self->{call} pc9x recognised, but node is isolated, using old protocol");
                } elsif (!$self->user->wantpc9x) {
-                       dbg("pc9x explicitly switched off on $self->{call}, using old protocol");
+                       dbg("$self->{call} pc9x explicitly switched off, using old protocol");
                } else {
                        $self->{do_pc9x} = 1;
-                       dbg("Do px9x set on $self->{call}");
+                       dbg("$self->{call} Set do PC9x");
                }
        }
 
@@ -646,15 +662,20 @@ sub check_add_node
        my $call = shift;
 
        # add this station to the user database, if required (don't remove SSID from nodes)
-       my $user = DXUser::get_current($call);
-       if (!$user) {
+       my $chan = DXChannel::get($call);
+       my $user;
+       $user = $chan->user if $chan;
+       $user ||= DXUser::get($call);
+       unless ($user) {
                $user = DXUser->new($call);
                $user->priv(1);         # I have relented and defaulted nodes
                $user->lockout(1);
                $user->homenode($call);
                $user->node($call);
+               $user->sort('A');
+               $user->lastin($main::systime); # this make it last longer than just this invocation
+               $user->put unless $chan && $chan->{_nospawn};                           # just to make sure it gets written away!!!
        }
-       $user->sort('A') unless $user->is_node;
        return $user;
 }
 
@@ -709,7 +730,7 @@ sub handle_19
                next unless $ver && $ver =~ /^\d+$/;
                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;
+               next if $call eq $main::mycall || $call eq $main::myalias;
 
                # check that this PC19 isn't trying to alter the wrong dxchan
                $h = 0;
@@ -782,7 +803,7 @@ sub handle_19
                $mref->stop_msg($call) if $mref;
 
                $user->lastin($main::systime) unless DXChannel::get($call);
-               $user->put;
+               $user->put unless $self->{_nospawn};
        }
 
        # we are not automatically sending out PC19s, we send out a composite PC21,PC19 instead
@@ -853,7 +874,7 @@ sub handle_21
 
        my @rout;
 
-       if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
+       if ($call ne $main::mycall && $call ne $main::myalias) { # don't allow malicious buggers to disconnect me!
                my $node = Route::Node::get($call);
                if ($node) {
 
@@ -864,7 +885,7 @@ sub handle_21
 
                        my $dxchan = DXChannel::get($call);
                        if ($dxchan && $dxchan != $self) {
-                               dbg("PCPROT: PC21 from $self->{call} trying to alter locally connected $call, ignored!") if isdbg('chanerr');
+                               dbg("PCPROT: PC21 from $self->{call} trying to alter locally connected $call, ignored!") if isdbg('chan');
                                return;
                        }
 
@@ -876,7 +897,7 @@ sub handle_21
                        push @rout, $call if $dxchan && @rout == 0;
                }
        } else {
-               dbg("PCPROT: I WILL _NOT_ be disconnected!") if isdbg('chanerr');
+               dbg("PCPROT: I WILL _NOT_ be disconnected!") if isdbg('chan');
                return;
        }
 
@@ -957,6 +978,7 @@ sub handle_23
 
        # note this only takes the first one it gets
        Geomag::update($d, $pc->[2], $sfi, $k, $i, @$pc[6..8], $r);
+       dbg("WWV: <$pc->[2]>, sfi=$sfi k=$k info=$i '$pc->[6]' $pc->[7]\@$pc->[8] $r route: $origin") if isdbg('progress');
 
        if (defined &Local::wwv) {
                my $rep;
@@ -1014,7 +1036,7 @@ sub handle_25
                return;
        }
        if ($pc->[2] eq $main::mycall) {
-               dbg("PCPROT: Trying to merge to myself, ignored") if isdbg('chanerr');
+               dbg("PCPROT: Trying to merge to myself, ignored") if isdbg('chan');
                return;
        }
 
@@ -1169,7 +1191,7 @@ sub handle_41
                return;
        }
 
-       if ($call eq $main::mycall && $call eq $main::myalias) {
+       if ($call eq $main::mycall || $call eq $main::myalias) {
                dbg "DXPROT: PC41 trying to update $call from outside via $origin, ignored";
                return;
        }
@@ -1215,7 +1237,7 @@ sub handle_41
                }
        }
        $user->lastoper($main::systime); # to cut down on excessive for/opers being generated
-       $user->put;
+       $user->put unless $self->{_nospawn};
 
        unless ($self->{isolate}) {
                DXChannel::broadcast_nodes($line, $self); # send it to everyone but me
@@ -1298,6 +1320,10 @@ sub handle_51
        my $from = $pc->[2];
        my $flag = $pc->[3];
 
+       if ($to eq $main::myalias) {
+               dbg("DXPROT: Ping addressed to \$myalias ($main::myalias), ignored") if isdbg('chan');
+               return;
+       }
 
        # is it for us?
        if ($to eq $main::mycall) {
@@ -1356,6 +1382,7 @@ sub handle_73
        }
 
        my $wcy = WCY::update($d, @$pc[2..12]);
+       dbg("WCY: <$pc->[2]> K=$pc->[5] expK=$pc->[6] A=$pc->[4] R=$pc->[7] SFI=$pc->[3] SA=$pc->[8] GMF=$pc->[9] Au=$pc->[10] $pc->[11]\@$pc->[12] route: $origin") if isdbg('progress');
 
        if (defined &Local::wcy) {
                my $rep;
@@ -1460,32 +1487,41 @@ sub _add_thingy
        my ($call, $is_node, $is_extnode, $here, $version, $build, $ip) = @$s;
        my @rout;
 
+       # remove spurious IPV6 prefix on IPV4 addresses
+       $ip =~ s/^::ffff:// if $ip;
+       
        if ($call) {
                my $ncall = $parent->call;
-               if ($is_node) {
-                       dbg("ROUTE: added node $call to $ncall") if isdbg('routelow');
-                       @rout = $parent->add($call, $version, Route::here($here), $ip);
-                       my $r = Route::Node::get($call);
-                       $r->PC92C_dxchan($dxchan->call, $hops) if $r;
-                       if ($ip) {
-                               $r->ip($ip);
-                               Log('DXProt', "PC92A $call -> $ip on $ncall");
+               if ($ncall ne $call) {
+                       if ($is_node) {
+                               dbg("ROUTE: added node $call to $ncall") if isdbg('routelow');
+                               @rout = $parent->add($call, $version, Route::here($here), $ip);
+                               my $r = Route::Node::get($call);
+                               $r->PC92C_dxchan($dxchan->call, $hops) if $r;
+                               if ($ip) {
+                                       $r->ip($ip);
+                                       Log('DXProt', "PC92A $call -> $ip on $ncall");
+                               }
+                       } else {
+                               dbg("ROUTE: added user $call to $ncall") if isdbg('routelow');
+                               @rout = $parent->add_user($call, Route::here($here), $ip);
+                               $dxchan->tell_buddies('loginb', $call, $ncall) if $dxchan;
+                               my $r = Route::User::get($call);
+                               if ($ip) {
+                                       $r->ip($ip);
+                                       Log('DXProt', "PC92A $call -> $ip on $ncall");
+                               }
                        }
-               } else {
-                       dbg("ROUTE: added user $call to $ncall") if isdbg('routelow');
-                       @rout = $parent->add_user($call, Route::here($here), $ip);
-                       $dxchan->tell_buddies('loginb', $call, $ncall) if $dxchan;
-                       my $r = Route::User::get($call);
-                       if ($ip) {
-                               $r->ip($ip);
-                               Log('DXProt', "PC92A $call -> $ip on $ncall");
+                       if ($pc92_slug_changes && $parent == $main::routeroot) {
+                               $things_add{$call} = Route::get($call);
+                               delete $things_del{$call};
                        }
-               }
-               if ($pc92_slug_changes && $parent == $main::routeroot) {
-                       $things_add{$call} = Route::get($call);
-                       delete $things_del{$call};
+               } else {
+                       dbgprintring(10);
+                       dbg("DXProt::add_thingy: Trying to add parent $call to itself $ncall, ignored");
                }
        }
+       
        return @rout;
 }
 
@@ -1646,7 +1682,11 @@ sub pc92_handle_first_slot
        my ($call, $is_node, $is_extnode, $here, $version, $build) = @$slot;
        if ($call && $is_node) {
                if ($call eq $main::mycall) {
-                       dbg("PCPROT: $call looped back onto $main::mycall, ignored") if isdbg('chanerr');
+                       dbg("PCPROT: $call looped back onto \$main::mycall ($main::mycall), ignored") if isdbg('chan');
+                       return;
+               }
+               if ($call eq $main::myalias) {
+                       dbg("PCPROT: $call looped back onto \$main::myalias ($main::myalias), ignored") if isdbg('chan');
                        return;
                }
                # this is only accepted from my "self".
@@ -1707,21 +1747,26 @@ sub handle_92
 #      }
 
        if ($pcall eq $main::mycall) {
-               dbg("PCPROT: looped back, ignored") if isdbg('chanerr');
+               dbg("PCPROT: looped back, ignored") if isdbg('chan');
+               return;
+       }
+
+       if ($pcall eq $main::myalias) {
+               dbg("PCPROT: looped back to \$myalias ($main::myalias), misconfiguration ignored") if isdbg('chan');
                return;
        }
 
        if ($pcall eq $self->{call} && $self->{state} eq 'init') {
                if ($self->{isolate}) {
-                       dbg("PC9x received, but $pcall is isolated, ignored");
+                       dbg("DXPROT: PC9x received, but $pcall is isolated, ignored");
                        return;
                } elsif (!$self->user->wantpc9x) {
-                       dbg("PC9x explicitly switched off on $pcall, ignored");
+                       dbg("DXPROT: PC9x explicitly switched off on $pcall, ignored");
                        return;
                } else {
                        $self->state('init92');
                        $self->{do_pc9x} = 1;
-                       dbg("Do pc9x set on $pcall");
+                       dbg("DXPROT: Do pc9x set on $pcall");
                }
        }
        unless ($self->{do_pc9x}) {
@@ -1987,6 +2032,12 @@ sub handle_93
                return;
        }
 
+       if (isdbg('progress')) {
+               my $vs = $via ne '*' ? " via $via" : ''; 
+               my $s = "ANNTALK: $from\@$onode$vs -> $to '$text' route: $origin";
+               dbg($s);
+       }
+       
        # will we allow it at all?
        if ($censorpc) {
                my @bad;