rearrange spot broadcast so that it copes according to terminal type
[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     $spotter = uc $f[1];
38     $line =~ s/^\s*$f[0]\s+$f[1]\s+//;
39         $line = $f[2];
40         @f = split /\s+/, $line;
41         return (1, $self->msg('dx2')) unless @f >= 2;
42 }
43
44 # get the freq and callsign either way round
45 if (is_freq($f[1]) && $f[0] =~ m{^[\w\d]+(?:/[\w\d]+){0,2}$}) {
46         $spotted = uc $f[0];
47         $freq = $f[1];
48 } elsif (is_freq($f[0]) && $f[1] =~ m{^[\w\d]+(?:/[\w\d]+){0,2}$}) {
49     $freq = $f[0];
50         $spotted = uc $f[1];
51 } else {
52         return (1, $self->msg('dx3'));
53 }
54
55 # make line the rest of the line
56 $line = $f[2] || " ";
57 @f = split /\s+/, $line;
58
59 # bash down the list of bands until a valid one is reached
60 my $bandref;
61 my @bb;
62 my $i;
63
64 # first in KHz
65 L1:
66 foreach $bandref (Bands::get_all()) {
67         @bb = @{$bandref->band};
68         for ($i = 0; $i < @bb; $i += 2) {
69                 if ($freq >= $bb[$i] && $freq <= $bb[$i+1]) {
70                         $valid = 1;
71                         last L1;
72                 }
73         }
74 }
75
76 unless ($valid) {
77
78         # try again in MHZ 
79         $freq = $freq * 1000 if $freq;
80
81  L2:
82     foreach $bandref (Bands::get_all()) {
83                 @bb = @{$bandref->band};
84                 for ($i = 0; $i < @bb; $i += 2) {
85                         if ($freq >= $bb[$i] && $freq <= $bb[$i+1]) {
86                                 $valid = 1;
87                                 last L2;
88                         }
89                 }
90         }
91 }
92
93
94 push @out, $self->msg('dx1', $freq) unless $valid;
95
96 # check we have a callsign :-)
97 if ($spotted le ' ') {
98         push @out, $self->msg('dx2');
99         $valid = 0;
100 }
101
102 return (1, @out) unless $valid;
103
104 # Store it here (but only if it isn't baddx)
105 my $t = (int ($main::systime/60)) * 60;
106 return (1, $self->msg('dup')) if Spot::dup($freq, $spotted, $t, $line);
107 my @spot = Spot::prepare($freq, $spotted, $t, $line, $spotter, $main::mycall);
108
109 if ($DXProt::baddx->in($spotted) || $freq =~ /^69/ || $localonly) {
110
111         # heaven forfend that we get a 69Mhz band :-)
112         if ($freq =~ /^69/) {
113                 $self->badcount(($self->badcount||0) + 1);
114         }
115
116         $self->dx_spot(undef, undef, @spot);
117         return (1);
118 } else {
119         if (@spot) {
120                 # store it 
121                 Spot::add(@spot);
122
123                 # send orf to the users
124                 DXProt::send_dx_spot($self, DXProt::pc11($spotter, $freq, $spotted, $line), @spot);
125         }
126 }
127
128 return (1, @out);
129
130
131
132
133