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;
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 %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
48 $allowzero $decode_dk0wcy $send_opernam @checklist);
50 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
51 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
53 $last_hour = time; # last time I did an hourly periodic update
54 %pings = (); # outstanding ping requests outbound
55 %rcmds = (); # outstanding rcmd requests outbound
56 %nodehops = (); # node specific hop control
57 $censorpc = 1; # Do a BadWords::check on text fields and reject things
58 # loads of 'bad things'
59 $baddx = new DXHash "baddx";
60 $badspotter = new DXHash "badspotter";
61 $badnode = new DXHash "badnode";
62 $last10 = $last_pc50 = time;
66 $eph_info_restime = 60*60;
67 $eph_pc34_restime = 30;
71 [ qw(c c m bp bc c) ], # pc10
72 [ qw(f m d t m c c h) ], # pc11
73 [ qw(c bc m bp bm p h) ], # pc12
77 undef , # pc16 has to be validated manually
80 undef , # pc19 has to be validated manually
81 undef , # pc20 no validation
83 undef , # pc22 no validation
84 [ qw(d n n n n m c c h) ], # pc23
86 [ qw(c c n n) ], # pc25
87 [ qw(f m d t m c c bc) ], # pc26
88 [ qw(d n n n n m c c bc) ], # pc27
89 [ qw(c c m c d t p m bp n p bp bc) ], # pc28
90 [ qw(c c n m) ], # pc29
98 [ qw(c c n m) ], # pc37
99 undef, # pc38 not interested
101 [ qw(c c m p n) ], # pc40
102 [ qw(c n m h) ], # pc41
103 [ qw(c c n) ], # pc42
104 undef, # pc43 don't handle it
105 [ qw(c c n m m c) ], # pc44
106 [ qw(c c n m) ], # pc45
107 [ qw(c c n) ], # pc46
110 [ qw(c m h) ], # pc49
111 [ qw(c n h) ], # pc50
112 [ qw(c c n) ], # pc51
134 [ qw(d n n n n n n m m m c c h) ], # pc73
145 [ qw(c c c m) ], # pc84
146 [ qw(c c c m) ], # pc85
149 # use the entry in the check list to check the field list presented
150 # return OK if line NOT in check list (for now)
155 return 0 if $n < 0 || $n > @checklist;
156 my $ref = $checklist[$n];
157 return 0 unless ref $ref;
160 shift; # not interested in the first field
161 for ($i = 0; $i < @$ref; $i++) {
162 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
163 return 0 unless $act;
164 next if $blank && $_[$i] =~ /^[ \*]$/;
166 return $i+1 unless is_callsign($_[$i]);
167 } elsif ($act eq 'm') {
168 return $i+1 unless is_pctext($_[$i]);
169 } elsif ($act eq 'p') {
170 return $i+1 unless is_pcflag($_[$i]);
171 } elsif ($act eq 'f') {
172 return $i+1 unless is_freq($_[$i]);
173 } elsif ($act eq 'n') {
174 return $i+1 unless $_[$i] =~ /^[\d ]+$/;
175 } elsif ($act eq 'h') {
176 return $i+1 unless $_[$i] =~ /^H\d\d?$/;
177 } elsif ($act eq 'd') {
178 return $i+1 unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
179 } elsif ($act eq 't') {
180 return $i+1 unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
188 my $user = DXUser->get($main::mycall);
189 $DXProt::myprot_version += $main::version*100;
190 $main::me = DXProt->new($main::mycall, 0, $user);
191 $main::me->{here} = 1;
192 $main::me->{state} = "indifferent";
193 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
195 $main::me->{sort} = 'S'; # S for spider
196 $main::me->{priv} = 9;
197 $main::me->{metric} = 0;
198 $main::me->{pingave} = 0;
199 $main::me->{version} = $main::version;
200 $main::me->{build} = $main::build;
202 # $Route::Node::me->adddxchan($main::me);
206 # obtain a new connection this is derived from dxchannel
211 my $self = DXChannel::alloc(@_);
213 # add this node to the table, the values get filled in later
216 $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
221 # this is how a pc connection starts (for an incoming connection)
222 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
223 # all the crap that comes between).
226 my ($self, $line, $sort) = @_;
227 my $call = $self->{call};
228 my $user = $self->{user};
231 my $host = $self->{conn}->{peerhost} || "unknown";
232 Log('DXProt', "$call connected from $host");
234 # remember type of connection
235 $self->{consort} = $line;
236 $self->{outbound} = $sort eq 'O';
237 my $priv = $user->priv;
238 $priv = $user->priv(1) unless $priv;
239 $self->{priv} = $priv; # other clusters can always be 'normal' users
240 $self->{lang} = $user->lang || 'en';
241 $self->{isolate} = $user->{isolate};
242 $self->{consort} = $line; # save the connection type
246 # sort out registration
247 $self->{registered} = 1;
249 # get the output filters
250 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
251 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
252 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
253 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
254 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
257 # get the INPUT filters (these only pertain to Clusters)
258 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
259 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
260 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
261 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
262 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
264 # set unbuffered and no echo
265 $self->send_now('B',"0");
266 $self->send_now('E',"0");
267 $self->conn->echo(0) if $self->conn->can('echo');
269 # ping neighbour node stuff
270 my $ping = $user->pingint;
271 $ping = 5*60 unless defined $ping;
272 $self->{pingint} = $ping;
273 $self->{nopings} = $user->nopings || 2;
274 $self->{pingtime} = [ ];
275 $self->{pingave} = 999;
276 $self->{metric} ||= 100;
277 $self->{lastping} = $main::systime;
279 # send initialisation string
280 unless ($self->{outbound}) {
284 $self->state('init');
285 $self->{pc50_t} = $main::systime;
287 # send info to all logged in thingies
288 $self->tell_login('loginn');
290 # run a script send the output to the debug file
291 my $script = new Script(lc $call) || new Script('node_default');
292 $script->run($self) if $script;
296 # This is the normal pcxx despatcher
300 my ($self, $line) = @_;
301 my @field = split /\^/, $line;
302 return unless @field;
304 pop @field if $field[-1] eq '~';
306 # print join(',', @field), "\n";
309 # process PC frames, this will fail unless the frame starts PCnn
310 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
312 return if $pcno < 10 || $pcno > 99;
314 # check for and dump bad protocol messages
315 my $n = check($pcno, @field);
317 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
324 $pcr = Local::pcprot($self, $pcno, @field);
326 # dbg("Local::pcprot error $@") if isdbg('local') if $@;
330 if ($pcno == 10) { # incoming talk
333 return if $rspfcheck and !$self->rspfcheck(0, $field[6], $field[1]);
335 # will we allow it at all?
338 if (@bad = BadWords::check($field[3])) {
339 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
344 # is it for me or one of mine?
345 my ($from, $to, $via, $call, $dxchan);
347 if ($field[5] gt ' ') {
354 # if this is a 'nodx' node then ignore it
355 if ($badnode->in($field[6]) || ($via && $badnode->in($via))) {
356 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
360 # if this is a 'bad spotter' user then ignore it
362 $nossid =~ s/-\d+$//;
363 if ($badspotter->in($nossid)) {
364 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
368 # if we are converting announces to talk is it a dup?
370 if (AnnTalk::is_talk_candidate($from, $field[3]) && AnnTalk::dup($from, $to, $field[3])) {
371 dbg("DXPROT: Dupe talk from announce, dropped") if isdbg('chanerr');
376 # it is here and logged on
377 $dxchan = DXChannel->get($main::myalias) if $to eq $main::mycall;
378 $dxchan = DXChannel->get($to) unless $dxchan;
379 if ($dxchan && $dxchan->is_user) {
380 $field[3] =~ s/\%5E/^/g;
381 $dxchan->talk($from, $to, $via, $field[3]);
385 # is it elsewhere, visible on the cluster via the to address?
386 # note: this discards the via unless the to address is on
389 if ($ref = Route::get($to)) {
390 $vref = Route::Node::get($via) if $via;
391 $vref = undef unless $vref && grep $to eq $_, $vref->users;
392 $ref->dxchan->talk($from, $to, $vref ? $via : undef, $field[3], $field[6]);
396 # not visible here, send a message of condolence
398 $ref = Route::get($from);
399 $vref = $ref = Route::Node::get($field[6]) unless $ref;
401 $dxchan = $ref->dxchan;
402 $dxchan->talk($main::mycall, $from, $vref ? $vref->call : undef, $dxchan->msg('talknh', $to) );
407 if ($pcno == 11 || $pcno == 26) { # dx spot
409 # route 'foreign' pc26s
411 if ($field[7] ne $main::mycall) {
412 $self->route($field[7], $line);
418 # return if $rspfcheck and !$self->rspfcheck(1, $field[7], $field[6]);
420 # if this is a 'nodx' node then ignore it
421 if ($badnode->in($field[7])) {
422 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
426 # if this is a 'bad spotter' user then ignore it
427 my $nossid = $field[6];
428 $nossid =~ s/-\d+$//;
429 if ($badspotter->in($nossid)) {
430 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
434 # convert the date to a unix date
435 my $d = cltounix($field[3], $field[4]);
436 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
437 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
438 dbg("PCPROT: Spot ignored, invalid date or out of range ($field[3] $field[4])\n") if isdbg('chanerr');
443 if ($baddx->in($field[2]) || BadWords::check($field[2]) || $field[2] =~ /COCK/) {
444 dbg("PCPROT: Bad DX spot, ignored") if isdbg('chanerr');
449 $field[5] =~ s/^\s+//; # take any leading blanks off
450 $field[2] = unpad($field[2]); # take off leading and trailing blanks from spotted callsign
451 if ($field[2] =~ /BUST\w*$/) {
452 dbg("PCPROT: useless 'BUSTED' spot") if isdbg('chanerr');
457 if (@bad = BadWords::check($field[5])) {
458 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
464 my @spot = Spot::prepare($field[1], $field[2], $d, $field[5], $field[6], $field[7]);
465 # global spot filtering on INPUT
466 if ($self->{inspotsfilter}) {
467 my ($filter, $hops) = $self->{inspotsfilter}->it(@spot);
469 dbg("PCPROT: Rejected by input spot filter") if isdbg('chanerr');
474 # this goes after the input filtering, but before the add
475 # so that if it is input filtered, it isn't added to the dup
476 # list. This allows it to come in from a "legitimate" source
477 if (Spot::dup($field[1], $field[2], $d, $field[5])) {
478 dbg("PCPROT: Duplicate Spot ignored\n") if isdbg('chanerr');
486 # @spot at this point contains:-
487 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
488 # then spotted itu, spotted cq, spotters itu, spotters cq
489 # you should be able to route on any of these
492 # fix up qra locators of known users
493 my $user = DXUser->get_current($spot[4]);
495 my $qra = $user->qra;
496 unless ($qra && is_qra($qra)) {
497 my $lat = $user->lat;
498 my $long = $user->long;
499 if (defined $lat && defined $long) {
500 $user->qra(DXBearing::lltoqra($lat, $long));
505 # send a remote command to a distant cluster if it is visible and there is no
506 # qra locator and we havn't done it for a month.
508 unless ($user->qra) {
510 my $to = $user->homenode;
511 my $last = $user->lastoper || 0;
512 if ($send_opernam && $to && $to ne $main::mycall && $main::systime > $last + $DXUser::lastoperinterval && ($node = Route::Node::get($to)) ) {
513 my $cmd = "forward/opernam $spot[4]";
514 # send the rcmd but we aren't interested in the replies...
515 my $dxchan = $node->dxchan;
516 if ($dxchan && $dxchan->is_clx) {
517 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
519 route(undef, $to, pc34($main::mycall, $to, $cmd));
521 if ($to ne $field[7]) {
523 $node = Route::Node::get($to);
525 $dxchan = $node->dxchan;
526 if ($dxchan && $dxchan->is_clx) {
527 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
529 route(undef, $to, pc34($main::mycall, $to, $cmd));
533 $user->lastoper($main::systime);
542 $r = Local::spot($self, @spot);
544 # dbg("Local::spot1 error $@") if isdbg('local') if $@;
547 # DON'T be silly and send on PC26s!
548 return if $pcno == 26;
550 # send out the filtered spots
551 send_dx_spot($self, $line, @spot) if @spot;
555 if ($pcno == 12) { # announces
557 # return if $rspfcheck and !$self->rspfcheck(1, $field[5], $field[1]);
559 # announce duplicate checking
560 $field[3] =~ s/^\s+//; # remove leading blanks
564 if (@bad = BadWords::check($field[3])) {
565 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
570 # if this is a 'nodx' node then ignore it
571 if ($badnode->in($field[5])) {
572 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
576 # if this is a 'bad spotter' user then ignore it
577 my $nossid = $field[1];
578 $nossid =~ s/-\d+$//;
579 if ($badspotter->in($nossid)) {
580 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
584 if ($field[2] eq '*' || $field[2] eq $main::mycall) {
587 # here's a bit of fun, convert incoming ann with a callsign in the first word
588 # or one saying 'to <call>' to a talk if we can route to the recipient
590 my $call = AnnTalk::is_talk_candidate($field[1], $field[3]);
592 my $ref = Route::get($call);
594 my $dxchan = $ref->dxchan;
595 $dxchan->talk($field[1], $call, undef, $field[3], $field[5]) if $dxchan != $self;
602 $self->send_announce($line, @field[1..6]);
604 $self->route($field[2], $line);
619 if ($pcno == 16) { # add a user
621 if (eph_dup($line)) {
622 dbg("PCPROT: dup PC16 detected") if isdbg('chanerr');
628 my $ncall = $field[1];
629 my $newline = "PC16^";
631 if ($ncall eq $main::mycall) {
632 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
635 my $parent = Route::Node::get($ncall);
637 dbg("PCPROT: Node $ncall not in config") if isdbg('chanerr');
640 $dxchan = $parent->dxchan;
641 if ($dxchan && $dxchan ne $self) {
642 dbg("PCPROT: PC16 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
646 # input filter if required
647 return unless $self->in_filter_route($parent);
651 for ($i = 2; $i < $#field; $i++) {
652 my ($call, $conf, $here) = $field[$i] =~ /^(\S+) (\S) (\d)/o;
653 next unless $call && $conf && defined $here && is_callsign($call);
654 next if $call eq $main::mycall;
656 eph_del_regex("^PC17\\^$call\\^$ncall");
658 $conf = $conf eq '*';
660 # reject this if we think it is a node already
661 my $r = Route::Node::get($call);
662 my $u = DXUser->get_current($call) unless $r;
663 if ($r || ($u && $u->is_node)) {
664 dbg("PCPROT: $call is a node") if isdbg('chanerr');
668 $r = Route::User::get($call);
669 my $flags = Route::here($here)|Route::conf($conf);
672 if ($r->flags != $flags) {
676 $r->addparent($parent);
678 push @rout, $parent->add_user($call, $flags);
681 # add this station to the user database, if required
682 $call =~ s/-\d+$//o; # remove ssid for users
683 my $user = DXUser->get_current($call);
684 $user = DXUser->new($call) if !$user;
685 $user->homenode($parent->call) if !$user->homenode;
686 $user->node($parent->call);
687 $user->lastin($main::systime) unless DXChannel->get($call);
691 # queue up any messages (look for privates only)
692 DXMsg::queue_msg(1) if $self->state eq 'normal';
694 $self->route_pc16($parent, @rout) if @rout;
698 if ($pcno == 17) { # remove a user
700 my $ncall = $field[2];
701 my $ucall = $field[1];
703 eph_del_regex("^PC16\\^$ncall.*$ucall");
705 if ($ncall eq $main::mycall) {
706 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
710 my $uref = Route::User::get($ucall);
712 dbg("PCPROT: Route::User $ucall not in config") if isdbg('chanerr');
715 my $parent = Route::Node::get($ncall);
717 dbg("PCPROT: Route::Node $ncall not in config") if isdbg('chanerr');
721 $dxchan = $parent->dxchan;
722 if ($dxchan && $dxchan ne $self) {
723 dbg("PCPROT: PC17 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
727 # input filter if required
728 return unless $self->in_filter_route($parent);
730 $parent->del_user($uref);
732 if (eph_dup($line)) {
733 dbg("PCPROT: dup PC17 detected") if isdbg('chanerr');
737 $self->route_pc17($parent, $uref);
741 if ($pcno == 18) { # link request
742 $self->state('init');
744 # record the type and version offered
745 if ($field[1] =~ /DXSpider Version: (\d+\.\d+) Build: (\d+\.\d+)/) {
746 $self->version(53 + $1);
747 $self->user->version(53 + $1);
748 $self->build(0 + $2);
749 $self->user->build(0 + $2);
750 unless ($self->is_spider) {
751 $self->user->sort('S');
756 $self->version(50.0);
757 $self->version($field[2] / 100) if $field[2] && $field[2] =~ /^\d+$/;
758 $self->user->version($self->version);
761 # first clear out any nodes on this dxchannel
762 my $parent = Route::Node::get($self->{call});
763 my @rout = $parent->del_nodes;
764 $self->route_pc21(@rout, $parent) if @rout;
765 $self->send_local_config();
767 return; # we don't pass these on
770 if ($pcno == 19) { # incoming cluster list
772 my $newline = "PC19^";
774 if (eph_dup($line)) {
775 dbg("PCPROT: dup PC19 detected") if isdbg('chanerr');
781 my $parent = Route::Node::get($self->{call});
783 dbg("DXPROT: my parent $self->{call} has disappeared");
789 for ($i = 1; $i < $#field-1; $i += 4) {
790 my $here = $field[$i];
791 my $call = uc $field[$i+1];
792 my $conf = $field[$i+2];
793 my $ver = $field[$i+3];
794 next unless defined $here && defined $conf && is_callsign($call);
796 eph_del_regex("^PC(?:21\\^$call|17\\^[^\\^]+\\^$call)");
798 # check for sane parameters
799 # $ver = 5000 if $ver eq '0000';
800 next if $ver < 5000; # only works with version 5 software
801 next if length $call < 3; # min 3 letter callsigns
802 next if $call eq $main::mycall;
804 # check that this PC19 isn't trying to alter the wrong dxchan
805 my $dxchan = DXChannel->get($call);
806 if ($dxchan && $dxchan != $self) {
807 dbg("PCPROT: PC19 from $self->{call} trying to alter wrong locally connected $call, ignored!") if isdbg('chanerr');
811 # update it if required
812 my $r = Route::Node::get($call);
813 my $flags = Route::here($here)|Route::conf($conf);
816 if ($call ne $parent->call) {
817 if ($self->in_filter_route($r)) {
818 $ar = $parent->add($call, $ver, $flags);
819 push @rout, $ar if $ar;
824 if ($r->version ne $ver || $r->flags != $flags) {
827 push @rout, $r unless $ar;
830 if ($call eq $self->{call}) {
831 dbg("DXPROT: my channel route for $call has disappeared");
835 my $new = Route->new($call); # throw away
836 if ($self->in_filter_route($new)) {
837 my $r = $parent->add($call, $ver, $flags);
844 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
845 my $mref = DXMsg::get_busy($call);
846 $mref->stop_msg($call) if $mref;
848 # add this station to the user database, if required (don't remove SSID from nodes)
849 my $user = DXUser->get_current($call);
851 $user = DXUser->new($call);
853 $user->priv(1); # I have relented and defaulted nodes
855 $user->homenode($call);
858 $user->lastin($main::systime) unless DXChannel->get($call);
863 $self->route_pc19(@rout) if @rout;
867 if ($pcno == 20) { # send local configuration
868 $self->send_local_config();
870 $self->state('normal');
871 $self->{lastping} = 0;
875 if ($pcno == 21) { # delete a cluster from the list
876 my $call = uc $field[1];
878 eph_del_regex("^PC1[79].*$call");
880 # if I get a PC21 from the same callsign as self then treat it
881 # as a PC39: I have gone away
882 if ($call eq $self->call) {
883 $self->disconnect(1);
888 my $parent = Route::Node::get($self->{call});
890 dbg("DXPROT: my parent $self->{call} has disappeared");
894 if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
895 my $node = Route::Node::get($call);
898 my $dxchan = DXChannel->get($call);
899 if ($dxchan && $dxchan != $self) {
900 dbg("PCPROT: PC21 from $self->{call} trying to alter locally connected $call, ignored!") if isdbg('chanerr');
905 return unless $self->in_filter_route($node);
908 push @rout, $node->del($parent);
911 dbg("PCPROT: I WILL _NOT_ be disconnected!") if isdbg('chanerr');
915 # if (eph_dup($line)) {
916 # dbg("PCPROT: dup PC21 detected") if isdbg('chanerr');
920 $self->route_pc21(@rout) if @rout;
925 $self->state('normal');
926 $self->{lastping} = 0;
930 if ($pcno == 23 || $pcno == 27) { # WWV info
932 # route 'foreign' pc27s
934 if ($field[8] ne $main::mycall) {
935 $self->route($field[8], $line);
940 return if $rspfcheck and !$self->rspfcheck(1, $field[8], $field[7]);
943 my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
944 my $sfi = unpad($field[3]);
945 my $k = unpad($field[4]);
946 my $i = unpad($field[5]);
947 my ($r) = $field[6] =~ /R=(\d+)/;
949 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
950 dbg("PCPROT: WWV Date ($field[1] $field[2]) out of range") if isdbg('chanerr');
953 if (Geomag::dup($d,$sfi,$k,$i,$field[6])) {
954 dbg("PCPROT: Dup WWV Spot ignored\n") if isdbg('chanerr');
957 $field[7] =~ s/-\d+$//o; # remove spotter's ssid
959 my $wwv = Geomag::update($d, $field[2], $sfi, $k, $i, @field[6..8], $r);
963 $rep = Local::wwv($self, $field[1], $field[2], $sfi, $k, $i, @field[6..8], $r);
965 # dbg("Local::wwv2 error $@") if isdbg('local') if $@;
968 # DON'T be silly and send on PC27s!
969 return if $pcno == 27;
971 # broadcast to the eager world
972 send_wwv_spot($self, $line, $d, $field[2], $sfi, $k, $i, @field[6..8]);
976 if ($pcno == 24) { # set here status
977 my $call = uc $field[1];
979 $nref = Route::Node::get($call);
980 $uref = Route::User::get($call);
981 return unless $nref || $uref; # if we don't know where they are, it's pointless sending it on
983 unless (eph_dup($line)) {
984 $nref->here($field[2]) if $nref;
985 $uref->here($field[2]) if $uref;
986 my $ref = $nref || $uref;
987 return unless $self->in_filter_route($ref);
988 $self->route_pc24($ref, $field[3]);
993 if ($pcno == 25) { # merge request
994 if ($field[1] ne $main::mycall) {
995 $self->route($field[1], $line);
998 if ($field[2] eq $main::mycall) {
999 dbg("PCPROT: Trying to merge to myself, ignored") if isdbg('chanerr');
1003 Log('DXProt', "Merge request for $field[3] spots and $field[4] WWV from $field[2]");
1006 if ($field[3] > 0) {
1007 my @in = reverse Spot::search(1, undef, undef, 0, $field[3]);
1010 $self->send(pc26(@{$in}[0..4], $field[2]));
1015 if ($field[4] > 0) {
1016 my @in = reverse Geomag::search(0, $field[4], time, 1);
1019 $self->send(pc27(@{$in}[0..5], $field[2]));
1025 if (($pcno >= 28 && $pcno <= 33) || $pcno == 40 || $pcno == 42 || $pcno == 49) { # mail/file handling
1026 return if $pcno == 49 && eph_dup($line);
1027 if ($pcno == 49 || $field[1] eq $main::mycall) {
1028 DXMsg::process($self, $line);
1030 $self->route($field[1], $line) unless $self->is_clx;
1035 if ($pcno == 34 || $pcno == 36) { # remote commands (incoming)
1036 if (eph_dup($line, $eph_pc34_restime)) {
1037 dbg("PCPROT: dupe") if isdbg('chanerr');
1039 $self->process_rcmd($field[1], $field[2], $field[2], $field[3]);
1044 if ($pcno == 35) { # remote command replies
1045 eph_del_regex("^PC35\\^$field[2]\\^$field[1]\\^");
1046 $self->process_rcmd_reply($field[1], $field[2], $field[1], $field[3]);
1050 # for pc 37 see 44 onwards
1052 if ($pcno == 38) { # node connected list from neighbour
1056 if ($pcno == 39) { # incoming disconnect
1057 if ($field[1] eq $self->{call}) {
1058 $self->disconnect(1);
1060 dbg("PCPROT: came in on wrong channel") if isdbg('chanerr');
1065 if ($pcno == 41) { # user info
1066 my $call = $field[1];
1068 if (eph_dup($line, $eph_info_restime)) {
1069 dbg("PCPROT: dupe") if isdbg('chanerr');
1073 # input filter if required
1074 # my $ref = Route::get($call) || Route->new($call);
1075 # return unless $self->in_filter_route($ref);
1077 if ($field[3] eq $field[2] || $field[3] =~ /^\s*$/) {
1078 dbg('PCPROT: invalid value') if isdbg('chanerr');
1082 # add this station to the user database, if required
1083 my $user = DXUser->get_current($call);
1084 $user = DXUser->new($call) if !$user;
1086 if ($field[2] == 1) {
1087 $user->name($field[3]);
1088 } elsif ($field[2] == 2) {
1089 $user->qth($field[3]);
1090 } elsif ($field[2] == 3) {
1091 if (is_latlong($field[3])) {
1092 my ($lat, $long) = DXBearing::stoll($field[3]);
1095 $user->qra(DXBearing::lltoqra($lat, $long));
1097 dbg('PCPROT: not a valid lat/long') if isdbg('chanerr');
1100 } elsif ($field[2] == 4) {
1101 $user->homenode($field[3]);
1102 } elsif ($field[2] == 5) {
1103 if (is_qra(uc $field[3])) {
1104 my ($lat, $long) = DXBearing::qratoll(uc $field[3]);
1107 $user->qra(uc $field[3]);
1109 dbg('PCPROT: not a valid QRA locator') if isdbg('chanerr');
1113 $user->lastoper($main::systime); # to cut down on excessive for/opers being generated
1116 unless ($self->{isolate}) {
1117 DXChannel::broadcast_nodes($line, $self); # send it to everyone but me
1120 # perhaps this IS what we want after all
1121 # $self->route_pc41($ref, $call, $field[2], $field[3], $field[4]);
1129 if ($pcno == 37 || $pcno == 44 || $pcno == 45 || $pcno == 46 || $pcno == 47 || $pcno == 48) {
1130 DXDb::process($self, $line);
1134 if ($pcno == 50) { # keep alive/user list
1135 my $call = $field[1];
1136 my $node = Route::Node::get($call);
1138 return unless $node->call eq $self->{call};
1139 $node->usercount($field[2]);
1141 # input filter if required
1142 return unless $self->in_filter_route($node);
1144 $self->route_pc50($node, $field[2], $field[3]) unless eph_dup($line);
1149 if ($pcno == 51) { # incoming ping requests/answers
1151 my $from = $field[2];
1152 my $flag = $field[3];
1156 if ($to eq $main::mycall) {
1158 $self->send(pc51($from, $to, '0'));
1160 # it's a reply, look in the ping list for this one
1161 my $ref = $pings{$from};
1163 my $tochan = DXChannel->get($from);
1165 my $r = shift @$ref;
1166 my $dxchan = DXChannel->get($r->{call});
1167 next unless $dxchan;
1168 my $t = tv_interval($r->{t}, [ gettimeofday ]);
1169 if ($dxchan->is_user) {
1170 my $s = sprintf "%.2f", $t;
1171 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
1172 $dxchan->send($dxchan->msg('pingi', $from, $s, $ave))
1173 } elsif ($dxchan->is_node) {
1175 my $nopings = $tochan->user->nopings || 2;
1176 push @{$tochan->{pingtime}}, $t;
1177 shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
1179 # cope with a missed ping, this means you must set the pingint large enough
1180 if ($t > $tochan->{pingint} && $t < 2 * $tochan->{pingint} ) {
1181 $t -= $tochan->{pingint};
1184 # calc smoothed RTT a la TCP
1185 if (@{$tochan->{pingtime}} == 1) {
1186 $tochan->{pingave} = $t;
1188 $tochan->{pingave} = $tochan->{pingave} + (($t - $tochan->{pingave}) / 6);
1190 $tochan->{nopings} = $nopings; # pump up the timer
1197 if (eph_dup($line)) {
1198 dbg("PCPROT: dup PC51 detected") if isdbg('chanerr');
1201 # route down an appropriate thingy
1202 $self->route($to, $line);
1207 if ($pcno == 75) { # dunno but route it
1208 my $call = $field[1];
1209 if ($call ne $main::mycall) {
1210 $self->route($call, $line);
1215 if ($pcno == 73) { # WCY broadcasts
1216 my $call = $field[1];
1219 my $d = cltounix($call, sprintf("%02d18Z", $field[2]));
1220 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
1221 dbg("PCPROT: WCY Date ($call $field[2]) out of range") if isdbg('chanerr');
1224 @field = map { unpad($_) } @field;
1226 dbg("PCPROT: Dup WCY Spot ignored\n") if isdbg('chanerr');
1230 my $wcy = WCY::update($d, @field[2..12]);
1234 $rep = Local::wcy($self, @field[1..12]);
1236 # dbg("Local::wcy error $@") if isdbg('local') if $@;
1239 # broadcast to the eager world
1240 send_wcy_spot($self, $line, $d, @field[2..12]);
1244 if ($pcno == 84) { # remote commands (incoming)
1245 $self->process_rcmd($field[1], $field[2], $field[3], $field[4]);
1249 if ($pcno == 85) { # remote command replies
1250 $self->process_rcmd_reply($field[1], $field[2], $field[3], $field[4]);
1254 if ($pcno == 90) { # new style PC16,17,19,21
1255 my $node = $field[1];
1257 # mark this node as wanting PC90s
1258 my $parent = Route::Node::get($node);
1260 my $t = hex $field[2];
1261 my $last = $parent->lastpc90 || 0;
1264 $parent->lastpc90($t);
1265 my ($updsort, $n) = unpack "AA*", $field[3];
1266 for (my $i = 4; $i < $#field; $i++) {
1267 my ($sort, $flag, $node, $ping) = $field[$i] =~ m{(\w)(\d)([-\w+])(,\d+)?};
1268 $ping /= 10 if (defined $ping);
1277 # if get here then rebroadcast the thing with its Hop count decremented (if
1278 # there is one). If it has a hop count and it decrements to zero then don't
1281 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
1285 if (eph_dup($line)) {
1286 dbg("PCPROT: Ephemeral dup, dropped") if isdbg('chanerr');
1288 unless ($self->{isolate}) {
1289 DXChannel::broadcast_nodes($line, $self); # send it to everyone but me
1295 # This is called from inside the main cluster processing loop and is used
1296 # for despatching commands that are doing some long processing job
1301 my @dxchan = DXChannel->get_all();
1305 # send out a pc50 on EVERY channel all at once
1306 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
1307 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
1312 foreach $dxchan (@dxchan) {
1313 next unless $dxchan->is_node();
1314 next if $dxchan == $main::me;
1316 # send the pc50 or PC90
1317 if ($pc50s && $dxchan->user->wantpc90) {
1318 $dxchan->send_route(\&pc90, 1, $main::me, 'T', @dxchan);
1320 $dxchan->send($pc50s) if $pc50s;
1323 # send a ping out on this channel
1324 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
1325 if ($dxchan->{nopings} <= 0) {
1326 $dxchan->disconnect;
1328 addping($main::mycall, $dxchan->call);
1329 $dxchan->{nopings} -= 1;
1330 $dxchan->{lastping} = $t;
1336 if ($t - $last10 >= 10) {
1337 # clean out ephemera
1344 if ($main::systime - 3600 > $last_hour) {
1345 $last_hour = $main::systime;
1350 # finish up a pc context
1354 # some active measures
1362 my @dxchan = DXChannel->get_all();
1365 # send it if it isn't the except list and isn't isolated and still has a hop count
1366 # taking into account filtering and so on
1367 foreach $dxchan (@dxchan) {
1368 next if $dxchan == $main::me;
1369 next if $dxchan == $self && $self->is_node;
1370 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
1378 my $isolate = shift;
1379 my ($filter, $hops);
1381 if ($self->{spotsfilter}) {
1382 ($filter, $hops) = $self->{spotsfilter}->it(@_);
1383 return unless $filter;
1385 send_prot_line($self, $filter, $hops, $isolate, $line);
1390 my ($self, $filter, $hops, $isolate, $line) = @_;
1395 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1397 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1398 return unless $routeit;
1401 $self->send($routeit);
1403 $self->send($routeit) unless $self->{isolate} || $isolate;
1412 my @dxchan = DXChannel->get_all();
1414 my ($wwv_dxcc, $wwv_itu, $wwv_cq, $org_dxcc, $org_itu, $org_cq) = (0..0);
1415 my @dxcc = Prefix::extract($_[6]);
1417 $wwv_dxcc = $dxcc[1]->dxcc;
1418 $wwv_itu = $dxcc[1]->itu;
1419 $wwv_cq = $dxcc[1]->cq;
1421 @dxcc = Prefix::extract($_[7]);
1423 $org_dxcc = $dxcc[1]->dxcc;
1424 $org_itu = $dxcc[1]->itu;
1425 $org_cq = $dxcc[1]->cq;
1428 # send it if it isn't the except list and isn't isolated and still has a hop count
1429 # taking into account filtering and so on
1430 foreach $dxchan (@dxchan) {
1431 next if $dxchan == $main::me;
1432 next if $dxchan == $self && $self->is_node;
1434 my ($filter, $hops);
1436 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, $wwv_dxcc, $wwv_itu, $wwv_cq, $org_dxcc, $org_itu, $org_cq);
1445 my $isolate = shift;
1446 my ($filter, $hops);
1448 if ($self->{wwvfilter}) {
1449 ($filter, $hops) = $self->{wwvfilter}->it(@_);
1450 return unless $filter;
1452 send_prot_line($self, $filter, $hops, $isolate, $line)
1459 my @dxchan = DXChannel->get_all();
1461 my ($wcy_dxcc, $wcy_itu, $wcy_cq, $org_dxcc, $org_itu, $org_cq) = (0..0);
1462 my @dxcc = Prefix::extract($_[10]);
1464 $wcy_dxcc = $dxcc[1]->dxcc;
1465 $wcy_itu = $dxcc[1]->itu;
1466 $wcy_cq = $dxcc[1]->cq;
1468 @dxcc = Prefix::extract($_[11]);
1470 $org_dxcc = $dxcc[1]->dxcc;
1471 $org_itu = $dxcc[1]->itu;
1472 $org_cq = $dxcc[1]->cq;
1475 # send it if it isn't the except list and isn't isolated and still has a hop count
1476 # taking into account filtering and so on
1477 foreach $dxchan (@dxchan) {
1478 next if $dxchan == $main::me;
1479 next if $dxchan == $self;
1481 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, $wcy_dxcc, $wcy_itu, $wcy_cq, $org_dxcc, $org_itu, $org_cq);
1489 my $isolate = shift;
1490 my ($filter, $hops);
1492 if ($self->{wcyfilter}) {
1493 ($filter, $hops) = $self->{wcyfilter}->it(@_);
1494 return unless $filter;
1496 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
1504 my @dxchan = DXChannel->get_all();
1508 my $text = unpad($_[2]);
1510 if ($_[3] eq '*') { # sysops
1512 } elsif ($_[3] gt ' ') { # speciality list handling
1513 my ($name) = split /\./, $_[3];
1514 $target = "$name"; # put the rest in later (if bothered)
1521 $target = "ALL" if !$target;
1524 # obtain country codes etc
1525 my ($ann_dxcc, $ann_itu, $ann_cq, $org_dxcc, $org_itu, $org_cq) = (0..0);
1526 my @dxcc = Prefix::extract($_[0]);
1528 $ann_dxcc = $dxcc[1]->dxcc;
1529 $ann_itu = $dxcc[1]->itu;
1530 $ann_cq = $dxcc[1]->cq;
1532 @dxcc = Prefix::extract($_[4]);
1534 $org_dxcc = $dxcc[1]->dxcc;
1535 $org_itu = $dxcc[1]->itu;
1536 $org_cq = $dxcc[1]->cq;
1539 if ($self->{inannfilter}) {
1540 my ($filter, $hops) =
1541 $self->{inannfilter}->it(@_, $self->{call},
1542 $ann_dxcc, $ann_itu, $ann_cq,
1543 $org_dxcc, $org_itu, $org_cq);
1545 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1550 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
1551 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1555 Log('ann', $target, $_[0], $text);
1557 # send it if it isn't the except list and isn't isolated and still has a hop count
1558 # taking into account filtering and so on
1559 foreach $dxchan (@dxchan) {
1560 next if $dxchan == $main::me;
1561 next if $dxchan == $self && $self->is_node;
1562 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call}, $ann_dxcc, $ann_itu, $ann_cq, $org_dxcc, $org_itu, $org_cq);
1570 my $isolate = shift;
1574 my ($filter, $hops);
1576 if ($self->{annfilter}) {
1577 ($filter, $hops) = $self->{annfilter}->it(@_);
1578 return unless $filter;
1580 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
1584 sub send_local_config
1592 dbg('DXProt::send_local_config') if isdbg('trace');
1595 if ($self->{isolate}) {
1596 @localnodes = ( $main::routeroot );
1598 # create a list of all the nodes that are not connected to this connection
1599 # and are not themselves isolated, this to make sure that isolated nodes
1600 # don't appear outside of this node
1601 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
1602 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
1603 my @intcalls = map { $_->nodes } @localnodes if @localnodes;
1604 my $ref = Route::Node::get($self->{call});
1605 my @rnodes = $ref->nodes;
1606 for my $n (@intcalls) {
1607 push @remotenodes, Route::Node::get($n) unless grep $n eq $_, @rnodes;
1609 unshift @localnodes, $main::routeroot;
1613 send_route($self, \&pc19, scalar(@localnodes)+scalar(@remotenodes), @localnodes, @remotenodes);
1615 # get all the users connected on the above nodes and send them out
1616 foreach $n (@localnodes, @remotenodes) {
1618 send_route($self, \&pc16, 1, $n, map {my $r = Route::User::get($_); $r ? ($r) : ()} $n->users);
1620 dbg("sent a null value") if isdbg('chanerr');
1623 $self->send_route(\&pc90, 1, $main::me, 'T', DXChannel::get_all()) if $self->user->wantpc90;
1627 # route a message down an appropriate interface for a callsign
1629 # is called route(to, pcline);
1633 my ($self, $call, $line) = @_;
1635 if (ref $self && $call eq $self->{call}) {
1636 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
1640 # always send it down the local interface if available
1641 my $dxchan = DXChannel->get($call);
1643 my $cl = Route::get($call);
1644 $dxchan = $cl->dxchan if $cl;
1646 if (ref $self && $dxchan eq $self) {
1647 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
1653 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1655 $dxchan->send($routeit) unless $dxchan == $main::me;
1658 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
1663 # obtain the hops from the list for this callsign and pc no
1669 my $hops = $DXProt::hopcount{$pcno};
1670 $hops = $DXProt::def_hopcount if !$hops;
1675 # adjust the hop count on a per node basis using the user loadable
1676 # hop table if available or else decrement an existing one
1683 my $call = $self->{call};
1686 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
1687 my ($pcno) = $s =~ /^PC(\d\d)/o;
1688 confess "$call called adjust_hops with '$s'" unless $pcno;
1689 my $ref = $nodehops{$call} if %nodehops;
1691 my $newhops = $ref->{$pcno};
1692 return "" if defined $newhops && $newhops == 0;
1693 $newhops = $ref->{default} unless $newhops;
1694 return "" if defined $newhops && $newhops == 0;
1695 $newhops = $hops if !$newhops;
1696 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1698 # simply decrement it
1700 return "" if !$hops;
1701 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
1713 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
1714 do "$main::data/hop_table.pl";
1720 # add a ping request to the ping queues
1723 my ($from, $to) = @_;
1724 my $ref = $pings{$to} || [];
1727 $r->{t} = [ gettimeofday ];
1728 route(undef, $to, pc51($to, $main::mycall, 1));
1735 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
1736 if ($tonode eq $main::mycall) {
1737 my $ref = DXUser->get_current($fromnode);
1738 my $cref = Route::Node::get($fromnode);
1739 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
1740 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
1741 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
1742 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
1743 my $oldpriv = $self->{priv};
1744 $self->{priv} = $ref->{priv}; # assume the user's privilege level
1745 my @in = (DXCommandmode::run_cmd($self, $cmd));
1746 $self->{priv} = $oldpriv;
1747 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
1748 delete $self->{remotecmd};
1750 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
1753 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
1756 my $ref = DXUser->get_current($tonode);
1757 if ($ref && $ref->is_clx) {
1758 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
1760 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
1765 sub process_rcmd_reply
1767 my ($self, $tonode, $fromnode, $user, $line) = @_;
1768 if ($tonode eq $main::mycall) {
1769 my $s = $rcmds{$fromnode};
1771 my $dxchan = DXChannel->get($s->{call});
1772 my $ref = $user eq $tonode ? $dxchan : (DXChannel->get($user) || $dxchan);
1773 $ref->send($line) if $ref;
1774 delete $rcmds{$fromnode} if !$dxchan;
1776 # send unsolicited ones to the sysop
1777 my $dxchan = DXChannel->get($main::myalias);
1778 $dxchan->send($line) if $dxchan;
1781 my $ref = DXUser->get_current($tonode);
1782 if ($ref && $ref->is_clx) {
1783 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
1785 $self->route($tonode, pc35($fromnode, $tonode, $line));
1794 my $fromnode = shift;
1799 Log('rcmd', 'out', $fromnode, $line);
1800 if ($self->is_clx) {
1801 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
1803 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
1808 # add a rcmd request to the rcmd queues
1811 my ($self, $to, $cmd) = @_;
1814 $r->{call} = $self->{call};
1815 $r->{t} = $main::systime;
1819 my $ref = Route::Node::get($to);
1820 my $dxchan = $ref->dxchan;
1821 if ($dxchan && $dxchan->is_clx) {
1822 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1824 route(undef, $to, pc34($main::mycall, $to, $cmd));
1831 my $pc39flag = shift;
1832 my $call = $self->call;
1834 return if $self->{disconnecting}++;
1836 unless ($pc39flag && $pc39flag == 1) {
1837 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1840 # get rid of any PC16 and 19s
1841 eph_del_regex("^PC16\\^$call");
1842 eph_del_regex("^PC19\\^.*$call");
1845 my $node = Route::Node::get($call);
1848 @rout = $node->del($main::routeroot);
1851 # unbusy and stop and outgoing mail
1852 my $mref = DXMsg::get_busy($call);
1853 $mref->stop_msg($call) if $mref;
1855 # broadcast to all other nodes that all the nodes connected to via me are gone
1856 unless ($pc39flag && $pc39flag == 2) {
1857 $self->route_pc21(@rout) if @rout;
1860 # remove outstanding pings
1861 delete $pings{$call};
1863 # I was the last node visited
1864 $self->user->node($main::mycall);
1866 # send info to all logged in thingies
1867 $self->tell_login('logoutn');
1869 Log('DXProt', $call . " Disconnected");
1871 $self->SUPER::disconnect;
1876 # send a talk message to this thingy
1880 my ($self, $from, $to, $via, $line, $origin) = @_;
1882 $line =~ s/\^/\\5E/g; # remove any ^ characters
1883 $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
1884 Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
1887 # send it if it isn't the except list and isn't isolated and still has a hop count
1888 # taking into account filtering and so on
1892 my $generate = shift;
1893 my $no = shift; # the no of things to filter on
1895 my ($filter, $hops);
1898 for (; @_ && $no; $no--) {
1901 if (!$self->{isolate} && $self->{routefilter}) {
1904 ($filter, $hops) = $self->{routefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq);
1908 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
1911 dbg("was sent a null value") if isdbg('chanerr');
1914 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
1918 foreach my $line (&$generate(@rin, @_)) {
1921 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1923 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1924 next unless $routeit;
1926 $self->send($routeit);
1934 my $generate = shift;
1935 my @dxchan = DXChannel::get_all_nodes();
1939 unless ($self->{isolate}) {
1940 foreach $dxchan (@dxchan) {
1941 next if $dxchan == $self;
1942 next if $dxchan == $main::me;
1943 $dxchan->send_route($generate, @_);
1951 broadcast_route($self, \&pc16, 1, @_);
1957 broadcast_route($self, \&pc17, 1, @_);
1963 broadcast_route($self, \&pc19, scalar @_, @_);
1969 broadcast_route($self, \&pc21, scalar @_, @_);
1975 broadcast_route($self, \&pc24, 1, @_);
1981 broadcast_route($self, \&pc41, 1, @_);
1987 broadcast_route($self, \&pc50, 1, @_);
1993 broadcast_route($self, \&pc90, 1, @_);
2000 my ($filter, $hops) = (1, 1);
2002 if ($self->{inroutefilter}) {
2003 ($filter, $hops) = $self->{inroutefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq);
2004 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
2012 my $t = shift || $eph_restime;
2016 $s =~ s/\^H\d\d?\^?\~?$//;
2017 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
2018 $eph{$s} = $main::systime + $t;
2026 while (($key, $val) = each %eph) {
2027 if ($key =~ m{$regex}) {
2037 while (($key, $val) = each %eph) {
2038 if ($main::systime >= $val) {
2049 while (($key, $val) = each %eph) {
2050 push @out, $key, $val;
2057 goto &DXCommandmode::run_cmd;