release 1.5
[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;
13 my $spotter = $self->call;
14 my $spotted;
15 my $freq;
16 my @out;
17 my $valid = 0;
18
19 # first lets see if we think we have a callsign as the first argument
20 if ($f[0] =~ /[A-Za-z]/) {
21   $spotter = uc $f[0];
22   $freq = $f[1];
23   $spotted = uc $f[2];
24   $line =~ s/^$f[0]\s+$f[1]\s+$f[2]\s*//;
25 } else {
26   $freq = $f[0];
27   $spotted = uc $f[1]; 
28   $line =~ s/^$f[0]\s+$f[1]\s*//;
29 }
30
31 # bash down the list of bands until a valid one is reached
32 my $bandref;
33 my @bb;
34 my $i;
35
36 # first in KHz
37 L1:
38 foreach $bandref (Bands::get_all()) {
39   @bb = @{$bandref->band};
40   for ($i = 0; $i < @bb; $i += 2) {
41     if ($freq >= $bb[$i] && $freq <= $bb[$i+1]) {
42           $valid = 1;
43           last L1;
44         }
45   }
46 }
47
48 if (!$valid) {
49
50         # try again in MHZ 
51         $freq = $freq * 1000 if $freq;
52
53 L2:
54     foreach $bandref (Bands::get_all()) {
55                 @bb = @{$bandref->band};
56                 for ($i = 0; $i < @bb; $i += 2) {
57                         if ($freq >= $bb[$i] && $freq <= $bb[$i+1]) {
58                                 $valid = 1;
59                                 last L2;
60                         }
61                 }
62         }
63 }
64
65
66
67 push @out, $self->msg('dx1', $freq) if !$valid;
68
69 # check we have a callsign :-)
70 if ($spotted le ' ') {
71         push @out, $self->msg('dx2');
72         
73   $valid = 0;
74 }
75
76 return (1, @out) if !$valid;
77
78 # Store it here
79 if (Spot::add($freq, $spotted, $main::systime, $line, $spotter)) {
80   # send orf to the users
81   my $buf = Spot::formatb($freq, $spotted, $main::systime, $line, $spotter);
82   DXProt::broadcast_users($buf);
83
84
85   # send it orf to the cluster (hang onto your tin helmets)!
86   DXProt::broadcast_ak1a(DXProt::pc11($spotter, $freq, $spotted, $line));
87 }
88
89 return (1, @out);