3 # This module impliments the protocal mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
41 use vars qw($VERSION $BRANCH);
42 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
43 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
44 $main::build += $VERSION;
45 $main::branch += $BRANCH;
47 use vars qw($pc11_max_age $pc23_max_age $last_pc50 $eph_restime $eph_info_restime $eph_pc34_restime
48 $last_hour $last10 %eph %pings %rcmds $ann_to_talk
49 $pingint $obscount %pc19list $chatdupeage $chatimportfn
50 $investigation_int $pc19_version $myprot_version
51 %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
52 $allowzero $decode_dk0wcy $send_opernam @checklist
53 $eph_pc15_restime $pc92_update_period $last_pc92_update
56 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
57 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
59 $last_hour = time; # last time I did an hourly periodic update
60 %rcmds = (); # outstanding rcmd requests outbound
61 %nodehops = (); # node specific hop control
62 %pc19list = (); # list of outstanding PC19s that haven't had PC16s on them
64 $censorpc = 1; # Do a BadWords::check on text fields and reject things
65 # loads of 'bad things'
66 $baddx = new DXHash "baddx";
67 $badspotter = new DXHash "badspotter";
68 $badnode = new DXHash "badnode";
69 $last10 = $last_pc50 = time;
73 $eph_info_restime = 60*60;
74 $eph_pc15_restime = 6*60;
75 $eph_pc34_restime = 30;
78 $chatdupeage = 20 * 60 * 60;
79 $chatimportfn = "$main::root/chat_import";
80 $investigation_int = 12*60*60; # time between checks to see if we can see this node
81 $pc19_version = 5466; # the visible version no for outgoing PC19s generated from pc59
82 $pc92_update_period = 60*60; # the period between PC92 C updates
83 $last_pc92_update = time; # the last time a PC92 config update
88 [ qw(i c c m bp bc c) ], # pc10
89 [ qw(i f m d t m c c h) ], # pc11
90 [ qw(i c bm m bm bm p h) ], # pc12
94 undef , # pc16 has to be validated manually
95 [ qw(i c c h) ], # pc17
97 undef , # pc19 has to be validated manually
98 undef , # pc20 no validation
99 [ qw(i c m h) ], # pc21
100 undef , # pc22 no validation
101 [ qw(i d n n n n m c c h) ], # pc23
102 [ qw(i c p h) ], # pc24
103 [ qw(i c c n n) ], # pc25
104 [ qw(i f m d t m c c bc) ], # pc26
105 [ qw(i d n n n n m c c bc) ], # pc27
106 [ qw(i c c m c d t p m bp n p bp bc) ], # pc28
107 [ qw(i c c n m) ], # pc29
108 [ qw(i c c n) ], # pc30
109 [ qw(i c c n) ], # pc31
110 [ qw(i c c n) ], # pc32
111 [ qw(i c c n) ], # pc33
112 [ qw(i c c m) ], # pc34
113 [ qw(i c c m) ], # pc35
114 [ qw(i c c m) ], # pc36
115 [ qw(i c c n m) ], # pc37
116 undef, # pc38 not interested
117 [ qw(i c m) ], # pc39
118 [ qw(i c c m p n) ], # pc40
119 [ qw(i c n m h) ], # pc41
120 [ qw(i c c n) ], # pc42
121 undef, # pc43 don't handle it
122 [ qw(i c c n m m c) ], # pc44
123 [ qw(i c c n m) ], # pc45
124 [ qw(i c c n) ], # pc46
127 [ qw(i c m h) ], # pc49
128 [ qw(i c n h) ], # pc50
129 [ qw(i c c n) ], # pc51
151 [ qw(i d n n n n n n m m m c c h) ], # pc73
162 [ qw(i c c c m) ], # pc84
163 [ qw(i c c c m) ], # pc85
168 [ qw(i c n) ], # pc90
171 # use the entry in the check list to check the field list presented
172 # return OK if line NOT in check list (for now)
177 return 0 if $n < 0 || $n > @checklist;
178 my $ref = $checklist[$n];
179 return 0 unless ref $ref;
182 for ($i = 1; $i < @$ref; $i++) {
183 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
184 return 0 unless $act;
185 next if $blank && $_[$i] =~ /^[ \*]$/;
187 return $i unless is_callsign($_[$i]);
188 } elsif ($act eq 'i') {
190 } elsif ($act eq 'm') {
191 return $i unless is_pctext($_[$i]);
192 } elsif ($act eq 'p') {
193 return $i unless is_pcflag($_[$i]);
194 } elsif ($act eq 'f') {
195 return $i unless is_freq($_[$i]);
196 } elsif ($act eq 'n') {
197 return $i unless $_[$i] =~ /^[\d ]+$/;
198 } elsif ($act eq 'h') {
199 return $i unless $_[$i] =~ /^H\d\d?$/;
200 } elsif ($act eq 'd') {
201 return $i unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
202 } elsif ($act eq 't') {
203 return $i unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
211 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
214 my $user = DXUser->get($main::mycall);
215 die "User $main::mycall not setup or disappeared RTFM" unless $user;
217 $myprot_version += $main::version*100;
218 $main::me = DXProt->new($main::mycall, 0, $user);
219 $main::me->{here} = 1;
220 $main::me->{state} = "indifferent";
221 $main::me->{sort} = 'S'; # S for spider
222 $main::me->{priv} = 9;
223 $main::me->{metric} = 0;
224 $main::me->{pingave} = 0;
225 $main::me->{registered} = 1;
226 $main::me->{version} = $main::version;
227 $main::me->{build} = $main::build;
231 # obtain a new connection this is derived from dxchannel
236 my $self = DXChannel::alloc(@_);
238 # add this node to the table, the values get filled in later
241 $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
246 # this is how a pc connection starts (for an incoming connection)
247 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
248 # all the crap that comes between).
251 my ($self, $line, $sort) = @_;
252 my $call = $self->{call};
253 my $user = $self->{user};
256 my $host = $self->{conn}->{peerhost};
257 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
260 Log('DXProt', "$call connected from $host");
262 # remember type of connection
263 $self->{consort} = $line;
264 $self->{outbound} = $sort eq 'O';
265 my $priv = $user->priv;
266 $priv = $user->priv(1) unless $priv;
267 $self->{priv} = $priv; # other clusters can always be 'normal' users
268 $self->{lang} = $user->lang || 'en';
269 $self->{isolate} = $user->{isolate};
270 $self->{consort} = $line; # save the connection type
274 # sort out registration
275 $self->{registered} = 1;
277 # get the output filters
278 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
279 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
280 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
281 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
282 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
285 # get the INPUT filters (these only pertain to Clusters)
286 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
287 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
288 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
289 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
290 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
292 # set unbuffered and no echo
293 $self->send_now('B',"0");
294 $self->send_now('E',"0");
295 $self->conn->echo(0) if $self->conn->can('echo');
297 # ping neighbour node stuff
298 my $ping = $user->pingint;
299 $ping = $pingint unless defined $ping;
300 $self->{pingint} = $ping;
301 $self->{nopings} = $user->nopings || $obscount;
302 $self->{pingtime} = [ ];
303 $self->{pingave} = 999;
304 $self->{metric} ||= 100;
305 $self->{lastping} = $main::systime;
307 # send initialisation string
308 unless ($self->{outbound}) {
312 $self->state('init');
313 $self->{pc50_t} = $main::systime;
315 # send info to all logged in thingies
316 $self->tell_login('loginn');
318 # run a script send the output to the debug file
319 my $script = new Script(lc $call) || new Script('node_default');
320 $script->run($self) if $script;
324 # send outgoing 'challenge'
334 # This is the normal pcxx despatcher
338 my ($self, $line) = @_;
340 if ($line =~ '^<\w+\s' && $main::do_xml) {
341 DXXml::normal($self, $line);
345 my @field = split /\^/, $line;
346 return unless @field;
348 pop @field if $field[-1] eq '~';
350 # print join(',', @field), "\n";
353 # process PC frames, this will fail unless the frame starts PCnn
354 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
355 unless (defined $pcno && $pcno >= 10 && $pcno <= 99) {
356 dbg("PCPROT: unknown protocol") if isdbg('chanerr');
360 # check for and dump bad protocol messages
361 my $n = check($pcno, @field);
363 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
367 # modify the hop count here
368 if (my ($hops, $trail) = $line =~ /\^H(\d+)(\^?\~?)?$/) {
372 $line =~ s/\^H(\d+)(\^?\~?)?$/sprintf('^H%d%s', $hops, $trail)/e;
373 $field[-1] = "H$hops";
376 # send it out for processing
377 my $origin = $self->{call};
379 my $sub = "handle_$pcno";
381 if ($self->can($sub)) {
382 $self->$sub($pcno, $line, $origin, @field);
384 $self->handle_default($pcno, $line, $origin, @field);
389 # This is called from inside the main cluster processing loop and is used
390 # for despatching commands that are doing some long processing job
395 my @dxchan = DXChannel::get_all();
399 # send out a pc50 on EVERY channel all at once
400 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
401 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
406 foreach $dxchan (@dxchan) {
407 next unless $dxchan->is_node;
408 next if $dxchan->handle_xml;
409 next if $dxchan == $main::me;
412 $dxchan->send($pc50s) if $pc50s;
414 # send a ping out on this channel
415 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
416 if ($dxchan->{nopings} <= 0) {
419 DXXml::Ping::add($main::me, $dxchan->call);
420 $dxchan->{nopings} -= 1;
421 $dxchan->{lastping} = $t;
422 $dxchan->{lastping} += $dxchan->{pingint} / 2 unless @{$dxchan->{pingtime}};
427 Investigate::process();
430 if ($t - $last10 >= 10) {
436 if ($main::systime >= $last_pc92_update + $pc92_update_period) {
438 $last_pc92_update = $main::systime;
444 if ($main::systime - 3600 > $last_hour) {
445 $last_hour = $main::systime;
450 # finish up a pc context
454 # some active measures
462 my @dxchan = DXChannel::get_all();
465 # send it if it isn't the except list and isn't isolated and still has a hop count
466 # taking into account filtering and so on
467 foreach $dxchan (@dxchan) {
468 next if $dxchan == $main::me;
469 next if $dxchan == $self && $self->is_node;
470 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
481 if ($self->{spotsfilter}) {
482 ($filter, $hops) = $self->{spotsfilter}->it(@_);
483 return unless $filter;
485 send_prot_line($self, $filter, $hops, $isolate, $line);
490 my ($self, $filter, $hops, $isolate, $line) = @_;
496 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
498 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
499 return unless $routeit;
502 $self->send($routeit);
504 $self->send($routeit) unless $self->{isolate} || $isolate;
513 my @dxchan = DXChannel::get_all();
515 my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
517 # send it if it isn't the except list and isn't isolated and still has a hop count
518 # taking into account filtering and so on
519 foreach $dxchan (@dxchan) {
520 next if $dxchan == $main::me;
521 next if $dxchan == $self && $self->is_node;
525 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
536 if ($self->{wwvfilter}) {
537 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_]);
538 return unless $filter;
540 send_prot_line($self, $filter, $hops, $isolate, $line)
547 my @dxchan = DXChannel::get_all();
549 my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
551 # send it if it isn't the except list and isn't isolated and still has a hop count
552 # taking into account filtering and so on
553 foreach $dxchan (@dxchan) {
554 next if $dxchan == $main::me;
555 next if $dxchan == $self;
557 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
568 if ($self->{wcyfilter}) {
569 ($filter, $hops) = $self->{wcyfilter}->it(@_);
570 return unless $filter;
572 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
580 my @dxchan = DXChannel::get_all();
584 my $text = unpad($_[2]);
586 if ($_[3] eq '*') { # sysops
588 } elsif ($_[3] gt ' ') { # speciality list handling
589 my ($name) = split /\./, $_[3];
590 $target = "$name"; # put the rest in later (if bothered)
597 $target = "ALL" if !$target;
600 # obtain country codes etc
601 my @a = Prefix::cty_data($_[0]);
602 my @b = Prefix::cty_data($_[4]);
603 if ($self->{inannfilter}) {
604 my ($filter, $hops) =
605 $self->{inannfilter}->it(@_, $self->{call},
607 @b[0..2], $a[3], $b[3]);
609 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
614 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
615 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
619 Log('ann', $target, $_[0], $text);
621 # send it if it isn't the except list and isn't isolated and still has a hop count
622 # taking into account filtering and so on
623 foreach $dxchan (@dxchan) {
624 next if $dxchan == $main::me;
625 next if $dxchan == $self && $self->is_node;
626 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
636 $msgid = 1 if $msgid > 999;
645 my @dxchan = DXChannel::get_all();
648 my $text = unpad($_[2]);
651 # munge the group and recast the line if required
652 if ($target =~ s/\.LST$//) {
656 # obtain country codes etc
657 my @a = Prefix::cty_data($_[0]);
658 my @b = Prefix::cty_data($_[4]);
659 if ($self->{inannfilter}) {
660 my ($filter, $hops) =
661 $self->{inannfilter}->it(@_, $self->{call},
663 @b[0..2], $a[3], $b[3]);
665 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
670 if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
671 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
676 Log('chat', $target, $_[0], $text);
678 # send it if it isn't the except list and isn't isolated and still has a hop count
679 # taking into account filtering and so on
680 foreach $dxchan (@dxchan) {
681 my $is_ak1a = $dxchan->is_ak1a;
683 if ($dxchan->is_node) {
684 next if $dxchan == $main::me;
685 next if $dxchan == $self;
686 next unless $dxchan->is_spider || $is_ak1a;
687 next if $target eq 'LOCAL';
688 if (!$ak1a_line && $is_ak1a) {
689 $ak1a_line = DXProt::pc12($_[0], $text, $_[1], "$target.LST");
693 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1],
694 $text, @_, $self->{call}, @a[0..2], @b[0..2]);
708 if ($self->{annfilter}) {
709 ($filter, $hops) = $self->{annfilter}->it(@_);
710 return unless $filter;
712 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
721 sub send_local_config
725 dbg('DXProt::send_local_config') if isdbg('trace');
728 if ($self->{do_pc92}) {
729 $self->send_pc92_config;
736 if ($self->{isolate}) {
737 @localnodes = ( $main::routeroot );
738 $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
740 # create a list of all the nodes that are not connected to this connection
741 # and are not themselves isolated, this to make sure that isolated nodes
742 # don't appear outside of this node
744 # send locally connected nodes
745 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
746 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
747 $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
750 my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
752 for $node (@rawintcalls) {
753 push @intcalls, $node unless grep $node eq $_, @intcalls;
755 my $ref = Route::Node::get($self->{call});
756 my @rnodes = $ref->nodes;
757 for $node (@intcalls) {
758 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
760 $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
763 # get all the users connected on the above nodes and send them out
764 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
766 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
767 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
769 dbg("sent a null value") if isdbg('chanerr');
780 dbg('DXProt::send_pc92_config') if isdbg('trace');
782 # send 'my' configuration for all users and pc92 capable nodes
783 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all();
784 my @localnodes = map { my $r = Route::get($_->{call}); $r ? $r : () } @dxchan;
785 # push @localnodes, map { my $r = Route::Node::get($_->{call}); $r ? $r : () } DXChannel::get_all_users();
786 $self->send_route_pc92($main::mycall, \&pc92c, (scalar @localnodes)+1, $main::routeroot, @localnodes);
788 # send out the configuration of all the PC92 nodes with current configuration
789 # but with the dates that the last config came in with.
790 @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && $_->{do_pc92} } DXChannel::get_all_nodes();
791 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan;
792 foreach $node (@localnodes) {
793 if ($node && $node->lastid->{92}) {
794 my @rout = map {my $r = Route::get($_); $r ? ($r) : ()} $node->nodes, $node->users;
795 my $line = gen_pc29_with_time($node->call, 'C', $node->lastid->{92}, @rout);
798 dbg("sent a null value") if isdbg('chanerr');
802 # send the configuration of all the 'external' nodes that don't handle PC92
803 # out with the 'external' marker on the first node.
804 @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && !$_->{do_pc92} } DXChannel::get_all_nodes();
805 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan;
806 foreach $node (@localnodes) {
808 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
809 $self->send_route_pc92($main::mycall, \&pc92c, 1, $node, @rout) if @rout;
811 dbg("sent a null value") if isdbg('chanerr');
822 dbg('DXProt::send_pc92_update') if isdbg('trace');
824 # send 'my' configuration for all users and pc92 capable nodes
825 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all();
826 my @localnodes = map { my $r = Route::get($_->{call}); $r ? $r : () } @dxchan;
827 # push @localnodes, map { my $r = Route::Node::get($_->{call}); $r ? $r : () } DXChannel::get_all_users();
828 push @lines, pc92c($main::routeroot, @localnodes);
831 # send the configuration of all the 'external' nodes that don't handle PC92
832 # out with the 'external' marker on the first node.
833 @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && !$_->{do_pc92} } DXChannel::get_all_nodes();
834 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan;
835 foreach $node (@localnodes) {
837 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
838 push @lines, pc92c($node, @rout);
842 # broadcast the lines to all PC92 nodes
844 $main::me->broadcast_route_pc92('', undef, $_, 0);
849 # route a message down an appropriate interface for a callsign
851 # is called route(to, pcline);
856 my ($self, $call, $line) = @_;
858 if (ref $self && $call eq $self->{call}) {
859 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
863 # always send it down the local interface if available
864 my $dxchan = DXChannel::get($call);
866 dbg("route: $call -> $dxchan->{call} direct" ) if isdbg('route');
868 my $cl = Route::get($call);
869 $dxchan = $cl->dxchan if $cl;
871 if (ref $self && $dxchan eq $self) {
872 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
875 dbg("route: $call -> $dxchan->{call} using normal route" ) if isdbg('route');
879 # try the backstop method
881 my $rcall = RouteDB::get($call);
883 if ($self && $rcall eq $self->{call}) {
884 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
887 $dxchan = DXChannel::get($rcall);
888 dbg("route: $call -> $rcall using RouteDB" ) if isdbg('route') && $dxchan;
893 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
895 $dxchan->send($routeit) unless $dxchan == $main::me;
898 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
903 # obtain the hops from the list for this callsign and pc no
909 my $hops = $DXProt::hopcount{$pcno};
910 $hops = $DXProt::def_hopcount if !$hops;
915 # adjust the hop count on a per node basis using the user loadable
916 # hop table if available or else decrement an existing one
923 my $call = $self->{call};
926 if (($hops) = $s =~ /\^H(\d+)\^?~?$/o) {
927 my ($pcno) = $s =~ /^PC(\d\d)/o;
928 confess "$call called adjust_hops with '$s'" unless $pcno;
929 my $ref = $nodehops{$call} if %nodehops;
931 my $newhops = $ref->{$pcno};
932 return "" if defined $newhops && $newhops == 0;
933 $newhops = $ref->{default} unless $newhops;
934 return "" if defined $newhops && $newhops == 0;
935 $newhops = $hops if !$newhops;
936 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
948 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
949 do "$main::data/hop_table.pl";
956 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
957 if ($tonode eq $main::mycall) {
958 my $ref = DXUser->get_current($fromnode);
959 my $cref = Route::Node::get($fromnode);
960 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
961 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
962 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
963 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
964 my $oldpriv = $self->{priv};
965 $self->{priv} = $ref->{priv}; # assume the user's privilege level
966 my @in = (DXCommandmode::run_cmd($self, $cmd));
967 $self->{priv} = $oldpriv;
968 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
969 delete $self->{remotecmd};
971 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
974 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
977 my $ref = DXUser->get_current($tonode);
978 if ($ref && $ref->is_clx) {
979 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
981 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
986 sub process_rcmd_reply
988 my ($self, $tonode, $fromnode, $user, $line) = @_;
989 if ($tonode eq $main::mycall) {
990 my $s = $rcmds{$fromnode};
992 my $dxchan = DXChannel::get($s->{call});
993 my $ref = $user eq $tonode ? $dxchan : (DXChannel::get($user) || $dxchan);
994 $ref->send($line) if $ref;
995 delete $rcmds{$fromnode} if !$dxchan;
997 # send unsolicited ones to the sysop
998 my $dxchan = DXChannel::get($main::myalias);
999 $dxchan->send($line) if $dxchan;
1002 my $ref = DXUser->get_current($tonode);
1003 if ($ref && $ref->is_clx) {
1004 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
1006 $self->route($tonode, pc35($fromnode, $tonode, $line));
1015 my $fromnode = shift;
1020 Log('rcmd', 'out', $fromnode, $line);
1021 if ($self->is_clx) {
1022 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
1024 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
1029 # add a rcmd request to the rcmd queues
1032 my ($self, $to, $cmd) = @_;
1035 $r->{call} = $self->{call};
1036 $r->{t} = $main::systime;
1040 my $ref = Route::Node::get($to);
1041 my $dxchan = $ref->dxchan;
1042 if ($dxchan && $dxchan->is_clx) {
1043 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1045 route(undef, $to, pc34($main::mycall, $to, $cmd));
1052 my $pc39flag = shift;
1053 my $call = $self->call;
1055 return if $self->{disconnecting}++;
1057 unless ($pc39flag && $pc39flag == 1) {
1058 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1061 # get rid of any PC16/17/19
1062 eph_del_regex("^PC1[679]*$call");
1064 # do routing stuff, remove me from routing table
1065 my $node = Route::Node::get($call);
1068 @rout = $node->del($main::routeroot);
1070 # and all my ephemera as well
1073 eph_del_regex("^PC1[679].*$c");
1077 RouteDB::delete_interface($call);
1079 # unbusy and stop and outgoing mail
1080 my $mref = DXMsg::get_busy($call);
1081 $mref->stop_msg($call) if $mref;
1083 # broadcast to all other nodes that all the nodes connected to via me are gone
1084 unless ($pc39flag && $pc39flag == 2) {
1085 $self->route_pc21($main::mycall, undef, @rout) if @rout;
1086 $self->route_pc92d($main::mycall, undef, $main::routeroot, $node) if $node;
1089 # remove outstanding pings
1090 delete $pings{$call};
1092 # I was the last node visited
1093 $self->user->node($main::mycall);
1095 # send info to all logged in thingies
1096 $self->tell_login('logoutn');
1098 Log('DXProt', $call . " Disconnected");
1100 $self->SUPER::disconnect;
1105 # send a talk message to this thingy
1109 my ($self, $from, $to, $via, $line, $origin) = @_;
1111 $line =~ s/\^/\\5E/g; # remove any ^ characters
1112 $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
1113 Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
1116 # send it if it isn't the except list and isn't isolated and still has a hop count
1117 # taking into account filtering and so on
1123 my $generate = shift;
1124 my $no = shift; # the no of things to filter on
1126 my ($filter, $hops);
1129 for (; @_ && $no; $no--) {
1132 if (!$self->{isolate} && $self->{routefilter}) {
1135 ($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});
1139 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
1142 dbg("was sent a null value") if isdbg('chanerr');
1145 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
1149 foreach my $line (&$generate(@rin, @_)) {
1152 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1154 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1155 next unless $routeit;
1158 $self->send($routeit);
1167 my $generate = shift;
1169 my @dxchan = DXChannel::get_all_nodes();
1173 $line =~ /\^H(\d+)\^?\~?$/;
1174 return unless $1 > 0;
1176 unless ($self->{isolate}) {
1177 foreach $dxchan (@dxchan) {
1178 next if $dxchan == $self;
1179 next if $dxchan == $main::me;
1180 next unless $dxchan->isa('DXProt');
1181 next if $dxchan->{do_pc92};
1182 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
1184 $dxchan->send_route($origin, $generate, @_);
1189 # this is only used for next door nodes on init
1194 return unless $self->{do_pc92};
1197 my $generate = shift;
1198 my $no = shift; # the no of things to filter on
1201 $line = &$generate(@_);
1205 sub broadcast_route_pc9x
1209 my $generate = shift;
1212 my @dxchan = DXChannel::get_all_nodes();
1215 if ($origin eq $main::mycall) {
1216 $line = &$generate(@_);
1219 $line =~ /\^H(\d+)\^\~?$/;
1220 unless ($1 > 0 && $self->{isolate}) {
1221 foreach $dxchan (@dxchan) {
1222 next if $dxchan == $self;
1223 next if $dxchan == $main::me;
1224 next unless $dxchan->{do_pc92};
1225 next unless $dxchan->isa('DXProt');
1227 $dxchan->send($line);
1235 return unless $self->user->wantpc16;
1238 broadcast_route($self, $origin, \&pc16, $line, 1, @_);
1244 return unless $self->user->wantpc16;
1247 broadcast_route($self, $origin, \&pc17, $line, 1, @_);
1255 broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
1263 broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
1271 broadcast_route($self, $origin, \&pc24, $line, 1, @_);
1279 broadcast_route($self, $origin, \&pc41, $line, 1, @_);
1287 broadcast_route($self, $origin, \&pc50, $line, 1, @_);
1295 broadcast_route_pc9x($self, $origin, \&pc92c, $line, 1, @_);
1303 broadcast_route_pc9x($self, $origin, \&pc92a, $line, 1, @_);
1311 broadcast_route_pc9x($self, $origin, \&pc92d, $line, 1, @_);
1318 my ($filter, $hops) = (1, 1);
1320 if ($self->{inroutefilter}) {
1321 ($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);
1322 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
1330 my $t = shift || $eph_restime;
1334 $s =~ s/\^H\d\d?\^?\~?$//;
1335 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
1336 $eph{$s} = $main::systime + $t;
1337 dbg("PCPROT: emphemeral duplicate") if $r && isdbg('chanerr');
1345 while (($key, $val) = each %eph) {
1346 if ($key =~ m{$regex}) {
1356 while (($key, $val) = each %eph) {
1357 if ($main::systime >= $val) {
1368 while (($key, $val) = each %eph) {
1369 push @out, $key, $val;
1376 goto &DXCommandmode::run_cmd;
1380 # import any msgs in the chat directory
1381 # the messages are sent to the chat group which forms the
1382 # the first part of the name (eg: solar.1243.txt would be
1383 # sent to chat group SOLAR)
1385 # Each message found is sent: one non-blank line to one chat
1386 # message. So 4 lines = 4 chat messages.
1388 # The special name LOCAL is for local users ANN
1389 # The special name ALL is for ANN/FULL
1390 # The special name SYSOP is for ANN/SYSOP
1394 # are there any to do in this directory?
1395 return unless -d $chatimportfn;
1396 unless (opendir(DIR, $chatimportfn)) {
1397 dbg("can\'t open $chatimportfn $!") if isdbg('msg');
1398 Log('msg', "can\'t open $chatimportfn $!");
1402 my @names = readdir(DIR);
1405 foreach $name (@names) {
1406 next if $name =~ /^\./;
1407 my $splitit = $name =~ /^split/;
1408 my $fn = "$chatimportfn/$name";
1410 unless (open(MSG, $fn)) {
1411 dbg("can\'t open import file $fn $!") if isdbg('msg');
1412 Log('msg', "can\'t open import file $fn $!");
1416 my @msg = map { s/\r?\n$//; $_ } <MSG>;
1420 my @cat = split /\./, $name;
1421 my $target = uc $cat[0];
1423 foreach my $text (@msg) {
1424 next unless $text && $text !~ /^\s*#/;
1425 if ($target eq 'ALL' || $target eq 'LOCAL' || $target eq 'SYSOP') {
1426 my $sysopflag = $target eq 'SYSOP' ? '*' : ' ';
1427 if ($target ne 'LOCAL') {
1428 send_announce($main::me, pc12($main::mycall, $text, '*', $sysopflag), $main::mycall, '*', $text, $sysopflag, $main::mycall, '0');
1430 Log('ann', 'LOCAL', $main::mycall, $text);
1431 DXChannel::broadcast_list("To LOCAL de ${main::mycall}: $text\a", 'ann', undef, DXCommandmode->get_all());
1434 my $msgid = nextchatmsgid();
1435 $text = "#$msgid $text";
1436 send_chat($main::me, pc12($main::mycall, $text, '*', $target), $main::mycall, '*', $text, $target, $main::mycall, '0');