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 $pc92_short_update_period
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_short_update_period = 15*60; # shorten the update period after a connection
78 %pc92_find = (); # outstanding pc92 find operations
79 $pc92_find_timeout = 30; # maximum time to wait for a reply
80 $pc92_obs_timeout = $pc92_update_period; # the time between obscount countdowns
86 [ qw(i c c m bp bc c) ], # pc10
87 [ qw(i f m d t m c c h) ], # pc11
88 [ qw(i c bm m bm bm p h) ], # pc12
92 undef , # pc16 has to be validated manually
93 [ qw(i c c h) ], # pc17
95 undef , # pc19 has to be validated manually
96 undef , # pc20 no validation
97 [ qw(i c m h) ], # pc21
98 undef , # pc22 no validation
99 [ qw(i d n n n n m c c h) ], # pc23
100 [ qw(i c p h) ], # pc24
101 [ qw(i c c n n) ], # pc25
102 [ qw(i f m d t m c c bc) ], # pc26
103 [ qw(i d n n n n m c c bc) ], # pc27
104 [ qw(i c c m c d t p m bp n p bp bc) ], # pc28
105 [ qw(i c c n m) ], # pc29
106 [ qw(i c c n) ], # pc30
107 [ qw(i c c n) ], # pc31
108 [ qw(i c c n) ], # pc32
109 [ qw(i c c n) ], # pc33
110 [ qw(i c c m) ], # pc34
111 [ qw(i c c m) ], # pc35
112 [ qw(i c c m) ], # pc36
113 [ qw(i c c n m) ], # pc37
114 undef, # pc38 not interested
115 [ qw(i c m) ], # pc39
116 [ qw(i c c m p n) ], # pc40
117 [ qw(i c n m h) ], # pc41
118 [ qw(i c c n) ], # pc42
119 undef, # pc43 don't handle it
120 [ qw(i c c n m m c) ], # pc44
121 [ qw(i c c n m) ], # pc45
122 [ qw(i c c n) ], # pc46
125 [ qw(i c m h) ], # pc49
126 [ qw(i c n h) ], # pc50
127 [ qw(i c c n) ], # pc51
149 [ qw(i d n n n n n n m m m c c h) ], # pc73
160 [ qw(i c c c m) ], # pc84
161 [ qw(i c c c m) ], # pc85
166 [ qw(i c n) ], # pc90
169 # use the entry in the check list to check the field list presented
170 # return OK if line NOT in check list (for now)
175 return 0 if $n < 0 || $n > @checklist;
176 my $ref = $checklist[$n];
177 return 0 unless ref $ref;
180 for ($i = 1; $i < @$ref; $i++) {
181 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
182 return 0 unless $act;
183 next if $blank && $_[$i] =~ /^[ \*]$/;
185 return $i unless is_callsign($_[$i]);
186 } elsif ($act eq 'i') {
188 } elsif ($act eq 'm') {
189 return $i unless is_pctext($_[$i]);
190 } elsif ($act eq 'p') {
191 return $i unless is_pcflag($_[$i]);
192 } elsif ($act eq 'f') {
193 return $i unless is_freq($_[$i]);
194 } elsif ($act eq 'n') {
195 return $i unless $_[$i] =~ /^[\d ]+$/;
196 } elsif ($act eq 'h') {
197 return $i unless $_[$i] =~ /^H\d\d?$/;
198 } elsif ($act eq 'd') {
199 return $i unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
200 } elsif ($act eq 't') {
201 return $i unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
210 my $period = shift || $pc92_update_period;
211 $self->{next_pc92_update} = $main::systime + $period - int rand($period / 4);
216 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
219 my $user = DXUser->get($main::mycall);
220 die "User $main::mycall not setup or disappeared RTFM" unless $user;
222 $myprot_version += $main::version*100;
223 $main::me = DXProt->new($main::mycall, 0, $user);
224 $main::me->{here} = 1;
225 $main::me->{state} = "indifferent";
226 $main::me->{sort} = 'S'; # S for spider
227 $main::me->{priv} = 9;
228 $main::me->{metric} = 0;
229 $main::me->{pingave} = 0;
230 $main::me->{registered} = 1;
231 $main::me->{version} = $main::version;
232 $main::me->{build} = "$main::subversion.$main::build";
233 $main::me->{do_pc9x} = 1;
234 $main::me->update_pc92_next($pc92_update_period);
238 # obtain a new connection this is derived from dxchannel
243 my $self = DXChannel::alloc(@_);
245 # add this node to the table, the values get filled in later
249 # if we have an entry already, then send a PC21 to all connect
250 # old style connections, because we are about to get the real deal
251 if (my $ref = Route::Node::get($call)) {
252 dbg("ROUTE: $call is already in the routing table, deleting") if isdbg('route');
253 my @rout = $ref->delete;
254 $self->route_pc21($main::mycall, undef, @rout) if @rout;
256 $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
261 # this is how a pc connection starts (for an incoming connection)
262 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
263 # all the crap that comes between).
266 my ($self, $line, $sort) = @_;
267 my $call = $self->{call};
268 my $user = $self->{user};
271 my $host = $self->{conn}->{peerhost};
272 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
275 Log('DXProt', "$call connected from $host");
277 # remember type of connection
278 $self->{consort} = $line;
279 $self->{outbound} = $sort eq 'O';
280 my $priv = $user->priv;
281 $priv = $user->priv(1) unless $priv;
282 $self->{priv} = $priv; # other clusters can always be 'normal' users
283 $self->{lang} = $user->lang || 'en';
284 $self->{isolate} = $user->{isolate};
285 $self->{consort} = $line; # save the connection type
289 # sort out registration
290 $self->{registered} = 1;
292 # get the output filters
293 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
294 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
295 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
296 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
297 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
300 # get the INPUT filters (these only pertain to Clusters)
301 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
302 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
303 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
304 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
305 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
306 # if there is no route input filter then specify a default one.
307 # obviously this can be changed later by the sysop.
308 if (!$self->{inroutefilter}) {
309 my $dxcc = $self->dxcc;
310 $Route::filterdef->cmd($self, 'route', 'accept', "input by_dxcc $dxcc" );
313 # set unbuffered and no echo
314 $self->send_now('B',"0");
315 $self->send_now('E',"0");
316 $self->conn->echo(0) if $self->conn->can('echo');
318 # ping neighbour node stuff
319 my $ping = $user->pingint;
320 $ping = $pingint unless defined $ping;
321 $self->{pingint} = $ping;
322 $self->{nopings} = $user->nopings || $obscount;
323 $self->{pingtime} = [ ];
324 $self->{pingave} = 999;
325 $self->{metric} ||= 100;
326 $self->{lastping} = $main::systime;
328 # send initialisation string
329 unless ($self->{outbound}) {
333 $self->state('init');
334 $self->{pc50_t} = $main::systime;
336 # send info to all logged in thingies
337 $self->tell_login('loginn');
339 # run a script send the output to the debug file
340 my $script = new Script(lc $call) || new Script('node_default');
341 $script->run($self) if $script;
343 # set next_pc92_update time for this node sooner
344 $self->update_pc92_next($pc92_short_update_period);
348 # send outgoing 'challenge'
358 # This is the normal pcxx despatcher
362 my ($self, $line) = @_;
364 if ($line =~ '^<\w+\s' && $main::do_xml) {
365 DXXml::normal($self, $line);
369 my @field = split /\^/, $line;
370 return unless @field;
372 pop @field if $field[-1] eq '~';
374 # print join(',', @field), "\n";
377 # process PC frames, this will fail unless the frame starts PCnn
378 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
379 unless (defined $pcno && $pcno >= 10 && $pcno <= 99) {
380 dbg("PCPROT: unknown protocol") if isdbg('chanerr');
384 # check for and dump bad protocol messages
385 my $n = check($pcno, @field);
387 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
391 # modify the hop count here
392 if ($self != $main::me) {
393 if (my ($hops, $trail) = $line =~ /\^H(\d+)(\^?\~?)?$/) {
397 $line =~ s/\^H(\d+)(\^?\~?)?$/sprintf('^H%d%s', $hops, $trail)/e;
398 $field[-1] = "H$hops";
402 # send it out for processing
403 my $origin = $self->{call};
405 my $sub = "handle_$pcno";
407 if ($self->can($sub)) {
408 $self->$sub($pcno, $line, $origin, @field);
410 $self->handle_default($pcno, $line, $origin, @field);
415 # This is called from inside the main cluster processing loop and is used
416 # for despatching commands that are doing some long processing job
421 my @dxchan = DXChannel::get_all();
425 # send out a pc50 on EVERY channel all at once
426 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
427 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
432 foreach $dxchan (@dxchan) {
433 next unless $dxchan->is_node;
434 next if $dxchan->handle_xml;
435 next if $dxchan == $main::me;
438 $dxchan->send($pc50s) if $pc50s;
440 # send a ping out on this channel
441 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
442 if ($dxchan->{nopings} <= 0) {
445 DXXml::Ping::add($main::me, $dxchan->call);
446 $dxchan->{nopings} -= 1;
447 $dxchan->{lastping} = $t;
448 $dxchan->{lastping} += $dxchan->{pingint} / 2 unless @{$dxchan->{pingtime}};
454 Investigate::process();
458 if ($t - $last10 >= 10) {
464 if ($main::systime >= $pc92_obs_timeout) {
465 time_out_pc92_routes();
466 $pc92_obs_timeout = $main::systime + $pc92_update_period;
471 # send out config broadcasts
472 foreach $dxchan (@dxchan) {
473 next unless $dxchan->is_node;
475 # send out a PC92 config record if required for me and
476 # all my non pc9x dependent nodes.
477 if ($main::systime >= $dxchan->{next_pc92_update}) {
478 if ($dxchan->{call} eq $main::mycall || !$dxchan->{do_pc9x}) {
479 $dxchan->broadcast_pc92_update($dxchan->{call});
485 if ($main::systime - 3600 > $last_hour) {
486 $last_hour = $main::systime;
491 # finish up a pc context
495 # some active measures
503 my @dxchan = DXChannel::get_all();
506 # send it if it isn't the except list and isn't isolated and still has a hop count
507 # taking into account filtering and so on
508 foreach $dxchan (@dxchan) {
509 next if $dxchan == $main::me;
510 next if $dxchan == $self && $self->is_node;
511 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
522 if ($self->{spotsfilter}) {
523 ($filter, $hops) = $self->{spotsfilter}->it(@_);
524 return unless $filter;
526 send_prot_line($self, $filter, $hops, $isolate, $line);
531 my ($self, $filter, $hops, $isolate, $line) = @_;
537 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
539 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
540 return unless $routeit;
543 $self->send($routeit);
545 $self->send($routeit) unless $self->{isolate} || $isolate;
554 my @dxchan = DXChannel::get_all();
556 my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
558 # send it if it isn't the except list and isn't isolated and still has a hop count
559 # taking into account filtering and so on
560 foreach $dxchan (@dxchan) {
561 next if $dxchan == $main::me;
562 next if $dxchan == $self && $self->is_node;
566 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
577 if ($self->{wwvfilter}) {
578 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_]);
579 return unless $filter;
581 send_prot_line($self, $filter, $hops, $isolate, $line)
588 my @dxchan = DXChannel::get_all();
590 my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
592 # send it if it isn't the except list and isn't isolated and still has a hop count
593 # taking into account filtering and so on
594 foreach $dxchan (@dxchan) {
595 next if $dxchan == $main::me;
596 next if $dxchan == $self;
598 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
609 if ($self->{wcyfilter}) {
610 ($filter, $hops) = $self->{wcyfilter}->it(@_);
611 return unless $filter;
613 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
620 my $from_pc9x = shift;
622 my @dxchan = DXChannel::get_all();
626 my $text = unpad($_[2]);
629 if ($_[3] eq '*') { # sysops
631 } elsif ($_[3] gt ' ') { # speciality list handling
632 my ($name) = split /\./, $_[3];
633 $target = "$name"; # put the rest in later (if bothered)
640 $target = "ALL" if !$target;
643 # obtain country codes etc
644 my @a = Prefix::cty_data($from);
645 my @b = Prefix::cty_data($_[4]);
646 if ($self->{inannfilter}) {
647 my ($filter, $hops) =
648 $self->{inannfilter}->it(@_, $self->{call},
650 @b[0..2], $a[3], $b[3]);
652 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
657 if (AnnTalk::dup($from, $_[1], $_[2])) {
658 my $dxchan = DXChannel::get($from);
659 if ($dxchan && $dxchan->is_user) {
660 if ($dxchan->priv < 5) {
661 $dxchan->send($dxchan->msg('dup'));
665 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
670 Log('ann', $target, $from, $text);
672 # send it if it isn't the except list and isn't isolated and still has a hop count
673 # taking into account filtering and so on
674 foreach $dxchan (@dxchan) {
675 next if $dxchan == $main::me;
676 next if $dxchan == $self && $self->is_node;
677 next if $from_pc9x && $dxchan->{do_pc9x};
678 next if $target eq 'LOCAL' && $dxchan->is_node;
679 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
689 $msgid = 1 if $msgid > 999;
697 my $from_pc9x = shift;
699 my @dxchan = DXChannel::get_all();
702 my $text = unpad($_[2]);
706 # munge the group and recast the line if required
707 if ($target =~ s/\.LST$//) {
711 # obtain country codes etc
712 my @a = Prefix::cty_data($from);
713 my @b = Prefix::cty_data($_[4]);
714 if ($self->{inannfilter}) {
715 my ($filter, $hops) =
716 $self->{inannfilter}->it(@_, $self->{call},
718 @b[0..2], $a[3], $b[3]);
720 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
725 if (AnnTalk::dup($from, $target, $_[2], $chatdupeage)) {
726 my $dxchan = DXChannel::get($from);
727 if ($dxchan && $dxchan->is_user) {
728 if ($dxchan->priv < 5) {
729 $dxchan->send($dxchan->msg('dup'));
733 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
739 Log('chat', $target, $from, $text);
741 # send it if it isn't the except list and isn't isolated and still has a hop count
742 # taking into account filtering and so on
743 foreach $dxchan (@dxchan) {
744 my $is_ak1a = $dxchan->is_ak1a;
746 if ($dxchan->is_node) {
747 next if $dxchan == $main::me;
748 next if $dxchan == $self;
749 next if $from_pc9x && $dxchan->{do_pc9x};
750 next unless $dxchan->is_spider || $is_ak1a;
751 next if $target eq 'LOCAL';
752 if (!$ak1a_line && $is_ak1a) {
753 $ak1a_line = pc12($_[0], $text, $_[1], "$target.LST");
757 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1],
758 $text, @_, $self->{call}, @a[0..2], @b[0..2]);
772 if ($self->{annfilter}) {
773 ($filter, $hops) = $self->{annfilter}->it(@_);
774 return unless $filter;
776 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
785 sub send_local_config
789 dbg('DXProt::send_local_config') if isdbg('trace');
797 if ($self->{isolate}) {
798 dbg("send_local_config: isolated");
799 @localnodes = ( $main::routeroot );
800 $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
801 } elsif ($self->{do_pc9x}) {
802 dbg("send_local_config: doing pc9x");
803 my $node = Route::Node::get($self->{call});
804 $self->send_last_pc92_config($main::routeroot);
805 $self->send(pc92a($main::routeroot, $node)) unless $main::routeroot->last_PC92C =~ /$self->{call}/;
807 # create a list of all the nodes that are not connected to this connection
808 # and are not themselves isolated, this to make sure that isolated nodes
809 # don't appear outside of this node
811 dbg("send_local_config: traditional");
813 # send locally connected nodes
814 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
815 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
816 $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
819 my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
821 for $node (@rawintcalls) {
822 push @intcalls, $node unless grep $node eq $_, @intcalls;
824 my $ref = Route::Node::get($self->{call});
825 my @rnodes = $ref->nodes;
826 for $node (@intcalls) {
827 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
829 $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
832 # get all the users connected on the above nodes and send them out
833 unless ($self->{do_pc9x}) {
834 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
836 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
837 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
839 dbg("sent a null value") if isdbg('chanerr');
845 sub gen_my_pc92_config
849 if ($node->{call} eq $main::mycall) {
850 my @dxchan = grep { $_->call ne $main::mycall && !$_->{isolate} } DXChannel::get_all();
851 dbg("ROUTE: all dxchan: " . join(',', map{$_->{call}} @dxchan)) if isdbg('routelow');
852 my @localnodes = map { my $r = Route::get($_->{call}); $r ? $r : () } @dxchan;
853 dbg("ROUTE: localnodes: " . join(',', map{$_->{call}} @localnodes)) if isdbg('routelow');
854 return pc92c($main::routeroot, @localnodes);
856 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
857 return pc92c($node, @rout);
861 sub send_last_pc92_config
865 if (my $l = $node->last_PC92C) {
868 $self->send_pc92_config($node);
877 dbg('DXProt::send_pc92_config') if isdbg('trace');
879 $node->last_PC92C(gen_my_pc92_config($node));
880 $self->send($node->last_PC92C);
883 sub broadcast_pc92_update
888 dbg('DXProt::broadcast_pc92_update') if isdbg('trace');
890 my $nref = Route::Node::get($call);
891 my $l = $nref->last_PC92C(gen_my_pc92_config($nref));
892 $main::me->broadcast_route_pc9x($main::mycall, undef, $l, 0);
893 $self->update_pc92_next($pc92_update_period);
896 sub time_out_pc92_routes
898 my @nodes = grep {$_->call ne $main::mycall && ($_->do_pc9x || $_->via_pc92)} Route::Node::get_all();
900 foreach my $n (@nodes) {
903 if (my $dxchan = DXChannel::get($n->call)) {
904 dbg("disconnecting local pc92 $dxchan->{call} on obscount") if isdbg('obscount');
908 my @parents = map {Route::Node::get($_)} $n->parents;
911 dbg("deleting pc92 $_->{call} from $n->{call} on obscount") if isdbg('obscount');
912 push @rdel, $n->del($_);
916 dbg("ROUTE: obscount on $n->{call} now $o") if isdbg('obscount');
920 $main::me->route_pc21($main::mycall, undef, $_) if $_;
925 # route a message down an appropriate interface for a callsign
927 # is called route(to, pcline);
932 my ($self, $call, $line) = @_;
934 if (ref $self && $call eq $self->{call}) {
935 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
939 # always send it down the local interface if available
940 my $dxchan = DXChannel::get($call);
942 dbg("route: $call -> $dxchan->{call} direct" ) if isdbg('route');
944 my $cl = Route::get($call);
945 $dxchan = $cl->dxchan if $cl;
947 if (ref $self && $dxchan eq $self) {
948 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
951 dbg("route: $call -> $dxchan->{call} using normal route" ) if isdbg('route');
955 # try the backstop method
957 my $rcall = RouteDB::get($call);
959 if ($self && $rcall eq $self->{call}) {
960 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
963 $dxchan = DXChannel::get($rcall);
964 dbg("route: $call -> $rcall using RouteDB" ) if isdbg('route') && $dxchan;
969 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
971 $dxchan->send($routeit) unless $dxchan == $main::me;
974 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
979 # obtain the hops from the list for this callsign and pc no
985 my $hops = $DXProt::hopcount{$pcno};
986 $hops = $DXProt::def_hopcount if !$hops;
991 # adjust the hop count on a per node basis using the user loadable
992 # hop table if available or else decrement an existing one
999 my $call = $self->{call};
1002 if (($hops) = $s =~ /\^H(\d+)\^?~?$/o) {
1003 my ($pcno) = $s =~ /^PC(\d\d)/o;
1004 confess "$call called adjust_hops with '$s'" unless $pcno;
1005 my $ref = $nodehops{$call} if %nodehops;
1007 my $newhops = $ref->{$pcno};
1008 return "" if defined $newhops && $newhops == 0;
1009 $newhops = $ref->{default} unless $newhops;
1010 return "" if defined $newhops && $newhops == 0;
1011 $newhops = $hops if !$newhops;
1012 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1024 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
1025 do "$main::data/hop_table.pl";
1032 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
1033 if ($tonode eq $main::mycall) {
1034 my $ref = DXUser->get_current($fromnode);
1035 my $cref = Route::Node::get($fromnode);
1036 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
1037 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
1038 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
1039 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
1040 my $oldpriv = $self->{priv};
1041 $self->{priv} = $ref->{priv}; # assume the user's privilege level
1042 my @in = (DXCommandmode::run_cmd($self, $cmd));
1043 $self->{priv} = $oldpriv;
1044 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
1045 delete $self->{remotecmd};
1047 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
1050 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
1053 my $ref = DXUser->get_current($tonode);
1054 if ($ref && $ref->is_clx) {
1055 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
1057 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
1062 sub process_rcmd_reply
1064 my ($self, $tonode, $fromnode, $user, $line) = @_;
1065 if ($tonode eq $main::mycall) {
1066 my $s = $rcmds{$fromnode};
1068 my $dxchan = DXChannel::get($s->{call});
1069 my $ref = $user eq $tonode ? $dxchan : (DXChannel::get($user) || $dxchan);
1070 $ref->send($line) if $ref;
1071 delete $rcmds{$fromnode} if !$dxchan;
1073 # send unsolicited ones to the sysop
1074 my $dxchan = DXChannel::get($main::myalias);
1075 $dxchan->send($line) if $dxchan;
1078 my $ref = DXUser->get_current($tonode);
1079 if ($ref && $ref->is_clx) {
1080 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
1082 $self->route($tonode, pc35($fromnode, $tonode, $line));
1091 my $fromnode = shift;
1096 Log('rcmd', 'out', $fromnode, $line);
1097 if ($self->is_clx) {
1098 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
1100 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
1105 # add a rcmd request to the rcmd queues
1108 my ($self, $to, $cmd) = @_;
1111 $r->{call} = $self->{call};
1112 $r->{t} = $main::systime;
1116 my $ref = Route::Node::get($to);
1117 my $dxchan = $ref->dxchan;
1118 if ($dxchan && $dxchan->is_clx) {
1119 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1121 route(undef, $to, pc34($main::mycall, $to, $cmd));
1128 my $pc39flag = shift;
1129 my $call = $self->call;
1131 return if $self->{disconnecting}++;
1133 unless ($pc39flag && $pc39flag == 1) {
1134 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1137 # get rid of any PC16/17/19
1138 eph_del_regex("^PC1[679]*$call");
1140 # do routing stuff, remove me from routing table
1141 my $node = Route::Node::get($call);
1144 @rout = $node->del($main::routeroot);
1146 # and all my ephemera as well
1149 eph_del_regex("^PC1[679].*$c");
1153 RouteDB::delete_interface($call);
1155 # unbusy and stop and outgoing mail
1156 my $mref = DXMsg::get_busy($call);
1157 $mref->stop_msg($call) if $mref;
1159 # broadcast to all other nodes that all the nodes connected to via me are gone
1160 unless ($pc39flag && $pc39flag == 2) {
1161 $self->route_pc21($main::mycall, undef, @rout) if @rout;
1162 $self->route_pc92d($main::mycall, undef, $main::routeroot, $node) if $node;
1165 # remove outstanding pings
1166 delete $pings{$call};
1168 # I was the last node visited
1169 $self->user->node($main::mycall);
1171 # send info to all logged in thingies
1172 $self->tell_login('logoutn');
1174 Log('DXProt', $call . " Disconnected");
1176 $self->SUPER::disconnect;
1181 # send a talk message to this thingy
1185 my ($self, $from, $to, $via, $line, $origin) = @_;
1187 if ($self->{do_pc9x}) {
1188 $self->send(pc93($to, $from, $via, $line));
1190 $self->send(pc10($from, $to, $via, $line, $origin));
1192 Log('talk', $to, $from, '>' . ($via || $origin || $self->call), $line) unless $origin && $origin ne $main::mycall;
1195 # send it if it isn't the except list and isn't isolated and still has a hop count
1196 # taking into account filtering and so on
1202 my $generate = shift;
1203 my $no = shift; # the no of things to filter on
1205 my ($filter, $hops);
1208 for (; @_ && $no; $no--) {
1211 if (!$self->{isolate} && $self->{routefilter}) {
1214 ($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});
1218 dbg("PCPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('filter');
1221 dbg("was sent a null value") if isdbg('chanerr');
1224 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
1228 foreach my $line (&$generate(@rin, @_)) {
1231 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1233 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1234 next unless $routeit;
1237 $self->send($routeit);
1242 # broadcast everywhere
1247 my $generate = shift;
1249 my @dxchan = DXChannel::get_all_nodes();
1253 $line =~ /\^H(\d+)\^?\~?$/;
1254 return unless $1 > 0;
1256 unless ($self->{isolate}) {
1257 foreach $dxchan (@dxchan) {
1258 next if $dxchan == $self || $dxchan == $main::me;
1259 next if $origin eq $dxchan->{call}; # don't route some from this call back again.
1260 next unless $dxchan->isa('DXProt');
1262 $dxchan->send_route($origin, $generate, @_);
1267 # broadcast to non-pc9x nodes
1268 sub broadcast_route_nopc9x
1272 my $generate = shift;
1274 my @dxchan = DXChannel::get_all_nodes();
1278 $line =~ /\^H(\d+)\^?\~?$/;
1279 return unless $1 > 0;
1281 unless ($self->{isolate}) {
1282 foreach $dxchan (@dxchan) {
1283 next if $dxchan == $self || $dxchan == $main::me;
1284 next if $origin eq $dxchan->{call}; # don't route some from this call back again.
1285 next unless $dxchan->isa('DXProt');
1286 next if $dxchan->{do_pc9x};
1287 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
1289 $dxchan->send_route($origin, $generate, @_);
1294 # this is only used for next door nodes on init
1299 return unless $self->{do_pc9x};
1302 my $generate = shift;
1303 my $no = shift; # the no of things to filter on
1306 $line = &$generate(@_);
1310 # broadcast only to pc9x nodes
1311 sub broadcast_route_pc9x
1315 my $generate = shift;
1318 my @dxchan = DXChannel::get_all_nodes();
1321 if ($origin eq $main::mycall && $generate && !$line) {
1322 $line = &$generate(@_);
1325 $line =~ /\^H(\d+)\^\~?$/;
1326 unless ($1 > 0 && $self->{isolate}) {
1327 foreach $dxchan (@dxchan) {
1328 next if $dxchan == $self || $dxchan == $main::me;
1329 next if $origin eq $dxchan->{call}; # don't route some from this call back again.
1330 next unless $dxchan->isa('DXProt');
1331 next unless $dxchan->{do_pc9x};
1333 $dxchan->send($line);
1341 return unless $self->user->wantpc16;
1344 broadcast_route_nopc9x($self, $origin, \&pc16, $line, 1, @_);
1350 return unless $self->user->wantpc16;
1353 broadcast_route_nopc9x($self, $origin, \&pc17, $line, 1, @_);
1361 broadcast_route_nopc9x($self, $origin, \&pc19, $line, scalar @_, @_);
1369 broadcast_route_nopc9x($self, $origin, \&pc21, $line, scalar @_, @_);
1377 broadcast_route($self, $origin, \&pc24, $line, 1, @_);
1385 broadcast_route($self, $origin, \&pc41, $line, 1, @_);
1393 broadcast_route($self, $origin, \&pc50, $line, 1, @_);
1401 broadcast_route_pc9x($self, $origin, \&pc92c, $line, 1, @_);
1409 broadcast_route_pc9x($self, $origin, \&pc92a, $line, 1, @_);
1417 broadcast_route_pc9x($self, $origin, \&pc92d, $line, 1, @_);
1424 my ($filter, $hops) = (1, 1);
1426 if ($self->{inroutefilter}) {
1427 ($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);
1428 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
1436 my $t = shift || $eph_restime;
1440 $s =~ s/\^H\d\d?\^?\~?$//;
1441 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
1442 $eph{$s} = $main::systime + $t;
1443 dbg("PCPROT: emphemeral duplicate") if $r && isdbg('chanerr');
1451 while (($key, $val) = each %eph) {
1452 if ($key =~ m{$regex}) {
1462 while (($key, $val) = each %eph) {
1463 if ($main::systime >= $val) {
1474 while (($key, $val) = each %eph) {
1475 push @out, $key, $val;
1482 goto &DXCommandmode::run_cmd;
1486 # import any msgs in the chat directory
1487 # the messages are sent to the chat group which forms the
1488 # the first part of the name (eg: solar.1243.txt would be
1489 # sent to chat group SOLAR)
1491 # Each message found is sent: one non-blank line to one chat
1492 # message. So 4 lines = 4 chat messages.
1494 # The special name LOCAL is for local users ANN
1495 # The special name ALL is for ANN/FULL
1496 # The special name SYSOP is for ANN/SYSOP
1500 # are there any to do in this directory?
1501 return unless -d $chatimportfn;
1502 unless (opendir(DIR, $chatimportfn)) {
1503 dbg("can\'t open $chatimportfn $!") if isdbg('msg');
1504 Log('msg', "can\'t open $chatimportfn $!");
1508 my @names = readdir(DIR);
1511 foreach $name (@names) {
1512 next if $name =~ /^\./;
1513 my $splitit = $name =~ /^split/;
1514 my $fn = "$chatimportfn/$name";
1516 unless (open(MSG, $fn)) {
1517 dbg("can\'t open import file $fn $!") if isdbg('msg');
1518 Log('msg', "can\'t open import file $fn $!");
1522 my @msg = map { s/\r?\n$//; $_ } <MSG>;
1526 my @cat = split /\./, $name;
1527 my $target = uc $cat[0];
1529 foreach my $text (@msg) {
1530 next unless $text && $text !~ /^\s*#/;
1531 if ($target eq 'ALL' || $target eq 'LOCAL' || $target eq 'SYSOP') {
1532 my $sysopflag = $target eq 'SYSOP' ? '*' : ' ';
1533 if ($target ne 'LOCAL') {
1534 send_announce($main::me, pc12($main::mycall, $text, '*', $sysopflag), $main::mycall, '*', $text, $sysopflag, $main::mycall, '0');
1536 Log('ann', 'LOCAL', $main::mycall, $text);
1537 DXChannel::broadcast_list("To LOCAL de ${main::mycall}: $text\a", 'ann', undef, DXCommandmode->get_all());
1540 my $msgid = nextchatmsgid();
1541 $text = "#$msgid $text";
1542 send_chat($main::me, pc12($main::mycall, $text, '*', $target), $main::mycall, '*', $text, $target, $main::mycall, '0');
1548 # start a pc92 find operation
1553 my $key = "$dxchan->{call}|$target";
1554 if ($pc92_find{$key}) {
1559 # function (not method) to handle pc92 find returns
1560 sub handle_pc92_find_reply
1562 my ($dxchan, $node, $from, $target, $flag, $ms) = @_;
1564 $dxchan->print_pc92_find_reply($node, $target, $flag, $ms) if $dxchan->can('print_pc92_find_return');