2 # This module is the PC Protocol Thingy Handler
3 # It will route transforming them on the way as required.
5 # Copyright (c) 2001 Dirk Koopman G1TLH
14 use vars qw($VERSION $BRANCH);
15 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
16 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
17 $main::build += $VERSION;
18 $main::branch += $BRANCH;
25 # incoming talk commands
32 return if $rspfcheck and !$self->rspfcheck(0, $_[6], $_[1]);
34 # will we allow it at all?
37 if (@bad = BadWords::check($_[3])) {
38 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
43 # is it for me or one of mine?
44 my ($from, $to, $via, $call, $dxchan);
53 # if this is a 'nodx' node then ignore it
54 if ($badnode->in($_[6]) || ($via && $badnode->in($via))) {
55 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
59 # if this is a 'bad spotter' user then ignore it
62 if ($badspotter->in($nossid)) {
63 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
67 # if we are converting announces to talk is it a dup?
69 if (AnnTalk::is_talk_candidate($from, $_[3]) && AnnTalk::dup($from, $to, $_[3])) {
70 dbg("DXPROT: Dupe talk from announce, dropped") if isdbg('chanerr');
75 # it is here and logged on
76 $dxchan = DXChannel->get($main::myalias) if $to eq $main::mycall;
77 $dxchan = DXChannel->get($to) unless $dxchan;
78 if ($dxchan && $dxchan->is_user) {
80 $dxchan->talk($from, $to, $via, $_[3]);
84 # is it elsewhere, visible on the cluster via the to address?
85 # note: this discards the via unless the to address is on
88 if ($ref = Route::get($to)) {
89 $vref = Route::Node::get($via) if $via;
90 $vref = undef unless $vref && grep $to eq $_, $vref->users;
91 $ref->dxchan->talk($from, $to, $vref ? $via : undef, $_[3], $_[6]);
95 # not visible here, send a message of condolence
97 $ref = Route::get($from);
98 $vref = $ref = Route::Node::get($_[6]) unless $ref;
100 $dxchan = $ref->dxchan;
101 $dxchan->talk($main::mycall, $from, $vref ? $vref->call : undef, $dxchan->msg('talknh', $to) );
106 package Thingy::PC11;
115 # route 'foreign' pc26s
117 if ($_[7] ne $main::mycall) {
118 $self->route($_[7], $line);
124 # return if $rspfcheck and !$self->rspfcheck(1, $_[7], $_[6]);
126 # if this is a 'nodx' node then ignore it
127 if ($badnode->in($_[7])) {
128 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
132 # if this is a 'bad spotter' user then ignore it
134 $nossid =~ s/-\d+$//;
135 if ($badspotter->in($nossid)) {
136 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
140 # convert the date to a unix date
141 my $d = cltounix($_[3], $_[4]);
142 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
143 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
144 dbg("PCPROT: Spot ignored, invalid date or out of range ($_[3] $_[4])\n") if isdbg('chanerr');
149 if ($baddx->in($_[2]) || BadWords::check($_[2]) || $_[2] =~ /COCK/) {
150 dbg("PCPROT: Bad DX spot, ignored") if isdbg('chanerr');
155 $_[5] =~ s/^\s+//; # take any leading blanks off
156 $_[2] = unpad($_[2]); # take off leading and trailing blanks from spotted callsign
157 if ($_[2] =~ /BUST\w*$/) {
158 dbg("PCPROT: useless 'BUSTED' spot") if isdbg('chanerr');
163 if (@bad = BadWords::check($_[5])) {
164 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
170 my @spot = Spot::prepare($_[1], $_[2], $d, $_[5], $_[6], $_[7]);
171 # global spot filtering on INPUT
172 if ($self->{inspotsfilter}) {
173 my ($filter, $hops) = $self->{inspotsfilter}->it(@spot);
175 dbg("PCPROT: Rejected by input spot filter") if isdbg('chanerr');
180 # this goes after the input filtering, but before the add
181 # so that if it is input filtered, it isn't added to the dup
182 # list. This allows it to come in from a "legitimate" source
183 if (Spot::dup($_[1], $_[2], $d, $_[5], $_[6])) {
184 dbg("PCPROT: Duplicate Spot ignored\n") if isdbg('chanerr');
192 # @spot at this point contains:-
193 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
194 # then spotted itu, spotted cq, spotters itu, spotters cq
195 # you should be able to route on any of these
198 # fix up qra locators of known users
199 my $user = DXUser->get_current($spot[4]);
201 my $qra = $user->qra;
202 unless ($qra && is_qra($qra)) {
203 my $lat = $user->lat;
204 my $long = $user->long;
205 if (defined $lat && defined $long) {
206 $user->qra(DXBearing::lltoqra($lat, $long));
211 # send a remote command to a distant cluster if it is visible and there is no
212 # qra locator and we havn't done it for a month.
214 unless ($user->qra) {
216 my $to = $user->homenode;
217 my $last = $user->lastoper || 0;
218 if ($send_opernam && $to && $to ne $main::mycall && $main::systime > $last + $DXUser::lastoperinterval && ($node = Route::Node::get($to)) ) {
219 my $cmd = "forward/opernam $spot[4]";
220 # send the rcmd but we aren't interested in the replies...
221 my $dxchan = $node->dxchan;
222 if ($dxchan && $dxchan->is_clx) {
223 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
225 route(undef, $to, pc34($main::mycall, $to, $cmd));
229 $node = Route::Node::get($to);
231 $dxchan = $node->dxchan;
232 if ($dxchan && $dxchan->is_clx) {
233 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
235 route(undef, $to, pc34($main::mycall, $to, $cmd));
239 $user->lastoper($main::systime);
248 $r = Local::spot($self, @spot);
250 # dbg("Local::spot1 error $@") if isdbg('local') if $@;
253 # DON'T be silly and send on PC26s!
254 return if $pcno == 26;
256 # send out the filtered spots
257 send_dx_spot($self, $line, @spot) if @spot;
261 package Thingy::PC12;
270 # return if $rspfcheck and !$self->rspfcheck(1, $_[5], $_[1]);
272 # announce duplicate checking
273 $_[3] =~ s/^\s+//; # remove leading blanks
277 if (@bad = BadWords::check($_[3])) {
278 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
283 # if this is a 'nodx' node then ignore it
284 if ($badnode->in($_[5])) {
285 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
289 # if this is a 'bad spotter' user then ignore it
291 $nossid =~ s/-\d+$//;
292 if ($badspotter->in($nossid)) {
293 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
297 if ($_[2] eq '*' || $_[2] eq $main::mycall) {
300 # here's a bit of fun, convert incoming ann with a callsign in the first word
301 # or one saying 'to <call>' to a talk if we can route to the recipient
303 my $call = AnnTalk::is_talk_candidate($_[1], $_[3]);
305 my $ref = Route::get($call);
307 my $dxchan = $ref->dxchan;
308 $dxchan->talk($_[1], $call, undef, $_[3], $_[5]) if $dxchan != $self;
315 $self->send_announce($line, @_[1..6]);
317 $self->route($_[2], $line);
322 package Thingy::PC16;
332 if (eph_dup($line)) {
333 dbg("PCPROT: dup PC16 detected") if isdbg('chanerr');
340 my $newline = "PC16^";
342 # do I want users from this channel?
343 unless ($self->user->wantpc16) {
344 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
348 if ($ncall eq $main::mycall) {
349 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
352 my $parent = Route::Node::get($ncall);
354 # if there is a parent, proceed, otherwise if there is a latent PC19 in the PC19list,
355 # fix it up in the routing tables and issue it forth before the PC16
357 my $nl = $pc19list{$ncall};
359 if ($nl && @_ > 3) { # 3 because of the hop count!
361 # this is a new (remembered) node, now attach it to me if it isn't in filtered
362 # and we haven't disallowed it
363 my $user = DXUser->get_current($ncall);
365 $user = DXUser->new($ncall);
367 $user->priv(1); # I have relented and defaulted nodes
369 $user->homenode($ncall);
373 my $wantpc19 = $user->wantroutepc19;
374 if ($wantpc19 || !defined $wantpc19) {
375 my $new = Route->new($ncall); # throw away
376 if ($self->in_filter_route($new)) {
379 $parent = Route::Node::get($_->[0]);
380 $dxchan = $parent->dxchan if $parent;
381 if ($dxchan && $dxchan ne $self) {
382 dbg("PCPROT: PC19 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
386 my $r = $parent->add($ncall, $_->[1], $_->[2]);
387 push @nrout, $r unless @nrout;
390 $user->wantroutepc19(1) unless defined $wantpc19; # for now we work on the basis that pc16 = real route
391 $user->lastin($main::systime) unless DXChannel->get($ncall);
394 # route the pc19 - this will cause 'stuttering PC19s' for a while
395 $self->route_pc19(@nrout) if @nrout ;
396 $parent = Route::Node::get($ncall);
398 dbg("PCPROT: lost $ncall after sending PC19 for it?");
404 delete $pc19list{$ncall};
407 dbg("PCPROT: Node $ncall not in config") if isdbg('chanerr');
412 $dxchan = $parent->dxchan;
413 if ($dxchan && $dxchan ne $self) {
414 dbg("PCPROT: PC16 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
418 # input filter if required
419 return unless $self->in_filter_route($parent);
424 for ($i = 2; $i < $#_; $i++) {
425 my ($call, $conf, $here) = $_[$i] =~ /^(\S+) (\S) (\d)/o;
426 next unless $call && $conf && defined $here && is_callsign($call);
427 next if $call eq $main::mycall;
429 eph_del_regex("^PC17\\^$call\\^$ncall");
431 $conf = $conf eq '*';
433 # reject this if we think it is a node already
434 my $r = Route::Node::get($call);
435 my $u = DXUser->get_current($call) unless $r;
436 if ($r || ($u && $u->is_node)) {
437 dbg("PCPROT: $call is a node") if isdbg('chanerr');
441 $r = Route::User::get($call);
442 my $flags = Route::here($here)|Route::conf($conf);
445 my $au = $r->addparent($parent);
446 if ($r->flags != $flags) {
450 push @rout, $r if $au;
452 push @rout, $parent->add_user($call, $flags);
456 # add this station to the user database, if required
457 $call =~ s/-\d+$//o; # remove ssid for users
458 my $user = DXUser->get_current($call);
459 $user = DXUser->new($call) if !$user;
460 $user->homenode($parent->call) if !$user->homenode;
461 $user->node($parent->call);
462 $user->lastin($main::systime) unless DXChannel->get($call);
466 $self->route_pc16($parent, @rout) if @rout;
470 package Thingy::PC17;
481 eph_del_regex("^PC16\\^$ncall.*$ucall");
483 # do I want users from this channel?
484 unless ($self->user->wantpc16) {
485 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
488 if ($ncall eq $main::mycall) {
489 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
493 my $uref = Route::User::get($ucall);
495 dbg("PCPROT: Route::User $ucall not in config") if isdbg('chanerr');
498 my $parent = Route::Node::get($ncall);
500 dbg("PCPROT: Route::Node $ncall not in config") if isdbg('chanerr');
504 $dxchan = $parent->dxchan;
505 if ($dxchan && $dxchan ne $self) {
506 dbg("PCPROT: PC17 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
510 # input filter if required
511 return unless $self->in_filter_route($parent);
513 $parent->del_user($uref);
515 if (eph_dup($line)) {
516 dbg("PCPROT: dup PC17 detected") if isdbg('chanerr');
520 $self->route_pc17($parent, $uref);
524 package Thingy::PC18;
532 $self->state('init');
534 # record the type and version offered
535 if ($_[1] =~ /DXSpider Version: (\d+\.\d+) Build: (\d+\.\d+)/) {
536 $self->version(53 + $1);
537 $self->user->version(53 + $1);
538 $self->build(0 + $2);
539 $self->user->build(0 + $2);
540 unless ($self->is_spider) {
541 $self->user->sort('S');
546 $self->version(50.0);
547 $self->version($_[2] / 100) if $_[2] && $_[2] =~ /^\d+$/;
548 $self->user->version($self->version);
551 # first clear out any nodes on this dxchannel
552 my $parent = Route::Node::get($self->{call});
553 my @rout = $parent->del_nodes;
554 $self->route_pc21(@rout, $parent) if @rout;
555 $self->send_local_config();
559 # incoming cluster list
560 package Thingy::PC19;
570 my $newline = "PC19^";
572 if (eph_dup($line)) {
573 dbg("PCPROT: dup PC19 detected") if isdbg('chanerr');
579 my $parent = Route::Node::get($self->{call});
581 dbg("DXPROT: my parent $self->{call} has disappeared");
587 for ($i = 1; $i < $#_-1; $i += 4) {
589 my $call = uc $_[$i+1];
592 next unless defined $here && defined $conf && is_callsign($call);
594 eph_del_regex("^PC(?:21\\^$call|17\\^[^\\^]+\\^$call)");
596 # check for sane parameters
597 # $ver = 5000 if $ver eq '0000';
598 next if $ver < 5000; # only works with version 5 software
599 next if length $call < 3; # min 3 letter callsigns
600 next if $call eq $main::mycall;
602 # check that this PC19 isn't trying to alter the wrong dxchan
603 my $dxchan = DXChannel->get($call);
604 if ($dxchan && $dxchan != $self) {
605 dbg("PCPROT: PC19 from $self->{call} trying to alter wrong locally connected $call, ignored!") if isdbg('chanerr');
609 # add this station to the user database, if required (don't remove SSID from nodes)
610 my $user = DXUser->get_current($call);
612 $user = DXUser->new($call);
614 $user->priv(1); # I have relented and defaulted nodes
616 $user->homenode($call);
620 my $r = Route::Node::get($call);
621 my $flags = Route::here($here)|Route::conf($conf);
623 # modify the routing table if it is in it, otherwise store it in the pc19list for now
626 if ($call ne $parent->call) {
627 if ($self->in_filter_route($r)) {
628 $ar = $parent->add($call, $ver, $flags);
629 push @rout, $ar if $ar;
634 if ($r->version ne $ver || $r->flags != $flags) {
637 push @rout, $r unless $ar;
641 # if he is directly connected or allowed then add him, otherwise store him up for later
642 if ($call eq $self->{call} || $user->wantroutepc19) {
643 my $new = Route->new($call); # throw away
644 if ($self->in_filter_route($new)) {
645 my $ar = $parent->add($call, $ver, $flags);
646 $user->wantroutepc19(1) unless defined $user->wantroutepc19;
647 push @rout, $ar if $ar;
652 $pc19list{$call} = [] unless exists $pc19list{$call};
653 my $nl = $pc19list{$call};
654 push @{$pc19list{$call}}, [$self->{call}, $ver, $flags] unless grep $_->[0] eq $self->{call}, @$nl;
658 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
659 my $mref = DXMsg::get_busy($call);
660 $mref->stop_msg($call) if $mref;
662 $user->lastin($main::systime) unless DXChannel->get($call);
667 $self->route_pc19(@rout) if @rout;
670 # send local configuration
671 package Thingy::PC20;
679 $self->send_local_config();
681 $self->state('normal');
682 $self->{lastping} = 0;
685 # delete a cluster from the list
686 package Thingy::PC21;
696 eph_del_regex("^PC1[679].*$call");
698 # if I get a PC21 from the same callsign as self then treat it
699 # as a PC39: I have gone away
700 if ($call eq $self->call) {
701 $self->disconnect(1);
705 # check to see if we are in the pc19list, if we are then don't bother with any of
706 # this routing table manipulation, just remove it from the list and dump it
708 if (my $nl = $pc19list{$call}) {
709 $pc19list{$call} = [ grep {$_->[0] ne $self->{call}} @$nl ];
710 delete $pc19list{$call} unless @{$pc19list{$call}};
713 my $parent = Route::Node::get($self->{call});
715 dbg("DXPROT: my parent $self->{call} has disappeared");
719 if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
720 my $node = Route::Node::get($call);
723 my $dxchan = DXChannel->get($call);
724 if ($dxchan && $dxchan != $self) {
725 dbg("PCPROT: PC21 from $self->{call} trying to alter locally connected $call, ignored!") if isdbg('chanerr');
730 return unless $self->in_filter_route($node);
733 push @rout, $node->del($parent);
736 dbg("PCPROT: I WILL _NOT_ be disconnected!") if isdbg('chanerr');
741 $self->route_pc21(@rout) if @rout;
745 package Thingy::PC22;
753 $self->state('normal');
754 $self->{lastping} = 0;
758 package Thingy::PC23;
767 # route 'foreign' pc27s
769 if ($_[8] ne $main::mycall) {
770 $self->route($_[8], $line);
775 return if $rspfcheck and !$self->rspfcheck(1, $_[8], $_[7]);
778 my $d = cltounix($_[1], sprintf("%02d18Z", $_[2]));
779 my $sfi = unpad($_[3]);
780 my $k = unpad($_[4]);
781 my $i = unpad($_[5]);
782 my ($r) = $_[6] =~ /R=(\d+)/;
784 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
785 dbg("PCPROT: WWV Date ($_[1] $_[2]) out of range") if isdbg('chanerr');
788 if (Geomag::dup($d,$sfi,$k,$i,$_[6])) {
789 dbg("PCPROT: Dup WWV Spot ignored\n") if isdbg('chanerr');
792 $_[7] =~ s/-\d+$//o; # remove spotter's ssid
794 my $wwv = Geomag::update($d, $_[2], $sfi, $k, $i, @_[6..8], $r);
798 $rep = Local::wwv($self, $_[1], $_[2], $sfi, $k, $i, @_[6..8], $r);
800 # dbg("Local::wwv2 error $@") if isdbg('local') if $@;
803 # DON'T be silly and send on PC27s!
804 return if $pcno == 27;
806 # broadcast to the eager world
807 send_wwv_spot($self, $line, $d, $_[2], $sfi, $k, $i, @_[6..8]);
811 package Thingy::PC24;
821 $nref = Route::Node::get($call);
822 $uref = Route::User::get($call);
823 return unless $nref || $uref; # if we don't know where they are, it's pointless sending it on
825 if (eph_dup($line)) {
826 dbg("PCPROT: Dup PC24 ignored\n") if isdbg('chanerr');
830 $nref->here($_[2]) if $nref;
831 $uref->here($_[2]) if $uref;
832 my $ref = $nref || $uref;
833 return unless $self->in_filter_route($ref);
835 $self->route_pc24($ref, $_[3]);
839 package Thingy::PC25;
847 if ($_[1] ne $main::mycall) {
848 $self->route($_[1], $line);
851 if ($_[2] eq $main::mycall) {
852 dbg("PCPROT: Trying to merge to myself, ignored") if isdbg('chanerr');
856 Log('DXProt', "Merge request for $_[3] spots and $_[4] WWV from $_[2]");
860 my @in = reverse Spot::search(1, undef, undef, 0, $_[3]);
863 $self->send_frame($main::me, pc26(@{$in}[0..4], $_[2]));
869 my @in = reverse Geomag::search(0, $_[4], time, 1);
872 $self->send_frame($main::me, pc27(@{$in}[0..5], $_[2]));
877 sub handle_26 {goto &handle_11}
878 sub handle_27 {goto &handle_23}
881 package Thingy::PC28;
889 if ($_[1] eq $main::mycall) {
891 my $sub = "DXMsg::handle_$pcno";
894 $self->route($_[1], $line) unless $self->is_clx;
898 sub handle_29 {goto &handle_28}
899 sub handle_30 {goto &handle_28}
900 sub handle_31 {goto &handle_28}
901 sub handle_32 {goto &handle_28}
902 sub handle_33 {goto &handle_28}
904 package Thingy::PC34;
912 if (eph_dup($line, $eph_pc34_restime)) {
913 dbg("PCPROT: dupe PC34, ignored") if isdbg('chanerr');
915 $self->process_rcmd($_[1], $_[2], $_[2], $_[3]);
919 # remote command replies
920 package Thingy::PC35;
928 eph_del_regex("^PC35\\^$_[2]\\^$_[1]\\^");
929 $self->process_rcmd_reply($_[1], $_[2], $_[1], $_[3]);
932 sub handle_36 {goto &handle_34}
935 package Thingy::PC37;
943 DXDb::process($self, $line);
946 # node connected list from neighbour
947 package Thingy::PC38;
957 # incoming disconnect
958 package Thingy::PC39;
966 if ($_[1] eq $self->{call}) {
967 $self->disconnect(1);
969 dbg("PCPROT: came in on wrong channel") if isdbg('chanerr');
973 sub handle_40 {goto &handle_28}
976 package Thingy::PC41;
987 $l =~ s/[\x00-\x20\x7f-\xff]+//g; # remove all funny characters and spaces for dup checking
988 if (eph_dup($l, $eph_info_restime)) {
989 dbg("PCPROT: dup PC41, ignored") if isdbg('chanerr');
993 # input filter if required
994 # my $ref = Route::get($call) || Route->new($call);
995 # return unless $self->in_filter_route($ref);
997 if ($_[3] eq $_[2] || $_[3] =~ /^\s*$/) {
998 dbg('PCPROT: invalid value') if isdbg('chanerr');
1002 # add this station to the user database, if required
1003 my $user = DXUser->get_current($call);
1004 $user = DXUser->new($call) unless $user;
1008 } elsif ($_[2] == 2) {
1010 } elsif ($_[2] == 3) {
1011 if (is_latlong($_[3])) {
1012 my ($lat, $long) = DXBearing::stoll($_[3]);
1015 $user->qra(DXBearing::lltoqra($lat, $long));
1017 dbg('PCPROT: not a valid lat/long') if isdbg('chanerr');
1020 } elsif ($_[2] == 4) {
1021 $user->homenode($_[3]);
1022 } elsif ($_[2] == 5) {
1023 if (is_qra(uc $_[3])) {
1024 my ($lat, $long) = DXBearing::qratoll(uc $_[3]);
1027 $user->qra(uc $_[3]);
1029 dbg('PCPROT: not a valid QRA locator') if isdbg('chanerr');
1033 $user->lastoper($main::systime); # to cut down on excessive for/opers being generated
1036 unless ($self->{isolate}) {
1037 DXChannel::broadcast_nodes($line, $self); # send it to everyone but me
1040 # perhaps this IS what we want after all
1041 # $self->route_pc41($ref, $call, $_[2], $_[3], $_[4]);
1044 sub handle_42 {goto &handle_28}
1048 sub handle_44 {goto &handle_37}
1049 sub handle_45 {goto &handle_37}
1050 sub handle_46 {goto &handle_37}
1051 sub handle_47 {goto &handle_37}
1052 sub handle_48 {goto &handle_37}
1054 # message and database
1055 package Thingy::PC49;
1064 if (eph_dup($line)) {
1065 dbg("PCPROT: Dup PC49 ignored\n") if isdbg('chanerr');
1069 if ($_[1] eq $main::mycall) {
1070 DXMsg::handle_49($self, @_);
1072 $self->route($_[1], $line) unless $self->is_clx;
1076 # keep alive/user list
1077 package Thingy::PC50;
1087 my $node = Route::Node::get($call);
1089 return unless $node->call eq $self->{call};
1090 $node->usercount($_[2]);
1092 # input filter if required
1093 return unless $self->in_filter_route($node);
1095 $self->route_pc50($node, $_[2], $_[3]) unless eph_dup($line);
1099 # incoming ping requests/answers
1100 package Thingy::PC51;
1114 if ($to eq $main::mycall) {
1116 $self->send_frame($main::me, pc51($from, $to, '0'));
1118 # it's a reply, look in the ping list for this one
1119 my $ref = $pings{$from};
1121 my $tochan = DXChannel->get($from);
1123 my $r = shift @$ref;
1124 my $dxchan = DXChannel->get($r->{call});
1125 next unless $dxchan;
1126 my $t = tv_interval($r->{t}, [ gettimeofday ]);
1127 if ($dxchan->is_user) {
1128 my $s = sprintf "%.2f", $t;
1129 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
1130 $dxchan->send($dxchan->msg('pingi', $from, $s, $ave))
1131 } elsif ($dxchan->is_node) {
1133 my $nopings = $tochan->user->nopings || 2;
1134 push @{$tochan->{pingtime}}, $t;
1135 shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
1137 # cope with a missed ping, this means you must set the pingint large enough
1138 if ($t > $tochan->{pingint} && $t < 2 * $tochan->{pingint} ) {
1139 $t -= $tochan->{pingint};
1142 # calc smoothed RTT a la TCP
1143 if (@{$tochan->{pingtime}} == 1) {
1144 $tochan->{pingave} = $t;
1146 $tochan->{pingave} = $tochan->{pingave} + (($t - $tochan->{pingave}) / 6);
1148 $tochan->{nopings} = $nopings; # pump up the timer
1155 if (eph_dup($line)) {
1156 dbg("PCPROT: dup PC51 detected") if isdbg('chanerr');
1159 # route down an appropriate thingy
1160 $self->route($to, $line);
1164 # dunno but route it
1165 package Thingy::PC75;
1174 if ($call ne $main::mycall) {
1175 $self->route($call, $line);
1180 package Thingy::PC73;
1191 my $d = cltounix($call, sprintf("%02d18Z", $_[2]));
1192 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1193 dbg("PCPROT: WCY Date ($call $_[2]) out of range") if isdbg('chanerr');
1196 @_ = map { unpad($_) } @_;
1198 dbg("PCPROT: Dup WCY Spot ignored\n") if isdbg('chanerr');
1202 my $wcy = WCY::update($d, @_[2..12]);
1206 $rep = Local::wcy($self, @_[1..12]);
1208 # dbg("Local::wcy error $@") if isdbg('local') if $@;
1211 # broadcast to the eager world
1212 send_wcy_spot($self, $line, $d, @_[2..12]);
1215 # remote commands (incoming)
1216 package Thingy::PC84;
1224 $self->process_rcmd($_[1], $_[2], $_[3], $_[4]);
1227 # remote command replies
1228 package Thingy::PC85;
1236 $self->process_rcmd_reply($_[1], $_[2], $_[3], $_[4]);
1239 # if get here then rebroadcast the thing with its Hop count decremented (if
1240 # there is one). If it has a hop count and it decrements to zero then don't
1243 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
1247 package Thingy::PCdefault;
1256 if (eph_dup($line)) {
1257 dbg("PCPROT: Ephemeral dup, dropped") if isdbg('chanerr');
1259 unless ($self->{isolate}) {
1260 DXChannel::broadcast_nodes($line, $self); # send it to everyone but me