added mycall to locally generated spots in spot database
[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 (defined @f && @f >= 3 && $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 } elsif (defined @f && @f >= 2) {
26         $freq = $f[0];
27         $spotted = uc $f[1]; 
28         $line =~ s/^$f[0]\s+$f[1]\s*//;
29 } elsif (!defined @f || @f < 2) {
30         return (1, $self->msg('dx2'));
31 }
32
33 # bash down the list of bands until a valid one is reached
34 my $bandref;
35 my @bb;
36 my $i;
37
38 # first in KHz
39 L1:
40 foreach $bandref (Bands::get_all()) {
41         @bb = @{$bandref->band};
42         for ($i = 0; $i < @bb; $i += 2) {
43                 if ($freq >= $bb[$i] && $freq <= $bb[$i+1]) {
44                         $valid = 1;
45                         last L1;
46                 }
47         }
48 }
49
50 if (!$valid) {
51
52         # try again in MHZ 
53         $freq = $freq * 1000 if $freq;
54
55  L2:
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 L2;
62                         }
63                 }
64         }
65 }
66
67
68
69 push @out, $self->msg('dx1', $freq) if !$valid;
70
71 # check we have a callsign :-)
72 if ($spotted le ' ') {
73         push @out, $self->msg('dx2');
74         
75         $valid = 0;
76 }
77
78 return (1, @out) if !$valid;
79
80 # change ^ into : for transmission
81 $line =~ s/\^/:/og;
82
83 # Store it here
84 if (Spot::add($freq, $spotted, $main::systime, $line, $spotter, $main::mycall)) {
85         # send orf to the users
86         my $buf = Spot::formatb($freq, $spotted, $main::systime, $line, $spotter);
87         DXProt::broadcast_users($buf, 'dx', $buf);
88
89
90         # send it orf to the cluster (hang onto your tin helmets)!
91         DXProt::broadcast_ak1a(DXProt::pc11($spotter, $freq, $spotted, $line));
92 }
93
94 return (1, @out);