3 # This module impliments the protocal mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
32 use vars qw($me $pc11_max_age $pc23_max_age $pc11_dup_age $pc23_dup_age
33 %spotdup %wwvdup $last_hour %pings %rcmds
34 %nodehops @baddx $baddxfn $pc12_dup_age
35 %anndup $allowzero $pc12_dup_lth $decode_dk0wcy);
37 $me = undef; # the channel id for this cluster
38 $decode_dk0wcy = undef; # if set use this callsign to decode announces from the EU WWV data beacon
39 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
40 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
41 $pc11_dup_age = 24*3600; # the maximum time to keep the spot dup list for
42 $pc23_dup_age = 24*3600; # the maximum time to keep the wwv dup list for
43 $pc12_dup_age = 12*3600; # the maximum time to keep the ann dup list for
44 $pc12_dup_lth = 60; # the length of ANN text to save for deduping
45 %spotdup = (); # the pc11 and 26 dup hash
46 %wwvdup = (); # the pc23 and 27 dup hash
47 %anndup = (); # the PC12 dup hash
48 $last_hour = time; # last time I did an hourly periodic update
49 %pings = (); # outstanding ping requests outbound
50 %rcmds = (); # outstanding rcmd requests outbound
51 %nodehops = (); # node specific hop control
52 @baddx = (); # list of illegal spotted callsigns
54 $baddxfn = "$main::data/baddx.pl";
58 my $user = DXUser->get($main::mycall);
59 $DXProt::myprot_version += $main::version*100;
60 $me = DXProt->new($main::mycall, 0, $user);
62 $me->{state} = "indifferent";
63 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
65 # $me->{sort} = 'M'; # M for me
67 # now prime the spot duplicates file with today's and yesterday's data
68 my @today = Julian::unixtoj(time);
69 my @spots = Spot::readfile(@today);
70 @today = Julian::sub(@today, 1);
71 push @spots, Spot::readfile(@today);
73 my $dupkey = "$_->[0]$_->[1]$_->[2]$_->[3]$_->[4]";
74 $spotdup{$dupkey} = $_->[2];
77 # now prime the wwv duplicates file with just this month's data
78 my @wwv = Geomag::readfile(time);
80 my $dupkey = "$_->[1].$_->[2]$_->[3]$_->[4]";
81 $wwvdup{$dupkey} = $_->[1];
85 do "$baddxfn" if -e "$baddxfn";
90 # obtain a new connection this is derived from dxchannel
95 my $self = DXChannel::alloc(@_);
96 $self->{'sort'} = 'A'; # in absence of how to find out what sort of an object I am
100 # this is how a pc connection starts (for an incoming connection)
101 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
102 # all the crap that comes between).
105 my ($self, $line, $sort) = @_;
106 my $call = $self->{call};
107 my $user = $self->{user};
109 # remember type of connection
110 $self->{consort} = $line;
111 $self->{outbound} = $sort eq 'O';
112 $self->{priv} = $user->priv;
113 $self->{lang} = $user->lang;
114 $self->{isolate} = $user->{isolate};
115 $self->{consort} = $line; # save the connection type
118 # get the INPUT filters (these only pertain to Clusters)
119 $self->{inspotfilter} = Filter::read_in('spots', $call, 1);
120 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1);
121 $self->{inannfilter} = Filter::read_in('ann', $call, 1);
123 # set unbuffered and no echo
124 $self->send_now('B',"0");
125 $self->send_now('E',"0");
127 # send initialisation string
128 if (!$self->{outbound}) {
129 $self->send(pc38()) if DXNode->get_all();
132 $self->state('init');
135 Log('DXProt', "$call connected");
139 # This is the normal pcxx despatcher
143 my ($self, $line) = @_;
144 my @field = split /\^/, $line;
145 pop @field if $field[-1] eq '~';
147 # print join(',', @field), "\n";
149 # ignore any lines that don't start with PC
150 return if !$field[0] =~ /^PC/;
153 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
155 return if $pcno < 10 || $pcno > 51;
157 # dump bad protocol messages unless it is a PC29
158 if ($line =~ /\%[0-9A-F][0-9A-F]/o && $pcno != 29) {
159 dbg('chan', "CORRUPT protocol message - dumped");
166 $pcr = Local::pcprot($self, $pcno, @field);
168 # dbg('local', "Local::pcprot error $@") if $@;
172 if ($pcno == 10) { # incoming talk
174 # is it for me or one of mine?
175 my $call = ($field[5] gt ' ') ? $field[5] : $field[2];
176 if ($call eq $main::mycall || grep $_ eq $call, get_all_user_calls()) {
179 my $text = unpad($field[3]);
180 Log('talk', $call, $field[1], $field[6], $text);
181 $call = $main::myalias if $call eq $main::mycall;
182 my $ref = DXChannel->get($call);
183 $ref->send("$call de $field[1]: $text") if $ref && $ref->{talk};
185 $self->route($field[2], $line); # relay it on its way
190 if ($pcno == 11 || $pcno == 26) { # dx spot
192 # route 'foreign' pc26s
194 if ($field[7] ne $main::mycall) {
195 $self->route($field[7], $line);
200 # if this is a 'nodx' node then ignore it
201 if (grep $field[7] =~ /^$_/, @DXProt::nodx_node) {
202 dbg('chan', "Bad DXNode, dropped");
206 # convert the date to a unix date
207 my $d = cltounix($field[3], $field[4]);
208 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
209 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
210 dbg('chan', "Spot ignored, invalid date or out of range ($field[3] $field[4])\n");
214 # strip off the leading & trailing spaces from the comment
215 my $text = unpad($field[5]);
218 my $spotter = $field[6];
219 $spotter =~ s/-[\@\d]+$//o; # strip off the ssid from the spotter
222 my $freq = $field[1] - 0;
223 my $dupkey = "$freq$field[2]$d$text$spotter";
224 if ($spotdup{$dupkey}) {
225 dbg('chan', "Duplicate Spot ignored\n");
229 $spotdup{$dupkey} = $d;
232 if (grep $field[2] eq $_, @baddx) {
233 dbg('chan', "Bad DX spot, ignored");
237 # are any of the crucial fields invalid?
238 if ($field[2] =~ /[a-z]/ || $field[6] =~ /[a-z]/ || $field[7] =~ /[a-z]/) {
239 dbg('chan', "Spot contains lower case callsigns, rejected");
243 my @spot = Spot::add($freq, $field[2], $d, $text, $spotter, $field[7]);
246 # @spot at this point contains:-
247 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
248 # then spotted itu, spotted cq, spotters itu, spotters cq
249 # you should be able to route on any of these
255 $r = Local::spot($self, @spot);
257 # dbg('local', "Local::spot1 error $@") if $@;
260 # DON'T be silly and send on PC26s!
261 return if $pcno == 26;
263 # send out the filtered spots
264 send_dx_spot($self, $line, @spot) if @spot;
268 if ($pcno == 12) { # announces
269 # announce duplicate checking
270 my $text = substr(uc unpad($field[3]), 0, $pc12_dup_lth);
271 my $dupkey = $field[1].$field[2].$text;
272 if ($anndup{$dupkey}) {
273 dbg('chan', "Duplicate Announce ignored\n");
276 $anndup{$dupkey} = $main::systime;
278 if ($field[2] eq '*' || $field[2] eq $main::mycall) {
280 # global ann filtering on INPUT
281 if ($self->{inannfilter}) {
282 my ($filter, $hops) = Filter::it($self->{inannfilter}, @field[1..6], $self->{call} );
284 dbg('chan', "Rejected by filter");
290 $self->send_announce($line, @field[1..6]);
292 if ($decode_dk0wcy && $field[1] eq $decode_dk0wcy) {
293 my ($hour, $k, $next, $a, $r, $sfi, $alarm) = $field[3] =~ /^Aurora Beacon\s+(\d+)UTC,\s+Kiel\s+K=(\d+),.*ed\s+K=(\d+),\s+A=(\d+),\s+R=(\d+),\s+SFI=(\d+),.*larm:\s+(\w+)/;
294 $alarm = ($alarm =~ /^Y/i) ? ', Aurora in DE' : '';
295 my $wwv = Geomag::update($main::systime, $hour, $sfi, $a, $k, "R=$r, Next K=$next$alarm", $decode_dk0wcy, $field[5], $r) if $sfi && $r;
299 $self->route($field[2], $line);
315 if ($pcno == 16) { # add a user
316 my $node = DXCluster->get_exact($field[1]);
318 if (!$node && ($dxchan = DXChannel->get($field[1]))) {
319 # add it to the node table if it isn't present and it's
321 $node = DXNode->new($dxchan, $field[1], 0, 1, 5400);
322 broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
325 return unless $node; # ignore if havn't seen a PC19 for this one yet
326 return unless $node->isa('DXNode');
327 if ($node->dxchan != $self) {
328 dbg('chan', "LOOP: $field[1] came in on wrong channel");
331 if (($dxchan = DXChannel->get($field[1])) && $dxchan != $self) {
332 dbg('chan', "LOOP: $field[1] connected locally");
337 for ($i = 2; $i < $#field; $i++) {
338 my ($call, $confmode, $here) = $field[$i] =~ /^(\S+) (\S) (\d)/o;
339 next if !$call || length $call < 3 || length $call > 8;
342 next if DXCluster->get_exact($call); # we already have this (loop?)
344 $confmode = $confmode eq '*';
345 DXNodeuser->new($self, $node, $call, $confmode, $here);
347 # add this station to the user database, if required
348 $call =~ s/-\d+$//o; # remove ssid for users
349 my $user = DXUser->get_current($call);
350 $user = DXUser->new($call) if !$user;
351 $user->homenode($node->call) if !$user->homenode;
352 $user->node($node->call);
353 $user->lastin($main::systime) unless DXChannel->get($call);
357 # queue up any messages (look for privates only)
358 DXMsg::queue_msg(1) if $self->state eq 'normal';
362 if ($pcno == 17) { # remove a user
363 my $node = DXCluster->get_exact($field[2]);
365 if (!$node && ($dxchan = DXChannel->get($field[2]))) {
366 # add it to the node table if it isn't present and it's
368 $node = DXNode->new($dxchan, $field[2], 0, 1, 5400);
369 broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
373 return unless $node->isa('DXNode');
374 if ($node->dxchan != $self) {
375 dbg('chan', "LOOP: $field[2] came in on wrong channel");
378 if (($dxchan = DXChannel->get($field[2])) && $dxchan != $self) {
379 dbg('chan', "LOOP: $field[2] connected locally");
382 my $ref = DXCluster->get_exact($field[1]);
387 if ($pcno == 18) { # link request
388 $self->state('init');
390 # first clear out any nodes on this dxchannel
391 my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
392 foreach my $node (@gonenodes) {
393 next if $node->dxchan == $DXProt::me;
394 broadcast_ak1a(pc21($node->call, 'Gone, re-init') , $self) unless $self->{isolate};
397 $self->send_local_config();
399 return; # we don't pass these on
402 if ($pcno == 19) { # incoming cluster list
404 my $newline = "PC19^";
405 for ($i = 1; $i < $#field-1; $i += 4) {
406 my $here = $field[$i];
407 my $call = uc $field[$i+1];
408 my $confmode = $field[$i+2];
409 my $ver = $field[$i+3];
411 $ver = 5400 if !$ver && $allowzero;
413 # now check the call over
414 my $node = DXCluster->get_exact($call);
417 if (($dxchan = DXChannel->get($call)) && $dxchan != $self) {
418 dbg('chan', "LOOP: $call connected locally");
420 if ($node->dxchan != $self) {
421 dbg('chan', "LOOP: $call come in on wrong channel");
424 dbg('chan', "already have $call");
428 # check for sane parameters
429 next if $ver < 5000; # only works with version 5 software
430 next if length $call < 3; # min 3 letter callsigns
432 # add it to the nodes table and outgoing line
433 $newline .= "$here^$call^$confmode^$ver^";
434 DXNode->new($self, $call, $confmode, $here, $ver);
436 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
437 my $mref = DXMsg::get_busy($call);
438 $mref->stop_msg($call) if $mref;
440 # add this station to the user database, if required (don't remove SSID from nodes)
441 my $user = DXUser->get_current($call);
443 $user = DXUser->new($call);
445 $user->priv(1); # I have relented and defaulted nodes
446 $self->{priv} = 1; # to user RCMDs allowed
447 $user->homenode($call);
450 $user->lastin($main::systime) unless DXChannel->get($call);
454 return if $newline eq "PC19^";
457 $newline .= get_hops(19) . "^";
462 if ($pcno == 20) { # send local configuration
463 $self->send_local_config();
465 $self->state('normal');
469 if ($pcno == 21) { # delete a cluster from the list
470 my $call = uc $field[1];
471 if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
472 my $node = DXCluster->get_exact($call);
474 if ($node->dxchan != $self) {
475 dbg('chan', "LOOP: $call come in on wrong channel");
479 if (($dxchan = DXChannel->get($call)) && $dxchan != $self) {
480 dbg('chan', "LOOP: $call connected locally");
485 dbg('chan', "$call not in table, dropped");
493 $self->state('normal');
497 if ($pcno == 23 || $pcno == 27) { # WWV info
499 # route 'foreign' pc27s
501 if ($field[8] ne $main::mycall) {
502 $self->route($field[8], $line);
508 my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
509 my $sfi = unpad($field[3]);
510 my $k = unpad($field[4]);
511 my $i = unpad($field[5]);
512 my ($r) = $field[6] =~ /R=(\d+)/;
514 my $dupkey = "$d.$sfi$k$i";
515 if ($wwvdup{$dupkey}) {
516 dbg('chan', "Dup WWV Spot ignored\n");
519 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
520 dbg('chan', "WWV Date ($field[1] $field[2]) out of range");
523 $wwvdup{$dupkey} = $d;
524 $field[6] =~ s/-\d+$//o; # remove spotter's ssid
526 my $wwv = Geomag::update($d, $field[2], $sfi, $k, $i, @field[6..8], $r);
530 $rep = Local::wwv($self, $field[1], $field[2], $sfi, $k, $i, @field[6..8], $r);
532 # dbg('local', "Local::wwv2 error $@") if $@;
535 # DON'T be silly and send on PC27s!
536 return if $pcno == 27;
538 # broadcast to the eager world
539 send_wwv_spot($self, $line, $d, $field[2], $sfi, $k, $i, @field[6..8]);
543 if ($pcno == 24) { # set here status
544 my $call = uc $field[1];
545 my $ref = DXCluster->get_exact($call);
546 $ref->here($field[2]) if $ref;
550 if ($pcno == 25) { # merge request
551 if ($field[1] ne $main::mycall) {
552 $self->route($field[1], $line);
555 if ($field[2] eq $main::mycall) {
556 dbg('chan', "Trying to merge to myself, ignored");
560 Log('DXProt', "Merge request for $field[3] spots and $field[4] WWV from $field[1]");
564 my @in = reverse Spot::search(1, undef, undef, 0, $field[3]);
567 $self->send(pc26(@{$in}[0..4], $field[2]));
573 my @in = reverse Geomag::search(0, $field[4], time, 1);
576 $self->send(pc27(@{$in}[0..5], $field[2]));
582 if (($pcno >= 28 && $pcno <= 33) || $pcno == 40 || $pcno == 42 || $pcno == 49) { # mail/file handling
583 if ($pcno == 49 || $field[1] eq $main::mycall) {
584 DXMsg::process($self, $line);
586 $self->route($field[1], $line);
591 if ($pcno == 34 || $pcno == 36) { # remote commands (incoming)
592 if ($field[1] eq $main::mycall) {
593 my $ref = DXUser->get_current($field[2]);
594 my $cref = DXCluster->get($field[2]);
595 Log('rcmd', 'in', $ref->{priv}, $field[2], $field[3]);
596 unless ($field[3] =~ /rcmd/i || !$cref || !$ref || $cref->mynode->call ne $ref->homenode) { # not allowed to relay RCMDS!
597 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
598 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
599 my $oldpriv = $self->{priv};
600 $self->{priv} = $ref->{priv}; # assume the user's privilege level
601 my @in = (DXCommandmode::run_cmd($self, $field[3]));
602 $self->{priv} = $oldpriv;
605 $self->send(pc35($main::mycall, $field[2], "$main::mycall:$_"));
606 Log('rcmd', 'out', $field[2], $_);
608 delete $self->{remotecmd};
610 $self->send(pc35($main::mycall, $field[2], "$main::mycall:sorry...!"));
613 $self->send(pc35($main::mycall, $field[2], "$main::mycall:your attempt is logged, Tut tut tut...!"));
616 $self->route($field[1], $line);
621 if ($pcno == 35) { # remote command replies
622 if ($field[1] eq $main::mycall) {
623 my $s = $rcmds{$field[2]};
625 my $dxchan = DXChannel->get($s->{call});
626 $dxchan->send($field[3]) if $dxchan;
627 delete $rcmds{$field[2]} if !$dxchan;
630 $self->route($field[1], $line);
635 # for pc 37 see 44 onwards
637 if ($pcno == 38) { # node connected list from neighbour
641 if ($pcno == 39) { # incoming disconnect
646 if ($pcno == 41) { # user info
647 # add this station to the user database, if required
648 my $user = DXUser->get_current($field[1]);
650 # then try without an SSID
651 $field[1] =~ s/-\d+$//o;
652 $user = DXUser->get_current($field[1]);
654 $user = DXUser->new($field[1]) if !$user;
656 if ($field[2] == 1) {
657 $user->name($field[3]);
658 } elsif ($field[2] == 2) {
659 $user->qth($field[3]);
660 } elsif ($field[2] == 3) {
661 my ($lat, $long) = DXBearing::stoll($field[3]);
664 } elsif ($field[2] == 4) {
665 $user->homenode($field[3]);
673 if ($pcno == 37 || $pcno == 44 || $pcno == 45 || $pcno == 46 || $pcno == 47) {
674 DXDb::process($self, $line);
678 if ($pcno == 50) { # keep alive/user list
679 my $node = DXCluster->get_exact($field[1]);
681 return unless $node->isa('DXNode');
682 return unless $node->dxchan == $self;
683 $node->update_users($field[2]);
688 if ($pcno == 51) { # incoming ping requests/answers
691 if ($field[1] eq $main::mycall) {
692 my $flag = $field[3];
694 $self->send(pc51($field[2], $field[1], '0'));
696 # it's a reply, look in the ping list for this one
697 my $ref = $pings{$field[2]};
701 my $dxchan = DXChannel->get($r->{call});
702 $dxchan->send($dxchan->msg('pingi', $field[2], atime($main::systime), $main::systime - $r->{t})) if $dxchan;
708 # route down an appropriate thingy
709 $self->route($field[1], $line);
715 # if get here then rebroadcast the thing with its Hop count decremented (if
716 # there is one). If it has a hop count and it decrements to zero then don't
719 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
723 unless ($self->{isolate}) {
724 broadcast_ak1a($line, $self); # send it to everyone but me
729 # This is called from inside the main cluster processing loop and is used
730 # for despatching commands that are doing some long processing job
735 my @dxchan = DXChannel->get_all();
738 foreach $dxchan (@dxchan) {
739 next unless $dxchan->is_ak1a();
740 next if $dxchan == $me;
742 # send a pc50 out on this channel
743 if ($t >= $dxchan->pc50_t + $DXProt::pc50_interval) {
744 $dxchan->send(pc50());
752 if ($main::systime - 3600 > $last_hour) {
753 $cutoff = $main::systime - $pc11_dup_age;
754 while (($key, $val) = each %spotdup) {
755 delete $spotdup{$key} if $val < $cutoff;
757 $cutoff = $main::systime - $pc23_dup_age;
758 while (($key, $val) = each %wwvdup) {
759 delete $wwvdup{$key} if $val < $cutoff;
761 $cutoff = $main::systime - $pc12_dup_age;
762 while (($key, $val) = each %anndup) {
763 delete $anndup{$key} if $val < $cutoff;
765 $last_hour = $main::systime;
770 # finish up a pc context
775 my $call = $self->call;
776 my $ref = DXCluster->get_exact($call);
778 # unbusy and stop and outgoing mail
779 my $mref = DXMsg::get_busy($call);
780 $mref->stop_msg($call) if $mref;
782 # broadcast to all other nodes that all the nodes connected to via me are gone
783 my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
786 foreach $node (@gonenodes) {
787 next if $node->call eq $call;
788 broadcast_ak1a(pc21($node->call, 'Gone') , $self) unless $self->{isolate};
792 # remove outstanding pings
793 delete $pings{$call};
795 # now broadcast to all other ak1a nodes that I have gone
796 broadcast_ak1a(pc21($call, 'Gone.'), $self) unless $self->{isolate};
798 Log('DXProt', $call . " Disconnected");
803 # some active measures
809 my @dxchan = DXChannel->get_all();
812 # send it if it isn't the except list and isn't isolated and still has a hop count
813 # taking into account filtering and so on
814 foreach $dxchan (@dxchan) {
818 if ($dxchan->{spotfilter}) {
819 ($filter, $hops) = Filter::it($dxchan->{spotfilter}, @_, $self->{call} );
823 if ($dxchan->is_ak1a) {
824 next if $dxchan == $self;
827 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
829 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
830 next unless $routeit;
833 $dxchan->send($routeit) if $routeit;
835 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
837 } elsif ($dxchan->is_user && $dxchan->{dx}) {
838 my $buf = Spot::formatb($_[0], $_[1], $_[2], $_[3], $_[4]);
839 $buf .= "\a\a" if $dxchan->{beep};
840 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
843 $dxchan->delay($buf);
853 my @dxchan = DXChannel->get_all();
856 # send it if it isn't the except list and isn't isolated and still has a hop count
857 # taking into account filtering and so on
858 foreach $dxchan (@dxchan) {
862 if ($dxchan->{spotfilter}) {
863 ($filter, $hops) = Filter::it($dxchan->{wwvfilter}, @_, $self->{call} );
866 if ($dxchan->is_ak1a) {
867 next if $dxchan == $self;
870 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
872 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
873 next unless $routeit;
876 $dxchan->send($routeit) if $routeit;
878 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
881 } elsif ($dxchan->is_user && $dxchan->{wwv}) {
882 my $buf = "WWV de $_[6] <$_[1]>: SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
883 $buf .= "\a\a" if $dxchan->{beep};
884 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
887 $dxchan->delay($buf);
898 my @dxchan = DXChannel->get_all();
900 my $text = unpad($_[2]);
904 if ($_[3] eq '*') { # sysops
906 } elsif ($_[3] gt ' ') { # speciality list handling
907 my ($name) = split /\./, $_[3];
908 $target = "$name"; # put the rest in later (if bothered)
915 $target = "All" if !$target;
917 Log('ann', $target, $_[0], $text);
919 # send it if it isn't the except list and isn't isolated and still has a hop count
920 # taking into account filtering and so on
921 foreach $dxchan (@dxchan) {
925 if ($dxchan->{annfilter}) {
926 ($filter, $hops) = Filter::it($dxchan->{annfilter}, @_, $self->{call} );
929 if ($dxchan->is_ak1a && $_[1] ne $main::mycall) { # i.e not specifically routed to me
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};
944 } elsif ($dxchan->is_user && $dxchan->{ann}) {
945 next if $target eq 'SYSOP' && $dxchan->{priv} < 5;
946 my $buf = "$to$target de $_[0]: $text";
947 $buf .= "\a\a" if $dxchan->{beep};
948 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
951 $dxchan->delay($buf);
957 sub send_local_config
966 if ($self->{isolate}) {
967 @localnodes = (DXCluster->get_exact($main::mycall));
969 # create a list of all the nodes that are not connected to this connection
970 # and are not themselves isolated, this to make sure that isolated nodes
971 # don't appear outside of this node
972 @nodes = DXNode::get_all();
973 @nodes = grep { $_->{call} ne $main::mycall } @nodes;
974 @nodes = grep { $_->dxchan != $self } @nodes if @nodes;
975 @nodes = grep { !$_->dxchan->{isolate} } @nodes if @nodes;
976 @localnodes = grep { $_->dxchan->{call} eq $_->{call} } @nodes if @nodes;
977 unshift @localnodes, DXCluster->get_exact($main::mycall);
978 @remotenodes = grep { $_->dxchan->{call} ne $_->{call} } @nodes if @nodes;
981 my @s = $me->pc19(@localnodes, @remotenodes);
983 my $routeit = adjust_hops($self, $_);
984 $self->send($routeit) if $routeit;
987 # get all the users connected on the above nodes and send them out
988 foreach $n (@localnodes, @remotenodes) {
989 my @users = values %{$n->list};
990 my @s = pc16($n, @users);
992 my $routeit = adjust_hops($self, $_);
993 $self->send($routeit) if $routeit;
999 # route a message down an appropriate interface for a callsign
1001 # is called route(to, pcline);
1005 my ($self, $call, $line) = @_;
1006 my $cl = DXCluster->get_exact($call);
1007 if ($cl) { # don't route it back down itself
1008 if (ref $self && $call eq $self->{call}) {
1009 dbg('chan', "Trying to route back to source, dropped");
1013 my $dxchan = $cl->{dxchan};
1015 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1017 $dxchan->send($routeit) if $dxchan;
1023 # broadcast a message to all clusters taking into account isolation
1024 # [except those mentioned after buffer]
1027 my $s = shift; # the line to be rebroadcast
1028 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1029 my @dxchan = get_all_ak1a();
1032 # send it if it isn't the except list and isn't isolated and still has a hop count
1033 foreach $dxchan (@dxchan) {
1034 next if grep $dxchan == $_, @except;
1035 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1036 $dxchan->send($routeit) unless $dxchan->{isolate} || !$routeit;
1040 # broadcast a message to all clusters ignoring isolation
1041 # [except those mentioned after buffer]
1042 sub broadcast_all_ak1a
1044 my $s = shift; # the line to be rebroadcast
1045 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1046 my @dxchan = get_all_ak1a();
1049 # send it if it isn't the except list and isn't isolated and still has a hop count
1050 foreach $dxchan (@dxchan) {
1051 next if grep $dxchan == $_, @except;
1052 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1053 $dxchan->send($routeit);
1057 # broadcast to all users
1058 # storing the spot or whatever until it is in a state to receive it
1061 my $s = shift; # the line to be rebroadcast
1062 my $sort = shift; # the type of transmission
1063 my $fref = shift; # a reference to an object to filter on
1064 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1065 my @dxchan = get_all_users();
1069 foreach $dxchan (@dxchan) {
1070 next if grep $dxchan == $_, @except;
1073 broadcast_list($s, $sort, $fref, @out);
1076 # broadcast to a list of users
1084 foreach $dxchan (@_) {
1087 if ($sort eq 'dx') {
1088 next unless $dxchan->{dx};
1089 ($filter) = Filter::it($dxchan->{spotfilter}, @{$fref}) if ref $fref;
1090 next unless $filter;
1092 next if $sort eq 'ann' && !$dxchan->{ann};
1093 next if $sort eq 'wwv' && !$dxchan->{wwv};
1094 next if $sort eq 'wx' && !$dxchan->{wx};
1096 $s =~ s/\a//og unless $dxchan->{beep};
1098 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1107 # gimme all the ak1a nodes
1111 my @list = DXChannel->get_all();
1114 foreach $ref (@list) {
1115 push @out, $ref if $ref->is_ak1a;
1120 # return a list of all users
1123 my @list = DXChannel->get_all();
1126 foreach $ref (@list) {
1127 push @out, $ref if $ref->is_user;
1132 # return a list of all user callsigns
1133 sub get_all_user_calls
1135 my @list = DXChannel->get_all();
1138 foreach $ref (@list) {
1139 push @out, $ref->call if $ref->is_user;
1145 # obtain the hops from the list for this callsign and pc no
1151 my $hops = $DXProt::hopcount{$pcno};
1152 $hops = $DXProt::def_hopcount if !$hops;
1157 # adjust the hop count on a per node basis using the user loadable
1158 # hop table if available or else decrement an existing one
1165 my $call = $self->{call};
1168 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
1169 my ($pcno) = $s =~ /^PC(\d\d)/o;
1170 confess "$call called adjust_hops with '$s'" unless $pcno;
1171 my $ref = $nodehops{$call} if %nodehops;
1173 my $newhops = $ref->{$pcno};
1174 return "" if defined $newhops && $newhops == 0;
1175 $newhops = $ref->{default} unless $newhops;
1176 return "" if defined $newhops && $newhops == 0;
1177 $newhops = $hops if !$newhops;
1178 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1180 # simply decrement it
1182 return "" if !$hops;
1183 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
1195 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
1196 do "$main::data/hop_table.pl";
1201 # remove leading and trailing spaces from an input string
1205 $s =~ s/^\s+|\s+$//;
1209 # add a ping request to the ping queues
1212 my ($from, $to) = @_;
1213 my $ref = $pings{$to};
1214 $ref = $pings{$to} = [] if !$ref;
1217 $r->{t} = $main::systime;
1218 route(undef, $to, pc51($to, $main::mycall, 1));
1222 # add a rcmd request to the rcmd queues
1225 my ($from, $to, $cmd) = @_;
1228 $r->{t} = $main::systime;
1230 route(undef, $to, pc34($main::mycall, $to, $cmd));