try and get the hops correct
[spider.git] / perl / Thingy / Dx.pm
1 #
2 # Dx Thingy handling
3 #
4 # $Id$
5 #
6 # Copyright (c) 2005 Dirk Koopman G1TLH
7 #
8
9 use strict;
10
11 package Thingy::Dx;
12
13 use vars qw($VERSION $BRANCH);
14
15 main::mkver($VERSION = q$Revision$);
16
17 use DXChannel;
18 use DXDebug;
19 use DXUtil;
20 use Thingy;
21 use Spot;
22
23 use vars qw(@ISA);
24 @ISA = qw(Thingy);
25
26 sub gen_Aranea
27 {
28         my $thing = shift;
29         unless ($thing->{Aranea}) {
30                 my $sd = $thing->{spotdata};
31                 $thing->{f} = $sd->[0];
32                 $thing->{c} = $sd->[1];
33                 $thing->{b} = $sd->[4] unless $thing->{user};
34                 my $t = int($sd->[2] / 60);
35                 $thing->{t} = sprintf("%X", $t) unless $t eq int($main::systime / 60);
36                 $thing->{o} =  $sd->[7] unless $sd->[7] eq $main::mycall; 
37                 $thing->{i} = $sd->[3] if $sd->[3];
38                 $thing->{Aranea} = Aranea::genmsg($thing, [qw(f c b t o i)]);
39         }
40         return $thing->{Aranea};
41 }
42
43 sub from_Aranea
44 {
45         my $thing = shift;
46         return unless $thing;
47         my $t = hex($thing->{t}) if exists $thing->{t};
48         $t ||= int($thing->{time} / 60);        # if it is an aranea generated
49         my $by = $thing->{b} || $thing->{fromuser} || $thing->{user} || $thing->{origin};
50         my @spot = Spot::prepare(
51                                                          $thing->{f},
52                                                          $thing->{c},
53                                                          $t*60,
54                                                          ($thing->{i} || ''),
55                                                          $by,
56                                                          ($thing->{o} || $thing->{origin}),
57                                                         );
58         $spot[4] = $by;                         # don't modify the spotter SSID
59         $thing->{spotdata} = \@spot;
60         return $thing;
61 }
62
63 sub gen_DXProt
64 {
65         my $thing = shift;
66         unless ($thing->{DXProt}) {
67                 my $sd = $thing->{spotdata};
68                 my $hops = $thing->{hops} || DXProt::get_hops(11);
69                 $hops = "H$hops" unless $hops =~ /^H/;
70                 my $text = $sd->[3] || ' ';
71                 $text =~ s/\^/\%5E/g;
72                 my $t = $sd->[2];
73                 $thing->{DXProt} = sprintf "PC11^%.1f^$sd->[1]^%s^%s^%s^$sd->[4]^$sd->[7]^$hops^~", $sd->[0], cldate($t), ztime($t), $text;
74         }
75         return $thing->{DXProt};
76 }
77
78 sub gen_DXCommandmode
79 {
80         my $thing = shift;
81         my $dxchan = shift;
82         
83         # these are always generated, never cached
84         return unless $dxchan->{dx};
85         
86         my $buf;
87         if ($dxchan->{ve7cc}) {
88                 $buf = VE7CC::dx_spot($dxchan, $thing->{spotdata});
89         } else {
90                 $buf = Spot::format_dx_spot($dxchan, $thing->{spotdata});
91                 $buf .= "\a\a" if $dxchan->{beep};
92                 $buf =~ s/\%5E/^/g;
93         }
94         return $buf;
95 }
96
97 sub from_DXProt
98 {
99         my $thing = shift;
100         while (@_) {
101                 my $k = shift;
102                 $thing->{$k} = shift;
103         }
104         ($thing->{hops}) = $thing->{DXProt} =~ /\^H(\d+)\^?~?$/ if exists $thing->{DXProt};
105         return $thing;
106 }
107
108 sub handle
109 {
110         my $thing = shift;
111         my $dxchan = shift;
112
113         my $spot = $thing->{spotdata};
114         if (Spot::dup(@$spot[0..4,5])) {
115                 dbg("PCPROT: Duplicate Spot ignored\n") if isdbg('chanerr');
116                 return;
117         }
118
119         # add it 
120         Spot::add(@$spot);
121
122         $thing->broadcast($dxchan);
123 }
124
125 sub in_filter
126 {
127         my $thing = shift;
128         my $dxchan = shift;
129         
130         # global spot filtering on INPUT
131         if ($dxchan->{inspotsfilter}) {
132                 my ($filter, $hops) = $dxchan->{inspotsfilter}->it($thing->{spotdata});
133                 unless ($filter) {
134                         dbg("PCPROT: Rejected by input spot filter") if isdbg('chanerr');
135                         return;
136                 }
137         }
138         return 1;
139 }
140
141 sub out_filter
142 {
143         my $thing = shift;
144         my $dxchan = shift;
145         
146         # global spot filtering on OUTPUT
147         if ($dxchan->{spotsfilter}) {
148                 my ($filter, $hops) = $dxchan->{spotsfilter}->it($thing->{spotdata});
149                 unless ($filter) {
150                         dbg("PCPROT: Rejected by output spot filter") if isdbg('chanerr');
151                         return;
152                 }
153                 $thing->{hops} = $hops if $hops;
154         } elsif ($dxchan->{isolate}) {
155                 return;
156         }
157         return 1;
158 }
159 1;