3 # This module impliments the protocal mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
31 use vars qw($me $pc11_max_age $pc23_max_age $pc11_dup_age $pc23_dup_age
32 %spotdup %wwvdup $last_hour %pings %rcmds
33 %nodehops @baddx $baddxfn $pc12_dup_age
34 %anndup $allowzero $pc12_dup_lth $decode_dk0wcy);
36 $me = undef; # the channel id for this cluster
37 $decode_dk0wcy = undef; # if set use this callsign to decode announces from the EU WWV data beacon
38 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
39 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
40 $pc11_dup_age = 24*3600; # the maximum time to keep the spot dup list for
41 $pc23_dup_age = 24*3600; # the maximum time to keep the wwv dup list for
42 $pc12_dup_age = 12*3600; # the maximum time to keep the ann dup list for
43 $pc12_dup_lth = 72; # the length of ANN text to save for deduping
44 %spotdup = (); # the pc11 and 26 dup hash
45 %wwvdup = (); # the pc23 and 27 dup hash
46 %anndup = (); # the PC12 dup hash
47 $last_hour = time; # last time I did an hourly periodic update
48 %pings = (); # outstanding ping requests outbound
49 %rcmds = (); # outstanding rcmd requests outbound
50 %nodehops = (); # node specific hop control
51 @baddx = (); # list of illegal spotted callsigns
53 $baddxfn = "$main::data/baddx.pl";
57 my $user = DXUser->get($main::mycall);
58 $DXProt::myprot_version += $main::version*100;
59 $me = DXProt->new($main::mycall, 0, $user);
61 $me->{state} = "indifferent";
62 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
64 # $me->{sort} = 'M'; # M for me
66 # now prime the spot duplicates file with today's and yesterday's data
67 my @today = Julian::unixtoj(time);
68 my @spots = Spot::readfile(@today);
69 @today = Julian::sub(@today, 1);
70 push @spots, Spot::readfile(@today);
72 my $dupkey = "$_->[0]$_->[1]$_->[2]$_->[3]$_->[4]";
73 $spotdup{$dupkey} = $_->[2];
76 # now prime the wwv duplicates file with just this month's data
77 my @wwv = Geomag::readfile(time);
79 my $dupkey = "$_->[1].$_->[2]$_->[3]$_->[4]";
80 $wwvdup{$dupkey} = $_->[1];
84 do "$baddxfn" if -e "$baddxfn";
89 # obtain a new connection this is derived from dxchannel
94 my $self = DXChannel::alloc(@_);
95 $self->{'sort'} = 'A'; # in absence of how to find out what sort of an object I am
99 # this is how a pc connection starts (for an incoming connection)
100 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
101 # all the crap that comes between).
104 my ($self, $line, $sort) = @_;
105 my $call = $self->{call};
106 my $user = $self->{user};
108 # remember type of connection
109 $self->{consort} = $line;
110 $self->{outbound} = $sort eq 'O';
111 $self->{priv} = $user->priv;
112 $self->{lang} = $user->lang;
113 $self->{isolate} = $user->{isolate};
114 $self->{consort} = $line; # save the connection type
117 # get the INPUT filters (these only pertain to Clusters)
118 $self->{inspotfilter} = Filter::read_in('spots', $call, 1);
119 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1);
120 $self->{inannfilter} = Filter::read_in('ann', $call, 1);
122 # set unbuffered and no echo
123 $self->send_now('B',"0");
124 $self->send_now('E',"0");
126 # send initialisation string
127 if (!$self->{outbound}) {
128 $self->send(pc38()) if DXNode->get_all();
131 $self->state('init');
134 Log('DXProt', "$call connected");
138 # This is the normal pcxx despatcher
142 my ($self, $line) = @_;
143 my @field = split /\^/, $line;
144 pop @field if $field[-1] eq '~';
146 # print join(',', @field), "\n";
148 # ignore any lines that don't start with PC
149 return if !$field[0] =~ /^PC/;
152 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
154 return if $pcno < 10 || $pcno > 51;
156 # dump bad protocol messages unless it is a PC29
157 if ($line =~ /\%[0-9A-F][0-9A-F]/o && $pcno != 29) {
158 dbg('chan', "CORRUPT protocol message - dumped");
165 $pcr = Local::pcprot($self, $pcno, @field);
167 # dbg('local', "Local::pcprot error $@") if $@;
171 if ($pcno == 10) { # incoming talk
173 # is it for me or one of mine?
174 my $call = ($field[5] gt ' ') ? $field[5] : $field[2];
175 if ($call eq $main::mycall || grep $_ eq $call, get_all_user_calls()) {
178 my $text = unpad($field[3]);
179 Log('talk', $call, $field[1], $field[6], $text);
180 $call = $main::myalias if $call eq $main::mycall;
181 my $ref = DXChannel->get($call);
182 $ref->send("$call de $field[1]: $text") if $ref && $ref->{talk};
184 route($field[2], $line); # relay it on its way
189 if ($pcno == 11 || $pcno == 26) { # dx spot
191 # route 'foreign' pc26s
193 if ($field[7] ne $main::mycall) {
194 route($field[7], $line);
199 # if this is a 'nodx' node then ignore it
200 if (grep $field[7] =~ /^$_/, @DXProt::nodx_node) {
201 dbg('chan', "Bad DXNode, dropped");
205 # convert the date to a unix date
206 my $d = cltounix($field[3], $field[4]);
207 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
208 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
209 dbg('chan', "Spot ignored, invalid date or out of range ($field[3] $field[4])\n");
213 # strip off the leading & trailing spaces from the comment
214 my $text = unpad($field[5]);
217 my $spotter = $field[6];
218 $spotter =~ s/-[\@\d]+$//o; # strip off the ssid from the spotter
221 my $freq = $field[1] - 0;
222 my $dupkey = "$freq$field[2]$d$text$spotter";
223 if ($spotdup{$dupkey}) {
224 dbg('chan', "Duplicate Spot ignored\n");
228 $spotdup{$dupkey} = $d;
231 if (grep $field[2] eq $_, @baddx) {
232 dbg('chan', "Bad DX spot, ignored");
236 # are any of the crucial fields invalid?
237 if ($field[2] =~ /[a-z]/ || $field[6] =~ /[a-z]/ || $field[7] =~ /[a-z]/) {
238 dbg('chan', "Spot contains lower case callsigns, rejected");
242 my @spot = Spot::add($freq, $field[2], $d, $text, $spotter, $field[7]);
245 # @spot at this point contains:-
246 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
247 # then spotted itu, spotted cq, spotters itu, spotters cq
248 # you should be able to route on any of these
254 $r = Local::spot($self, @spot);
256 # dbg('local', "Local::spot1 error $@") if $@;
259 # DON'T be silly and send on PC26s!
260 return if $pcno == 26;
262 # send out the filtered spots
263 send_dx_spot($self, $line, @spot) if @spot;
267 if ($pcno == 12) { # announces
268 # announce duplicate checking
269 my $text = substr(uc unpad($field[3]), 0, $pc12_dup_lth);
270 my $dupkey = $field[1].$field[2].$text.$field[4].$field[6];
271 if ($anndup{$dupkey}) {
272 dbg('chan', "Duplicate Announce ignored\n");
275 $anndup{$dupkey} = $main::systime;
277 if ($field[2] eq '*' || $field[2] eq $main::mycall) {
279 # global ann filtering on INPUT
280 if ($self->{inannfilter}) {
281 my ($filter, $hops) = Filter::it($self->{inannfilter}, @field[1..6], $self->{call} );
283 dbg('chan', "Rejected by filter");
289 $self->send_announce($line, @field[1..6]);
291 if ($decode_dk0wcy && $field[1] eq $decode_dk0wcy) {
292 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+)/;
293 $alarm = ($alarm =~ /^Y/i) ? ', Aurora in DE' : '';
294 my $wwv = Geomag::update($main::systime, $hour, $sfi, $a, $k, "R=$r, Next K=$next$alarm", $decode_dk0wcy, $field[5], $r);
298 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 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 my $dupkey = "$d.$sfi$k$i";
514 if ($wwvdup{$dupkey}) {
515 dbg('chan', "Dup WWV Spot ignored\n");
518 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 900 || $field[2] < 0 || $field[2] > 23) {
519 dbg('chan', "WWV Date ($field[1] $field[2]) out of range");
522 $wwvdup{$dupkey} = $d;
523 $field[6] =~ s/-\d+$//o; # remove spotter's ssid
525 my $wwv = Geomag::update($d, $field[2], $sfi, $k, $i, @field[6..8], $r);
529 $rep = Local::wwv($self, $field[1], $field[2], $sfi, $k, $i, @field[6..8], $r);
531 # dbg('local', "Local::wwv2 error $@") if $@;
534 # DON'T be silly and send on PC27s!
535 return if $pcno == 27;
537 # broadcast to the eager world
538 send_wwv_spot($self, $line, $d, $field[2], $sfi, $k, $i, @field[6..8]);
542 if ($pcno == 24) { # set here status
543 my $call = uc $field[1];
544 my $ref = DXCluster->get_exact($call);
545 $ref->here($field[2]) if $ref;
549 if ($pcno == 25) { # merge request
550 if ($field[1] ne $main::mycall) {
551 route($field[1], $line);
554 if ($field[2] eq $main::mycall) {
555 dbg('chan', "Trying to merge to myself, ignored");
559 Log('DXProt', "Merge request for $field[3] spots and $field[4] WWV from $field[1]");
563 my @in = reverse Spot::search(1, undef, undef, 0, $field[3]);
566 $self->send(pc26(@{$in}[0..4], $field[2]));
572 my @in = reverse Geomag::search(0, $field[4], time, 1);
575 $self->send(pc27(@{$in}[0..5], $field[2]));
581 if (($pcno >= 28 && $pcno <= 33) || $pcno == 40 || $pcno == 42 || $pcno == 49) { # mail/file handling
582 if ($pcno == 49 || $field[1] eq $main::mycall) {
583 DXMsg::process($self, $line);
585 route($field[1], $line);
590 if ($pcno == 34 || $pcno == 36) { # remote commands (incoming)
591 if ($field[1] eq $main::mycall) {
592 my $ref = DXUser->get_current($field[2]);
593 my $cref = DXCluster->get($field[2]);
594 Log('rcmd', 'in', $ref->{priv}, $field[2], $field[3]);
595 unless ($field[3] =~ /rcmd/i || !$cref || !$ref || $cref->mynode->call ne $ref->homenode) { # not allowed to relay RCMDS!
596 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
597 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
598 my $oldpriv = $self->{priv};
599 $self->{priv} = $ref->{priv}; # assume the user's privilege level
600 my @in = (DXCommandmode::run_cmd($self, $field[3]));
601 $self->{priv} = $oldpriv;
604 $self->send(pc35($main::mycall, $field[2], "$main::mycall:$_"));
605 Log('rcmd', 'out', $field[2], $_);
607 delete $self->{remotecmd};
609 $self->send(pc35($main::mycall, $field[2], "$main::mycall:sorry...!"));
612 $self->send(pc35($main::mycall, $field[2], "$main::mycall:your attempt is logged, Tut tut tut...!"));
615 route($field[1], $line);
620 if ($pcno == 35) { # remote command replies
621 if ($field[1] eq $main::mycall) {
622 my $s = $rcmds{$field[2]};
624 my $dxchan = DXChannel->get($s->{call});
625 $dxchan->send($field[3]) if $dxchan;
626 delete $rcmds{$field[2]} if !$dxchan;
629 route($field[1], $line);
634 # for pc 37 see 44 onwards
636 if ($pcno == 38) { # node connected list from neighbour
640 if ($pcno == 39) { # incoming disconnect
645 if ($pcno == 41) { # user info
646 # add this station to the user database, if required
647 my $user = DXUser->get_current($field[1]);
649 # then try without an SSID
650 $field[1] =~ s/-\d+$//o;
651 $user = DXUser->get_current($field[1]);
653 $user = DXUser->new($field[1]) if !$user;
655 if ($field[2] == 1) {
656 $user->name($field[3]);
657 } elsif ($field[2] == 2) {
658 $user->qth($field[3]);
659 } elsif ($field[2] == 3) {
660 my ($lat, $long) = DXBearing::stoll($field[3]);
663 } elsif ($field[2] == 4) {
664 $user->homenode($field[3]);
672 if ($pcno == 37 || $pcno == 44 || $pcno == 45 || $pcno == 46 || $pcno == 47) {
673 if ($field[1] eq $main::mycall) {
676 route($field[1], $line);
681 if ($pcno == 50) { # keep alive/user list
682 my $node = DXCluster->get_exact($field[1]);
684 return unless $node->isa('DXNode');
685 return unless $node->dxchan == $self;
686 $node->update_users($field[2]);
691 if ($pcno == 51) { # incoming ping requests/answers
694 if ($field[1] eq $main::mycall) {
695 my $flag = $field[3];
697 $self->send(pc51($field[2], $field[1], '0'));
699 # it's a reply, look in the ping list for this one
700 my $ref = $pings{$field[2]};
703 my $dxchan = DXChannel->get($r->{call});
704 $dxchan->send($dxchan->msg('pingi', $field[2], atime($main::systime), $main::systime - $r->{t})) if $dxchan;
709 # route down an appropriate thingy
710 route($field[1], $line);
716 # if get here then rebroadcast the thing with its Hop count decremented (if
717 # there is one). If it has a hop count and it decrements to zero then don't
720 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
724 if (!$self->{isolate}) {
725 broadcast_ak1a($line, $self); # send it to everyone but me
730 # This is called from inside the main cluster processing loop and is used
731 # for despatching commands that are doing some long processing job
736 my @dxchan = DXChannel->get_all();
739 foreach $dxchan (@dxchan) {
740 next unless $dxchan->is_ak1a();
741 next if $dxchan == $me;
743 # send a pc50 out on this channel
744 if ($t >= $dxchan->pc50_t + $DXProt::pc50_interval) {
745 $dxchan->send(pc50());
753 if ($main::systime - 3600 > $last_hour) {
754 $cutoff = $main::systime - $pc11_dup_age;
755 while (($key, $val) = each %spotdup) {
756 delete $spotdup{$key} if $val < $cutoff;
758 $cutoff = $main::systime - $pc23_dup_age;
759 while (($key, $val) = each %wwvdup) {
760 delete $wwvdup{$key} if $val < $cutoff;
762 $cutoff = $main::systime - $pc12_dup_age;
763 while (($key, $val) = each %anndup) {
764 delete $anndup{$key} if $val < $cutoff;
766 $last_hour = $main::systime;
771 # finish up a pc context
776 my $call = $self->call;
777 my $ref = DXCluster->get_exact($call);
779 # unbusy and stop and outgoing mail
780 my $mref = DXMsg::get_busy($call);
781 $mref->stop_msg($call) if $mref;
783 # broadcast to all other nodes that all the nodes connected to via me are gone
784 my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
787 foreach $node (@gonenodes) {
788 next if $node->call eq $call;
789 broadcast_ak1a(pc21($node->call, 'Gone') , $self) unless $self->{isolate};
793 # remove outstanding pings
794 delete $pings{$call};
796 # now broadcast to all other ak1a nodes that I have gone
797 broadcast_ak1a(pc21($call, 'Gone.'), $self) unless $self->{isolate};
799 Log('DXProt', $call . " Disconnected");
804 # some active measures
810 my @dxchan = DXChannel->get_all();
813 # send it if it isn't the except list and isn't isolated and still has a hop count
814 # taking into account filtering and so on
815 foreach $dxchan (@dxchan) {
819 if ($dxchan->{spotfilter}) {
820 ($filter, $hops) = Filter::it($dxchan->{spotfilter}, @_, $self->{call} );
824 if ($dxchan->is_ak1a) {
825 next if $dxchan == $self;
828 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
830 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
831 next unless $routeit;
834 $dxchan->send($routeit) if $routeit;
836 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
838 } elsif ($dxchan->is_user && $dxchan->{dx}) {
839 my $buf = Spot::formatb($_[0], $_[1], $_[2], $_[3], $_[4]);
840 $buf .= "\a\a" if $dxchan->{beep};
841 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
844 $dxchan->delay($buf);
854 my @dxchan = DXChannel->get_all();
857 # send it if it isn't the except list and isn't isolated and still has a hop count
858 # taking into account filtering and so on
859 foreach $dxchan (@dxchan) {
863 if ($dxchan->{spotfilter}) {
864 ($filter, $hops) = Filter::it($dxchan->{wwvfilter}, @_, $self->{call} );
867 if ($dxchan->is_ak1a) {
868 next if $dxchan == $self;
871 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
873 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
874 next unless $routeit;
877 $dxchan->send($routeit) if $routeit;
879 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
882 } elsif ($dxchan->is_user && $dxchan->{wwv}) {
883 my $buf = "WWV de $_[6] <$_[1]>: SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
884 $buf .= "\a\a" if $dxchan->{beep};
885 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
888 $dxchan->delay($buf);
899 my @dxchan = DXChannel->get_all();
901 my $text = unpad($_[2]);
905 if ($_[3] eq '*') { # sysops
907 } elsif ($_[3] gt ' ') { # speciality list handling
908 my ($name) = split /\./, $_[3];
909 $target = "$name"; # put the rest in later (if bothered)
916 $target = "All" if !$target;
918 Log('ann', $target, $_[0], $text);
920 # send it if it isn't the except list and isn't isolated and still has a hop count
921 # taking into account filtering and so on
922 foreach $dxchan (@dxchan) {
926 if ($dxchan->{annfilter}) {
927 ($filter, $hops) = Filter::it($dxchan->{annfilter}, @_, $self->{call} );
930 if ($dxchan->is_ak1a && $_[1] ne $main::mycall) { # i.e not specifically routed to me
931 next if $dxchan == $self;
934 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
936 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
937 next unless $routeit;
940 $dxchan->send($routeit) if $routeit;
942 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
945 } elsif ($dxchan->is_user && $dxchan->{ann}) {
946 next if $target eq 'SYSOP' && $dxchan->{priv} < 5;
947 my $buf = "$to$target de $_[0]: $text";
948 $buf .= "\a\a" if $dxchan->{beep};
949 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
952 $dxchan->delay($buf);
958 sub send_local_config
967 if ($self->{isolate}) {
968 @localnodes = (DXCluster->get_exact($main::mycall));
970 # create a list of all the nodes that are not connected to this connection
971 # and are not themselves isolated, this to make sure that isolated nodes
972 # don't appear outside of this node
973 @nodes = DXNode::get_all();
974 @nodes = grep { $_->{call} ne $main::mycall } @nodes;
975 @nodes = grep { $_->dxchan != $self } @nodes if @nodes;
976 @nodes = grep { !$_->dxchan->{isolate} } @nodes if @nodes;
977 @localnodes = grep { $_->dxchan->{call} eq $_->{call} } @nodes if @nodes;
978 unshift @localnodes, DXCluster->get_exact($main::mycall);
979 @remotenodes = grep { $_->dxchan->{call} ne $_->{call} } @nodes if @nodes;
982 my @s = $me->pc19(@localnodes, @remotenodes);
984 my $routeit = adjust_hops($self, $_);
985 $self->send($routeit) if $routeit;
988 # get all the users connected on the above nodes and send them out
989 foreach $n (@localnodes, @remotenodes) {
990 my @users = values %{$n->list};
991 my @s = pc16($n, @users);
993 my $routeit = adjust_hops($self, $_);
994 $self->send($routeit) if $routeit;
1000 # route a message down an appropriate interface for a callsign
1002 # is called route(to, pcline);
1006 my ($call, $line) = @_;
1007 my $cl = DXCluster->get_exact($call);
1010 my $dxchan = $cl->{dxchan};
1012 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1014 $dxchan->send($routeit) if $dxchan;
1020 # broadcast a message to all clusters taking into account isolation
1021 # [except those mentioned after buffer]
1024 my $s = shift; # the line to be rebroadcast
1025 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1026 my @dxchan = get_all_ak1a();
1029 # send it if it isn't the except list and isn't isolated and still has a hop count
1030 foreach $dxchan (@dxchan) {
1031 next if grep $dxchan == $_, @except;
1032 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1033 $dxchan->send($routeit) unless $dxchan->{isolate} || !$routeit;
1037 # broadcast a message to all clusters ignoring isolation
1038 # [except those mentioned after buffer]
1039 sub broadcast_all_ak1a
1041 my $s = shift; # the line to be rebroadcast
1042 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1043 my @dxchan = get_all_ak1a();
1046 # send it if it isn't the except list and isn't isolated and still has a hop count
1047 foreach $dxchan (@dxchan) {
1048 next if grep $dxchan == $_, @except;
1049 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1050 $dxchan->send($routeit);
1054 # broadcast to all users
1055 # storing the spot or whatever until it is in a state to receive it
1058 my $s = shift; # the line to be rebroadcast
1059 my $sort = shift; # the type of transmission
1060 my $fref = shift; # a reference to an object to filter on
1061 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1062 my @dxchan = get_all_users();
1066 foreach $dxchan (@dxchan) {
1067 next if grep $dxchan == $_, @except;
1070 broadcast_list($s, $sort, $fref, @out);
1073 # broadcast to a list of users
1081 foreach $dxchan (@_) {
1084 if ($sort eq 'dx') {
1085 next unless $dxchan->{dx};
1086 ($filter) = Filter::it($dxchan->{spotfilter}, @{$fref}) if ref $fref;
1087 next unless $filter;
1089 next if $sort eq 'ann' && !$dxchan->{ann};
1090 next if $sort eq 'wwv' && !$dxchan->{wwv};
1091 next if $sort eq 'wx' && !$dxchan->{wx};
1093 $s =~ s/\a//og unless $dxchan->{beep};
1095 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1104 # gimme all the ak1a nodes
1108 my @list = DXChannel->get_all();
1111 foreach $ref (@list) {
1112 push @out, $ref if $ref->is_ak1a;
1117 # return a list of all users
1120 my @list = DXChannel->get_all();
1123 foreach $ref (@list) {
1124 push @out, $ref if $ref->is_user;
1129 # return a list of all user callsigns
1130 sub get_all_user_calls
1132 my @list = DXChannel->get_all();
1135 foreach $ref (@list) {
1136 push @out, $ref->call if $ref->is_user;
1142 # obtain the hops from the list for this callsign and pc no
1148 my $hops = $DXProt::hopcount{$pcno};
1149 $hops = $DXProt::def_hopcount if !$hops;
1154 # adjust the hop count on a per node basis using the user loadable
1155 # hop table if available or else decrement an existing one
1162 my $call = $self->{call};
1165 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
1166 my ($pcno) = $s =~ /^PC(\d\d)/o;
1167 confess "$call called adjust_hops with '$s'" unless $pcno;
1168 my $ref = $nodehops{$call} if %nodehops;
1170 my $newhops = $ref->{$pcno};
1171 return "" if defined $newhops && $newhops == 0;
1172 $newhops = $ref->{default} unless $newhops;
1173 return "" if defined $newhops && $newhops == 0;
1174 $newhops = $hops if !$newhops;
1175 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1177 # simply decrement it
1179 return "" if !$hops;
1180 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
1192 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
1193 do "$main::data/hop_table.pl";
1198 # remove leading and trailing spaces from an input string
1202 $s =~ s/^\s+|\s+$//;
1206 # add a ping request to the ping queues
1209 my ($from, $to) = @_;
1210 my $ref = $pings{$to};
1211 $ref = $pings{$to} = [] if !$ref;
1214 $r->{t} = $main::systime;
1215 route($to, pc51($to, $main::mycall, 1));
1219 # add a rcmd request to the rcmd queues
1222 my ($from, $to, $cmd) = @_;
1225 $r->{t} = $main::systime;
1227 route($to, pc34($main::mycall, $to, $cmd));