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