2 # Route Thingy handling
6 # Copyright (c) 2005 Dirk Koopman G1TLH
13 use vars qw($VERSION $BRANCH);
15 main::mkver($VERSION = q$Revision$);
29 unless ($thing->{Aranea}) {
31 push @items, 's', $thing->{'s'} if $thing->{'s'};
32 push @items, 'n', $thing->{n} if $thing->{n};
33 push @items, 'v', $thing->{v} if $thing->{v};
34 push @items, 'u', $thing->{u} if $thing->{u};
35 $thing->{Aranea} = Aranea::genmsg($thing, 'RT', @items) if @items;
37 return $thing->{Aranea};
51 my $s = $thing->{'s'};
53 my $n = $thing->{n} || $thing->{user};
55 if ($n && (my $u = $thing->{u})) {
58 my ($here, $call) = unpack "A1 A*", $_;
59 my $str = sprintf "^%s * %d", $call, $here;
60 if (length($s) + length($str) > $DXProt::sentencelth) {
61 push @out, "PC16^$n" . $s . sprintf "^%s^", DXProt::get_hops(16);
66 push @out, "PC16^$n" . $s . sprintf "^%s^", DXProt::get_hops(16);
67 $thing->{DXProt} = @out > 1 ? \@out : $out[0];
69 } elsif ($s eq 'du') {
70 my $n = $thing->{n} || $thing->{user};
71 my $hops = DXProt::get_hops(17);
72 if ($n && (my $u = $thing->{u})) {
73 $thing->{DXProt} = "PC17^$u^$n^$hops^";
75 } elsif ($s eq 'an') {
76 } elsif ($s eq 'dn') {
78 return $thing->{DXProt};
81 #sub gen_DXCommandmode
97 ($thing->{hops}) = $thing->{DXProt} =~ /\^H(\d+)\^?~?$/ if exists $thing->{DXProt};
107 my $sub = "handle_$thing->{t}";
108 if ($thing->can($sub)) {
110 $thing = $thing->$sub($dxchan);
113 $thing->broadcast($dxchan) if $thing;
117 # these contain users and either a node (for externals) or the from address
123 my $node = $thing->{n} || $thing->{user};
124 my $nref = Route::Node::get($node);
127 if (my $u = $thing->{u}) {
128 for (split /:/, $u) {
129 my ($here, $call) = unpack "A1 A*", $_;
130 add_user($nref, $call, $here);
131 my $h = $dxchan->{call} eq $nref->{call} ? 3 : ($thing->{hops} || 99);
132 RouteDB::update($call, $dxchan->{call}, $h);
136 dbg("Thingy::Rt::au: $node not found") if isdbg('chanerr');
147 my $node = $thing->{n} || $thing->{user};
148 my $nref = Route::Node::get($node);
151 if (my $u = $thing->{u}) {
152 for (split /:/, $u) {
153 my ($here, $call) = unpack "A1 A*", $_;
154 my $uref = Route::User::get($call);
156 dbg("Thingy::Rt::du $call not a user") if isdbg('chanerr');
159 $nref->del_user($uref);
160 RouteDB::delete($call, $dxchan->{call});
162 RouteDB::update($nref->{call}, $dxchan->{call}, $dxchan->{call} eq $nref->{call} ? 2 : ($thing->{hops} || 99));
165 dbg("Thingy::Rt::du: $node not found") if isdbg('chanerr');
177 # global route filtering on INPUT
178 if ($dxchan->{inroutefilter}) {
179 my $r = Route::Node::get($thing->{origin});
180 my ($filter, $hops) = $dxchan->{inroutefilter}->it($dxchan->{call}, $dxchan->{dxcc}, $dxchan->{itu}, $dxchan->{cq}, $r->{call}, $r->{dxcc}, $r->{itu}, $r->{cq}, $dxchan->{state}, $r->{state});
182 dbg("PCPROT: Rejected by input route filter") if isdbg('chanerr');
194 # global route filtering on OUTPUT
195 if ($dxchan->{routefilter}) {
196 my $r = Route::Node::get($thing->{origin});
197 my ($filter, $hops) = $dxchan->{routefilter}->it($dxchan->{call}, $dxchan->{dxcc}, $dxchan->{itu}, $dxchan->{cq}, $r->{call}, $r->{dxcc}, $r->{itu}, $r->{cq}, $dxchan->{state}, $r->{state});
199 dbg("PCPROT: Rejected by output route filter") if isdbg('chanerr');
202 $thing->{hops} = $hops if $hops;
203 } elsif ($dxchan->{isolate}) {
215 $node->add_user($user, $flag);
216 my $ur = upd_user_rec($user, $node);
223 my $parentcall = shift;
225 # add this station to the user database, if required
226 $call =~ s/-\d+$//o; # remove ssid for users
227 my $user = DXUser->get_current($call);
228 $user = DXUser->new($call) if !$user;
229 $user->homenode($parentcall) if !$user->homenode;
230 $user->node($parentcall);
231 $user->lastin($main::systime) unless DXChannel->get($call);