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
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;
76 [ qw(c c m bp bc c) ], # pc10
77 [ qw(f m d t m c c h) ], # pc11
78 [ qw(c bc m bp bm p h) ], # pc12
82 undef , # pc16 has to be validated manually
85 undef , # pc19 has to be validated manually
86 undef , # pc20 no validation
88 undef , # pc22 no validation
89 [ qw(d n n n n m c c h) ], # pc23
91 [ qw(c c n n) ], # pc25
92 [ qw(f m d t m c c bc) ], # pc26
93 [ qw(d n n n n m c c bc) ], # pc27
94 [ qw(c c m c d t p m bp n p bp bc) ], # pc28
95 [ qw(c c n m) ], # pc29
100 [ qw(c c m) ], # pc34
101 [ qw(c c m) ], # pc35
102 [ qw(c c m) ], # pc36
103 [ qw(c c n m) ], # pc37
104 undef, # pc38 not interested
106 [ qw(c c m p n) ], # pc40
107 [ qw(c n m h) ], # pc41
108 [ qw(c c n) ], # pc42
109 undef, # pc43 don't handle it
110 [ qw(c c n m m c) ], # pc44
111 [ qw(c c n m) ], # pc45
112 [ qw(c c n) ], # pc46
115 [ qw(c m h) ], # pc49
116 [ qw(c n h) ], # pc50
117 [ qw(c c n) ], # pc51
139 [ qw(d n n n n n n m m m c c h) ], # pc73
150 [ qw(c c c m) ], # pc84
151 [ qw(c c c m) ], # pc85
154 # use the entry in the check list to check the field list presented
155 # return OK if line NOT in check list (for now)
160 return 0 if $n < 0 || $n > @checklist;
161 my $ref = $checklist[$n];
162 return 0 unless ref $ref;
165 shift; # not interested in the first field
166 for ($i = 0; $i < @$ref; $i++) {
167 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
168 return 0 unless $act;
169 next if $blank && $_[$i] =~ /^[ \*]$/;
171 return $i+1 unless is_callsign($_[$i]);
172 } elsif ($act eq 'm') {
173 return $i+1 unless is_pctext($_[$i]);
174 } elsif ($act eq 'p') {
175 return $i+1 unless is_pcflag($_[$i]);
176 } elsif ($act eq 'f') {
177 return $i+1 unless is_freq($_[$i]);
178 } elsif ($act eq 'n') {
179 return $i+1 unless $_[$i] =~ /^[\d ]+$/;
180 } elsif ($act eq 'h') {
181 return $i+1 unless $_[$i] =~ /^H\d\d?$/;
182 } elsif ($act eq 'd') {
183 return $i+1 unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
184 } elsif ($act eq 't') {
185 return $i+1 unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
193 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
198 # obtain a new connection this is derived from dxchannel
203 my $self = DXChannel::alloc(@_);
205 # add this node to the table, the values get filled in later
208 $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
213 # this is how a pc connection starts (for an incoming connection)
214 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
215 # all the crap that comes between).
218 my ($self, $line, $sort) = @_;
219 my $call = $self->{call};
220 my $user = $self->{user};
223 my $host = $self->{conn}->{peerhost} || "unknown";
224 Log('DXProt', "$call connected from $host");
226 # remember type of connection
227 $self->{consort} = $line;
228 $self->{outbound} = $sort eq 'O';
229 my $priv = $user->priv;
230 $priv = $user->priv(1) unless $priv;
231 $self->{priv} = $priv; # other clusters can always be 'normal' users
232 $self->{lang} = $user->lang || 'en';
233 $self->{isolate} = $user->{isolate};
234 $self->{consort} = $line; # save the connection type
238 # sort out registration
239 $self->{registered} = 1;
241 # get the output filters
242 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
243 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
244 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
245 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
246 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
249 # get the INPUT filters (these only pertain to Clusters)
250 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
251 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
252 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
253 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
254 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
256 # set unbuffered and no echo
257 $self->send_now('B',"0");
258 $self->send_now('E',"0");
259 $self->conn->echo(0) if $self->conn->can('echo');
261 # ping neighbour node stuff
262 my $ping = $user->pingint;
263 $ping = $pingint unless defined $ping;
264 $self->{pingint} = $ping;
265 $self->{nopings} = $user->nopings || $obscount;
266 $self->{pingtime} = [ ];
267 $self->{pingave} = 999;
268 $self->{metric} ||= 100;
269 $self->{lastping} = $main::systime;
271 # send initialisation string
272 unless ($self->{outbound}) {
276 $self->state('init');
277 $self->{pc50_t} = $main::systime;
279 # send info to all logged in thingies
280 $self->tell_login('loginn');
282 # run a script send the output to the debug file
283 my $script = new Script(lc $call) || new Script('node_default');
284 $script->run($self) if $script;
288 # send outgoing 'challenge'
298 # This is the normal pcxx despatcher
302 my ($self, $line) = @_;
303 my @field = split /\^/, $line;
304 return unless @field;
306 pop @field if $field[-1] eq '~';
308 # print join(',', @field), "\n";
311 # process PC frames, this will fail unless the frame starts PCnn
312 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
314 return if $pcno < 10 || $pcno > 99;
316 # check for and dump bad protocol messages
317 my $n = check($pcno, @field);
319 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
326 $pcr = Local::pcprot($self, $pcno, @field);
328 # dbg("Local::pcprot error $@") if isdbg('local') if $@;
332 my $sub = "handle_$pcno";
333 if ($self->can($sub)) {
334 $self->$sub($pcno, $line, @field);
336 $self->handle_default($pcno, $line, @field);
340 # incoming talk commands
348 return if $rspfcheck and !$self->rspfcheck(0, $_[6], $_[1]);
350 # will we allow it at all?
353 if (@bad = BadWords::check($_[3])) {
354 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
359 # is it for me or one of mine?
360 my ($from, $to, $via, $call, $dxchan);
369 # if this is a 'nodx' node then ignore it
370 if ($badnode->in($_[6]) || ($via && $badnode->in($via))) {
371 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
375 # if this is a 'bad spotter' user then ignore it
377 $nossid =~ s/-\d+$//;
378 if ($badspotter->in($nossid)) {
379 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
383 # if we are converting announces to talk is it a dup?
385 if (AnnTalk::is_talk_candidate($from, $_[3]) && AnnTalk::dup($from, $to, $_[3])) {
386 dbg("DXPROT: Dupe talk from announce, dropped") if isdbg('chanerr');
391 # it is here and logged on
392 $dxchan = DXChannel->get($main::myalias) if $to eq $main::mycall;
393 $dxchan = DXChannel->get($to) unless $dxchan;
394 if ($dxchan && $dxchan->is_user) {
396 $dxchan->talk($from, $to, $via, $_[3]);
400 # is it elsewhere, visible on the cluster via the to address?
401 # note: this discards the via unless the to address is on
404 if ($ref = Route::get($to)) {
405 $vref = Route::Node::get($via) if $via;
406 $vref = undef unless $vref && grep $to eq $_, $vref->users;
407 $ref->dxchan->talk($from, $to, $vref ? $via : undef, $_[3], $_[6]);
411 # not visible here, send a message of condolence
413 $ref = Route::get($from);
414 $vref = $ref = Route::Node::get($_[6]) unless $ref;
416 $dxchan = $ref->dxchan;
417 $dxchan->talk($main::mycall, $from, $vref ? $vref->call : undef, $dxchan->msg('talknh', $to) );
428 # route 'foreign' pc26s
430 if ($_[7] ne $main::mycall) {
431 $self->route($_[7], $line);
437 # return if $rspfcheck and !$self->rspfcheck(1, $_[7], $_[6]);
439 # if this is a 'nodx' node then ignore it
440 if ($badnode->in($_[7])) {
441 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
445 # if this is a 'bad spotter' user then ignore it
447 $nossid =~ s/-\d+$//;
448 if ($badspotter->in($nossid)) {
449 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
453 # convert the date to a unix date
454 my $d = cltounix($_[3], $_[4]);
455 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
456 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
457 dbg("PCPROT: Spot ignored, invalid date or out of range ($_[3] $_[4])\n") if isdbg('chanerr');
462 if ($baddx->in($_[2]) || BadWords::check($_[2]) || $_[2] =~ /COCK/) {
463 dbg("PCPROT: Bad DX spot, ignored") if isdbg('chanerr');
468 $_[5] =~ s/^\s+//; # take any leading blanks off
469 $_[2] = unpad($_[2]); # take off leading and trailing blanks from spotted callsign
470 if ($_[2] =~ /BUST\w*$/) {
471 dbg("PCPROT: useless 'BUSTED' spot") if isdbg('chanerr');
476 if (@bad = BadWords::check($_[5])) {
477 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
483 my @spot = Spot::prepare($_[1], $_[2], $d, $_[5], $_[6], $_[7]);
484 # global spot filtering on INPUT
485 if ($self->{inspotsfilter}) {
486 my ($filter, $hops) = $self->{inspotsfilter}->it(@spot);
488 dbg("PCPROT: Rejected by input spot filter") if isdbg('chanerr');
493 # this goes after the input filtering, but before the add
494 # so that if it is input filtered, it isn't added to the dup
495 # list. This allows it to come in from a "legitimate" source
496 if (Spot::dup($_[1], $_[2], $d, $_[5], $_[6])) {
497 dbg("PCPROT: Duplicate Spot ignored\n") if isdbg('chanerr');
505 # @spot at this point contains:-
506 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
507 # then spotted itu, spotted cq, spotters itu, spotters cq
508 # you should be able to route on any of these
511 # fix up qra locators of known users
512 my $user = DXUser->get_current($spot[4]);
514 my $qra = $user->qra;
515 unless ($qra && is_qra($qra)) {
516 my $lat = $user->lat;
517 my $long = $user->long;
518 if (defined $lat && defined $long) {
519 $user->qra(DXBearing::lltoqra($lat, $long));
524 # send a remote command to a distant cluster if it is visible and there is no
525 # qra locator and we havn't done it for a month.
527 unless ($user->qra) {
529 my $to = $user->homenode;
530 my $last = $user->lastoper || 0;
531 if ($send_opernam && $to && $to ne $main::mycall && $main::systime > $last + $DXUser::lastoperinterval && ($node = Route::Node::get($to)) ) {
532 my $cmd = "forward/opernam $spot[4]";
533 # send the rcmd but we aren't interested in the replies...
534 my $dxchan = $node->dxchan;
535 if ($dxchan && $dxchan->is_clx) {
536 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
538 route(undef, $to, pc34($main::mycall, $to, $cmd));
542 $node = Route::Node::get($to);
544 $dxchan = $node->dxchan;
545 if ($dxchan && $dxchan->is_clx) {
546 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
548 route(undef, $to, pc34($main::mycall, $to, $cmd));
552 $user->lastoper($main::systime);
561 $r = Local::spot($self, @spot);
563 # dbg("Local::spot1 error $@") if isdbg('local') if $@;
566 # DON'T be silly and send on PC26s!
567 return if $pcno == 26;
569 # send out the filtered spots
570 send_dx_spot($self, $line, @spot) if @spot;
580 # return if $rspfcheck and !$self->rspfcheck(1, $_[5], $_[1]);
582 # announce duplicate checking
583 $_[3] =~ s/^\s+//; # remove leading blanks
587 if (@bad = BadWords::check($_[3])) {
588 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
593 # if this is a 'nodx' node then ignore it
594 if ($badnode->in($_[5])) {
595 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
599 # if this is a 'bad spotter' user then ignore it
601 $nossid =~ s/-\d+$//;
602 if ($badspotter->in($nossid)) {
603 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
607 if ($_[2] eq '*' || $_[2] eq $main::mycall) {
610 # here's a bit of fun, convert incoming ann with a callsign in the first word
611 # or one saying 'to <call>' to a talk if we can route to the recipient
613 my $call = AnnTalk::is_talk_candidate($_[1], $_[3]);
615 my $ref = Route::get($call);
617 my $dxchan = $ref->dxchan;
618 $dxchan->talk($_[1], $call, undef, $_[3], $_[5]) if $dxchan != $self;
625 $self->send_announce($line, @_[1..6]);
627 $self->route($_[2], $line);
639 if (eph_dup($line)) {
640 dbg("PCPROT: dup PC16 detected") if isdbg('chanerr');
647 my $newline = "PC16^";
649 # do I want users from this channel?
650 unless ($self->user->wantpc16) {
651 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
655 if ($ncall eq $main::mycall) {
656 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
659 my $parent = Route::Node::get($ncall);
661 # if there is a parent, proceed, otherwise if there is a latent PC19 in the PC19list,
662 # fix it up in the routing tables and issue it forth before the PC16
664 my $nl = $pc19list{$ncall};
666 if ($nl && @_ > 3) { # 3 because of the hop count!
668 # this is a new (remembered) node, now attach it to me if it isn't in filtered
669 # and we haven't disallowed it
670 my $user = DXUser->get_current($ncall);
672 $user = DXUser->new($ncall);
674 $user->priv(1); # I have relented and defaulted nodes
676 $user->homenode($ncall);
680 my $wantpc19 = $user->wantroutepc19;
681 if ($wantpc19 || !defined $wantpc19) {
682 my $new = Route->new($ncall); # throw away
683 if ($self->in_filter_route($new)) {
686 $parent = Route::Node::get($_->[0]);
687 $dxchan = $parent->dxchan if $parent;
688 if ($dxchan && $dxchan ne $self) {
689 dbg("PCPROT: PC19 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
693 my $r = $parent->add($ncall, $_->[1], $_->[2]);
694 push @nrout, $r unless @nrout;
697 $user->wantroutepc19(1) unless defined $wantpc19; # for now we work on the basis that pc16 = real route
698 $user->lastin($main::systime) unless DXChannel->get($ncall);
701 # route the pc19 - this will cause 'stuttering PC19s' for a while
702 $self->route_pc19(@nrout) if @nrout ;
703 $parent = Route::Node::get($ncall);
705 dbg("PCPROT: lost $ncall after sending PC19 for it?");
711 delete $pc19list{$ncall};
714 dbg("PCPROT: Node $ncall not in config") if isdbg('chanerr');
719 $dxchan = $parent->dxchan;
720 if ($dxchan && $dxchan ne $self) {
721 dbg("PCPROT: PC16 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
725 # input filter if required
726 return unless $self->in_filter_route($parent);
731 for ($i = 2; $i < $#_; $i++) {
732 my ($call, $conf, $here) = $_[$i] =~ /^(\S+) (\S) (\d)/o;
733 next unless $call && $conf && defined $here && is_callsign($call);
734 next if $call eq $main::mycall;
736 eph_del_regex("^PC17\\^$call\\^$ncall");
738 $conf = $conf eq '*';
740 # reject this if we think it is a node already
741 my $r = Route::Node::get($call);
742 my $u = DXUser->get_current($call) unless $r;
743 if ($r || ($u && $u->is_node)) {
744 dbg("PCPROT: $call is a node") if isdbg('chanerr');
748 $r = Route::User::get($call);
749 my $flags = Route::here($here)|Route::conf($conf);
752 my $au = $r->addparent($parent);
753 if ($r->flags != $flags) {
757 push @rout, $r if $au;
759 push @rout, $parent->add_user($call, $flags);
763 # add this station to the user database, if required
764 $call =~ s/-\d+$//o; # remove ssid for users
765 my $user = DXUser->get_current($call);
766 $user = DXUser->new($call) if !$user;
767 $user->homenode($parent->call) if !$user->homenode;
768 $user->node($parent->call);
769 $user->lastin($main::systime) unless DXChannel->get($call);
773 $self->route_pc16($parent, @rout) if @rout;
786 eph_del_regex("^PC16\\^$ncall.*$ucall");
788 # do I want users from this channel?
789 unless ($self->user->wantpc16) {
790 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
793 if ($ncall eq $main::mycall) {
794 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
798 my $uref = Route::User::get($ucall);
800 dbg("PCPROT: Route::User $ucall not in config") if isdbg('chanerr');
803 my $parent = Route::Node::get($ncall);
805 dbg("PCPROT: Route::Node $ncall not in config") if isdbg('chanerr');
809 $dxchan = $parent->dxchan;
810 if ($dxchan && $dxchan ne $self) {
811 dbg("PCPROT: PC17 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
815 # input filter if required
816 return unless $self->in_filter_route($parent);
818 $parent->del_user($uref);
820 if (eph_dup($line)) {
821 dbg("PCPROT: dup PC17 detected") if isdbg('chanerr');
825 $self->route_pc17($parent, $uref);
834 $self->state('init');
836 # record the type and version offered
837 if ($_[1] =~ /DXSpider Version: (\d+\.\d+) Build: (\d+\.\d+)/) {
838 $self->version(53 + $1);
839 $self->user->version(53 + $1);
840 $self->build(0 + $2);
841 $self->user->build(0 + $2);
842 unless ($self->is_spider) {
843 $self->user->sort('S');
848 $self->version(50.0);
849 $self->version($_[2] / 100) if $_[2] && $_[2] =~ /^\d+$/;
850 $self->user->version($self->version);
853 # first clear out any nodes on this dxchannel
854 my $parent = Route::Node::get($self->{call});
855 my @rout = $parent->del_nodes;
856 $self->route_pc21(@rout, $parent) if @rout;
857 $self->send_local_config();
861 # incoming cluster list
869 my $newline = "PC19^";
871 if (eph_dup($line)) {
872 dbg("PCPROT: dup PC19 detected") if isdbg('chanerr');
878 my $parent = Route::Node::get($self->{call});
880 dbg("DXPROT: my parent $self->{call} has disappeared");
886 for ($i = 1; $i < $#_-1; $i += 4) {
888 my $call = uc $_[$i+1];
891 next unless defined $here && defined $conf && is_callsign($call);
893 eph_del_regex("^PC(?:21\\^$call|17\\^[^\\^]+\\^$call)");
895 # check for sane parameters
896 # $ver = 5000 if $ver eq '0000';
897 next if $ver < 5000; # only works with version 5 software
898 next if length $call < 3; # min 3 letter callsigns
899 next if $call eq $main::mycall;
901 # check that this PC19 isn't trying to alter the wrong dxchan
902 my $dxchan = DXChannel->get($call);
903 if ($dxchan && $dxchan != $self) {
904 dbg("PCPROT: PC19 from $self->{call} trying to alter wrong locally connected $call, ignored!") if isdbg('chanerr');
908 # add this station to the user database, if required (don't remove SSID from nodes)
909 my $user = DXUser->get_current($call);
911 $user = DXUser->new($call);
913 $user->priv(1); # I have relented and defaulted nodes
915 $user->homenode($call);
919 my $r = Route::Node::get($call);
920 my $flags = Route::here($here)|Route::conf($conf);
922 # modify the routing table if it is in it, otherwise store it in the pc19list for now
925 if ($call ne $parent->call) {
926 if ($self->in_filter_route($r)) {
927 $ar = $parent->add($call, $ver, $flags);
928 push @rout, $ar if $ar;
933 if ($r->version ne $ver || $r->flags != $flags) {
936 push @rout, $r unless $ar;
940 # if he is directly connected or allowed then add him, otherwise store him up for later
941 if ($call eq $self->{call} || $user->wantroutepc19) {
942 my $new = Route->new($call); # throw away
943 if ($self->in_filter_route($new)) {
944 my $ar = $parent->add($call, $ver, $flags);
945 $user->wantroutepc19(1) unless defined $user->wantroutepc19;
946 push @rout, $ar if $ar;
951 $pc19list{$call} = [] unless exists $pc19list{$call};
952 my $nl = $pc19list{$call};
953 push @{$pc19list{$call}}, [$self->{call}, $ver, $flags] unless grep $_->[0] eq $self->{call}, @$nl;
957 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
958 my $mref = DXMsg::get_busy($call);
959 $mref->stop_msg($call) if $mref;
961 $user->lastin($main::systime) unless DXChannel->get($call);
966 $self->route_pc19(@rout) if @rout;
969 # send local configuration
975 $self->send_local_config();
977 $self->state('normal');
978 $self->{lastping} = 0;
981 # delete a cluster from the list
989 eph_del_regex("^PC1[679].*$call");
991 # if I get a PC21 from the same callsign as self then treat it
992 # as a PC39: I have gone away
993 if ($call eq $self->call) {
994 $self->disconnect(1);
998 # check to see if we are in the pc19list, if we are then don't bother with any of
999 # this routing table manipulation, just remove it from the list and dump it
1001 if (my $nl = $pc19list{$call}) {
1002 $pc19list{$call} = [ grep {$_->[0] ne $self->{call}} @$nl ];
1003 delete $pc19list{$call} unless @{$pc19list{$call}};
1006 my $parent = Route::Node::get($self->{call});
1008 dbg("DXPROT: my parent $self->{call} has disappeared");
1012 if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
1013 my $node = Route::Node::get($call);
1016 my $dxchan = DXChannel->get($call);
1017 if ($dxchan && $dxchan != $self) {
1018 dbg("PCPROT: PC21 from $self->{call} trying to alter locally connected $call, ignored!") if isdbg('chanerr');
1023 return unless $self->in_filter_route($node);
1026 push @rout, $node->del($parent);
1029 dbg("PCPROT: I WILL _NOT_ be disconnected!") if isdbg('chanerr');
1034 $self->route_pc21(@rout) if @rout;
1043 $self->state('normal');
1044 $self->{lastping} = 0;
1054 # route 'foreign' pc27s
1056 if ($_[8] ne $main::mycall) {
1057 $self->route($_[8], $line);
1062 return if $rspfcheck and !$self->rspfcheck(1, $_[8], $_[7]);
1065 my $d = cltounix($_[1], sprintf("%02d18Z", $_[2]));
1066 my $sfi = unpad($_[3]);
1067 my $k = unpad($_[4]);
1068 my $i = unpad($_[5]);
1069 my ($r) = $_[6] =~ /R=(\d+)/;
1071 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1072 dbg("PCPROT: WWV Date ($_[1] $_[2]) out of range") if isdbg('chanerr');
1075 if (Geomag::dup($d,$sfi,$k,$i,$_[6])) {
1076 dbg("PCPROT: Dup WWV Spot ignored\n") if isdbg('chanerr');
1079 $_[7] =~ s/-\d+$//o; # remove spotter's ssid
1081 my $wwv = Geomag::update($d, $_[2], $sfi, $k, $i, @_[6..8], $r);
1085 $rep = Local::wwv($self, $_[1], $_[2], $sfi, $k, $i, @_[6..8], $r);
1087 # dbg("Local::wwv2 error $@") if isdbg('local') if $@;
1090 # DON'T be silly and send on PC27s!
1091 return if $pcno == 27;
1093 # broadcast to the eager world
1094 send_wwv_spot($self, $line, $d, $_[2], $sfi, $k, $i, @_[6..8]);
1103 my $call = uc $_[1];
1105 $nref = Route::Node::get($call);
1106 $uref = Route::User::get($call);
1107 return unless $nref || $uref; # if we don't know where they are, it's pointless sending it on
1109 if (eph_dup($line)) {
1110 dbg("PCPROT: Dup PC24 ignored\n") if isdbg('chanerr');
1114 $nref->here($_[2]) if $nref;
1115 $uref->here($_[2]) if $uref;
1116 my $ref = $nref || $uref;
1117 return unless $self->in_filter_route($ref);
1119 $self->route_pc24($ref, $_[3]);
1128 if ($_[1] ne $main::mycall) {
1129 $self->route($_[1], $line);
1132 if ($_[2] eq $main::mycall) {
1133 dbg("PCPROT: Trying to merge to myself, ignored") if isdbg('chanerr');
1137 Log('DXProt', "Merge request for $_[3] spots and $_[4] WWV from $_[2]");
1141 my @in = reverse Spot::search(1, undef, undef, 0, $_[3]);
1144 $self->send_frame($main::me, pc26(@{$in}[0..4], $_[2]));
1150 my @in = reverse Geomag::search(0, $_[4], time, 1);
1153 $self->send_frame($main::me, pc27(@{$in}[0..5], $_[2]));
1158 sub handle_26 {goto &handle_11}
1159 sub handle_27 {goto &handle_23}
1161 # mail/file handling
1167 if ($_[1] eq $main::mycall) {
1169 my $sub = "DXMsg::handle_$pcno";
1172 $self->route($_[1], $line) unless $self->is_clx;
1176 sub handle_29 {goto &handle_28}
1177 sub handle_30 {goto &handle_28}
1178 sub handle_31 {goto &handle_28}
1179 sub handle_32 {goto &handle_28}
1180 sub handle_33 {goto &handle_28}
1187 if (eph_dup($line, $eph_pc34_restime)) {
1188 dbg("PCPROT: dupe PC34, ignored") if isdbg('chanerr');
1190 $self->process_rcmd($_[1], $_[2], $_[2], $_[3]);
1194 # remote command replies
1200 eph_del_regex("^PC35\\^$_[2]\\^$_[1]\\^");
1201 $self->process_rcmd_reply($_[1], $_[2], $_[1], $_[3]);
1204 sub handle_36 {goto &handle_34}
1212 DXDb::process($self, $line);
1215 # node connected list from neighbour
1223 # incoming disconnect
1229 if ($_[1] eq $self->{call}) {
1230 $self->disconnect(1);
1232 dbg("PCPROT: came in on wrong channel") if isdbg('chanerr');
1236 sub handle_40 {goto &handle_28}
1247 $l =~ s/[\x00-\x20\x7f-\xff]+//g; # remove all funny characters and spaces for dup checking
1248 if (eph_dup($l, $eph_info_restime)) {
1249 dbg("PCPROT: dup PC41, ignored") if isdbg('chanerr');
1253 # input filter if required
1254 # my $ref = Route::get($call) || Route->new($call);
1255 # return unless $self->in_filter_route($ref);
1257 if ($_[3] eq $_[2] || $_[3] =~ /^\s*$/) {
1258 dbg('PCPROT: invalid value') if isdbg('chanerr');
1262 # add this station to the user database, if required
1263 my $user = DXUser->get_current($call);
1264 $user = DXUser->new($call) unless $user;
1268 } elsif ($_[2] == 2) {
1270 } elsif ($_[2] == 3) {
1271 if (is_latlong($_[3])) {
1272 my ($lat, $long) = DXBearing::stoll($_[3]);
1275 $user->qra(DXBearing::lltoqra($lat, $long));
1277 dbg('PCPROT: not a valid lat/long') if isdbg('chanerr');
1280 } elsif ($_[2] == 4) {
1281 $user->homenode($_[3]);
1282 } elsif ($_[2] == 5) {
1283 if (is_qra(uc $_[3])) {
1284 my ($lat, $long) = DXBearing::qratoll(uc $_[3]);
1287 $user->qra(uc $_[3]);
1289 dbg('PCPROT: not a valid QRA locator') if isdbg('chanerr');
1293 $user->lastoper($main::systime); # to cut down on excessive for/opers being generated
1296 unless ($self->{isolate}) {
1297 DXChannel::broadcast_nodes($line, $self); # send it to everyone but me
1300 # perhaps this IS what we want after all
1301 # $self->route_pc41($ref, $call, $_[2], $_[3], $_[4]);
1304 sub handle_42 {goto &handle_28}
1308 sub handle_44 {goto &handle_37}
1309 sub handle_45 {goto &handle_37}
1310 sub handle_46 {goto &handle_37}
1311 sub handle_47 {goto &handle_37}
1312 sub handle_48 {goto &handle_37}
1314 # message and database
1321 if (eph_dup($line)) {
1322 dbg("PCPROT: Dup PC49 ignored\n") if isdbg('chanerr');
1326 if ($_[1] eq $main::mycall) {
1327 DXMsg::handle_49($self, @_);
1329 $self->route($_[1], $line) unless $self->is_clx;
1333 # keep alive/user list
1341 my $node = Route::Node::get($call);
1343 return unless $node->call eq $self->{call};
1344 $node->usercount($_[2]);
1346 # input filter if required
1347 return unless $self->in_filter_route($node);
1349 $self->route_pc50($node, $_[2], $_[3]) unless eph_dup($line);
1353 # incoming ping requests/answers
1365 if ($to eq $main::mycall) {
1367 $self->send_frame($main::me, pc51($from, $to, '0'));
1369 # it's a reply, look in the ping list for this one
1370 my $ref = $pings{$from};
1372 my $tochan = DXChannel->get($from);
1374 my $r = shift @$ref;
1375 my $dxchan = DXChannel->get($r->{call});
1376 next unless $dxchan;
1377 my $t = tv_interval($r->{t}, [ gettimeofday ]);
1378 if ($dxchan->is_user) {
1379 my $s = sprintf "%.2f", $t;
1380 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
1381 $dxchan->send($dxchan->msg('pingi', $from, $s, $ave))
1382 } elsif ($dxchan->is_node) {
1384 my $nopings = $tochan->user->nopings || 2;
1385 push @{$tochan->{pingtime}}, $t;
1386 shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
1388 # cope with a missed ping, this means you must set the pingint large enough
1389 if ($t > $tochan->{pingint} && $t < 2 * $tochan->{pingint} ) {
1390 $t -= $tochan->{pingint};
1393 # calc smoothed RTT a la TCP
1394 if (@{$tochan->{pingtime}} == 1) {
1395 $tochan->{pingave} = $t;
1397 $tochan->{pingave} = $tochan->{pingave} + (($t - $tochan->{pingave}) / 6);
1399 $tochan->{nopings} = $nopings; # pump up the timer
1406 if (eph_dup($line)) {
1407 dbg("PCPROT: dup PC51 detected") if isdbg('chanerr');
1410 # route down an appropriate thingy
1411 $self->route($to, $line);
1415 # dunno but route it
1422 if ($call ne $main::mycall) {
1423 $self->route($call, $line);
1436 my $d = cltounix($call, sprintf("%02d18Z", $_[2]));
1437 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1438 dbg("PCPROT: WCY Date ($call $_[2]) out of range") if isdbg('chanerr');
1441 @_ = map { unpad($_) } @_;
1443 dbg("PCPROT: Dup WCY Spot ignored\n") if isdbg('chanerr');
1447 my $wcy = WCY::update($d, @_[2..12]);
1451 $rep = Local::wcy($self, @_[1..12]);
1453 # dbg("Local::wcy error $@") if isdbg('local') if $@;
1456 # broadcast to the eager world
1457 send_wcy_spot($self, $line, $d, @_[2..12]);
1460 # remote commands (incoming)
1466 $self->process_rcmd($_[1], $_[2], $_[3], $_[4]);
1469 # remote command replies
1475 $self->process_rcmd_reply($_[1], $_[2], $_[3], $_[4]);
1478 # if get here then rebroadcast the thing with its Hop count decremented (if
1479 # there is one). If it has a hop count and it decrements to zero then don't
1482 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
1492 if (eph_dup($line)) {
1493 dbg("PCPROT: Ephemeral dup, dropped") if isdbg('chanerr');
1495 unless ($self->{isolate}) {
1496 DXChannel::broadcast_nodes($line, $self); # send it to everyone but me
1502 # This is called from inside the main cluster processing loop and is used
1503 # for despatching commands that are doing some long processing job
1508 my @dxchan = DXChannel->get_all();
1512 # send out a pc50 on EVERY channel all at once
1513 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
1514 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
1519 foreach $dxchan (@dxchan) {
1520 next unless $dxchan->is_node();
1521 next if $dxchan == $main::me;
1523 # send the pc50 or PC90
1524 $dxchan->send_frame($main::me, $pc50s) if $pc50s;
1526 # send a ping out on this channel
1527 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
1528 if ($dxchan->{nopings} <= 0) {
1529 Log('DXProt', $dxchan->call . " Disconnected on Ping Timeout");
1530 dbg($dxchan->call . " Disconnected on Ping Timeout");
1531 $dxchan->disconnect;
1533 addping($main::mycall, $dxchan->call);
1534 $dxchan->{nopings} -= 1;
1535 $dxchan->{lastping} = $t;
1541 if ($t - $last10 >= 10) {
1542 # clean out ephemera
1549 if ($main::systime - 3600 > $last_hour) {
1550 $last_hour = $main::systime;
1555 # wrap send up so that we can tell where this came from
1556 # new prot will need this
1567 # some active measures
1575 my @dxchan = DXChannel->get_all();
1578 # send it if it isn't the except list and isn't isolated and still has a hop count
1579 # taking into account filtering and so on
1580 foreach $dxchan (@dxchan) {
1581 next if $dxchan == $main::me;
1582 next if $dxchan == $self && $self->is_node;
1583 $dxchan->dx_spot($self, $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, $origin, $filter, $hops, $isolate, $line);
1604 my ($self, $origin, $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_frame($origin, $routeit);
1617 $self->send_frame($origin, $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($self, $line, $self->{isolate}, @_, $self->{call}, $wwv_dxcc, $wwv_itu, $wwv_cq, $org_dxcc, $org_itu, $org_cq);
1660 my $isolate = shift;
1661 my ($filter, $hops);
1663 if ($self->{wwvfilter}) {
1664 ($filter, $hops) = $self->{wwvfilter}->it(@_);
1665 return unless $filter;
1667 send_prot_line($self, $origin, $filter, $hops, $isolate, $line)
1674 my @dxchan = DXChannel->get_all();
1676 my ($wcy_dxcc, $wcy_itu, $wcy_cq, $org_dxcc, $org_itu, $org_cq) = (0..0);
1677 my @dxcc = Prefix::extract($_[10]);
1679 $wcy_dxcc = $dxcc[1]->dxcc;
1680 $wcy_itu = $dxcc[1]->itu;
1681 $wcy_cq = $dxcc[1]->cq;
1683 @dxcc = Prefix::extract($_[11]);
1685 $org_dxcc = $dxcc[1]->dxcc;
1686 $org_itu = $dxcc[1]->itu;
1687 $org_cq = $dxcc[1]->cq;
1690 # send it if it isn't the except list and isn't isolated and still has a hop count
1691 # taking into account filtering and so on
1692 foreach $dxchan (@dxchan) {
1693 next if $dxchan == $main::me;
1694 next if $dxchan == $self;
1696 $dxchan->wcy($self, $line, $self->{isolate}, @_, $self->{call}, $wcy_dxcc, $wcy_itu, $wcy_cq, $org_dxcc, $org_itu, $org_cq);
1705 my $isolate = shift;
1706 my ($filter, $hops);
1708 if ($self->{wcyfilter}) {
1709 ($filter, $hops) = $self->{wcyfilter}->it(@_);
1710 return unless $filter;
1712 send_prot_line($self, $origin,$filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
1720 my @dxchan = DXChannel->get_all();
1724 my $text = unpad($_[2]);
1726 if ($_[3] eq '*') { # sysops
1728 } elsif ($_[3] gt ' ') { # speciality list handling
1729 my ($name) = split /\./, $_[3];
1730 $target = "$name"; # put the rest in later (if bothered)
1737 $target = "ALL" if !$target;
1740 # obtain country codes etc
1741 my ($ann_dxcc, $ann_itu, $ann_cq, $org_dxcc, $org_itu, $org_cq) = (0..0);
1742 my ($ann_state, $org_state) = ("", "");
1743 my @dxcc = Prefix::extract($_[0]);
1745 $ann_dxcc = $dxcc[1]->dxcc;
1746 $ann_itu = $dxcc[1]->itu;
1747 $ann_cq = $dxcc[1]->cq;
1748 $ann_state = $dxcc[1]->state;
1750 @dxcc = Prefix::extract($_[4]);
1752 $org_dxcc = $dxcc[1]->dxcc;
1753 $org_itu = $dxcc[1]->itu;
1754 $org_cq = $dxcc[1]->cq;
1755 $org_state = $dxcc[1]->state;
1758 if ($self->{inannfilter}) {
1759 my ($filter, $hops) =
1760 $self->{inannfilter}->it(@_, $self->{call},
1761 $ann_dxcc, $ann_itu, $ann_cq,
1762 $org_dxcc, $org_itu, $org_cq, $ann_state, $org_state);
1764 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1769 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
1770 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1774 Log('ann', $target, $_[0], $text);
1776 # send it if it isn't the except list and isn't isolated and still has a hop count
1777 # taking into account filtering and so on
1778 foreach $dxchan (@dxchan) {
1779 next if $dxchan == $main::me;
1780 next if $dxchan == $self && $self->is_node;
1781 $dxchan->announce($self, $line, $self->{isolate}, $to, $target, $text, @_, $self->{call}, $ann_dxcc, $ann_itu, $ann_cq, $org_dxcc, $org_itu, $org_cq);
1790 my $isolate = shift;
1794 my ($filter, $hops);
1796 if ($self->{annfilter}) {
1797 ($filter, $hops) = $self->{annfilter}->it(@_);
1798 return unless $filter;
1800 send_prot_line($self, $origin, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
1804 sub send_local_config
1812 dbg('DXProt::send_local_config') if isdbg('trace');
1815 if ($self->{isolate}) {
1816 @localnodes = ( $main::routeroot );
1818 # create a list of all the nodes that are not connected to this connection
1819 # and are not themselves isolated, this to make sure that isolated nodes
1820 # don't appear outside of this node
1821 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
1822 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
1823 my @intcalls = map { $_->nodes } @localnodes if @localnodes;
1824 my $ref = Route::Node::get($self->{call});
1825 my @rnodes = $ref->nodes;
1826 for my $node (@intcalls) {
1827 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes;
1829 unshift @localnodes, $main::routeroot;
1833 $self->send_route($main::me, \&pc19, scalar(@localnodes)+scalar(@remotenodes), @localnodes, @remotenodes);
1835 # get all the users connected on the above nodes and send them out
1836 foreach $node (@localnodes, @remotenodes) {
1838 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
1839 $self->send_route($main::me, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
1841 dbg("sent a null value") if isdbg('chanerr');
1847 # route a message down an appropriate interface for a callsign
1849 # is called route(to, pcline);
1853 my ($self, $call, $line) = @_;
1855 if (ref $self && $call eq $self->{call}) {
1856 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
1860 # always send it down the local interface if available
1861 my $dxchan = DXChannel->get($call);
1863 my $cl = Route::get($call);
1864 $dxchan = $cl->dxchan if $cl;
1866 if (ref $self && $dxchan eq $self) {
1867 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
1873 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1875 $dxchan->send_frame($self, $routeit) unless $dxchan == $main::me;
1878 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
1883 # obtain the hops from the list for this callsign and pc no
1889 my $hops = $DXProt::hopcount{$pcno};
1890 $hops = $DXProt::def_hopcount if !$hops;
1895 # adjust the hop count on a per node basis using the user loadable
1896 # hop table if available or else decrement an existing one
1903 my $call = $self->{call};
1906 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
1907 my ($pcno) = $s =~ /^PC(\d\d)/o;
1908 confess "$call called adjust_hops with '$s'" unless $pcno;
1909 my $ref = $nodehops{$call} if %nodehops;
1911 my $newhops = $ref->{$pcno};
1912 return "" if defined $newhops && $newhops == 0;
1913 $newhops = $ref->{default} unless $newhops;
1914 return "" if defined $newhops && $newhops == 0;
1915 $newhops = $hops if !$newhops || $hops < $newhops;
1916 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1918 # simply decrement it
1920 return "" if !$hops;
1921 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
1933 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
1934 do "$main::data/hop_table.pl";
1940 # add a ping request to the ping queues
1943 my ($from, $to) = @_;
1944 my $ref = $pings{$to} || [];
1947 $r->{t} = [ gettimeofday ];
1948 route(undef, $to, pc51($to, $main::mycall, 1));
1955 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
1956 if ($tonode eq $main::mycall) {
1957 my $ref = DXUser->get_current($fromnode);
1958 my $cref = Route::Node::get($fromnode);
1959 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
1960 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
1961 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
1962 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
1963 my $oldpriv = $self->{priv};
1964 $self->{priv} = $ref->{priv}; # assume the user's privilege level
1965 my @in = (DXCommandmode::run_cmd($self, $cmd));
1966 $self->{priv} = $oldpriv;
1967 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
1968 delete $self->{remotecmd};
1970 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
1973 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
1976 my $ref = DXUser->get_current($tonode);
1977 if ($ref && $ref->is_clx) {
1978 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
1980 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
1985 sub process_rcmd_reply
1987 my ($self, $tonode, $fromnode, $user, $line) = @_;
1988 if ($tonode eq $main::mycall) {
1989 my $s = $rcmds{$fromnode};
1991 my $dxchan = DXChannel->get($s->{call});
1992 my $ref = $user eq $tonode ? $dxchan : (DXChannel->get($user) || $dxchan);
1993 $ref->send($line) if $ref;
1994 delete $rcmds{$fromnode} if !$dxchan;
1996 # send unsolicited ones to the sysop
1997 my $dxchan = DXChannel->get($main::myalias);
1998 $dxchan->send($line) if $dxchan;
2001 my $ref = DXUser->get_current($tonode);
2002 if ($ref && $ref->is_clx) {
2003 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
2005 $self->route($tonode, pc35($fromnode, $tonode, $line));
2014 my $fromnode = shift;
2019 Log('rcmd', 'out', $fromnode, $line);
2020 if ($self->is_clx) {
2021 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
2023 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
2028 # add a rcmd request to the rcmd queues
2031 my ($self, $to, $cmd) = @_;
2034 $r->{call} = $self->{call};
2035 $r->{t} = $main::systime;
2039 my $ref = Route::Node::get($to);
2040 my $dxchan = $ref->dxchan;
2041 if ($dxchan && $dxchan->is_clx) {
2042 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
2044 route(undef, $to, pc34($main::mycall, $to, $cmd));
2051 my $pc39flag = shift;
2052 my $call = $self->call;
2054 return if $self->{disconnecting}++;
2056 unless ($pc39flag && $pc39flag == 1) {
2057 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
2060 # get rid of any PC16/17/19
2061 eph_del_regex("^PC1[679]*$call");
2063 # do routing stuff, remove me from routing table
2064 my $node = Route::Node::get($call);
2067 @rout = $node->del($main::routeroot);
2069 # and all my ephemera as well
2072 eph_del_regex("^PC1[679].*$c");
2076 # remove them from the pc19list as well
2077 while (my ($k,$v) = each %pc19list) {
2078 my @l = grep {$_->[0] ne $call} @{$pc19list{$k}};
2080 $pc19list{$k} = \@l;
2082 delete $pc19list{$k};
2086 eph_del_regex("^PC1[679].*$k");
2089 # unbusy and stop and outgoing mail
2090 my $mref = DXMsg::get_busy($call);
2091 $mref->stop_msg($call) if $mref;
2093 # broadcast to all other nodes that all the nodes connected to via me are gone
2094 unless ($pc39flag && $pc39flag == 2) {
2095 $self->route_pc21(@rout) if @rout;
2098 # remove outstanding pings
2099 delete $pings{$call};
2101 # I was the last node visited
2102 $self->user->node($main::mycall);
2104 # send info to all logged in thingies
2105 $self->tell_login('logoutn');
2107 Log('DXProt', $call . " Disconnected");
2109 $self->SUPER::disconnect;
2114 # send a talk message to this thingy
2118 my ($self, $from, $to, $via, $line, $origin) = @_;
2120 $line =~ s/\^/\\5E/g; # remove any ^ characters
2121 $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
2122 Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
2125 # send it if it isn't the except list and isn't isolated and still has a hop count
2126 # taking into account filtering and so on
2131 my $generate = shift;
2132 my $no = shift; # the no of things to filter on
2134 my ($filter, $hops);
2137 for (; @_ && $no; $no--) {
2140 if (!$self->{isolate} && $self->{routefilter}) {
2143 ($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});
2147 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
2150 dbg("was sent a null value") if isdbg('chanerr');
2153 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
2157 foreach my $line (&$generate(@rin, @_)) {
2160 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
2162 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
2163 next unless $routeit;
2165 $self->send_frame($origin, $routeit);
2173 my $generate = shift;
2174 my @dxchan = DXChannel::get_all_nodes();
2178 unless ($self->{isolate}) {
2179 foreach $dxchan (@dxchan) {
2180 next if $dxchan == $self;
2181 next if $dxchan == $main::me;
2182 next unless $dxchan->isa('DXProt');
2183 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
2185 $dxchan->send_route($self, $generate, @_);
2193 return unless $self->user->wantpc16;
2194 broadcast_route($self, \&pc16, 1, @_);
2200 return unless $self->user->wantpc16;
2201 broadcast_route($self, \&pc17, 1, @_);
2207 broadcast_route($self, \&pc19, scalar @_, @_);
2213 broadcast_route($self, \&pc21, scalar @_, @_);
2219 broadcast_route($self, \&pc24, 1, @_);
2225 broadcast_route($self, \&pc41, 1, @_);
2231 broadcast_route($self, \&pc50, 1, @_);
2237 broadcast_route($self, \&pc90, 1, @_);
2244 my ($filter, $hops) = (1, 1);
2246 if ($self->{inroutefilter}) {
2247 ($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);
2248 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
2256 my $t = shift || $eph_restime;
2260 $s =~ s/\^H\d\d?\^?\~?$//;
2261 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
2262 $eph{$s} = $main::systime + $t;
2270 while (($key, $val) = each %eph) {
2271 if ($key =~ m{$regex}) {
2281 while (($key, $val) = each %eph) {
2282 if ($main::systime >= $val) {
2293 while (($key, $val) = each %eph) {
2294 push @out, $key, $val;
2301 goto &DXCommandmode::run_cmd;