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);
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 my $user = DXUser->get($main::mycall);
55 $DXProt::myprot_version += $main::version*100;
56 $me = DXProt->new($main::mycall, 0, $user);
58 $me->{state} = "indifferent";
59 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
61 # $me->{sort} = 'M'; # M for me
63 # now prime the spot and wwv duplicates file with data
64 my @today = Julian::unixtoj(time);
65 for (Spot::readfile(@today), Spot::readfile(Julian::sub(@today, 1))) {
66 Spot::dup(@{$_}[0..3]);
68 for (Geomag::readfile(time)) {
69 Geomag::dup(@{$_}[1..5]);
73 do "$baddxfn" if -e "$baddxfn";
78 # obtain a new connection this is derived from dxchannel
83 my $self = DXChannel::alloc(@_);
87 # this is how a pc connection starts (for an incoming connection)
88 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
89 # all the crap that comes between).
92 my ($self, $line, $sort) = @_;
93 my $call = $self->{call};
94 my $user = $self->{user};
96 # remember type of connection
97 $self->{consort} = $line;
98 $self->{outbound} = $sort eq 'O';
99 $self->{priv} = $user->priv;
100 $self->{lang} = $user->lang;
101 $self->{isolate} = $user->{isolate};
102 $self->{consort} = $line; # save the connection type
105 # get the INPUT filters (these only pertain to Clusters)
106 $self->{inspotfilter} = Filter::read_in('spots', $call, 1);
107 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1);
108 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1);
109 $self->{inannfilter} = Filter::read_in('ann', $call, 1);
111 # set unbuffered and no echo
112 $self->send_now('B',"0");
113 $self->send_now('E',"0");
115 # ping neighbour node stuff
116 my $ping = $user->pingint;
117 $ping = 5*60 unless defined $ping;
118 $self->{pingint} = $ping;
119 $self->{nopings} = $user->nopings || 2;
120 $self->{pingtime} = [ ];
121 $self->{pingave} = 0;
123 # send initialisation string
124 unless ($self->{outbound}) {
125 $self->send(pc38()) if DXNode->get_all();
127 $self->{lastping} = $main::systime;
129 # remove from outstanding connects queue
130 @main::outstanding_connects = grep {$_->{call} ne $call} @main::outstanding_connects;
131 $self->{lastping} = $main::systime + $self->pingint / 2;
133 $self->state('init');
136 # send info to all logged in thingies
137 $self->tell_login('loginn');
139 Log('DXProt', "$call connected");
143 # This is the normal pcxx despatcher
147 my ($self, $line) = @_;
148 my @field = split /\^/, $line;
149 pop @field if $field[-1] eq '~';
151 # print join(',', @field), "\n";
153 # ignore any lines that don't start with PC
154 return if !$field[0] =~ /^PC/;
157 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
159 return if $pcno < 10 || $pcno > 99;
161 # dump bad protocol messages unless it is a PC29
162 if ($line =~ /\%[0-9A-F][0-9A-F]/o && $pcno != 29) {
163 dbg('chan', "CORRUPT protocol message - dumped");
170 $pcr = Local::pcprot($self, $pcno, @field);
172 # dbg('local', "Local::pcprot error $@") if $@;
176 if ($pcno == 10) { # incoming talk
178 # is it for me or one of mine?
179 my $call = ($field[5] gt ' ') ? $field[5] : $field[2];
180 if ($call eq $main::mycall || grep $_ eq $call, DXChannel::get_all_user_calls()) {
183 my $text = unpad($field[3]);
184 Log('talk', $call, $field[1], $field[6], $text);
185 $call = $main::myalias if $call eq $main::mycall;
186 my $ref = DXChannel->get($call);
187 $ref->send("$call de $field[1]: $text") if $ref && $ref->{talk};
189 $self->route($field[2], $line); # relay it on its way
194 if ($pcno == 11 || $pcno == 26) { # dx spot
196 # route 'foreign' pc26s
198 if ($field[7] ne $main::mycall) {
199 $self->route($field[7], $line);
204 # if this is a 'nodx' node then ignore it
205 if (grep $field[7] =~ /^$_/, @DXProt::nodx_node) {
206 dbg('chan', "Bad DXNode, dropped");
210 # convert the date to a unix date
211 my $d = cltounix($field[3], $field[4]);
212 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
213 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
214 dbg('chan', "Spot ignored, invalid date or out of range ($field[3] $field[4])\n");
219 if (grep $field[2] eq $_, @baddx) {
220 dbg('chan', "Bad DX spot, ignored");
224 # are any of the crucial fields invalid?
225 if ($field[2] =~ /(?:^\s*$|[a-z])/ || $field[6] =~ /(?:^\s*$|[a-z])/ || $field[7] =~ /(?:^\s*$|[a-z])/) {
226 dbg('chan', "Spot contains lower case callsigns or blanks, rejected");
231 $field[5] =~ s/^\s+//; # take any leading blanks off
232 if (Spot::dup($field[1], $field[2], $d, $field[5])) {
233 dbg('chan', "Duplicate Spot ignored\n");
237 my @spot = Spot::add($field[1], $field[2], $d, $field[5], $field[6], $field[7]);
240 # @spot at this point contains:-
241 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
242 # then spotted itu, spotted cq, spotters itu, spotters cq
243 # you should be able to route on any of these
246 # fix up qra locators of known users
247 my $user = DXUser->get_current($spot[4]);
249 my $qra = $user->qra;
250 unless ($qra && DXBearing::is_qra($qra)) {
251 my $lat = $user->lat;
252 my $long = $user->long;
253 if (defined $lat && defined $long) {
254 $user->qra(DXBearing::lltoqra($lat, $long));
263 $r = Local::spot($self, @spot);
265 # dbg('local', "Local::spot1 error $@") if $@;
268 # DON'T be silly and send on PC26s!
269 return if $pcno == 26;
271 # send out the filtered spots
272 send_dx_spot($self, $line, @spot) if @spot;
276 if ($pcno == 12) { # announces
277 # announce duplicate checking
278 $field[3] =~ s/^\s+//; # remove leading blanks
279 if (AnnTalk::dup($field[1], $field[2], $field[3])) {
280 dbg('chan', "Duplicate Announce ignored\n");
284 if ($field[2] eq '*' || $field[2] eq $main::mycall) {
286 # global ann filtering on INPUT
287 if ($self->{inannfilter}) {
288 my ($filter, $hops) = Filter::it($self->{inannfilter}, @field[1..6], $self->{call} );
290 dbg('chan', "Rejected by filter");
296 $self->send_announce($line, @field[1..6]);
298 $self->route($field[2], $line);
314 if ($pcno == 16) { # add a user
315 my $node = DXCluster->get_exact($field[1]);
317 if (!$node && ($dxchan = DXChannel->get($field[1]))) {
318 # add it to the node table if it isn't present and it's
320 $node = DXNode->new($dxchan, $field[1], 0, 1, 5400);
321 broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
324 return unless $node; # ignore if havn't seen a PC19 for this one yet
325 return unless $node->isa('DXNode');
326 if ($node->dxchan != $self) {
327 dbg('chan', "LOOP: $field[1] came in on wrong channel");
330 if (($dxchan = DXChannel->get($field[1])) && $dxchan != $self) {
331 dbg('chan', "LOOP: $field[1] connected locally");
336 for ($i = 2; $i < $#field; $i++) {
337 my ($call, $confmode, $here) = $field[$i] =~ /^(\S+) (\S) (\d)/o;
338 next if !$call || length $call < 3 || length $call > 8;
341 next if DXCluster->get_exact($call); # we already have this (loop?)
343 $confmode = $confmode eq '*';
344 DXNodeuser->new($self, $node, $call, $confmode, $here);
346 # add this station to the user database, if required
347 $call =~ s/-\d+$//o; # remove ssid for users
348 my $user = DXUser->get_current($call);
349 $user = DXUser->new($call) if !$user;
350 $user->homenode($node->call) if !$user->homenode;
351 $user->node($node->call);
352 $user->lastin($main::systime) unless DXChannel->get($call);
356 # queue up any messages (look for privates only)
357 DXMsg::queue_msg(1) if $self->state eq 'normal';
361 if ($pcno == 17) { # remove a user
362 my $node = DXCluster->get_exact($field[2]);
364 if (!$node && ($dxchan = DXChannel->get($field[2]))) {
365 # add it to the node table if it isn't present and it's
367 $node = DXNode->new($dxchan, $field[2], 0, 1, 5400);
368 broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
372 return unless $node->isa('DXNode');
373 if ($node->dxchan != $self) {
374 dbg('chan', "LOOP: $field[2] came in on wrong channel");
377 if (($dxchan = DXChannel->get($field[2])) && $dxchan != $self) {
378 dbg('chan', "LOOP: $field[2] connected locally");
381 my $ref = DXCluster->get_exact($field[1]);
386 if ($pcno == 18) { # link request
387 $self->state('init');
389 # first clear out any nodes on this dxchannel
390 my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
391 foreach my $node (@gonenodes) {
392 next if $node->dxchan == $DXProt::me;
393 broadcast_ak1a(pc21($node->call, 'Gone, re-init') , $self) unless $self->{isolate};
396 $self->send_local_config();
398 return; # we don't pass these on
401 if ($pcno == 19) { # incoming cluster list
403 my $newline = "PC19^";
404 for ($i = 1; $i < $#field-1; $i += 4) {
405 my $here = $field[$i];
406 my $call = uc $field[$i+1];
407 my $confmode = $field[$i+2];
408 my $ver = $field[$i+3];
410 $ver = 5400 if !$ver && $allowzero;
412 # now check the call over
413 my $node = DXCluster->get_exact($call);
416 if (($dxchan = DXChannel->get($call)) && $dxchan != $self) {
417 dbg('chan', "LOOP: $call connected locally");
419 if ($node->dxchan != $self) {
420 dbg('chan', "LOOP: $call come in on wrong channel");
423 dbg('chan', "already have $call");
427 # check for sane parameters
428 next if $ver < 5000; # only works with version 5 software
429 next if length $call < 3; # min 3 letter callsigns
431 # add it to the nodes table and outgoing line
432 $newline .= "$here^$call^$confmode^$ver^";
433 DXNode->new($self, $call, $confmode, $here, $ver);
435 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
436 my $mref = DXMsg::get_busy($call);
437 $mref->stop_msg($call) if $mref;
439 # add this station to the user database, if required (don't remove SSID from nodes)
440 my $user = DXUser->get_current($call);
442 $user = DXUser->new($call);
444 $user->priv(1); # I have relented and defaulted nodes
445 $self->{priv} = 1; # to user RCMDs allowed
446 $user->homenode($call);
449 $user->lastin($main::systime) unless DXChannel->get($call);
453 return if $newline eq "PC19^";
456 $newline .= get_hops(19) . "^";
461 if ($pcno == 20) { # send local configuration
462 $self->send_local_config();
464 $self->state('normal');
468 if ($pcno == 21) { # delete a cluster from the list
469 my $call = uc $field[1];
470 if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
471 my $node = DXCluster->get_exact($call);
473 if ($node->dxchan != $self) {
474 dbg('chan', "LOOP: $call come in on wrong channel");
478 if (($dxchan = DXChannel->get($call)) && $dxchan != $self) {
479 dbg('chan', "LOOP: $call connected locally");
484 dbg('chan', "$call not in table, dropped");
492 $self->state('normal');
496 if ($pcno == 23 || $pcno == 27) { # WWV info
498 # route 'foreign' pc27s
500 if ($field[8] ne $main::mycall) {
501 $self->route($field[8], $line);
507 my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
508 my $sfi = unpad($field[3]);
509 my $k = unpad($field[4]);
510 my $i = unpad($field[5]);
511 my ($r) = $field[6] =~ /R=(\d+)/;
513 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
514 dbg('chan', "WWV Date ($field[1] $field[2]) out of range");
517 if (Geomag::dup($d,$sfi,$k,$i,$field[6])) {
518 dbg('chan', "Dup WWV Spot ignored\n");
521 $field[7] =~ s/-\d+$//o; # remove spotter's ssid
523 my $wwv = Geomag::update($d, $field[2], $sfi, $k, $i, @field[6..8], $r);
527 $rep = Local::wwv($self, $field[1], $field[2], $sfi, $k, $i, @field[6..8], $r);
529 # dbg('local', "Local::wwv2 error $@") if $@;
532 # DON'T be silly and send on PC27s!
533 return if $pcno == 27;
535 # broadcast to the eager world
536 send_wwv_spot($self, $line, $d, $field[2], $sfi, $k, $i, @field[6..8]);
540 if ($pcno == 24) { # set here status
541 my $call = uc $field[1];
542 my $ref = DXCluster->get_exact($call);
543 $ref->here($field[2]) if $ref;
547 if ($pcno == 25) { # merge request
548 if ($field[1] ne $main::mycall) {
549 $self->route($field[1], $line);
552 if ($field[2] eq $main::mycall) {
553 dbg('chan', "Trying to merge to myself, ignored");
557 Log('DXProt', "Merge request for $field[3] spots and $field[4] WWV from $field[1]");
561 my @in = reverse Spot::search(1, undef, undef, 0, $field[3]);
564 $self->send(pc26(@{$in}[0..4], $field[2]));
570 my @in = reverse Geomag::search(0, $field[4], time, 1);
573 $self->send(pc27(@{$in}[0..5], $field[2]));
579 if (($pcno >= 28 && $pcno <= 33) || $pcno == 40 || $pcno == 42 || $pcno == 49) { # mail/file handling
580 if ($pcno == 49 || $field[1] eq $main::mycall) {
581 DXMsg::process($self, $line);
583 $self->route($field[1], $line);
588 if ($pcno == 34 || $pcno == 36) { # remote commands (incoming)
589 if ($field[1] eq $main::mycall) {
590 my $ref = DXUser->get_current($field[2]);
591 my $cref = DXCluster->get($field[2]);
592 Log('rcmd', 'in', $ref->{priv}, $field[2], $field[3]);
593 unless ($field[3] =~ /rcmd/i || !$cref || !$ref || $cref->mynode->call ne $ref->homenode) { # not allowed to relay RCMDS!
594 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
595 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
596 my $oldpriv = $self->{priv};
597 $self->{priv} = $ref->{priv}; # assume the user's privilege level
598 my @in = (DXCommandmode::run_cmd($self, $field[3]));
599 $self->{priv} = $oldpriv;
602 $self->send(pc35($main::mycall, $field[2], "$main::mycall:$_"));
603 Log('rcmd', 'out', $field[2], $_);
605 delete $self->{remotecmd};
607 $self->send(pc35($main::mycall, $field[2], "$main::mycall:sorry...!"));
610 $self->send(pc35($main::mycall, $field[2], "$main::mycall:your attempt is logged, Tut tut tut...!"));
613 my $ref = DXUser->get_current($field[1]);
614 if ($ref && $ref->is_clx) {
615 route($field[1], pc84($field[2], $field[1], $field[2], $field[3]));
617 $self->route($field[1], $line);
623 if ($pcno == 35) { # remote command replies
624 if ($field[1] eq $main::mycall) {
625 my $s = $rcmds{$field[2]};
627 my $dxchan = DXChannel->get($s->{call});
628 $dxchan->send($field[3]) if $dxchan;
629 delete $rcmds{$field[2]} if !$dxchan;
632 my $ref = DXUser->get_current($field[1]);
633 if ($ref && $ref->is_clx) {
634 route($field[1], pc85($field[2], $field[1], $field[2], $field[3]));
636 $self->route($field[1], $line);
642 # for pc 37 see 44 onwards
644 if ($pcno == 38) { # node connected list from neighbour
648 if ($pcno == 39) { # incoming disconnect
649 $self->disconnect(1);
653 if ($pcno == 41) { # user info
654 # add this station to the user database, if required
655 my $user = DXUser->get_current($field[1]);
657 # then try without an SSID
658 $field[1] =~ s/-\d+$//o;
659 $user = DXUser->get_current($field[1]);
661 $user = DXUser->new($field[1]) if !$user;
663 if ($field[2] == 1) {
664 $user->name($field[3]);
665 } elsif ($field[2] == 2) {
666 $user->qth($field[3]);
667 } elsif ($field[2] == 3) {
668 my ($lat, $long) = DXBearing::stoll($field[3]);
671 my $qra = $user->qra || DXBearing::lltoqra($lat, $long);
672 $qra = DXBearing::lltoqra($lat, $long) unless DXBearing::is_qra($qra);
673 } elsif ($field[2] == 4) {
674 $user->homenode($field[3]);
682 if ($pcno == 37 || $pcno == 44 || $pcno == 45 || $pcno == 46 || $pcno == 47 || $pcno == 48) {
683 DXDb::process($self, $line);
687 if ($pcno == 50) { # keep alive/user list
688 my $node = DXCluster->get_exact($field[1]);
690 return unless $node->isa('DXNode');
691 return unless $node->dxchan == $self;
692 $node->update_users($field[2]);
697 if ($pcno == 51) { # incoming ping requests/answers
700 if ($field[1] eq $main::mycall) {
701 my $flag = $field[3];
703 $self->send(pc51($field[2], $field[1], '0'));
705 # it's a reply, look in the ping list for this one
706 my $ref = $pings{$field[2]};
708 my $tochan = DXChannel->get($field[2]);
711 my $dxchan = DXChannel->get($r->{call});
713 my $t = tv_interval($r->{t}, [ gettimeofday ]);
714 if ($dxchan->is_user) {
715 my $s = sprintf "%.2f", $t;
716 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
717 $dxchan->send($dxchan->msg('pingi', $field[2], $s, $ave))
718 } elsif ($dxchan->is_node) {
720 $tochan->{nopings} = 2; # pump up the timer
721 push @{$tochan->{pingtime}}, $t;
722 shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
724 for (@{$tochan->{pingtime}}) {
727 $tochan->{pingave} = $st / @{$tochan->{pingtime}};
734 # route down an appropriate thingy
735 $self->route($field[1], $line);
740 if ($pcno == 73) { # WCY broadcasts
743 my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
744 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
745 dbg('chan', "WCY Date ($field[1] $field[2]) out of range");
748 @field = map { unpad($_) } @field;
749 if (WCY::dup($d,@field[3..7])) {
750 dbg('chan', "Dup WCY Spot ignored\n");
754 my $wcy = WCY::update($d, @field[2..12]);
758 $rep = Local::wwv($self, @field[1..12]);
760 # dbg('local', "Local::wcy error $@") if $@;
763 # broadcast to the eager world
764 send_wcy_spot($self, $line, $d, @field[2..12]);
768 if ($pcno == 84) { # remote commands (incoming)
769 if ($field[1] eq $main::mycall) {
770 my $ref = DXUser->get_current($field[2]);
771 my $cref = DXCluster->get($field[2]);
772 Log('rcmd', 'in', $ref->{priv}, $field[2], $field[4]);
773 unless ($field[3] =~ /rcmd/i || !$cref || !$ref || $cref->mynode->call ne $ref->homenode) { # not allowed to relay RCMDS!
774 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
775 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
776 my $oldpriv = $self->{priv};
777 $self->{priv} = $ref->{priv}; # assume the user's privilege level
778 my @in = (DXCommandmode::run_cmd($self, $field[4]));
779 $self->{priv} = $oldpriv;
782 $self->send(pc85($main::mycall, $field[2], $field[3], "$main::mycall:$_"));
783 Log('rcmd', 'out', $field[2], $_);
785 delete $self->{remotecmd};
787 $self->send(pc85($main::mycall, $field[2], $field[3], "$main::mycall:sorry...!"));
790 $self->send(pc85($main::mycall, $field[2], $field[3],"$main::mycall:your attempt is logged, Tut tut tut...!"));
793 my $ref = DXUser->get_current($field[1]);
794 if ($ref && $ref->is_clx) {
795 $self->route($field[1], $line);
797 route($field[1], pc34($field[2], $field[1], $field[3]));
803 if ($pcno == 85) { # remote command replies
804 if ($field[1] eq $main::mycall) {
805 my $dxchan = DXChannel->get($field[3]);
807 $dxchan->send($field[4]);
809 my $s = $rcmds{$field[2]};
811 $dxchan = DXChannel->get($s->{call});
812 $dxchan->send($field[4]) if $dxchan;
813 delete $rcmds{$field[2]} if !$dxchan;
817 my $ref = DXUser->get_current($field[1]);
818 if ($ref && $ref->is_clx) {
819 $self->route($field[1], $line);
821 route($field[1], pc35($field[2], $field[1], $field[3]));
828 # if get here then rebroadcast the thing with its Hop count decremented (if
829 # there is one). If it has a hop count and it decrements to zero then don't
832 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
836 unless ($self->{isolate}) {
837 broadcast_ak1a($line, $self); # send it to everyone but me
842 # This is called from inside the main cluster processing loop and is used
843 # for despatching commands that are doing some long processing job
848 my @dxchan = DXChannel->get_all();
851 foreach $dxchan (@dxchan) {
852 next unless $dxchan->is_node();
853 next if $dxchan == $me;
855 # send a pc50 out on this channel
856 if ($t >= $dxchan->pc50_t + $DXProt::pc50_interval) {
857 $dxchan->send(pc50(scalar DXChannel::get_all_users));
861 # send a ping out on this channel
862 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
863 if ($dxchan->{nopings} <= 0) {
866 addping($main::mycall, $dxchan->call);
867 $dxchan->{nopings} -= 1;
868 $dxchan->{lastping} = $t;
876 if ($main::systime - 3600 > $last_hour) {
880 $last_hour = $main::systime;
885 # finish up a pc context
890 my $call = $self->call;
892 my $ref = DXCluster->get_exact($call);
894 # unbusy and stop and outgoing mail
895 my $mref = DXMsg::get_busy($call);
896 $mref->stop_msg($call) if $mref;
898 # broadcast to all other nodes that all the nodes connected to via me are gone
899 my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
902 foreach $node (@gonenodes) {
903 next if $node->call eq $call;
904 broadcast_ak1a(pc21($node->call, 'Gone') , $self) unless $self->{isolate};
908 # remove outstanding pings
909 delete $pings{$call};
911 # now broadcast to all other ak1a nodes that I have gone
912 broadcast_ak1a(pc21($call, 'Gone.'), $self) unless $self->{isolate};
914 # I was the last node visited
915 $self->user->node($main::mycall);
917 # send info to all logged in thingies
918 $self->tell_login('logoutn');
920 Log('DXProt', $call . " Disconnected");
925 # some active measures
931 my @dxchan = DXChannel->get_all();
934 # send it if it isn't the except list and isn't isolated and still has a hop count
935 # taking into account filtering and so on
936 foreach $dxchan (@dxchan) {
940 if ($dxchan->{spotfilter}) {
941 ($filter, $hops) = Filter::it($dxchan->{spotfilter}, @_, $self->{call} );
945 if ($dxchan->is_node) {
946 next if $dxchan == $self;
949 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
951 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
952 next unless $routeit;
955 $dxchan->send($routeit) if $routeit;
957 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
959 } elsif ($dxchan->is_user && $dxchan->{dx}) {
960 my $buf = Spot::formatb($_[0], $_[1], $_[2], $_[3], $_[4]);
961 $buf .= "\a\a" if $dxchan->{beep};
962 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
965 $dxchan->delay($buf);
975 my @dxchan = DXChannel->get_all();
978 # send it if it isn't the except list and isn't isolated and still has a hop count
979 # taking into account filtering and so on
980 foreach $dxchan (@dxchan) {
984 if ($dxchan->{wwvfilter}) {
985 ($filter, $hops) = Filter::it($dxchan->{wwvfilter}, @_, $self->{call} );
988 if ($dxchan->is_node) {
989 next if $dxchan == $self;
992 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
994 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
995 next unless $routeit;
998 $dxchan->send($routeit) if $routeit;
1000 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1003 } elsif ($dxchan->is_user && $dxchan->{wwv}) {
1004 my $buf = "WWV de $_[6] <$_[1]>: SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
1005 $buf .= "\a\a" if $dxchan->{beep};
1006 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1007 $dxchan->send($buf);
1009 $dxchan->delay($buf);
1019 my @dxchan = DXChannel->get_all();
1022 # send it if it isn't the except list and isn't isolated and still has a hop count
1023 # taking into account filtering and so on
1024 foreach $dxchan (@dxchan) {
1026 my ($filter, $hops);
1028 if ($dxchan->{wcyfilter}) {
1029 ($filter, $hops) = Filter::it($dxchan->{wcyfilter}, @_, $self->{call} );
1030 next unless $filter;
1032 if ($dxchan->is_clx || $dxchan->is_spider) {
1033 next if $dxchan == $self;
1036 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1038 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1039 next unless $routeit;
1042 $dxchan->send($routeit) if $routeit;
1044 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1046 } elsif ($dxchan->is_user && $dxchan->{wcy}) {
1047 my $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
1048 $buf .= "\a\a" if $dxchan->{beep};
1049 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1050 $dxchan->send($buf);
1052 $dxchan->delay($buf);
1063 my @dxchan = DXChannel->get_all();
1065 my $text = unpad($_[2]);
1069 if ($_[3] eq '*') { # sysops
1071 } elsif ($_[3] gt ' ') { # speciality list handling
1072 my ($name) = split /\./, $_[3];
1073 $target = "$name"; # put the rest in later (if bothered)
1080 $target = "All" if !$target;
1082 Log('ann', $target, $_[0], $text);
1084 # send it if it isn't the except list and isn't isolated and still has a hop count
1085 # taking into account filtering and so on
1086 foreach $dxchan (@dxchan) {
1088 my ($filter, $hops);
1090 if ($dxchan->{annfilter}) {
1091 ($filter, $hops) = Filter::it($dxchan->{annfilter}, @_, $self->{call} );
1092 next unless $filter;
1094 if ($dxchan->is_node && $_[1] ne $main::mycall) { # i.e not specifically routed to me
1095 next if $dxchan == $self;
1098 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1100 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1101 next unless $routeit;
1104 $dxchan->send($routeit) if $routeit;
1106 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1109 } elsif ($dxchan->is_user && $dxchan->{ann}) {
1110 next if $target eq 'SYSOP' && $dxchan->{priv} < 5;
1111 my $buf = "$to$target de $_[0]: $text";
1112 $buf .= "\a\a" if $dxchan->{beep};
1113 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1114 $dxchan->send($buf);
1116 $dxchan->delay($buf);
1122 sub send_local_config
1131 if ($self->{isolate}) {
1132 @localnodes = (DXCluster->get_exact($main::mycall));
1134 # create a list of all the nodes that are not connected to this connection
1135 # and are not themselves isolated, this to make sure that isolated nodes
1136 # don't appear outside of this node
1137 @nodes = DXNode::get_all();
1138 @nodes = grep { $_->{call} ne $main::mycall } @nodes;
1139 @nodes = grep { $_->dxchan != $self } @nodes if @nodes;
1140 @nodes = grep { !$_->dxchan->{isolate} } @nodes if @nodes;
1141 @localnodes = grep { $_->dxchan->{call} eq $_->{call} } @nodes if @nodes;
1142 unshift @localnodes, DXCluster->get_exact($main::mycall);
1143 @remotenodes = grep { $_->dxchan->{call} ne $_->{call} } @nodes if @nodes;
1146 my @s = $me->pc19(@localnodes, @remotenodes);
1148 my $routeit = adjust_hops($self, $_);
1149 $self->send($routeit) if $routeit;
1152 # get all the users connected on the above nodes and send them out
1153 foreach $n (@localnodes, @remotenodes) {
1154 my @users = values %{$n->list};
1155 my @s = pc16($n, @users);
1157 my $routeit = adjust_hops($self, $_);
1158 $self->send($routeit) if $routeit;
1164 # route a message down an appropriate interface for a callsign
1166 # is called route(to, pcline);
1170 my ($self, $call, $line) = @_;
1171 my $cl = DXCluster->get_exact($call);
1172 if ($cl) { # don't route it back down itself
1173 if (ref $self && $call eq $self->{call}) {
1174 dbg('chan', "Trying to route back to source, dropped");
1178 my $dxchan = $cl->{dxchan};
1180 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1182 $dxchan->send($routeit) if $dxchan;
1188 # broadcast a message to all clusters taking into account isolation
1189 # [except those mentioned after buffer]
1192 my $s = shift; # the line to be rebroadcast
1193 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1194 my @dxchan = DXChannel::get_all_ak1a();
1197 # send it if it isn't the except list and isn't isolated and still has a hop count
1198 foreach $dxchan (@dxchan) {
1199 next if grep $dxchan == $_, @except;
1200 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1201 $dxchan->send($routeit) unless $dxchan->{isolate} || !$routeit;
1205 # broadcast a message to all clusters ignoring isolation
1206 # [except those mentioned after buffer]
1207 sub broadcast_all_ak1a
1209 my $s = shift; # the line to be rebroadcast
1210 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1211 my @dxchan = DXChannel::get_all_ak1a();
1214 # send it if it isn't the except list and isn't isolated and still has a hop count
1215 foreach $dxchan (@dxchan) {
1216 next if grep $dxchan == $_, @except;
1217 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1218 $dxchan->send($routeit);
1222 # broadcast to all users
1223 # storing the spot or whatever until it is in a state to receive it
1226 my $s = shift; # the line to be rebroadcast
1227 my $sort = shift; # the type of transmission
1228 my $fref = shift; # a reference to an object to filter on
1229 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1230 my @dxchan = DXChannel::get_all_users();
1234 foreach $dxchan (@dxchan) {
1235 next if grep $dxchan == $_, @except;
1238 broadcast_list($s, $sort, $fref, @out);
1241 # broadcast to a list of users
1249 foreach $dxchan (@_) {
1252 if ($sort eq 'dx') {
1253 next unless $dxchan->{dx};
1254 ($filter) = Filter::it($dxchan->{spotfilter}, @{$fref}) if ref $fref;
1255 next unless $filter;
1257 next if $sort eq 'ann' && !$dxchan->{ann};
1258 next if $sort eq 'wwv' && !$dxchan->{wwv};
1259 next if $sort eq 'wcy' && !$dxchan->{wcy};
1260 next if $sort eq 'wx' && !$dxchan->{wx};
1262 $s =~ s/\a//og unless $dxchan->{beep};
1264 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1274 # obtain the hops from the list for this callsign and pc no
1280 my $hops = $DXProt::hopcount{$pcno};
1281 $hops = $DXProt::def_hopcount if !$hops;
1286 # adjust the hop count on a per node basis using the user loadable
1287 # hop table if available or else decrement an existing one
1294 my $call = $self->{call};
1297 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
1298 my ($pcno) = $s =~ /^PC(\d\d)/o;
1299 confess "$call called adjust_hops with '$s'" unless $pcno;
1300 my $ref = $nodehops{$call} if %nodehops;
1302 my $newhops = $ref->{$pcno};
1303 return "" if defined $newhops && $newhops == 0;
1304 $newhops = $ref->{default} unless $newhops;
1305 return "" if defined $newhops && $newhops == 0;
1306 $newhops = $hops if !$newhops;
1307 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1309 # simply decrement it
1311 return "" if !$hops;
1312 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
1324 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
1325 do "$main::data/hop_table.pl";
1331 # add a ping request to the ping queues
1334 my ($from, $to) = @_;
1335 my $ref = $pings{$to} || [];
1338 $r->{t} = [ gettimeofday ];
1339 route(undef, $to, pc51($to, $main::mycall, 1));
1344 # add a rcmd request to the rcmd queues
1347 my ($self, $to, $cmd) = @_;
1350 $r->{call} = $self->{call};
1351 $r->{t} = $main::systime;
1355 my $ref = DXCluster->get_exact($to);
1356 if ($ref && $ref->dxchan && $ref->dxchan->is_clx) {
1357 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1359 route(undef, $to, pc34($main::mycall, $to, $cmd));
1368 if ($self->{conn} && !$nopc39) {
1369 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1372 $self->SUPER::disconnect;