3 # This module impliments the protocal mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
41 use vars qw($VERSION $BRANCH);
42 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
43 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
44 $main::build += $VERSION;
45 $main::branch += $BRANCH;
47 use vars qw($pc11_max_age $pc23_max_age $last_pc50 $eph_restime $eph_info_restime $eph_pc34_restime
48 $last_hour $last10 %eph %pings %rcmds $ann_to_talk
49 $pingint $obscount %pc19list $chatdupeage $chatimportfn
50 $investigation_int $pc19_version $myprot_version
51 %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
52 $allowzero $decode_dk0wcy $send_opernam @checklist
55 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
56 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
58 $last_hour = time; # last time I did an hourly periodic update
59 %rcmds = (); # outstanding rcmd requests outbound
60 %nodehops = (); # node specific hop control
61 %pc19list = (); # list of outstanding PC19s that haven't had PC16s on them
63 $censorpc = 1; # Do a BadWords::check on text fields and reject things
64 # loads of 'bad things'
65 $baddx = new DXHash "baddx";
66 $badspotter = new DXHash "badspotter";
67 $badnode = new DXHash "badnode";
68 $last10 = $last_pc50 = time;
72 $eph_info_restime = 60*60;
73 $eph_pc34_restime = 30;
76 $chatdupeage = 20 * 60 * 60;
77 $chatimportfn = "$main::root/chat_import";
78 $investigation_int = 12*60*60; # time between checks to see if we can see this node
79 $pc19_version = 5466; # the visible version no for outgoing PC19s generated from pc59
83 [ qw(i c c m bp bc c) ], # pc10
84 [ qw(i f m d t m c c h) ], # pc11
85 [ qw(i c bm m bm bm p h) ], # pc12
89 undef , # pc16 has to be validated manually
90 [ qw(i c c h) ], # pc17
92 undef , # pc19 has to be validated manually
93 undef , # pc20 no validation
94 [ qw(i c m h) ], # pc21
95 undef , # pc22 no validation
96 [ qw(i d n n n n m c c h) ], # pc23
97 [ qw(i c p h) ], # pc24
98 [ qw(i c c n n) ], # pc25
99 [ qw(i f m d t m c c bc) ], # pc26
100 [ qw(i d n n n n m c c bc) ], # pc27
101 [ qw(i c c m c d t p m bp n p bp bc) ], # pc28
102 [ qw(i c c n m) ], # pc29
103 [ qw(i c c n) ], # pc30
104 [ qw(i c c n) ], # pc31
105 [ qw(i c c n) ], # pc32
106 [ qw(i c c n) ], # pc33
107 [ qw(i c c m) ], # pc34
108 [ qw(i c c m) ], # pc35
109 [ qw(i c c m) ], # pc36
110 [ qw(i c c n m) ], # pc37
111 undef, # pc38 not interested
112 [ qw(i c m) ], # pc39
113 [ qw(i c c m p n) ], # pc40
114 [ qw(i c n m h) ], # pc41
115 [ qw(i c c n) ], # pc42
116 undef, # pc43 don't handle it
117 [ qw(i c c n m m c) ], # pc44
118 [ qw(i c c n m) ], # pc45
119 [ qw(i c c n) ], # pc46
122 [ qw(i c m h) ], # pc49
123 [ qw(i c n h) ], # pc50
124 [ qw(i c c n) ], # pc51
146 [ qw(i d n n n n n n m m m c c h) ], # pc73
157 [ qw(i c c c m) ], # pc84
158 [ qw(i c c c m) ], # pc85
163 [ qw(i c n) ], # pc90
166 # use the entry in the check list to check the field list presented
167 # return OK if line NOT in check list (for now)
172 return 0 if $n < 0 || $n > @checklist;
173 my $ref = $checklist[$n];
174 return 0 unless ref $ref;
177 for ($i = 1; $i < @$ref; $i++) {
178 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
179 return 0 unless $act;
180 next if $blank && $_[$i] =~ /^[ \*]$/;
182 return $i unless is_callsign($_[$i]);
183 } elsif ($act eq 'i') {
185 } elsif ($act eq 'm') {
186 return $i unless is_pctext($_[$i]);
187 } elsif ($act eq 'p') {
188 return $i unless is_pcflag($_[$i]);
189 } elsif ($act eq 'f') {
190 return $i unless is_freq($_[$i]);
191 } elsif ($act eq 'n') {
192 return $i unless $_[$i] =~ /^[\d ]+$/;
193 } elsif ($act eq 'h') {
194 return $i unless $_[$i] =~ /^H\d\d?$/;
195 } elsif ($act eq 'd') {
196 return $i unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
197 } elsif ($act eq 't') {
198 return $i unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
206 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
209 my $user = DXUser->get($main::mycall);
210 die "User $main::mycall not setup or disappeared RTFM" unless $user;
212 $myprot_version += $main::version*100;
213 $main::me = DXProt->new($main::mycall, 0, $user);
214 $main::me->{here} = 1;
215 $main::me->{state} = "indifferent";
216 $main::me->{sort} = 'S'; # S for spider
217 $main::me->{priv} = 9;
218 $main::me->{metric} = 0;
219 $main::me->{pingave} = 0;
220 $main::me->{registered} = 1;
221 $main::me->{version} = $main::version;
222 $main::me->{build} = $main::build;
226 # obtain a new connection this is derived from dxchannel
231 my $self = DXChannel::alloc(@_);
233 # add this node to the table, the values get filled in later
236 $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
241 # this is how a pc connection starts (for an incoming connection)
242 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
243 # all the crap that comes between).
246 my ($self, $line, $sort) = @_;
247 my $call = $self->{call};
248 my $user = $self->{user};
251 my $host = $self->{conn}->{peerhost};
252 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
255 Log('DXProt', "$call connected from $host");
257 # remember type of connection
258 $self->{consort} = $line;
259 $self->{outbound} = $sort eq 'O';
260 my $priv = $user->priv;
261 $priv = $user->priv(1) unless $priv;
262 $self->{priv} = $priv; # other clusters can always be 'normal' users
263 $self->{lang} = $user->lang || 'en';
264 $self->{isolate} = $user->{isolate};
265 $self->{consort} = $line; # save the connection type
269 # sort out registration
270 $self->{registered} = 1;
272 # get the output filters
273 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
274 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
275 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
276 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
277 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
280 # get the INPUT filters (these only pertain to Clusters)
281 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
282 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
283 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
284 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
285 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
287 # set unbuffered and no echo
288 $self->send_now('B',"0");
289 $self->send_now('E',"0");
290 $self->conn->echo(0) if $self->conn->can('echo');
292 # ping neighbour node stuff
293 my $ping = $user->pingint;
294 $ping = $pingint unless defined $ping;
295 $self->{pingint} = $ping;
296 $self->{nopings} = $user->nopings || $obscount;
297 $self->{pingtime} = [ ];
298 $self->{pingave} = 999;
299 $self->{metric} ||= 100;
300 $self->{lastping} = $main::systime;
302 # send initialisation string
303 unless ($self->{outbound}) {
307 $self->state('init');
308 $self->{pc50_t} = $main::systime;
310 # send info to all logged in thingies
311 $self->tell_login('loginn');
313 # run a script send the output to the debug file
314 my $script = new Script(lc $call) || new Script('node_default');
315 $script->run($self) if $script;
319 # send outgoing 'challenge'
329 # This is the normal pcxx despatcher
333 my ($self, $line) = @_;
335 if ($line =~ '^<\w+\s' && $main::do_xml) {
336 DXXml::normal($self, $line);
340 my @field = split /\^/, $line;
341 return unless @field;
343 pop @field if $field[-1] eq '~';
345 # print join(',', @field), "\n";
348 # process PC frames, this will fail unless the frame starts PCnn
349 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
350 unless (defined $pcno && $pcno >= 10 && $pcno <= 99) {
351 dbg("PCPROT: unknown protocol") if isdbg('chanerr');
355 # check for and dump bad protocol messages
356 my $n = check($pcno, @field);
358 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
362 # modify the hop count here
363 if (my ($hops, $trail) = $line =~ /\^H(\d+)(\^?\~?)?$/) {
367 $line =~ s/\^H(\d+)(\^?\~?)?$/sprintf('^H%d%s', $hops, $trail)/e;
368 $field[-1] = "H$hops";
371 # send it out for processing
372 my $origin = $self->{call};
374 my $sub = "handle_$pcno";
376 if ($self->can($sub)) {
377 $self->$sub($pcno, $line, $origin, @field);
379 $self->handle_default($pcno, $line, $origin, @field);
384 # This is called from inside the main cluster processing loop and is used
385 # for despatching commands that are doing some long processing job
390 my @dxchan = DXChannel::get_all();
394 # send out a pc50 on EVERY channel all at once
395 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
396 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
401 foreach $dxchan (@dxchan) {
402 next unless $dxchan->is_node;
403 next if $dxchan->handle_xml;
404 next if $dxchan == $main::me;
407 $dxchan->send($pc50s) if $pc50s;
409 # send a ping out on this channel
410 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
411 if ($dxchan->{nopings} <= 0) {
414 DXXml::Ping::add($main::me, $dxchan->call);
415 $dxchan->{nopings} -= 1;
416 $dxchan->{lastping} = $t;
417 $dxchan->{lastping} += $dxchan->{pingint} / 2 unless @{$dxchan->{pingtime}};
422 Investigate::process();
425 if ($t - $last10 >= 10) {
435 if ($main::systime - 3600 > $last_hour) {
436 $last_hour = $main::systime;
441 # finish up a pc context
445 # some active measures
453 my @dxchan = DXChannel::get_all();
456 # send it if it isn't the except list and isn't isolated and still has a hop count
457 # taking into account filtering and so on
458 foreach $dxchan (@dxchan) {
459 next if $dxchan == $main::me;
460 next if $dxchan == $self && $self->is_node;
461 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
472 if ($self->{spotsfilter}) {
473 ($filter, $hops) = $self->{spotsfilter}->it(@_);
474 return unless $filter;
476 send_prot_line($self, $filter, $hops, $isolate, $line);
481 my ($self, $filter, $hops, $isolate, $line) = @_;
487 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
489 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
490 return unless $routeit;
493 $self->send($routeit);
495 $self->send($routeit) unless $self->{isolate} || $isolate;
504 my @dxchan = DXChannel::get_all();
506 my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
508 # send it if it isn't the except list and isn't isolated and still has a hop count
509 # taking into account filtering and so on
510 foreach $dxchan (@dxchan) {
511 next if $dxchan == $main::me;
512 next if $dxchan == $self && $self->is_node;
516 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
527 if ($self->{wwvfilter}) {
528 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_]);
529 return unless $filter;
531 send_prot_line($self, $filter, $hops, $isolate, $line)
538 my @dxchan = DXChannel::get_all();
540 my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
542 # send it if it isn't the except list and isn't isolated and still has a hop count
543 # taking into account filtering and so on
544 foreach $dxchan (@dxchan) {
545 next if $dxchan == $main::me;
546 next if $dxchan == $self;
548 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
559 if ($self->{wcyfilter}) {
560 ($filter, $hops) = $self->{wcyfilter}->it(@_);
561 return unless $filter;
563 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
571 my @dxchan = DXChannel::get_all();
575 my $text = unpad($_[2]);
577 if ($_[3] eq '*') { # sysops
579 } elsif ($_[3] gt ' ') { # speciality list handling
580 my ($name) = split /\./, $_[3];
581 $target = "$name"; # put the rest in later (if bothered)
588 $target = "ALL" if !$target;
591 # obtain country codes etc
592 my @a = Prefix::cty_data($_[0]);
593 my @b = Prefix::cty_data($_[4]);
594 if ($self->{inannfilter}) {
595 my ($filter, $hops) =
596 $self->{inannfilter}->it(@_, $self->{call},
598 @b[0..2], $a[3], $b[3]);
600 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
605 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
606 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
610 Log('ann', $target, $_[0], $text);
612 # send it if it isn't the except list and isn't isolated and still has a hop count
613 # taking into account filtering and so on
614 foreach $dxchan (@dxchan) {
615 next if $dxchan == $main::me;
616 next if $dxchan == $self && $self->is_node;
617 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
627 $msgid = 1 if $msgid > 999;
636 my @dxchan = DXChannel::get_all();
639 my $text = unpad($_[2]);
642 # munge the group and recast the line if required
643 if ($target =~ s/\.LST$//) {
647 # obtain country codes etc
648 my @a = Prefix::cty_data($_[0]);
649 my @b = Prefix::cty_data($_[4]);
650 if ($self->{inannfilter}) {
651 my ($filter, $hops) =
652 $self->{inannfilter}->it(@_, $self->{call},
654 @b[0..2], $a[3], $b[3]);
656 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
661 if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
662 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
667 Log('chat', $target, $_[0], $text);
669 # send it if it isn't the except list and isn't isolated and still has a hop count
670 # taking into account filtering and so on
671 foreach $dxchan (@dxchan) {
672 my $is_ak1a = $dxchan->is_ak1a;
674 if ($dxchan->is_node) {
675 next if $dxchan == $main::me;
676 next if $dxchan == $self;
677 next unless $dxchan->is_spider || $is_ak1a;
678 next if $target eq 'LOCAL';
679 if (!$ak1a_line && $is_ak1a) {
680 $ak1a_line = DXProt::pc12($_[0], $text, $_[1], "$target.LST");
684 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1],
685 $text, @_, $self->{call}, @a[0..2], @b[0..2]);
699 if ($self->{annfilter}) {
700 ($filter, $hops) = $self->{annfilter}->it(@_);
701 return unless $filter;
703 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
712 sub send_local_config
716 dbg('DXProt::send_local_config') if isdbg('trace');
719 if ($self->{do_pc92}) {
720 $self->send_pc92_config;
727 if ($self->{isolate}) {
728 @localnodes = ( $main::routeroot );
729 $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
731 # create a list of all the nodes that are not connected to this connection
732 # and are not themselves isolated, this to make sure that isolated nodes
733 # don't appear outside of this node
735 # send locally connected nodes
736 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
737 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
738 $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
741 my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
743 for $node (@rawintcalls) {
744 push @intcalls, $node unless grep $node eq $_, @intcalls;
746 my $ref = Route::Node::get($self->{call});
747 my @rnodes = $ref->nodes;
748 for $node (@intcalls) {
749 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
751 $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
754 # get all the users connected on the above nodes and send them out
755 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
757 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
758 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
760 dbg("sent a null value") if isdbg('chanerr');
771 dbg('DXProt::send_pc92_config') if isdbg('trace');
773 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all();
774 my @localnodes = map { my $r = Route::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
775 $self->send_route_pc92($main::mycall, \&pc92c, scalar @localnodes, @localnodes);
779 # route a message down an appropriate interface for a callsign
781 # is called route(to, pcline);
786 my ($self, $call, $line) = @_;
788 if (ref $self && $call eq $self->{call}) {
789 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
793 # always send it down the local interface if available
794 my $dxchan = DXChannel::get($call);
796 dbg("route: $call -> $dxchan->{call} direct" ) if isdbg('route');
798 my $cl = Route::get($call);
799 $dxchan = $cl->dxchan if $cl;
801 if (ref $self && $dxchan eq $self) {
802 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
805 dbg("route: $call -> $dxchan->{call} using normal route" ) if isdbg('route');
809 # try the backstop method
811 my $rcall = RouteDB::get($call);
813 if ($self && $rcall eq $self->{call}) {
814 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
817 $dxchan = DXChannel::get($rcall);
818 dbg("route: $call -> $rcall using RouteDB" ) if isdbg('route') && $dxchan;
823 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
825 $dxchan->send($routeit) unless $dxchan == $main::me;
828 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
833 # obtain the hops from the list for this callsign and pc no
839 my $hops = $DXProt::hopcount{$pcno};
840 $hops = $DXProt::def_hopcount if !$hops;
845 # adjust the hop count on a per node basis using the user loadable
846 # hop table if available or else decrement an existing one
853 my $call = $self->{call};
856 if (($hops) = $s =~ /\^H(\d+)\^?~?$/o) {
857 my ($pcno) = $s =~ /^PC(\d\d)/o;
858 confess "$call called adjust_hops with '$s'" unless $pcno;
859 my $ref = $nodehops{$call} if %nodehops;
861 my $newhops = $ref->{$pcno};
862 return "" if defined $newhops && $newhops == 0;
863 $newhops = $ref->{default} unless $newhops;
864 return "" if defined $newhops && $newhops == 0;
865 $newhops = $hops if !$newhops;
866 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
878 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
879 do "$main::data/hop_table.pl";
886 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
887 if ($tonode eq $main::mycall) {
888 my $ref = DXUser->get_current($fromnode);
889 my $cref = Route::Node::get($fromnode);
890 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
891 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
892 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
893 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
894 my $oldpriv = $self->{priv};
895 $self->{priv} = $ref->{priv}; # assume the user's privilege level
896 my @in = (DXCommandmode::run_cmd($self, $cmd));
897 $self->{priv} = $oldpriv;
898 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
899 delete $self->{remotecmd};
901 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
904 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
907 my $ref = DXUser->get_current($tonode);
908 if ($ref && $ref->is_clx) {
909 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
911 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
916 sub process_rcmd_reply
918 my ($self, $tonode, $fromnode, $user, $line) = @_;
919 if ($tonode eq $main::mycall) {
920 my $s = $rcmds{$fromnode};
922 my $dxchan = DXChannel::get($s->{call});
923 my $ref = $user eq $tonode ? $dxchan : (DXChannel::get($user) || $dxchan);
924 $ref->send($line) if $ref;
925 delete $rcmds{$fromnode} if !$dxchan;
927 # send unsolicited ones to the sysop
928 my $dxchan = DXChannel::get($main::myalias);
929 $dxchan->send($line) if $dxchan;
932 my $ref = DXUser->get_current($tonode);
933 if ($ref && $ref->is_clx) {
934 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
936 $self->route($tonode, pc35($fromnode, $tonode, $line));
945 my $fromnode = shift;
950 Log('rcmd', 'out', $fromnode, $line);
952 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
954 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
959 # add a rcmd request to the rcmd queues
962 my ($self, $to, $cmd) = @_;
965 $r->{call} = $self->{call};
966 $r->{t} = $main::systime;
970 my $ref = Route::Node::get($to);
971 my $dxchan = $ref->dxchan;
972 if ($dxchan && $dxchan->is_clx) {
973 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
975 route(undef, $to, pc34($main::mycall, $to, $cmd));
982 my $pc39flag = shift;
983 my $call = $self->call;
985 return if $self->{disconnecting}++;
987 unless ($pc39flag && $pc39flag == 1) {
988 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
991 # get rid of any PC16/17/19
992 eph_del_regex("^PC1[679]*$call");
994 # do routing stuff, remove me from routing table
995 my $node = Route::Node::get($call);
998 @rout = $node->del($main::routeroot);
1000 # and all my ephemera as well
1003 eph_del_regex("^PC1[679].*$c");
1007 RouteDB::delete_interface($call);
1009 # unbusy and stop and outgoing mail
1010 my $mref = DXMsg::get_busy($call);
1011 $mref->stop_msg($call) if $mref;
1013 # broadcast to all other nodes that all the nodes connected to via me are gone
1014 unless ($pc39flag && $pc39flag == 2) {
1015 $self->route_pc21($main::mycall, undef, @rout) if @rout;
1016 $self->route_pc92d($main::mycall, undef, $node) if $node;
1019 # remove outstanding pings
1020 delete $pings{$call};
1022 # I was the last node visited
1023 $self->user->node($main::mycall);
1025 # send info to all logged in thingies
1026 $self->tell_login('logoutn');
1028 Log('DXProt', $call . " Disconnected");
1030 $self->SUPER::disconnect;
1035 # send a talk message to this thingy
1039 my ($self, $from, $to, $via, $line, $origin) = @_;
1041 $line =~ s/\^/\\5E/g; # remove any ^ characters
1042 $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
1043 Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
1046 # send it if it isn't the except list and isn't isolated and still has a hop count
1047 # taking into account filtering and so on
1053 my $generate = shift;
1054 my $no = shift; # the no of things to filter on
1056 my ($filter, $hops);
1059 for (; @_ && $no; $no--) {
1062 if (!$self->{isolate} && $self->{routefilter}) {
1065 ($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});
1069 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
1072 dbg("was sent a null value") if isdbg('chanerr');
1075 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
1079 foreach my $line (&$generate(@rin, @_)) {
1082 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1084 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1085 next unless $routeit;
1088 $self->send($routeit);
1097 my $generate = shift;
1099 my @dxchan = DXChannel::get_all_nodes();
1103 $line =~ /\^H(\d+)\^?\~?$/;
1104 return unless $1 > 0;
1106 unless ($self->{isolate}) {
1107 foreach $dxchan (@dxchan) {
1108 next if $dxchan == $self;
1109 next if $dxchan == $main::me;
1110 next unless $dxchan->isa('DXProt');
1111 next if $dxchan->{do_pc92};
1112 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
1114 $dxchan->send_route($origin, $generate, @_);
1119 # this is only used for next door nodes on init
1124 return unless $self->{do_pc92};
1127 my $generate = shift;
1128 my $no = shift; # the no of things to filter on
1131 $line = &$generate(@_);
1135 sub broadcast_route_pc9x
1139 my $generate = shift;
1142 my @dxchan = DXChannel::get_all_nodes();
1145 if ($origin eq $main::mycall) {
1146 $line = &$generate(@_);
1149 $line =~ /\^H(\d+)\^\~?$/;
1150 unless ($1 > 0 && $self->{isolate}) {
1151 foreach $dxchan (@dxchan) {
1152 next if $dxchan == $self;
1153 next if $dxchan == $main::me;
1154 next unless $dxchan->{do_pc92};
1155 next unless $dxchan->isa('DXProt');
1157 $dxchan->send($line);
1165 return unless $self->user->wantpc16;
1168 broadcast_route($self, $origin, \&pc16, $line, 1, @_);
1174 return unless $self->user->wantpc16;
1177 broadcast_route($self, $origin, \&pc17, $line, 1, @_);
1185 broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
1193 broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
1201 broadcast_route($self, $origin, \&pc24, $line, 1, @_);
1209 broadcast_route($self, $origin, \&pc41, $line, 1, @_);
1217 broadcast_route($self, $origin, \&pc50, $line, 1, @_);
1225 broadcast_route_pc9x($self, $origin, \&pc92c, $line, 1, @_);
1233 broadcast_route_pc9x($self, $origin, \&pc92a, $line, 1, @_);
1241 broadcast_route_pc9x($self, $origin, \&pc92d, $line, 1, @_);
1248 my ($filter, $hops) = (1, 1);
1250 if ($self->{inroutefilter}) {
1251 ($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);
1252 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
1260 my $t = shift || $eph_restime;
1264 $s =~ s/\^H\d\d?\^?\~?$//;
1265 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
1266 $eph{$s} = $main::systime + $t;
1267 dbg("PCPROT: emphemeral duplicate") if $r && isdbg('chanerr');
1275 while (($key, $val) = each %eph) {
1276 if ($key =~ m{$regex}) {
1286 while (($key, $val) = each %eph) {
1287 if ($main::systime >= $val) {
1298 while (($key, $val) = each %eph) {
1299 push @out, $key, $val;
1306 goto &DXCommandmode::run_cmd;
1310 # import any msgs in the chat directory
1311 # the messages are sent to the chat group which forms the
1312 # the first part of the name (eg: solar.1243.txt would be
1313 # sent to chat group SOLAR)
1315 # Each message found is sent: one non-blank line to one chat
1316 # message. So 4 lines = 4 chat messages.
1318 # The special name LOCAL is for local users ANN
1319 # The special name ALL is for ANN/FULL
1320 # The special name SYSOP is for ANN/SYSOP
1324 # are there any to do in this directory?
1325 return unless -d $chatimportfn;
1326 unless (opendir(DIR, $chatimportfn)) {
1327 dbg("can\'t open $chatimportfn $!") if isdbg('msg');
1328 Log('msg', "can\'t open $chatimportfn $!");
1332 my @names = readdir(DIR);
1335 foreach $name (@names) {
1336 next if $name =~ /^\./;
1337 my $splitit = $name =~ /^split/;
1338 my $fn = "$chatimportfn/$name";
1340 unless (open(MSG, $fn)) {
1341 dbg("can\'t open import file $fn $!") if isdbg('msg');
1342 Log('msg', "can\'t open import file $fn $!");
1346 my @msg = map { s/\r?\n$//; $_ } <MSG>;
1350 my @cat = split /\./, $name;
1351 my $target = uc $cat[0];
1353 foreach my $text (@msg) {
1354 next unless $text && $text !~ /^\s*#/;
1355 if ($target eq 'ALL' || $target eq 'LOCAL' || $target eq 'SYSOP') {
1356 my $sysopflag = $target eq 'SYSOP' ? '*' : ' ';
1357 if ($target ne 'LOCAL') {
1358 send_announce($main::me, pc12($main::mycall, $text, '*', $sysopflag), $main::mycall, '*', $text, $sysopflag, $main::mycall, '0');
1360 Log('ann', 'LOCAL', $main::mycall, $text);
1361 DXChannel::broadcast_list("To LOCAL de ${main::mycall}: $text\a", 'ann', undef, DXCommandmode->get_all());
1364 my $msgid = nextchatmsgid();
1365 $text = "#$msgid $text";
1366 send_chat($main::me, pc12($main::mycall, $text, '*', $target), $main::mycall, '*', $text, $target, $main::mycall, '0');