3 # This module impliments the protocal mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
40 use vars qw($VERSION $BRANCH);
41 use vars qw($pc11_max_age $pc23_max_age $last_pc50 $eph_restime $eph_info_restime $eph_pc34_restime
42 $last_hour $last10 %eph %pings %rcmds $ann_to_talk
43 $pingint $obscount %pc19list $chatdupeage $chatimportfn
44 $investigation_int $pc19_version $myprot_version
45 %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
46 $allowzero $decode_dk0wcy $send_opernam @checklist
47 $eph_pc15_restime $pc92_update_period $last_pc92_update
50 ($VERSION, $BRANCH) = dxver(q$Revision$);
52 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
53 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
55 $last_hour = time; # last time I did an hourly periodic update
56 %rcmds = (); # outstanding rcmd requests outbound
57 %nodehops = (); # node specific hop control
58 %pc19list = (); # list of outstanding PC19s that haven't had PC16s on them
60 $censorpc = 1; # Do a BadWords::check on text fields and reject things
61 # loads of 'bad things'
62 $baddx = new DXHash "baddx";
63 $badspotter = new DXHash "badspotter";
64 $badnode = new DXHash "badnode";
65 $last10 = $last_pc50 = time;
69 $eph_info_restime = 60*60;
70 $eph_pc15_restime = 6*60;
71 $eph_pc34_restime = 30;
74 $chatdupeage = 20 * 60 * 60;
75 $chatimportfn = "$main::root/chat_import";
76 $investigation_int = 12*60*60; # time between checks to see if we can see this node
77 $pc19_version = 5466; # the visible version no for outgoing PC19s generated from pc59
78 $pc92_update_period = 30*60; # the period between PC92 C updates
79 $last_pc92_update = time + int rand(180); # the last time a PC92 config update
84 [ qw(i c c m bp bc c) ], # pc10
85 [ qw(i f m d t m c c h) ], # pc11
86 [ qw(i c bm m bm bm p h) ], # pc12
90 undef , # pc16 has to be validated manually
91 [ qw(i c c h) ], # pc17
93 undef , # pc19 has to be validated manually
94 undef , # pc20 no validation
95 [ qw(i c m h) ], # pc21
96 undef , # pc22 no validation
97 [ qw(i d n n n n m c c h) ], # pc23
98 [ qw(i c p h) ], # pc24
99 [ qw(i c c n n) ], # pc25
100 [ qw(i f m d t m c c bc) ], # pc26
101 [ qw(i d n n n n m c c bc) ], # pc27
102 [ qw(i c c m c d t p m bp n p bp bc) ], # pc28
103 [ qw(i c c n m) ], # pc29
104 [ qw(i c c n) ], # pc30
105 [ qw(i c c n) ], # pc31
106 [ qw(i c c n) ], # pc32
107 [ qw(i c c n) ], # pc33
108 [ qw(i c c m) ], # pc34
109 [ qw(i c c m) ], # pc35
110 [ qw(i c c m) ], # pc36
111 [ qw(i c c n m) ], # pc37
112 undef, # pc38 not interested
113 [ qw(i c m) ], # pc39
114 [ qw(i c c m p n) ], # pc40
115 [ qw(i c n m h) ], # pc41
116 [ qw(i c c n) ], # pc42
117 undef, # pc43 don't handle it
118 [ qw(i c c n m m c) ], # pc44
119 [ qw(i c c n m) ], # pc45
120 [ qw(i c c n) ], # pc46
123 [ qw(i c m h) ], # pc49
124 [ qw(i c n h) ], # pc50
125 [ qw(i c c n) ], # pc51
147 [ qw(i d n n n n n n m m m c c h) ], # pc73
158 [ qw(i c c c m) ], # pc84
159 [ qw(i c c c m) ], # pc85
164 [ qw(i c n) ], # pc90
167 # use the entry in the check list to check the field list presented
168 # return OK if line NOT in check list (for now)
173 return 0 if $n < 0 || $n > @checklist;
174 my $ref = $checklist[$n];
175 return 0 unless ref $ref;
178 for ($i = 1; $i < @$ref; $i++) {
179 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
180 return 0 unless $act;
181 next if $blank && $_[$i] =~ /^[ \*]$/;
183 return $i unless is_callsign($_[$i]);
184 } elsif ($act eq 'i') {
186 } elsif ($act eq 'm') {
187 return $i unless is_pctext($_[$i]);
188 } elsif ($act eq 'p') {
189 return $i unless is_pcflag($_[$i]);
190 } elsif ($act eq 'f') {
191 return $i unless is_freq($_[$i]);
192 } elsif ($act eq 'n') {
193 return $i unless $_[$i] =~ /^[\d ]+$/;
194 } elsif ($act eq 'h') {
195 return $i unless $_[$i] =~ /^H\d\d?$/;
196 } elsif ($act eq 'd') {
197 return $i unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
198 } elsif ($act eq 't') {
199 return $i unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
207 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
210 my $user = DXUser->get($main::mycall);
211 die "User $main::mycall not setup or disappeared RTFM" unless $user;
213 $myprot_version += $main::version*100;
214 $main::me = DXProt->new($main::mycall, 0, $user);
215 $main::me->{here} = 1;
216 $main::me->{state} = "indifferent";
217 $main::me->{sort} = 'S'; # S for spider
218 $main::me->{priv} = 9;
219 $main::me->{metric} = 0;
220 $main::me->{pingave} = 0;
221 $main::me->{registered} = 1;
222 $main::me->{version} = $main::version;
223 $main::me->{build} = $main::build;
224 $main::me->{do_pc9x} = 1;
228 # obtain a new connection this is derived from dxchannel
233 my $self = DXChannel::alloc(@_);
235 # add this node to the table, the values get filled in later
239 # if we have an entry already, then send a PC21 to all connect
240 # old style connections, because we are about to get the real deal
241 if (my $ref = Route::Node::get($call)) {
242 dbg("ROUTE: $call is already in the routing table, deleting") if isdbg('route');
243 my @rout = $ref->delete;
244 $self->route_pc21($main::mycall, undef, @rout) if @rout;
246 $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
251 # this is how a pc connection starts (for an incoming connection)
252 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
253 # all the crap that comes between).
256 my ($self, $line, $sort) = @_;
257 my $call = $self->{call};
258 my $user = $self->{user};
261 my $host = $self->{conn}->{peerhost};
262 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
265 Log('DXProt', "$call connected from $host");
267 # remember type of connection
268 $self->{consort} = $line;
269 $self->{outbound} = $sort eq 'O';
270 my $priv = $user->priv;
271 $priv = $user->priv(1) unless $priv;
272 $self->{priv} = $priv; # other clusters can always be 'normal' users
273 $self->{lang} = $user->lang || 'en';
274 $self->{isolate} = $user->{isolate};
275 $self->{consort} = $line; # save the connection type
279 # sort out registration
280 $self->{registered} = 1;
282 # get the output filters
283 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
284 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
285 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
286 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
287 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
290 # get the INPUT filters (these only pertain to Clusters)
291 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
292 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
293 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
294 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
295 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
297 # set unbuffered and no echo
298 $self->send_now('B',"0");
299 $self->send_now('E',"0");
300 $self->conn->echo(0) if $self->conn->can('echo');
302 # ping neighbour node stuff
303 my $ping = $user->pingint;
304 $ping = $pingint unless defined $ping;
305 $self->{pingint} = $ping;
306 $self->{nopings} = $user->nopings || $obscount;
307 $self->{pingtime} = [ ];
308 $self->{pingave} = 999;
309 $self->{metric} ||= 100;
310 $self->{lastping} = $main::systime;
312 # send initialisation string
313 unless ($self->{outbound}) {
317 $self->state('init');
318 $self->{pc50_t} = $main::systime;
320 # send info to all logged in thingies
321 $self->tell_login('loginn');
323 # run a script send the output to the debug file
324 my $script = new Script(lc $call) || new Script('node_default');
325 $script->run($self) if $script;
329 # send outgoing 'challenge'
339 # This is the normal pcxx despatcher
343 my ($self, $line) = @_;
345 if ($line =~ '^<\w+\s' && $main::do_xml) {
346 DXXml::normal($self, $line);
350 my @field = split /\^/, $line;
351 return unless @field;
353 pop @field if $field[-1] eq '~';
355 # print join(',', @field), "\n";
358 # process PC frames, this will fail unless the frame starts PCnn
359 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
360 unless (defined $pcno && $pcno >= 10 && $pcno <= 99) {
361 dbg("PCPROT: unknown protocol") if isdbg('chanerr');
365 # check for and dump bad protocol messages
366 my $n = check($pcno, @field);
368 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
372 # modify the hop count here
373 if ($self != $main::me) {
374 if (my ($hops, $trail) = $line =~ /\^H(\d+)(\^?\~?)?$/) {
378 $line =~ s/\^H(\d+)(\^?\~?)?$/sprintf('^H%d%s', $hops, $trail)/e;
379 $field[-1] = "H$hops";
383 # send it out for processing
384 my $origin = $self->{call};
386 my $sub = "handle_$pcno";
388 if ($self->can($sub)) {
389 $self->$sub($pcno, $line, $origin, @field);
391 $self->handle_default($pcno, $line, $origin, @field);
396 # This is called from inside the main cluster processing loop and is used
397 # for despatching commands that are doing some long processing job
402 my @dxchan = DXChannel::get_all();
406 # send out a pc50 on EVERY channel all at once
407 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
408 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
413 foreach $dxchan (@dxchan) {
414 next unless $dxchan->is_node;
415 next if $dxchan->handle_xml;
416 next if $dxchan == $main::me;
419 $dxchan->send($pc50s) if $pc50s;
421 # send a ping out on this channel
422 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
423 if ($dxchan->{nopings} <= 0) {
426 DXXml::Ping::add($main::me, $dxchan->call);
427 $dxchan->{nopings} -= 1;
428 $dxchan->{lastping} = $t;
429 $dxchan->{lastping} += $dxchan->{pingint} / 2 unless @{$dxchan->{pingtime}};
434 Investigate::process();
437 if ($t - $last10 >= 10) {
443 if ($main::systime >= $last_pc92_update + $pc92_update_period) {
444 dbg("ROUTE: sending pc92 update") if isdbg('route');
446 time_out_pc92_routes();
447 $last_pc92_update = $main::systime + int rand(180);
453 if ($main::systime - 3600 > $last_hour) {
454 $last_hour = $main::systime;
459 # finish up a pc context
463 # some active measures
471 my @dxchan = DXChannel::get_all();
474 # send it if it isn't the except list and isn't isolated and still has a hop count
475 # taking into account filtering and so on
476 foreach $dxchan (@dxchan) {
477 next if $dxchan == $main::me;
478 next if $dxchan == $self && $self->is_node;
479 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
490 if ($self->{spotsfilter}) {
491 ($filter, $hops) = $self->{spotsfilter}->it(@_);
492 return unless $filter;
494 send_prot_line($self, $filter, $hops, $isolate, $line);
499 my ($self, $filter, $hops, $isolate, $line) = @_;
505 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
507 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
508 return unless $routeit;
511 $self->send($routeit);
513 $self->send($routeit) unless $self->{isolate} || $isolate;
522 my @dxchan = DXChannel::get_all();
524 my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
526 # send it if it isn't the except list and isn't isolated and still has a hop count
527 # taking into account filtering and so on
528 foreach $dxchan (@dxchan) {
529 next if $dxchan == $main::me;
530 next if $dxchan == $self && $self->is_node;
534 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
545 if ($self->{wwvfilter}) {
546 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_]);
547 return unless $filter;
549 send_prot_line($self, $filter, $hops, $isolate, $line)
556 my @dxchan = DXChannel::get_all();
558 my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
560 # send it if it isn't the except list and isn't isolated and still has a hop count
561 # taking into account filtering and so on
562 foreach $dxchan (@dxchan) {
563 next if $dxchan == $main::me;
564 next if $dxchan == $self;
566 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
577 if ($self->{wcyfilter}) {
578 ($filter, $hops) = $self->{wcyfilter}->it(@_);
579 return unless $filter;
581 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
588 my $from_pc9x = shift;
590 my @dxchan = DXChannel::get_all();
594 my $text = unpad($_[2]);
596 if ($_[3] eq '*') { # sysops
598 } elsif ($_[3] gt ' ') { # speciality list handling
599 my ($name) = split /\./, $_[3];
600 $target = "$name"; # put the rest in later (if bothered)
607 $target = "ALL" if !$target;
610 # obtain country codes etc
611 my @a = Prefix::cty_data($_[0]);
612 my @b = Prefix::cty_data($_[4]);
613 if ($self->{inannfilter}) {
614 my ($filter, $hops) =
615 $self->{inannfilter}->it(@_, $self->{call},
617 @b[0..2], $a[3], $b[3]);
619 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
624 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
625 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
629 Log('ann', $target, $_[0], $text);
631 # send it if it isn't the except list and isn't isolated and still has a hop count
632 # taking into account filtering and so on
633 foreach $dxchan (@dxchan) {
634 next if $dxchan == $main::me;
635 next if $dxchan == $self && $self->is_node;
636 next if $from_pc9x && $dxchan->{do_pc9x};
637 next if $target eq 'LOCAL' && $dxchan->is_node;
638 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
648 $msgid = 1 if $msgid > 999;
656 my $from_pc9x = shift;
658 my @dxchan = DXChannel::get_all();
661 my $text = unpad($_[2]);
664 # munge the group and recast the line if required
665 if ($target =~ s/\.LST$//) {
669 # obtain country codes etc
670 my @a = Prefix::cty_data($_[0]);
671 my @b = Prefix::cty_data($_[4]);
672 if ($self->{inannfilter}) {
673 my ($filter, $hops) =
674 $self->{inannfilter}->it(@_, $self->{call},
676 @b[0..2], $a[3], $b[3]);
678 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
683 if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
684 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
689 Log('chat', $target, $_[0], $text);
691 # send it if it isn't the except list and isn't isolated and still has a hop count
692 # taking into account filtering and so on
693 foreach $dxchan (@dxchan) {
694 my $is_ak1a = $dxchan->is_ak1a;
696 if ($dxchan->is_node) {
697 next if $dxchan == $main::me;
698 next if $dxchan == $self;
699 next if $from_pc9x && $dxchan->{do_pc9x};
700 next unless $dxchan->is_spider || $is_ak1a;
701 next if $target eq 'LOCAL';
702 if (!$ak1a_line && $is_ak1a) {
703 $ak1a_line = pc12($_[0], $text, $_[1], "$target.LST");
707 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1],
708 $text, @_, $self->{call}, @a[0..2], @b[0..2]);
722 if ($self->{annfilter}) {
723 ($filter, $hops) = $self->{annfilter}->it(@_);
724 return unless $filter;
726 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
735 sub send_local_config
739 dbg('DXProt::send_local_config') if isdbg('trace');
742 if ($self->{do_pc9x}) {
743 $self->send_pc92_config;
750 if ($self->{isolate}) {
751 @localnodes = ( $main::routeroot );
752 $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
754 # create a list of all the nodes that are not connected to this connection
755 # and are not themselves isolated, this to make sure that isolated nodes
756 # don't appear outside of this node
758 # send locally connected nodes
759 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
760 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
761 $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
764 my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
766 for $node (@rawintcalls) {
767 push @intcalls, $node unless grep $node eq $_, @intcalls;
769 my $ref = Route::Node::get($self->{call});
770 my @rnodes = $ref->nodes;
771 for $node (@intcalls) {
772 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
774 $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
777 # get all the users connected on the above nodes and send them out
778 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
780 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
781 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
783 dbg("sent a null value") if isdbg('chanerr');
789 sub gen_my_pc92_config
793 if ($node->{call} eq $main::mycall) {
794 my @dxchan = grep { $_->call ne $main::mycall && !$_->{isolate} } DXChannel::get_all();
795 dbg("ROUTE: all dxchan: " . join(',', map{$_->{call}} @dxchan)) if isdbg('routelow');
796 my @localnodes = map { my $r = Route::get($_->{call}); $r ? $r : () } @dxchan;
797 dbg("ROUTE: localnodes: " . join(',', map{$_->{call}} @localnodes)) if isdbg('routelow');
798 return pc92c($main::routeroot, @localnodes);
800 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
801 return pc92c($node, @rout);
808 my $with_pc92_nodes = shift;
814 dbg('ROUTE: DXProt::gen_pc92_update start') if isdbg('routelow');
816 # send 'my' configuration for all channels
817 push @lines, gen_my_pc92_config($main::routeroot);
819 if ($with_pc92_nodes) {
820 # send out the configuration of all the directly connected PC92 nodes with current configuration
821 # but with the dates that the last config came in with.
822 @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && $_->{do_pc9x} } DXChannel::get_all_nodes();
823 dbg("ROUTE: pc92 dxchan: " . join(',', map{$_->{call}} @dxchan)) if isdbg('routelow');
824 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan;
825 dbg("ROUTE: pc92 localnodes: " . join(',', map{$_->{call}} @localnodes)) if isdbg('routelow');
826 foreach $node (@localnodes) {
827 if ($node && $node->lastid->{92}) {
828 my @rout = map {my $r = Route::get($_); $r ? ($r) : ()} $node->nodes, $node->users;
829 push @lines, gen_pc92_with_time($node->call, 'C', $node->lastid->{92}, @rout);
834 # send the configuration of all the directly connected 'external' nodes that don't handle PC92
835 # out with the 'external' marker on the first node.
836 @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && !$_->{do_pc9x} } DXChannel::get_all_nodes();
837 dbg("ROUTE: non pc92 dxchan: " . join(',', map{$_->{call}} @dxchan)) if isdbg('routelow');
838 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan;
839 dbg("ROUTE: non pc92 localnodes: " . join(',', map{$_->{call}} @localnodes)) if isdbg('routelow');
840 foreach $node (@localnodes) {
842 push @lines, gen_my_pc92_config($node);
846 dbg('ROUTE: DXProt::gen_pc92_update end with ' . scalar @lines . ' lines') if isdbg('routelow');
855 dbg('DXProt::send_pc92_config') if isdbg('trace');
857 my @out = $self->gen_pc92_update(1);
859 # send the complete config out on this interface
867 my @out = $main::me->gen_pc92_update(0);
869 # broadcast the lines to all PC92 nodes
871 $main::me->broadcast_route_pc9x($main::mycall, undef, $_, 0);
875 sub time_out_pc92_routes
877 my @nodes = grep {$_->call ne $main::mycall && ($_->do_pc9x || $_->via_pc92)} Route::Node::get_all();
879 foreach my $n (@nodes) {
882 if (my $dxchan = DXChannel::get($n->call)) {
883 dbg("ROUTE: disconnecting local pc92 $dxchan->{call} on obscount") if isdbg('route');
887 my @parents = map {Route::Node::get($_)} $n->parents;
890 dbg("ROUTE: deleting pc92 $_->{call} from $n->{call} on obscount") if isdbg('route');
891 push @rdel, $n->del($_);
895 dbg("ROUTE: obscount on $n->{call} now $o") if isdbg('route');
899 $main::me->route_pc21($main::mycall, undef, $_) if $_;
904 # route a message down an appropriate interface for a callsign
906 # is called route(to, pcline);
911 my ($self, $call, $line) = @_;
913 if (ref $self && $call eq $self->{call}) {
914 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
918 # always send it down the local interface if available
919 my $dxchan = DXChannel::get($call);
921 dbg("route: $call -> $dxchan->{call} direct" ) if isdbg('route');
923 my $cl = Route::get($call);
924 $dxchan = $cl->dxchan if $cl;
926 if (ref $self && $dxchan eq $self) {
927 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
930 dbg("route: $call -> $dxchan->{call} using normal route" ) if isdbg('route');
934 # try the backstop method
936 my $rcall = RouteDB::get($call);
938 if ($self && $rcall eq $self->{call}) {
939 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
942 $dxchan = DXChannel::get($rcall);
943 dbg("route: $call -> $rcall using RouteDB" ) if isdbg('route') && $dxchan;
948 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
950 $dxchan->send($routeit) unless $dxchan == $main::me;
953 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
958 # obtain the hops from the list for this callsign and pc no
964 my $hops = $DXProt::hopcount{$pcno};
965 $hops = $DXProt::def_hopcount if !$hops;
970 # adjust the hop count on a per node basis using the user loadable
971 # hop table if available or else decrement an existing one
978 my $call = $self->{call};
981 if (($hops) = $s =~ /\^H(\d+)\^?~?$/o) {
982 my ($pcno) = $s =~ /^PC(\d\d)/o;
983 confess "$call called adjust_hops with '$s'" unless $pcno;
984 my $ref = $nodehops{$call} if %nodehops;
986 my $newhops = $ref->{$pcno};
987 return "" if defined $newhops && $newhops == 0;
988 $newhops = $ref->{default} unless $newhops;
989 return "" if defined $newhops && $newhops == 0;
990 $newhops = $hops if !$newhops;
991 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1003 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
1004 do "$main::data/hop_table.pl";
1011 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
1012 if ($tonode eq $main::mycall) {
1013 my $ref = DXUser->get_current($fromnode);
1014 my $cref = Route::Node::get($fromnode);
1015 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
1016 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
1017 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
1018 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
1019 my $oldpriv = $self->{priv};
1020 $self->{priv} = $ref->{priv}; # assume the user's privilege level
1021 my @in = (DXCommandmode::run_cmd($self, $cmd));
1022 $self->{priv} = $oldpriv;
1023 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
1024 delete $self->{remotecmd};
1026 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
1029 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
1032 my $ref = DXUser->get_current($tonode);
1033 if ($ref && $ref->is_clx) {
1034 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
1036 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
1041 sub process_rcmd_reply
1043 my ($self, $tonode, $fromnode, $user, $line) = @_;
1044 if ($tonode eq $main::mycall) {
1045 my $s = $rcmds{$fromnode};
1047 my $dxchan = DXChannel::get($s->{call});
1048 my $ref = $user eq $tonode ? $dxchan : (DXChannel::get($user) || $dxchan);
1049 $ref->send($line) if $ref;
1050 delete $rcmds{$fromnode} if !$dxchan;
1052 # send unsolicited ones to the sysop
1053 my $dxchan = DXChannel::get($main::myalias);
1054 $dxchan->send($line) if $dxchan;
1057 my $ref = DXUser->get_current($tonode);
1058 if ($ref && $ref->is_clx) {
1059 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
1061 $self->route($tonode, pc35($fromnode, $tonode, $line));
1070 my $fromnode = shift;
1075 Log('rcmd', 'out', $fromnode, $line);
1076 if ($self->is_clx) {
1077 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
1079 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
1084 # add a rcmd request to the rcmd queues
1087 my ($self, $to, $cmd) = @_;
1090 $r->{call} = $self->{call};
1091 $r->{t} = $main::systime;
1095 my $ref = Route::Node::get($to);
1096 my $dxchan = $ref->dxchan;
1097 if ($dxchan && $dxchan->is_clx) {
1098 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1100 route(undef, $to, pc34($main::mycall, $to, $cmd));
1107 my $pc39flag = shift;
1108 my $call = $self->call;
1110 return if $self->{disconnecting}++;
1112 unless ($pc39flag && $pc39flag == 1) {
1113 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1116 # get rid of any PC16/17/19
1117 eph_del_regex("^PC1[679]*$call");
1119 # do routing stuff, remove me from routing table
1120 my $node = Route::Node::get($call);
1123 @rout = $node->del($main::routeroot);
1125 # and all my ephemera as well
1128 eph_del_regex("^PC1[679].*$c");
1132 RouteDB::delete_interface($call);
1134 # unbusy and stop and outgoing mail
1135 my $mref = DXMsg::get_busy($call);
1136 $mref->stop_msg($call) if $mref;
1138 # broadcast to all other nodes that all the nodes connected to via me are gone
1139 unless ($pc39flag && $pc39flag == 2) {
1140 $self->route_pc21($main::mycall, undef, @rout) if @rout;
1141 $self->route_pc92d($main::mycall, undef, $main::routeroot, $node) if $node;
1144 # remove outstanding pings
1145 delete $pings{$call};
1147 # I was the last node visited
1148 $self->user->node($main::mycall);
1150 # send info to all logged in thingies
1151 $self->tell_login('logoutn');
1153 Log('DXProt', $call . " Disconnected");
1155 $self->SUPER::disconnect;
1160 # send a talk message to this thingy
1164 my ($self, $from, $to, $via, $line, $origin) = @_;
1166 if ($self->{do_pc9x}) {
1167 $self->send(pc93($to, $from, $via, $line));
1169 $self->send(pc10($from, $to, $via, $line, $origin));
1171 Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
1174 # send it if it isn't the except list and isn't isolated and still has a hop count
1175 # taking into account filtering and so on
1181 my $generate = shift;
1182 my $no = shift; # the no of things to filter on
1184 my ($filter, $hops);
1187 for (; @_ && $no; $no--) {
1190 if (!$self->{isolate} && $self->{routefilter}) {
1193 ($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});
1197 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
1200 dbg("was sent a null value") if isdbg('chanerr');
1203 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
1207 foreach my $line (&$generate(@rin, @_)) {
1210 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1212 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1213 next unless $routeit;
1216 $self->send($routeit);
1225 my $generate = shift;
1227 my @dxchan = DXChannel::get_all_nodes();
1231 $line =~ /\^H(\d+)\^?\~?$/;
1232 return unless $1 > 0;
1234 unless ($self->{isolate}) {
1235 foreach $dxchan (@dxchan) {
1236 next if $dxchan == $self;
1237 next if $dxchan == $main::me;
1238 next unless $dxchan->isa('DXProt');
1239 next if $dxchan->{do_pc9x};
1240 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
1242 $dxchan->send_route($origin, $generate, @_);
1247 # this is only used for next door nodes on init
1252 return unless $self->{do_pc9x};
1255 my $generate = shift;
1256 my $no = shift; # the no of things to filter on
1259 $line = &$generate(@_);
1263 sub broadcast_route_pc9x
1267 my $generate = shift;
1270 my @dxchan = DXChannel::get_all_nodes();
1273 if ($origin eq $main::mycall && $generate && !$line) {
1274 $line = &$generate(@_);
1277 $line =~ /\^H(\d+)\^\~?$/;
1278 unless ($1 > 0 && $self->{isolate}) {
1279 foreach $dxchan (@dxchan) {
1280 next if $dxchan == $self || $dxchan == $main::me;
1281 next if $origin eq $dxchan->{call}; # don't route some from this call back again.
1282 next unless $dxchan->{do_pc9x};
1283 next unless $dxchan->isa('DXProt');
1285 $dxchan->send($line);
1293 return unless $self->user->wantpc16;
1296 broadcast_route($self, $origin, \&pc16, $line, 1, @_);
1302 return unless $self->user->wantpc16;
1305 broadcast_route($self, $origin, \&pc17, $line, 1, @_);
1313 broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
1321 broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
1329 broadcast_route($self, $origin, \&pc24, $line, 1, @_);
1337 broadcast_route($self, $origin, \&pc41, $line, 1, @_);
1345 broadcast_route($self, $origin, \&pc50, $line, 1, @_);
1353 broadcast_route_pc9x($self, $origin, \&pc92c, $line, 1, @_);
1361 broadcast_route_pc9x($self, $origin, \&pc92a, $line, 1, @_);
1369 broadcast_route_pc9x($self, $origin, \&pc92d, $line, 1, @_);
1376 my ($filter, $hops) = (1, 1);
1378 if ($self->{inroutefilter}) {
1379 ($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);
1380 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
1388 my $t = shift || $eph_restime;
1392 $s =~ s/\^H\d\d?\^?\~?$//;
1393 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
1394 $eph{$s} = $main::systime + $t;
1395 dbg("PCPROT: emphemeral duplicate") if $r && isdbg('chanerr');
1403 while (($key, $val) = each %eph) {
1404 if ($key =~ m{$regex}) {
1414 while (($key, $val) = each %eph) {
1415 if ($main::systime >= $val) {
1426 while (($key, $val) = each %eph) {
1427 push @out, $key, $val;
1434 goto &DXCommandmode::run_cmd;
1438 # import any msgs in the chat directory
1439 # the messages are sent to the chat group which forms the
1440 # the first part of the name (eg: solar.1243.txt would be
1441 # sent to chat group SOLAR)
1443 # Each message found is sent: one non-blank line to one chat
1444 # message. So 4 lines = 4 chat messages.
1446 # The special name LOCAL is for local users ANN
1447 # The special name ALL is for ANN/FULL
1448 # The special name SYSOP is for ANN/SYSOP
1452 # are there any to do in this directory?
1453 return unless -d $chatimportfn;
1454 unless (opendir(DIR, $chatimportfn)) {
1455 dbg("can\'t open $chatimportfn $!") if isdbg('msg');
1456 Log('msg', "can\'t open $chatimportfn $!");
1460 my @names = readdir(DIR);
1463 foreach $name (@names) {
1464 next if $name =~ /^\./;
1465 my $splitit = $name =~ /^split/;
1466 my $fn = "$chatimportfn/$name";
1468 unless (open(MSG, $fn)) {
1469 dbg("can\'t open import file $fn $!") if isdbg('msg');
1470 Log('msg', "can\'t open import file $fn $!");
1474 my @msg = map { s/\r?\n$//; $_ } <MSG>;
1478 my @cat = split /\./, $name;
1479 my $target = uc $cat[0];
1481 foreach my $text (@msg) {
1482 next unless $text && $text !~ /^\s*#/;
1483 if ($target eq 'ALL' || $target eq 'LOCAL' || $target eq 'SYSOP') {
1484 my $sysopflag = $target eq 'SYSOP' ? '*' : ' ';
1485 if ($target ne 'LOCAL') {
1486 send_announce($main::me, pc12($main::mycall, $text, '*', $sysopflag), $main::mycall, '*', $text, $sysopflag, $main::mycall, '0');
1488 Log('ann', 'LOCAL', $main::mycall, $text);
1489 DXChannel::broadcast_list("To LOCAL de ${main::mycall}: $text\a", 'ann', undef, DXCommandmode->get_all());
1492 my $msgid = nextchatmsgid();
1493 $text = "#$msgid $text";
1494 send_chat($main::me, pc12($main::mycall, $text, '*', $target), $main::mycall, '*', $text, $target, $main::mycall, '0');