new, more flexible, dx command
[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 # 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     shift @f;
30         shift @f;
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 $line =~ s/^$f[0]\s+$f[1]\s*//;
45
46 # bash down the list of bands until a valid one is reached
47 my $bandref;
48 my @bb;
49 my $i;
50
51 # first in KHz
52 L1:
53 foreach $bandref (Bands::get_all()) {
54         @bb = @{$bandref->band};
55         for ($i = 0; $i < @bb; $i += 2) {
56                 if ($freq >= $bb[$i] && $freq <= $bb[$i+1]) {
57                         $valid = 1;
58                         last L1;
59                 }
60         }
61 }
62
63 unless ($valid) {
64
65         # try again in MHZ 
66         $freq = $freq * 1000 if $freq;
67
68  L2:
69     foreach $bandref (Bands::get_all()) {
70                 @bb = @{$bandref->band};
71                 for ($i = 0; $i < @bb; $i += 2) {
72                         if ($freq >= $bb[$i] && $freq <= $bb[$i+1]) {
73                                 $valid = 1;
74                                 last L2;
75                         }
76                 }
77         }
78 }
79
80
81 push @out, $self->msg('dx1', $freq) unless $valid;
82
83 # check we have a callsign :-)
84 if ($spotted le ' ') {
85         push @out, $self->msg('dx2');
86         
87         $valid = 0;
88 }
89
90 return (1, @out) unless $valid;
91
92 # change ^ into : for transmission
93 $line =~ s/\^/:/og;
94
95 # Store it here (but only if it isn't baddx)
96 if (grep $_ eq $spotted, @DXProt::baddx) {
97         my $buf = Spot::formatb($freq, $spotted, $main::systime, $line, $spotter);
98         push @out, $buf;
99 } else {
100         my @spot = Spot::add($freq, $spotted, $main::systime, $line, $spotter, $main::mycall);
101         if (@spot) {
102                 # send orf to the users
103                 DXProt::send_dx_spot($self, DXProt::pc11($spotter, $freq, $spotted, $line), @spot);
104                 
105 #               my $buf = Spot::formatb($freq, $spotted, $main::systime, $line, $spotter);
106 #               DXProt::broadcast_users("$buf\a\a", 'dx', $spot[0]);
107
108                 # send it orf to the cluster (hang onto your tin helmets) 
109 #               DXProt::broadcast_all_ak1a(DXProt::pc11($spotter, $freq, $spotted, $line), $DXProt::me);
110         }
111 }
112
113 return (1, @out);