]> dxcluster.net Git - spider.git/blob - perl/Thingy/Dx.pm
fix DL coords
[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                 my $text = $sd->[3] || ' ';
70                 $text =~ s/\^/\%5E/g;
71                 my $t = $sd->[2];
72                 $thing->{DXProt} = sprintf "PC11^%.1f^$sd->[1]^%s^%s^%s^$sd->[4]^$sd->[7]^$hops^~", $sd->[0], cldate($t), ztime($t), $text;
73         }
74         return $thing->{DXProt};
75 }
76
77 sub gen_DXCommandmode
78 {
79         my $thing = shift;
80         my $dxchan = shift;
81         
82         # these are always generated, never cached
83         return unless $dxchan->{dx};
84         
85         my $buf;
86         if ($dxchan->{ve7cc}) {
87                 $buf = VE7CC::dx_spot($dxchan, $thing->{spotdata});
88         } else {
89                 $buf = Spot::format_dx_spot($dxchan, $thing->{spotdata});
90                 $buf .= "\a\a" if $dxchan->{beep};
91                 $buf =~ s/\%5E/^/g;
92         }
93         return $buf;
94 }
95
96 sub from_DXProt
97 {
98         my $thing = shift;
99         while (@_) {
100                 my $k = shift;
101                 $thing->{$k} = shift;
102         }
103         ($thing->{hops}) = $thing->{DXProt} =~ /\^H(\d+)\^?~?$/ if exists $thing->{DXProt};
104         return $thing;
105 }
106
107 sub handle
108 {
109         my $thing = shift;
110         my $dxchan = shift;
111
112         my $spot = $thing->{spotdata};
113         if (Spot::dup(@$spot[0..4,5])) {
114                 dbg("PCPROT: Duplicate Spot ignored\n") if isdbg('chanerr');
115                 return;
116         }
117
118         # add it 
119         Spot::add(@$spot);
120
121         $thing->broadcast($dxchan);
122 }
123
124 sub in_filter
125 {
126         my $thing = shift;
127         my $dxchan = shift;
128         
129         # global spot filtering on INPUT
130         if ($dxchan->{inspotsfilter}) {
131                 my ($filter, $hops) = $dxchan->{inspotsfilter}->it($thing->{spotdata});
132                 unless ($filter) {
133                         dbg("PCPROT: Rejected by input spot filter") if isdbg('chanerr');
134                         return;
135                 }
136         }
137         return 1;
138 }
139
140 sub out_filter
141 {
142         my $thing = shift;
143         my $dxchan = shift;
144         
145         # global spot filtering on OUTPUT
146         if ($dxchan->{spotsfilter}) {
147                 my ($filter, $hops) = $dxchan->{spotsfilter}->it($thing->{spotdata});
148                 unless ($filter) {
149                         dbg("PCPROT: Rejected by output spot filter") if isdbg('chanerr');
150                         return;
151                 }
152                 $thing->{hops} = $hops if $hops;
153         } elsif ($dxchan->{isolate}) {
154                 return;
155         }
156         return 1;
157 }
158 1;