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] =~ /[a-z]/ || $field[6] =~ /[a-z]/ || $field[7] =~ /[a-z]/) {
226 dbg('chan', "Spot contains lower case callsigns, 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
249 $r = Local::spot($self, @spot);
251 # dbg('local', "Local::spot1 error $@") if $@;
254 # DON'T be silly and send on PC26s!
255 return if $pcno == 26;
257 # send out the filtered spots
258 send_dx_spot($self, $line, @spot) if @spot;
262 if ($pcno == 12) { # announces
263 # announce duplicate checking
264 $field[3] =~ s/^\s+//; # remove leading blanks
265 if (AnnTalk::dup($field[1], $field[2], $field[3])) {
266 dbg('chan', "Duplicate Announce ignored\n");
270 if ($field[2] eq '*' || $field[2] eq $main::mycall) {
272 # global ann filtering on INPUT
273 if ($self->{inannfilter}) {
274 my ($filter, $hops) = Filter::it($self->{inannfilter}, @field[1..6], $self->{call} );
276 dbg('chan', "Rejected by filter");
282 $self->send_announce($line, @field[1..6]);
284 $self->route($field[2], $line);
300 if ($pcno == 16) { # add a user
301 my $node = DXCluster->get_exact($field[1]);
303 if (!$node && ($dxchan = DXChannel->get($field[1]))) {
304 # add it to the node table if it isn't present and it's
306 $node = DXNode->new($dxchan, $field[1], 0, 1, 5400);
307 broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
310 return unless $node; # ignore if havn't seen a PC19 for this one yet
311 return unless $node->isa('DXNode');
312 if ($node->dxchan != $self) {
313 dbg('chan', "LOOP: $field[1] came in on wrong channel");
316 if (($dxchan = DXChannel->get($field[1])) && $dxchan != $self) {
317 dbg('chan', "LOOP: $field[1] connected locally");
322 for ($i = 2; $i < $#field; $i++) {
323 my ($call, $confmode, $here) = $field[$i] =~ /^(\S+) (\S) (\d)/o;
324 next if !$call || length $call < 3 || length $call > 8;
327 next if DXCluster->get_exact($call); # we already have this (loop?)
329 $confmode = $confmode eq '*';
330 DXNodeuser->new($self, $node, $call, $confmode, $here);
332 # add this station to the user database, if required
333 $call =~ s/-\d+$//o; # remove ssid for users
334 my $user = DXUser->get_current($call);
335 $user = DXUser->new($call) if !$user;
336 $user->homenode($node->call) if !$user->homenode;
337 $user->node($node->call);
338 $user->lastin($main::systime) unless DXChannel->get($call);
342 # queue up any messages (look for privates only)
343 DXMsg::queue_msg(1) if $self->state eq 'normal';
347 if ($pcno == 17) { # remove a user
348 my $node = DXCluster->get_exact($field[2]);
350 if (!$node && ($dxchan = DXChannel->get($field[2]))) {
351 # add it to the node table if it isn't present and it's
353 $node = DXNode->new($dxchan, $field[2], 0, 1, 5400);
354 broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
358 return unless $node->isa('DXNode');
359 if ($node->dxchan != $self) {
360 dbg('chan', "LOOP: $field[2] came in on wrong channel");
363 if (($dxchan = DXChannel->get($field[2])) && $dxchan != $self) {
364 dbg('chan', "LOOP: $field[2] connected locally");
367 my $ref = DXCluster->get_exact($field[1]);
372 if ($pcno == 18) { # link request
373 $self->state('init');
375 # first clear out any nodes on this dxchannel
376 my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
377 foreach my $node (@gonenodes) {
378 next if $node->dxchan == $DXProt::me;
379 broadcast_ak1a(pc21($node->call, 'Gone, re-init') , $self) unless $self->{isolate};
382 $self->send_local_config();
384 return; # we don't pass these on
387 if ($pcno == 19) { # incoming cluster list
389 my $newline = "PC19^";
390 for ($i = 1; $i < $#field-1; $i += 4) {
391 my $here = $field[$i];
392 my $call = uc $field[$i+1];
393 my $confmode = $field[$i+2];
394 my $ver = $field[$i+3];
396 $ver = 5400 if !$ver && $allowzero;
398 # now check the call over
399 my $node = DXCluster->get_exact($call);
402 if (($dxchan = DXChannel->get($call)) && $dxchan != $self) {
403 dbg('chan', "LOOP: $call connected locally");
405 if ($node->dxchan != $self) {
406 dbg('chan', "LOOP: $call come in on wrong channel");
409 dbg('chan', "already have $call");
413 # check for sane parameters
414 next if $ver < 5000; # only works with version 5 software
415 next if length $call < 3; # min 3 letter callsigns
417 # add it to the nodes table and outgoing line
418 $newline .= "$here^$call^$confmode^$ver^";
419 DXNode->new($self, $call, $confmode, $here, $ver);
421 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
422 my $mref = DXMsg::get_busy($call);
423 $mref->stop_msg($call) if $mref;
425 # add this station to the user database, if required (don't remove SSID from nodes)
426 my $user = DXUser->get_current($call);
428 $user = DXUser->new($call);
430 $user->priv(1); # I have relented and defaulted nodes
431 $self->{priv} = 1; # to user RCMDs allowed
432 $user->homenode($call);
435 $user->lastin($main::systime) unless DXChannel->get($call);
439 return if $newline eq "PC19^";
442 $newline .= get_hops(19) . "^";
447 if ($pcno == 20) { # send local configuration
448 $self->send_local_config();
450 $self->state('normal');
454 if ($pcno == 21) { # delete a cluster from the list
455 my $call = uc $field[1];
456 if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
457 my $node = DXCluster->get_exact($call);
459 if ($node->dxchan != $self) {
460 dbg('chan', "LOOP: $call come in on wrong channel");
464 if (($dxchan = DXChannel->get($call)) && $dxchan != $self) {
465 dbg('chan', "LOOP: $call connected locally");
470 dbg('chan', "$call not in table, dropped");
478 $self->state('normal');
482 if ($pcno == 23 || $pcno == 27) { # WWV info
484 # route 'foreign' pc27s
486 if ($field[8] ne $main::mycall) {
487 $self->route($field[8], $line);
493 my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
494 my $sfi = unpad($field[3]);
495 my $k = unpad($field[4]);
496 my $i = unpad($field[5]);
497 my ($r) = $field[6] =~ /R=(\d+)/;
499 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
500 dbg('chan', "WWV Date ($field[1] $field[2]) out of range");
503 if (Geomag::dup($d,$sfi,$k,$i,$field[6])) {
504 dbg('chan', "Dup WWV Spot ignored\n");
507 $field[7] =~ s/-\d+$//o; # remove spotter's ssid
509 my $wwv = Geomag::update($d, $field[2], $sfi, $k, $i, @field[6..8], $r);
513 $rep = Local::wwv($self, $field[1], $field[2], $sfi, $k, $i, @field[6..8], $r);
515 # dbg('local', "Local::wwv2 error $@") if $@;
518 # DON'T be silly and send on PC27s!
519 return if $pcno == 27;
521 # broadcast to the eager world
522 send_wwv_spot($self, $line, $d, $field[2], $sfi, $k, $i, @field[6..8]);
526 if ($pcno == 24) { # set here status
527 my $call = uc $field[1];
528 my $ref = DXCluster->get_exact($call);
529 $ref->here($field[2]) if $ref;
533 if ($pcno == 25) { # merge request
534 if ($field[1] ne $main::mycall) {
535 $self->route($field[1], $line);
538 if ($field[2] eq $main::mycall) {
539 dbg('chan', "Trying to merge to myself, ignored");
543 Log('DXProt', "Merge request for $field[3] spots and $field[4] WWV from $field[1]");
547 my @in = reverse Spot::search(1, undef, undef, 0, $field[3]);
550 $self->send(pc26(@{$in}[0..4], $field[2]));
556 my @in = reverse Geomag::search(0, $field[4], time, 1);
559 $self->send(pc27(@{$in}[0..5], $field[2]));
565 if (($pcno >= 28 && $pcno <= 33) || $pcno == 40 || $pcno == 42 || $pcno == 49) { # mail/file handling
566 if ($pcno == 49 || $field[1] eq $main::mycall) {
567 DXMsg::process($self, $line);
569 $self->route($field[1], $line);
574 if ($pcno == 34 || $pcno == 36) { # remote commands (incoming)
575 if ($field[1] eq $main::mycall) {
576 my $ref = DXUser->get_current($field[2]);
577 my $cref = DXCluster->get($field[2]);
578 Log('rcmd', 'in', $ref->{priv}, $field[2], $field[3]);
579 unless ($field[3] =~ /rcmd/i || !$cref || !$ref || $cref->mynode->call ne $ref->homenode) { # not allowed to relay RCMDS!
580 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
581 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
582 my $oldpriv = $self->{priv};
583 $self->{priv} = $ref->{priv}; # assume the user's privilege level
584 my @in = (DXCommandmode::run_cmd($self, $field[3]));
585 $self->{priv} = $oldpriv;
588 $self->send(pc35($main::mycall, $field[2], "$main::mycall:$_"));
589 Log('rcmd', 'out', $field[2], $_);
591 delete $self->{remotecmd};
593 $self->send(pc35($main::mycall, $field[2], "$main::mycall:sorry...!"));
596 $self->send(pc35($main::mycall, $field[2], "$main::mycall:your attempt is logged, Tut tut tut...!"));
599 my $ref = DXUser->get_current($field[1]);
600 if ($ref && $ref->is_clx) {
601 route($field[1], pc84($field[2], $field[1], $field[2], $field[3]));
603 $self->route($field[1], $line);
609 if ($pcno == 35) { # remote command replies
610 if ($field[1] eq $main::mycall) {
611 my $s = $rcmds{$field[2]};
613 my $dxchan = DXChannel->get($s->{call});
614 $dxchan->send($field[3]) if $dxchan;
615 delete $rcmds{$field[2]} if !$dxchan;
618 my $ref = DXUser->get_current($field[1]);
619 if ($ref && $ref->is_clx) {
620 route($field[1], pc85($field[2], $field[1], $field[2], $field[3]));
622 $self->route($field[1], $line);
628 # for pc 37 see 44 onwards
630 if ($pcno == 38) { # node connected list from neighbour
634 if ($pcno == 39) { # incoming disconnect
635 $self->disconnect(1);
639 if ($pcno == 41) { # user info
640 # add this station to the user database, if required
641 my $user = DXUser->get_current($field[1]);
643 # then try without an SSID
644 $field[1] =~ s/-\d+$//o;
645 $user = DXUser->get_current($field[1]);
647 $user = DXUser->new($field[1]) if !$user;
649 if ($field[2] == 1) {
650 $user->name($field[3]);
651 } elsif ($field[2] == 2) {
652 $user->qth($field[3]);
653 } elsif ($field[2] == 3) {
654 my ($lat, $long) = DXBearing::stoll($field[3]);
657 } elsif ($field[2] == 4) {
658 $user->homenode($field[3]);
666 if ($pcno == 37 || $pcno == 44 || $pcno == 45 || $pcno == 46 || $pcno == 47 || $pcno == 48) {
667 DXDb::process($self, $line);
671 if ($pcno == 50) { # keep alive/user list
672 my $node = DXCluster->get_exact($field[1]);
674 return unless $node->isa('DXNode');
675 return unless $node->dxchan == $self;
676 $node->update_users($field[2]);
681 if ($pcno == 51) { # incoming ping requests/answers
684 if ($field[1] eq $main::mycall) {
685 my $flag = $field[3];
687 $self->send(pc51($field[2], $field[1], '0'));
689 # it's a reply, look in the ping list for this one
690 my $ref = $pings{$field[2]};
692 my $tochan = DXChannel->get($field[2]);
695 my $dxchan = DXChannel->get($r->{call});
697 my $t = tv_interval($r->{t}, [ gettimeofday ]);
698 if ($dxchan->is_user) {
699 my $s = sprintf "%.2f", $t;
700 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
701 $dxchan->send($dxchan->msg('pingi', $field[2], $s, $ave))
702 } elsif ($dxchan->is_node) {
704 $tochan->{nopings} = 2; # pump up the timer
705 push @{$tochan->{pingtime}}, $t;
706 shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
708 for (@{$tochan->{pingtime}}) {
711 $tochan->{pingave} = $st / @{$tochan->{pingtime}};
718 # route down an appropriate thingy
719 $self->route($field[1], $line);
724 if ($pcno == 73) { # WCY broadcasts
727 my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
728 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
729 dbg('chan', "WCY Date ($field[1] $field[2]) out of range");
732 @field = map { unpad($_) } @field;
733 if (WCY::dup($d,@field[3..7])) {
734 dbg('chan', "Dup WCY Spot ignored\n");
738 my $wcy = WCY::update($d, @field[2..12]);
742 $rep = Local::wwv($self, @field[1..12]);
744 # dbg('local', "Local::wcy error $@") if $@;
747 # broadcast to the eager world
748 send_wcy_spot($self, $line, $d, @field[2..12]);
752 if ($pcno == 84) { # remote commands (incoming)
753 if ($field[1] eq $main::mycall) {
754 my $ref = DXUser->get_current($field[2]);
755 my $cref = DXCluster->get($field[2]);
756 Log('rcmd', 'in', $ref->{priv}, $field[2], $field[4]);
757 unless ($field[3] =~ /rcmd/i || !$cref || !$ref || $cref->mynode->call ne $ref->homenode) { # not allowed to relay RCMDS!
758 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
759 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
760 my $oldpriv = $self->{priv};
761 $self->{priv} = $ref->{priv}; # assume the user's privilege level
762 my @in = (DXCommandmode::run_cmd($self, $field[4]));
763 $self->{priv} = $oldpriv;
766 $self->send(pc85($main::mycall, $field[2], $field[3], "$main::mycall:$_"));
767 Log('rcmd', 'out', $field[2], $_);
769 delete $self->{remotecmd};
771 $self->send(pc85($main::mycall, $field[2], $field[3], "$main::mycall:sorry...!"));
774 $self->send(pc85($main::mycall, $field[2], $field[3],"$main::mycall:your attempt is logged, Tut tut tut...!"));
777 my $ref = DXUser->get_current($field[1]);
778 if ($ref && $ref->is_clx) {
779 $self->route($field[1], $line);
781 route($field[1], pc34($field[2], $field[1], $field[3]));
787 if ($pcno == 85) { # remote command replies
788 if ($field[1] eq $main::mycall) {
789 my $dxchan = DXChannel->get($field[3]);
791 $dxchan->send($field[4]);
793 my $s = $rcmds{$field[2]};
795 $dxchan = DXChannel->get($s->{call});
796 $dxchan->send($field[4]) if $dxchan;
797 delete $rcmds{$field[2]} if !$dxchan;
801 my $ref = DXUser->get_current($field[1]);
802 if ($ref && $ref->is_clx) {
803 $self->route($field[1], $line);
805 route($field[1], pc35($field[2], $field[1], $field[3]));
812 # if get here then rebroadcast the thing with its Hop count decremented (if
813 # there is one). If it has a hop count and it decrements to zero then don't
816 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
820 unless ($self->{isolate}) {
821 broadcast_ak1a($line, $self); # send it to everyone but me
826 # This is called from inside the main cluster processing loop and is used
827 # for despatching commands that are doing some long processing job
832 my @dxchan = DXChannel->get_all();
835 foreach $dxchan (@dxchan) {
836 next unless $dxchan->is_node();
837 next if $dxchan == $me;
839 # send a pc50 out on this channel
840 if ($t >= $dxchan->pc50_t + $DXProt::pc50_interval) {
841 $dxchan->send(pc50(scalar DXChannel::get_all_users));
845 # send a ping out on this channel
846 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
847 if ($dxchan->{nopings} <= 0) {
850 addping($main::mycall, $dxchan->call);
851 $dxchan->{nopings} -= 1;
852 $dxchan->{lastping} = $t;
860 if ($main::systime - 3600 > $last_hour) {
864 $last_hour = $main::systime;
869 # finish up a pc context
874 my $call = $self->call;
876 my $ref = DXCluster->get_exact($call);
878 # unbusy and stop and outgoing mail
879 my $mref = DXMsg::get_busy($call);
880 $mref->stop_msg($call) if $mref;
882 # broadcast to all other nodes that all the nodes connected to via me are gone
883 my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
886 foreach $node (@gonenodes) {
887 next if $node->call eq $call;
888 broadcast_ak1a(pc21($node->call, 'Gone') , $self) unless $self->{isolate};
892 # remove outstanding pings
893 delete $pings{$call};
895 # now broadcast to all other ak1a nodes that I have gone
896 broadcast_ak1a(pc21($call, 'Gone.'), $self) unless $self->{isolate};
898 # I was the last node visited
899 $self->user->node($main::mycall);
901 # send info to all logged in thingies
902 $self->tell_login('logoutn');
904 Log('DXProt', $call . " Disconnected");
909 # some active measures
915 my @dxchan = DXChannel->get_all();
918 # send it if it isn't the except list and isn't isolated and still has a hop count
919 # taking into account filtering and so on
920 foreach $dxchan (@dxchan) {
924 if ($dxchan->{spotfilter}) {
925 ($filter, $hops) = Filter::it($dxchan->{spotfilter}, @_, $self->{call} );
929 if ($dxchan->is_node) {
930 next if $dxchan == $self;
933 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
935 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
936 next unless $routeit;
939 $dxchan->send($routeit) if $routeit;
941 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
943 } elsif ($dxchan->is_user && $dxchan->{dx}) {
944 my $buf = Spot::formatb($_[0], $_[1], $_[2], $_[3], $_[4]);
945 $buf .= "\a\a" if $dxchan->{beep};
946 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
949 $dxchan->delay($buf);
959 my @dxchan = DXChannel->get_all();
962 # send it if it isn't the except list and isn't isolated and still has a hop count
963 # taking into account filtering and so on
964 foreach $dxchan (@dxchan) {
968 if ($dxchan->{wwvfilter}) {
969 ($filter, $hops) = Filter::it($dxchan->{wwvfilter}, @_, $self->{call} );
972 if ($dxchan->is_node) {
973 next if $dxchan == $self;
976 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
978 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
979 next unless $routeit;
982 $dxchan->send($routeit) if $routeit;
984 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
987 } elsif ($dxchan->is_user && $dxchan->{wwv}) {
988 my $buf = "WWV de $_[6] <$_[1]>: SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
989 $buf .= "\a\a" if $dxchan->{beep};
990 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
993 $dxchan->delay($buf);
1003 my @dxchan = DXChannel->get_all();
1006 # send it if it isn't the except list and isn't isolated and still has a hop count
1007 # taking into account filtering and so on
1008 foreach $dxchan (@dxchan) {
1010 my ($filter, $hops);
1012 if ($dxchan->{wcyfilter}) {
1013 ($filter, $hops) = Filter::it($dxchan->{wcyfilter}, @_, $self->{call} );
1014 next unless $filter;
1016 if ($dxchan->is_clx || $dxchan->is_spider) {
1017 next if $dxchan == $self;
1020 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1022 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1023 next unless $routeit;
1026 $dxchan->send($routeit) if $routeit;
1028 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1030 } elsif ($dxchan->is_user && $dxchan->{wcy}) {
1031 my $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
1032 $buf .= "\a\a" if $dxchan->{beep};
1033 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1034 $dxchan->send($buf);
1036 $dxchan->delay($buf);
1047 my @dxchan = DXChannel->get_all();
1049 my $text = unpad($_[2]);
1053 if ($_[3] eq '*') { # sysops
1055 } elsif ($_[3] gt ' ') { # speciality list handling
1056 my ($name) = split /\./, $_[3];
1057 $target = "$name"; # put the rest in later (if bothered)
1064 $target = "All" if !$target;
1066 Log('ann', $target, $_[0], $text);
1068 # send it if it isn't the except list and isn't isolated and still has a hop count
1069 # taking into account filtering and so on
1070 foreach $dxchan (@dxchan) {
1072 my ($filter, $hops);
1074 if ($dxchan->{annfilter}) {
1075 ($filter, $hops) = Filter::it($dxchan->{annfilter}, @_, $self->{call} );
1076 next unless $filter;
1078 if ($dxchan->is_node && $_[1] ne $main::mycall) { # i.e not specifically routed to me
1079 next if $dxchan == $self;
1082 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1084 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1085 next unless $routeit;
1088 $dxchan->send($routeit) if $routeit;
1090 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1093 } elsif ($dxchan->is_user && $dxchan->{ann}) {
1094 next if $target eq 'SYSOP' && $dxchan->{priv} < 5;
1095 my $buf = "$to$target de $_[0]: $text";
1096 $buf .= "\a\a" if $dxchan->{beep};
1097 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1098 $dxchan->send($buf);
1100 $dxchan->delay($buf);
1106 sub send_local_config
1115 if ($self->{isolate}) {
1116 @localnodes = (DXCluster->get_exact($main::mycall));
1118 # create a list of all the nodes that are not connected to this connection
1119 # and are not themselves isolated, this to make sure that isolated nodes
1120 # don't appear outside of this node
1121 @nodes = DXNode::get_all();
1122 @nodes = grep { $_->{call} ne $main::mycall } @nodes;
1123 @nodes = grep { $_->dxchan != $self } @nodes if @nodes;
1124 @nodes = grep { !$_->dxchan->{isolate} } @nodes if @nodes;
1125 @localnodes = grep { $_->dxchan->{call} eq $_->{call} } @nodes if @nodes;
1126 unshift @localnodes, DXCluster->get_exact($main::mycall);
1127 @remotenodes = grep { $_->dxchan->{call} ne $_->{call} } @nodes if @nodes;
1130 my @s = $me->pc19(@localnodes, @remotenodes);
1132 my $routeit = adjust_hops($self, $_);
1133 $self->send($routeit) if $routeit;
1136 # get all the users connected on the above nodes and send them out
1137 foreach $n (@localnodes, @remotenodes) {
1138 my @users = values %{$n->list};
1139 my @s = pc16($n, @users);
1141 my $routeit = adjust_hops($self, $_);
1142 $self->send($routeit) if $routeit;
1148 # route a message down an appropriate interface for a callsign
1150 # is called route(to, pcline);
1154 my ($self, $call, $line) = @_;
1155 my $cl = DXCluster->get_exact($call);
1156 if ($cl) { # don't route it back down itself
1157 if (ref $self && $call eq $self->{call}) {
1158 dbg('chan', "Trying to route back to source, dropped");
1162 my $dxchan = $cl->{dxchan};
1164 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1166 $dxchan->send($routeit) if $dxchan;
1172 # broadcast a message to all clusters taking into account isolation
1173 # [except those mentioned after buffer]
1176 my $s = shift; # the line to be rebroadcast
1177 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1178 my @dxchan = DXChannel::get_all_ak1a();
1181 # send it if it isn't the except list and isn't isolated and still has a hop count
1182 foreach $dxchan (@dxchan) {
1183 next if grep $dxchan == $_, @except;
1184 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1185 $dxchan->send($routeit) unless $dxchan->{isolate} || !$routeit;
1189 # broadcast a message to all clusters ignoring isolation
1190 # [except those mentioned after buffer]
1191 sub broadcast_all_ak1a
1193 my $s = shift; # the line to be rebroadcast
1194 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1195 my @dxchan = DXChannel::get_all_ak1a();
1198 # send it if it isn't the except list and isn't isolated and still has a hop count
1199 foreach $dxchan (@dxchan) {
1200 next if grep $dxchan == $_, @except;
1201 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1202 $dxchan->send($routeit);
1206 # broadcast to all users
1207 # storing the spot or whatever until it is in a state to receive it
1210 my $s = shift; # the line to be rebroadcast
1211 my $sort = shift; # the type of transmission
1212 my $fref = shift; # a reference to an object to filter on
1213 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1214 my @dxchan = DXChannel::get_all_users();
1218 foreach $dxchan (@dxchan) {
1219 next if grep $dxchan == $_, @except;
1222 broadcast_list($s, $sort, $fref, @out);
1225 # broadcast to a list of users
1233 foreach $dxchan (@_) {
1236 if ($sort eq 'dx') {
1237 next unless $dxchan->{dx};
1238 ($filter) = Filter::it($dxchan->{spotfilter}, @{$fref}) if ref $fref;
1239 next unless $filter;
1241 next if $sort eq 'ann' && !$dxchan->{ann};
1242 next if $sort eq 'wwv' && !$dxchan->{wwv};
1243 next if $sort eq 'wcy' && !$dxchan->{wcy};
1244 next if $sort eq 'wx' && !$dxchan->{wx};
1246 $s =~ s/\a//og unless $dxchan->{beep};
1248 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1258 # obtain the hops from the list for this callsign and pc no
1264 my $hops = $DXProt::hopcount{$pcno};
1265 $hops = $DXProt::def_hopcount if !$hops;
1270 # adjust the hop count on a per node basis using the user loadable
1271 # hop table if available or else decrement an existing one
1278 my $call = $self->{call};
1281 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
1282 my ($pcno) = $s =~ /^PC(\d\d)/o;
1283 confess "$call called adjust_hops with '$s'" unless $pcno;
1284 my $ref = $nodehops{$call} if %nodehops;
1286 my $newhops = $ref->{$pcno};
1287 return "" if defined $newhops && $newhops == 0;
1288 $newhops = $ref->{default} unless $newhops;
1289 return "" if defined $newhops && $newhops == 0;
1290 $newhops = $hops if !$newhops;
1291 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1293 # simply decrement it
1295 return "" if !$hops;
1296 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
1308 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
1309 do "$main::data/hop_table.pl";
1315 # add a ping request to the ping queues
1318 my ($from, $to) = @_;
1319 my $ref = $pings{$to} || [];
1322 $r->{t} = [ gettimeofday ];
1323 route(undef, $to, pc51($to, $main::mycall, 1));
1328 # add a rcmd request to the rcmd queues
1331 my ($self, $to, $cmd) = @_;
1334 $r->{call} = $self->{call};
1335 $r->{t} = $main::systime;
1339 my $ref = DXCluster->get_exact($to);
1340 if ($ref && $ref->dxchan && $ref->dxchan->is_clx) {
1341 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1343 route(undef, $to, pc34($main::mycall, $to, $cmd));
1352 if ($self->{conn} && !$nopc39) {
1353 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1356 $self->SUPER::disconnect;