changed dx by to require at least privilege 1
[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 # $Id$
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 return (1, $self->msg('e5')) if $self->remotecmd;
20 return (1, $self->msg('e28')) unless $self->registered;
21
22 my @bad;
23 if (@bad = BadWords::check($line)) {    
24         $self->badcount(($self->badcount||0) + @bad);
25         Log('DXCommand', "$self->{call} swore: $line");
26         $localonly++;
27 }
28
29 # do we have at least two args?
30 return (1, $self->msg('dx2')) unless @f >= 2;
31
32 # as a result of a suggestion by Steve K9AN, I am changing the syntax of
33 # 'spotted by' things to "dx by g1tlh <freq> <call>" <freq> and <call>
34 # can be in any order
35
36 if ($f[0] =~ /^by$/i) {
37         return (1, $self->msg('e5')) unless $self->priv;
38     $spotter = uc $f[1];
39     $line =~ s/^\s*\Q$f[0]\s+\Q$f[1]\s+//;
40         $line = $f[2];
41         @f = split /\s+/, $line;
42         return (1, $self->msg('dx2')) unless @f >= 2;
43 }
44
45 # get the freq and callsign either way round
46 if (is_freq($f[1]) && $f[0] =~ m{^[\w\d]+(?:/[\w\d]+){0,2}$}) {
47         $spotted = uc $f[0];
48         $freq = $f[1];
49 } elsif (is_freq($f[0]) && $f[1] =~ m{^[\w\d]+(?:/[\w\d]+){0,2}$}) {
50     $freq = $f[0];
51         $spotted = uc $f[1];
52 } else {
53         return (1, $self->msg('dx3'));
54 }
55
56 # make line the rest of the line
57 $line = $f[2] || " ";
58 @f = split /\s+/, $line;
59
60 # bash down the list of bands until a valid one is reached
61 my $bandref;
62 my @bb;
63 my $i;
64
65 # first in KHz
66 L1:
67 foreach $bandref (Bands::get_all()) {
68         @bb = @{$bandref->band};
69         for ($i = 0; $i < @bb; $i += 2) {
70                 if ($freq >= $bb[$i] && $freq <= $bb[$i+1]) {
71                         $valid = 1;
72                         last L1;
73                 }
74         }
75 }
76
77 unless ($valid) {
78
79         # try again in MHZ 
80         $freq = $freq * 1000 if $freq;
81
82  L2:
83     foreach $bandref (Bands::get_all()) {
84                 @bb = @{$bandref->band};
85                 for ($i = 0; $i < @bb; $i += 2) {
86                         if ($freq >= $bb[$i] && $freq <= $bb[$i+1]) {
87                                 $valid = 1;
88                                 last L2;
89                         }
90                 }
91         }
92 }
93
94
95 push @out, $self->msg('dx1', $freq) unless $valid;
96
97 # check we have a callsign :-)
98 if ($spotted le ' ') {
99         push @out, $self->msg('dx2');
100         $valid = 0;
101 }
102
103 return (1, @out) unless $valid;
104
105 # Store it here (but only if it isn't baddx)
106 my $t = (int ($main::systime/60)) * 60;
107 return (1, $self->msg('dup')) if Spot::dup($freq, $spotted, $t, $line, $spotter);
108 my @spot = Spot::prepare($freq, $spotted, $t, $line, $spotter, $main::mycall);
109
110 if ($DXProt::baddx->in($spotted) || $freq =~ /^69/ || $localonly) {
111
112         # heaven forfend that we get a 69Mhz band :-)
113         if ($freq =~ /^69/) {
114                 $self->badcount(($self->badcount||0) + 1);
115         }
116
117         $self->dx_spot(undef, undef, @spot);
118         return (1);
119 } else {
120         if (@spot) {
121                 # store it 
122                 Spot::add(@spot);
123
124                 # send orf to the users
125                 DXProt::send_dx_spot($self, DXProt::pc11($spotter, $freq, $spotted, $line), @spot);
126         }
127 }
128
129 return (1, @out);
130
131
132
133
134