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 $decode_dk0wcy = undef; # if set use this callsign to decode announces from the EU WWV data beacon
41 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
42 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
44 $last_hour = time; # last time I did an hourly periodic update
45 %pings = (); # outstanding ping requests outbound
46 %rcmds = (); # outstanding rcmd requests outbound
47 %nodehops = (); # node specific hop control
48 @baddx = (); # list of illegal spotted callsigns
51 $baddxfn = "$main::data/baddx.pl";
55 my $user = DXUser->get($main::mycall);
56 $DXProt::myprot_version += $main::version*100;
57 $me = DXProt->new($main::mycall, 0, $user);
59 $me->{state} = "indifferent";
60 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
62 # $me->{sort} = 'M'; # M for me
64 # now prime the spot and wwv duplicates file with data
65 my @today = Julian::unixtoj(time);
66 for (Spot::readfile(@today), Spot::readfile(Julian::sub(@today, 1))) {
67 Spot::dup(@{$_}[0..3]);
69 for (Geomag::readfile(time)) {
70 Geomag::dup(@{$_}[1..5]);
74 do "$baddxfn" if -e "$baddxfn";
79 # obtain a new connection this is derived from dxchannel
84 my $self = DXChannel::alloc(@_);
88 # this is how a pc connection starts (for an incoming connection)
89 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
90 # all the crap that comes between).
93 my ($self, $line, $sort) = @_;
94 my $call = $self->{call};
95 my $user = $self->{user};
97 # remember type of connection
98 $self->{consort} = $line;
99 $self->{outbound} = $sort eq 'O';
100 $self->{priv} = $user->priv;
101 $self->{lang} = $user->lang;
102 $self->{isolate} = $user->{isolate};
103 $self->{consort} = $line; # save the connection type
106 # get the INPUT filters (these only pertain to Clusters)
107 $self->{inspotfilter} = Filter::read_in('spots', $call, 1);
108 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1);
109 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1);
110 $self->{inannfilter} = Filter::read_in('ann', $call, 1);
112 # set unbuffered and no echo
113 $self->send_now('B',"0");
114 $self->send_now('E',"0");
116 # ping neighbour node stuff
117 my $ping = $user->pingint;
118 $ping = 5*60 unless defined $ping;
119 $self->{pingint} = $ping;
120 $self->{nopings} = $user->nopings || 2;
121 $self->{pingtime} = [ ];
122 $self->{pingave} = 0;
124 # send initialisation string
125 unless ($self->{outbound}) {
126 $self->send(pc38()) if DXNode->get_all();
128 $self->{lastping} = $main::systime;
130 # remove from outstanding connects queue
131 @main::outstanding_connects = grep {$_->{call} ne $call} @main::outstanding_connects;
132 $self->{lastping} = $main::systime + $self->pingint / 2;
134 $self->state('init');
137 # send info to all logged in thingies
138 $self->tell_login('loginn');
140 Log('DXProt', "$call connected");
144 # This is the normal pcxx despatcher
148 my ($self, $line) = @_;
149 my @field = split /\^/, $line;
150 pop @field if $field[-1] eq '~';
152 # print join(',', @field), "\n";
154 # ignore any lines that don't start with PC
155 return if !$field[0] =~ /^PC/;
158 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
160 return if $pcno < 10 || $pcno > 99;
162 # dump bad protocol messages unless it is a PC29
163 if ($line =~ /\%[0-9A-F][0-9A-F]/o && $pcno != 29) {
164 dbg('chan', "CORRUPT protocol message - dumped");
171 $pcr = Local::pcprot($self, $pcno, @field);
173 # dbg('local', "Local::pcprot error $@") if $@;
177 if ($pcno == 10) { # incoming talk
179 # is it for me or one of mine?
180 my $call = ($field[5] gt ' ') ? $field[5] : $field[2];
181 if ($call eq $main::mycall || grep $_ eq $call, DXChannel::get_all_user_calls()) {
184 my $text = unpad($field[3]);
185 Log('talk', $call, $field[1], $field[6], $text);
186 $call = $main::myalias if $call eq $main::mycall;
187 my $ref = DXChannel->get($call);
188 $ref->send("$call de $field[1]: $text") if $ref && $ref->{talk};
190 $self->route($field[2], $line); # relay it on its way
195 if ($pcno == 11 || $pcno == 26) { # dx spot
197 # route 'foreign' pc26s
199 if ($field[7] ne $main::mycall) {
200 $self->route($field[7], $line);
205 # if this is a 'nodx' node then ignore it
206 if (grep $field[7] =~ /^$_/, @DXProt::nodx_node) {
207 dbg('chan', "Bad DXNode, dropped");
211 # convert the date to a unix date
212 my $d = cltounix($field[3], $field[4]);
213 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
214 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
215 dbg('chan', "Spot ignored, invalid date or out of range ($field[3] $field[4])\n");
220 if (grep $field[2] eq $_, @baddx) {
221 dbg('chan', "Bad DX spot, ignored");
225 # are any of the crucial fields invalid?
226 if ($field[2] =~ /[a-z]/ || $field[6] =~ /[a-z]/ || $field[7] =~ /[a-z]/) {
227 dbg('chan', "Spot contains lower case callsigns, rejected");
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 if (AnnTalk::dup($field[1], $field[2], $field[3])) {
265 dbg('chan', "Duplicate Announce ignored\n");
269 if ($field[2] eq '*' || $field[2] eq $main::mycall) {
271 # global ann filtering on INPUT
272 if ($self->{inannfilter}) {
273 my ($filter, $hops) = Filter::it($self->{inannfilter}, @field[1..6], $self->{call} );
275 dbg('chan', "Rejected by filter");
281 $self->send_announce($line, @field[1..6]);
283 if ($decode_dk0wcy && $field[1] eq $decode_dk0wcy) {
284 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+)/;
285 $alarm = ($alarm =~ /^Y/i) ? ', Aurora in DE' : '';
286 my $wwv = Geomag::update($main::systime, $hour, $sfi, $a, $k, "R=$r, Next K=$next$alarm", $decode_dk0wcy, $field[5], $r) if $sfi && $r;
290 $self->route($field[2], $line);
306 if ($pcno == 16) { # add a user
307 my $node = DXCluster->get_exact($field[1]);
309 if (!$node && ($dxchan = DXChannel->get($field[1]))) {
310 # add it to the node table if it isn't present and it's
312 $node = DXNode->new($dxchan, $field[1], 0, 1, 5400);
313 broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
316 return unless $node; # ignore if havn't seen a PC19 for this one yet
317 return unless $node->isa('DXNode');
318 if ($node->dxchan != $self) {
319 dbg('chan', "LOOP: $field[1] came in on wrong channel");
322 if (($dxchan = DXChannel->get($field[1])) && $dxchan != $self) {
323 dbg('chan', "LOOP: $field[1] connected locally");
328 for ($i = 2; $i < $#field; $i++) {
329 my ($call, $confmode, $here) = $field[$i] =~ /^(\S+) (\S) (\d)/o;
330 next if !$call || length $call < 3 || length $call > 8;
333 next if DXCluster->get_exact($call); # we already have this (loop?)
335 $confmode = $confmode eq '*';
336 DXNodeuser->new($self, $node, $call, $confmode, $here);
338 # add this station to the user database, if required
339 $call =~ s/-\d+$//o; # remove ssid for users
340 my $user = DXUser->get_current($call);
341 $user = DXUser->new($call) if !$user;
342 $user->homenode($node->call) if !$user->homenode;
343 $user->node($node->call);
344 $user->lastin($main::systime) unless DXChannel->get($call);
348 # queue up any messages (look for privates only)
349 DXMsg::queue_msg(1) if $self->state eq 'normal';
353 if ($pcno == 17) { # remove a user
354 my $node = DXCluster->get_exact($field[2]);
356 if (!$node && ($dxchan = DXChannel->get($field[2]))) {
357 # add it to the node table if it isn't present and it's
359 $node = DXNode->new($dxchan, $field[2], 0, 1, 5400);
360 broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
364 return unless $node->isa('DXNode');
365 if ($node->dxchan != $self) {
366 dbg('chan', "LOOP: $field[2] came in on wrong channel");
369 if (($dxchan = DXChannel->get($field[2])) && $dxchan != $self) {
370 dbg('chan', "LOOP: $field[2] connected locally");
373 my $ref = DXCluster->get_exact($field[1]);
378 if ($pcno == 18) { # link request
379 $self->state('init');
381 # first clear out any nodes on this dxchannel
382 my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
383 foreach my $node (@gonenodes) {
384 next if $node->dxchan == $DXProt::me;
385 broadcast_ak1a(pc21($node->call, 'Gone, re-init') , $self) unless $self->{isolate};
388 $self->send_local_config();
390 return; # we don't pass these on
393 if ($pcno == 19) { # incoming cluster list
395 my $newline = "PC19^";
396 for ($i = 1; $i < $#field-1; $i += 4) {
397 my $here = $field[$i];
398 my $call = uc $field[$i+1];
399 my $confmode = $field[$i+2];
400 my $ver = $field[$i+3];
402 $ver = 5400 if !$ver && $allowzero;
404 # now check the call over
405 my $node = DXCluster->get_exact($call);
408 if (($dxchan = DXChannel->get($call)) && $dxchan != $self) {
409 dbg('chan', "LOOP: $call connected locally");
411 if ($node->dxchan != $self) {
412 dbg('chan', "LOOP: $call come in on wrong channel");
415 dbg('chan', "already have $call");
419 # check for sane parameters
420 next if $ver < 5000; # only works with version 5 software
421 next if length $call < 3; # min 3 letter callsigns
423 # add it to the nodes table and outgoing line
424 $newline .= "$here^$call^$confmode^$ver^";
425 DXNode->new($self, $call, $confmode, $here, $ver);
427 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
428 my $mref = DXMsg::get_busy($call);
429 $mref->stop_msg($call) if $mref;
431 # add this station to the user database, if required (don't remove SSID from nodes)
432 my $user = DXUser->get_current($call);
434 $user = DXUser->new($call);
436 $user->priv(1); # I have relented and defaulted nodes
437 $self->{priv} = 1; # to user RCMDs allowed
438 $user->homenode($call);
441 $user->lastin($main::systime) unless DXChannel->get($call);
445 return if $newline eq "PC19^";
448 $newline .= get_hops(19) . "^";
453 if ($pcno == 20) { # send local configuration
454 $self->send_local_config();
456 $self->state('normal');
460 if ($pcno == 21) { # delete a cluster from the list
461 my $call = uc $field[1];
462 if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
463 my $node = DXCluster->get_exact($call);
465 if ($node->dxchan != $self) {
466 dbg('chan', "LOOP: $call come in on wrong channel");
470 if (($dxchan = DXChannel->get($call)) && $dxchan != $self) {
471 dbg('chan', "LOOP: $call connected locally");
476 dbg('chan', "$call not in table, dropped");
484 $self->state('normal');
488 if ($pcno == 23 || $pcno == 27) { # WWV info
490 # route 'foreign' pc27s
492 if ($field[8] ne $main::mycall) {
493 $self->route($field[8], $line);
499 my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
500 my $sfi = unpad($field[3]);
501 my $k = unpad($field[4]);
502 my $i = unpad($field[5]);
503 my ($r) = $field[6] =~ /R=(\d+)/;
505 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
506 dbg('chan', "WWV Date ($field[1] $field[2]) out of range");
509 if (Geomag::dup($d,$sfi,$k,$i,$field[6])) {
510 dbg('chan', "Dup WWV Spot ignored\n");
513 $field[7] =~ s/-\d+$//o; # remove spotter's ssid
515 my $wwv = Geomag::update($d, $field[2], $sfi, $k, $i, @field[6..8], $r);
519 $rep = Local::wwv($self, $field[1], $field[2], $sfi, $k, $i, @field[6..8], $r);
521 # dbg('local', "Local::wwv2 error $@") if $@;
524 # DON'T be silly and send on PC27s!
525 return if $pcno == 27;
527 # broadcast to the eager world
528 send_wwv_spot($self, $line, $d, $field[2], $sfi, $k, $i, @field[6..8]);
532 if ($pcno == 24) { # set here status
533 my $call = uc $field[1];
534 my $ref = DXCluster->get_exact($call);
535 $ref->here($field[2]) if $ref;
539 if ($pcno == 25) { # merge request
540 if ($field[1] ne $main::mycall) {
541 $self->route($field[1], $line);
544 if ($field[2] eq $main::mycall) {
545 dbg('chan', "Trying to merge to myself, ignored");
549 Log('DXProt', "Merge request for $field[3] spots and $field[4] WWV from $field[1]");
553 my @in = reverse Spot::search(1, undef, undef, 0, $field[3]);
556 $self->send(pc26(@{$in}[0..4], $field[2]));
562 my @in = reverse Geomag::search(0, $field[4], time, 1);
565 $self->send(pc27(@{$in}[0..5], $field[2]));
571 if (($pcno >= 28 && $pcno <= 33) || $pcno == 40 || $pcno == 42 || $pcno == 49) { # mail/file handling
572 if ($pcno == 49 || $field[1] eq $main::mycall) {
573 DXMsg::process($self, $line);
575 $self->route($field[1], $line);
580 if ($pcno == 34 || $pcno == 36) { # remote commands (incoming)
581 if ($field[1] eq $main::mycall) {
582 my $ref = DXUser->get_current($field[2]);
583 my $cref = DXCluster->get($field[2]);
584 Log('rcmd', 'in', $ref->{priv}, $field[2], $field[3]);
585 unless ($field[3] =~ /rcmd/i || !$cref || !$ref || $cref->mynode->call ne $ref->homenode) { # not allowed to relay RCMDS!
586 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
587 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
588 my $oldpriv = $self->{priv};
589 $self->{priv} = $ref->{priv}; # assume the user's privilege level
590 my @in = (DXCommandmode::run_cmd($self, $field[3]));
591 $self->{priv} = $oldpriv;
594 $self->send(pc35($main::mycall, $field[2], "$main::mycall:$_"));
595 Log('rcmd', 'out', $field[2], $_);
597 delete $self->{remotecmd};
599 $self->send(pc35($main::mycall, $field[2], "$main::mycall:sorry...!"));
602 $self->send(pc35($main::mycall, $field[2], "$main::mycall:your attempt is logged, Tut tut tut...!"));
605 my $ref = DXUser->get_current($field[1]);
606 if ($ref && $ref->is_clx) {
607 route($field[1], pc84($field[2], $field[1], $field[2], $field[3]));
609 $self->route($field[1], $line);
615 if ($pcno == 35) { # remote command replies
616 if ($field[1] eq $main::mycall) {
617 my $s = $rcmds{$field[2]};
619 my $dxchan = DXChannel->get($s->{call});
620 $dxchan->send($field[3]) if $dxchan;
621 delete $rcmds{$field[2]} if !$dxchan;
624 my $ref = DXUser->get_current($field[1]);
625 if ($ref && $ref->is_clx) {
626 route($field[1], pc85($field[2], $field[1], $field[2], $field[3]));
628 $self->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
641 $self->disconnect(1);
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 || $pcno == 48) {
673 DXDb::process($self, $line);
677 if ($pcno == 50) { # keep alive/user list
678 my $node = DXCluster->get_exact($field[1]);
680 return unless $node->isa('DXNode');
681 return unless $node->dxchan == $self;
682 $node->update_users($field[2]);
687 if ($pcno == 51) { # incoming ping requests/answers
690 if ($field[1] eq $main::mycall) {
691 my $flag = $field[3];
693 $self->send(pc51($field[2], $field[1], '0'));
695 # it's a reply, look in the ping list for this one
696 my $ref = $pings{$field[2]};
698 my $tochan = DXChannel->get($field[2]);
701 my $dxchan = DXChannel->get($r->{call});
703 my $t = tv_interval($r->{t}, [ gettimeofday ]);
704 if ($dxchan->is_user) {
705 my $s = sprintf "%.2f", $t;
706 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
707 $dxchan->send($dxchan->msg('pingi', $field[2], $s, $ave))
708 } elsif ($dxchan->is_node) {
710 $tochan->{nopings} = 2; # pump up the timer
711 push @{$tochan->{pingtime}}, $t;
712 shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
714 for (@{$tochan->{pingtime}}) {
717 $tochan->{pingave} = $st / @{$tochan->{pingtime}};
724 # route down an appropriate thingy
725 $self->route($field[1], $line);
730 if ($pcno == 73) { # WCY broadcasts
733 my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
734 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
735 dbg('chan', "WCY Date ($field[1] $field[2]) out of range");
738 @field = map { unpad($_) } @field;
739 if (WCY::dup($d,@field[3..7])) {
740 dbg('chan', "Dup WCY Spot ignored\n");
744 my $wcy = WCY::update($d, @field[2..12]);
748 $rep = Local::wwv($self, @field[1..12]);
750 # dbg('local', "Local::wcy error $@") if $@;
753 # broadcast to the eager world
754 send_wcy_spot($self, $line, $d, @field[2..12]);
758 if ($pcno == 84) { # remote commands (incoming)
759 if ($field[1] eq $main::mycall) {
760 my $ref = DXUser->get_current($field[2]);
761 my $cref = DXCluster->get($field[2]);
762 Log('rcmd', 'in', $ref->{priv}, $field[2], $field[4]);
763 unless ($field[3] =~ /rcmd/i || !$cref || !$ref || $cref->mynode->call ne $ref->homenode) { # not allowed to relay RCMDS!
764 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
765 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
766 my $oldpriv = $self->{priv};
767 $self->{priv} = $ref->{priv}; # assume the user's privilege level
768 my @in = (DXCommandmode::run_cmd($self, $field[4]));
769 $self->{priv} = $oldpriv;
772 $self->send(pc85($main::mycall, $field[2], $field[3], "$main::mycall:$_"));
773 Log('rcmd', 'out', $field[2], $_);
775 delete $self->{remotecmd};
777 $self->send(pc85($main::mycall, $field[2], $field[3], "$main::mycall:sorry...!"));
780 $self->send(pc85($main::mycall, $field[2], $field[3],"$main::mycall:your attempt is logged, Tut tut tut...!"));
783 my $ref = DXUser->get_current($field[1]);
784 if ($ref && $ref->is_clx) {
785 $self->route($field[1], $line);
787 route($field[1], pc34($field[2], $field[1], $field[3]));
793 if ($pcno == 85) { # remote command replies
794 if ($field[1] eq $main::mycall) {
795 my $dxchan = DXChannel->get($field[3]);
797 $dxchan->send($field[4]);
799 my $s = $rcmds{$field[2]};
801 $dxchan = DXChannel->get($s->{call});
802 $dxchan->send($field[4]) if $dxchan;
803 delete $rcmds{$field[2]} if !$dxchan;
807 my $ref = DXUser->get_current($field[1]);
808 if ($ref && $ref->is_clx) {
809 $self->route($field[1], $line);
811 route($field[1], pc35($field[2], $field[1], $field[3]));
818 # if get here then rebroadcast the thing with its Hop count decremented (if
819 # there is one). If it has a hop count and it decrements to zero then don't
822 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
826 unless ($self->{isolate}) {
827 broadcast_ak1a($line, $self); # send it to everyone but me
832 # This is called from inside the main cluster processing loop and is used
833 # for despatching commands that are doing some long processing job
838 my @dxchan = DXChannel->get_all();
841 foreach $dxchan (@dxchan) {
842 next unless $dxchan->is_node();
843 next if $dxchan == $me;
845 # send a pc50 out on this channel
846 if ($t >= $dxchan->pc50_t + $DXProt::pc50_interval) {
847 $dxchan->send(pc50(scalar DXChannel::get_all_users));
851 # send a ping out on this channel
852 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
853 if ($dxchan->{nopings} <= 0) {
856 addping($main::mycall, $dxchan->call);
857 $dxchan->{nopings} -= 1;
858 $dxchan->{lastping} = $t;
866 if ($main::systime - 3600 > $last_hour) {
870 $last_hour = $main::systime;
875 # finish up a pc context
880 my $call = $self->call;
882 my $ref = DXCluster->get_exact($call);
884 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op"))) unless $nopc39;
886 # unbusy and stop and outgoing mail
887 my $mref = DXMsg::get_busy($call);
888 $mref->stop_msg($call) if $mref;
890 # broadcast to all other nodes that all the nodes connected to via me are gone
891 my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
894 foreach $node (@gonenodes) {
895 next if $node->call eq $call;
896 broadcast_ak1a(pc21($node->call, 'Gone') , $self) unless $self->{isolate};
900 # remove outstanding pings
901 delete $pings{$call};
903 # now broadcast to all other ak1a nodes that I have gone
904 broadcast_ak1a(pc21($call, 'Gone.'), $self) unless $self->{isolate};
906 # I was the last node visited
907 $self->user->node($main::mycall);
909 # send info to all logged in thingies
910 $self->tell_login('logoutn');
912 Log('DXProt', $call . " Disconnected");
917 # some active measures
923 my @dxchan = DXChannel->get_all();
926 # send it if it isn't the except list and isn't isolated and still has a hop count
927 # taking into account filtering and so on
928 foreach $dxchan (@dxchan) {
932 if ($dxchan->{spotfilter}) {
933 ($filter, $hops) = Filter::it($dxchan->{spotfilter}, @_, $self->{call} );
937 if ($dxchan->is_node) {
938 next if $dxchan == $self;
941 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
943 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
944 next unless $routeit;
947 $dxchan->send($routeit) if $routeit;
949 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
951 } elsif ($dxchan->is_user && $dxchan->{dx}) {
952 my $buf = Spot::formatb($_[0], $_[1], $_[2], $_[3], $_[4]);
953 $buf .= "\a\a" if $dxchan->{beep};
954 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
957 $dxchan->delay($buf);
967 my @dxchan = DXChannel->get_all();
970 # send it if it isn't the except list and isn't isolated and still has a hop count
971 # taking into account filtering and so on
972 foreach $dxchan (@dxchan) {
976 if ($dxchan->{wwvfilter}) {
977 ($filter, $hops) = Filter::it($dxchan->{wwvfilter}, @_, $self->{call} );
980 if ($dxchan->is_node) {
981 next if $dxchan == $self;
984 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
986 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
987 next unless $routeit;
990 $dxchan->send($routeit) if $routeit;
992 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
995 } elsif ($dxchan->is_user && $dxchan->{wwv}) {
996 my $buf = "WWV de $_[6] <$_[1]>: SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
997 $buf .= "\a\a" if $dxchan->{beep};
998 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1001 $dxchan->delay($buf);
1011 my @dxchan = DXChannel->get_all();
1014 # send it if it isn't the except list and isn't isolated and still has a hop count
1015 # taking into account filtering and so on
1016 foreach $dxchan (@dxchan) {
1018 my ($filter, $hops);
1020 if ($dxchan->{wcyfilter}) {
1021 ($filter, $hops) = Filter::it($dxchan->{wcyfilter}, @_, $self->{call} );
1022 next unless $filter;
1024 if ($dxchan->is_clx || $dxchan->is_spider) {
1025 next if $dxchan == $self;
1028 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1030 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1031 next unless $routeit;
1034 $dxchan->send($routeit) if $routeit;
1036 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1038 } elsif ($dxchan->is_user && $dxchan->{wcy}) {
1039 my $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
1040 $buf .= "\a\a" if $dxchan->{beep};
1041 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1042 $dxchan->send($buf);
1044 $dxchan->delay($buf);
1055 my @dxchan = DXChannel->get_all();
1057 my $text = unpad($_[2]);
1061 if ($_[3] eq '*') { # sysops
1063 } elsif ($_[3] gt ' ') { # speciality list handling
1064 my ($name) = split /\./, $_[3];
1065 $target = "$name"; # put the rest in later (if bothered)
1072 $target = "All" if !$target;
1074 Log('ann', $target, $_[0], $text);
1076 # send it if it isn't the except list and isn't isolated and still has a hop count
1077 # taking into account filtering and so on
1078 foreach $dxchan (@dxchan) {
1080 my ($filter, $hops);
1082 if ($dxchan->{annfilter}) {
1083 ($filter, $hops) = Filter::it($dxchan->{annfilter}, @_, $self->{call} );
1084 next unless $filter;
1086 if ($dxchan->is_node && $_[1] ne $main::mycall) { # i.e not specifically routed to me
1087 next if $dxchan == $self;
1090 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1092 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1093 next unless $routeit;
1096 $dxchan->send($routeit) if $routeit;
1098 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1101 } elsif ($dxchan->is_user && $dxchan->{ann}) {
1102 next if $target eq 'SYSOP' && $dxchan->{priv} < 5;
1103 my $buf = "$to$target de $_[0]: $text";
1104 $buf .= "\a\a" if $dxchan->{beep};
1105 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1106 $dxchan->send($buf);
1108 $dxchan->delay($buf);
1114 sub send_local_config
1123 if ($self->{isolate}) {
1124 @localnodes = (DXCluster->get_exact($main::mycall));
1126 # create a list of all the nodes that are not connected to this connection
1127 # and are not themselves isolated, this to make sure that isolated nodes
1128 # don't appear outside of this node
1129 @nodes = DXNode::get_all();
1130 @nodes = grep { $_->{call} ne $main::mycall } @nodes;
1131 @nodes = grep { $_->dxchan != $self } @nodes if @nodes;
1132 @nodes = grep { !$_->dxchan->{isolate} } @nodes if @nodes;
1133 @localnodes = grep { $_->dxchan->{call} eq $_->{call} } @nodes if @nodes;
1134 unshift @localnodes, DXCluster->get_exact($main::mycall);
1135 @remotenodes = grep { $_->dxchan->{call} ne $_->{call} } @nodes if @nodes;
1138 my @s = $me->pc19(@localnodes, @remotenodes);
1140 my $routeit = adjust_hops($self, $_);
1141 $self->send($routeit) if $routeit;
1144 # get all the users connected on the above nodes and send them out
1145 foreach $n (@localnodes, @remotenodes) {
1146 my @users = values %{$n->list};
1147 my @s = pc16($n, @users);
1149 my $routeit = adjust_hops($self, $_);
1150 $self->send($routeit) if $routeit;
1156 # route a message down an appropriate interface for a callsign
1158 # is called route(to, pcline);
1162 my ($self, $call, $line) = @_;
1163 my $cl = DXCluster->get_exact($call);
1164 if ($cl) { # don't route it back down itself
1165 if (ref $self && $call eq $self->{call}) {
1166 dbg('chan', "Trying to route back to source, dropped");
1170 my $dxchan = $cl->{dxchan};
1172 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1174 $dxchan->send($routeit) if $dxchan;
1180 # broadcast a message to all clusters taking into account isolation
1181 # [except those mentioned after buffer]
1184 my $s = shift; # the line to be rebroadcast
1185 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1186 my @dxchan = DXChannel::get_all_ak1a();
1189 # send it if it isn't the except list and isn't isolated and still has a hop count
1190 foreach $dxchan (@dxchan) {
1191 next if grep $dxchan == $_, @except;
1192 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1193 $dxchan->send($routeit) unless $dxchan->{isolate} || !$routeit;
1197 # broadcast a message to all clusters ignoring isolation
1198 # [except those mentioned after buffer]
1199 sub broadcast_all_ak1a
1201 my $s = shift; # the line to be rebroadcast
1202 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1203 my @dxchan = DXChannel::get_all_ak1a();
1206 # send it if it isn't the except list and isn't isolated and still has a hop count
1207 foreach $dxchan (@dxchan) {
1208 next if grep $dxchan == $_, @except;
1209 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1210 $dxchan->send($routeit);
1214 # broadcast to all users
1215 # storing the spot or whatever until it is in a state to receive it
1218 my $s = shift; # the line to be rebroadcast
1219 my $sort = shift; # the type of transmission
1220 my $fref = shift; # a reference to an object to filter on
1221 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1222 my @dxchan = DXChannel::get_all_users();
1226 foreach $dxchan (@dxchan) {
1227 next if grep $dxchan == $_, @except;
1230 broadcast_list($s, $sort, $fref, @out);
1233 # broadcast to a list of users
1241 foreach $dxchan (@_) {
1244 if ($sort eq 'dx') {
1245 next unless $dxchan->{dx};
1246 ($filter) = Filter::it($dxchan->{spotfilter}, @{$fref}) if ref $fref;
1247 next unless $filter;
1249 next if $sort eq 'ann' && !$dxchan->{ann};
1250 next if $sort eq 'wwv' && !$dxchan->{wwv};
1251 next if $sort eq 'wcy' && !$dxchan->{wcy};
1252 next if $sort eq 'wx' && !$dxchan->{wx};
1254 $s =~ s/\a//og unless $dxchan->{beep};
1256 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1266 # obtain the hops from the list for this callsign and pc no
1272 my $hops = $DXProt::hopcount{$pcno};
1273 $hops = $DXProt::def_hopcount if !$hops;
1278 # adjust the hop count on a per node basis using the user loadable
1279 # hop table if available or else decrement an existing one
1286 my $call = $self->{call};
1289 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
1290 my ($pcno) = $s =~ /^PC(\d\d)/o;
1291 confess "$call called adjust_hops with '$s'" unless $pcno;
1292 my $ref = $nodehops{$call} if %nodehops;
1294 my $newhops = $ref->{$pcno};
1295 return "" if defined $newhops && $newhops == 0;
1296 $newhops = $ref->{default} unless $newhops;
1297 return "" if defined $newhops && $newhops == 0;
1298 $newhops = $hops if !$newhops;
1299 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1301 # simply decrement it
1303 return "" if !$hops;
1304 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
1316 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
1317 do "$main::data/hop_table.pl";
1323 # add a ping request to the ping queues
1326 my ($from, $to) = @_;
1327 my $ref = $pings{$to} || [];
1330 $r->{t} = [ gettimeofday ];
1331 route(undef, $to, pc51($to, $main::mycall, 1));
1336 # add a rcmd request to the rcmd queues
1339 my ($self, $to, $cmd) = @_;
1342 $r->{call} = $self->{call};
1343 $r->{t} = $main::systime;
1347 my $ref = DXCluster->get_exact($to);
1348 if ($ref && $ref->dxchan && $ref->dxchan->is_clx) {
1349 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1351 route(undef, $to, pc34($main::mycall, $to, $cmd));