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