]> dxcluster.net Git - spider.git/blob - perl/Thingy/Dx.pm
remove all old dx stuff and check that it all now works solely from the
[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 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
15 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
16 $main::build += $VERSION;
17 $main::branch += $BRANCH;
18
19 use DXChannel;
20 use DXDebug;
21 use DXUtil;
22 use Thingy;
23 use Spot;
24
25 use vars qw(@ISA);
26 @ISA = qw(Thingy);
27
28 sub gen_Aranea
29 {
30         my $thing = shift;
31         unless ($thing->{Aranea}) {
32                 my $sd = $thing->{spotdata};
33                 my @items = (
34                                          f=>$sd->[0],
35                                          c=>$sd->[1],
36                                         );
37                 push @items, ('b', $sd->[4]) unless $thing->{user};
38                 push @items, ('st', sprintf("%X", $sd->[2] / 60), 'o', $sd->[7]) unless $sd->[7] eq $main::mycall;
39                 push @items, ('i', $sd->[3]) if $sd->[3];
40                 $thing->{Aranea} = Aranea::genmsg($thing, 'DX', @items);
41         }
42         return $thing->{Aranea};
43 }
44
45 sub from_Aranea
46 {
47         my $thing = shift;
48         return unless $thing;
49         my $t = hex($thing->{st}) if exists $thing->{st};
50         $t ||= $thing->{time} / 60;
51         my @spot = Spot::prepare(
52                                                          $thing->{f},
53                                                          $thing->{c},
54                                                          $t*60,
55                                                          ($thing->{i} || ''),
56                                                          ($thing->{b} || $thing->{fromuser} || $thing->{user} || $thing->{origin}),
57                                                          ($thing->{o} || $thing->{origin}),
58                                                         );
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^$text^$sd->[4]^$sd->[7]^$hops^~", $sd->[0], cldate($t), ztime($t);
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])) {
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 INPUT
146         if ($dxchan->{inspotsfilter}) {
147                 my ($filter, $hops) = $dxchan->{inspotsfilter}->it($thing->{spotdata});
148                 unless ($filter) {
149                         dbg("PCPROT: Rejected by input 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;