PC61 with badip will now also stop following PC11s
[spider.git] / perl / DXProtHandle.pm
index a6668a36db0daeef1752d86b796d4dcaf7d82e18..f1972b094af888870e44470c1ca5458762eb4085 100644 (file)
@@ -89,16 +89,6 @@ sub handle_10
                return;
        }
 
-       # will we allow it at all?
-       if ($censorpc) {
-               my @bad;
-               if (@bad = BadWords::check($pc->[3])) {
-                       my $bw = join ', ', @bad; 
-                       dbg($line) if isdbg('nologchan');
-                       dbg("PCPROT: Badwords: '$bw', dropped");
-                       return;
-               }
-       }
 
        # is it for me or one of mine?
        my ($from, $to, $via, $call, $dxchan);
@@ -133,6 +123,17 @@ sub handle_10
                        return;
                }
        }
+       
+       # will we allow it at all?
+       if ($censorpc) {
+               my @bad;
+               if (@bad = BadWords::check($pc->[3])) {
+                       my $bw = join ', ', @bad; 
+                       dbg($line) if isdbg('nologchan');
+                       dbg("PCPROT: Badwords: '$bw', dropped");
+                       return;
+               }
+       }
 
        # convert this to a PC93, coming from mycall with origin set and process it as such
        $main::me->normal(pc93($to, $from, $via, $pc->[3], $pc->[6]));
@@ -160,7 +161,7 @@ sub handle_11
                }
        }
 
-       dbg("INPUT PC$pcno $line origin $origin recurse: $recurse") if isdbg("pc11"); 
+       dbg("INPUT PC$pcno $line origin $origin recurse: $recurse") if isdbg("pc11") || isdbg("pc61")
 
 #      my ($hops) = $pc->[8] =~ /^H(\d+)/;
 
@@ -194,29 +195,20 @@ sub handle_11
                return;
        }
 
-       # check IP addresses
-       if ($pc->[8] && is_ipaddr($pc->[8])) {
-               my $ip = $pc->[8];
-               $ip =~ s/,/:/g;
-               $ip =~ s/^::ffff://;
-               if (DXCIDR::find($ip)) {
-                       
-               }
-       }
 
        # convert the date to a unix date
        my $d = cltounix($pc->[3], $pc->[4]);
        # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
        if (!$d || (($pcno == 11 || $pcno == 61) && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
+               dbg($line) if isdbg('nologchan');
                dbg("PCPROT: Spot ignored, invalid date or out of range ($pc->[3] $pc->[4])\n");
                return;
        }
 
        # is it 'baddx'
-       if ($baddx->in($pc->[2]) || (my @bad = BadWords::check($pc->[2]))) {
-               my $bw = join ', ', @bad;
-               $bw = qq{ '$bw'} if $bw;
-               dbg("PCPROT: Bad DX spot$bw, ignored");
+       if ($baddx->in($pc->[2])) {
+               dbg("PCPROT: Bad DX spot '$pc->[2]', ignored");
+               dbg($line) if isdbg('nologchan');
                return;
        }
 
@@ -224,21 +216,27 @@ sub handle_11
        $pc->[5] =~ s/^\s+//;                   # take any leading blanks off
        $pc->[2] = unpad($pc->[2]);             # take off leading and trailing blanks from spotted callsign
        if ($pc->[2] =~ /BUST\w*$/) {
+               dbg($line) if isdbg('nologchan');
                dbg("PCPROT: useless 'BUSTED' spot") if isdbg('chanerr');
                return;
        }
-       if ($censorpc) {
-               my @bad;
-               if (@bad = BadWords::check($pc->[5])) {
-                       my $bw = join ', ', @bad;
+       
+
+       my @spot = Spot::prepare($pc->[1], $pc->[2], $d, $pc->[5], $nossid, $pc->[7], $pc->[8]);
+
+       # check IP addresses
+       if (@$pc > 8 && is_ipaddr($pc->[8])) {
+               my $ip = $pc->[8];
+               $ip =~ s/,/:/g;
+               $ip =~ s/^::ffff://;
+               if (DXCIDR::find($ip)) {
                        dbg($line) if isdbg('nologchan');
-                       dbg("PCPROT: Badwords: '$bw', dropped");
+                       dbg("PCPROT: $ip in badip list, dropped");
+                       # sneakily put it into the dup list to prevent following PC11s also getting through :-)
+                       Spot::dup(@spot[0..4,7]);
                        return;
                }
        }
-       
-
-       my @spot = Spot::prepare($pc->[1], $pc->[2], $d, $pc->[5], $nossid, $pc->[7], $pc->[8]);
 
        # global spot filtering on INPUT
        if ($self->{inspotsfilter}) {
@@ -328,12 +326,24 @@ sub handle_11
                        if ($s) {
                                my $action = $senderverify > 1 ? ", DUMPED" : '';
                                $s =~ s/, $//;
-                               dbg("PCProt: Suspicious Spot $pc->[2] on $pc->[1] by $pc->[6]($ip)\@$pc->[7] $s$action");
+                               dbg("PCPROT: Suspicious Spot $pc->[2] on $pc->[1] by $pc->[6]($ip)\@$pc->[7] $s$action");
                                return unless $senderverify < 2;
                        }
                }
        }
 
+# we until here to do any censorship to try and reduce the amount of noise that repeated copies
+# from other connected nodes cause
+       if ($censorpc) {
+               my @bad;
+               if (@bad = BadWords::check($pc->[5])) {
+                       my $bw = join ', ', @bad;
+                       dbg($line) if isdbg('nologchan');
+                       dbg("PCPROT: Badwords: '$bw', dropped");
+                       return;
+               }
+       }
+
        # If is a new PC11, store it, releasing the one that is there (if any),
        # if a PC61 comes along then dump the stored PC11
        # If there is a different PC11 stored, release that one and store this PC11 instead,
@@ -448,16 +458,6 @@ sub handle_12
        # announce duplicate checking
        $pc->[3] =~ s/^\s+//;                   # remove leading blanks
 
-       if ($censorpc) {
-               my @bad;
-               if (@bad = BadWords::check($pc->[3])) {
-                       my $bw = join ', ', @bad;
-                       dbg($line) if isdbg('nologchan');
-                       dbg("PCPROT: Badwords: '$bw', dropped");
-                       return;
-               }
-       }
-
        # if this is a 'nodx' node then ignore it
        if ($badnode->in($pc->[5])) {
                dbg($line) if isdbg('nologchan');
@@ -481,6 +481,17 @@ sub handle_12
                return;
        }
 
+       if ($censorpc) {
+               my @bad;
+               if (@bad = BadWords::check($pc->[3])) {
+                       my $bw = join ', ', @bad;
+                       dbg($line) if isdbg('nologchan');
+                       dbg("PCPROT: Badwords: '$bw', dropped");
+                       return;
+               }
+       }
+
+
        my $dxchan;
 
        if ((($dxchan = DXChannel::get($pc->[2])) && $dxchan->is_user) || $pc->[4] =~ /^[\#\w.]+$/){
@@ -750,14 +761,17 @@ sub handle_18
        my $parent = Route::Node::get($self->{call});
 
        # record the type and version offered
-       if (my ($version) = $pc->[1] =~ /DXSpider Version: (\d+\.\d+)/) {
-               $self->{version} = 53 + $version;
-               $self->user->version(53 + $version);
-               $parent->version(0 + $version);
+       if (my ($version) = $pc->[1] =~ /(?:DXSpider|CC\s*Cluster)\s+Version: (\d+(?:\.\d+))/) {
+               $version += 0;
+               $version += 53 if $version < 6;
+               $self->{version} = $version;
+               $self->user->version($version);
+               $parent->version($version);
                my ($build) = $pc->[1] =~ /Build: (\d+(?:\.\d+)?)/;
-               $self->{build} = 0 + $build;
-               $self->user->build(0 + $build);
-               $parent->build(0 + $build);
+               $build += 0;
+               $self->{build} = $build;
+               $self->user->build($build);
+               $parent->build($build);
                dbg("$self->{call} = DXSpider version $version build $build");
                unless ($self->is_spider) {
                        dbg("Change U " . $self->user->sort . " C $self->{sort} -> S");
@@ -1683,12 +1697,12 @@ sub _add_thingy
                                        my $old = $user->sort;
                                        if ($user->is_ak1a && (($version >= 5455 &&  $build > 0) || ($version >= 3000 && $version <= 3500)) ) {
                                                $user->sort('S');
-                                               dbg("PCProt::_add_thingy node $call v: $version b: $build sort ($old) updated to " . $user->sort);
+                                               dbg("PCPROT::_add_thingy node $call v: $version b: $build sort ($old) updated to " . $user->sort);
                                        } elsif ($user->is_spider && ($version < 3000 || ($version > 4000 && $version < 5455))) {
                                                unless ($version > 0  && $build == 0) {
                                                        $user->sort('A');
                                                        $build ||= 0;
-                                                       dbg("PCProt::_add_thingy node $call v: $version b: $build sort ($old) downgraded to " . $user->sort);
+                                                       dbg("PCPROT::_add_thingy node $call v: $version b: $build sort ($old) downgraded to " . $user->sort);
                                                }
                                        }
                                }
@@ -2045,23 +2059,23 @@ sub handle_92
                        my $user = check_add_user($parent->call, 'S');
                        my $oldsort = $user->sort // '';
 
-                       dbg("PCProt PC92 K v: $version ov: $oldversion b: $build ob: $oldbuild pk: " . ($parent->K || '0') . " uk: " . ($user->K || 0)) if isdbg('pc92k');
+                       dbg("PCPROT: PC92 K v: $version ov: $oldversion b: $build ob: $oldbuild pk: " . ($parent->K || '0') . " uk: " . ($user->K || 0)) if isdbg('pc92k');
                                
                        if (is_numeric($version) || is_numeric($build)) {
                                my $changed = 0;
                                if (($oldversion ne $version || $build ne $oldbuild)) {
-                                       dbg("PCProt PC92 K node $call updated version: $version (was $oldversion) build: $build (was $oldbuild)");
+                                       dbg("PCPROT: PC92 K node $call updated version: $version (was $oldversion) build: $build (was $oldbuild)");
                                        $user->version($parent->version($version));
                                        $user->build($parent->build($build));
                                        ++$changed;
                                }
                                if ($oldsort ne 'S') {
-                                       dbg("PCProt PC92 K node $call updated sort: $sort (was $oldsort)");
+                                       dbg("PCPROT: PC92 K node $call updated sort: $sort (was $oldsort)");
                                        $user->sort('S');
                                        ++$changed;
                                }
                                unless ($user->K) {
-                                       dbg("PCProt PC92 K node $call updated - marked as PC92 K user");
+                                       dbg("PCPROT: PC92 K node $call updated - marked as PC92 K user");
                                        $user->K(1);
                                        ++$changed;
                                }
@@ -2268,17 +2282,6 @@ sub handle_93
                my $s = "ANNTALK: $from\@$onode$vs -> $to '$text' route: $origin";
                dbg($s);
        }
-       
-       # will we allow it at all?
-       if ($censorpc) {
-               my @bad;
-               if (@bad = BadWords::check($text)) {
-                       my $bw = join ', ', @bad;
-                       dbg($line) if isdbg('nologchan');
-                       dbg("PCPROT: Badwords: '$bw', dropped");
-                       return;
-               }
-       }
 
        # if this is a 'bad spotter' user then ignore it
        my $nossid = $from;
@@ -2295,6 +2298,17 @@ sub handle_93
                return;
        }
 
+       # will we allow it at all?
+       if ($censorpc) {
+               my @bad;
+               if (@bad = BadWords::check($text)) {
+                       my $bw = join ', ', @bad;
+                       dbg($line) if isdbg('nologchan');
+                       dbg("PCPROT: Badwords: '$bw', dropped");
+                       return;
+               }
+       }
+
        # if it is routeable then then treat it like a talk
        my $ref = Route::get($to);
        if ($ref) {