+ $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;
+ }
+
+ $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;
+
+ if ($line) {
+ $line =~ /\^H(\d+)\^?\~?$/;
+ return unless $1 > 0;
+ }
+ unless ($self->{isolate}) {
+ foreach $dxchan (@dxchan) {
+ next if $dxchan == $self;
+ next if $dxchan == $main::me;
+ next unless $dxchan->isa('DXProt');
+ next if $dxchan->{do_pc92};
+ next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
+
+ $dxchan->send_route($origin, $generate, @_);
+ }
+ }
+}
+
+# this is only used for next door nodes on init
+sub send_route_pc92
+{
+ my $self = shift;
+
+ return unless $self->{do_pc92};
+
+ my $origin = shift;
+ my $generate = shift;
+ my $no = shift; # the no of things to filter on
+ my $line;
+
+ $line = &$generate(@_);
+ $self->send($line);
+}
+
+sub broadcast_route_pc9x
+{
+ my $self = shift;
+ my $origin = shift;
+ my $generate = shift;
+ my $line = shift;
+ my $no = shift;
+ my @dxchan = DXChannel::get_all_nodes();
+ my $dxchan;
+
+ if ($origin eq $main::mycall) {
+ $line = &$generate(@_);
+ }
+
+ $line =~ /\^H(\d+)\^\~?$/;
+ unless ($1 > 0 && $self->{isolate}) {
+ foreach $dxchan (@dxchan) {
+ next if $dxchan == $self || $main::me;
+ next if $origin eq $dxchan->{call}; # don't route some from this call back again.
+ next unless $dxchan->{do_pc92};
+ next unless $dxchan->isa('DXProt');
+
+ $dxchan->send($line);
+ }
+ }
+}
+
+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 route_pc92c
+{
+ my $self = shift;
+ my $origin = shift;
+ my $line = shift;
+ broadcast_route_pc9x($self, $origin, \&pc92c, $line, 1, @_);
+}
+
+sub route_pc92a
+{
+ my $self = shift;
+ my $origin = shift;
+ my $line = shift;
+ broadcast_route_pc9x($self, $origin, \&pc92a, $line, 1, @_);
+}
+
+sub route_pc92d
+{
+ my $self = shift;
+ my $origin = shift;
+ my $line = shift;
+ broadcast_route_pc9x($self, $origin, \&pc92d, $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?\^?\~?$//;
+ $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
+ $eph{$s} = $main::systime + $t;
+ dbg("PCPROT: emphemeral duplicate") if $r && isdbg('chanerr');
+ 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;
+}
+
+
+# import any msgs in the chat directory
+# the messages are sent to the chat group which forms the
+# the first part of the name (eg: solar.1243.txt would be
+# sent to chat group SOLAR)
+#
+# Each message found is sent: one non-blank line to one chat
+# message. So 4 lines = 4 chat messages.
+#
+# The special name LOCAL is for local users ANN
+# The special name ALL is for ANN/FULL
+# The special name SYSOP is for ANN/SYSOP
+#
+sub import_chat
+{
+ # are there any to do in this directory?
+ return unless -d $chatimportfn;
+ unless (opendir(DIR, $chatimportfn)) {
+ dbg("can\'t open $chatimportfn $!") if isdbg('msg');
+ Log('msg', "can\'t open $chatimportfn $!");
+ return;
+ }
+
+ my @names = readdir(DIR);
+ closedir(DIR);
+ my $name;
+ foreach $name (@names) {
+ next if $name =~ /^\./;
+ my $splitit = $name =~ /^split/;
+ my $fn = "$chatimportfn/$name";
+ next unless -f $fn;
+ unless (open(MSG, $fn)) {
+ dbg("can\'t open import file $fn $!") if isdbg('msg');
+ Log('msg', "can\'t open import file $fn $!");
+ unlink($fn);
+ next;
+ }
+ my @msg = map { s/\r?\n$//; $_ } <MSG>;
+ close(MSG);
+ unlink($fn);
+
+ my @cat = split /\./, $name;
+ my $target = uc $cat[0];
+
+ foreach my $text (@msg) {
+ next unless $text && $text !~ /^\s*#/;
+ if ($target eq 'ALL' || $target eq 'LOCAL' || $target eq 'SYSOP') {
+ my $sysopflag = $target eq 'SYSOP' ? '*' : ' ';
+ if ($target ne 'LOCAL') {
+ send_announce($main::me, pc12($main::mycall, $text, '*', $sysopflag), $main::mycall, '*', $text, $sysopflag, $main::mycall, '0');
+ } else {
+ Log('ann', 'LOCAL', $main::mycall, $text);
+ DXChannel::broadcast_list("To LOCAL de ${main::mycall}: $text\a", 'ann', undef, DXCommandmode->get_all());
+ }
+ } else {
+ my $msgid = nextchatmsgid();
+ $text = "#$msgid $text";
+ send_chat($main::me, pc12($main::mycall, $text, '*', $target), $main::mycall, '*', $text, $target, $main::mycall, '0');
+ }
+ }
+ }