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