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);
39 use vars qw($VERSION $BRANCH);
40 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
41 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
42 $main::build += $VERSION;
43 $main::branch += $BRANCH;
45 use vars qw($pc11_max_age $pc23_max_age $last_pc50 $eph_restime $eph_info_restime $eph_pc34_restime
46 $last_hour $last10 %eph %pings %rcmds $ann_to_talk
47 $pingint $obscount %pc19list $chatdupeage
48 %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
49 $allowzero $decode_dk0wcy $send_opernam @checklist);
51 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
52 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
54 $last_hour = time; # last time I did an hourly periodic update
55 %pings = (); # outstanding ping requests outbound
56 %rcmds = (); # outstanding rcmd requests outbound
57 %nodehops = (); # node specific hop control
58 %pc19list = (); # list of outstanding PC19s that haven't had PC16s on them
60 $censorpc = 1; # Do a BadWords::check on text fields and reject things
61 # loads of 'bad things'
62 $baddx = new DXHash "baddx";
63 $badspotter = new DXHash "badspotter";
64 $badnode = new DXHash "badnode";
65 $last10 = $last_pc50 = time;
69 $eph_info_restime = 60*60;
70 $eph_pc34_restime = 30;
73 $chatdupeage = 20 * 60 * 60;
77 [ qw(c c m bp bc c) ], # pc10
78 [ qw(f m d t m c c h) ], # pc11
79 [ qw(c bm m bm bm p h) ], # pc12
83 undef , # pc16 has to be validated manually
86 undef , # pc19 has to be validated manually
87 undef , # pc20 no validation
89 undef , # pc22 no validation
90 [ qw(d n n n n m c c h) ], # pc23
92 [ qw(c c n n) ], # pc25
93 [ qw(f m d t m c c bc) ], # pc26
94 [ qw(d n n n n m c c bc) ], # pc27
95 [ qw(c c m c d t p m bp n p bp bc) ], # pc28
96 [ qw(c c n m) ], # pc29
100 [ qw(c c n) ], # pc33
101 [ qw(c c m) ], # pc34
102 [ qw(c c m) ], # pc35
103 [ qw(c c m) ], # pc36
104 [ qw(c c n m) ], # pc37
105 undef, # pc38 not interested
107 [ qw(c c m p n) ], # pc40
108 [ qw(c n m h) ], # pc41
109 [ qw(c c n) ], # pc42
110 undef, # pc43 don't handle it
111 [ qw(c c n m m c) ], # pc44
112 [ qw(c c n m) ], # pc45
113 [ qw(c c n) ], # pc46
116 [ qw(c m h) ], # pc49
117 [ qw(c n h) ], # pc50
118 [ qw(c c n) ], # pc51
140 [ qw(d n n n n n n m m m c c h) ], # pc73
151 [ qw(c c c m) ], # pc84
152 [ qw(c c c m) ], # pc85
155 # use the entry in the check list to check the field list presented
156 # return OK if line NOT in check list (for now)
161 return 0 if $n < 0 || $n > @checklist;
162 my $ref = $checklist[$n];
163 return 0 unless ref $ref;
166 shift; # not interested in the first field
167 for ($i = 0; $i < @$ref; $i++) {
168 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
169 return 0 unless $act;
170 next if $blank && $_[$i] =~ /^[ \*]$/;
172 return $i+1 unless is_callsign($_[$i]);
173 } elsif ($act eq 'm') {
174 return $i+1 unless is_pctext($_[$i]);
175 } elsif ($act eq 'p') {
176 return $i+1 unless is_pcflag($_[$i]);
177 } elsif ($act eq 'f') {
178 return $i+1 unless is_freq($_[$i]);
179 } elsif ($act eq 'n') {
180 return $i+1 unless $_[$i] =~ /^[\d ]+$/;
181 } elsif ($act eq 'h') {
182 return $i+1 unless $_[$i] =~ /^H\d\d?$/;
183 } elsif ($act eq 'd') {
184 return $i+1 unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
185 } elsif ($act eq 't') {
186 return $i+1 unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
194 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
199 # obtain a new connection this is derived from dxchannel
204 my $self = DXChannel::alloc(@_);
206 # add this node to the table, the values get filled in later
209 $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
214 # this is how a pc connection starts (for an incoming connection)
215 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
216 # all the crap that comes between).
219 my ($self, $line, $sort) = @_;
220 my $call = $self->{call};
221 my $user = $self->{user};
224 my $host = $self->{conn}->{peerhost} || "unknown";
225 Log('DXProt', "$call connected from $host");
227 # remember type of connection
228 $self->{consort} = $line;
229 $self->{outbound} = $sort eq 'O';
230 my $priv = $user->priv;
231 $priv = $user->priv(1) unless $priv;
232 $self->{priv} = $priv; # other clusters can always be 'normal' users
233 $self->{lang} = $user->lang || 'en';
234 $self->{isolate} = $user->{isolate};
235 $self->{consort} = $line; # save the connection type
239 # sort out registration
240 $self->{registered} = 1;
242 # get the output filters
243 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
244 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
245 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
246 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
247 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
250 # get the INPUT filters (these only pertain to Clusters)
251 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
252 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
253 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
254 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
255 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
257 # set unbuffered and no echo
258 $self->send_now('B',"0");
259 $self->send_now('E',"0");
260 $self->conn->echo(0) if $self->conn->can('echo');
262 # ping neighbour node stuff
263 my $ping = $user->pingint;
264 $ping = $pingint unless defined $ping;
265 $self->{pingint} = $ping;
266 $self->{nopings} = $user->nopings || $obscount;
267 $self->{pingtime} = [ ];
268 $self->{pingave} = 999;
269 $self->{metric} ||= 100;
270 $self->{lastping} = $main::systime;
272 # send initialisation string
273 unless ($self->{outbound}) {
277 $self->state('init');
278 $self->{pc50_t} = $main::systime;
280 # send info to all logged in thingies
281 $self->tell_login('loginn');
283 # run a script send the output to the debug file
284 my $script = new Script(lc $call) || new Script('node_default');
285 $script->run($self) if $script;
289 # send outgoing 'challenge'
299 # This is the normal pcxx despatcher
303 my ($self, $line) = @_;
304 my @field = split /\^/, $line;
305 return unless @field;
307 pop @field if $field[-1] eq '~';
309 # print join(',', @field), "\n";
312 # process PC frames, this will fail unless the frame starts PCnn
313 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
315 return if $pcno < 10 || $pcno > 99;
317 # check for and dump bad protocol messages
318 my $n = check($pcno, @field);
320 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
327 $pcr = Local::pcprot($self, $pcno, @field);
329 # dbg("Local::pcprot error $@") if isdbg('local') if $@;
333 my $sub = "handle_$pcno";
334 if ($self->can($sub)) {
335 $self->$sub($pcno, $line, @field);
337 $self->handle_default($pcno, $line, @field);
341 # incoming talk commands
349 return if $rspfcheck and !$self->rspfcheck(0, $_[6], $_[1]);
351 # will we allow it at all?
354 if (@bad = BadWords::check($_[3])) {
355 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
360 # is it for me or one of mine?
361 my ($from, $to, $via, $call, $dxchan);
370 # if this is a 'nodx' node then ignore it
371 if ($badnode->in($_[6]) || ($via && $badnode->in($via))) {
372 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
376 # if this is a 'bad spotter' user then ignore it
378 $nossid =~ s/-\d+$//;
379 if ($badspotter->in($nossid)) {
380 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
384 # if we are converting announces to talk is it a dup?
386 if (AnnTalk::is_talk_candidate($from, $_[3]) && AnnTalk::dup($from, $to, $_[3])) {
387 dbg("DXPROT: Dupe talk from announce, dropped") if isdbg('chanerr');
392 # it is here and logged on
393 $dxchan = DXChannel->get($main::myalias) if $to eq $main::mycall;
394 $dxchan = DXChannel->get($to) unless $dxchan;
395 if ($dxchan && $dxchan->is_user) {
397 $dxchan->talk($from, $to, $via, $_[3]);
401 # is it elsewhere, visible on the cluster via the to address?
402 # note: this discards the via unless the to address is on
405 if ($ref = Route::get($to)) {
406 $vref = Route::Node::get($via) if $via;
407 $vref = undef unless $vref && grep $to eq $_, $vref->users;
408 $ref->dxchan->talk($from, $to, $vref ? $via : undef, $_[3], $_[6]);
412 # not visible here, send a message of condolence
414 $ref = Route::get($from);
415 $vref = $ref = Route::Node::get($_[6]) unless $ref;
417 $dxchan = $ref->dxchan;
418 $dxchan->talk($main::mycall, $from, $vref ? $vref->call : undef, $dxchan->msg('talknh', $to) );
429 # route 'foreign' pc26s
431 if ($_[7] ne $main::mycall) {
432 $self->route($_[7], $line);
438 # return if $rspfcheck and !$self->rspfcheck(1, $_[7], $_[6]);
440 # if this is a 'nodx' node then ignore it
441 if ($badnode->in($_[7])) {
442 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
446 # if this is a 'bad spotter' user then ignore it
448 $nossid =~ s/-\d+$//;
449 if ($badspotter->in($nossid)) {
450 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
454 # convert the date to a unix date
455 my $d = cltounix($_[3], $_[4]);
456 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
457 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
458 dbg("PCPROT: Spot ignored, invalid date or out of range ($_[3] $_[4])\n") if isdbg('chanerr');
463 if ($baddx->in($_[2]) || BadWords::check($_[2]) || $_[2] =~ /COCK/) {
464 dbg("PCPROT: Bad DX spot, ignored") if isdbg('chanerr');
469 $_[5] =~ s/^\s+//; # take any leading blanks off
470 $_[2] = unpad($_[2]); # take off leading and trailing blanks from spotted callsign
471 if ($_[2] =~ /BUST\w*$/) {
472 dbg("PCPROT: useless 'BUSTED' spot") if isdbg('chanerr');
477 if (@bad = BadWords::check($_[5])) {
478 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
484 my @spot = Spot::prepare($_[1], $_[2], $d, $_[5], $_[6], $_[7]);
485 # global spot filtering on INPUT
486 if ($self->{inspotsfilter}) {
487 my ($filter, $hops) = $self->{inspotsfilter}->it(@spot);
489 dbg("PCPROT: Rejected by input spot filter") if isdbg('chanerr');
494 # this goes after the input filtering, but before the add
495 # so that if it is input filtered, it isn't added to the dup
496 # list. This allows it to come in from a "legitimate" source
497 if (Spot::dup($_[1], $_[2], $d, $_[5], $_[6])) {
498 dbg("PCPROT: Duplicate Spot ignored\n") if isdbg('chanerr');
506 # @spot at this point contains:-
507 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
508 # then spotted itu, spotted cq, spotters itu, spotters cq
509 # you should be able to route on any of these
512 # fix up qra locators of known users
513 my $user = DXUser->get_current($spot[4]);
515 my $qra = $user->qra;
516 unless ($qra && is_qra($qra)) {
517 my $lat = $user->lat;
518 my $long = $user->long;
519 if (defined $lat && defined $long) {
520 $user->qra(DXBearing::lltoqra($lat, $long));
525 # send a remote command to a distant cluster if it is visible and there is no
526 # qra locator and we havn't done it for a month.
528 unless ($user->qra) {
530 my $to = $user->homenode;
531 my $last = $user->lastoper || 0;
532 if ($send_opernam && $to && $to ne $main::mycall && $main::systime > $last + $DXUser::lastoperinterval && ($node = Route::Node::get($to)) ) {
533 my $cmd = "forward/opernam $spot[4]";
534 # send the rcmd but we aren't interested in the replies...
535 my $dxchan = $node->dxchan;
536 if ($dxchan && $dxchan->is_clx) {
537 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
539 route(undef, $to, pc34($main::mycall, $to, $cmd));
543 $node = Route::Node::get($to);
545 $dxchan = $node->dxchan;
546 if ($dxchan && $dxchan->is_clx) {
547 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
549 route(undef, $to, pc34($main::mycall, $to, $cmd));
553 $user->lastoper($main::systime);
562 $r = Local::spot($self, @spot);
564 # dbg("Local::spot1 error $@") if isdbg('local') if $@;
567 # DON'T be silly and send on PC26s!
568 return if $pcno == 26;
570 # send out the filtered spots
571 send_dx_spot($self, $line, @spot) if @spot;
581 # return if $rspfcheck and !$self->rspfcheck(1, $_[5], $_[1]);
583 # announce duplicate checking
584 $_[3] =~ s/^\s+//; # remove leading blanks
588 if (@bad = BadWords::check($_[3])) {
589 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
594 # if this is a 'nodx' node then ignore it
595 if ($badnode->in($_[5])) {
596 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
600 # if this is a 'bad spotter' user then ignore it
602 $nossid =~ s/-\d+$//;
603 if ($badspotter->in($nossid)) {
604 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
610 if ((($dxchan = DXChannel->get($_[2])) && $dxchan->is_user) || $_[4] =~ /^[\#\w]+$/){
611 $self->send_chat($line, @_[1..6]);
612 } elsif ($_[2] eq '*' || $_[2] eq $main::mycall) {
614 # ignore something that looks like a chat line coming in with sysop
615 # flag - this is a kludge...
616 if ($_[3] =~ /^\#\d+ / && $_[4] eq '*') {
617 dbg('PCPROT: Probable chat rewrite, dropped') if isdbg('chanerr');
621 # here's a bit of fun, convert incoming ann with a callsign in the first word
622 # or one saying 'to <call>' to a talk if we can route to the recipient
624 my $call = AnnTalk::is_talk_candidate($_[1], $_[3]);
626 my $ref = Route::get($call);
628 $dxchan = $ref->dxchan;
629 $dxchan->talk($_[1], $call, undef, $_[3], $_[5]) if $dxchan != $self;
636 $self->send_announce($line, @_[1..6]);
638 $self->route($_[2], $line);
650 if (eph_dup($line)) {
651 dbg("PCPROT: dup PC16 detected") if isdbg('chanerr');
658 my $newline = "PC16^";
660 # do I want users from this channel?
661 unless ($self->user->wantpc16) {
662 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
666 if ($ncall eq $main::mycall) {
667 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
670 my $parent = Route::Node::get($ncall);
672 # if there is a parent, proceed, otherwise if there is a latent PC19 in the PC19list,
673 # fix it up in the routing tables and issue it forth before the PC16
675 my $nl = $pc19list{$ncall};
677 if ($nl && @_ > 3) { # 3 because of the hop count!
679 # this is a new (remembered) node, now attach it to me if it isn't in filtered
680 # and we haven't disallowed it
681 my $user = DXUser->get_current($ncall);
683 $user = DXUser->new($ncall);
685 $user->priv(1); # I have relented and defaulted nodes
687 $user->homenode($ncall);
691 my $wantpc19 = $user->wantroutepc19;
692 if ($wantpc19 || !defined $wantpc19) {
693 my $new = Route->new($ncall); # throw away
694 if ($self->in_filter_route($new)) {
697 $parent = Route::Node::get($_->[0]);
698 $dxchan = $parent->dxchan if $parent;
699 if ($dxchan && $dxchan ne $self) {
700 dbg("PCPROT: PC19 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
704 my $r = $parent->add($ncall, $_->[1], $_->[2]);
705 push @nrout, $r unless @nrout;
708 $user->wantroutepc19(1) unless defined $wantpc19; # for now we work on the basis that pc16 = real route
709 $user->lastin($main::systime) unless DXChannel->get($ncall);
712 # route the pc19 - this will cause 'stuttering PC19s' for a while
713 $self->route_pc19(@nrout) if @nrout ;
714 $parent = Route::Node::get($ncall);
716 dbg("PCPROT: lost $ncall after sending PC19 for it?");
722 delete $pc19list{$ncall};
725 dbg("PCPROT: Node $ncall not in config") if isdbg('chanerr');
730 $dxchan = $parent->dxchan;
731 if ($dxchan && $dxchan ne $self) {
732 dbg("PCPROT: PC16 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
736 # input filter if required
737 return unless $self->in_filter_route($parent);
742 for ($i = 2; $i < $#_; $i++) {
743 my ($call, $conf, $here) = $_[$i] =~ /^(\S+) (\S) (\d)/o;
744 next unless $call && $conf && defined $here && is_callsign($call);
745 next if $call eq $main::mycall;
747 eph_del_regex("^PC17\\^$call\\^$ncall");
749 $conf = $conf eq '*';
751 # reject this if we think it is a node already
752 my $r = Route::Node::get($call);
753 my $u = DXUser->get_current($call) unless $r;
754 if ($r || ($u && $u->is_node)) {
755 dbg("PCPROT: $call is a node") if isdbg('chanerr');
759 $r = Route::User::get($call);
760 my $flags = Route::here($here)|Route::conf($conf);
763 my $au = $r->addparent($parent);
764 if ($r->flags != $flags) {
768 push @rout, $r if $au;
770 push @rout, $parent->add_user($call, $flags);
774 # add this station to the user database, if required
775 $call =~ s/-\d+$//o; # remove ssid for users
776 my $user = DXUser->get_current($call);
777 $user = DXUser->new($call) if !$user;
778 $user->homenode($parent->call) if !$user->homenode;
779 $user->node($parent->call);
780 $user->lastin($main::systime) unless DXChannel->get($call);
784 $self->route_pc16($parent, @rout) if @rout;
797 eph_del_regex("^PC16\\^$ncall.*$ucall");
799 # do I want users from this channel?
800 unless ($self->user->wantpc16) {
801 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
804 if ($ncall eq $main::mycall) {
805 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
809 my $uref = Route::User::get($ucall);
811 dbg("PCPROT: Route::User $ucall not in config") if isdbg('chanerr');
814 my $parent = Route::Node::get($ncall);
816 dbg("PCPROT: Route::Node $ncall not in config") if isdbg('chanerr');
820 $dxchan = $parent->dxchan;
821 if ($dxchan && $dxchan ne $self) {
822 dbg("PCPROT: PC17 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
826 # input filter if required
827 return unless $self->in_filter_route($parent);
829 $parent->del_user($uref);
831 if (eph_dup($line)) {
832 dbg("PCPROT: dup PC17 detected") if isdbg('chanerr');
836 $self->route_pc17($parent, $uref);
845 $self->state('init');
847 # record the type and version offered
848 if ($_[1] =~ /DXSpider Version: (\d+\.\d+) Build: (\d+\.\d+)/) {
849 $self->version(53 + $1);
850 $self->user->version(53 + $1);
851 $self->build(0 + $2);
852 $self->user->build(0 + $2);
853 unless ($self->is_spider) {
854 $self->user->sort('S');
859 $self->version(50.0);
860 $self->version($_[2] / 100) if $_[2] && $_[2] =~ /^\d+$/;
861 $self->user->version($self->version);
864 # first clear out any nodes on this dxchannel
865 my $parent = Route::Node::get($self->{call});
866 my @rout = $parent->del_nodes;
867 $self->route_pc21(@rout, $parent) if @rout;
868 $self->send_local_config();
872 # incoming cluster list
880 my $newline = "PC19^";
882 if (eph_dup($line)) {
883 dbg("PCPROT: dup PC19 detected") if isdbg('chanerr');
889 my $parent = Route::Node::get($self->{call});
891 dbg("DXPROT: my parent $self->{call} has disappeared");
897 for ($i = 1; $i < $#_-1; $i += 4) {
899 my $call = uc $_[$i+1];
902 next unless defined $here && defined $conf && is_callsign($call);
904 eph_del_regex("^PC(?:21\\^$call|17\\^[^\\^]+\\^$call)");
906 # check for sane parameters
907 # $ver = 5000 if $ver eq '0000';
908 next if $ver < 5000; # only works with version 5 software
909 next if length $call < 3; # min 3 letter callsigns
910 next if $call eq $main::mycall;
912 # check that this PC19 isn't trying to alter the wrong dxchan
913 my $dxchan = DXChannel->get($call);
914 if ($dxchan && $dxchan != $self) {
915 dbg("PCPROT: PC19 from $self->{call} trying to alter wrong locally connected $call, ignored!") if isdbg('chanerr');
919 # add this station to the user database, if required (don't remove SSID from nodes)
920 my $user = DXUser->get_current($call);
922 $user = DXUser->new($call);
924 $user->priv(1); # I have relented and defaulted nodes
926 $user->homenode($call);
930 my $r = Route::Node::get($call);
931 my $flags = Route::here($here)|Route::conf($conf);
933 # modify the routing table if it is in it, otherwise store it in the pc19list for now
936 if ($call ne $parent->call) {
937 if ($self->in_filter_route($r)) {
938 $ar = $parent->add($call, $ver, $flags);
939 push @rout, $ar if $ar;
944 if ($r->version ne $ver || $r->flags != $flags) {
947 push @rout, $r unless $ar;
951 # if he is directly connected or allowed then add him, otherwise store him up for later
952 if ($call eq $self->{call} || $user->wantroutepc19) {
953 my $new = Route->new($call); # throw away
954 if ($self->in_filter_route($new)) {
955 my $ar = $parent->add($call, $ver, $flags);
956 $user->wantroutepc19(1) unless defined $user->wantroutepc19;
957 push @rout, $ar if $ar;
962 $pc19list{$call} = [] unless exists $pc19list{$call};
963 my $nl = $pc19list{$call};
964 push @{$pc19list{$call}}, [$self->{call}, $ver, $flags] unless grep $_->[0] eq $self->{call}, @$nl;
968 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
969 my $mref = DXMsg::get_busy($call);
970 $mref->stop_msg($call) if $mref;
972 $user->lastin($main::systime) unless DXChannel->get($call);
977 $self->route_pc19(@rout) if @rout;
980 # send local configuration
986 $self->send_local_config();
988 $self->state('normal');
989 $self->{lastping} = 0;
992 # delete a cluster from the list
1000 eph_del_regex("^PC1[679].*$call");
1002 # if I get a PC21 from the same callsign as self then treat it
1003 # as a PC39: I have gone away
1004 if ($call eq $self->call) {
1005 $self->disconnect(1);
1009 # check to see if we are in the pc19list, if we are then don't bother with any of
1010 # this routing table manipulation, just remove it from the list and dump it
1012 if (my $nl = $pc19list{$call}) {
1013 $pc19list{$call} = [ grep {$_->[0] ne $self->{call}} @$nl ];
1014 delete $pc19list{$call} unless @{$pc19list{$call}};
1017 my $parent = Route::Node::get($self->{call});
1019 dbg("DXPROT: my parent $self->{call} has disappeared");
1023 if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
1024 my $node = Route::Node::get($call);
1027 my $dxchan = DXChannel->get($call);
1028 if ($dxchan && $dxchan != $self) {
1029 dbg("PCPROT: PC21 from $self->{call} trying to alter locally connected $call, ignored!") if isdbg('chanerr');
1034 return unless $self->in_filter_route($node);
1037 push @rout, $node->del($parent);
1040 dbg("PCPROT: I WILL _NOT_ be disconnected!") if isdbg('chanerr');
1045 $self->route_pc21(@rout) if @rout;
1054 $self->state('normal');
1055 $self->{lastping} = 0;
1065 # route 'foreign' pc27s
1067 if ($_[8] ne $main::mycall) {
1068 $self->route($_[8], $line);
1073 return if $rspfcheck and !$self->rspfcheck(1, $_[8], $_[7]);
1076 my $d = cltounix($_[1], sprintf("%02d18Z", $_[2]));
1077 my $sfi = unpad($_[3]);
1078 my $k = unpad($_[4]);
1079 my $i = unpad($_[5]);
1080 my ($r) = $_[6] =~ /R=(\d+)/;
1082 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1083 dbg("PCPROT: WWV Date ($_[1] $_[2]) out of range") if isdbg('chanerr');
1086 if (Geomag::dup($d,$sfi,$k,$i,$_[6])) {
1087 dbg("PCPROT: Dup WWV Spot ignored\n") if isdbg('chanerr');
1090 $_[7] =~ s/-\d+$//o; # remove spotter's ssid
1092 my $wwv = Geomag::update($d, $_[2], $sfi, $k, $i, @_[6..8], $r);
1096 $rep = Local::wwv($self, $_[1], $_[2], $sfi, $k, $i, @_[6..8], $r);
1098 # dbg("Local::wwv2 error $@") if isdbg('local') if $@;
1101 # DON'T be silly and send on PC27s!
1102 return if $pcno == 27;
1104 # broadcast to the eager world
1105 send_wwv_spot($self, $line, $d, $_[2], $sfi, $k, $i, @_[6..8]);
1114 my $call = uc $_[1];
1116 $nref = Route::Node::get($call);
1117 $uref = Route::User::get($call);
1118 return unless $nref || $uref; # if we don't know where they are, it's pointless sending it on
1120 if (eph_dup($line)) {
1121 dbg("PCPROT: Dup PC24 ignored\n") if isdbg('chanerr');
1125 $nref->here($_[2]) if $nref;
1126 $uref->here($_[2]) if $uref;
1127 my $ref = $nref || $uref;
1128 return unless $self->in_filter_route($ref);
1130 $self->route_pc24($ref, $_[3]);
1139 if ($_[1] ne $main::mycall) {
1140 $self->route($_[1], $line);
1143 if ($_[2] eq $main::mycall) {
1144 dbg("PCPROT: Trying to merge to myself, ignored") if isdbg('chanerr');
1148 Log('DXProt', "Merge request for $_[3] spots and $_[4] WWV from $_[2]");
1152 my @in = reverse Spot::search(1, undef, undef, 0, $_[3]);
1155 $self->send(pc26(@{$in}[0..4], $_[2]));
1161 my @in = reverse Geomag::search(0, $_[4], time, 1);
1164 $self->send(pc27(@{$in}[0..5], $_[2]));
1169 sub handle_26 {goto &handle_11}
1170 sub handle_27 {goto &handle_23}
1172 # mail/file handling
1178 if ($_[1] eq $main::mycall) {
1180 my $sub = "DXMsg::handle_$pcno";
1183 $self->route($_[1], $line) unless $self->is_clx;
1187 sub handle_29 {goto &handle_28}
1188 sub handle_30 {goto &handle_28}
1189 sub handle_31 {goto &handle_28}
1190 sub handle_32 {goto &handle_28}
1191 sub handle_33 {goto &handle_28}
1198 if (eph_dup($line, $eph_pc34_restime)) {
1199 dbg("PCPROT: dupe PC34, ignored") if isdbg('chanerr');
1201 $self->process_rcmd($_[1], $_[2], $_[2], $_[3]);
1205 # remote command replies
1211 eph_del_regex("^PC35\\^$_[2]\\^$_[1]\\^");
1212 $self->process_rcmd_reply($_[1], $_[2], $_[1], $_[3]);
1215 sub handle_36 {goto &handle_34}
1223 DXDb::process($self, $line);
1226 # node connected list from neighbour
1234 # incoming disconnect
1240 if ($_[1] eq $self->{call}) {
1241 $self->disconnect(1);
1243 dbg("PCPROT: came in on wrong channel") if isdbg('chanerr');
1247 sub handle_40 {goto &handle_28}
1258 $l =~ s/[\x00-\x20\x7f-\xff]+//g; # remove all funny characters and spaces for dup checking
1259 if (eph_dup($l, $eph_info_restime)) {
1260 dbg("PCPROT: dup PC41, ignored") if isdbg('chanerr');
1264 # input filter if required
1265 # my $ref = Route::get($call) || Route->new($call);
1266 # return unless $self->in_filter_route($ref);
1268 if ($_[3] eq $_[2] || $_[3] =~ /^\s*$/) {
1269 dbg('PCPROT: invalid value') if isdbg('chanerr');
1273 # add this station to the user database, if required
1274 my $user = DXUser->get_current($call);
1275 $user = DXUser->new($call) unless $user;
1279 } elsif ($_[2] == 2) {
1281 } elsif ($_[2] == 3) {
1282 if (is_latlong($_[3])) {
1283 my ($lat, $long) = DXBearing::stoll($_[3]);
1286 $user->qra(DXBearing::lltoqra($lat, $long));
1288 dbg('PCPROT: not a valid lat/long') if isdbg('chanerr');
1291 } elsif ($_[2] == 4) {
1292 $user->homenode($_[3]);
1293 } elsif ($_[2] == 5) {
1294 if (is_qra(uc $_[3])) {
1295 my ($lat, $long) = DXBearing::qratoll(uc $_[3]);
1298 $user->qra(uc $_[3]);
1300 dbg('PCPROT: not a valid QRA locator') if isdbg('chanerr');
1304 $user->lastoper($main::systime); # to cut down on excessive for/opers being generated
1307 unless ($self->{isolate}) {
1308 DXChannel::broadcast_nodes($line, $self); # send it to everyone but me
1311 # perhaps this IS what we want after all
1312 # $self->route_pc41($ref, $call, $_[2], $_[3], $_[4]);
1315 sub handle_42 {goto &handle_28}
1319 sub handle_44 {goto &handle_37}
1320 sub handle_45 {goto &handle_37}
1321 sub handle_46 {goto &handle_37}
1322 sub handle_47 {goto &handle_37}
1323 sub handle_48 {goto &handle_37}
1325 # message and database
1332 if (eph_dup($line)) {
1333 dbg("PCPROT: Dup PC49 ignored\n") if isdbg('chanerr');
1337 if ($_[1] eq $main::mycall) {
1338 DXMsg::handle_49($self, @_);
1340 $self->route($_[1], $line) unless $self->is_clx;
1344 # keep alive/user list
1352 my $node = Route::Node::get($call);
1354 return unless $node->call eq $self->{call};
1355 $node->usercount($_[2]);
1357 # input filter if required
1358 return unless $self->in_filter_route($node);
1360 $self->route_pc50($node, $_[2], $_[3]) unless eph_dup($line);
1364 # incoming ping requests/answers
1376 if ($to eq $main::mycall) {
1378 $self->send(pc51($from, $to, '0'));
1380 # it's a reply, look in the ping list for this one
1381 my $ref = $pings{$from};
1383 my $tochan = DXChannel->get($from);
1385 my $r = shift @$ref;
1386 my $dxchan = DXChannel->get($r->{call});
1387 next unless $dxchan;
1388 my $t = tv_interval($r->{t}, [ gettimeofday ]);
1389 if ($dxchan->is_user) {
1390 my $s = sprintf "%.2f", $t;
1391 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
1392 $dxchan->send($dxchan->msg('pingi', $from, $s, $ave))
1393 } elsif ($dxchan->is_node) {
1395 my $nopings = $tochan->user->nopings || 2;
1396 push @{$tochan->{pingtime}}, $t;
1397 shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
1399 # cope with a missed ping, this means you must set the pingint large enough
1400 if ($t > $tochan->{pingint} && $t < 2 * $tochan->{pingint} ) {
1401 $t -= $tochan->{pingint};
1404 # calc smoothed RTT a la TCP
1405 if (@{$tochan->{pingtime}} == 1) {
1406 $tochan->{pingave} = $t;
1408 $tochan->{pingave} = $tochan->{pingave} + (($t - $tochan->{pingave}) / 6);
1410 $tochan->{nopings} = $nopings; # pump up the timer
1417 if (eph_dup($line)) {
1418 dbg("PCPROT: dup PC51 detected") if isdbg('chanerr');
1421 # route down an appropriate thingy
1422 $self->route($to, $line);
1426 # dunno but route it
1433 if ($call ne $main::mycall) {
1434 $self->route($call, $line);
1447 my $d = cltounix($call, sprintf("%02d18Z", $_[2]));
1448 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1449 dbg("PCPROT: WCY Date ($call $_[2]) out of range") if isdbg('chanerr');
1452 @_ = map { unpad($_) } @_;
1454 dbg("PCPROT: Dup WCY Spot ignored\n") if isdbg('chanerr');
1458 my $wcy = WCY::update($d, @_[2..12]);
1462 $rep = Local::wcy($self, @_[1..12]);
1464 # dbg("Local::wcy error $@") if isdbg('local') if $@;
1467 # broadcast to the eager world
1468 send_wcy_spot($self, $line, $d, @_[2..12]);
1471 # remote commands (incoming)
1477 $self->process_rcmd($_[1], $_[2], $_[3], $_[4]);
1480 # remote command replies
1486 $self->process_rcmd_reply($_[1], $_[2], $_[3], $_[4]);
1489 # if get here then rebroadcast the thing with its Hop count decremented (if
1490 # there is one). If it has a hop count and it decrements to zero then don't
1493 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
1503 if (eph_dup($line)) {
1504 dbg("PCPROT: Ephemeral dup, dropped") if isdbg('chanerr');
1506 unless ($self->{isolate}) {
1507 DXChannel::broadcast_nodes($line, $self); # send it to everyone but me
1513 # This is called from inside the main cluster processing loop and is used
1514 # for despatching commands that are doing some long processing job
1519 my @dxchan = DXChannel->get_all();
1523 # send out a pc50 on EVERY channel all at once
1524 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
1525 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
1530 foreach $dxchan (@dxchan) {
1531 next unless $dxchan->is_node();
1532 next if $dxchan == $main::me;
1534 # send the pc50 or PC90
1535 $dxchan->send($pc50s) if $pc50s;
1537 # send a ping out on this channel
1538 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
1539 if ($dxchan->{nopings} <= 0) {
1540 $dxchan->disconnect;
1542 addping($main::mycall, $dxchan->call);
1543 $dxchan->{nopings} -= 1;
1544 $dxchan->{lastping} = $t;
1550 if ($t - $last10 >= 10) {
1551 # clean out ephemera
1558 if ($main::systime - 3600 > $last_hour) {
1559 $last_hour = $main::systime;
1564 # finish up a pc context
1568 # some active measures
1576 my @dxchan = DXChannel->get_all();
1579 # send it if it isn't the except list and isn't isolated and still has a hop count
1580 # taking into account filtering and so on
1581 foreach $dxchan (@dxchan) {
1582 next if $dxchan == $main::me;
1583 next if $dxchan == $self && $self->is_node;
1584 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
1592 my $isolate = shift;
1593 my ($filter, $hops);
1595 if ($self->{spotsfilter}) {
1596 ($filter, $hops) = $self->{spotsfilter}->it(@_);
1597 return unless $filter;
1599 send_prot_line($self, $filter, $hops, $isolate, $line);
1604 my ($self, $filter, $hops, $isolate, $line) = @_;
1609 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1611 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1612 return unless $routeit;
1615 $self->send($routeit);
1617 $self->send($routeit) unless $self->{isolate} || $isolate;
1626 my @dxchan = DXChannel->get_all();
1628 my ($wwv_dxcc, $wwv_itu, $wwv_cq, $org_dxcc, $org_itu, $org_cq) = (0..0);
1629 my @dxcc = Prefix::extract($_[6]);
1631 $wwv_dxcc = $dxcc[1]->dxcc;
1632 $wwv_itu = $dxcc[1]->itu;
1633 $wwv_cq = $dxcc[1]->cq;
1635 @dxcc = Prefix::extract($_[7]);
1637 $org_dxcc = $dxcc[1]->dxcc;
1638 $org_itu = $dxcc[1]->itu;
1639 $org_cq = $dxcc[1]->cq;
1642 # send it if it isn't the except list and isn't isolated and still has a hop count
1643 # taking into account filtering and so on
1644 foreach $dxchan (@dxchan) {
1645 next if $dxchan == $main::me;
1646 next if $dxchan == $self && $self->is_node;
1648 my ($filter, $hops);
1650 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, $wwv_dxcc, $wwv_itu, $wwv_cq, $org_dxcc, $org_itu, $org_cq);
1659 my $isolate = shift;
1660 my ($filter, $hops);
1662 if ($self->{wwvfilter}) {
1663 ($filter, $hops) = $self->{wwvfilter}->it(@_);
1664 return unless $filter;
1666 send_prot_line($self, $filter, $hops, $isolate, $line)
1673 my @dxchan = DXChannel->get_all();
1675 my ($wcy_dxcc, $wcy_itu, $wcy_cq, $org_dxcc, $org_itu, $org_cq) = (0..0);
1676 my @dxcc = Prefix::extract($_[10]);
1678 $wcy_dxcc = $dxcc[1]->dxcc;
1679 $wcy_itu = $dxcc[1]->itu;
1680 $wcy_cq = $dxcc[1]->cq;
1682 @dxcc = Prefix::extract($_[11]);
1684 $org_dxcc = $dxcc[1]->dxcc;
1685 $org_itu = $dxcc[1]->itu;
1686 $org_cq = $dxcc[1]->cq;
1689 # send it if it isn't the except list and isn't isolated and still has a hop count
1690 # taking into account filtering and so on
1691 foreach $dxchan (@dxchan) {
1692 next if $dxchan == $main::me;
1693 next if $dxchan == $self;
1695 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, $wcy_dxcc, $wcy_itu, $wcy_cq, $org_dxcc, $org_itu, $org_cq);
1703 my $isolate = shift;
1704 my ($filter, $hops);
1706 if ($self->{wcyfilter}) {
1707 ($filter, $hops) = $self->{wcyfilter}->it(@_);
1708 return unless $filter;
1710 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
1718 my @dxchan = DXChannel->get_all();
1722 my $text = unpad($_[2]);
1724 if ($_[3] eq '*') { # sysops
1726 } elsif ($_[3] gt ' ') { # speciality list handling
1727 my ($name) = split /\./, $_[3];
1728 $target = "$name"; # put the rest in later (if bothered)
1735 $target = "ALL" if !$target;
1738 # obtain country codes etc
1739 my ($ann_dxcc, $ann_itu, $ann_cq, $org_dxcc, $org_itu, $org_cq) = (0..0);
1740 my ($ann_state, $org_state) = ("", "");
1741 my @dxcc = Prefix::extract($_[0]);
1743 $ann_dxcc = $dxcc[1]->dxcc;
1744 $ann_itu = $dxcc[1]->itu;
1745 $ann_cq = $dxcc[1]->cq;
1746 $ann_state = $dxcc[1]->state;
1748 @dxcc = Prefix::extract($_[4]);
1750 $org_dxcc = $dxcc[1]->dxcc;
1751 $org_itu = $dxcc[1]->itu;
1752 $org_cq = $dxcc[1]->cq;
1753 $org_state = $dxcc[1]->state;
1756 if ($self->{inannfilter}) {
1757 my ($filter, $hops) =
1758 $self->{inannfilter}->it(@_, $self->{call},
1759 $ann_dxcc, $ann_itu, $ann_cq,
1760 $org_dxcc, $org_itu, $org_cq, $ann_state, $org_state);
1762 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1767 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
1768 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1772 Log('ann', $target, $_[0], $text);
1774 # send it if it isn't the except list and isn't isolated and still has a hop count
1775 # taking into account filtering and so on
1776 foreach $dxchan (@dxchan) {
1777 next if $dxchan == $main::me;
1778 next if $dxchan == $self && $self->is_node;
1779 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call}, $ann_dxcc, $ann_itu, $ann_cq, $org_dxcc, $org_itu, $org_cq);
1788 $msgid = 1 if $msgid > 999;
1797 my @dxchan = DXChannel->get_all();
1800 my $text = unpad($_[2]);
1802 # obtain country codes etc
1803 my ($ann_dxcc, $ann_itu, $ann_cq, $org_dxcc, $org_itu, $org_cq) = (0..0);
1804 my ($ann_state, $org_state) = ("", "");
1805 my @dxcc = Prefix::extract($_[0]);
1807 $ann_dxcc = $dxcc[1]->dxcc;
1808 $ann_itu = $dxcc[1]->itu;
1809 $ann_cq = $dxcc[1]->cq;
1810 $ann_state = $dxcc[1]->state;
1812 @dxcc = Prefix::extract($_[4]);
1814 $org_dxcc = $dxcc[1]->dxcc;
1815 $org_itu = $dxcc[1]->itu;
1816 $org_cq = $dxcc[1]->cq;
1817 $org_state = $dxcc[1]->state;
1820 if ($self->{inannfilter}) {
1821 my ($filter, $hops) =
1822 $self->{inannfilter}->it(@_, $self->{call},
1823 $ann_dxcc, $ann_itu, $ann_cq,
1824 $org_dxcc, $org_itu, $org_cq, $ann_state, $org_state);
1826 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1831 if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
1832 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1837 Log('chat', $target, $_[0], $text);
1839 # send it if it isn't the except list and isn't isolated and still has a hop count
1840 # taking into account filtering and so on
1841 foreach $dxchan (@dxchan) {
1842 next if $dxchan == $main::me;
1843 next if $dxchan == $self && $self->is_node;
1844 next if $target eq 'LOCAL' && $dxchan->is_node;
1845 $dxchan->chat($line, $self->{isolate}, $target, $_[1], $text, @_, $self->{call}, $ann_dxcc, $ann_itu, $ann_cq, $org_dxcc, $org_itu, $org_cq);
1853 my $isolate = shift;
1857 my ($filter, $hops);
1859 if ($self->{annfilter}) {
1860 ($filter, $hops) = $self->{annfilter}->it(@_);
1861 return unless $filter;
1863 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
1872 sub send_local_config
1880 dbg('DXProt::send_local_config') if isdbg('trace');
1883 if ($self->{isolate}) {
1884 @localnodes = ( $main::routeroot );
1886 # create a list of all the nodes that are not connected to this connection
1887 # and are not themselves isolated, this to make sure that isolated nodes
1888 # don't appear outside of this node
1889 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
1890 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
1891 my @intcalls = map { $_->nodes } @localnodes if @localnodes;
1892 my $ref = Route::Node::get($self->{call});
1893 my @rnodes = $ref->nodes;
1894 for my $node (@intcalls) {
1895 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes;
1897 unshift @localnodes, $main::routeroot;
1901 $self->send_route(\&pc19, scalar(@localnodes)+scalar(@remotenodes), @localnodes, @remotenodes);
1903 # get all the users connected on the above nodes and send them out
1904 foreach $node (@localnodes, @remotenodes) {
1906 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
1907 $self->send_route(\&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
1909 dbg("sent a null value") if isdbg('chanerr');
1915 # route a message down an appropriate interface for a callsign
1917 # is called route(to, pcline);
1921 my ($self, $call, $line) = @_;
1923 if (ref $self && $call eq $self->{call}) {
1924 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
1928 # always send it down the local interface if available
1929 my $dxchan = DXChannel->get($call);
1931 my $cl = Route::get($call);
1932 $dxchan = $cl->dxchan if $cl;
1934 if (ref $self && $dxchan eq $self) {
1935 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
1941 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1943 $dxchan->send($routeit) unless $dxchan == $main::me;
1946 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
1951 # obtain the hops from the list for this callsign and pc no
1957 my $hops = $DXProt::hopcount{$pcno};
1958 $hops = $DXProt::def_hopcount if !$hops;
1963 # adjust the hop count on a per node basis using the user loadable
1964 # hop table if available or else decrement an existing one
1971 my $call = $self->{call};
1974 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
1975 my ($pcno) = $s =~ /^PC(\d\d)/o;
1976 confess "$call called adjust_hops with '$s'" unless $pcno;
1977 my $ref = $nodehops{$call} if %nodehops;
1979 my $newhops = $ref->{$pcno};
1980 return "" if defined $newhops && $newhops == 0;
1981 $newhops = $ref->{default} unless $newhops;
1982 return "" if defined $newhops && $newhops == 0;
1983 $newhops = $hops if !$newhops;
1984 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1986 # simply decrement it
1988 return "" if !$hops;
1989 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
2001 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
2002 do "$main::data/hop_table.pl";
2008 # add a ping request to the ping queues
2011 my ($from, $to) = @_;
2012 my $ref = $pings{$to} || [];
2015 $r->{t} = [ gettimeofday ];
2016 route(undef, $to, pc51($to, $main::mycall, 1));
2023 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
2024 if ($tonode eq $main::mycall) {
2025 my $ref = DXUser->get_current($fromnode);
2026 my $cref = Route::Node::get($fromnode);
2027 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
2028 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
2029 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
2030 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
2031 my $oldpriv = $self->{priv};
2032 $self->{priv} = $ref->{priv}; # assume the user's privilege level
2033 my @in = (DXCommandmode::run_cmd($self, $cmd));
2034 $self->{priv} = $oldpriv;
2035 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
2036 delete $self->{remotecmd};
2038 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
2041 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
2044 my $ref = DXUser->get_current($tonode);
2045 if ($ref && $ref->is_clx) {
2046 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
2048 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
2053 sub process_rcmd_reply
2055 my ($self, $tonode, $fromnode, $user, $line) = @_;
2056 if ($tonode eq $main::mycall) {
2057 my $s = $rcmds{$fromnode};
2059 my $dxchan = DXChannel->get($s->{call});
2060 my $ref = $user eq $tonode ? $dxchan : (DXChannel->get($user) || $dxchan);
2061 $ref->send($line) if $ref;
2062 delete $rcmds{$fromnode} if !$dxchan;
2064 # send unsolicited ones to the sysop
2065 my $dxchan = DXChannel->get($main::myalias);
2066 $dxchan->send($line) if $dxchan;
2069 my $ref = DXUser->get_current($tonode);
2070 if ($ref && $ref->is_clx) {
2071 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
2073 $self->route($tonode, pc35($fromnode, $tonode, $line));
2082 my $fromnode = shift;
2087 Log('rcmd', 'out', $fromnode, $line);
2088 if ($self->is_clx) {
2089 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
2091 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
2096 # add a rcmd request to the rcmd queues
2099 my ($self, $to, $cmd) = @_;
2102 $r->{call} = $self->{call};
2103 $r->{t} = $main::systime;
2107 my $ref = Route::Node::get($to);
2108 my $dxchan = $ref->dxchan;
2109 if ($dxchan && $dxchan->is_clx) {
2110 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
2112 route(undef, $to, pc34($main::mycall, $to, $cmd));
2119 my $pc39flag = shift;
2120 my $call = $self->call;
2122 return if $self->{disconnecting}++;
2124 unless ($pc39flag && $pc39flag == 1) {
2125 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
2128 # get rid of any PC16/17/19
2129 eph_del_regex("^PC1[679]*$call");
2131 # do routing stuff, remove me from routing table
2132 my $node = Route::Node::get($call);
2135 @rout = $node->del($main::routeroot);
2137 # and all my ephemera as well
2140 eph_del_regex("^PC1[679].*$c");
2144 # remove them from the pc19list as well
2145 while (my ($k,$v) = each %pc19list) {
2146 my @l = grep {$_->[0] ne $call} @{$pc19list{$k}};
2148 $pc19list{$k} = \@l;
2150 delete $pc19list{$k};
2154 eph_del_regex("^PC1[679].*$k");
2157 # unbusy and stop and outgoing mail
2158 my $mref = DXMsg::get_busy($call);
2159 $mref->stop_msg($call) if $mref;
2161 # broadcast to all other nodes that all the nodes connected to via me are gone
2162 unless ($pc39flag && $pc39flag == 2) {
2163 $self->route_pc21(@rout) if @rout;
2166 # remove outstanding pings
2167 delete $pings{$call};
2169 # I was the last node visited
2170 $self->user->node($main::mycall);
2172 # send info to all logged in thingies
2173 $self->tell_login('logoutn');
2175 Log('DXProt', $call . " Disconnected");
2177 $self->SUPER::disconnect;
2182 # send a talk message to this thingy
2186 my ($self, $from, $to, $via, $line, $origin) = @_;
2188 $line =~ s/\^/\\5E/g; # remove any ^ characters
2189 $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
2190 Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
2193 # send it if it isn't the except list and isn't isolated and still has a hop count
2194 # taking into account filtering and so on
2198 my $generate = shift;
2199 my $no = shift; # the no of things to filter on
2201 my ($filter, $hops);
2204 for (; @_ && $no; $no--) {
2207 if (!$self->{isolate} && $self->{routefilter}) {
2210 ($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});
2214 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
2217 dbg("was sent a null value") if isdbg('chanerr');
2220 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
2224 foreach my $line (&$generate(@rin, @_)) {
2227 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
2229 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
2230 next unless $routeit;
2232 $self->send($routeit);
2240 my $generate = shift;
2241 my @dxchan = DXChannel::get_all_nodes();
2245 unless ($self->{isolate}) {
2246 foreach $dxchan (@dxchan) {
2247 next if $dxchan == $self;
2248 next if $dxchan == $main::me;
2249 next unless $dxchan->isa('DXProt');
2250 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
2252 $dxchan->send_route($generate, @_);
2260 return unless $self->user->wantpc16;
2261 broadcast_route($self, \&pc16, 1, @_);
2267 return unless $self->user->wantpc16;
2268 broadcast_route($self, \&pc17, 1, @_);
2274 broadcast_route($self, \&pc19, scalar @_, @_);
2280 broadcast_route($self, \&pc21, scalar @_, @_);
2286 broadcast_route($self, \&pc24, 1, @_);
2292 broadcast_route($self, \&pc41, 1, @_);
2298 broadcast_route($self, \&pc50, 1, @_);
2304 broadcast_route($self, \&pc90, 1, @_);
2311 my ($filter, $hops) = (1, 1);
2313 if ($self->{inroutefilter}) {
2314 ($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);
2315 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
2323 my $t = shift || $eph_restime;
2327 $s =~ s/\^H\d\d?\^?\~?$//;
2328 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
2329 $eph{$s} = $main::systime + $t;
2337 while (($key, $val) = each %eph) {
2338 if ($key =~ m{$regex}) {
2348 while (($key, $val) = each %eph) {
2349 if ($main::systime >= $val) {
2360 while (($key, $val) = each %eph) {
2361 push @out, $key, $val;
2368 goto &DXCommandmode::run_cmd;