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);
35 use vars qw($me $pc11_max_age $pc23_max_age
36 $last_hour %pings %rcmds
37 %nodehops @baddx $baddxfn
38 $allowzero $decode_dk0wcy $send_opernam @checklist);
40 $me = undef; # the channel id for this cluster
41 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
42 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
44 $last_hour = time; # last time I did an hourly periodic update
45 %pings = (); # outstanding ping requests outbound
46 %rcmds = (); # outstanding rcmd requests outbound
47 %nodehops = (); # node specific hop control
48 @baddx = (); # list of illegal spotted callsigns
51 $baddxfn = "$main::data/baddx.pl";
55 [ qw(c c m bp bc c) ], # pc10
56 [ qw(f m d t m c c h) ], # pc11
57 [ qw(c bc m bp bm p h) ], # pc12
61 undef , # pc16 has to be validated manually
64 undef , # pc19 has to be validated manually
65 undef , # pc20 no validation
67 undef , # pc22 no validation
68 [ qw(d n n n n m c c h) ], # pc23
70 [ qw(c c n n) ], # pc25
71 [ qw(f m d t m c c bc) ], # pc26
72 [ qw(d n n n n m c c bc) ], # pc27
73 [ qw(c c c c d t p m bp n p bp bc) ], # pc28
74 [ qw(c c n m) ], # pc29
82 [ qw(c c n m) ], # pc37
83 undef, # pc38 not interested
85 [ qw(c c m p n) ], # pc40
86 [ qw(c n m h) ], # pc41
88 undef, # pc43 don't handle it
89 [ qw(c c n m m c) ], # pc44
90 [ qw(c c n m) ], # pc45
118 [ qw(d n n n n n n m m m c c h) ], # pc73
129 [ qw(c c c m) ], # pc84
130 [ qw(c c c m) ], # pc85
133 # use the entry in the check list to check the field list presented
134 # return OK if line NOT in check list (for now)
139 return 0 if $n < 0 || $n > @checklist;
140 my $ref = $checklist[$n];
141 return 0 unless ref $ref;
144 shift; # not interested in the first field
145 for ($i = 0; $i < @$ref; $i++) {
146 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
147 return 0 unless $act;
148 next if $blank && $_[$i] =~ /^[ \*]$/;
150 return $i+1 unless is_callsign($_[$i]);
151 } elsif ($act eq 'm') {
152 return $i+1 unless is_pctext($_[$i]);
153 } elsif ($act eq 'p') {
154 return $i+1 unless is_pcflag($_[$i]);
155 } elsif ($act eq 'f') {
156 return $i+1 unless is_freq($_[$i]);
157 } elsif ($act eq 'n') {
158 return $i+1 unless $_[$i] =~ /^[\d ]+$/;
159 } elsif ($act eq 'h') {
160 return $i+1 unless $_[$i] =~ /^H\d\d?$/;
161 } elsif ($act eq 'd') {
162 return $i+1 unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
163 } elsif ($act eq 't') {
164 return $i+1 unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
172 my $user = DXUser->get($main::mycall);
173 $DXProt::myprot_version += $main::version*100;
174 $me = DXProt->new($main::mycall, 0, $user);
176 $me->{state} = "indifferent";
177 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
179 $me->{sort} = 'S'; # S for spider
181 # now prime the spot and wwv duplicates file with data
182 # my @today = Julian::unixtoj(time);
183 # for (Spot::readfile(@today), Spot::readfile(Julian::sub(@today, 1))) {
184 # Spot::dup(@{$_}[0..3]);
186 # for (Geomag::readfile(time)) {
187 # Geomag::dup(@{$_}[1..5]);
190 # load the baddx file
191 do "$baddxfn" if -e "$baddxfn";
196 # obtain a new connection this is derived from dxchannel
201 my $self = DXChannel::alloc(@_);
205 # this is how a pc connection starts (for an incoming connection)
206 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
207 # all the crap that comes between).
210 my ($self, $line, $sort) = @_;
211 my $call = $self->{call};
212 my $user = $self->{user};
214 # remember type of connection
215 $self->{consort} = $line;
216 $self->{outbound} = $sort eq 'O';
217 $self->{priv} = $user->priv || 1; # other clusters can always be 'normal' users
218 $self->{lang} = $user->lang || 'en';
219 $self->{isolate} = $user->{isolate};
220 $self->{consort} = $line; # save the connection type
223 # get the INPUT filters (these only pertain to Clusters)
224 $self->{inspotfilter} = Filter::read_in('spots', $call, 1);
225 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1);
226 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1);
227 $self->{inannfilter} = Filter::read_in('ann', $call, 1);
229 # set unbuffered and no echo
230 $self->send_now('B',"0");
231 $self->send_now('E',"0");
233 # ping neighbour node stuff
234 my $ping = $user->pingint;
235 $ping = 5*60 unless defined $ping;
236 $self->{pingint} = $ping;
237 $self->{nopings} = $user->nopings || 2;
238 $self->{pingtime} = [ ];
239 $self->{pingave} = 0;
241 # send initialisation string
242 unless ($self->{outbound}) {
243 # $self->send(pc38()) if DXNode->get_all();
245 $self->{lastping} = $main::systime;
247 # remove from outstanding connects queue
248 @main::outstanding_connects = grep {$_->{call} ne $call} @main::outstanding_connects;
249 $self->{lastping} = $main::systime + $self->pingint / 2;
251 $self->state('init');
254 # send info to all logged in thingies
255 $self->tell_login('loginn');
257 Log('DXProt', "$call connected");
261 # This is the normal pcxx despatcher
265 my ($self, $line) = @_;
266 my @field = split /\^/, $line;
267 return unless @field;
269 pop @field if $field[-1] eq '~';
271 # print join(',', @field), "\n";
273 # ignore any lines that don't start with PC
274 return if !$field[0] =~ /^PC/;
277 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
279 return if $pcno < 10 || $pcno > 99;
281 # check for and dump bad protocol messages
282 my $n = check($pcno, @field);
284 dbg('chan', "bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")");
291 $pcr = Local::pcprot($self, $pcno, @field);
293 # dbg('local', "Local::pcprot error $@") if $@;
297 if ($pcno == 10) { # incoming talk
299 # will we allow it at all?
301 if (@bad = BadWords::check($field[3])) {
302 dbg('chan', "Bad words: @bad, dropped" );
306 # is it for me or one of mine?
307 my ($to, $via, $call, $dxchan);
308 if ($field[5] gt ' ') {
309 $call = $via = $field[2];
312 $call = $to = $field[2];
314 $dxchan = DXChannel->get($call);
315 if ($dxchan && $dxchan->is_user) {
316 $field[3] =~ s/\%5E/^/g;
317 $dxchan->talk($field[1], $to, $via, $field[3]);
319 $self->route($field[2], $line); # relay it on its way
324 if ($pcno == 11 || $pcno == 26) { # dx spot
326 # route 'foreign' pc26s
328 if ($field[7] ne $main::mycall) {
329 $self->route($field[7], $line);
334 # if this is a 'nodx' node then ignore it
335 if (grep $field[7] =~ /^$_/, @DXProt::nodx_node) {
336 dbg('chan', "Bad DXNode, dropped");
340 # convert the date to a unix date
341 my $d = cltounix($field[3], $field[4]);
342 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
343 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
344 dbg('chan', "Spot ignored, invalid date or out of range ($field[3] $field[4])\n");
349 if (grep $field[2] eq $_, @baddx) {
350 dbg('chan', "Bad DX spot, ignored");
355 $field[5] =~ s/^\s+//; # take any leading blanks off
356 if (Spot::dup($field[1], $field[2], $d, $field[5])) {
357 dbg('chan', "Duplicate Spot ignored\n");
361 if (@bad = BadWords::check($field[5])) {
362 dbg('chan', "Bad words: @bad, dropped" );
366 my @spot = Spot::add($field[1], $field[2], $d, $field[5], $field[6], $field[7]);
369 # @spot at this point contains:-
370 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
371 # then spotted itu, spotted cq, spotters itu, spotters cq
372 # you should be able to route on any of these
375 # fix up qra locators of known users
376 my $user = DXUser->get_current($spot[4]);
378 my $qra = $user->qra;
379 unless ($qra && DXBearing::is_qra($qra)) {
380 my $lat = $user->lat;
381 my $long = $user->long;
382 if (defined $lat && defined $long) {
383 $user->qra(DXBearing::lltoqra($lat, $long));
388 # send a remote command to a distant cluster if it is visible and there is no
389 # qra locator and we havn't done it for a month.
391 unless ($user->qra) {
393 my $to = $user->homenode;
394 my $last = $user->lastoper || 0;
395 if ($send_opernam && $main::systime > $last + $DXUser::lastoperinterval && $to && ($node = DXCluster->get_exact($to)) ) {
396 my $cmd = "forward/opernam $spot[4]";
397 # send the rcmd but we aren't interested in the replies...
398 if ($node && $node->dxchan && $node->dxchan->is_clx) {
399 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
401 route(undef, $to, pc34($main::mycall, $to, $cmd));
403 if ($to ne $field[7]) {
405 $node = DXCluster->get_exact($to);
406 if ($node && $node->dxchan && $node->dxchan->is_clx) {
407 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
409 route(undef, $to, pc34($main::mycall, $to, $cmd));
412 $user->lastoper($main::systime);
421 $r = Local::spot($self, @spot);
423 # dbg('local', "Local::spot1 error $@") if $@;
426 # DON'T be silly and send on PC26s!
427 return if $pcno == 26;
429 # send out the filtered spots
430 send_dx_spot($self, $line, @spot) if @spot;
434 if ($pcno == 12) { # announces
435 # announce duplicate checking
436 $field[3] =~ s/^\s+//; # remove leading blanks
437 if (AnnTalk::dup($field[1], $field[2], $field[3])) {
438 dbg('chan', "Duplicate Announce ignored");
443 if (@bad = BadWords::check($field[3])) {
444 dbg('chan', "Bad words: @bad, dropped" );
447 if ($field[2] eq '*' || $field[2] eq $main::mycall) {
449 # global ann filtering on INPUT
450 if ($self->{inannfilter}) {
451 my ($filter, $hops) = Filter::it($self->{inannfilter}, @field[1..6], $self->{call} );
453 dbg('chan', "Rejected by filter");
459 $self->send_announce($line, @field[1..6]);
461 $self->route($field[2], $line);
477 if ($pcno == 16) { # add a user
478 my $node = DXCluster->get_exact($field[1]);
480 if (!$node && ($dxchan = DXChannel->get($field[1]))) {
481 # add it to the node table if it isn't present and it's
483 $node = DXNode->new($dxchan, $field[1], 0, 1, 5400);
484 broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
487 return unless $node; # ignore if havn't seen a PC19 for this one yet
488 return unless $node->isa('DXNode');
489 if ($node->dxchan != $self) {
490 dbg('chan', "LOOP: $field[1] came in on wrong channel");
493 if (($dxchan = DXChannel->get($field[1])) && $dxchan != $self) {
494 dbg('chan', "LOOP: $field[1] connected locally");
499 for ($i = 2; $i < $#field; $i++) {
500 my ($call, $confmode, $here) = $field[$i] =~ /^(\S+) (\S) (\d)/o;
501 next if !$call || length $call < 3 || length $call > 8;
504 next if DXCluster->get_exact($call); # we already have this (loop?)
506 $confmode = $confmode eq '*';
507 DXNodeuser->new($self, $node, $call, $confmode, $here);
509 # add this station to the user database, if required
510 $call =~ s/-\d+$//o; # remove ssid for users
511 my $user = DXUser->get_current($call);
512 $user = DXUser->new($call) if !$user;
513 $user->homenode($node->call) if !$user->homenode;
514 $user->node($node->call);
515 $user->lastin($main::systime) unless DXChannel->get($call);
519 # queue up any messages (look for privates only)
520 DXMsg::queue_msg(1) if $self->state eq 'normal';
524 if ($pcno == 17) { # remove a user
525 my $node = DXCluster->get_exact($field[2]);
527 if (!$node && ($dxchan = DXChannel->get($field[2]))) {
528 # add it to the node table if it isn't present and it's
530 $node = DXNode->new($dxchan, $field[2], 0, 1, 5400);
531 broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
535 return unless $node->isa('DXNode');
536 if ($node->dxchan != $self) {
537 dbg('chan', "LOOP: $field[2] came in on wrong channel");
540 if (($dxchan = DXChannel->get($field[2])) && $dxchan != $self) {
541 dbg('chan', "LOOP: $field[2] connected locally");
544 my $ref = DXCluster->get_exact($field[1]);
549 if ($pcno == 18) { # link request
550 $self->state('init');
552 # first clear out any nodes on this dxchannel
553 my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
554 foreach my $node (@gonenodes) {
555 next if $node->dxchan == $DXProt::me;
556 broadcast_ak1a(pc21($node->call, 'Gone, re-init') , $self) unless $self->{isolate};
559 $self->send_local_config();
561 return; # we don't pass these on
564 if ($pcno == 19) { # incoming cluster list
566 my $newline = "PC19^";
567 for ($i = 1; $i < $#field-1; $i += 4) {
568 my $here = $field[$i];
569 my $call = uc $field[$i+1];
570 my $confmode = $field[$i+2];
571 my $ver = $field[$i+3];
573 $ver = 5400 if !$ver && $allowzero;
575 # now check the call over
576 my $node = DXCluster->get_exact($call);
579 if (($dxchan = DXChannel->get($call)) && $dxchan != $self) {
580 dbg('chan', "LOOP: $call connected locally");
582 if ($node->dxchan != $self) {
583 dbg('chan', "LOOP: $call come in on wrong channel");
586 dbg('chan', "already have $call");
590 # check for sane parameters
591 next if $ver < 5000; # only works with version 5 software
592 next if length $call < 3; # min 3 letter callsigns
594 # add it to the nodes table and outgoing line
595 $newline .= "$here^$call^$confmode^$ver^";
596 DXNode->new($self, $call, $confmode, $here, $ver);
598 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
599 my $mref = DXMsg::get_busy($call);
600 $mref->stop_msg($call) if $mref;
602 # add this station to the user database, if required (don't remove SSID from nodes)
603 my $user = DXUser->get_current($call);
605 $user = DXUser->new($call);
607 $user->priv(1); # I have relented and defaulted nodes
608 $self->{priv} = 1; # to user RCMDs allowed
609 $user->homenode($call);
612 $user->lastin($main::systime) unless DXChannel->get($call);
616 return if $newline eq "PC19^";
619 $newline .= get_hops(19) . "^";
624 if ($pcno == 20) { # send local configuration
625 $self->send_local_config();
627 $self->state('normal');
631 if ($pcno == 21) { # delete a cluster from the list
632 my $call = uc $field[1];
633 if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
634 my $node = DXCluster->get_exact($call);
636 if ($call eq $self->{call}) {
637 dbg('chan', "LOOP: Trying to disconnect myself with PC21");
640 if ($node->dxchan != $self) {
641 dbg('chan', "LOOP: $call come in on wrong channel");
645 if ($dxchan = DXChannel->get($call)) {
646 dbg('chan', "LOOP: $call connected locally");
651 dbg('chan', "$call not in table, dropped");
659 $self->state('normal');
663 if ($pcno == 23 || $pcno == 27) { # WWV info
665 # route 'foreign' pc27s
667 if ($field[8] ne $main::mycall) {
668 $self->route($field[8], $line);
674 my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
675 my $sfi = unpad($field[3]);
676 my $k = unpad($field[4]);
677 my $i = unpad($field[5]);
678 my ($r) = $field[6] =~ /R=(\d+)/;
680 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
681 dbg('chan', "WWV Date ($field[1] $field[2]) out of range");
684 if (Geomag::dup($d,$sfi,$k,$i,$field[6])) {
685 dbg('chan', "Dup WWV Spot ignored\n");
688 $field[7] =~ s/-\d+$//o; # remove spotter's ssid
690 my $wwv = Geomag::update($d, $field[2], $sfi, $k, $i, @field[6..8], $r);
694 $rep = Local::wwv($self, $field[1], $field[2], $sfi, $k, $i, @field[6..8], $r);
696 # dbg('local', "Local::wwv2 error $@") if $@;
699 # DON'T be silly and send on PC27s!
700 return if $pcno == 27;
702 # broadcast to the eager world
703 send_wwv_spot($self, $line, $d, $field[2], $sfi, $k, $i, @field[6..8]);
707 if ($pcno == 24) { # set here status
708 my $call = uc $field[1];
709 my $ref = DXCluster->get_exact($call);
710 $ref->here($field[2]) if $ref;
714 if ($pcno == 25) { # merge request
715 if ($field[1] ne $main::mycall) {
716 $self->route($field[1], $line);
719 if ($field[2] eq $main::mycall) {
720 dbg('chan', "Trying to merge to myself, ignored");
724 Log('DXProt', "Merge request for $field[3] spots and $field[4] WWV from $field[1]");
728 my @in = reverse Spot::search(1, undef, undef, 0, $field[3]);
731 $self->send(pc26(@{$in}[0..4], $field[2]));
737 my @in = reverse Geomag::search(0, $field[4], time, 1);
740 $self->send(pc27(@{$in}[0..5], $field[2]));
746 if (($pcno >= 28 && $pcno <= 33) || $pcno == 40 || $pcno == 42 || $pcno == 49) { # mail/file handling
747 if ($pcno == 49 || $field[1] eq $main::mycall) {
748 DXMsg::process($self, $line);
750 $self->route($field[1], $line) unless $self->is_clx;
755 if ($pcno == 34 || $pcno == 36) { # remote commands (incoming)
756 if ($field[1] eq $main::mycall) {
757 my $ref = DXUser->get_current($field[2]);
758 my $cref = DXCluster->get($field[2]);
759 Log('rcmd', 'in', $ref->{priv}, $field[2], $field[3]);
760 unless (!$cref || !$ref || $cref->mynode->call ne $ref->homenode) { # not allowed to relay RCMDS!
761 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
762 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
763 my $oldpriv = $self->{priv};
764 $self->{priv} = $ref->{priv}; # assume the user's privilege level
765 my @in = (DXCommandmode::run_cmd($self, $field[3]));
766 $self->{priv} = $oldpriv;
769 $self->send(pc35($main::mycall, $field[2], "$main::mycall:$_"));
770 Log('rcmd', 'out', $field[2], $_);
772 delete $self->{remotecmd};
774 $self->send(pc35($main::mycall, $field[2], "$main::mycall:sorry...!"));
777 $self->send(pc35($main::mycall, $field[2], "$main::mycall:your attempt is logged, Tut tut tut...!"));
780 my $ref = DXUser->get_current($field[1]);
781 if ($ref && $ref->is_clx) {
782 route($field[1], pc84($field[2], $field[1], $field[2], $field[3]));
784 $self->route($field[1], $line);
790 if ($pcno == 35) { # remote command replies
791 if ($field[1] eq $main::mycall) {
792 my $s = $rcmds{$field[2]};
794 my $dxchan = DXChannel->get($s->{call});
795 $dxchan->send($field[3]) if $dxchan;
796 delete $rcmds{$field[2]} if !$dxchan;
798 # send unsolicited ones to the sysop
799 my $dxchan = DXChannel->get($main::myalias);
800 $dxchan->send($field[3]) if $dxchan;
803 my $ref = DXUser->get_current($field[1]);
804 if ($ref && $ref->is_clx) {
805 route($field[1], pc85($field[2], $field[1], $field[2], $field[3]));
807 $self->route($field[1], $line);
813 # for pc 37 see 44 onwards
815 if ($pcno == 38) { # node connected list from neighbour
819 if ($pcno == 39) { # incoming disconnect
820 $self->disconnect(1);
824 if ($pcno == 41) { # user info
825 # add this station to the user database, if required
826 my $user = DXUser->get_current($field[1]);
828 # then try without an SSID
829 $field[1] =~ s/-\d+$//o;
830 $user = DXUser->get_current($field[1]);
832 $user = DXUser->new($field[1]) if !$user;
834 if ($field[2] == 1) {
835 $user->name($field[3]);
836 } elsif ($field[2] == 2) {
837 $user->qth($field[3]);
838 } elsif ($field[2] == 3) {
839 my ($lat, $long) = DXBearing::stoll($field[3]);
842 $user->qra(DXBearing::lltoqra($lat, $long)) unless $user->qra && DXBearing::is_qra($user->qra);
843 } elsif ($field[2] == 4) {
844 $user->homenode($field[3]);
846 $user->lastoper($main::systime); # to cut down on excessive for/opers being generated
853 if ($pcno == 37 || $pcno == 44 || $pcno == 45 || $pcno == 46 || $pcno == 47 || $pcno == 48) {
854 DXDb::process($self, $line);
858 if ($pcno == 50) { # keep alive/user list
859 my $node = DXCluster->get_exact($field[1]);
861 return unless $node->isa('DXNode');
862 return unless $node->dxchan == $self;
863 $node->update_users($field[2]);
868 if ($pcno == 51) { # incoming ping requests/answers
871 if ($field[1] eq $main::mycall) {
872 my $flag = $field[3];
874 $self->send(pc51($field[2], $field[1], '0'));
876 # it's a reply, look in the ping list for this one
877 my $ref = $pings{$field[2]};
879 my $tochan = DXChannel->get($field[2]);
882 my $dxchan = DXChannel->get($r->{call});
884 my $t = tv_interval($r->{t}, [ gettimeofday ]);
885 if ($dxchan->is_user) {
886 my $s = sprintf "%.2f", $t;
887 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
888 $dxchan->send($dxchan->msg('pingi', $field[2], $s, $ave))
889 } elsif ($dxchan->is_node) {
891 $tochan->{nopings} = 2; # pump up the timer
892 push @{$tochan->{pingtime}}, $t;
893 shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
895 for (@{$tochan->{pingtime}}) {
898 $tochan->{pingave} = $st / @{$tochan->{pingtime}};
905 # route down an appropriate thingy
906 $self->route($field[1], $line);
911 if ($pcno == 75) { # dunno but route it
912 if ($field[1] ne $main::mycall) {
913 $self->route($field[1], $line);
918 if ($pcno == 73) { # WCY broadcasts
921 my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
922 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
923 dbg('chan', "WCY Date ($field[1] $field[2]) out of range");
926 @field = map { unpad($_) } @field;
927 if (WCY::dup($d,@field[3..7])) {
928 dbg('chan', "Dup WCY Spot ignored\n");
932 my $wcy = WCY::update($d, @field[2..12]);
936 $rep = Local::wwv($self, @field[1..12]);
938 # dbg('local', "Local::wcy error $@") if $@;
941 # broadcast to the eager world
942 send_wcy_spot($self, $line, $d, @field[2..12]);
946 if ($pcno == 84) { # remote commands (incoming)
947 if ($field[1] eq $main::mycall) {
948 my $ref = DXUser->get_current($field[2]);
949 my $cref = DXCluster->get($field[2]);
950 Log('rcmd', 'in', $ref->{priv}, $field[2], $field[4]);
951 unless ($field[4] =~ /rcmd/i || !$cref || !$ref || $cref->mynode->call ne $ref->homenode) { # not allowed to relay RCMDS!
952 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
953 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
954 my $oldpriv = $self->{priv};
955 $self->{priv} = $ref->{priv}; # assume the user's privilege level
956 my @in = (DXCommandmode::run_cmd($self, $field[4]));
957 $self->{priv} = $oldpriv;
960 $self->send(pc85($main::mycall, $field[2], $field[3], "$main::mycall:$_"));
961 Log('rcmd', 'out', $field[2], $_);
963 delete $self->{remotecmd};
965 $self->send(pc85($main::mycall, $field[2], $field[3], "$main::mycall:sorry...!"));
968 $self->send(pc85($main::mycall, $field[2], $field[3],"$main::mycall:your attempt is logged, Tut tut tut...!"));
971 my $ref = DXUser->get_current($field[1]);
972 if ($ref && $ref->is_clx) {
973 $self->route($field[1], $line);
975 route($field[1], pc34($field[2], $field[1], $field[4]));
981 if ($pcno == 85) { # remote command replies
982 if ($field[1] eq $main::mycall) {
983 my $dxchan = DXChannel->get($field[3]);
985 $dxchan->send($field[4]);
987 my $s = $rcmds{$field[2]};
989 $dxchan = DXChannel->get($s->{call});
990 $dxchan->send($field[4]) if $dxchan;
991 delete $rcmds{$field[2]} if !$dxchan;
993 # send unsolicited ones to the sysop
994 my $dxchan = DXChannel->get($main::myalias);
995 $dxchan->send($field[4]) if $dxchan;
999 my $ref = DXUser->get_current($field[1]);
1000 if ($ref && $ref->is_clx) {
1001 $self->route($field[1], $line);
1003 route($field[1], pc35($field[2], $field[1], $field[4]));
1010 # if get here then rebroadcast the thing with its Hop count decremented (if
1011 # there is one). If it has a hop count and it decrements to zero then don't
1014 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
1018 unless ($self->{isolate}) {
1019 broadcast_ak1a($line, $self); # send it to everyone but me
1024 # This is called from inside the main cluster processing loop and is used
1025 # for despatching commands that are doing some long processing job
1030 my @dxchan = DXChannel->get_all();
1033 foreach $dxchan (@dxchan) {
1034 next unless $dxchan->is_node();
1035 next if $dxchan == $me;
1037 # send a pc50 out on this channel
1038 if ($t >= $dxchan->pc50_t + $DXProt::pc50_interval) {
1039 $dxchan->send(pc50(scalar DXChannel::get_all_users));
1040 $dxchan->pc50_t($t);
1043 # send a ping out on this channel
1044 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
1045 if ($dxchan->{nopings} <= 0) {
1046 $dxchan->disconnect;
1048 addping($main::mycall, $dxchan->call);
1049 $dxchan->{nopings} -= 1;
1050 $dxchan->{lastping} = $t;
1058 if ($main::systime - 3600 > $last_hour) {
1062 $last_hour = $main::systime;
1067 # finish up a pc context
1072 my $call = $self->call;
1074 my $ref = DXCluster->get_exact($call);
1076 # unbusy and stop and outgoing mail
1077 my $mref = DXMsg::get_busy($call);
1078 $mref->stop_msg($call) if $mref;
1080 # broadcast to all other nodes that all the nodes connected to via me are gone
1081 my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
1084 foreach $node (@gonenodes) {
1085 next if $node->call eq $call;
1086 broadcast_ak1a(pc21($node->call, 'Gone') , $self) unless $self->{isolate};
1090 # remove outstanding pings
1091 delete $pings{$call};
1093 # now broadcast to all other ak1a nodes that I have gone
1094 broadcast_ak1a(pc21($call, 'Gone.'), $self) unless $self->{isolate};
1096 # I was the last node visited
1097 $self->user->node($main::mycall);
1099 # send info to all logged in thingies
1100 $self->tell_login('logoutn');
1102 Log('DXProt', $call . " Disconnected");
1103 $ref->del() if $ref;
1107 # some active measures
1113 my @dxchan = DXChannel->get_all();
1116 # send it if it isn't the except list and isn't isolated and still has a hop count
1117 # taking into account filtering and so on
1118 foreach $dxchan (@dxchan) {
1120 my ($filter, $hops);
1122 if ($dxchan->{spotfilter}) {
1123 ($filter, $hops) = Filter::it($dxchan->{spotfilter}, @_, $self->{call} );
1124 next unless $filter;
1127 if ($dxchan->is_node) {
1128 next if $dxchan == $self;
1131 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1133 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1134 next unless $routeit;
1137 $dxchan->send($routeit) if $routeit;
1139 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1141 } elsif ($dxchan->is_user && $dxchan->{dx}) {
1142 my $buf = Spot::formatb($dxchan->{user}->wantgrid, $_[0], $_[1], $_[2], $_[3], $_[4]);
1143 $buf .= "\a\a" if $dxchan->{beep};
1145 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'talk') {
1146 $dxchan->send($buf);
1148 $dxchan->delay($buf);
1158 my @dxchan = DXChannel->get_all();
1161 # send it if it isn't the except list and isn't isolated and still has a hop count
1162 # taking into account filtering and so on
1163 foreach $dxchan (@dxchan) {
1165 my ($filter, $hops);
1167 if ($dxchan->{wwvfilter}) {
1168 ($filter, $hops) = Filter::it($dxchan->{wwvfilter}, @_, $self->{call} );
1169 next unless $filter;
1171 if ($dxchan->is_node) {
1172 next if $dxchan == $self;
1175 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1177 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1178 next unless $routeit;
1181 $dxchan->send($routeit) if $routeit;
1183 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1186 } elsif ($dxchan->is_user && $dxchan->{wwv}) {
1187 my $buf = "WWV de $_[6] <$_[1]>: SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
1188 $buf .= "\a\a" if $dxchan->{beep};
1189 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'talk') {
1190 $dxchan->send($buf);
1192 $dxchan->delay($buf);
1202 my @dxchan = DXChannel->get_all();
1205 # send it if it isn't the except list and isn't isolated and still has a hop count
1206 # taking into account filtering and so on
1207 foreach $dxchan (@dxchan) {
1209 my ($filter, $hops);
1211 if ($dxchan->{wcyfilter}) {
1212 ($filter, $hops) = Filter::it($dxchan->{wcyfilter}, @_, $self->{call} );
1213 next unless $filter;
1215 if ($dxchan->is_clx || $dxchan->is_spider) {
1216 next if $dxchan == $self;
1219 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1221 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1222 next unless $routeit;
1225 $dxchan->send($routeit) if $routeit;
1227 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1229 } elsif ($dxchan->is_user && $dxchan->{wcy}) {
1230 my $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
1231 $buf .= "\a\a" if $dxchan->{beep};
1232 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'talk') {
1233 $dxchan->send($buf);
1235 $dxchan->delay($buf);
1246 my @dxchan = DXChannel->get_all();
1248 my $text = unpad($_[2]);
1252 if ($_[3] eq '*') { # sysops
1254 } elsif ($_[3] gt ' ') { # speciality list handling
1255 my ($name) = split /\./, $_[3];
1256 $target = "$name"; # put the rest in later (if bothered)
1263 $target = "All" if !$target;
1265 Log('ann', $target, $_[0], $text);
1267 # send it if it isn't the except list and isn't isolated and still has a hop count
1268 # taking into account filtering and so on
1269 foreach $dxchan (@dxchan) {
1271 my ($filter, $hops);
1273 if ($dxchan->{annfilter}) {
1274 ($filter, $hops) = Filter::it($dxchan->{annfilter}, @_, $self->{call} );
1275 next unless $filter;
1277 if ($dxchan->is_node && $_[1] ne $main::mycall) { # i.e not specifically routed to me
1278 next if $dxchan == $self;
1281 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1283 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1284 next unless $routeit;
1287 $dxchan->send($routeit) if $routeit;
1289 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1292 } elsif ($dxchan->is_user) {
1293 unless ($dxchan->{ann}) {
1294 next if $_[0] ne $main::myalias && $_[0] ne $main::mycall;
1296 next if $target eq 'SYSOP' && $dxchan->{priv} < 5;
1297 my $buf = "$to$target de $_[0]: $text";
1299 $buf .= "\a\a" if $dxchan->{beep};
1300 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'talk') {
1301 $dxchan->send($buf);
1303 $dxchan->delay($buf);
1309 sub send_local_config
1318 if ($self->{isolate}) {
1319 @localnodes = (DXCluster->get_exact($main::mycall));
1321 # create a list of all the nodes that are not connected to this connection
1322 # and are not themselves isolated, this to make sure that isolated nodes
1323 # don't appear outside of this node
1324 @nodes = DXNode::get_all();
1325 @nodes = grep { $_->{call} ne $main::mycall } @nodes;
1326 @nodes = grep { $_->dxchan != $self } @nodes if @nodes;
1327 @nodes = grep { !$_->dxchan->{isolate} } @nodes if @nodes;
1328 @localnodes = grep { $_->dxchan->{call} eq $_->{call} } @nodes if @nodes;
1329 unshift @localnodes, DXCluster->get_exact($main::mycall);
1330 @remotenodes = grep { $_->dxchan->{call} ne $_->{call} } @nodes if @nodes;
1333 my @s = $me->pc19(@localnodes, @remotenodes);
1335 my $routeit = adjust_hops($self, $_);
1336 $self->send($routeit) if $routeit;
1339 # get all the users connected on the above nodes and send them out
1340 foreach $n (@localnodes, @remotenodes) {
1341 my @users = values %{$n->list};
1342 my @s = pc16($n, @users);
1344 my $routeit = adjust_hops($self, $_);
1345 $self->send($routeit) if $routeit;
1351 # route a message down an appropriate interface for a callsign
1353 # is called route(to, pcline);
1357 my ($self, $call, $line) = @_;
1358 my $cl = DXCluster->get_exact($call);
1359 if ($cl) { # don't route it back down itself
1360 if (ref $self && $call eq $self->{call}) {
1361 dbg('chan', "Trying to route back to source, dropped");
1365 my $dxchan = $cl->{dxchan};
1367 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1369 $dxchan->send($routeit) if $dxchan;
1375 # broadcast a message to all clusters taking into account isolation
1376 # [except those mentioned after buffer]
1379 my $s = shift; # the line to be rebroadcast
1380 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1381 my @dxchan = DXChannel::get_all_nodes();
1384 # send it if it isn't the except list and isn't isolated and still has a hop count
1385 foreach $dxchan (@dxchan) {
1386 next if grep $dxchan == $_, @except;
1387 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1388 $dxchan->send($routeit) unless $dxchan->{isolate} || !$routeit;
1392 # broadcast a message to all clusters ignoring isolation
1393 # [except those mentioned after buffer]
1394 sub broadcast_all_ak1a
1396 my $s = shift; # the line to be rebroadcast
1397 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1398 my @dxchan = DXChannel::get_all_nodes();
1401 # send it if it isn't the except list and isn't isolated and still has a hop count
1402 foreach $dxchan (@dxchan) {
1403 next if grep $dxchan == $_, @except;
1404 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1405 $dxchan->send($routeit);
1409 # broadcast to all users
1410 # storing the spot or whatever until it is in a state to receive it
1413 my $s = shift; # the line to be rebroadcast
1414 my $sort = shift; # the type of transmission
1415 my $fref = shift; # a reference to an object to filter on
1416 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1417 my @dxchan = DXChannel::get_all_users();
1421 foreach $dxchan (@dxchan) {
1422 next if grep $dxchan == $_, @except;
1425 broadcast_list($s, $sort, $fref, @out);
1428 # broadcast to a list of users
1436 foreach $dxchan (@_) {
1439 if ($sort eq 'dx') {
1440 next unless $dxchan->{dx};
1441 ($filter) = Filter::it($dxchan->{spotfilter}, @{$fref}) if ref $fref;
1442 next unless $filter;
1444 next if $sort eq 'ann' && !$dxchan->{ann};
1445 next if $sort eq 'wwv' && !$dxchan->{wwv};
1446 next if $sort eq 'wcy' && !$dxchan->{wcy};
1447 next if $sort eq 'wx' && !$dxchan->{wx};
1449 $s =~ s/\a//og unless $dxchan->{beep};
1451 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'talk') {
1461 # obtain the hops from the list for this callsign and pc no
1467 my $hops = $DXProt::hopcount{$pcno};
1468 $hops = $DXProt::def_hopcount if !$hops;
1473 # adjust the hop count on a per node basis using the user loadable
1474 # hop table if available or else decrement an existing one
1481 my $call = $self->{call};
1484 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
1485 my ($pcno) = $s =~ /^PC(\d\d)/o;
1486 confess "$call called adjust_hops with '$s'" unless $pcno;
1487 my $ref = $nodehops{$call} if %nodehops;
1489 my $newhops = $ref->{$pcno};
1490 return "" if defined $newhops && $newhops == 0;
1491 $newhops = $ref->{default} unless $newhops;
1492 return "" if defined $newhops && $newhops == 0;
1493 $newhops = $hops if !$newhops;
1494 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1496 # simply decrement it
1498 return "" if !$hops;
1499 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
1511 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
1512 do "$main::data/hop_table.pl";
1518 # add a ping request to the ping queues
1521 my ($from, $to) = @_;
1522 my $ref = $pings{$to} || [];
1525 $r->{t} = [ gettimeofday ];
1526 route(undef, $to, pc51($to, $main::mycall, 1));
1531 # add a rcmd request to the rcmd queues
1534 my ($self, $to, $cmd) = @_;
1537 $r->{call} = $self->{call};
1538 $r->{t} = $main::systime;
1542 my $ref = DXCluster->get_exact($to);
1543 if ($ref && $ref->dxchan && $ref->dxchan->is_clx) {
1544 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1546 route(undef, $to, pc34($main::mycall, $to, $cmd));
1555 if ($self->{conn} && !$nopc39) {
1556 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1559 $self->SUPER::disconnect;
1564 # send a talk message to this thingy
1568 my ($self, $from, $to, $via, $line) = @_;
1570 $line =~ s/\^/\\5E/g; # remove any ^ characters
1571 $self->send(DXProt::pc10($from, $to, $via, $line));
1572 Log('talk', $self->call, $from, $via?$via:$main::mycall, $line);