3 # This module impliments the protocal mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
30 use Time::HiRes qw(gettimeofday tv_interval);
41 use vars qw($VERSION $BRANCH);
42 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /:\s+(\d+)\.(\d+)/ );
43 $BRANCH = sprintf( "%d.%03d", (q$Revision$ =~ /:\s+\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 $pc19_version
49 $pingint $obscount %pc19list $chatdupeage $investigation_int
50 %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
51 $allowzero $decode_dk0wcy $send_opernam @checklist);
53 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
54 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
56 $last_hour = time; # last time I did an hourly periodic update
57 %pings = (); # outstanding ping requests outbound
58 %rcmds = (); # outstanding rcmd requests outbound
59 %nodehops = (); # node specific hop control
60 %pc19list = (); # list of outstanding PC19s that haven't had PC16s on them
62 $censorpc = 1; # Do a BadWords::check on text fields and reject things
63 # loads of 'bad things'
64 $baddx = new DXHash "baddx";
65 $badspotter = new DXHash "badspotter";
66 $badnode = new DXHash "badnode";
67 $last10 = $last_pc50 = time;
71 $eph_info_restime = 60*60;
72 $eph_pc34_restime = 30;
75 $chatdupeage = 20 * 60 * 60;
76 $investigation_int = 7*86400; # time between checks to see if we can see this node
77 $pc19_version = 5466; # the visible version no for outgoing PC19s generated from pc59
82 [ qw(i c c m bp bc c) ], # pc10
83 [ qw(i f m d t m c c h) ], # pc11
84 [ qw(i c bm m bm bm p h) ], # pc12
88 undef , # pc16 has to be validated manually
89 [ qw(i c c h) ], # pc17
91 undef , # pc19 has to be validated manually
92 undef , # pc20 no validation
93 [ qw(i c m h) ], # pc21
94 undef , # pc22 no validation
95 [ qw(i d n n n n m c c h) ], # pc23
96 [ qw(i c p h) ], # pc24
97 [ qw(i c c n n) ], # pc25
98 [ qw(i f m d t m c c bc) ], # pc26
99 [ qw(i d n n n n m c c bc) ], # pc27
100 [ qw(i c c m c d t p m bp n p bp bc) ], # pc28
101 [ qw(i c c n m) ], # pc29
102 [ qw(i c c n) ], # pc30
103 [ qw(i c c n) ], # pc31
104 [ qw(i c c n) ], # pc32
105 [ qw(i c c n) ], # pc33
106 [ qw(i c c m) ], # pc34
107 [ qw(i c c m) ], # pc35
108 [ qw(i c c m) ], # pc36
109 [ qw(i c c n m) ], # pc37
110 undef, # pc38 not interested
111 [ qw(i c m) ], # pc39
112 [ qw(i c c m p n) ], # pc40
113 [ qw(i c n m h) ], # pc41
114 [ qw(i c c n) ], # pc42
115 undef, # pc43 don't handle it
116 [ qw(i c c n m m c) ], # pc44
117 [ qw(i c c n m) ], # pc45
118 [ qw(i c c n) ], # pc46
121 [ qw(i c m h) ], # pc49
122 [ qw(i c n h) ], # pc50
123 [ qw(i c c n) ], # pc51
145 [ qw(i d n n n n n n m m m c c h) ], # pc73
156 [ qw(i c c c m) ], # pc84
157 [ qw(i c c c m) ], # pc85
162 [ qw(i c n) ], # pc90
165 # use the entry in the check list to check the field list presented
166 # return OK if line NOT in check list (for now)
171 return 0 if $n < 0 || $n > @checklist;
172 my $ref = $checklist[$n];
173 return 0 unless ref $ref;
176 for ($i = 1; $i < @$ref; $i++) {
177 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
178 return 0 unless $act;
179 next if $blank && $_[$i] =~ /^[ \*]$/;
181 return $i unless is_callsign($_[$i]);
182 } elsif ($act eq 'i') {
184 } elsif ($act eq 'm') {
185 return $i unless is_pctext($_[$i]);
186 } elsif ($act eq 'p') {
187 return $i unless is_pcflag($_[$i]);
188 } elsif ($act eq 'f') {
189 return $i unless is_freq($_[$i]);
190 } elsif ($act eq 'n') {
191 return $i unless $_[$i] =~ /^[\d ]+$/;
192 } elsif ($act eq 'h') {
193 return $i unless $_[$i] =~ /^H\d\d?$/;
194 } elsif ($act eq 'd') {
195 return $i unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
196 } elsif ($act eq 't') {
197 return $i unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
205 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
208 my $user = DXUser->get($main::mycall);
209 $DXProt::myprot_version += $main::version*100;
210 $main::me = DXProt->SUPER::alloc($main::mycall, 0, $user);
211 $main::me->{here} = 1;
212 $main::me->{state} = "indifferent";
213 $main::me->{sort} = 'S'; # S for spider
214 $main::me->{priv} = 9;
215 $main::me->{metric} = 0;
216 $main::me->{pingave} = 0;
217 $main::me->{registered} = 1;
218 $main::me->{version} = $main::version;
219 $main::me->{build} = $main::build;
223 # obtain a new connection this is derived from dxchannel
228 my $self = DXChannel::alloc(@_);
230 # add this node to the table, the values get filled in later
234 my $uref = Route::Node::get($call) || Route::Node->new($call);
237 $uref->version($pc19_version);
238 $main::routeroot->link_node($uref, $self);
242 # this is how a pc connection starts (for an incoming connection)
243 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
244 # all the crap that comes between).
247 my ($self, $line, $sort) = @_;
248 my $call = $self->{call};
249 my $user = $self->{user};
252 my $host = $self->{conn}->{peerhost} || "unknown";
253 Log('DXProt', "$call connected from $host");
255 # remember type of connection
256 $self->{consort} = $line;
257 $self->{outbound} = $sort eq 'O';
258 my $priv = $user->priv;
259 $priv = $user->priv(1) unless $priv;
260 $self->{priv} = $priv; # other clusters can always be 'normal' users
261 $self->{lang} = $user->lang || 'en';
262 $self->{isolate} = $user->{isolate};
263 $self->{consort} = $line; # save the connection type
267 # sort out registration
268 $self->{registered} = 1;
270 # get the output filters
271 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
272 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
273 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
274 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
275 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
278 # get the INPUT filters (these only pertain to Clusters)
279 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
280 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
281 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
282 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
283 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
285 # set unbuffered and no echo
286 $self->send_now('B',"0");
287 $self->send_now('E',"0");
288 $self->conn->echo(0) if $self->conn->can('echo');
290 # ping neighbour node stuff
291 my $ping = $user->pingint;
292 $ping = $pingint unless defined $ping;
293 $self->{pingint} = $ping;
294 $self->{nopings} = $user->nopings || $obscount;
295 $self->{pingtime} = [ ];
296 $self->{pingave} = 999;
297 $self->{metric} ||= 100;
298 $self->{lastping} = $main::systime;
300 # send initialisation string
301 unless ($self->{outbound}) {
305 $self->state('init');
306 $self->{pc50_t} = $main::systime;
308 # send info to all logged in thingies
309 $self->tell_login('loginn');
311 # run a script send the output to the debug file
312 my $script = new Script(lc $call) || new Script('node_default');
313 $script->run($self) if $script;
317 # send outgoing 'challenge'
328 $_[0] =~ s/^PC90\^[-A-Z0-9]+\^\d+\^//;
329 $_[0] =~ s/^PC91\^[-A-Z0-9]+\^\d+\^[-A-Z0-9]+\^//;
337 # $self->SUPER::send($line);
342 # This is the normal pcxx despatcher
346 my ($self, $line) = @_;
348 # remove any incoming PC90 frames
351 my @field = split /\^/, $line;
352 return unless @field;
354 pop @field if $field[-1] eq '~';
356 # print join(',', @field), "\n";
359 # process PC frames, this will fail unless the frame starts PCnn
360 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
361 unless (defined $pcno && $pcno >= 10 && $pcno <= 99) {
362 dbg("PCPROT: unknown protocol") if isdbg('chanerr');
366 # check for and dump bad protocol messages
367 my $n = check($pcno, @field);
369 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
373 my $origin = $self->{call};
375 my $sub = "handle_$pcno";
377 if ($self->can($sub)) {
378 $self->$sub($pcno, $line, $origin, @field);
380 $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
389 # It is called once per second
394 my @dxchan = DXChannel->get_all();
398 # send out a pc50 on EVERY channel all at once
399 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
400 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
405 foreach $dxchan (@dxchan) {
406 next unless $dxchan->is_node();
407 next if $dxchan == $main::me;
410 $dxchan->send($pc50s) if $pc50s;
412 # send a ping out on this channel
413 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
414 if ($dxchan->{nopings} <= 0) {
417 addping($main::mycall, $dxchan->call);
418 $dxchan->{nopings} -= 1;
419 $dxchan->{lastping} = $t;
424 Investigate::process();
427 if ($t - $last10 >= 10) {
435 if ($main::systime - 3600 > $last_hour) {
436 $last_hour = $main::systime;
441 # This the routine that does all routing table updates
442 # It determines which nodes have been created or
445 # legacy protocol calls this routine after transforming
446 # the arguments to be compatible, viz: some scalar
447 # parameters and a bunch of routing objects.
449 # A list of 4 references to (any) adds/deletes that
450 # have occured is returned to allow generation of
459 my $hexstamp = shift || hexstamp();
464 my $ncall = $node->call;
465 my $origin = $enode->call;
467 # if it is a delete, disconnect all the entries mentioned
468 # from this node (which is a parent in this context).
473 next if $ref->call eq $ncall;
474 next if $ref->call eq $main::mycall;
475 if ($ref->isa('Route::Node')) {
476 push @delnode, $enode->unlink_node($ref, $self);
477 } elsif ($ref->isa('Route::User')) {
478 push @deluser, $enode->del_user($ref);
483 # if it is an add, connect all the entries
488 next if $ref->call eq $ncall;
489 next if $ref->call eq $main::mycall;
490 if ($ref->isa('Route::Node')) {
491 my $new = $enode->link_node($ref, $self);
492 push @addnode, $new if $new;
493 } elsif ($ref->isa('Route::User')) {
494 push @adduser, $enode->add_user($ref);
499 # if it is a configure, unlink all the nodes and users that
500 # are not in @_ but are in the node, then add all the
501 # nodes and users that are @_ but not in the node.
508 for my $r (map {Route::Node::get($_)} $node->nodes) {
510 next if $r->call eq $ncall;
511 next if $r->call eq $main::mycall;
512 push @dn, $r unless grep $_->call eq $r->call, @_;
514 for my $r (map {Route::User::get($_)} $node->users) {
516 push @du, $r unless grep $_->call eq $r->call, @_;
520 next if $r->call eq $ncall;
521 next if $r->call eq $main::mycall;
522 if ($r->isa('Route::Node')) {
523 push @an, $r unless grep $r->call eq $_, $node->nodes;
524 } elsif ($r->isa('Route::User')) {
525 push @au, $r unless grep $r->call eq $_, $node->users;
528 push @addnode, $node if $self->{state} =~ /^init/;
529 push @delnode, $enode->remove_route($_, $self) for @dn;
530 push @deluser, $enode->del_user($_) for @du;
531 push @addnode, $enode->add_route($_, $self) for @an;
532 push @adduser, $enode->add_user($_) for @au;
535 $self->route_pc21($origin, $line, @delnode) if @delnode;
536 $self->route_pc19($origin, $line, @addnode) if @addnode;
537 $self->route_pc17($origin, $line, $enode, @deluser) if @deluser;
538 $self->route_pc16($origin, $line, $enode, @adduser) if @adduser;
540 unshift @_, $enode if $ncall ne $origin;
541 $self->route_pc59($origin, $line, $sort, $hexstamp, $origin, @_) if @_;
543 $_->delete for @deluser;
544 $_->delete for @delnode;
548 # some active measures
556 my @dxchan = DXChannel->get_all();
559 # send it if it isn't the except list and isn't isolated and still has a hop count
560 # taking into account filtering and so on
561 foreach $dxchan (@dxchan) {
562 next if $dxchan == $main::me;
563 next if $dxchan == $self && $self->is_node;
564 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
575 if ($self->{spotsfilter}) {
576 ($filter, $hops) = $self->{spotsfilter}->it(@_);
577 return unless $filter;
579 send_prot_line($self, $filter, $hops, $isolate, $line);
584 my ($self, $filter, $hops, $isolate, $line) = @_;
590 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
592 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
593 return unless $routeit;
596 $self->send($routeit);
598 $self->send($routeit) unless $self->{isolate} || $isolate;
607 my @dxchan = DXChannel->get_all();
609 my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
611 # send it if it isn't the except list and isn't isolated and still has a hop count
612 # taking into account filtering and so on
613 foreach $dxchan (@dxchan) {
614 next if $dxchan == $main::me;
615 next if $dxchan == $self && $self->is_node;
619 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
630 if ($self->{wwvfilter}) {
631 ($filter, $hops) = $self->{wwvfilter}->it(@_);
632 return unless $filter;
634 send_prot_line($self, $filter, $hops, $isolate, $line)
641 my @dxchan = DXChannel->get_all();
643 my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
645 # send it if it isn't the except list and isn't isolated and still has a hop count
646 # taking into account filtering and so on
647 foreach $dxchan (@dxchan) {
648 next if $dxchan == $main::me;
649 next if $dxchan == $self;
651 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
662 if ($self->{wcyfilter}) {
663 ($filter, $hops) = $self->{wcyfilter}->it(@_);
664 return unless $filter;
666 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
674 my @dxchan = DXChannel->get_all();
678 my $text = unpad($_[2]);
680 if ($_[3] eq '*') { # sysops
682 } elsif ($_[3] gt ' ') { # speciality list handling
683 my ($name) = split /\./, $_[3];
684 $target = "$name"; # put the rest in later (if bothered)
691 $target = "ALL" if !$target;
694 # obtain country codes etc
695 my @a = Prefix::cty_data($_[0]);
696 my @b = Prefix::cty_data($_[4]);
697 if ($self->{inannfilter}) {
698 my ($filter, $hops) =
699 $self->{inannfilter}->it(@_, $self->{call},
701 @b[0..2], $a[3], $b[3]);
703 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
708 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
709 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
713 Log('ann', $target, $_[0], $text);
715 # send it if it isn't the except list and isn't isolated and still has a hop count
716 # taking into account filtering and so on
717 foreach $dxchan (@dxchan) {
718 next if $dxchan == $main::me;
719 next if $dxchan == $self && $self->is_node;
720 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
730 $msgid = 1 if $msgid > 999;
739 my @dxchan = DXChannel->get_all();
742 my $text = unpad($_[2]);
745 # munge the group and recast the line if required
746 if ($target =~ s/\.LST$//) {
750 # obtain country codes etc
751 my @a = Prefix::cty_data($_[0]);
752 my @b = Prefix::cty_data($_[4]);
753 if ($self->{inannfilter}) {
754 my ($filter, $hops) =
755 $self->{inannfilter}->it(@_, $self->{call},
757 @b[0..2], $a[3], $b[3]);
759 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
764 if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
765 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
770 Log('chat', $target, $_[0], $text);
772 # send it if it isn't the except list and isn't isolated and still has a hop count
773 # taking into account filtering and so on
774 foreach $dxchan (@dxchan) {
775 my $is_ak1a = $dxchan->is_ak1a;
777 if ($dxchan->is_node) {
778 next if $dxchan == $main::me;
779 next if $dxchan == $self;
780 next unless $dxchan->is_spider || $is_ak1a;
781 next if $target eq 'LOCAL';
782 if (!$ak1a_line && $is_ak1a) {
783 $ak1a_line = DXProt::pc12($_[0], $text, $_[1], "$target.LST");
787 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1],
788 $text, @_, $self->{call}, @a[0..2], @b[0..2]);
802 if ($self->{annfilter}) {
803 ($filter, $hops) = $self->{annfilter}->it(@_);
804 return unless $filter;
806 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
815 sub send_local_config
823 dbg('DXProt::send_local_config') if isdbg('trace');
825 if ($self->{newroute}) {
826 my @nodes = $self->{isolate} ? ($main::routeroot) : grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
827 my @users = DXChannel::get_all_users();
828 @localnodes = map { Route::Node::get($_->{call}) } @nodes;
829 my @localusers = map { Route::User::get($_->{call}) } @users;
830 $self->send_route($main::mycall, \&pc59, @nodes+@users+4, 'C', 0, $main::mycall, $main::routeroot, @localnodes, @localusers);
833 if ($self->{isolate}) {
834 @localnodes = ( $main::routeroot );
835 $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
837 # create a list of all the nodes that are not connected to this connection
838 # and are not themselves isolated, this to make sure that isolated nodes
839 # don't appear outside of this node
841 # send locally connected nodes
842 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
843 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
844 $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
847 my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
849 for $node (@rawintcalls) {
850 push @intcalls, $node unless grep $node eq $_, @intcalls;
852 my $ref = Route::Node::get($self->{call});
853 my @rnodes = $ref->nodes;
854 for $node (@intcalls) {
855 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
857 $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
860 # get all the users connected on the above nodes and send them out
861 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
863 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
864 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
866 dbg("sent a null value") if isdbg('chanerr');
873 # route a message down an appropriate interface for a callsign
875 # is called route(to, pcline);
879 my ($self, $call, $line) = @_;
881 if (ref $self && $call eq $self->{call}) {
882 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
886 # always send it down the local interface if available
887 my $dxchan = DXChannel->get($call);
889 my $cl = Route::get($call);
890 $dxchan = $cl->bestdxchan if $cl;
892 if (ref $self && $dxchan eq $self) {
893 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
899 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
901 $dxchan->send($routeit) unless $dxchan == $main::me;
904 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
909 # obtain the hops from the list for this callsign and pc no
915 my $hops = $DXProt::hopcount{$pcno};
916 $hops = $DXProt::def_hopcount if !$hops;
921 # adjust the hop count on a per node basis using the user loadable
922 # hop table if available or else decrement an existing one
929 my $call = $self->{call};
932 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
933 my ($pcno) = $s =~ /^PC(\d\d)/o;
934 confess "$call called adjust_hops with '$s'" unless $pcno;
935 my $ref = $nodehops{$call} if %nodehops;
937 my $newhops = $ref->{$pcno};
938 return "" if defined $newhops && $newhops == 0;
939 $newhops = $ref->{default} unless $newhops;
940 return "" if defined $newhops && $newhops == 0;
941 $newhops = $hops if !$newhops;
942 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
944 # simply decrement it
947 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
959 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
960 do "$main::data/hop_table.pl";
966 # add a ping request to the ping queues
969 my ($from, $to, $via) = @_;
970 my $ref = $pings{$to} || [];
973 $r->{t} = [ gettimeofday ];
974 if ($via && (my $dxchan = DXChannel->get($via))) {
975 $dxchan->send(pc51($to, $main::mycall, 1));
977 route(undef, $to, pc51($to, $main::mycall, 1));
981 my $u = DXUser->get_current($to);
983 $u->lastping($main::systime);
990 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
991 if ($tonode eq $main::mycall) {
992 my $ref = DXUser->get_current($fromnode);
993 my $cref = Route::Node::get($fromnode);
994 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
995 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
996 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
997 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
998 my $oldpriv = $self->{priv};
999 $self->{priv} = $ref->{priv}; # assume the user's privilege level
1000 my @in = (DXCommandmode::run_cmd($self, $cmd));
1001 $self->{priv} = $oldpriv;
1002 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
1003 delete $self->{remotecmd};
1005 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
1008 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
1011 my $ref = DXUser->get_current($tonode);
1012 if ($ref && $ref->is_clx) {
1013 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
1015 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
1020 sub process_rcmd_reply
1022 my ($self, $tonode, $fromnode, $user, $line) = @_;
1023 if ($tonode eq $main::mycall) {
1024 my $s = $rcmds{$fromnode};
1026 my $dxchan = DXChannel->get($s->{call});
1027 my $ref = $user eq $tonode ? $dxchan : (DXChannel->get($user) || $dxchan);
1028 $ref->send($line) if $ref;
1029 delete $rcmds{$fromnode} if !$dxchan;
1031 # send unsolicited ones to the sysop
1032 my $dxchan = DXChannel->get($main::myalias);
1033 $dxchan->send($line) if $dxchan;
1036 my $ref = DXUser->get_current($tonode);
1037 if ($ref && $ref->is_clx) {
1038 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
1040 $self->route($tonode, pc35($fromnode, $tonode, $line));
1049 my $fromnode = shift;
1054 Log('rcmd', 'out', $fromnode, $line);
1055 if ($self->is_clx) {
1056 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
1058 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
1063 # add a rcmd request to the rcmd queues
1066 my ($self, $to, $cmd) = @_;
1069 $r->{call} = $self->{call};
1070 $r->{t} = $main::systime;
1074 my $ref = Route::Node::get($to);
1075 my $dxchan = $ref->bestdxchan;
1076 if ($dxchan && $dxchan->is_clx) {
1077 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1079 route(undef, $to, pc34($main::mycall, $to, $cmd));
1086 my $pc39flag = shift;
1087 my $call = $self->call;
1089 return if $self->{disconnecting}++;
1091 unless ($pc39flag && $pc39flag == 1) {
1092 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1095 # get rid of any PC16/17/19
1096 eph_del_regex("^PC1[679]*$call");
1098 # do routing stuff, remove me from routing table
1099 my $node = Route::Node::get($call);
1103 # remove the route from this node and return a list
1104 # of nodes that have become orphanned as a result.
1105 push @rout, $main::routeroot->remove_route($node, $self);
1107 # remove all my ephemera as well
1110 eph_del_regex("^PC1[679].*$c");
1114 # unbusy and stop and outgoing mail
1115 my $mref = DXMsg::get_busy($call);
1116 $mref->stop_msg($call) if $mref;
1118 # broadcast to all other nodes that all the nodes connected to via me are gone
1119 unless ($pc39flag && $pc39flag == 2) {
1120 $self->route_pc21($main::mycall, undef, @rout) if @rout;
1121 $self->route_pc59($main::mycall, "", 'D', hexstamp(), $main::mycall, $node);
1124 # delete all the unwanted nodes
1125 $_->delete for @rout;
1127 # remove outstanding pings
1128 delete $pings{$call};
1130 # I was the last node visited
1131 $self->user->node($main::mycall);
1133 # send info to all logged in thingies
1134 $self->tell_login('logoutn');
1136 Log('DXProt', $call . " Disconnected");
1138 $self->SUPER::disconnect;
1143 # send a talk message to this thingy
1147 my ($self, $from, $to, $via, $line, $origin) = @_;
1149 $line =~ s/\^/\\5E/g; # remove any ^ characters
1150 $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
1151 Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
1154 # send it if it isn't the except list and isn't isolated and still has a hop count
1155 # taking into account filtering and so on
1161 my $generate = shift;
1162 my $no = shift; # the no of things to filter on
1164 my ($filter, $hops);
1167 for (; @_ && $no; $no--) {
1170 # deal with non routing parameters
1171 unless (ref $r && $r->isa('Route')) {
1176 if (!$self->{isolate} && $self->{routefilter}) {
1179 ($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});
1183 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
1186 dbg("was sent a null value") if isdbg('chanerr');
1189 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
1193 foreach my $line (&$generate(@rin, @_)) {
1196 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1198 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1199 next unless $routeit;
1202 $self->send($routeit);
1211 my $generate = shift;
1213 my @dxchan = DXChannel::get_all_nodes();
1216 unless ($self->{isolate}) {
1217 foreach $dxchan (@dxchan) {
1218 next if $dxchan == $self;
1219 next if $dxchan == $main::me;
1220 next unless $dxchan->isa('DXProt');
1221 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
1222 if ($dxchan->{newroute}) {
1223 next if ($generate == \&pc19 || $generate==\&pc21 ||
1224 $generate == \&pc16 || $generate==\&pc17);
1226 next if ($generate == \&pc19 || $generate==\&pc21) && !$dxchan->user->wantroutepc19;
1227 next if ($generate == \&pc59);
1230 $dxchan->send_route($origin, $generate, @_);
1238 return unless $self->user->wantpc16;
1241 broadcast_route($self, $origin, \&pc16, $line, 1, @_);
1247 return unless $self->user->wantpc16;
1250 broadcast_route($self, $origin, \&pc17, $line, 1, @_);
1258 broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
1266 broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
1274 broadcast_route($self, $origin, \&pc24, $line, 1, @_);
1282 broadcast_route($self, $origin, \&pc41, $line, 1, @_);
1290 broadcast_route($self, $origin, \&pc50, $line, 1, @_);
1299 broadcast_route($self, $origin, \&pc59, $line, scalar @_, @_);
1306 my ($filter, $hops) = (1, 1);
1308 if ($self->{inroutefilter}) {
1309 ($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);
1310 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
1318 my $t = shift || $eph_restime;
1322 $s =~ s/\^H\d\d?\^?\~?$//;
1323 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
1324 $eph{$s} = $main::systime + $t;
1332 while (($key, $val) = each %eph) {
1333 if ($key =~ m{$regex}) {
1343 while (($key, $val) = each %eph) {
1344 if ($main::systime >= $val) {
1355 while (($key, $val) = each %eph) {
1356 push @out, $key, $val;
1363 goto &DXCommandmode::run_cmd;