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
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
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;
228 # obtain a new connection this is derived from dxchannel
233 my $self = DXChannel::alloc(@_);
235 # add this node to the table, the values get filled in later
238 $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
243 # this is how a pc connection starts (for an incoming connection)
244 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
245 # all the crap that comes between).
248 my ($self, $line, $sort) = @_;
249 my $call = $self->{call};
250 my $user = $self->{user};
253 my $host = $self->{conn}->{peerhost};
254 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
257 Log('DXProt', "$call connected from $host");
259 # remember type of connection
260 $self->{consort} = $line;
261 $self->{outbound} = $sort eq 'O';
262 my $priv = $user->priv;
263 $priv = $user->priv(1) unless $priv;
264 $self->{priv} = $priv; # other clusters can always be 'normal' users
265 $self->{lang} = $user->lang || 'en';
266 $self->{isolate} = $user->{isolate};
267 $self->{consort} = $line; # save the connection type
271 # sort out registration
272 $self->{registered} = 1;
274 # get the output filters
275 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
276 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
277 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
278 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
279 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
282 # get the INPUT filters (these only pertain to Clusters)
283 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
284 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
285 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
286 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
287 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
289 # set unbuffered and no echo
290 $self->send_now('B',"0");
291 $self->send_now('E',"0");
292 $self->conn->echo(0) if $self->conn->can('echo');
294 # ping neighbour node stuff
295 my $ping = $user->pingint;
296 $ping = $pingint unless defined $ping;
297 $self->{pingint} = $ping;
298 $self->{nopings} = $user->nopings || $obscount;
299 $self->{pingtime} = [ ];
300 $self->{pingave} = 999;
301 $self->{metric} ||= 100;
302 $self->{lastping} = $main::systime;
304 # send initialisation string
305 unless ($self->{outbound}) {
309 $self->state('init');
310 $self->{pc50_t} = $main::systime;
312 # send info to all logged in thingies
313 $self->tell_login('loginn');
315 # run a script send the output to the debug file
316 my $script = new Script(lc $call) || new Script('node_default');
317 $script->run($self) if $script;
321 # send outgoing 'challenge'
331 # This is the normal pcxx despatcher
335 my ($self, $line) = @_;
337 if ($line =~ '^<\w+\s' && $main::do_xml) {
338 DXXml::normal($self, $line);
342 my @field = split /\^/, $line;
343 return unless @field;
345 pop @field if $field[-1] eq '~';
347 # print join(',', @field), "\n";
350 # process PC frames, this will fail unless the frame starts PCnn
351 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
352 unless (defined $pcno && $pcno >= 10 && $pcno <= 99) {
353 dbg("PCPROT: unknown protocol") if isdbg('chanerr');
357 # check for and dump bad protocol messages
358 my $n = check($pcno, @field);
360 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
364 # modify the hop count here
365 if (my ($hops, $trail) = $line =~ /\^H(\d+)(\^?\~?)?$/) {
369 $line =~ s/\^H(\d+)(\^?\~?)?$/sprintf('^H%d%s', $hops, $trail)/e;
370 $field[-1] = "H$hops";
373 # send it out for processing
374 my $origin = $self->{call};
376 my $sub = "handle_$pcno";
378 if ($self->can($sub)) {
379 $self->$sub($pcno, $line, $origin, @field);
381 $self->handle_default($pcno, $line, $origin, @field);
386 # This is called from inside the main cluster processing loop and is used
387 # for despatching commands that are doing some long processing job
392 my @dxchan = DXChannel::get_all();
396 # send out a pc50 on EVERY channel all at once
397 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
398 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
403 foreach $dxchan (@dxchan) {
404 next unless $dxchan->is_node;
405 next if $dxchan->handle_xml;
406 next if $dxchan == $main::me;
409 $dxchan->send($pc50s) if $pc50s;
411 # send a ping out on this channel
412 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
413 if ($dxchan->{nopings} <= 0) {
416 DXXml::Ping::add($main::me, $dxchan->call);
417 $dxchan->{nopings} -= 1;
418 $dxchan->{lastping} = $t;
419 $dxchan->{lastping} += $dxchan->{pingint} / 2 unless @{$dxchan->{pingtime}};
424 Investigate::process();
427 if ($t - $last10 >= 10) {
437 if ($main::systime - 3600 > $last_hour) {
438 $last_hour = $main::systime;
443 # finish up a pc context
447 # some active measures
455 my @dxchan = DXChannel::get_all();
458 # send it if it isn't the except list and isn't isolated and still has a hop count
459 # taking into account filtering and so on
460 foreach $dxchan (@dxchan) {
461 next if $dxchan == $main::me;
462 next if $dxchan == $self && $self->is_node;
463 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
474 if ($self->{spotsfilter}) {
475 ($filter, $hops) = $self->{spotsfilter}->it(@_);
476 return unless $filter;
478 send_prot_line($self, $filter, $hops, $isolate, $line);
483 my ($self, $filter, $hops, $isolate, $line) = @_;
489 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
491 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
492 return unless $routeit;
495 $self->send($routeit);
497 $self->send($routeit) unless $self->{isolate} || $isolate;
506 my @dxchan = DXChannel::get_all();
508 my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
510 # send it if it isn't the except list and isn't isolated and still has a hop count
511 # taking into account filtering and so on
512 foreach $dxchan (@dxchan) {
513 next if $dxchan == $main::me;
514 next if $dxchan == $self && $self->is_node;
518 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
529 if ($self->{wwvfilter}) {
530 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_]);
531 return unless $filter;
533 send_prot_line($self, $filter, $hops, $isolate, $line)
540 my @dxchan = DXChannel::get_all();
542 my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
544 # send it if it isn't the except list and isn't isolated and still has a hop count
545 # taking into account filtering and so on
546 foreach $dxchan (@dxchan) {
547 next if $dxchan == $main::me;
548 next if $dxchan == $self;
550 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
561 if ($self->{wcyfilter}) {
562 ($filter, $hops) = $self->{wcyfilter}->it(@_);
563 return unless $filter;
565 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
573 my @dxchan = DXChannel::get_all();
577 my $text = unpad($_[2]);
579 if ($_[3] eq '*') { # sysops
581 } elsif ($_[3] gt ' ') { # speciality list handling
582 my ($name) = split /\./, $_[3];
583 $target = "$name"; # put the rest in later (if bothered)
590 $target = "ALL" if !$target;
593 # obtain country codes etc
594 my @a = Prefix::cty_data($_[0]);
595 my @b = Prefix::cty_data($_[4]);
596 if ($self->{inannfilter}) {
597 my ($filter, $hops) =
598 $self->{inannfilter}->it(@_, $self->{call},
600 @b[0..2], $a[3], $b[3]);
602 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
607 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
608 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
612 Log('ann', $target, $_[0], $text);
614 # send it if it isn't the except list and isn't isolated and still has a hop count
615 # taking into account filtering and so on
616 foreach $dxchan (@dxchan) {
617 next if $dxchan == $main::me;
618 next if $dxchan == $self && $self->is_node;
619 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
629 $msgid = 1 if $msgid > 999;
638 my @dxchan = DXChannel::get_all();
641 my $text = unpad($_[2]);
644 # munge the group and recast the line if required
645 if ($target =~ s/\.LST$//) {
649 # obtain country codes etc
650 my @a = Prefix::cty_data($_[0]);
651 my @b = Prefix::cty_data($_[4]);
652 if ($self->{inannfilter}) {
653 my ($filter, $hops) =
654 $self->{inannfilter}->it(@_, $self->{call},
656 @b[0..2], $a[3], $b[3]);
658 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
663 if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
664 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
669 Log('chat', $target, $_[0], $text);
671 # send it if it isn't the except list and isn't isolated and still has a hop count
672 # taking into account filtering and so on
673 foreach $dxchan (@dxchan) {
674 my $is_ak1a = $dxchan->is_ak1a;
676 if ($dxchan->is_node) {
677 next if $dxchan == $main::me;
678 next if $dxchan == $self;
679 next unless $dxchan->is_spider || $is_ak1a;
680 next if $target eq 'LOCAL';
681 if (!$ak1a_line && $is_ak1a) {
682 $ak1a_line = DXProt::pc12($_[0], $text, $_[1], "$target.LST");
686 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1],
687 $text, @_, $self->{call}, @a[0..2], @b[0..2]);
701 if ($self->{annfilter}) {
702 ($filter, $hops) = $self->{annfilter}->it(@_);
703 return unless $filter;
705 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
714 sub send_local_config
718 dbg('DXProt::send_local_config') if isdbg('trace');
721 if ($self->{do_pc92}) {
722 $self->send_pc92_config;
729 if ($self->{isolate}) {
730 @localnodes = ( $main::routeroot );
731 $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
733 # create a list of all the nodes that are not connected to this connection
734 # and are not themselves isolated, this to make sure that isolated nodes
735 # don't appear outside of this node
737 # send locally connected nodes
738 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
739 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
740 $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
743 my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
745 for $node (@rawintcalls) {
746 push @intcalls, $node unless grep $node eq $_, @intcalls;
748 my $ref = Route::Node::get($self->{call});
749 my @rnodes = $ref->nodes;
750 for $node (@intcalls) {
751 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
753 $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
756 # get all the users connected on the above nodes and send them out
757 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
759 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
760 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
762 dbg("sent a null value") if isdbg('chanerr');
773 dbg('DXProt::send_pc92_config') if isdbg('trace');
775 # send 'my' configuration for all users and pc92 capable nodes
776 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all();
777 my @localnodes = map { my $r = Route::get($_->{call}); $r ? $r : () } @dxchan;
778 # push @localnodes, map { my $r = Route::Node::get($_->{call}); $r ? $r : () } DXChannel::get_all_users();
779 $self->send_route_pc92($main::mycall, \&pc92c, (scalar @localnodes)+1, $main::routeroot, @localnodes);
781 # send out the configuration of all the PC92 nodes with current configuration
782 # but with the dates that the last config came in with.
783 @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && $_->{do_pc92} } DXChannel::get_all_nodes();
784 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan;
785 foreach $node (@localnodes) {
786 if ($node && $node->lastid->{92}) {
787 my @rout = map {my $r = Route::get($_); $r ? ($r) : ()} $node->nodes, $node->users;
788 my $line = gen_pc29_with_time($node->call, 'C', $node->lastid->{92}, @rout);
791 dbg("sent a null value") if isdbg('chanerr');
795 # send the configuration of all the 'external' nodes that don't handle PC92
796 # out with the 'external' marker on the first node.
797 @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && !$_->{do_pc92} } DXChannel::get_all_nodes();
798 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan;
799 foreach $node (@localnodes) {
801 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
802 $self->send_route_pc92($main::mycall, \&pc92c, 1, $node, @rout) if @rout;
804 dbg("sent a null value") if isdbg('chanerr');
810 # route a message down an appropriate interface for a callsign
812 # is called route(to, pcline);
817 my ($self, $call, $line) = @_;
819 if (ref $self && $call eq $self->{call}) {
820 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
824 # always send it down the local interface if available
825 my $dxchan = DXChannel::get($call);
827 dbg("route: $call -> $dxchan->{call} direct" ) if isdbg('route');
829 my $cl = Route::get($call);
830 $dxchan = $cl->dxchan if $cl;
832 if (ref $self && $dxchan eq $self) {
833 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
836 dbg("route: $call -> $dxchan->{call} using normal route" ) if isdbg('route');
840 # try the backstop method
842 my $rcall = RouteDB::get($call);
844 if ($self && $rcall eq $self->{call}) {
845 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
848 $dxchan = DXChannel::get($rcall);
849 dbg("route: $call -> $rcall using RouteDB" ) if isdbg('route') && $dxchan;
854 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
856 $dxchan->send($routeit) unless $dxchan == $main::me;
859 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
864 # obtain the hops from the list for this callsign and pc no
870 my $hops = $DXProt::hopcount{$pcno};
871 $hops = $DXProt::def_hopcount if !$hops;
876 # adjust the hop count on a per node basis using the user loadable
877 # hop table if available or else decrement an existing one
884 my $call = $self->{call};
887 if (($hops) = $s =~ /\^H(\d+)\^?~?$/o) {
888 my ($pcno) = $s =~ /^PC(\d\d)/o;
889 confess "$call called adjust_hops with '$s'" unless $pcno;
890 my $ref = $nodehops{$call} if %nodehops;
892 my $newhops = $ref->{$pcno};
893 return "" if defined $newhops && $newhops == 0;
894 $newhops = $ref->{default} unless $newhops;
895 return "" if defined $newhops && $newhops == 0;
896 $newhops = $hops if !$newhops;
897 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
909 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
910 do "$main::data/hop_table.pl";
917 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
918 if ($tonode eq $main::mycall) {
919 my $ref = DXUser->get_current($fromnode);
920 my $cref = Route::Node::get($fromnode);
921 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
922 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
923 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
924 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
925 my $oldpriv = $self->{priv};
926 $self->{priv} = $ref->{priv}; # assume the user's privilege level
927 my @in = (DXCommandmode::run_cmd($self, $cmd));
928 $self->{priv} = $oldpriv;
929 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
930 delete $self->{remotecmd};
932 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
935 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
938 my $ref = DXUser->get_current($tonode);
939 if ($ref && $ref->is_clx) {
940 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
942 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
947 sub process_rcmd_reply
949 my ($self, $tonode, $fromnode, $user, $line) = @_;
950 if ($tonode eq $main::mycall) {
951 my $s = $rcmds{$fromnode};
953 my $dxchan = DXChannel::get($s->{call});
954 my $ref = $user eq $tonode ? $dxchan : (DXChannel::get($user) || $dxchan);
955 $ref->send($line) if $ref;
956 delete $rcmds{$fromnode} if !$dxchan;
958 # send unsolicited ones to the sysop
959 my $dxchan = DXChannel::get($main::myalias);
960 $dxchan->send($line) if $dxchan;
963 my $ref = DXUser->get_current($tonode);
964 if ($ref && $ref->is_clx) {
965 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
967 $self->route($tonode, pc35($fromnode, $tonode, $line));
976 my $fromnode = shift;
981 Log('rcmd', 'out', $fromnode, $line);
983 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
985 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
990 # add a rcmd request to the rcmd queues
993 my ($self, $to, $cmd) = @_;
996 $r->{call} = $self->{call};
997 $r->{t} = $main::systime;
1001 my $ref = Route::Node::get($to);
1002 my $dxchan = $ref->dxchan;
1003 if ($dxchan && $dxchan->is_clx) {
1004 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1006 route(undef, $to, pc34($main::mycall, $to, $cmd));
1013 my $pc39flag = shift;
1014 my $call = $self->call;
1016 return if $self->{disconnecting}++;
1018 unless ($pc39flag && $pc39flag == 1) {
1019 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1022 # get rid of any PC16/17/19
1023 eph_del_regex("^PC1[679]*$call");
1025 # do routing stuff, remove me from routing table
1026 my $node = Route::Node::get($call);
1029 @rout = $node->del($main::routeroot);
1031 # and all my ephemera as well
1034 eph_del_regex("^PC1[679].*$c");
1038 RouteDB::delete_interface($call);
1040 # unbusy and stop and outgoing mail
1041 my $mref = DXMsg::get_busy($call);
1042 $mref->stop_msg($call) if $mref;
1044 # broadcast to all other nodes that all the nodes connected to via me are gone
1045 unless ($pc39flag && $pc39flag == 2) {
1046 $self->route_pc21($main::mycall, undef, @rout) if @rout;
1047 $self->route_pc92d($main::mycall, undef, $main::routeroot, $node) if $node;
1050 # remove outstanding pings
1051 delete $pings{$call};
1053 # I was the last node visited
1054 $self->user->node($main::mycall);
1056 # send info to all logged in thingies
1057 $self->tell_login('logoutn');
1059 Log('DXProt', $call . " Disconnected");
1061 $self->SUPER::disconnect;
1066 # send a talk message to this thingy
1070 my ($self, $from, $to, $via, $line, $origin) = @_;
1072 $line =~ s/\^/\\5E/g; # remove any ^ characters
1073 $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
1074 Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
1077 # send it if it isn't the except list and isn't isolated and still has a hop count
1078 # taking into account filtering and so on
1084 my $generate = shift;
1085 my $no = shift; # the no of things to filter on
1087 my ($filter, $hops);
1090 for (; @_ && $no; $no--) {
1093 if (!$self->{isolate} && $self->{routefilter}) {
1096 ($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});
1100 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
1103 dbg("was sent a null value") if isdbg('chanerr');
1106 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
1110 foreach my $line (&$generate(@rin, @_)) {
1113 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1115 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1116 next unless $routeit;
1119 $self->send($routeit);
1128 my $generate = shift;
1130 my @dxchan = DXChannel::get_all_nodes();
1134 $line =~ /\^H(\d+)\^?\~?$/;
1135 return unless $1 > 0;
1137 unless ($self->{isolate}) {
1138 foreach $dxchan (@dxchan) {
1139 next if $dxchan == $self;
1140 next if $dxchan == $main::me;
1141 next unless $dxchan->isa('DXProt');
1142 next if $dxchan->{do_pc92};
1143 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
1145 $dxchan->send_route($origin, $generate, @_);
1150 # this is only used for next door nodes on init
1155 return unless $self->{do_pc92};
1158 my $generate = shift;
1159 my $no = shift; # the no of things to filter on
1162 $line = &$generate(@_);
1166 sub broadcast_route_pc9x
1170 my $generate = shift;
1173 my @dxchan = DXChannel::get_all_nodes();
1176 if ($origin eq $main::mycall) {
1177 $line = &$generate(@_);
1180 $line =~ /\^H(\d+)\^\~?$/;
1181 unless ($1 > 0 && $self->{isolate}) {
1182 foreach $dxchan (@dxchan) {
1183 next if $dxchan == $self;
1184 next if $dxchan == $main::me;
1185 next unless $dxchan->{do_pc92};
1186 next unless $dxchan->isa('DXProt');
1188 $dxchan->send($line);
1196 return unless $self->user->wantpc16;
1199 broadcast_route($self, $origin, \&pc16, $line, 1, @_);
1205 return unless $self->user->wantpc16;
1208 broadcast_route($self, $origin, \&pc17, $line, 1, @_);
1216 broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
1224 broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
1232 broadcast_route($self, $origin, \&pc24, $line, 1, @_);
1240 broadcast_route($self, $origin, \&pc41, $line, 1, @_);
1248 broadcast_route($self, $origin, \&pc50, $line, 1, @_);
1256 broadcast_route_pc9x($self, $origin, \&pc92c, $line, 1, @_);
1264 broadcast_route_pc9x($self, $origin, \&pc92a, $line, 1, @_);
1272 broadcast_route_pc9x($self, $origin, \&pc92d, $line, 1, @_);
1279 my ($filter, $hops) = (1, 1);
1281 if ($self->{inroutefilter}) {
1282 ($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);
1283 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
1291 my $t = shift || $eph_restime;
1295 $s =~ s/\^H\d\d?\^?\~?$//;
1296 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
1297 $eph{$s} = $main::systime + $t;
1298 dbg("PCPROT: emphemeral duplicate") if $r && isdbg('chanerr');
1306 while (($key, $val) = each %eph) {
1307 if ($key =~ m{$regex}) {
1317 while (($key, $val) = each %eph) {
1318 if ($main::systime >= $val) {
1329 while (($key, $val) = each %eph) {
1330 push @out, $key, $val;
1337 goto &DXCommandmode::run_cmd;
1341 # import any msgs in the chat directory
1342 # the messages are sent to the chat group which forms the
1343 # the first part of the name (eg: solar.1243.txt would be
1344 # sent to chat group SOLAR)
1346 # Each message found is sent: one non-blank line to one chat
1347 # message. So 4 lines = 4 chat messages.
1349 # The special name LOCAL is for local users ANN
1350 # The special name ALL is for ANN/FULL
1351 # The special name SYSOP is for ANN/SYSOP
1355 # are there any to do in this directory?
1356 return unless -d $chatimportfn;
1357 unless (opendir(DIR, $chatimportfn)) {
1358 dbg("can\'t open $chatimportfn $!") if isdbg('msg');
1359 Log('msg', "can\'t open $chatimportfn $!");
1363 my @names = readdir(DIR);
1366 foreach $name (@names) {
1367 next if $name =~ /^\./;
1368 my $splitit = $name =~ /^split/;
1369 my $fn = "$chatimportfn/$name";
1371 unless (open(MSG, $fn)) {
1372 dbg("can\'t open import file $fn $!") if isdbg('msg');
1373 Log('msg', "can\'t open import file $fn $!");
1377 my @msg = map { s/\r?\n$//; $_ } <MSG>;
1381 my @cat = split /\./, $name;
1382 my $target = uc $cat[0];
1384 foreach my $text (@msg) {
1385 next unless $text && $text !~ /^\s*#/;
1386 if ($target eq 'ALL' || $target eq 'LOCAL' || $target eq 'SYSOP') {
1387 my $sysopflag = $target eq 'SYSOP' ? '*' : ' ';
1388 if ($target ne 'LOCAL') {
1389 send_announce($main::me, pc12($main::mycall, $text, '*', $sysopflag), $main::mycall, '*', $text, $sysopflag, $main::mycall, '0');
1391 Log('ann', 'LOCAL', $main::mycall, $text);
1392 DXChannel::broadcast_list("To LOCAL de ${main::mycall}: $text\a", 'ann', undef, DXCommandmode->get_all());
1395 my $msgid = nextchatmsgid();
1396 $text = "#$msgid $text";
1397 send_chat($main::me, pc12($main::mycall, $text, '*', $target), $main::mycall, '*', $text, $target, $main::mycall, '0');