3 # This module impliments the protocal mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
31 use Time::HiRes qw(gettimeofday tv_interval);
34 use vars qw($me $pc11_max_age $pc23_max_age
35 $last_hour %pings %rcmds
36 %nodehops @baddx $baddxfn
37 $allowzero $decode_dk0wcy $send_opernam @checklist);
39 $me = undef; # the channel id for this cluster
40 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
41 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
43 $last_hour = time; # last time I did an hourly periodic update
44 %pings = (); # outstanding ping requests outbound
45 %rcmds = (); # outstanding rcmd requests outbound
46 %nodehops = (); # node specific hop control
47 @baddx = (); # list of illegal spotted callsigns
50 $baddxfn = "$main::data/baddx.pl";
54 [ qw(c c m p bc c) ], # pc10
55 [ qw(f m d t m c c h) ], # pc11
56 [ qw(c bc m bp c p h) ], # pc12
60 undef , # pc16 has to be validated manually
63 undef , # pc19 has to be validated manually
64 undef , # pc20 no validation
66 undef , # pc22 no validation
67 [ qw(d n n n n m c c h) ], # pc23
69 [ qw(c c n n) ], # pc25
70 [ qw(f m d t m c c) ], # pc26
71 [ qw(d n n n n m c c) ], # pc27
72 [ qw(c c c c d t p m bp n p bp bc) ], # pc28
73 [ qw(c c n m) ], # pc29
81 [ qw(c c n m) ], # pc37
82 undef, # pc38 not interested
84 [ qw(c c m p n) ], # pc40
85 [ qw(c n m h) ], # pc41
87 undef, # pc43 don't handle it
88 [ qw(c c n m m c) ], # pc44
89 [ qw(c c n m) ], # pc45
117 [ qw(d n n n n n n m m m c c h) ], # pc73
128 [ qw(c c c m) ], # pc84
129 [ qw(c c c m) ], # pc85
132 # use the entry in the check list to check the field list presented
133 # return OK if line NOT in check list (for now)
138 return 0 if $n < 0 || $n > @checklist;
139 my $ref = $checklist[$n];
140 return 0 unless ref $ref;
143 shift; # not interested in the first field
144 for ($i = 0; $i < @_; $i++) {
145 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
146 return 0 unless $act;
147 next if $blank && $_[$i] =~ /^[ \*]$/;
149 return $i+1 unless is_callsign($_[$i]);
150 } elsif ($act eq 'm') {
151 return $i+1 unless is_pctext($_[$i]);
152 } elsif ($act eq 'p') {
153 return $i+1 unless is_pcflag($_[$i]);
154 } elsif ($act eq 'f') {
155 return $i+1 unless is_freq($_[$i]);
156 } elsif ($act eq 'n') {
157 return $i+1 unless $_[$i] =~ /^[\d ]+$/;
158 } elsif ($act eq 'h') {
159 return $i+1 unless $_[$i] =~ /^H\d\d?$/;
160 } elsif ($act eq 'd') {
161 return $i+1 unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
162 } elsif ($act eq 't') {
163 return $i+1 unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
171 my $user = DXUser->get($main::mycall);
172 $DXProt::myprot_version += $main::version*100;
173 $me = DXProt->new($main::mycall, 0, $user);
175 $me->{state} = "indifferent";
176 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
178 # $me->{sort} = 'M'; # M for me
180 # now prime the spot and wwv duplicates file with data
181 my @today = Julian::unixtoj(time);
182 for (Spot::readfile(@today), Spot::readfile(Julian::sub(@today, 1))) {
183 Spot::dup(@{$_}[0..3]);
185 for (Geomag::readfile(time)) {
186 Geomag::dup(@{$_}[1..5]);
189 # load the baddx file
190 do "$baddxfn" if -e "$baddxfn";
195 # obtain a new connection this is derived from dxchannel
200 my $self = DXChannel::alloc(@_);
204 # this is how a pc connection starts (for an incoming connection)
205 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
206 # all the crap that comes between).
209 my ($self, $line, $sort) = @_;
210 my $call = $self->{call};
211 my $user = $self->{user};
213 # remember type of connection
214 $self->{consort} = $line;
215 $self->{outbound} = $sort eq 'O';
216 $self->{priv} = $user->priv || 1; # other clusters can always be 'normal' users
217 $self->{lang} = $user->lang || 'en';
218 $self->{isolate} = $user->{isolate};
219 $self->{consort} = $line; # save the connection type
222 # get the INPUT filters (these only pertain to Clusters)
223 $self->{inspotfilter} = Filter::read_in('spots', $call, 1);
224 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1);
225 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1);
226 $self->{inannfilter} = Filter::read_in('ann', $call, 1);
228 # set unbuffered and no echo
229 $self->send_now('B',"0");
230 $self->send_now('E',"0");
232 # ping neighbour node stuff
233 my $ping = $user->pingint;
234 $ping = 5*60 unless defined $ping;
235 $self->{pingint} = $ping;
236 $self->{nopings} = $user->nopings || 2;
237 $self->{pingtime} = [ ];
238 $self->{pingave} = 0;
240 # send initialisation string
241 unless ($self->{outbound}) {
242 $self->send(pc38()) if DXNode->get_all();
244 $self->{lastping} = $main::systime;
246 # remove from outstanding connects queue
247 @main::outstanding_connects = grep {$_->{call} ne $call} @main::outstanding_connects;
248 $self->{lastping} = $main::systime + $self->pingint / 2;
250 $self->state('init');
253 # send info to all logged in thingies
254 $self->tell_login('loginn');
256 Log('DXProt', "$call connected");
260 # This is the normal pcxx despatcher
264 my ($self, $line) = @_;
265 my @field = split /\^/, $line;
266 pop @field if $field[-1] eq '~';
268 # print join(',', @field), "\n";
270 # ignore any lines that don't start with PC
271 return if !$field[0] =~ /^PC/;
274 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
276 return if $pcno < 10 || $pcno > 99;
278 # check for and dump bad protocol messages
279 my $n = check($pcno, @field);
281 dbg('chan', "bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")");
288 $pcr = Local::pcprot($self, $pcno, @field);
290 # dbg('local', "Local::pcprot error $@") if $@;
294 if ($pcno == 10) { # incoming talk
296 # is it for me or one of mine?
297 my ($to, $via, $call, $dxchan);
298 if ($field[5] gt ' ') {
299 $call = $via = $field[2];
301 unless (is_callsign($to)) {
302 dbg('chan', "Corrupt talk, rejected");
306 $call = $to = $field[2];
308 if ($dxchan = DXChannel->get($call)) {
309 $dxchan->talk($field[1], $to, $via, $field[3]);
311 $self->route($field[2], $line); # relay it on its way
316 if ($pcno == 11 || $pcno == 26) { # dx spot
318 # route 'foreign' pc26s
320 if ($field[7] ne $main::mycall) {
321 $self->route($field[7], $line);
326 # if this is a 'nodx' node then ignore it
327 if (grep $field[7] =~ /^$_/, @DXProt::nodx_node) {
328 dbg('chan', "Bad DXNode, dropped");
332 # convert the date to a unix date
333 my $d = cltounix($field[3], $field[4]);
334 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
335 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
336 dbg('chan', "Spot ignored, invalid date or out of range ($field[3] $field[4])\n");
341 if (grep $field[2] eq $_, @baddx) {
342 dbg('chan', "Bad DX spot, ignored");
347 $field[5] =~ s/^\s+//; # take any leading blanks off
348 if (Spot::dup($field[1], $field[2], $d, $field[5])) {
349 dbg('chan', "Duplicate Spot ignored\n");
353 my @spot = Spot::add($field[1], $field[2], $d, $field[5], $field[6], $field[7]);
356 # @spot at this point contains:-
357 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
358 # then spotted itu, spotted cq, spotters itu, spotters cq
359 # you should be able to route on any of these
362 # fix up qra locators of known users
363 my $user = DXUser->get_current($spot[4]);
365 my $qra = $user->qra;
366 unless ($qra && DXBearing::is_qra($qra)) {
367 my $lat = $user->lat;
368 my $long = $user->long;
369 if (defined $lat && defined $long) {
370 $user->qra(DXBearing::lltoqra($lat, $long));
375 # send a remote command to a distant cluster if it is visible and there is no
376 # qra locator and we havn't done it for a month.
378 unless ($user->qra) {
380 my $to = $user->homenode;
381 my $last = $user->lastoper || 0;
382 if ($send_opernam && $main::systime > $last + $DXUser::lastoperinterval && $to && ($node = DXCluster->get_exact($to)) ) {
383 my $cmd = "forward/opernam $spot[4]";
384 # send the rcmd but we aren't interested in the replies...
385 if ($node && $node->dxchan && $node->dxchan->is_clx) {
386 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
388 route(undef, $to, pc34($main::mycall, $to, $cmd));
390 if ($to ne $field[7]) {
392 $node = DXCluster->get_exact($to);
393 if ($node && $node->dxchan && $node->dxchan->is_clx) {
394 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
396 route(undef, $to, pc34($main::mycall, $to, $cmd));
399 $user->lastoper($main::systime);
408 $r = Local::spot($self, @spot);
410 # dbg('local', "Local::spot1 error $@") if $@;
413 # DON'T be silly and send on PC26s!
414 return if $pcno == 26;
416 # send out the filtered spots
417 send_dx_spot($self, $line, @spot) if @spot;
421 if ($pcno == 12) { # announces
422 # announce duplicate checking
423 $field[3] =~ s/^\s+//; # remove leading blanks
424 if (AnnTalk::dup($field[1], $field[2], $field[3])) {
425 dbg('chan', "Duplicate Announce ignored\n");
429 if ($field[2] eq '*' || $field[2] eq $main::mycall) {
431 # global ann filtering on INPUT
432 if ($self->{inannfilter}) {
433 my ($filter, $hops) = Filter::it($self->{inannfilter}, @field[1..6], $self->{call} );
435 dbg('chan', "Rejected by filter");
441 $self->send_announce($line, @field[1..6]);
443 $self->route($field[2], $line);
459 if ($pcno == 16) { # add a user
460 my $node = DXCluster->get_exact($field[1]);
462 if (!$node && ($dxchan = DXChannel->get($field[1]))) {
463 # add it to the node table if it isn't present and it's
465 $node = DXNode->new($dxchan, $field[1], 0, 1, 5400);
466 broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
469 return unless $node; # ignore if havn't seen a PC19 for this one yet
470 return unless $node->isa('DXNode');
471 if ($node->dxchan != $self) {
472 dbg('chan', "LOOP: $field[1] came in on wrong channel");
475 if (($dxchan = DXChannel->get($field[1])) && $dxchan != $self) {
476 dbg('chan', "LOOP: $field[1] connected locally");
481 for ($i = 2; $i < $#field; $i++) {
482 my ($call, $confmode, $here) = $field[$i] =~ /^(\S+) (\S) (\d)/o;
483 next if !$call || length $call < 3 || length $call > 8;
486 next if DXCluster->get_exact($call); # we already have this (loop?)
488 $confmode = $confmode eq '*';
489 DXNodeuser->new($self, $node, $call, $confmode, $here);
491 # add this station to the user database, if required
492 $call =~ s/-\d+$//o; # remove ssid for users
493 my $user = DXUser->get_current($call);
494 $user = DXUser->new($call) if !$user;
495 $user->homenode($node->call) if !$user->homenode;
496 $user->node($node->call);
497 $user->lastin($main::systime) unless DXChannel->get($call);
501 # queue up any messages (look for privates only)
502 DXMsg::queue_msg(1) if $self->state eq 'normal';
506 if ($pcno == 17) { # remove a user
507 my $node = DXCluster->get_exact($field[2]);
509 if (!$node && ($dxchan = DXChannel->get($field[2]))) {
510 # add it to the node table if it isn't present and it's
512 $node = DXNode->new($dxchan, $field[2], 0, 1, 5400);
513 broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
517 return unless $node->isa('DXNode');
518 if ($node->dxchan != $self) {
519 dbg('chan', "LOOP: $field[2] came in on wrong channel");
522 if (($dxchan = DXChannel->get($field[2])) && $dxchan != $self) {
523 dbg('chan', "LOOP: $field[2] connected locally");
526 my $ref = DXCluster->get_exact($field[1]);
531 if ($pcno == 18) { # link request
532 $self->state('init');
534 # first clear out any nodes on this dxchannel
535 my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
536 foreach my $node (@gonenodes) {
537 next if $node->dxchan == $DXProt::me;
538 broadcast_ak1a(pc21($node->call, 'Gone, re-init') , $self) unless $self->{isolate};
541 $self->send_local_config();
543 return; # we don't pass these on
546 if ($pcno == 19) { # incoming cluster list
548 my $newline = "PC19^";
549 for ($i = 1; $i < $#field-1; $i += 4) {
550 my $here = $field[$i];
551 my $call = uc $field[$i+1];
552 my $confmode = $field[$i+2];
553 my $ver = $field[$i+3];
555 $ver = 5400 if !$ver && $allowzero;
557 # now check the call over
558 my $node = DXCluster->get_exact($call);
561 if (($dxchan = DXChannel->get($call)) && $dxchan != $self) {
562 dbg('chan', "LOOP: $call connected locally");
564 if ($node->dxchan != $self) {
565 dbg('chan', "LOOP: $call come in on wrong channel");
568 dbg('chan', "already have $call");
572 # check for sane parameters
573 next if $ver < 5000; # only works with version 5 software
574 next if length $call < 3; # min 3 letter callsigns
576 # add it to the nodes table and outgoing line
577 $newline .= "$here^$call^$confmode^$ver^";
578 DXNode->new($self, $call, $confmode, $here, $ver);
580 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
581 my $mref = DXMsg::get_busy($call);
582 $mref->stop_msg($call) if $mref;
584 # add this station to the user database, if required (don't remove SSID from nodes)
585 my $user = DXUser->get_current($call);
587 $user = DXUser->new($call);
589 $user->priv(1); # I have relented and defaulted nodes
590 $self->{priv} = 1; # to user RCMDs allowed
591 $user->homenode($call);
594 $user->lastin($main::systime) unless DXChannel->get($call);
598 return if $newline eq "PC19^";
601 $newline .= get_hops(19) . "^";
606 if ($pcno == 20) { # send local configuration
607 $self->send_local_config();
609 $self->state('normal');
613 if ($pcno == 21) { # delete a cluster from the list
614 my $call = uc $field[1];
615 if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
616 my $node = DXCluster->get_exact($call);
618 if ($node->dxchan != $self) {
619 dbg('chan', "LOOP: $call come in on wrong channel");
623 if (($dxchan = DXChannel->get($call)) && $dxchan != $self) {
624 dbg('chan', "LOOP: $call connected locally");
629 dbg('chan', "$call not in table, dropped");
637 $self->state('normal');
641 if ($pcno == 23 || $pcno == 27) { # WWV info
643 # route 'foreign' pc27s
645 if ($field[8] ne $main::mycall) {
646 $self->route($field[8], $line);
652 my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
653 my $sfi = unpad($field[3]);
654 my $k = unpad($field[4]);
655 my $i = unpad($field[5]);
656 my ($r) = $field[6] =~ /R=(\d+)/;
658 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
659 dbg('chan', "WWV Date ($field[1] $field[2]) out of range");
662 if (Geomag::dup($d,$sfi,$k,$i,$field[6])) {
663 dbg('chan', "Dup WWV Spot ignored\n");
666 $field[7] =~ s/-\d+$//o; # remove spotter's ssid
668 my $wwv = Geomag::update($d, $field[2], $sfi, $k, $i, @field[6..8], $r);
672 $rep = Local::wwv($self, $field[1], $field[2], $sfi, $k, $i, @field[6..8], $r);
674 # dbg('local', "Local::wwv2 error $@") if $@;
677 # DON'T be silly and send on PC27s!
678 return if $pcno == 27;
680 # broadcast to the eager world
681 send_wwv_spot($self, $line, $d, $field[2], $sfi, $k, $i, @field[6..8]);
685 if ($pcno == 24) { # set here status
686 my $call = uc $field[1];
687 my $ref = DXCluster->get_exact($call);
688 $ref->here($field[2]) if $ref;
692 if ($pcno == 25) { # merge request
693 if ($field[1] ne $main::mycall) {
694 $self->route($field[1], $line);
697 if ($field[2] eq $main::mycall) {
698 dbg('chan', "Trying to merge to myself, ignored");
702 Log('DXProt', "Merge request for $field[3] spots and $field[4] WWV from $field[1]");
706 my @in = reverse Spot::search(1, undef, undef, 0, $field[3]);
709 $self->send(pc26(@{$in}[0..4], $field[2]));
715 my @in = reverse Geomag::search(0, $field[4], time, 1);
718 $self->send(pc27(@{$in}[0..5], $field[2]));
724 if (($pcno >= 28 && $pcno <= 33) || $pcno == 40 || $pcno == 42 || $pcno == 49) { # mail/file handling
725 if ($pcno == 49 || $field[1] eq $main::mycall) {
726 DXMsg::process($self, $line);
728 $self->route($field[1], $line);
733 if ($pcno == 34 || $pcno == 36) { # remote commands (incoming)
734 if ($field[1] eq $main::mycall) {
735 my $ref = DXUser->get_current($field[2]);
736 my $cref = DXCluster->get($field[2]);
737 Log('rcmd', 'in', $ref->{priv}, $field[2], $field[3]);
738 unless (!$cref || !$ref || $cref->mynode->call ne $ref->homenode) { # not allowed to relay RCMDS!
739 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
740 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
741 my $oldpriv = $self->{priv};
742 $self->{priv} = $ref->{priv}; # assume the user's privilege level
743 my @in = (DXCommandmode::run_cmd($self, $field[3]));
744 $self->{priv} = $oldpriv;
747 $self->send(pc35($main::mycall, $field[2], "$main::mycall:$_"));
748 Log('rcmd', 'out', $field[2], $_);
750 delete $self->{remotecmd};
752 $self->send(pc35($main::mycall, $field[2], "$main::mycall:sorry...!"));
755 $self->send(pc35($main::mycall, $field[2], "$main::mycall:your attempt is logged, Tut tut tut...!"));
758 my $ref = DXUser->get_current($field[1]);
759 if ($ref && $ref->is_clx) {
760 route($field[1], pc84($field[2], $field[1], $field[2], $field[3]));
762 $self->route($field[1], $line);
768 if ($pcno == 35) { # remote command replies
769 if ($field[1] eq $main::mycall) {
770 my $s = $rcmds{$field[2]};
772 my $dxchan = DXChannel->get($s->{call});
773 $dxchan->send($field[3]) if $dxchan;
774 delete $rcmds{$field[2]} if !$dxchan;
776 # send unsolicited ones to the sysop
777 my $dxchan = DXChannel->get($main::myalias);
778 $dxchan->send($field[3]) if $dxchan;
781 my $ref = DXUser->get_current($field[1]);
782 if ($ref && $ref->is_clx) {
783 route($field[1], pc85($field[2], $field[1], $field[2], $field[3]));
785 $self->route($field[1], $line);
791 # for pc 37 see 44 onwards
793 if ($pcno == 38) { # node connected list from neighbour
797 if ($pcno == 39) { # incoming disconnect
798 $self->disconnect(1);
802 if ($pcno == 41) { # user info
803 # add this station to the user database, if required
804 my $user = DXUser->get_current($field[1]);
806 # then try without an SSID
807 $field[1] =~ s/-\d+$//o;
808 $user = DXUser->get_current($field[1]);
810 $user = DXUser->new($field[1]) if !$user;
812 if ($field[2] == 1) {
813 $user->name($field[3]);
814 } elsif ($field[2] == 2) {
815 $user->qth($field[3]);
816 } elsif ($field[2] == 3) {
817 my ($lat, $long) = DXBearing::stoll($field[3]);
820 $user->qra(DXBearing::lltoqra($lat, $long)) unless $user->qra && DXBearing::is_qra($user->qra);
821 } elsif ($field[2] == 4) {
822 $user->homenode($field[3]);
824 $user->lastoper($main::systime); # to cut down on excessive for/opers being generated
831 if ($pcno == 37 || $pcno == 44 || $pcno == 45 || $pcno == 46 || $pcno == 47 || $pcno == 48) {
832 DXDb::process($self, $line);
836 if ($pcno == 50) { # keep alive/user list
837 my $node = DXCluster->get_exact($field[1]);
839 return unless $node->isa('DXNode');
840 return unless $node->dxchan == $self;
841 $node->update_users($field[2]);
846 if ($pcno == 51) { # incoming ping requests/answers
849 if ($field[1] eq $main::mycall) {
850 my $flag = $field[3];
852 $self->send(pc51($field[2], $field[1], '0'));
854 # it's a reply, look in the ping list for this one
855 my $ref = $pings{$field[2]};
857 my $tochan = DXChannel->get($field[2]);
860 my $dxchan = DXChannel->get($r->{call});
862 my $t = tv_interval($r->{t}, [ gettimeofday ]);
863 if ($dxchan->is_user) {
864 my $s = sprintf "%.2f", $t;
865 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
866 $dxchan->send($dxchan->msg('pingi', $field[2], $s, $ave))
867 } elsif ($dxchan->is_node) {
869 $tochan->{nopings} = 2; # pump up the timer
870 push @{$tochan->{pingtime}}, $t;
871 shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
873 for (@{$tochan->{pingtime}}) {
876 $tochan->{pingave} = $st / @{$tochan->{pingtime}};
883 # route down an appropriate thingy
884 $self->route($field[1], $line);
889 if ($pcno == 73) { # WCY broadcasts
892 my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
893 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
894 dbg('chan', "WCY Date ($field[1] $field[2]) out of range");
897 @field = map { unpad($_) } @field;
898 if (WCY::dup($d,@field[3..7])) {
899 dbg('chan', "Dup WCY Spot ignored\n");
903 my $wcy = WCY::update($d, @field[2..12]);
907 $rep = Local::wwv($self, @field[1..12]);
909 # dbg('local', "Local::wcy error $@") if $@;
912 # broadcast to the eager world
913 send_wcy_spot($self, $line, $d, @field[2..12]);
917 if ($pcno == 84) { # remote commands (incoming)
918 if ($field[1] eq $main::mycall) {
919 my $ref = DXUser->get_current($field[2]);
920 my $cref = DXCluster->get($field[2]);
921 Log('rcmd', 'in', $ref->{priv}, $field[2], $field[4]);
922 unless ($field[4] =~ /rcmd/i || !$cref || !$ref || $cref->mynode->call ne $ref->homenode) { # not allowed to relay RCMDS!
923 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
924 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
925 my $oldpriv = $self->{priv};
926 $self->{priv} = $ref->{priv}; # assume the user's privilege level
927 my @in = (DXCommandmode::run_cmd($self, $field[4]));
928 $self->{priv} = $oldpriv;
931 $self->send(pc85($main::mycall, $field[2], $field[3], "$main::mycall:$_"));
932 Log('rcmd', 'out', $field[2], $_);
934 delete $self->{remotecmd};
936 $self->send(pc85($main::mycall, $field[2], $field[3], "$main::mycall:sorry...!"));
939 $self->send(pc85($main::mycall, $field[2], $field[3],"$main::mycall:your attempt is logged, Tut tut tut...!"));
942 my $ref = DXUser->get_current($field[1]);
943 if ($ref && $ref->is_clx) {
944 $self->route($field[1], $line);
946 route($field[1], pc34($field[2], $field[1], $field[4]));
952 if ($pcno == 85) { # remote command replies
953 if ($field[1] eq $main::mycall) {
954 my $dxchan = DXChannel->get($field[3]);
956 $dxchan->send($field[4]);
958 my $s = $rcmds{$field[2]};
960 $dxchan = DXChannel->get($s->{call});
961 $dxchan->send($field[4]) if $dxchan;
962 delete $rcmds{$field[2]} if !$dxchan;
964 # send unsolicited ones to the sysop
965 my $dxchan = DXChannel->get($main::myalias);
966 $dxchan->send($field[4]) if $dxchan;
970 my $ref = DXUser->get_current($field[1]);
971 if ($ref && $ref->is_clx) {
972 $self->route($field[1], $line);
974 route($field[1], pc35($field[2], $field[1], $field[4]));
981 # if get here then rebroadcast the thing with its Hop count decremented (if
982 # there is one). If it has a hop count and it decrements to zero then don't
985 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
989 unless ($self->{isolate}) {
990 broadcast_ak1a($line, $self); # send it to everyone but me
995 # This is called from inside the main cluster processing loop and is used
996 # for despatching commands that are doing some long processing job
1001 my @dxchan = DXChannel->get_all();
1004 foreach $dxchan (@dxchan) {
1005 next unless $dxchan->is_node();
1006 next if $dxchan == $me;
1008 # send a pc50 out on this channel
1009 if ($t >= $dxchan->pc50_t + $DXProt::pc50_interval) {
1010 $dxchan->send(pc50(scalar DXChannel::get_all_users));
1011 $dxchan->pc50_t($t);
1014 # send a ping out on this channel
1015 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
1016 if ($dxchan->{nopings} <= 0) {
1017 $dxchan->disconnect;
1019 addping($main::mycall, $dxchan->call);
1020 $dxchan->{nopings} -= 1;
1021 $dxchan->{lastping} = $t;
1029 if ($main::systime - 3600 > $last_hour) {
1033 $last_hour = $main::systime;
1038 # finish up a pc context
1043 my $call = $self->call;
1045 my $ref = DXCluster->get_exact($call);
1047 # unbusy and stop and outgoing mail
1048 my $mref = DXMsg::get_busy($call);
1049 $mref->stop_msg($call) if $mref;
1051 # broadcast to all other nodes that all the nodes connected to via me are gone
1052 my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
1055 foreach $node (@gonenodes) {
1056 next if $node->call eq $call;
1057 broadcast_ak1a(pc21($node->call, 'Gone') , $self) unless $self->{isolate};
1061 # remove outstanding pings
1062 delete $pings{$call};
1064 # now broadcast to all other ak1a nodes that I have gone
1065 broadcast_ak1a(pc21($call, 'Gone.'), $self) unless $self->{isolate};
1067 # I was the last node visited
1068 $self->user->node($main::mycall);
1070 # send info to all logged in thingies
1071 $self->tell_login('logoutn');
1073 Log('DXProt', $call . " Disconnected");
1074 $ref->del() if $ref;
1078 # some active measures
1084 my @dxchan = DXChannel->get_all();
1087 # send it if it isn't the except list and isn't isolated and still has a hop count
1088 # taking into account filtering and so on
1089 foreach $dxchan (@dxchan) {
1091 my ($filter, $hops);
1093 if ($dxchan->{spotfilter}) {
1094 ($filter, $hops) = Filter::it($dxchan->{spotfilter}, @_, $self->{call} );
1095 next unless $filter;
1098 if ($dxchan->is_node) {
1099 next if $dxchan == $self;
1102 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1104 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1105 next unless $routeit;
1108 $dxchan->send($routeit) if $routeit;
1110 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1112 } elsif ($dxchan->is_user && $dxchan->{dx}) {
1113 my $buf = Spot::formatb($dxchan->{user}->wantgrid, $_[0], $_[1], $_[2], $_[3], $_[4]);
1114 $buf .= "\a\a" if $dxchan->{beep};
1115 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'talk') {
1116 $dxchan->send($buf);
1118 $dxchan->delay($buf);
1128 my @dxchan = DXChannel->get_all();
1131 # send it if it isn't the except list and isn't isolated and still has a hop count
1132 # taking into account filtering and so on
1133 foreach $dxchan (@dxchan) {
1135 my ($filter, $hops);
1137 if ($dxchan->{wwvfilter}) {
1138 ($filter, $hops) = Filter::it($dxchan->{wwvfilter}, @_, $self->{call} );
1139 next unless $filter;
1141 if ($dxchan->is_node) {
1142 next if $dxchan == $self;
1145 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1147 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1148 next unless $routeit;
1151 $dxchan->send($routeit) if $routeit;
1153 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1156 } elsif ($dxchan->is_user && $dxchan->{wwv}) {
1157 my $buf = "WWV de $_[6] <$_[1]>: SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
1158 $buf .= "\a\a" if $dxchan->{beep};
1159 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'talk') {
1160 $dxchan->send($buf);
1162 $dxchan->delay($buf);
1172 my @dxchan = DXChannel->get_all();
1175 # send it if it isn't the except list and isn't isolated and still has a hop count
1176 # taking into account filtering and so on
1177 foreach $dxchan (@dxchan) {
1179 my ($filter, $hops);
1181 if ($dxchan->{wcyfilter}) {
1182 ($filter, $hops) = Filter::it($dxchan->{wcyfilter}, @_, $self->{call} );
1183 next unless $filter;
1185 if ($dxchan->is_clx || $dxchan->is_spider) {
1186 next if $dxchan == $self;
1189 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1191 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1192 next unless $routeit;
1195 $dxchan->send($routeit) if $routeit;
1197 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1199 } elsif ($dxchan->is_user && $dxchan->{wcy}) {
1200 my $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
1201 $buf .= "\a\a" if $dxchan->{beep};
1202 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'talk') {
1203 $dxchan->send($buf);
1205 $dxchan->delay($buf);
1216 my @dxchan = DXChannel->get_all();
1218 my $text = unpad($_[2]);
1222 if ($_[3] eq '*') { # sysops
1224 } elsif ($_[3] gt ' ') { # speciality list handling
1225 my ($name) = split /\./, $_[3];
1226 $target = "$name"; # put the rest in later (if bothered)
1233 $target = "All" if !$target;
1235 Log('ann', $target, $_[0], $text);
1237 # send it if it isn't the except list and isn't isolated and still has a hop count
1238 # taking into account filtering and so on
1239 foreach $dxchan (@dxchan) {
1241 my ($filter, $hops);
1243 if ($dxchan->{annfilter}) {
1244 ($filter, $hops) = Filter::it($dxchan->{annfilter}, @_, $self->{call} );
1245 next unless $filter;
1247 if ($dxchan->is_node && $_[1] ne $main::mycall) { # i.e not specifically routed to me
1248 next if $dxchan == $self;
1251 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1253 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1254 next unless $routeit;
1257 $dxchan->send($routeit) if $routeit;
1259 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1262 } elsif ($dxchan->is_user && $dxchan->{ann}) {
1263 next if $target eq 'SYSOP' && $dxchan->{priv} < 5;
1264 my $buf = "$to$target de $_[0]: $text";
1265 $buf .= "\a\a" if $dxchan->{beep};
1266 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'talk') {
1267 $dxchan->send($buf);
1269 $dxchan->delay($buf);
1275 sub send_local_config
1284 if ($self->{isolate}) {
1285 @localnodes = (DXCluster->get_exact($main::mycall));
1287 # create a list of all the nodes that are not connected to this connection
1288 # and are not themselves isolated, this to make sure that isolated nodes
1289 # don't appear outside of this node
1290 @nodes = DXNode::get_all();
1291 @nodes = grep { $_->{call} ne $main::mycall } @nodes;
1292 @nodes = grep { $_->dxchan != $self } @nodes if @nodes;
1293 @nodes = grep { !$_->dxchan->{isolate} } @nodes if @nodes;
1294 @localnodes = grep { $_->dxchan->{call} eq $_->{call} } @nodes if @nodes;
1295 unshift @localnodes, DXCluster->get_exact($main::mycall);
1296 @remotenodes = grep { $_->dxchan->{call} ne $_->{call} } @nodes if @nodes;
1299 my @s = $me->pc19(@localnodes, @remotenodes);
1301 my $routeit = adjust_hops($self, $_);
1302 $self->send($routeit) if $routeit;
1305 # get all the users connected on the above nodes and send them out
1306 foreach $n (@localnodes, @remotenodes) {
1307 my @users = values %{$n->list};
1308 my @s = pc16($n, @users);
1310 my $routeit = adjust_hops($self, $_);
1311 $self->send($routeit) if $routeit;
1317 # route a message down an appropriate interface for a callsign
1319 # is called route(to, pcline);
1323 my ($self, $call, $line) = @_;
1324 my $cl = DXCluster->get_exact($call);
1325 if ($cl) { # don't route it back down itself
1326 if (ref $self && $call eq $self->{call}) {
1327 dbg('chan', "Trying to route back to source, dropped");
1331 my $dxchan = $cl->{dxchan};
1333 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1335 $dxchan->send($routeit) if $dxchan;
1341 # broadcast a message to all clusters taking into account isolation
1342 # [except those mentioned after buffer]
1345 my $s = shift; # the line to be rebroadcast
1346 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1347 my @dxchan = DXChannel::get_all_ak1a();
1350 # send it if it isn't the except list and isn't isolated and still has a hop count
1351 foreach $dxchan (@dxchan) {
1352 next if grep $dxchan == $_, @except;
1353 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1354 $dxchan->send($routeit) unless $dxchan->{isolate} || !$routeit;
1358 # broadcast a message to all clusters ignoring isolation
1359 # [except those mentioned after buffer]
1360 sub broadcast_all_ak1a
1362 my $s = shift; # the line to be rebroadcast
1363 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1364 my @dxchan = DXChannel::get_all_ak1a();
1367 # send it if it isn't the except list and isn't isolated and still has a hop count
1368 foreach $dxchan (@dxchan) {
1369 next if grep $dxchan == $_, @except;
1370 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1371 $dxchan->send($routeit);
1375 # broadcast to all users
1376 # storing the spot or whatever until it is in a state to receive it
1379 my $s = shift; # the line to be rebroadcast
1380 my $sort = shift; # the type of transmission
1381 my $fref = shift; # a reference to an object to filter on
1382 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1383 my @dxchan = DXChannel::get_all_users();
1387 foreach $dxchan (@dxchan) {
1388 next if grep $dxchan == $_, @except;
1391 broadcast_list($s, $sort, $fref, @out);
1394 # broadcast to a list of users
1402 foreach $dxchan (@_) {
1405 if ($sort eq 'dx') {
1406 next unless $dxchan->{dx};
1407 ($filter) = Filter::it($dxchan->{spotfilter}, @{$fref}) if ref $fref;
1408 next unless $filter;
1410 next if $sort eq 'ann' && !$dxchan->{ann};
1411 next if $sort eq 'wwv' && !$dxchan->{wwv};
1412 next if $sort eq 'wcy' && !$dxchan->{wcy};
1413 next if $sort eq 'wx' && !$dxchan->{wx};
1415 $s =~ s/\a//og unless $dxchan->{beep};
1417 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'talk') {
1427 # obtain the hops from the list for this callsign and pc no
1433 my $hops = $DXProt::hopcount{$pcno};
1434 $hops = $DXProt::def_hopcount if !$hops;
1439 # adjust the hop count on a per node basis using the user loadable
1440 # hop table if available or else decrement an existing one
1447 my $call = $self->{call};
1450 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
1451 my ($pcno) = $s =~ /^PC(\d\d)/o;
1452 confess "$call called adjust_hops with '$s'" unless $pcno;
1453 my $ref = $nodehops{$call} if %nodehops;
1455 my $newhops = $ref->{$pcno};
1456 return "" if defined $newhops && $newhops == 0;
1457 $newhops = $ref->{default} unless $newhops;
1458 return "" if defined $newhops && $newhops == 0;
1459 $newhops = $hops if !$newhops;
1460 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1462 # simply decrement it
1464 return "" if !$hops;
1465 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
1477 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
1478 do "$main::data/hop_table.pl";
1484 # add a ping request to the ping queues
1487 my ($from, $to) = @_;
1488 my $ref = $pings{$to} || [];
1491 $r->{t} = [ gettimeofday ];
1492 route(undef, $to, pc51($to, $main::mycall, 1));
1497 # add a rcmd request to the rcmd queues
1500 my ($self, $to, $cmd) = @_;
1503 $r->{call} = $self->{call};
1504 $r->{t} = $main::systime;
1508 my $ref = DXCluster->get_exact($to);
1509 if ($ref && $ref->dxchan && $ref->dxchan->is_clx) {
1510 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1512 route(undef, $to, pc34($main::mycall, $to, $cmd));
1521 if ($self->{conn} && !$nopc39) {
1522 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1525 $self->SUPER::disconnect;
1530 # send a talk message to this thingy
1534 my ($self, $from, $to, $via, $line) = @_;
1536 $line =~ s/\^/\\5E/g; # remove any ^ characters
1537 $self->send(DXProt::pc10($from, $to, $via, $line));
1538 Log('talk', $self->call, $from, $via?$via:$main::mycall, $line);