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 $send_opernam);
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 || 1; # other clusters can always be 'normal' users
100 $self->{lang} = $user->lang || 'en';
101 $self->{isolate} = $user->{isolate};
102 $self->{consort} = $line; # save the connection type
105 # get the INPUT filters (these only pertain to Clusters)
106 $self->{inspotfilter} = Filter::read_in('spots', $call, 1);
107 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1);
108 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1);
109 $self->{inannfilter} = Filter::read_in('ann', $call, 1);
111 # set unbuffered and no echo
112 $self->send_now('B',"0");
113 $self->send_now('E',"0");
115 # ping neighbour node stuff
116 my $ping = $user->pingint;
117 $ping = 5*60 unless defined $ping;
118 $self->{pingint} = $ping;
119 $self->{nopings} = $user->nopings || 2;
120 $self->{pingtime} = [ ];
121 $self->{pingave} = 0;
123 # send initialisation string
124 unless ($self->{outbound}) {
125 $self->send(pc38()) if DXNode->get_all();
127 $self->{lastping} = $main::systime;
129 # remove from outstanding connects queue
130 @main::outstanding_connects = grep {$_->{call} ne $call} @main::outstanding_connects;
131 $self->{lastping} = $main::systime + $self->pingint / 2;
133 $self->state('init');
136 # send info to all logged in thingies
137 $self->tell_login('loginn');
139 Log('DXProt', "$call connected");
143 # This is the normal pcxx despatcher
147 my ($self, $line) = @_;
148 my @field = split /\^/, $line;
149 pop @field if $field[-1] eq '~';
151 # print join(',', @field), "\n";
153 # ignore any lines that don't start with PC
154 return if !$field[0] =~ /^PC/;
157 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
159 return if $pcno < 10 || $pcno > 99;
161 # dump bad protocol messages unless it is a PC29
162 if ($line =~ /\%[0-9A-F][0-9A-F]/o && $pcno != 29) {
163 dbg('chan', "CORRUPT protocol message - dumped");
170 $pcr = Local::pcprot($self, $pcno, @field);
172 # dbg('local', "Local::pcprot error $@") if $@;
176 if ($pcno == 10) { # incoming talk
178 # is it for me or one of mine?
179 my $call = ($field[5] gt ' ') ? $field[5] : $field[2];
180 if ($call eq $main::mycall || grep $_ eq $call, DXChannel::get_all_user_calls()) {
183 my $text = unpad($field[3]);
184 Log('talk', $call, $field[1], $field[6], $text);
185 $call = $main::myalias if $call eq $main::mycall;
186 my $ref = DXChannel->get($call);
187 $ref->send("$call de $field[1]: $text") if $ref && $ref->{talk};
189 $self->route($field[2], $line); # relay it on its way
194 if ($pcno == 11 || $pcno == 26) { # dx spot
196 # route 'foreign' pc26s
198 if ($field[7] ne $main::mycall) {
199 $self->route($field[7], $line);
204 # if this is a 'nodx' node then ignore it
205 if (grep $field[7] =~ /^$_/, @DXProt::nodx_node) {
206 dbg('chan', "Bad DXNode, dropped");
210 # convert the date to a unix date
211 my $d = cltounix($field[3], $field[4]);
212 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
213 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
214 dbg('chan', "Spot ignored, invalid date or out of range ($field[3] $field[4])\n");
219 if (grep $field[2] eq $_, @baddx) {
220 dbg('chan', "Bad DX spot, ignored");
224 # are any of the crucial fields invalid?
225 if ($field[2] =~ /(?:^\s*$|[a-z])/ || $field[6] =~ /(?:^\s*$|[a-z])/ || $field[7] =~ /(?:^\s*$|[a-z])/) {
226 dbg('chan', "Spot contains lower case callsigns or blanks, rejected");
231 $field[5] =~ s/^\s+//; # take any leading blanks off
232 if (Spot::dup($field[1], $field[2], $d, $field[5])) {
233 dbg('chan', "Duplicate Spot ignored\n");
237 my @spot = Spot::add($field[1], $field[2], $d, $field[5], $field[6], $field[7]);
240 # @spot at this point contains:-
241 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
242 # then spotted itu, spotted cq, spotters itu, spotters cq
243 # you should be able to route on any of these
246 # fix up qra locators of known users
247 my $user = DXUser->get_current($spot[4]);
249 my $qra = $user->qra;
250 unless ($qra && DXBearing::is_qra($qra)) {
251 my $lat = $user->lat;
252 my $long = $user->long;
253 if (defined $lat && defined $long) {
254 $user->qra(DXBearing::lltoqra($lat, $long));
259 # send a remote command to a distant cluster if it is visible and there is no
260 # qra locator and we havn't done it for a month.
262 unless ($user->qra) {
264 my $to = $user->homenode;
265 my $last = $user->lastoper || 0;
266 if ($send_opernam && $main::systime > $last + $DXUser::lastoperinterval && $to && ($node = DXCluster->get_exact($to)) ) {
267 my $cmd = "forward/opernam $spot[4]";
268 # send the rcmd but we aren't interested in the replies...
269 if ($node && $node->dxchan && $node->dxchan->is_clx) {
270 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
272 route(undef, $to, pc34($main::mycall, $to, $cmd));
274 if ($to ne $field[7]) {
276 $node = DXCluster->get_exact($to);
277 if ($node && $node->dxchan && $node->dxchan->is_clx) {
278 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
280 route(undef, $to, pc34($main::mycall, $to, $cmd));
283 $user->lastoper($main::systime);
292 $r = Local::spot($self, @spot);
294 # dbg('local', "Local::spot1 error $@") if $@;
297 # DON'T be silly and send on PC26s!
298 return if $pcno == 26;
300 # send out the filtered spots
301 send_dx_spot($self, $line, @spot) if @spot;
305 if ($pcno == 12) { # announces
306 # announce duplicate checking
307 $field[3] =~ s/^\s+//; # remove leading blanks
308 if (AnnTalk::dup($field[1], $field[2], $field[3])) {
309 dbg('chan', "Duplicate Announce ignored\n");
313 if ($field[2] eq '*' || $field[2] eq $main::mycall) {
315 # global ann filtering on INPUT
316 if ($self->{inannfilter}) {
317 my ($filter, $hops) = Filter::it($self->{inannfilter}, @field[1..6], $self->{call} );
319 dbg('chan', "Rejected by filter");
325 $self->send_announce($line, @field[1..6]);
327 $self->route($field[2], $line);
343 if ($pcno == 16) { # add a user
344 my $node = DXCluster->get_exact($field[1]);
346 if (!$node && ($dxchan = DXChannel->get($field[1]))) {
347 # add it to the node table if it isn't present and it's
349 $node = DXNode->new($dxchan, $field[1], 0, 1, 5400);
350 broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
353 return unless $node; # ignore if havn't seen a PC19 for this one yet
354 return unless $node->isa('DXNode');
355 if ($node->dxchan != $self) {
356 dbg('chan', "LOOP: $field[1] came in on wrong channel");
359 if (($dxchan = DXChannel->get($field[1])) && $dxchan != $self) {
360 dbg('chan', "LOOP: $field[1] connected locally");
365 for ($i = 2; $i < $#field; $i++) {
366 my ($call, $confmode, $here) = $field[$i] =~ /^(\S+) (\S) (\d)/o;
367 next if !$call || length $call < 3 || length $call > 8;
370 next if DXCluster->get_exact($call); # we already have this (loop?)
372 $confmode = $confmode eq '*';
373 DXNodeuser->new($self, $node, $call, $confmode, $here);
375 # add this station to the user database, if required
376 $call =~ s/-\d+$//o; # remove ssid for users
377 my $user = DXUser->get_current($call);
378 $user = DXUser->new($call) if !$user;
379 $user->homenode($node->call) if !$user->homenode;
380 $user->node($node->call);
381 $user->lastin($main::systime) unless DXChannel->get($call);
385 # queue up any messages (look for privates only)
386 DXMsg::queue_msg(1) if $self->state eq 'normal';
390 if ($pcno == 17) { # remove a user
391 my $node = DXCluster->get_exact($field[2]);
393 if (!$node && ($dxchan = DXChannel->get($field[2]))) {
394 # add it to the node table if it isn't present and it's
396 $node = DXNode->new($dxchan, $field[2], 0, 1, 5400);
397 broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
401 return unless $node->isa('DXNode');
402 if ($node->dxchan != $self) {
403 dbg('chan', "LOOP: $field[2] came in on wrong channel");
406 if (($dxchan = DXChannel->get($field[2])) && $dxchan != $self) {
407 dbg('chan', "LOOP: $field[2] connected locally");
410 my $ref = DXCluster->get_exact($field[1]);
415 if ($pcno == 18) { # link request
416 $self->state('init');
418 # first clear out any nodes on this dxchannel
419 my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
420 foreach my $node (@gonenodes) {
421 next if $node->dxchan == $DXProt::me;
422 broadcast_ak1a(pc21($node->call, 'Gone, re-init') , $self) unless $self->{isolate};
425 $self->send_local_config();
427 return; # we don't pass these on
430 if ($pcno == 19) { # incoming cluster list
432 my $newline = "PC19^";
433 for ($i = 1; $i < $#field-1; $i += 4) {
434 my $here = $field[$i];
435 my $call = uc $field[$i+1];
436 my $confmode = $field[$i+2];
437 my $ver = $field[$i+3];
439 $ver = 5400 if !$ver && $allowzero;
441 # now check the call over
442 my $node = DXCluster->get_exact($call);
445 if (($dxchan = DXChannel->get($call)) && $dxchan != $self) {
446 dbg('chan', "LOOP: $call connected locally");
448 if ($node->dxchan != $self) {
449 dbg('chan', "LOOP: $call come in on wrong channel");
452 dbg('chan', "already have $call");
456 # check for sane parameters
457 next if $ver < 5000; # only works with version 5 software
458 next if length $call < 3; # min 3 letter callsigns
460 # add it to the nodes table and outgoing line
461 $newline .= "$here^$call^$confmode^$ver^";
462 DXNode->new($self, $call, $confmode, $here, $ver);
464 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
465 my $mref = DXMsg::get_busy($call);
466 $mref->stop_msg($call) if $mref;
468 # add this station to the user database, if required (don't remove SSID from nodes)
469 my $user = DXUser->get_current($call);
471 $user = DXUser->new($call);
473 $user->priv(1); # I have relented and defaulted nodes
474 $self->{priv} = 1; # to user RCMDs allowed
475 $user->homenode($call);
478 $user->lastin($main::systime) unless DXChannel->get($call);
482 return if $newline eq "PC19^";
485 $newline .= get_hops(19) . "^";
490 if ($pcno == 20) { # send local configuration
491 $self->send_local_config();
493 $self->state('normal');
497 if ($pcno == 21) { # delete a cluster from the list
498 my $call = uc $field[1];
499 if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
500 my $node = DXCluster->get_exact($call);
502 if ($node->dxchan != $self) {
503 dbg('chan', "LOOP: $call come in on wrong channel");
507 if (($dxchan = DXChannel->get($call)) && $dxchan != $self) {
508 dbg('chan', "LOOP: $call connected locally");
513 dbg('chan', "$call not in table, dropped");
521 $self->state('normal');
525 if ($pcno == 23 || $pcno == 27) { # WWV info
527 # route 'foreign' pc27s
529 if ($field[8] ne $main::mycall) {
530 $self->route($field[8], $line);
536 my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
537 my $sfi = unpad($field[3]);
538 my $k = unpad($field[4]);
539 my $i = unpad($field[5]);
540 my ($r) = $field[6] =~ /R=(\d+)/;
542 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
543 dbg('chan', "WWV Date ($field[1] $field[2]) out of range");
546 if (Geomag::dup($d,$sfi,$k,$i,$field[6])) {
547 dbg('chan', "Dup WWV Spot ignored\n");
550 $field[7] =~ s/-\d+$//o; # remove spotter's ssid
552 my $wwv = Geomag::update($d, $field[2], $sfi, $k, $i, @field[6..8], $r);
556 $rep = Local::wwv($self, $field[1], $field[2], $sfi, $k, $i, @field[6..8], $r);
558 # dbg('local', "Local::wwv2 error $@") if $@;
561 # DON'T be silly and send on PC27s!
562 return if $pcno == 27;
564 # broadcast to the eager world
565 send_wwv_spot($self, $line, $d, $field[2], $sfi, $k, $i, @field[6..8]);
569 if ($pcno == 24) { # set here status
570 my $call = uc $field[1];
571 my $ref = DXCluster->get_exact($call);
572 $ref->here($field[2]) if $ref;
576 if ($pcno == 25) { # merge request
577 if ($field[1] ne $main::mycall) {
578 $self->route($field[1], $line);
581 if ($field[2] eq $main::mycall) {
582 dbg('chan', "Trying to merge to myself, ignored");
586 Log('DXProt', "Merge request for $field[3] spots and $field[4] WWV from $field[1]");
590 my @in = reverse Spot::search(1, undef, undef, 0, $field[3]);
593 $self->send(pc26(@{$in}[0..4], $field[2]));
599 my @in = reverse Geomag::search(0, $field[4], time, 1);
602 $self->send(pc27(@{$in}[0..5], $field[2]));
608 if (($pcno >= 28 && $pcno <= 33) || $pcno == 40 || $pcno == 42 || $pcno == 49) { # mail/file handling
609 if ($pcno == 49 || $field[1] eq $main::mycall) {
610 DXMsg::process($self, $line);
612 $self->route($field[1], $line);
617 if ($pcno == 34 || $pcno == 36) { # remote commands (incoming)
618 if ($field[1] eq $main::mycall) {
619 my $ref = DXUser->get_current($field[2]);
620 my $cref = DXCluster->get($field[2]);
621 Log('rcmd', 'in', $ref->{priv}, $field[2], $field[3]);
622 unless ($field[3] =~ /rcmd/i || !$cref || !$ref || $cref->mynode->call ne $ref->homenode) { # not allowed to relay RCMDS!
623 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
624 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
625 my $oldpriv = $self->{priv};
626 $self->{priv} = $ref->{priv}; # assume the user's privilege level
627 my @in = (DXCommandmode::run_cmd($self, $field[3]));
628 $self->{priv} = $oldpriv;
631 $self->send(pc35($main::mycall, $field[2], "$main::mycall:$_"));
632 Log('rcmd', 'out', $field[2], $_);
634 delete $self->{remotecmd};
636 $self->send(pc35($main::mycall, $field[2], "$main::mycall:sorry...!"));
639 $self->send(pc35($main::mycall, $field[2], "$main::mycall:your attempt is logged, Tut tut tut...!"));
642 my $ref = DXUser->get_current($field[1]);
643 if ($ref && $ref->is_clx) {
644 route($field[1], pc84($field[2], $field[1], $field[2], $field[3]));
646 $self->route($field[1], $line);
652 if ($pcno == 35) { # remote command replies
653 if ($field[1] eq $main::mycall) {
654 my $s = $rcmds{$field[2]};
656 my $dxchan = DXChannel->get($s->{call});
657 $dxchan->send($field[3]) if $dxchan;
658 delete $rcmds{$field[2]} if !$dxchan;
661 my $ref = DXUser->get_current($field[1]);
662 if ($ref && $ref->is_clx) {
663 route($field[1], pc85($field[2], $field[1], $field[2], $field[3]));
665 $self->route($field[1], $line);
671 # for pc 37 see 44 onwards
673 if ($pcno == 38) { # node connected list from neighbour
677 if ($pcno == 39) { # incoming disconnect
678 $self->disconnect(1);
682 if ($pcno == 41) { # user info
683 # add this station to the user database, if required
684 my $user = DXUser->get_current($field[1]);
686 # then try without an SSID
687 $field[1] =~ s/-\d+$//o;
688 $user = DXUser->get_current($field[1]);
690 $user = DXUser->new($field[1]) if !$user;
692 if ($field[2] == 1) {
693 $user->name($field[3]);
694 } elsif ($field[2] == 2) {
695 $user->qth($field[3]);
696 } elsif ($field[2] == 3) {
697 my ($lat, $long) = DXBearing::stoll($field[3]);
700 my $qra = $user->qra || DXBearing::lltoqra($lat, $long);
701 $qra = DXBearing::lltoqra($lat, $long) unless $qra && DXBearing::is_qra($qra);
702 $user->qra($qra) if $qra ne $user->qra;
703 } elsif ($field[2] == 4) {
704 $user->homenode($field[3]);
706 $user->lastoper($main::systime); # to cut down on excessive for/opers being generated
713 if ($pcno == 37 || $pcno == 44 || $pcno == 45 || $pcno == 46 || $pcno == 47 || $pcno == 48) {
714 DXDb::process($self, $line);
718 if ($pcno == 50) { # keep alive/user list
719 my $node = DXCluster->get_exact($field[1]);
721 return unless $node->isa('DXNode');
722 return unless $node->dxchan == $self;
723 $node->update_users($field[2]);
728 if ($pcno == 51) { # incoming ping requests/answers
731 if ($field[1] eq $main::mycall) {
732 my $flag = $field[3];
734 $self->send(pc51($field[2], $field[1], '0'));
736 # it's a reply, look in the ping list for this one
737 my $ref = $pings{$field[2]};
739 my $tochan = DXChannel->get($field[2]);
742 my $dxchan = DXChannel->get($r->{call});
744 my $t = tv_interval($r->{t}, [ gettimeofday ]);
745 if ($dxchan->is_user) {
746 my $s = sprintf "%.2f", $t;
747 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
748 $dxchan->send($dxchan->msg('pingi', $field[2], $s, $ave))
749 } elsif ($dxchan->is_node) {
751 $tochan->{nopings} = 2; # pump up the timer
752 push @{$tochan->{pingtime}}, $t;
753 shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
755 for (@{$tochan->{pingtime}}) {
758 $tochan->{pingave} = $st / @{$tochan->{pingtime}};
765 # route down an appropriate thingy
766 $self->route($field[1], $line);
771 if ($pcno == 73) { # WCY broadcasts
774 my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
775 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
776 dbg('chan', "WCY Date ($field[1] $field[2]) out of range");
779 @field = map { unpad($_) } @field;
780 if (WCY::dup($d,@field[3..7])) {
781 dbg('chan', "Dup WCY Spot ignored\n");
785 my $wcy = WCY::update($d, @field[2..12]);
789 $rep = Local::wwv($self, @field[1..12]);
791 # dbg('local', "Local::wcy error $@") if $@;
794 # broadcast to the eager world
795 send_wcy_spot($self, $line, $d, @field[2..12]);
799 if ($pcno == 84) { # remote commands (incoming)
800 if ($field[1] eq $main::mycall) {
801 my $ref = DXUser->get_current($field[2]);
802 my $cref = DXCluster->get($field[2]);
803 Log('rcmd', 'in', $ref->{priv}, $field[2], $field[4]);
804 unless ($field[4] =~ /rcmd/i || !$cref || !$ref || $cref->mynode->call ne $ref->homenode) { # not allowed to relay RCMDS!
805 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
806 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
807 my $oldpriv = $self->{priv};
808 $self->{priv} = $ref->{priv}; # assume the user's privilege level
809 my @in = (DXCommandmode::run_cmd($self, $field[4]));
810 $self->{priv} = $oldpriv;
813 $self->send(pc85($main::mycall, $field[2], $field[3], "$main::mycall:$_"));
814 Log('rcmd', 'out', $field[2], $_);
816 delete $self->{remotecmd};
818 $self->send(pc85($main::mycall, $field[2], $field[3], "$main::mycall:sorry...!"));
821 $self->send(pc85($main::mycall, $field[2], $field[3],"$main::mycall:your attempt is logged, Tut tut tut...!"));
824 my $ref = DXUser->get_current($field[1]);
825 if ($ref && $ref->is_clx) {
826 $self->route($field[1], $line);
828 route($field[1], pc34($field[2], $field[1], $field[4]));
834 if ($pcno == 85) { # remote command replies
835 if ($field[1] eq $main::mycall) {
836 my $dxchan = DXChannel->get($field[3]);
838 $dxchan->send($field[4]);
840 my $s = $rcmds{$field[2]};
842 $dxchan = DXChannel->get($s->{call});
843 $dxchan->send($field[4]) if $dxchan;
844 delete $rcmds{$field[2]} if !$dxchan;
848 my $ref = DXUser->get_current($field[1]);
849 if ($ref && $ref->is_clx) {
850 $self->route($field[1], $line);
852 route($field[1], pc35($field[2], $field[1], $field[4]));
859 # if get here then rebroadcast the thing with its Hop count decremented (if
860 # there is one). If it has a hop count and it decrements to zero then don't
863 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
867 unless ($self->{isolate}) {
868 broadcast_ak1a($line, $self); # send it to everyone but me
873 # This is called from inside the main cluster processing loop and is used
874 # for despatching commands that are doing some long processing job
879 my @dxchan = DXChannel->get_all();
882 foreach $dxchan (@dxchan) {
883 next unless $dxchan->is_node();
884 next if $dxchan == $me;
886 # send a pc50 out on this channel
887 if ($t >= $dxchan->pc50_t + $DXProt::pc50_interval) {
888 $dxchan->send(pc50(scalar DXChannel::get_all_users));
892 # send a ping out on this channel
893 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
894 if ($dxchan->{nopings} <= 0) {
897 addping($main::mycall, $dxchan->call);
898 $dxchan->{nopings} -= 1;
899 $dxchan->{lastping} = $t;
907 if ($main::systime - 3600 > $last_hour) {
911 $last_hour = $main::systime;
916 # finish up a pc context
921 my $call = $self->call;
923 my $ref = DXCluster->get_exact($call);
925 # unbusy and stop and outgoing mail
926 my $mref = DXMsg::get_busy($call);
927 $mref->stop_msg($call) if $mref;
929 # broadcast to all other nodes that all the nodes connected to via me are gone
930 my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
933 foreach $node (@gonenodes) {
934 next if $node->call eq $call;
935 broadcast_ak1a(pc21($node->call, 'Gone') , $self) unless $self->{isolate};
939 # remove outstanding pings
940 delete $pings{$call};
942 # now broadcast to all other ak1a nodes that I have gone
943 broadcast_ak1a(pc21($call, 'Gone.'), $self) unless $self->{isolate};
945 # I was the last node visited
946 $self->user->node($main::mycall);
948 # send info to all logged in thingies
949 $self->tell_login('logoutn');
951 Log('DXProt', $call . " Disconnected");
956 # some active measures
962 my @dxchan = DXChannel->get_all();
965 # send it if it isn't the except list and isn't isolated and still has a hop count
966 # taking into account filtering and so on
967 foreach $dxchan (@dxchan) {
971 if ($dxchan->{spotfilter}) {
972 ($filter, $hops) = Filter::it($dxchan->{spotfilter}, @_, $self->{call} );
976 if ($dxchan->is_node) {
977 next if $dxchan == $self;
980 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
982 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
983 next unless $routeit;
986 $dxchan->send($routeit) if $routeit;
988 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
990 } elsif ($dxchan->is_user && $dxchan->{dx}) {
991 my $buf = Spot::formatb($dxchan->{user}->wantgrid, $_[0], $_[1], $_[2], $_[3], $_[4]);
992 $buf .= "\a\a" if $dxchan->{beep};
993 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
996 $dxchan->delay($buf);
1006 my @dxchan = DXChannel->get_all();
1009 # send it if it isn't the except list and isn't isolated and still has a hop count
1010 # taking into account filtering and so on
1011 foreach $dxchan (@dxchan) {
1013 my ($filter, $hops);
1015 if ($dxchan->{wwvfilter}) {
1016 ($filter, $hops) = Filter::it($dxchan->{wwvfilter}, @_, $self->{call} );
1017 next unless $filter;
1019 if ($dxchan->is_node) {
1020 next if $dxchan == $self;
1023 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1025 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1026 next unless $routeit;
1029 $dxchan->send($routeit) if $routeit;
1031 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1034 } elsif ($dxchan->is_user && $dxchan->{wwv}) {
1035 my $buf = "WWV de $_[6] <$_[1]>: SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
1036 $buf .= "\a\a" if $dxchan->{beep};
1037 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1038 $dxchan->send($buf);
1040 $dxchan->delay($buf);
1050 my @dxchan = DXChannel->get_all();
1053 # send it if it isn't the except list and isn't isolated and still has a hop count
1054 # taking into account filtering and so on
1055 foreach $dxchan (@dxchan) {
1057 my ($filter, $hops);
1059 if ($dxchan->{wcyfilter}) {
1060 ($filter, $hops) = Filter::it($dxchan->{wcyfilter}, @_, $self->{call} );
1061 next unless $filter;
1063 if ($dxchan->is_clx || $dxchan->is_spider) {
1064 next if $dxchan == $self;
1067 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1069 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1070 next unless $routeit;
1073 $dxchan->send($routeit) if $routeit;
1075 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1077 } elsif ($dxchan->is_user && $dxchan->{wcy}) {
1078 my $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
1079 $buf .= "\a\a" if $dxchan->{beep};
1080 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1081 $dxchan->send($buf);
1083 $dxchan->delay($buf);
1094 my @dxchan = DXChannel->get_all();
1096 my $text = unpad($_[2]);
1100 if ($_[3] eq '*') { # sysops
1102 } elsif ($_[3] gt ' ') { # speciality list handling
1103 my ($name) = split /\./, $_[3];
1104 $target = "$name"; # put the rest in later (if bothered)
1111 $target = "All" if !$target;
1113 Log('ann', $target, $_[0], $text);
1115 # send it if it isn't the except list and isn't isolated and still has a hop count
1116 # taking into account filtering and so on
1117 foreach $dxchan (@dxchan) {
1119 my ($filter, $hops);
1121 if ($dxchan->{annfilter}) {
1122 ($filter, $hops) = Filter::it($dxchan->{annfilter}, @_, $self->{call} );
1123 next unless $filter;
1125 if ($dxchan->is_node && $_[1] ne $main::mycall) { # i.e not specifically routed to me
1126 next if $dxchan == $self;
1129 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1131 $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1132 next unless $routeit;
1135 $dxchan->send($routeit) if $routeit;
1137 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1140 } elsif ($dxchan->is_user && $dxchan->{ann}) {
1141 next if $target eq 'SYSOP' && $dxchan->{priv} < 5;
1142 my $buf = "$to$target de $_[0]: $text";
1143 $buf .= "\a\a" if $dxchan->{beep};
1144 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1145 $dxchan->send($buf);
1147 $dxchan->delay($buf);
1153 sub send_local_config
1162 if ($self->{isolate}) {
1163 @localnodes = (DXCluster->get_exact($main::mycall));
1165 # create a list of all the nodes that are not connected to this connection
1166 # and are not themselves isolated, this to make sure that isolated nodes
1167 # don't appear outside of this node
1168 @nodes = DXNode::get_all();
1169 @nodes = grep { $_->{call} ne $main::mycall } @nodes;
1170 @nodes = grep { $_->dxchan != $self } @nodes if @nodes;
1171 @nodes = grep { !$_->dxchan->{isolate} } @nodes if @nodes;
1172 @localnodes = grep { $_->dxchan->{call} eq $_->{call} } @nodes if @nodes;
1173 unshift @localnodes, DXCluster->get_exact($main::mycall);
1174 @remotenodes = grep { $_->dxchan->{call} ne $_->{call} } @nodes if @nodes;
1177 my @s = $me->pc19(@localnodes, @remotenodes);
1179 my $routeit = adjust_hops($self, $_);
1180 $self->send($routeit) if $routeit;
1183 # get all the users connected on the above nodes and send them out
1184 foreach $n (@localnodes, @remotenodes) {
1185 my @users = values %{$n->list};
1186 my @s = pc16($n, @users);
1188 my $routeit = adjust_hops($self, $_);
1189 $self->send($routeit) if $routeit;
1195 # route a message down an appropriate interface for a callsign
1197 # is called route(to, pcline);
1201 my ($self, $call, $line) = @_;
1202 my $cl = DXCluster->get_exact($call);
1203 if ($cl) { # don't route it back down itself
1204 if (ref $self && $call eq $self->{call}) {
1205 dbg('chan', "Trying to route back to source, dropped");
1209 my $dxchan = $cl->{dxchan};
1211 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1213 $dxchan->send($routeit) if $dxchan;
1219 # broadcast a message to all clusters taking into account isolation
1220 # [except those mentioned after buffer]
1223 my $s = shift; # the line to be rebroadcast
1224 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1225 my @dxchan = DXChannel::get_all_ak1a();
1228 # send it if it isn't the except list and isn't isolated and still has a hop count
1229 foreach $dxchan (@dxchan) {
1230 next if grep $dxchan == $_, @except;
1231 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1232 $dxchan->send($routeit) unless $dxchan->{isolate} || !$routeit;
1236 # broadcast a message to all clusters ignoring isolation
1237 # [except those mentioned after buffer]
1238 sub broadcast_all_ak1a
1240 my $s = shift; # the line to be rebroadcast
1241 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1242 my @dxchan = DXChannel::get_all_ak1a();
1245 # send it if it isn't the except list and isn't isolated and still has a hop count
1246 foreach $dxchan (@dxchan) {
1247 next if grep $dxchan == $_, @except;
1248 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1249 $dxchan->send($routeit);
1253 # broadcast to all users
1254 # storing the spot or whatever until it is in a state to receive it
1257 my $s = shift; # the line to be rebroadcast
1258 my $sort = shift; # the type of transmission
1259 my $fref = shift; # a reference to an object to filter on
1260 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1261 my @dxchan = DXChannel::get_all_users();
1265 foreach $dxchan (@dxchan) {
1266 next if grep $dxchan == $_, @except;
1269 broadcast_list($s, $sort, $fref, @out);
1272 # broadcast to a list of users
1280 foreach $dxchan (@_) {
1283 if ($sort eq 'dx') {
1284 next unless $dxchan->{dx};
1285 ($filter) = Filter::it($dxchan->{spotfilter}, @{$fref}) if ref $fref;
1286 next unless $filter;
1288 next if $sort eq 'ann' && !$dxchan->{ann};
1289 next if $sort eq 'wwv' && !$dxchan->{wwv};
1290 next if $sort eq 'wcy' && !$dxchan->{wcy};
1291 next if $sort eq 'wx' && !$dxchan->{wx};
1293 $s =~ s/\a//og unless $dxchan->{beep};
1295 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1305 # obtain the hops from the list for this callsign and pc no
1311 my $hops = $DXProt::hopcount{$pcno};
1312 $hops = $DXProt::def_hopcount if !$hops;
1317 # adjust the hop count on a per node basis using the user loadable
1318 # hop table if available or else decrement an existing one
1325 my $call = $self->{call};
1328 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
1329 my ($pcno) = $s =~ /^PC(\d\d)/o;
1330 confess "$call called adjust_hops with '$s'" unless $pcno;
1331 my $ref = $nodehops{$call} if %nodehops;
1333 my $newhops = $ref->{$pcno};
1334 return "" if defined $newhops && $newhops == 0;
1335 $newhops = $ref->{default} unless $newhops;
1336 return "" if defined $newhops && $newhops == 0;
1337 $newhops = $hops if !$newhops;
1338 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1340 # simply decrement it
1342 return "" if !$hops;
1343 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
1355 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
1356 do "$main::data/hop_table.pl";
1362 # add a ping request to the ping queues
1365 my ($from, $to) = @_;
1366 my $ref = $pings{$to} || [];
1369 $r->{t} = [ gettimeofday ];
1370 route(undef, $to, pc51($to, $main::mycall, 1));
1375 # add a rcmd request to the rcmd queues
1378 my ($self, $to, $cmd) = @_;
1381 $r->{call} = $self->{call};
1382 $r->{t} = $main::systime;
1386 my $ref = DXCluster->get_exact($to);
1387 if ($ref && $ref->dxchan && $ref->dxchan->is_clx) {
1388 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1390 route(undef, $to, pc34($main::mycall, $to, $cmd));
1399 if ($self->{conn} && !$nopc39) {
1400 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1403 $self->SUPER::disconnect;