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