3 # This module impliments the protocal mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
40 use vars qw($pc11_max_age $pc23_max_age $last_pc50 $eph_restime $eph_info_restime $eph_pc34_restime
41 $last_hour $last10 %eph %pings %rcmds $ann_to_talk
42 $pingint $obscount %pc19list $chatdupeage $chatimportfn
43 $investigation_int $pc19_version $myprot_version
44 %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
45 $allowzero $decode_dk0wcy $send_opernam @checklist
46 $eph_pc15_restime $pc92_update_period $pc92_obs_timeout
47 %pc92_find $pc92_find_timeout
50 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
51 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
53 $last_hour = time; # last time I did an hourly periodic update
54 %rcmds = (); # outstanding rcmd requests outbound
55 %nodehops = (); # node specific hop control
56 %pc19list = (); # list of outstanding PC19s that haven't had PC16s on them
58 $censorpc = 1; # Do a BadWords::check on text fields and reject things
59 # loads of 'bad things'
60 $baddx = new DXHash "baddx";
61 $badspotter = new DXHash "badspotter";
62 $badnode = new DXHash "badnode";
63 $last10 = $last_pc50 = time;
67 $eph_info_restime = 60*60;
68 $eph_pc15_restime = 6*60;
69 $eph_pc34_restime = 30;
72 $chatdupeage = 20 * 60 * 60;
73 $chatimportfn = "$main::root/chat_import";
74 $investigation_int = 12*60*60; # time between checks to see if we can see this node
75 $pc19_version = 5466; # the visible version no for outgoing PC19s generated from pc59
76 $pc92_update_period = 60*60; # the period between PC92 C updates
77 %pc92_find = (); # outstanding pc92 find operations
78 $pc92_find_timeout = 30; # maximum time to wait for a reply
79 $pc92_obs_timeout = $pc92_update_period; # the time between obscount countdowns
85 [ qw(i c c m bp bc c) ], # pc10
86 [ qw(i f m d t m c c h) ], # pc11
87 [ qw(i c bm m bm bm p h) ], # pc12
91 undef , # pc16 has to be validated manually
92 [ qw(i c c h) ], # pc17
94 undef , # pc19 has to be validated manually
95 undef , # pc20 no validation
96 [ qw(i c m h) ], # pc21
97 undef , # pc22 no validation
98 [ qw(i d n n n n m c c h) ], # pc23
99 [ qw(i c p h) ], # pc24
100 [ qw(i c c n n) ], # pc25
101 [ qw(i f m d t m c c bc) ], # pc26
102 [ qw(i d n n n n m c c bc) ], # pc27
103 [ qw(i c c m c d t p m bp n p bp bc) ], # pc28
104 [ qw(i c c n m) ], # pc29
105 [ qw(i c c n) ], # pc30
106 [ qw(i c c n) ], # pc31
107 [ qw(i c c n) ], # pc32
108 [ qw(i c c n) ], # pc33
109 [ qw(i c c m) ], # pc34
110 [ qw(i c c m) ], # pc35
111 [ qw(i c c m) ], # pc36
112 [ qw(i c c n m) ], # pc37
113 undef, # pc38 not interested
114 [ qw(i c m) ], # pc39
115 [ qw(i c c m p n) ], # pc40
116 [ qw(i c n m h) ], # pc41
117 [ qw(i c c n) ], # pc42
118 undef, # pc43 don't handle it
119 [ qw(i c c n m m c) ], # pc44
120 [ qw(i c c n m) ], # pc45
121 [ qw(i c c n) ], # pc46
124 [ qw(i c m h) ], # pc49
125 [ qw(i c n h) ], # pc50
126 [ qw(i c c n) ], # pc51
148 [ qw(i d n n n n n n m m m c c h) ], # pc73
159 [ qw(i c c c m) ], # pc84
160 [ qw(i c c c m) ], # pc85
165 [ qw(i c n) ], # pc90
168 # use the entry in the check list to check the field list presented
169 # return OK if line NOT in check list (for now)
174 return 0 if $n < 0 || $n > @checklist;
175 my $ref = $checklist[$n];
176 return 0 unless ref $ref;
179 for ($i = 1; $i < @$ref; $i++) {
180 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
181 return 0 unless $act;
182 next if $blank && $_[$i] =~ /^[ \*]$/;
184 return $i unless is_callsign($_[$i]);
185 } elsif ($act eq 'i') {
187 } elsif ($act eq 'm') {
188 return $i unless is_pctext($_[$i]);
189 } elsif ($act eq 'p') {
190 return $i unless is_pcflag($_[$i]);
191 } elsif ($act eq 'f') {
192 return $i unless is_freq($_[$i]);
193 } elsif ($act eq 'n') {
194 return $i unless $_[$i] =~ /^[\d ]+$/;
195 } elsif ($act eq 'h') {
196 return $i unless $_[$i] =~ /^H\d\d?$/;
197 } elsif ($act eq 'd') {
198 return $i unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
199 } elsif ($act eq 't') {
200 return $i unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
209 $self->{next_pc92_update} = $main::systime + $pc92_update_period - int rand($pc92_update_period / 4);
214 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
217 my $user = DXUser->get($main::mycall);
218 die "User $main::mycall not setup or disappeared RTFM" unless $user;
220 $myprot_version += $main::version*100;
221 $main::me = DXProt->new($main::mycall, 0, $user);
222 $main::me->{here} = 1;
223 $main::me->{state} = "indifferent";
224 $main::me->{sort} = 'S'; # S for spider
225 $main::me->{priv} = 9;
226 $main::me->{metric} = 0;
227 $main::me->{pingave} = 0;
228 $main::me->{registered} = 1;
229 $main::me->{version} = $main::version;
230 $main::me->{build} = "$main::subversion.$main::build";
231 $main::me->{do_pc9x} = 1;
232 $main::me->update_pc92_next;
236 # obtain a new connection this is derived from dxchannel
241 my $self = DXChannel::alloc(@_);
243 # add this node to the table, the values get filled in later
247 # if we have an entry already, then send a PC21 to all connect
248 # old style connections, because we are about to get the real deal
249 if (my $ref = Route::Node::get($call)) {
250 dbg("ROUTE: $call is already in the routing table, deleting") if isdbg('route');
251 my @rout = $ref->delete;
252 $self->route_pc21($main::mycall, undef, @rout) if @rout;
254 $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
259 # this is how a pc connection starts (for an incoming connection)
260 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
261 # all the crap that comes between).
264 my ($self, $line, $sort) = @_;
265 my $call = $self->{call};
266 my $user = $self->{user};
269 my $host = $self->{conn}->{peerhost};
270 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
273 Log('DXProt', "$call connected from $host");
275 # remember type of connection
276 $self->{consort} = $line;
277 $self->{outbound} = $sort eq 'O';
278 my $priv = $user->priv;
279 $priv = $user->priv(1) unless $priv;
280 $self->{priv} = $priv; # other clusters can always be 'normal' users
281 $self->{lang} = $user->lang || 'en';
282 $self->{isolate} = $user->{isolate};
283 $self->{consort} = $line; # save the connection type
287 # sort out registration
288 $self->{registered} = 1;
290 # get the output filters
291 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
292 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
293 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
294 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
295 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
298 # get the INPUT filters (these only pertain to Clusters)
299 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
300 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
301 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
302 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
303 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
304 # if there is no route input filter then specify a default one.
305 # obviously this can be changed later by the sysop.
306 if (!$self->{inroutefilter}) {
307 my $dxcc = $self->dxcc;
308 $Route::filterdef->cmd($self, 'route', 'accept', "input by_dxcc $dxcc" );
311 # set unbuffered and no echo
312 $self->send_now('B',"0");
313 $self->send_now('E',"0");
314 $self->conn->echo(0) if $self->conn->can('echo');
316 # ping neighbour node stuff
317 my $ping = $user->pingint;
318 $ping = $pingint unless defined $ping;
319 $self->{pingint} = $ping;
320 $self->{nopings} = $user->nopings || $obscount;
321 $self->{pingtime} = [ ];
322 $self->{pingave} = 999;
323 $self->{metric} ||= 100;
324 $self->{lastping} = $main::systime;
326 # send initialisation string
327 unless ($self->{outbound}) {
331 $self->state('init');
332 $self->{pc50_t} = $main::systime;
334 # send info to all logged in thingies
335 $self->tell_login('loginn');
337 # run a script send the output to the debug file
338 my $script = new Script(lc $call) || new Script('node_default');
339 $script->run($self) if $script;
341 # set next_pc92_update time
342 $self->update_pc92_next;
346 # send outgoing 'challenge'
356 # This is the normal pcxx despatcher
360 my ($self, $line) = @_;
362 if ($line =~ '^<\w+\s' && $main::do_xml) {
363 DXXml::normal($self, $line);
367 my @field = split /\^/, $line;
368 return unless @field;
370 pop @field if $field[-1] eq '~';
372 # print join(',', @field), "\n";
375 # process PC frames, this will fail unless the frame starts PCnn
376 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
377 unless (defined $pcno && $pcno >= 10 && $pcno <= 99) {
378 dbg("PCPROT: unknown protocol") if isdbg('chanerr');
382 # check for and dump bad protocol messages
383 my $n = check($pcno, @field);
385 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
389 # modify the hop count here
390 if ($self != $main::me) {
391 if (my ($hops, $trail) = $line =~ /\^H(\d+)(\^?\~?)?$/) {
395 $line =~ s/\^H(\d+)(\^?\~?)?$/sprintf('^H%d%s', $hops, $trail)/e;
396 $field[-1] = "H$hops";
400 # send it out for processing
401 my $origin = $self->{call};
403 my $sub = "handle_$pcno";
405 if ($self->can($sub)) {
406 $self->$sub($pcno, $line, $origin, @field);
408 $self->handle_default($pcno, $line, $origin, @field);
413 # This is called from inside the main cluster processing loop and is used
414 # for despatching commands that are doing some long processing job
419 my @dxchan = DXChannel::get_all();
423 # send out a pc50 on EVERY channel all at once
424 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
425 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
430 foreach $dxchan (@dxchan) {
431 next unless $dxchan->is_node;
432 next if $dxchan->handle_xml;
433 next if $dxchan == $main::me;
436 $dxchan->send($pc50s) if $pc50s;
438 # send a ping out on this channel
439 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
440 if ($dxchan->{nopings} <= 0) {
443 DXXml::Ping::add($main::me, $dxchan->call);
444 $dxchan->{nopings} -= 1;
445 $dxchan->{lastping} = $t;
446 $dxchan->{lastping} += $dxchan->{pingint} / 2 unless @{$dxchan->{pingtime}};
450 # send out a PC92 config record if required
451 if ($main::systime >= $dxchan->{next_pc92_update}) {
452 $dxchan->send_pc92_config;
453 $dxchan->update_pc92_next;
457 Investigate::process();
461 if ($t - $last10 >= 10) {
467 if ($main::systime >= $pc92_obs_timeout) {
468 time_out_pc92_routes();
469 $pc92_obs_timeout = $main::systime + $pc92_update_period;
475 if ($main::systime - 3600 > $last_hour) {
476 $last_hour = $main::systime;
481 # finish up a pc context
485 # some active measures
493 my @dxchan = DXChannel::get_all();
496 # send it if it isn't the except list and isn't isolated and still has a hop count
497 # taking into account filtering and so on
498 foreach $dxchan (@dxchan) {
499 next if $dxchan == $main::me;
500 next if $dxchan == $self && $self->is_node;
501 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
512 if ($self->{spotsfilter}) {
513 ($filter, $hops) = $self->{spotsfilter}->it(@_);
514 return unless $filter;
516 send_prot_line($self, $filter, $hops, $isolate, $line);
521 my ($self, $filter, $hops, $isolate, $line) = @_;
527 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
529 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
530 return unless $routeit;
533 $self->send($routeit);
535 $self->send($routeit) unless $self->{isolate} || $isolate;
544 my @dxchan = DXChannel::get_all();
546 my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
548 # send it if it isn't the except list and isn't isolated and still has a hop count
549 # taking into account filtering and so on
550 foreach $dxchan (@dxchan) {
551 next if $dxchan == $main::me;
552 next if $dxchan == $self && $self->is_node;
556 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
567 if ($self->{wwvfilter}) {
568 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_]);
569 return unless $filter;
571 send_prot_line($self, $filter, $hops, $isolate, $line)
578 my @dxchan = DXChannel::get_all();
580 my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
582 # send it if it isn't the except list and isn't isolated and still has a hop count
583 # taking into account filtering and so on
584 foreach $dxchan (@dxchan) {
585 next if $dxchan == $main::me;
586 next if $dxchan == $self;
588 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
599 if ($self->{wcyfilter}) {
600 ($filter, $hops) = $self->{wcyfilter}->it(@_);
601 return unless $filter;
603 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
610 my $from_pc9x = shift;
612 my @dxchan = DXChannel::get_all();
616 my $text = unpad($_[2]);
618 if ($_[3] eq '*') { # sysops
620 } elsif ($_[3] gt ' ') { # speciality list handling
621 my ($name) = split /\./, $_[3];
622 $target = "$name"; # put the rest in later (if bothered)
629 $target = "ALL" if !$target;
632 # obtain country codes etc
633 my @a = Prefix::cty_data($_[0]);
634 my @b = Prefix::cty_data($_[4]);
635 if ($self->{inannfilter}) {
636 my ($filter, $hops) =
637 $self->{inannfilter}->it(@_, $self->{call},
639 @b[0..2], $a[3], $b[3]);
641 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
646 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
647 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
651 Log('ann', $target, $_[0], $text);
653 # send it if it isn't the except list and isn't isolated and still has a hop count
654 # taking into account filtering and so on
655 foreach $dxchan (@dxchan) {
656 next if $dxchan == $main::me;
657 next if $dxchan == $self && $self->is_node;
658 next if $from_pc9x && $dxchan->{do_pc9x};
659 next if $target eq 'LOCAL' && $dxchan->is_node;
660 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
670 $msgid = 1 if $msgid > 999;
678 my $from_pc9x = shift;
680 my @dxchan = DXChannel::get_all();
683 my $text = unpad($_[2]);
686 # munge the group and recast the line if required
687 if ($target =~ s/\.LST$//) {
691 # obtain country codes etc
692 my @a = Prefix::cty_data($_[0]);
693 my @b = Prefix::cty_data($_[4]);
694 if ($self->{inannfilter}) {
695 my ($filter, $hops) =
696 $self->{inannfilter}->it(@_, $self->{call},
698 @b[0..2], $a[3], $b[3]);
700 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
705 if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
706 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
711 Log('chat', $target, $_[0], $text);
713 # send it if it isn't the except list and isn't isolated and still has a hop count
714 # taking into account filtering and so on
715 foreach $dxchan (@dxchan) {
716 my $is_ak1a = $dxchan->is_ak1a;
718 if ($dxchan->is_node) {
719 next if $dxchan == $main::me;
720 next if $dxchan == $self;
721 next if $from_pc9x && $dxchan->{do_pc9x};
722 next unless $dxchan->is_spider || $is_ak1a;
723 next if $target eq 'LOCAL';
724 if (!$ak1a_line && $is_ak1a) {
725 $ak1a_line = pc12($_[0], $text, $_[1], "$target.LST");
729 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1],
730 $text, @_, $self->{call}, @a[0..2], @b[0..2]);
744 if ($self->{annfilter}) {
745 ($filter, $hops) = $self->{annfilter}->it(@_);
746 return unless $filter;
748 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
757 sub send_local_config
761 dbg('DXProt::send_local_config') if isdbg('trace');
769 if ($self->{isolate}) {
770 @localnodes = ( $main::routeroot );
771 $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
772 } elsif ($self->{do_pc9x}) {
773 my $node = Route::Node::get($self->{call});
774 $self->send_last_pc92_config($main::routeroot);
775 $self->send(pc92a($main::routeroot, $node)) unless $main::routeroot->last_PC92C =~ /$self->{call}/;
777 # create a list of all the nodes that are not connected to this connection
778 # and are not themselves isolated, this to make sure that isolated nodes
779 # don't appear outside of this node
781 # send locally connected nodes
782 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
783 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
784 $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
787 my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
789 for $node (@rawintcalls) {
790 push @intcalls, $node unless grep $node eq $_, @intcalls;
792 my $ref = Route::Node::get($self->{call});
793 my @rnodes = $ref->nodes;
794 for $node (@intcalls) {
795 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
797 $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
800 # get all the users connected on the above nodes and send them out
801 unless ($self->{do_pc9x}) {
802 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
804 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
805 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
807 dbg("sent a null value") if isdbg('chanerr');
813 sub gen_my_pc92_config
817 if ($node->{call} eq $main::mycall) {
818 my @dxchan = grep { $_->call ne $main::mycall && !$_->{isolate} } DXChannel::get_all();
819 dbg("ROUTE: all dxchan: " . join(',', map{$_->{call}} @dxchan)) if isdbg('routelow');
820 my @localnodes = map { my $r = Route::get($_->{call}); $r ? $r : () } @dxchan;
821 dbg("ROUTE: localnodes: " . join(',', map{$_->{call}} @localnodes)) if isdbg('routelow');
822 return pc92c($main::routeroot, @localnodes);
824 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
825 return pc92c($node, @rout);
832 my $with_pc92_nodes = shift;
838 dbg('ROUTE: DXProt::gen_pc92_update start') if isdbg('routelow');
840 # send 'my' configuration for all channels
841 push @lines, gen_my_pc92_config($main::routeroot);
843 # if ($with_pc92_nodes) {
844 # send out the configuration of all the directly connected PC92 nodes with current configuration
845 # but with the dates that the last config came in with.
846 # @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && $_->{do_pc9x} } DXChannel::get_all_nodes();
847 # dbg("ROUTE: pc92 dxchan: " . join(',', map{$_->{call}} @dxchan)) if isdbg('routelow');
848 # @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan;
849 # dbg("ROUTE: pc92 localnodes: " . join(',', map{$_->{call}} @localnodes)) if isdbg('routelow');
850 # foreach $node (@localnodes) {
851 # if ($node && $node->lastid->{92}) {
852 # my @rout = map {my $r = Route::get($_); $r ? ($r) : ()} $node->nodes, $node->users;
853 # push @lines, gen_pc92_with_time($node->call, 'C', $node->lastid->{92}, @rout);
858 # send the configuration of all the directly connected 'external' nodes that don't handle PC92
859 # out with the 'external' marker on the first node.
860 # @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && !$_->{do_pc9x} } DXChannel::get_all_nodes();
861 # dbg("ROUTE: non pc92 dxchan: " . join(',', map{$_->{call}} @dxchan)) if isdbg('routelow');
862 # @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan;
863 # dbg("ROUTE: non pc92 localnodes: " . join(',', map{$_->{call}} @localnodes)) if isdbg('routelow');
864 # foreach $node (@localnodes) {
866 # push @lines, gen_my_pc92_config($node);
870 dbg('ROUTE: DXProt::gen_pc92_update end with ' . scalar @lines . ' lines') if isdbg('routelow');
875 sub send_last_pc92_config
879 if (my $l = $node->last_PC92C) {
882 $self->send_pc92_config($node);
891 dbg('DXProt::send_pc92_config') if isdbg('trace');
893 $node->last_PC92C(gen_my_pc92_config($node));
894 $self->send($node->last_PC92C);
899 my @out = $main::me->gen_pc92_update(0);
901 # broadcast the lines to all PC92 nodes
903 $main::me->broadcast_route_pc9x($main::mycall, undef, $_, 0);
907 sub time_out_pc92_routes
909 my @nodes = grep {$_->call ne $main::mycall && ($_->do_pc9x || $_->via_pc92)} Route::Node::get_all();
911 foreach my $n (@nodes) {
914 if (my $dxchan = DXChannel::get($n->call)) {
915 dbg("ROUTE: disconnecting local pc92 $dxchan->{call} on obscount") if isdbg('route');
919 my @parents = map {Route::Node::get($_)} $n->parents;
922 dbg("ROUTE: deleting pc92 $_->{call} from $n->{call} on obscount") if isdbg('route');
923 push @rdel, $n->del($_);
927 dbg("ROUTE: obscount on $n->{call} now $o") if isdbg('route');
931 $main::me->route_pc21($main::mycall, undef, $_) if $_;
936 # route a message down an appropriate interface for a callsign
938 # is called route(to, pcline);
943 my ($self, $call, $line) = @_;
945 if (ref $self && $call eq $self->{call}) {
946 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
950 # always send it down the local interface if available
951 my $dxchan = DXChannel::get($call);
953 dbg("route: $call -> $dxchan->{call} direct" ) if isdbg('route');
955 my $cl = Route::get($call);
956 $dxchan = $cl->dxchan if $cl;
958 if (ref $self && $dxchan eq $self) {
959 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
962 dbg("route: $call -> $dxchan->{call} using normal route" ) if isdbg('route');
966 # try the backstop method
968 my $rcall = RouteDB::get($call);
970 if ($self && $rcall eq $self->{call}) {
971 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
974 $dxchan = DXChannel::get($rcall);
975 dbg("route: $call -> $rcall using RouteDB" ) if isdbg('route') && $dxchan;
980 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
982 $dxchan->send($routeit) unless $dxchan == $main::me;
985 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
990 # obtain the hops from the list for this callsign and pc no
996 my $hops = $DXProt::hopcount{$pcno};
997 $hops = $DXProt::def_hopcount if !$hops;
1002 # adjust the hop count on a per node basis using the user loadable
1003 # hop table if available or else decrement an existing one
1010 my $call = $self->{call};
1013 if (($hops) = $s =~ /\^H(\d+)\^?~?$/o) {
1014 my ($pcno) = $s =~ /^PC(\d\d)/o;
1015 confess "$call called adjust_hops with '$s'" unless $pcno;
1016 my $ref = $nodehops{$call} if %nodehops;
1018 my $newhops = $ref->{$pcno};
1019 return "" if defined $newhops && $newhops == 0;
1020 $newhops = $ref->{default} unless $newhops;
1021 return "" if defined $newhops && $newhops == 0;
1022 $newhops = $hops if !$newhops;
1023 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1035 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
1036 do "$main::data/hop_table.pl";
1043 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
1044 if ($tonode eq $main::mycall) {
1045 my $ref = DXUser->get_current($fromnode);
1046 my $cref = Route::Node::get($fromnode);
1047 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
1048 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
1049 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
1050 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
1051 my $oldpriv = $self->{priv};
1052 $self->{priv} = $ref->{priv}; # assume the user's privilege level
1053 my @in = (DXCommandmode::run_cmd($self, $cmd));
1054 $self->{priv} = $oldpriv;
1055 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
1056 delete $self->{remotecmd};
1058 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
1061 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
1064 my $ref = DXUser->get_current($tonode);
1065 if ($ref && $ref->is_clx) {
1066 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
1068 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
1073 sub process_rcmd_reply
1075 my ($self, $tonode, $fromnode, $user, $line) = @_;
1076 if ($tonode eq $main::mycall) {
1077 my $s = $rcmds{$fromnode};
1079 my $dxchan = DXChannel::get($s->{call});
1080 my $ref = $user eq $tonode ? $dxchan : (DXChannel::get($user) || $dxchan);
1081 $ref->send($line) if $ref;
1082 delete $rcmds{$fromnode} if !$dxchan;
1084 # send unsolicited ones to the sysop
1085 my $dxchan = DXChannel::get($main::myalias);
1086 $dxchan->send($line) if $dxchan;
1089 my $ref = DXUser->get_current($tonode);
1090 if ($ref && $ref->is_clx) {
1091 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
1093 $self->route($tonode, pc35($fromnode, $tonode, $line));
1102 my $fromnode = shift;
1107 Log('rcmd', 'out', $fromnode, $line);
1108 if ($self->is_clx) {
1109 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
1111 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
1116 # add a rcmd request to the rcmd queues
1119 my ($self, $to, $cmd) = @_;
1122 $r->{call} = $self->{call};
1123 $r->{t} = $main::systime;
1127 my $ref = Route::Node::get($to);
1128 my $dxchan = $ref->dxchan;
1129 if ($dxchan && $dxchan->is_clx) {
1130 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1132 route(undef, $to, pc34($main::mycall, $to, $cmd));
1139 my $pc39flag = shift;
1140 my $call = $self->call;
1142 return if $self->{disconnecting}++;
1144 unless ($pc39flag && $pc39flag == 1) {
1145 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1148 # get rid of any PC16/17/19
1149 eph_del_regex("^PC1[679]*$call");
1151 # do routing stuff, remove me from routing table
1152 my $node = Route::Node::get($call);
1155 @rout = $node->del($main::routeroot);
1157 # and all my ephemera as well
1160 eph_del_regex("^PC1[679].*$c");
1164 RouteDB::delete_interface($call);
1166 # unbusy and stop and outgoing mail
1167 my $mref = DXMsg::get_busy($call);
1168 $mref->stop_msg($call) if $mref;
1170 # broadcast to all other nodes that all the nodes connected to via me are gone
1171 unless ($pc39flag && $pc39flag == 2) {
1172 $self->route_pc21($main::mycall, undef, @rout) if @rout;
1173 $self->route_pc92d($main::mycall, undef, $main::routeroot, $node) if $node;
1176 # remove outstanding pings
1177 delete $pings{$call};
1179 # I was the last node visited
1180 $self->user->node($main::mycall);
1182 # send info to all logged in thingies
1183 $self->tell_login('logoutn');
1185 Log('DXProt', $call . " Disconnected");
1187 $self->SUPER::disconnect;
1192 # send a talk message to this thingy
1196 my ($self, $from, $to, $via, $line, $origin) = @_;
1198 if ($self->{do_pc9x}) {
1199 $self->send(pc93($to, $from, $via, $line));
1201 $self->send(pc10($from, $to, $via, $line, $origin));
1203 Log('talk', $to, $from, '>' . ($via || $origin || $self->call), $line) unless $origin && $origin ne $main::mycall;
1206 # send it if it isn't the except list and isn't isolated and still has a hop count
1207 # taking into account filtering and so on
1213 my $generate = shift;
1214 my $no = shift; # the no of things to filter on
1216 my ($filter, $hops);
1219 for (; @_ && $no; $no--) {
1222 if (!$self->{isolate} && $self->{routefilter}) {
1225 ($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});
1229 dbg("PCPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('filter');
1232 dbg("was sent a null value") if isdbg('chanerr');
1235 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
1239 foreach my $line (&$generate(@rin, @_)) {
1242 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1244 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1245 next unless $routeit;
1248 $self->send($routeit);
1257 my $generate = shift;
1259 my @dxchan = DXChannel::get_all_nodes();
1263 $line =~ /\^H(\d+)\^?\~?$/;
1264 return unless $1 > 0;
1266 unless ($self->{isolate}) {
1267 foreach $dxchan (@dxchan) {
1268 next if $dxchan == $self;
1269 next if $dxchan == $main::me;
1270 next unless $dxchan->isa('DXProt');
1271 next if $dxchan->{do_pc9x};
1272 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
1274 $dxchan->send_route($origin, $generate, @_);
1279 # this is only used for next door nodes on init
1284 return unless $self->{do_pc9x};
1287 my $generate = shift;
1288 my $no = shift; # the no of things to filter on
1291 $line = &$generate(@_);
1295 sub broadcast_route_pc9x
1299 my $generate = shift;
1302 my @dxchan = DXChannel::get_all_nodes();
1305 if ($origin eq $main::mycall && $generate && !$line) {
1306 $line = &$generate(@_);
1309 $line =~ /\^H(\d+)\^\~?$/;
1310 unless ($1 > 0 && $self->{isolate}) {
1311 foreach $dxchan (@dxchan) {
1312 next if $dxchan == $self || $dxchan == $main::me;
1313 next if $origin eq $dxchan->{call}; # don't route some from this call back again.
1314 next unless $dxchan->{do_pc9x};
1315 next unless $dxchan->isa('DXProt');
1317 $dxchan->send($line);
1325 return unless $self->user->wantpc16;
1328 broadcast_route($self, $origin, \&pc16, $line, 1, @_);
1334 return unless $self->user->wantpc16;
1337 broadcast_route($self, $origin, \&pc17, $line, 1, @_);
1345 broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
1353 broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
1361 broadcast_route($self, $origin, \&pc24, $line, 1, @_);
1369 broadcast_route($self, $origin, \&pc41, $line, 1, @_);
1377 broadcast_route($self, $origin, \&pc50, $line, 1, @_);
1385 broadcast_route_pc9x($self, $origin, \&pc92c, $line, 1, @_);
1393 broadcast_route_pc9x($self, $origin, \&pc92a, $line, 1, @_);
1401 broadcast_route_pc9x($self, $origin, \&pc92d, $line, 1, @_);
1408 my ($filter, $hops) = (1, 1);
1410 if ($self->{inroutefilter}) {
1411 ($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);
1412 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
1420 my $t = shift || $eph_restime;
1424 $s =~ s/\^H\d\d?\^?\~?$//;
1425 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
1426 $eph{$s} = $main::systime + $t;
1427 dbg("PCPROT: emphemeral duplicate") if $r && isdbg('chanerr');
1435 while (($key, $val) = each %eph) {
1436 if ($key =~ m{$regex}) {
1446 while (($key, $val) = each %eph) {
1447 if ($main::systime >= $val) {
1458 while (($key, $val) = each %eph) {
1459 push @out, $key, $val;
1466 goto &DXCommandmode::run_cmd;
1470 # import any msgs in the chat directory
1471 # the messages are sent to the chat group which forms the
1472 # the first part of the name (eg: solar.1243.txt would be
1473 # sent to chat group SOLAR)
1475 # Each message found is sent: one non-blank line to one chat
1476 # message. So 4 lines = 4 chat messages.
1478 # The special name LOCAL is for local users ANN
1479 # The special name ALL is for ANN/FULL
1480 # The special name SYSOP is for ANN/SYSOP
1484 # are there any to do in this directory?
1485 return unless -d $chatimportfn;
1486 unless (opendir(DIR, $chatimportfn)) {
1487 dbg("can\'t open $chatimportfn $!") if isdbg('msg');
1488 Log('msg', "can\'t open $chatimportfn $!");
1492 my @names = readdir(DIR);
1495 foreach $name (@names) {
1496 next if $name =~ /^\./;
1497 my $splitit = $name =~ /^split/;
1498 my $fn = "$chatimportfn/$name";
1500 unless (open(MSG, $fn)) {
1501 dbg("can\'t open import file $fn $!") if isdbg('msg');
1502 Log('msg', "can\'t open import file $fn $!");
1506 my @msg = map { s/\r?\n$//; $_ } <MSG>;
1510 my @cat = split /\./, $name;
1511 my $target = uc $cat[0];
1513 foreach my $text (@msg) {
1514 next unless $text && $text !~ /^\s*#/;
1515 if ($target eq 'ALL' || $target eq 'LOCAL' || $target eq 'SYSOP') {
1516 my $sysopflag = $target eq 'SYSOP' ? '*' : ' ';
1517 if ($target ne 'LOCAL') {
1518 send_announce($main::me, pc12($main::mycall, $text, '*', $sysopflag), $main::mycall, '*', $text, $sysopflag, $main::mycall, '0');
1520 Log('ann', 'LOCAL', $main::mycall, $text);
1521 DXChannel::broadcast_list("To LOCAL de ${main::mycall}: $text\a", 'ann', undef, DXCommandmode->get_all());
1524 my $msgid = nextchatmsgid();
1525 $text = "#$msgid $text";
1526 send_chat($main::me, pc12($main::mycall, $text, '*', $target), $main::mycall, '*', $text, $target, $main::mycall, '0');
1532 # start a pc92 find operation
1537 my $key = "$dxchan->{call}|$target";
1538 if ($pc92_find{$key}) {
1543 # function (not method) to handle pc92 find returns
1544 sub handle_pc92_find_reply
1546 my ($dxchan, $node, $from, $target, $flag, $ms) = @_;
1548 $dxchan->print_pc92_find_reply($node, $target, $flag, $ms) if $dxchan->can('print_pc92_find_return');