stop self spotting bwlow 23cms (configurable)
[spider.git] / cmd / dx.pl
1 #
2 # the DX command
3 #
4 # this is where the fun starts!
5 #
6 # Copyright (c) 1998 Dirk Koopman G1TLH
7 #
8 #
9 #
10
11 my ($self, $line) = @_;
12 my @f = split /\s+/, $line, 3;
13 my $spotter = $self->call;
14 my $spotted;
15 my $freq;
16 my @out;
17 my $valid = 0;
18 my $localonly;
19 my $oline = $line;
20
21 return (1, $self->msg('e5')) if $self->remotecmd || $self->inscript;
22 return (1, $self->msg('e28')) unless $self->registered;
23
24 my @bad;
25 if (@bad = BadWords::check($line)) {    
26         $self->badcount(($self->badcount||0) + @bad);
27         LogDbg('DXCommand', "$self->{call} swore: $line (with words:" . join(',', @bad) . ")");
28         $localonly++; 
29 }
30
31 # do we have at least two args?
32 return (1, $self->msg('dx2')) unless @f >= 2;
33
34 # as a result of a suggestion by Steve K9AN, I am changing the syntax of
35 # 'spotted by' things to "dx by g1tlh <freq> <call>" <freq> and <call>
36 # can be in any order
37
38 if ($f[0] =~ /^by$/i) {
39         return (1, $self->msg('e5')) unless $main::allowdxby || $self->priv;
40     $spotter = uc $f[1];
41     $line =~ s/\s*$f[0]\s+$f[1]\s+//;
42 #       $line = $f[2];
43         @f = split /\s+/, $line, 3;
44         return (1, $self->msg('dx2')) unless @f >= 2;
45 }
46
47 # get the freq and callsign either way round
48 if (is_freq($f[1]) && $f[0] =~ m{^[\w\d]+(?:/[\w\d]+){0,2}$}) {
49         $spotted = uc $f[0];
50         $freq = $f[1];
51 } elsif (is_freq($f[0]) && $f[1] =~ m{^[\w\d]+(?:/[\w\d]+){0,2}$}) {
52     $freq = $f[0];
53         $spotted = uc $f[1];
54 } else {
55         return (1, $self->msg('dx3'));
56 }
57
58 # check some other things
59 # remove ssid from calls
60 my $spotternoid = basecall($spotter);
61 my $callnoid = basecall($self->{call});
62
63 #$DB::single = 1;
64
65 if ($DXProt::baddx->in($spotted)) {
66         $localonly++; 
67 }
68 if ($DXProt::badspotter->in($spotternoid)) { 
69         LogDbg('DXCommand', "badspotter $spotternoid as $spotter ($oline)");
70         $localonly++; 
71 }
72
73 dbg "spotter $spotternoid/$callnoid\n";
74
75 if (($spotted =~ /$spotternoid/ || $spotted =~ /$callnoid/) && $freq < $Spot::minselfspotqrg) {
76         LogDbg('DXCommand', "$spotternoid/$callnoid trying to self spot below ${Spot::minselfspotqrg}KHz ($oline), not passed on to cluster");
77         $localonly++;
78 }
79
80 # make line the rest of the line
81 $line = $f[2] || " ";
82 @f = split /\s+/, $line;
83
84 # bash down the list of bands until a valid one is reached
85 my $bandref;
86 my @bb;
87 my $i;
88
89 # first in KHz
90 L1:
91 foreach $bandref (Bands::get_all()) {
92         @bb = @{$bandref->band};
93         for ($i = 0; $i < @bb; $i += 2) {
94                 if ($freq >= $bb[$i] && $freq <= $bb[$i+1]) {
95                         $valid = 1;
96                         last L1;
97                 }
98         }
99 }
100
101 unless ($valid) {
102
103         # try again in MHZ 
104         $freq = $freq * 1000 if $freq;
105
106  L2:
107     foreach $bandref (Bands::get_all()) {
108                 @bb = @{$bandref->band};
109                 for ($i = 0; $i < @bb; $i += 2) {
110                         if ($freq >= $bb[$i] && $freq <= $bb[$i+1]) {
111                                 $valid = 1;
112                                 last L2;
113                         }
114                 }
115         }
116 }
117
118
119 push @out, $self->msg('dx1', $freq) unless $valid;
120
121 # check we have a callsign :-)
122 if ($spotted le ' ') {
123         push @out, $self->msg('dx2');
124         $valid = 0;
125 }
126
127 return (1, @out) unless $valid;
128
129 my $ipaddr;
130
131 if ($self->conn && $self->conn->peerhost) {
132         my $addr = $self->hostname;
133         $ipaddr = $addr unless !is_ipaddr($addr) || $addr =~ /^127\./ || $addr =~ /^::[0-9a-f]+$/;
134 } elsif ($self->inscript) {
135         $ipaddr = "script";
136 }
137
138 # Store it here (but only if it isn't baddx)
139 my $t = (int ($main::systime/60)) * 60;
140 return (1, $self->msg('dup')) if Spot::dup($freq, $spotted, $t, $line, $spotter);
141 my @spot = Spot::prepare($freq, $spotted, $t, $line, $spotter, $main::mycall, $ipaddr);
142
143 if ($freq =~ /^69/ || $localonly) {
144
145         # heaven forfend that we get a 69Mhz band :-)
146         if ($freq =~ /^69/) {
147                 $self->badcount(($self->badcount||0) + 1);
148         }
149
150         $self->dx_spot(undef, undef, @spot);
151         return (1);
152 } else {
153         if (@spot) {
154                 # store it 
155                 Spot::add(@spot);
156
157                 # send orf to the users
158                 if ($ipaddr) {
159                         DXProt::send_dx_spot($self, DXProt::pc61($spotter, $freq, $spotted, $line, $ipaddr), @spot);
160                 } else {
161                         DXProt::send_dx_spot($self, DXProt::pc11($spotter, $freq, $spotted, $line), @spot);
162                 }
163         }
164 }
165
166 return (1, @out);
167
168
169
170
171