remove any leading ::ffff: on ipv4 addresses
[spider.git] / perl / DXProtHandle.pm
index 1114a1d0811834cb736605bb07f0409d9fa312b6..e108666c9283adad0cf6e4106369a3970ed53da5 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]);
@@ -458,7 +462,7 @@ sub handle_16
 
        my $i;
        my @rout;
-       for ($i = 2; $i < $#_; $i++) {
+       for ($i = 2; $i < $#$pc; $i++) {
                my ($call, $conf, $here) = $pc->[$i] =~ /^(\S+) (\S) (\d)/o;
                next unless $call && $conf && defined $here && is_callsign($call);
                next if $call eq $main::mycall;
@@ -653,8 +657,8 @@ sub check_add_node
                $user->lockout(1);
                $user->homenode($call);
                $user->node($call);
+               $user->sort('A');
        }
-       $user->sort('A') unless $user->is_node;
        return $user;
 }
 
@@ -695,7 +699,7 @@ sub handle_19
        # From now on we are only going to believe PC92 data and locally connected
        # non-pc92 nodes.
        #
-       for ($i = 1; $i < $#_-1; $i += 4) {
+       for ($i = 1; $i < $#$pc-1; $i += 4) {
                my $here = $pc->[$i];
                my $call = uc $pc->[$i+1];
                my $conf = $pc->[$i+2];
@@ -709,7 +713,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;
@@ -853,7 +857,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 +868,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 +880,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;
        }
 
@@ -1014,7 +1018,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,6 +1173,16 @@ sub handle_41
                return;
        }
 
+       if ($call eq $main::mycall || $call eq $main::myalias) {
+               dbg "DXPROT: PC41 trying to update $call from outside via $origin, ignored";
+               return;
+       }
+       my $chan = DXChannel::get($call);
+       if ($chan) {
+               dbg "DXPROT: PC41 trying to update online $call from outside via $origin, ignored";
+               return;
+       }
+
        # add this station to the user database, if required
        my $user = DXUser::get_current($call);
        $user = DXUser->new($call) unless $user;
@@ -1176,9 +1190,6 @@ sub handle_41
        if ($sort == 1) {
                if (($val =~ /spotter/i || $val =~ /self/i) && $user->name && $user->name ne $val) {
                        dbg("PCPROT: invalid name") if isdbg('chanerr');
-                       if ($main::mycall eq 'GB7DJK' || $main::mycall eq 'GB7BAA' || $main::mycall eq 'WR3D') {
-                               DXChannel::broadcast_nodes(pc41($pc->[1], 1, $user->name)); # send it to everyone including me
-                       }
                        return;
                }
                $user->name($val);
@@ -1291,6 +1302,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) {
@@ -1639,7 +1654,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".
@@ -1700,21 +1719,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}) {
@@ -1810,7 +1834,7 @@ sub handle_92
                my $me = $pc->[4] || '';
                $me ||= _encode_pc92_call($parent) unless $me ;
 
-               my @ent = map {my @a = _decode_pc92_call($_); @a ? \@a : ()} grep {$_ && /^[0-7]/} $me, @$pc[5 .. $#_];
+               my @ent = map {my @a = _decode_pc92_call($_); @a ? \@a : ()} grep {$_ && /^[0-7]/} $me, @$pc[5 .. $#$pc];
 
                if (@ent) {