fix self spotting by proxy (using by command)
[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
59 my $ipaddr;
60 my $addr = $self->hostname;
61
62 if ($self->conn && $self->conn->peerhost) {
63         $ipaddr = $addr unless !is_ipaddr($addr) || $addr =~ /^127\./ || $addr =~ /^::[0-9a-f]+$/;
64 } elsif ($self->inscript) {
65         $ipaddr = "script";
66 }
67
68 # check some other things
69 # remove ssid from calls
70 my $spotternoid = basecall($spotter);
71 my $callnoid = basecall($self->{call});
72
73 #$DB::single = 1;
74
75 if ($DXProt::baddx->in($spotted)) {
76         $localonly++; 
77 }
78 if ($DXProt::badspotter->in($spotternoid)) { 
79         LogDbg('DXCommand', "badspotter $spotternoid as $spotter ($oline) from $addr");
80         $localonly++; 
81 }
82
83 dbg "spotter $spotternoid/$callnoid\n";
84
85 if (($spotted =~ /$spotternoid/ || $spotted =~ /$callnoid/) && $freq < $Spot::minselfspotqrg) {
86         LogDbg('DXCommand', "$spotternoid/$callnoid trying to self spot below ${Spot::minselfspotqrg}KHz ($oline) from $addr, not passed on to cluster");
87         $localonly++;
88 }
89
90 # make line the rest of the line
91 $line = $f[2] || " ";
92 @f = split /\s+/, $line;
93
94 # bash down the list of bands until a valid one is reached
95 my $bandref;
96 my @bb;
97 my $i;
98
99 # first in KHz
100 L1:
101 foreach $bandref (Bands::get_all()) {
102         @bb = @{$bandref->band};
103         for ($i = 0; $i < @bb; $i += 2) {
104                 if ($freq >= $bb[$i] && $freq <= $bb[$i+1]) {
105                         $valid = 1;
106                         last L1;
107                 }
108         }
109 }
110
111 unless ($valid) {
112
113         # try again in MHZ 
114         $freq = $freq * 1000 if $freq;
115
116  L2:
117     foreach $bandref (Bands::get_all()) {
118                 @bb = @{$bandref->band};
119                 for ($i = 0; $i < @bb; $i += 2) {
120                         if ($freq >= $bb[$i] && $freq <= $bb[$i+1]) {
121                                 $valid = 1;
122                                 last L2;
123                         }
124                 }
125         }
126 }
127
128
129 push @out, $self->msg('dx1', $freq) unless $valid;
130
131 # check we have a callsign :-)
132 if ($spotted le ' ') {
133         push @out, $self->msg('dx2');
134         $valid = 0;
135 }
136
137 return (1, @out) unless $valid;
138
139 # Store it here (but only if it isn't baddx)
140 my $t = (int ($main::systime/60)) * 60;
141 return (1, $self->msg('dup')) if Spot::dup($freq, $spotted, $t, $line, $spotter);
142 my @spot = Spot::prepare($freq, $spotted, $t, $line, $spotter, $main::mycall, $ipaddr);
143
144 if ($freq =~ /^69/ || $localonly) {
145
146         # heaven forfend that we get a 69Mhz band :-)
147         if ($freq =~ /^69/) {
148                 $self->badcount(($self->badcount||0) + 1);
149         }
150
151         $self->dx_spot(undef, undef, @spot);
152         return (1);
153 } else {
154         if (@spot) {
155                 # store it 
156                 Spot::add(@spot);
157
158                 # send orf to the users
159                 if ($ipaddr) {
160                         DXProt::send_dx_spot($self, DXProt::pc61($spotter, $freq, $spotted, $line, $ipaddr), @spot);
161                 } else {
162                         DXProt::send_dx_spot($self, DXProt::pc11($spotter, $freq, $spotted, $line), @spot);
163                 }
164         }
165 }
166
167 return (1, @out);
168
169
170
171
172