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