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 $last_pc92_update
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 = 30*60; # the period between PC92 C updates
77 $last_pc92_update = time + int rand(180); # the last time a PC92 config update
78 %pc92_find = (); # outstanding pc92 find operations
79 $pc92_find_timeout = 30; # maximum time to wait for a reply
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$/;
208 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
211 my $user = DXUser->get($main::mycall);
212 die "User $main::mycall not setup or disappeared RTFM" unless $user;
214 $myprot_version += $main::version*100;
215 $main::me = DXProt->new($main::mycall, 0, $user);
216 $main::me->{here} = 1;
217 $main::me->{state} = "indifferent";
218 $main::me->{sort} = 'S'; # S for spider
219 $main::me->{priv} = 9;
220 $main::me->{metric} = 0;
221 $main::me->{pingave} = 0;
222 $main::me->{registered} = 1;
223 $main::me->{version} = $main::version;
224 $main::me->{build} = $main::build;
225 $main::me->{do_pc9x} = 1;
229 # obtain a new connection this is derived from dxchannel
234 my $self = DXChannel::alloc(@_);
236 # add this node to the table, the values get filled in later
240 # if we have an entry already, then send a PC21 to all connect
241 # old style connections, because we are about to get the real deal
242 if (my $ref = Route::Node::get($call)) {
243 dbg("ROUTE: $call is already in the routing table, deleting") if isdbg('route');
244 my @rout = $ref->delete;
245 $self->route_pc21($main::mycall, undef, @rout) if @rout;
247 $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
252 # this is how a pc connection starts (for an incoming connection)
253 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
254 # all the crap that comes between).
257 my ($self, $line, $sort) = @_;
258 my $call = $self->{call};
259 my $user = $self->{user};
262 my $host = $self->{conn}->{peerhost};
263 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
266 Log('DXProt', "$call connected from $host");
268 # remember type of connection
269 $self->{consort} = $line;
270 $self->{outbound} = $sort eq 'O';
271 my $priv = $user->priv;
272 $priv = $user->priv(1) unless $priv;
273 $self->{priv} = $priv; # other clusters can always be 'normal' users
274 $self->{lang} = $user->lang || 'en';
275 $self->{isolate} = $user->{isolate};
276 $self->{consort} = $line; # save the connection type
280 # sort out registration
281 $self->{registered} = 1;
283 # get the output filters
284 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
285 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
286 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
287 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
288 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
291 # get the INPUT filters (these only pertain to Clusters)
292 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
293 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
294 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
295 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
296 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
297 # if there is no route input filter then specify a default one.
298 # obviously this can be changed later by the sysop.
299 if (!$self->{inroutefilter}) {
300 my $dxcc = $self->dxcc;
301 $Route::filterdef->cmd($self, 'route', 'accept', "input by_dxcc $dxcc" );
304 # set unbuffered and no echo
305 $self->send_now('B',"0");
306 $self->send_now('E',"0");
307 $self->conn->echo(0) if $self->conn->can('echo');
309 # ping neighbour node stuff
310 my $ping = $user->pingint;
311 $ping = $pingint unless defined $ping;
312 $self->{pingint} = $ping;
313 $self->{nopings} = $user->nopings || $obscount;
314 $self->{pingtime} = [ ];
315 $self->{pingave} = 999;
316 $self->{metric} ||= 100;
317 $self->{lastping} = $main::systime;
319 # send initialisation string
320 unless ($self->{outbound}) {
324 $self->state('init');
325 $self->{pc50_t} = $main::systime;
327 # send info to all logged in thingies
328 $self->tell_login('loginn');
330 # run a script send the output to the debug file
331 my $script = new Script(lc $call) || new Script('node_default');
332 $script->run($self) if $script;
336 # send outgoing 'challenge'
346 # This is the normal pcxx despatcher
350 my ($self, $line) = @_;
352 if ($line =~ '^<\w+\s' && $main::do_xml) {
353 DXXml::normal($self, $line);
357 my @field = split /\^/, $line;
358 return unless @field;
360 pop @field if $field[-1] eq '~';
362 # print join(',', @field), "\n";
365 # process PC frames, this will fail unless the frame starts PCnn
366 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
367 unless (defined $pcno && $pcno >= 10 && $pcno <= 99) {
368 dbg("PCPROT: unknown protocol") if isdbg('chanerr');
372 # check for and dump bad protocol messages
373 my $n = check($pcno, @field);
375 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
379 # modify the hop count here
380 if ($self != $main::me) {
381 if (my ($hops, $trail) = $line =~ /\^H(\d+)(\^?\~?)?$/) {
385 $line =~ s/\^H(\d+)(\^?\~?)?$/sprintf('^H%d%s', $hops, $trail)/e;
386 $field[-1] = "H$hops";
390 # send it out for processing
391 my $origin = $self->{call};
393 my $sub = "handle_$pcno";
395 if ($self->can($sub)) {
396 $self->$sub($pcno, $line, $origin, @field);
398 $self->handle_default($pcno, $line, $origin, @field);
403 # This is called from inside the main cluster processing loop and is used
404 # for despatching commands that are doing some long processing job
409 my @dxchan = DXChannel::get_all();
413 # send out a pc50 on EVERY channel all at once
414 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
415 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
420 foreach $dxchan (@dxchan) {
421 next unless $dxchan->is_node;
422 next if $dxchan->handle_xml;
423 next if $dxchan == $main::me;
426 $dxchan->send($pc50s) if $pc50s;
428 # send a ping out on this channel
429 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
430 if ($dxchan->{nopings} <= 0) {
433 DXXml::Ping::add($main::me, $dxchan->call);
434 $dxchan->{nopings} -= 1;
435 $dxchan->{lastping} = $t;
436 $dxchan->{lastping} += $dxchan->{pingint} / 2 unless @{$dxchan->{pingtime}};
441 Investigate::process();
445 if ($t - $last10 >= 10) {
451 if ($main::systime >= $last_pc92_update + $pc92_update_period) {
452 dbg("ROUTE: sending pc92 update") if isdbg('route');
454 time_out_pc92_routes();
455 $last_pc92_update = $main::systime + int rand(5*60);
461 if ($main::systime - 3600 > $last_hour) {
462 $last_hour = $main::systime;
467 # finish up a pc context
471 # some active measures
479 my @dxchan = DXChannel::get_all();
482 # send it if it isn't the except list and isn't isolated and still has a hop count
483 # taking into account filtering and so on
484 foreach $dxchan (@dxchan) {
485 next if $dxchan == $main::me;
486 next if $dxchan == $self && $self->is_node;
487 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
498 if ($self->{spotsfilter}) {
499 ($filter, $hops) = $self->{spotsfilter}->it(@_);
500 return unless $filter;
502 send_prot_line($self, $filter, $hops, $isolate, $line);
507 my ($self, $filter, $hops, $isolate, $line) = @_;
513 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
515 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
516 return unless $routeit;
519 $self->send($routeit);
521 $self->send($routeit) unless $self->{isolate} || $isolate;
530 my @dxchan = DXChannel::get_all();
532 my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
534 # send it if it isn't the except list and isn't isolated and still has a hop count
535 # taking into account filtering and so on
536 foreach $dxchan (@dxchan) {
537 next if $dxchan == $main::me;
538 next if $dxchan == $self && $self->is_node;
542 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
553 if ($self->{wwvfilter}) {
554 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_]);
555 return unless $filter;
557 send_prot_line($self, $filter, $hops, $isolate, $line)
564 my @dxchan = DXChannel::get_all();
566 my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
568 # send it if it isn't the except list and isn't isolated and still has a hop count
569 # taking into account filtering and so on
570 foreach $dxchan (@dxchan) {
571 next if $dxchan == $main::me;
572 next if $dxchan == $self;
574 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
585 if ($self->{wcyfilter}) {
586 ($filter, $hops) = $self->{wcyfilter}->it(@_);
587 return unless $filter;
589 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
596 my $from_pc9x = shift;
598 my @dxchan = DXChannel::get_all();
602 my $text = unpad($_[2]);
604 if ($_[3] eq '*') { # sysops
606 } elsif ($_[3] gt ' ') { # speciality list handling
607 my ($name) = split /\./, $_[3];
608 $target = "$name"; # put the rest in later (if bothered)
615 $target = "ALL" if !$target;
618 # obtain country codes etc
619 my @a = Prefix::cty_data($_[0]);
620 my @b = Prefix::cty_data($_[4]);
621 if ($self->{inannfilter}) {
622 my ($filter, $hops) =
623 $self->{inannfilter}->it(@_, $self->{call},
625 @b[0..2], $a[3], $b[3]);
627 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
632 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
633 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
637 Log('ann', $target, $_[0], $text);
639 # send it if it isn't the except list and isn't isolated and still has a hop count
640 # taking into account filtering and so on
641 foreach $dxchan (@dxchan) {
642 next if $dxchan == $main::me;
643 next if $dxchan == $self && $self->is_node;
644 next if $from_pc9x && $dxchan->{do_pc9x};
645 next if $target eq 'LOCAL' && $dxchan->is_node;
646 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
656 $msgid = 1 if $msgid > 999;
664 my $from_pc9x = shift;
666 my @dxchan = DXChannel::get_all();
669 my $text = unpad($_[2]);
672 # munge the group and recast the line if required
673 if ($target =~ s/\.LST$//) {
677 # obtain country codes etc
678 my @a = Prefix::cty_data($_[0]);
679 my @b = Prefix::cty_data($_[4]);
680 if ($self->{inannfilter}) {
681 my ($filter, $hops) =
682 $self->{inannfilter}->it(@_, $self->{call},
684 @b[0..2], $a[3], $b[3]);
686 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
691 if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
692 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
697 Log('chat', $target, $_[0], $text);
699 # send it if it isn't the except list and isn't isolated and still has a hop count
700 # taking into account filtering and so on
701 foreach $dxchan (@dxchan) {
702 my $is_ak1a = $dxchan->is_ak1a;
704 if ($dxchan->is_node) {
705 next if $dxchan == $main::me;
706 next if $dxchan == $self;
707 next if $from_pc9x && $dxchan->{do_pc9x};
708 next unless $dxchan->is_spider || $is_ak1a;
709 next if $target eq 'LOCAL';
710 if (!$ak1a_line && $is_ak1a) {
711 $ak1a_line = pc12($_[0], $text, $_[1], "$target.LST");
715 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1],
716 $text, @_, $self->{call}, @a[0..2], @b[0..2]);
730 if ($self->{annfilter}) {
731 ($filter, $hops) = $self->{annfilter}->it(@_);
732 return unless $filter;
734 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
743 sub send_local_config
747 dbg('DXProt::send_local_config') if isdbg('trace');
750 if ($self->{do_pc9x}) {
751 $self->send_pc92_config;
758 if ($self->{isolate}) {
759 @localnodes = ( $main::routeroot );
760 $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
762 # create a list of all the nodes that are not connected to this connection
763 # and are not themselves isolated, this to make sure that isolated nodes
764 # don't appear outside of this node
766 # send locally connected nodes
767 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
768 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
769 $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
772 my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
774 for $node (@rawintcalls) {
775 push @intcalls, $node unless grep $node eq $_, @intcalls;
777 my $ref = Route::Node::get($self->{call});
778 my @rnodes = $ref->nodes;
779 for $node (@intcalls) {
780 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
782 $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
785 # get all the users connected on the above nodes and send them out
786 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
788 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
789 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
791 dbg("sent a null value") if isdbg('chanerr');
797 sub gen_my_pc92_config
801 if ($node->{call} eq $main::mycall) {
802 my @dxchan = grep { $_->call ne $main::mycall && !$_->{isolate} } DXChannel::get_all();
803 dbg("ROUTE: all dxchan: " . join(',', map{$_->{call}} @dxchan)) if isdbg('routelow');
804 my @localnodes = map { my $r = Route::get($_->{call}); $r ? $r : () } @dxchan;
805 dbg("ROUTE: localnodes: " . join(',', map{$_->{call}} @localnodes)) if isdbg('routelow');
806 return pc92c($main::routeroot, @localnodes);
808 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
809 return pc92c($node, @rout);
816 my $with_pc92_nodes = shift;
822 dbg('ROUTE: DXProt::gen_pc92_update start') if isdbg('routelow');
824 # send 'my' configuration for all channels
825 push @lines, gen_my_pc92_config($main::routeroot);
827 if ($with_pc92_nodes) {
828 # send out the configuration of all the directly connected PC92 nodes with current configuration
829 # but with the dates that the last config came in with.
830 @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && $_->{do_pc9x} } DXChannel::get_all_nodes();
831 dbg("ROUTE: pc92 dxchan: " . join(',', map{$_->{call}} @dxchan)) if isdbg('routelow');
832 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan;
833 dbg("ROUTE: pc92 localnodes: " . join(',', map{$_->{call}} @localnodes)) if isdbg('routelow');
834 foreach $node (@localnodes) {
835 if ($node && $node->lastid->{92}) {
836 my @rout = map {my $r = Route::get($_); $r ? ($r) : ()} $node->nodes, $node->users;
837 push @lines, gen_pc92_with_time($node->call, 'C', $node->lastid->{92}, @rout);
842 # send the configuration of all the directly connected 'external' nodes that don't handle PC92
843 # out with the 'external' marker on the first node.
844 @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && !$_->{do_pc9x} } DXChannel::get_all_nodes();
845 dbg("ROUTE: non pc92 dxchan: " . join(',', map{$_->{call}} @dxchan)) if isdbg('routelow');
846 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan;
847 dbg("ROUTE: non pc92 localnodes: " . join(',', map{$_->{call}} @localnodes)) if isdbg('routelow');
848 foreach $node (@localnodes) {
850 push @lines, gen_my_pc92_config($node);
854 dbg('ROUTE: DXProt::gen_pc92_update end with ' . scalar @lines . ' lines') if isdbg('routelow');
863 dbg('DXProt::send_pc92_config') if isdbg('trace');
865 my @out = $self->gen_pc92_update(1);
867 # send the complete config out on this interface
875 my @out = $main::me->gen_pc92_update(0);
877 # broadcast the lines to all PC92 nodes
879 $main::me->broadcast_route_pc9x($main::mycall, undef, $_, 0);
883 sub time_out_pc92_routes
885 my @nodes = grep {$_->call ne $main::mycall && ($_->do_pc9x || $_->via_pc92)} Route::Node::get_all();
887 foreach my $n (@nodes) {
890 if (my $dxchan = DXChannel::get($n->call)) {
891 dbg("ROUTE: disconnecting local pc92 $dxchan->{call} on obscount") if isdbg('route');
895 my @parents = map {Route::Node::get($_)} $n->parents;
898 dbg("ROUTE: deleting pc92 $_->{call} from $n->{call} on obscount") if isdbg('route');
899 push @rdel, $n->del($_);
903 dbg("ROUTE: obscount on $n->{call} now $o") if isdbg('route');
907 $main::me->route_pc21($main::mycall, undef, $_) if $_;
912 # route a message down an appropriate interface for a callsign
914 # is called route(to, pcline);
919 my ($self, $call, $line) = @_;
921 if (ref $self && $call eq $self->{call}) {
922 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
926 # always send it down the local interface if available
927 my $dxchan = DXChannel::get($call);
929 dbg("route: $call -> $dxchan->{call} direct" ) if isdbg('route');
931 my $cl = Route::get($call);
932 $dxchan = $cl->dxchan if $cl;
934 if (ref $self && $dxchan eq $self) {
935 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
938 dbg("route: $call -> $dxchan->{call} using normal route" ) if isdbg('route');
942 # try the backstop method
944 my $rcall = RouteDB::get($call);
946 if ($self && $rcall eq $self->{call}) {
947 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
950 $dxchan = DXChannel::get($rcall);
951 dbg("route: $call -> $rcall using RouteDB" ) if isdbg('route') && $dxchan;
956 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
958 $dxchan->send($routeit) unless $dxchan == $main::me;
961 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
966 # obtain the hops from the list for this callsign and pc no
972 my $hops = $DXProt::hopcount{$pcno};
973 $hops = $DXProt::def_hopcount if !$hops;
978 # adjust the hop count on a per node basis using the user loadable
979 # hop table if available or else decrement an existing one
986 my $call = $self->{call};
989 if (($hops) = $s =~ /\^H(\d+)\^?~?$/o) {
990 my ($pcno) = $s =~ /^PC(\d\d)/o;
991 confess "$call called adjust_hops with '$s'" unless $pcno;
992 my $ref = $nodehops{$call} if %nodehops;
994 my $newhops = $ref->{$pcno};
995 return "" if defined $newhops && $newhops == 0;
996 $newhops = $ref->{default} unless $newhops;
997 return "" if defined $newhops && $newhops == 0;
998 $newhops = $hops if !$newhops;
999 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1011 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
1012 do "$main::data/hop_table.pl";
1019 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
1020 if ($tonode eq $main::mycall) {
1021 my $ref = DXUser->get_current($fromnode);
1022 my $cref = Route::Node::get($fromnode);
1023 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
1024 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
1025 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
1026 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
1027 my $oldpriv = $self->{priv};
1028 $self->{priv} = $ref->{priv}; # assume the user's privilege level
1029 my @in = (DXCommandmode::run_cmd($self, $cmd));
1030 $self->{priv} = $oldpriv;
1031 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
1032 delete $self->{remotecmd};
1034 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
1037 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
1040 my $ref = DXUser->get_current($tonode);
1041 if ($ref && $ref->is_clx) {
1042 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
1044 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
1049 sub process_rcmd_reply
1051 my ($self, $tonode, $fromnode, $user, $line) = @_;
1052 if ($tonode eq $main::mycall) {
1053 my $s = $rcmds{$fromnode};
1055 my $dxchan = DXChannel::get($s->{call});
1056 my $ref = $user eq $tonode ? $dxchan : (DXChannel::get($user) || $dxchan);
1057 $ref->send($line) if $ref;
1058 delete $rcmds{$fromnode} if !$dxchan;
1060 # send unsolicited ones to the sysop
1061 my $dxchan = DXChannel::get($main::myalias);
1062 $dxchan->send($line) if $dxchan;
1065 my $ref = DXUser->get_current($tonode);
1066 if ($ref && $ref->is_clx) {
1067 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
1069 $self->route($tonode, pc35($fromnode, $tonode, $line));
1078 my $fromnode = shift;
1083 Log('rcmd', 'out', $fromnode, $line);
1084 if ($self->is_clx) {
1085 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
1087 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
1092 # add a rcmd request to the rcmd queues
1095 my ($self, $to, $cmd) = @_;
1098 $r->{call} = $self->{call};
1099 $r->{t} = $main::systime;
1103 my $ref = Route::Node::get($to);
1104 my $dxchan = $ref->dxchan;
1105 if ($dxchan && $dxchan->is_clx) {
1106 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1108 route(undef, $to, pc34($main::mycall, $to, $cmd));
1115 my $pc39flag = shift;
1116 my $call = $self->call;
1118 return if $self->{disconnecting}++;
1120 unless ($pc39flag && $pc39flag == 1) {
1121 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1124 # get rid of any PC16/17/19
1125 eph_del_regex("^PC1[679]*$call");
1127 # do routing stuff, remove me from routing table
1128 my $node = Route::Node::get($call);
1131 @rout = $node->del($main::routeroot);
1133 # and all my ephemera as well
1136 eph_del_regex("^PC1[679].*$c");
1140 RouteDB::delete_interface($call);
1142 # unbusy and stop and outgoing mail
1143 my $mref = DXMsg::get_busy($call);
1144 $mref->stop_msg($call) if $mref;
1146 # broadcast to all other nodes that all the nodes connected to via me are gone
1147 unless ($pc39flag && $pc39flag == 2) {
1148 $self->route_pc21($main::mycall, undef, @rout) if @rout;
1149 $self->route_pc92d($main::mycall, undef, $main::routeroot, $node) if $node;
1152 # remove outstanding pings
1153 delete $pings{$call};
1155 # I was the last node visited
1156 $self->user->node($main::mycall);
1158 # send info to all logged in thingies
1159 $self->tell_login('logoutn');
1161 Log('DXProt', $call . " Disconnected");
1163 $self->SUPER::disconnect;
1168 # send a talk message to this thingy
1172 my ($self, $from, $to, $via, $line, $origin) = @_;
1174 if ($self->{do_pc9x}) {
1175 $self->send(pc93($to, $from, $via, $line));
1177 $self->send(pc10($from, $to, $via, $line, $origin));
1179 Log('talk', $to, $from, '>' . ($via || $origin || $self->call), $line) unless $origin && $origin ne $main::mycall;
1182 # send it if it isn't the except list and isn't isolated and still has a hop count
1183 # taking into account filtering and so on
1189 my $generate = shift;
1190 my $no = shift; # the no of things to filter on
1192 my ($filter, $hops);
1195 for (; @_ && $no; $no--) {
1198 if (!$self->{isolate} && $self->{routefilter}) {
1201 ($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});
1205 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
1208 dbg("was sent a null value") if isdbg('chanerr');
1211 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
1215 foreach my $line (&$generate(@rin, @_)) {
1218 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1220 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1221 next unless $routeit;
1224 $self->send($routeit);
1233 my $generate = shift;
1235 my @dxchan = DXChannel::get_all_nodes();
1239 $line =~ /\^H(\d+)\^?\~?$/;
1240 return unless $1 > 0;
1242 unless ($self->{isolate}) {
1243 foreach $dxchan (@dxchan) {
1244 next if $dxchan == $self;
1245 next if $dxchan == $main::me;
1246 next unless $dxchan->isa('DXProt');
1247 next if $dxchan->{do_pc9x};
1248 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
1250 $dxchan->send_route($origin, $generate, @_);
1255 # this is only used for next door nodes on init
1260 return unless $self->{do_pc9x};
1263 my $generate = shift;
1264 my $no = shift; # the no of things to filter on
1267 $line = &$generate(@_);
1271 sub broadcast_route_pc9x
1275 my $generate = shift;
1278 my @dxchan = DXChannel::get_all_nodes();
1281 if ($origin eq $main::mycall && $generate && !$line) {
1282 $line = &$generate(@_);
1285 $line =~ /\^H(\d+)\^\~?$/;
1286 unless ($1 > 0 && $self->{isolate}) {
1287 foreach $dxchan (@dxchan) {
1288 next if $dxchan == $self || $dxchan == $main::me;
1289 next if $origin eq $dxchan->{call}; # don't route some from this call back again.
1290 next unless $dxchan->{do_pc9x};
1291 next unless $dxchan->isa('DXProt');
1293 $dxchan->send($line);
1301 return unless $self->user->wantpc16;
1304 broadcast_route($self, $origin, \&pc16, $line, 1, @_);
1310 return unless $self->user->wantpc16;
1313 broadcast_route($self, $origin, \&pc17, $line, 1, @_);
1321 broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
1329 broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
1337 broadcast_route($self, $origin, \&pc24, $line, 1, @_);
1345 broadcast_route($self, $origin, \&pc41, $line, 1, @_);
1353 broadcast_route($self, $origin, \&pc50, $line, 1, @_);
1361 broadcast_route_pc9x($self, $origin, \&pc92c, $line, 1, @_);
1369 broadcast_route_pc9x($self, $origin, \&pc92a, $line, 1, @_);
1377 broadcast_route_pc9x($self, $origin, \&pc92d, $line, 1, @_);
1384 my ($filter, $hops) = (1, 1);
1386 if ($self->{inroutefilter}) {
1387 ($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);
1388 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
1396 my $t = shift || $eph_restime;
1400 $s =~ s/\^H\d\d?\^?\~?$//;
1401 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
1402 $eph{$s} = $main::systime + $t;
1403 dbg("PCPROT: emphemeral duplicate") if $r && isdbg('chanerr');
1411 while (($key, $val) = each %eph) {
1412 if ($key =~ m{$regex}) {
1422 while (($key, $val) = each %eph) {
1423 if ($main::systime >= $val) {
1434 while (($key, $val) = each %eph) {
1435 push @out, $key, $val;
1442 goto &DXCommandmode::run_cmd;
1446 # import any msgs in the chat directory
1447 # the messages are sent to the chat group which forms the
1448 # the first part of the name (eg: solar.1243.txt would be
1449 # sent to chat group SOLAR)
1451 # Each message found is sent: one non-blank line to one chat
1452 # message. So 4 lines = 4 chat messages.
1454 # The special name LOCAL is for local users ANN
1455 # The special name ALL is for ANN/FULL
1456 # The special name SYSOP is for ANN/SYSOP
1460 # are there any to do in this directory?
1461 return unless -d $chatimportfn;
1462 unless (opendir(DIR, $chatimportfn)) {
1463 dbg("can\'t open $chatimportfn $!") if isdbg('msg');
1464 Log('msg', "can\'t open $chatimportfn $!");
1468 my @names = readdir(DIR);
1471 foreach $name (@names) {
1472 next if $name =~ /^\./;
1473 my $splitit = $name =~ /^split/;
1474 my $fn = "$chatimportfn/$name";
1476 unless (open(MSG, $fn)) {
1477 dbg("can\'t open import file $fn $!") if isdbg('msg');
1478 Log('msg', "can\'t open import file $fn $!");
1482 my @msg = map { s/\r?\n$//; $_ } <MSG>;
1486 my @cat = split /\./, $name;
1487 my $target = uc $cat[0];
1489 foreach my $text (@msg) {
1490 next unless $text && $text !~ /^\s*#/;
1491 if ($target eq 'ALL' || $target eq 'LOCAL' || $target eq 'SYSOP') {
1492 my $sysopflag = $target eq 'SYSOP' ? '*' : ' ';
1493 if ($target ne 'LOCAL') {
1494 send_announce($main::me, pc12($main::mycall, $text, '*', $sysopflag), $main::mycall, '*', $text, $sysopflag, $main::mycall, '0');
1496 Log('ann', 'LOCAL', $main::mycall, $text);
1497 DXChannel::broadcast_list("To LOCAL de ${main::mycall}: $text\a", 'ann', undef, DXCommandmode->get_all());
1500 my $msgid = nextchatmsgid();
1501 $text = "#$msgid $text";
1502 send_chat($main::me, pc12($main::mycall, $text, '*', $target), $main::mycall, '*', $text, $target, $main::mycall, '0');
1508 # start a pc92 find operation
1513 my $key = "$dxchan->{call}|$target";
1514 if ($pc92_find{$key}) {
1519 # function (not method) to handle pc92 find returns
1520 sub handle_pc92_find_reply
1522 my ($dxchan, $node, $from, $target, $flag, $ms) = @_;
1524 $dxchan->print_pc92_find_reply($node, $target, $flag, $ms) if $dxchan->can('print_pc92_find_return');