+
+ my $ref = Route::Node::get($to);
+ my $dxchan = $ref->dxchan;
+ if ($dxchan && $dxchan->is_clx) {
+ route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
+ } else {
+ route(undef, $to, pc34($main::mycall, $to, $cmd));
+ }
+}
+
+sub disconnect
+{
+ my $self = shift;
+ my $pc39flag = shift;
+ my $call = $self->call;
+
+ return if $self->{disconnecting}++;
+
+ unless ($pc39flag && $pc39flag == 1) {
+ $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
+ }
+
+ # get rid of any PC16/17/19
+ eph_del_regex("^PC1[679]*$call");
+
+ # do routing stuff, remove me from routing table
+ my $node = Route::Node::get($call);
+ my @rout;
+ if ($node) {
+ @rout = $node->del($main::routeroot);
+
+ # and all my ephemera as well
+ for (@rout) {
+ my $c = $_->call;
+ eph_del_regex("^PC1[679].*$c");
+ }
+ }
+
+ # remove them from the pc19list as well
+ while (my ($k,$v) = each %pc19list) {
+ my @l = grep {$_->[0] ne $call} @{$pc19list{$k}};
+ if (@l) {
+ $pc19list{$k} = \@l;
+ } else {
+ delete $pc19list{$k};
+ }
+
+ # and the ephemera
+ eph_del_regex("^PC1[679].*$k");
+ }
+
+ # unbusy and stop and outgoing mail
+ my $mref = DXMsg::get_busy($call);
+ $mref->stop_msg($call) if $mref;
+
+ # broadcast to all other nodes that all the nodes connected to via me are gone
+ unless ($pc39flag && $pc39flag == 2) {
+ $self->route_pc21($main::mycall, undef, @rout) if @rout;
+ }
+
+ # remove outstanding pings
+ delete $pings{$call};
+
+ # I was the last node visited
+ $self->user->node($main::mycall);
+
+ # send info to all logged in thingies
+ $self->tell_login('logoutn');
+
+ Log('DXProt', $call . " Disconnected");
+
+ $self->SUPER::disconnect;
+}
+
+
+#
+# send a talk message to this thingy
+#
+sub talk
+{
+ my ($self, $from, $to, $via, $line, $origin) = @_;
+
+ $line =~ s/\^/\\5E/g; # remove any ^ characters
+ $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
+ Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
+}
+
+# send it if it isn't the except list and isn't isolated and still has a hop count
+# taking into account filtering and so on
+
+sub send_route
+{
+ my $self = shift;
+ my $origin = shift;
+ my $generate = shift;
+ my $no = shift; # the no of things to filter on
+ my $routeit;
+ my ($filter, $hops);
+ my @rin;
+
+ for (; @_ && $no; $no--) {
+ my $r = shift;
+
+ if (!$self->{isolate} && $self->{routefilter}) {
+ $filter = undef;
+ if ($r) {
+ ($filter, $hops) = $self->{routefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq, $self->{state}, $r->{state});
+ if ($filter) {
+ push @rin, $r;
+ } else {
+ dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
+ }
+ } else {
+ dbg("was sent a null value") if isdbg('chanerr');
+ }
+ } else {
+ push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
+ }
+ }
+ if (@rin) {
+ foreach my $line (&$generate(@rin, @_)) {
+ if ($hops) {
+ $routeit = $line;
+ $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
+ } else {
+ $routeit = adjust_hops($self, $line); # adjust its hop count by node name
+ next unless $routeit;
+ }
+
+ $routeit = mungepc91($origin, $routeit) if $self->user->wantpc90;
+ $self->send($routeit);
+ }
+ }
+}
+
+sub broadcast_route
+{
+ my $self = shift;
+ my $origin = shift;
+ my $generate = shift;
+ my $line = shift;
+ my @dxchan = DXChannel::get_all_nodes();
+ my $dxchan;
+
+ unless ($self->{isolate}) {
+ foreach $dxchan (@dxchan) {
+ next if $dxchan == $self;
+ next if $dxchan == $main::me;
+ next unless $dxchan->isa('DXProt');
+ next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
+
+ if ($self->user->wantpc90 && $line) {
+ $dxchan->send(mungepc91($origin, $line));
+ } else {
+ $dxchan->send_route($origin, $generate, @_);
+ }
+ }
+ }
+}
+
+sub route_pc16
+{
+ my $self = shift;
+ return unless $self->user->wantpc16;
+ my $origin = shift;
+ my $line = shift;
+ broadcast_route($self, $origin, \&pc16, $line, 1, @_);
+}
+
+sub route_pc17
+{
+ my $self = shift;
+ return unless $self->user->wantpc16;
+ my $origin = shift;
+ my $line = shift;
+ broadcast_route($self, $origin, \&pc17, $line, 1, @_);
+}
+
+sub route_pc19
+{
+ my $self = shift;
+ my $origin = shift;
+ my $line = shift;
+ broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
+}
+
+sub route_pc21
+{
+ my $self = shift;
+ my $origin = shift;
+ my $line = shift;
+ broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
+}
+
+sub route_pc24
+{
+ my $self = shift;
+ my $origin = shift;
+ my $line = shift;
+ broadcast_route($self, $origin, \&pc24, $line, 1, @_);
+}
+
+sub route_pc41
+{
+ my $self = shift;
+ my $origin = shift;
+ my $line = shift;
+ broadcast_route($self, $origin, \&pc41, $line, 1, @_);
+}
+
+sub route_pc50
+{
+ my $self = shift;
+ my $origin = shift;
+ my $line = shift;
+ broadcast_route($self, $origin, \&pc50, $line, 1, @_);
+}
+
+sub in_filter_route
+{
+ my $self = shift;
+ my $r = shift;
+ my ($filter, $hops) = (1, 1);
+
+ if ($self->{inroutefilter}) {
+ ($filter, $hops) = $self->{inroutefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq, $self->state, $r->state);
+ dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
+ }
+ return $filter;
+}
+
+sub eph_dup
+{
+ my $s = shift;
+ my $t = shift || $eph_restime;
+ my $r;
+
+ # chop the end off
+ $s =~ s/\^H\d\d?\^?\~?$//;
+ removepc90($s);
+ $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
+ $eph{$s} = $main::systime + $t;
+ return $r;
+}
+
+sub eph_del_regex
+{
+ my $regex = shift;
+ my ($key, $val);
+ while (($key, $val) = each %eph) {
+ if ($key =~ m{$regex}) {
+ delete $eph{$key};
+ }
+ }
+}
+
+sub eph_clean
+{
+ my ($key, $val);
+
+ while (($key, $val) = each %eph) {
+ if ($main::systime >= $val) {
+ delete $eph{$key};
+ }
+ }
+}
+
+sub eph_list
+{
+ my ($key, $val);
+ my @out;
+
+ while (($key, $val) = each %eph) {
+ push @out, $key, $val;
+ }
+ return @out;
+}
+
+sub run_cmd
+{
+ goto &DXCommandmode::run_cmd;