]> dxcluster.net Git - spider.git/blob - perl/Thingy/Dx.pm
fix naming
[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                 unless ($sd->[7] eq $main::mycall) {
35                         $thing->{t} = sprintf("%X", $sd->[2] / 60);
36                         $thing->{o} =  $sd->[7]; 
37                 }
38                 $thing->{i} = $sd->[3] if $sd->[3];
39                 $thing->{Aranea} = Aranea::genmsg($thing, [qw(f c b t o i)]);
40         }
41         return $thing->{Aranea};
42 }
43
44 sub from_Aranea
45 {
46         my $thing = shift;
47         return unless $thing;
48         my $t = hex($thing->{t}) if exists $thing->{t};
49         $t ||= $thing->{time} / 60;     # if it is an aranea generated
50         my @spot = Spot::prepare(
51                                                          $thing->{f},
52                                                          $thing->{c},
53                                                          $t*60,
54                                                          ($thing->{i} || ''),
55                                                          ($thing->{b} || $thing->{fromuser} || $thing->{user} || $thing->{origin}),
56                                                          ($thing->{o} || $thing->{origin}),
57                                                         );
58         $thing->{spotdata} = \@spot;
59         return $thing;
60 }
61
62 sub gen_DXProt
63 {
64         my $thing = shift;
65         unless ($thing->{DXProt}) {
66                 my $sd = $thing->{spotdata};
67                 my $hops = $thing->{hops} || DXProt::get_hops(11);
68                 my $text = $sd->[3] || ' ';
69                 $text =~ s/\^/%5E/g;
70                 my $t = $sd->[2];
71                 $thing->{DXProt} = sprintf "PC11^%.1f^$sd->[1]^%s^%s^$text^$sd->[4]^$sd->[7]^$hops^~", $sd->[0], cldate($t), ztime($t);
72         }
73         return $thing->{DXProt};
74 }
75
76 sub gen_DXCommandmode
77 {
78         my $thing = shift;
79         my $dxchan = shift;
80         
81         # these are always generated, never cached
82         return unless $dxchan->{dx};
83         
84         my $buf;
85         if ($dxchan->{ve7cc}) {
86                 $buf = VE7CC::dx_spot($dxchan, $thing->{spotdata});
87         } else {
88                 $buf = Spot::format_dx_spot($dxchan, $thing->{spotdata});
89                 $buf .= "\a\a" if $dxchan->{beep};
90                 $buf =~ s/\%5E/^/g;
91         }
92         return $buf;
93 }
94
95 sub from_DXProt
96 {
97         my $thing = shift;
98         while (@_) {
99                 my $k = shift;
100                 $thing->{$k} = shift;
101         }
102         ($thing->{hops}) = $thing->{DXProt} =~ /\^H(\d+)\^?~?$/ if exists $thing->{DXProt};
103         return $thing;
104 }
105
106 sub handle
107 {
108         my $thing = shift;
109         my $dxchan = shift;
110
111         my $spot = $thing->{spotdata};
112         if (Spot::dup(@$spot[0..4])) {
113                 dbg("PCPROT: Duplicate Spot ignored\n") if isdbg('chanerr');
114                 return;
115         }
116
117         # add it 
118         Spot::add(@$spot);
119
120         $thing->broadcast($dxchan);
121 }
122
123 sub in_filter
124 {
125         my $thing = shift;
126         my $dxchan = shift;
127         
128         # global spot filtering on INPUT
129         if ($dxchan->{inspotsfilter}) {
130                 my ($filter, $hops) = $dxchan->{inspotsfilter}->it($thing->{spotdata});
131                 unless ($filter) {
132                         dbg("PCPROT: Rejected by input spot filter") if isdbg('chanerr');
133                         return;
134                 }
135         }
136         return 1;
137 }
138
139 sub out_filter
140 {
141         my $thing = shift;
142         my $dxchan = shift;
143         
144         # global spot filtering on OUTPUT
145         if ($dxchan->{spotsfilter}) {
146                 my ($filter, $hops) = $dxchan->{spotsfilter}->it($thing->{spotdata});
147                 unless ($filter) {
148                         dbg("PCPROT: Rejected by output spot filter") if isdbg('chanerr');
149                         return;
150                 }
151                 $thing->{hops} = $hops if $hops;
152         } elsif ($dxchan->{isolate}) {
153                 return;
154         }
155         return 1;
156 }
157 1;