3 # This module impliments the protocal mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
30 use Time::HiRes qw(gettimeofday tv_interval);
40 use vars qw($VERSION $BRANCH);
41 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
42 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
43 $main::build += $VERSION;
44 $main::branch += $BRANCH;
46 use vars qw($pc11_max_age $pc23_max_age $last_pc50 $eph_restime $eph_info_restime $eph_pc34_restime
47 $last_hour $last10 %eph %pings %rcmds $ann_to_talk
48 $pingint $obscount %pc19list $chatdupeage
49 $investigation_int $pc19_version
50 %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
51 $allowzero $decode_dk0wcy $send_opernam @checklist);
53 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
54 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
56 $last_hour = time; # last time I did an hourly periodic update
57 %pings = (); # outstanding ping requests outbound
58 %rcmds = (); # outstanding rcmd requests outbound
59 %nodehops = (); # node specific hop control
60 %pc19list = (); # list of outstanding PC19s that haven't had PC16s on them
62 $censorpc = 1; # Do a BadWords::check on text fields and reject things
63 # loads of 'bad things'
64 $baddx = new DXHash "baddx";
65 $badspotter = new DXHash "badspotter";
66 $badnode = new DXHash "badnode";
67 $last10 = $last_pc50 = time;
71 $eph_info_restime = 60*60;
72 $eph_pc34_restime = 30;
75 $chatdupeage = 20 * 60 * 60;
76 $investigation_int = 7*86400; # time between checks to see if we can see this node
77 $pc19_version = 5466; # the visible version no for outgoing PC19s generated from pc59
81 [ qw(i c c m bp bc c) ], # pc10
82 [ qw(i f m d t m c c h) ], # pc11
83 [ qw(i c bm m bm bm p h) ], # pc12
87 undef , # pc16 has to be validated manually
88 [ qw(i c c h) ], # pc17
90 undef , # pc19 has to be validated manually
91 undef , # pc20 no validation
92 [ qw(i c m h) ], # pc21
93 undef , # pc22 no validation
94 [ qw(i d n n n n m c c h) ], # pc23
95 [ qw(i c p h) ], # pc24
96 [ qw(i c c n n) ], # pc25
97 [ qw(i f m d t m c c bc) ], # pc26
98 [ qw(i d n n n n m c c bc) ], # pc27
99 [ qw(i c c m c d t p m bp n p bp bc) ], # pc28
100 [ qw(i c c n m) ], # pc29
101 [ qw(i c c n) ], # pc30
102 [ qw(i c c n) ], # pc31
103 [ qw(i c c n) ], # pc32
104 [ qw(i c c n) ], # pc33
105 [ qw(i c c m) ], # pc34
106 [ qw(i c c m) ], # pc35
107 [ qw(i c c m) ], # pc36
108 [ qw(i c c n m) ], # pc37
109 undef, # pc38 not interested
110 [ qw(i c m) ], # pc39
111 [ qw(i c c m p n) ], # pc40
112 [ qw(i c n m h) ], # pc41
113 [ qw(i c c n) ], # pc42
114 undef, # pc43 don't handle it
115 [ qw(i c c n m m c) ], # pc44
116 [ qw(i c c n m) ], # pc45
117 [ qw(i c c n) ], # pc46
120 [ qw(i c m h) ], # pc49
121 [ qw(i c n h) ], # pc50
122 [ qw(i c c n) ], # pc51
144 [ qw(i d n n n n n n m m m c c h) ], # pc73
155 [ qw(i c c c m) ], # pc84
156 [ qw(i c c c m) ], # pc85
161 [ qw(i c n) ], # pc90
164 # use the entry in the check list to check the field list presented
165 # return OK if line NOT in check list (for now)
170 return 0 if $n < 0 || $n > @checklist;
171 my $ref = $checklist[$n];
172 return 0 unless ref $ref;
175 for ($i = 1; $i < @$ref; $i++) {
176 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
177 return 0 unless $act;
178 next if $blank && $_[$i] =~ /^[ \*]$/;
180 return $i unless is_callsign($_[$i]);
181 } elsif ($act eq 'i') {
183 } elsif ($act eq 'm') {
184 return $i unless is_pctext($_[$i]);
185 } elsif ($act eq 'p') {
186 return $i unless is_pcflag($_[$i]);
187 } elsif ($act eq 'f') {
188 return $i unless is_freq($_[$i]);
189 } elsif ($act eq 'n') {
190 return $i unless $_[$i] =~ /^[\d ]+$/;
191 } elsif ($act eq 'h') {
192 return $i unless $_[$i] =~ /^H\d\d?$/;
193 } elsif ($act eq 'd') {
194 return $i unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
195 } elsif ($act eq 't') {
196 return $i unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
204 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
209 # obtain a new connection this is derived from dxchannel
214 my $self = DXChannel::alloc(@_);
216 # add this node to the table, the values get filled in later
219 $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
224 # this is how a pc connection starts (for an incoming connection)
225 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
226 # all the crap that comes between).
229 my ($self, $line, $sort) = @_;
230 my $call = $self->{call};
231 my $user = $self->{user};
234 my $host = $self->{conn}->{peerhost} || "unknown";
235 Log('DXProt', "$call connected from $host");
237 # remember type of connection
238 $self->{consort} = $line;
239 $self->{outbound} = $sort eq 'O';
240 my $priv = $user->priv;
241 $priv = $user->priv(1) unless $priv;
242 $self->{priv} = $priv; # other clusters can always be 'normal' users
243 $self->{lang} = $user->lang || 'en';
244 $self->{isolate} = $user->{isolate};
245 $self->{consort} = $line; # save the connection type
249 # sort out registration
250 $self->{registered} = 1;
252 # get the output filters
253 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
254 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
255 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
256 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
257 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
260 # get the INPUT filters (these only pertain to Clusters)
261 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
262 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
263 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
264 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
265 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
267 # set unbuffered and no echo
268 $self->send_now('B',"0");
269 $self->send_now('E',"0");
270 $self->conn->echo(0) if $self->conn->can('echo');
272 # ping neighbour node stuff
273 my $ping = $user->pingint;
274 $ping = $pingint unless defined $ping;
275 $self->{pingint} = $ping;
276 $self->{nopings} = $user->nopings || $obscount;
277 $self->{pingtime} = [ ];
278 $self->{pingave} = 999;
279 $self->{metric} ||= 100;
280 $self->{lastping} = $main::systime;
282 # send initialisation string
283 unless ($self->{outbound}) {
287 $self->state('init');
288 $self->{pc50_t} = $main::systime;
290 # send info to all logged in thingies
291 $self->tell_login('loginn');
293 # run a script send the output to the debug file
294 my $script = new Script(lc $call) || new Script('node_default');
295 $script->run($self) if $script;
299 # send outgoing 'challenge'
310 $_[0] =~ s/^PC90\^[-A-Z0-9]+\^\d+\^//;
311 $_[0] =~ s/^PC91\^[-A-Z0-9]+\^\d+\^[-A-Z0-9]+\^//;
319 # $self->SUPER::send($line);
324 # This is the normal pcxx despatcher
328 my ($self, $line) = @_;
330 # remove any incoming PC90 frames
333 my @field = split /\^/, $line;
334 return unless @field;
336 pop @field if $field[-1] eq '~';
338 # print join(',', @field), "\n";
341 # process PC frames, this will fail unless the frame starts PCnn
342 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
343 unless (defined $pcno && $pcno >= 10 && $pcno <= 99) {
344 dbg("PCPROT: unknown protocol") if isdbg('chanerr');
348 # check for and dump bad protocol messages
349 my $n = check($pcno, @field);
351 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
355 my $origin = $self->{call};
357 my $sub = "handle_$pcno";
359 if ($self->can($sub)) {
360 $self->$sub($pcno, $line, $origin, @field);
362 $self->handle_default($pcno, $line, $origin, @field);
366 # incoming talk commands
375 return if $rspfcheck and !$self->rspfcheck(0, $_[6], $_[1]);
377 # will we allow it at all?
380 if (@bad = BadWords::check($_[3])) {
381 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
386 # is it for me or one of mine?
387 my ($from, $to, $via, $call, $dxchan);
396 # if this is a 'nodx' node then ignore it
397 if ($badnode->in($_[6]) || ($via && $badnode->in($via))) {
398 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
402 # if this is a 'bad spotter' user then ignore it
404 $nossid =~ s/-\d+$//;
405 if ($badspotter->in($nossid)) {
406 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
410 # if we are converting announces to talk is it a dup?
412 if (AnnTalk::is_talk_candidate($from, $_[3]) && AnnTalk::dup($from, $to, $_[3])) {
413 dbg("DXPROT: Dupe talk from announce, dropped") if isdbg('chanerr');
418 # it is here and logged on
419 $dxchan = DXChannel->get($main::myalias) if $to eq $main::mycall;
420 $dxchan = DXChannel->get($to) unless $dxchan;
421 if ($dxchan && $dxchan->is_user) {
423 $dxchan->talk($from, $to, $via, $_[3]);
427 # is it elsewhere, visible on the cluster via the to address?
428 # note: this discards the via unless the to address is on
431 if ($ref = Route::get($to)) {
432 $vref = Route::Node::get($via) if $via;
433 $vref = undef unless $vref && grep $to eq $_, $vref->users;
434 $ref->dxchan->talk($from, $to, $vref ? $via : undef, $_[3], $_[6]);
438 # not visible here, send a message of condolence
440 $ref = Route::get($from);
441 $vref = $ref = Route::Node::get($_[6]) unless $ref;
443 $dxchan = $ref->dxchan;
444 $dxchan->talk($main::mycall, $from, $vref ? $vref->call : undef, $dxchan->msg('talknh', $to) );
456 # route 'foreign' pc26s
458 if ($_[7] ne $main::mycall) {
459 $self->route($_[7], $line);
465 # return if $rspfcheck and !$self->rspfcheck(1, $_[7], $_[6]);
467 # if this is a 'nodx' node then ignore it
468 if ($badnode->in($_[7])) {
469 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
473 # if this is a 'bad spotter' user then ignore it
475 $nossid =~ s/-\d+$//;
476 if ($badspotter->in($nossid)) {
477 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
481 # convert the date to a unix date
482 my $d = cltounix($_[3], $_[4]);
483 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
484 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
485 dbg("PCPROT: Spot ignored, invalid date or out of range ($_[3] $_[4])\n") if isdbg('chanerr');
490 if ($baddx->in($_[2]) || BadWords::check($_[2]) || $_[2] =~ /COCK/) {
491 dbg("PCPROT: Bad DX spot, ignored") if isdbg('chanerr');
496 $_[5] =~ s/^\s+//; # take any leading blanks off
497 $_[2] = unpad($_[2]); # take off leading and trailing blanks from spotted callsign
498 if ($_[2] =~ /BUST\w*$/) {
499 dbg("PCPROT: useless 'BUSTED' spot") if isdbg('chanerr');
504 if (@bad = BadWords::check($_[5])) {
505 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
511 my @spot = Spot::prepare($_[1], $_[2], $d, $_[5], $_[6], $_[7]);
512 # global spot filtering on INPUT
513 if ($self->{inspotsfilter}) {
514 my ($filter, $hops) = $self->{inspotsfilter}->it(@spot);
516 dbg("PCPROT: Rejected by input spot filter") if isdbg('chanerr');
521 # this goes after the input filtering, but before the add
522 # so that if it is input filtered, it isn't added to the dup
523 # list. This allows it to come in from a "legitimate" source
524 if (Spot::dup($_[1], $_[2], $d, $_[5], $_[6])) {
525 dbg("PCPROT: Duplicate Spot ignored\n") if isdbg('chanerr');
533 # @spot at this point contains:-
534 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
535 # then spotted itu, spotted cq, spotters itu, spotters cq
536 # you should be able to route on any of these
539 # fix up qra locators of known users
540 my $user = DXUser->get_current($spot[4]);
542 my $qra = $user->qra;
543 unless ($qra && is_qra($qra)) {
544 my $lat = $user->lat;
545 my $long = $user->long;
546 if (defined $lat && defined $long) {
547 $user->qra(DXBearing::lltoqra($lat, $long));
552 # send a remote command to a distant cluster if it is visible and there is no
553 # qra locator and we havn't done it for a month.
555 unless ($user->qra) {
557 my $to = $user->homenode;
558 my $last = $user->lastoper || 0;
559 if ($send_opernam && $to && $to ne $main::mycall && $main::systime > $last + $DXUser::lastoperinterval && ($node = Route::Node::get($to)) ) {
560 my $cmd = "forward/opernam $spot[4]";
561 # send the rcmd but we aren't interested in the replies...
562 my $dxchan = $node->dxchan;
563 if ($dxchan && $dxchan->is_clx) {
564 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
566 route(undef, $to, pc34($main::mycall, $to, $cmd));
570 $node = Route::Node::get($to);
572 $dxchan = $node->dxchan;
573 if ($dxchan && $dxchan->is_clx) {
574 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
576 route(undef, $to, pc34($main::mycall, $to, $cmd));
580 $user->lastoper($main::systime);
589 $r = Local::spot($self, @spot);
591 # dbg("Local::spot1 error $@") if isdbg('local') if $@;
594 # DON'T be silly and send on PC26s!
595 return if $pcno == 26;
597 # send out the filtered spots
598 send_dx_spot($self, $line, @spot) if @spot;
609 # return if $rspfcheck and !$self->rspfcheck(1, $_[5], $_[1]);
611 # announce duplicate checking
612 $_[3] =~ s/^\s+//; # remove leading blanks
616 if (@bad = BadWords::check($_[3])) {
617 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
622 # if this is a 'nodx' node then ignore it
623 if ($badnode->in($_[5])) {
624 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
628 # if this is a 'bad spotter' user then ignore it
630 $nossid =~ s/-\d+$//;
631 if ($badspotter->in($nossid)) {
632 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
638 if ((($dxchan = DXChannel->get($_[2])) && $dxchan->is_user) || $_[4] =~ /^[\#\w.]+$/){
639 $self->send_chat($line, @_[1..6]);
640 } elsif ($_[2] eq '*' || $_[2] eq $main::mycall) {
642 # ignore something that looks like a chat line coming in with sysop
643 # flag - this is a kludge...
644 if ($_[3] =~ /^\#\d+ / && $_[4] eq '*') {
645 dbg('PCPROT: Probable chat rewrite, dropped') if isdbg('chanerr');
649 # here's a bit of fun, convert incoming ann with a callsign in the first word
650 # or one saying 'to <call>' to a talk if we can route to the recipient
652 my $call = AnnTalk::is_talk_candidate($_[1], $_[3]);
654 my $ref = Route::get($call);
656 $dxchan = $ref->dxchan;
657 $dxchan->talk($_[1], $call, undef, $_[3], $_[5]) if $dxchan != $self;
664 $self->send_announce($line, @_[1..6]);
666 $self->route($_[2], $line);
681 my $newline = "PC16^";
683 # dos I want users from this channel?
684 unless ($self->user->wantpc16) {
685 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
689 if ($ncall eq $main::mycall) {
690 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
694 # do we believe this call?
695 unless ($ncall eq $self->{call} || $self->is_believed($ncall)) {
696 if (my $ivp = Investigate::get($ncall, $self->{call})) {
697 $ivp->store_pcxx($pcno,$line,$origin,@_);
699 dbg("PCPROT: We don't believe $ncall on $self->{call}");
703 if (eph_dup($line)) {
704 dbg("PCPROT: dup PC16 detected") if isdbg('chanerr');
708 my $parent = Route::Node::get($ncall);
710 # if there is a parent, proceed, otherwise if there is a latent PC19 in the PC19list,
711 # fix it up in the routing tables and issue it forth before the PC16
713 my $nl = $pc19list{$ncall};
715 if ($nl && @_ > 3) { # 3 because of the hop count!
717 # this is a new (remembered) node, now attach it to me if it isn't in filtered
718 # and we haven't disallowed it
719 my $user = DXUser->get_current($ncall);
721 $user = DXUser->new($ncall);
723 $user->priv(1); # I have relented and defaulted nodes
725 $user->homenode($ncall);
729 my $wantpc19 = $user->wantroutepc19;
730 if ($wantpc19 || !defined $wantpc19) {
731 my $new = Route->new($ncall); # throw away
732 if ($self->in_filter_route($new)) {
735 $parent = Route::Node::get($_->[0]);
736 $dxchan = $parent->dxchan if $parent;
737 if ($dxchan && $dxchan ne $self) {
738 dbg("PCPROT: PC19 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
742 my $r = $parent->add($ncall, $_->[1], $_->[2]);
743 push @nrout, $r unless @nrout;
746 $user->wantroutepc19(1) unless defined $wantpc19; # for now we work on the basis that pc16 = real route
747 $user->lastin($main::systime) unless DXChannel->get($ncall);
750 # route the pc19 - this will cause 'stuttering PC19s' for a while
751 $self->route_pc19($origin, $line, @nrout) if @nrout ;
752 $parent = Route::Node::get($ncall);
754 dbg("PCPROT: lost $ncall after sending PC19 for it?");
760 delete $pc19list{$ncall};
763 dbg("PCPROT: Node $ncall not in config") if isdbg('chanerr');
768 $dxchan = $parent->dxchan;
769 if ($dxchan && $dxchan ne $self) {
770 dbg("PCPROT: PC16 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
774 # input filter if required
775 return unless $self->in_filter_route($parent);
780 for ($i = 2; $i < $#_; $i++) {
781 my ($call, $conf, $here) = $_[$i] =~ /^(\S+) (\S) (\d)/o;
782 next unless $call && $conf && defined $here && is_callsign($call);
783 next if $call eq $main::mycall;
785 eph_del_regex("^PC17\\^$call\\^$ncall");
787 $conf = $conf eq '*';
789 # reject this if we think it is a node already
790 my $r = Route::Node::get($call);
791 my $u = DXUser->get_current($call) unless $r;
792 if ($r || ($u && $u->is_node)) {
793 dbg("PCPROT: $call is a node") if isdbg('chanerr');
797 $r = Route::User::get($call);
798 my $flags = Route::here($here)|Route::conf($conf);
801 my $au = $r->addparent($parent);
802 if ($r->flags != $flags) {
806 push @rout, $r if $au;
808 push @rout, $parent->add_user($call, $flags);
812 # add this station to the user database, if required
813 $call =~ s/-\d+$//o; # remove ssid for users
814 my $user = DXUser->get_current($call);
815 $user = DXUser->new($call) if !$user;
816 $user->homenode($parent->call) if !$user->homenode;
817 $user->node($parent->call);
818 $user->lastin($main::systime) unless DXChannel->get($call);
821 $self->route_pc16($origin, $line, $parent, @rout) if @rout;
835 eph_del_regex("^PC16\\^$ncall.*$ucall");
837 # do I want users from this channel?
838 unless ($self->user->wantpc16) {
839 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
842 if ($ncall eq $main::mycall) {
843 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
847 # do we believe this call?
848 unless ($ncall eq $self->{call} || $self->is_believed($ncall)) {
849 if (my $ivp = Investigate::get($ncall, $self->{call})) {
850 $ivp->store_pcxx($pcno,$line,$origin,@_);
852 dbg("PCPROT: We don't believe $ncall on $self->{call}");
856 my $uref = Route::User::get($ucall);
858 dbg("PCPROT: Route::User $ucall not in config") if isdbg('chanerr');
860 my $parent = Route::Node::get($ncall);
862 dbg("PCPROT: Route::Node $ncall not in config") if isdbg('chanerr');
865 $dxchan = $parent->dxchan if $parent;
866 if ($dxchan && $dxchan ne $self) {
867 dbg("PCPROT: PC17 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
871 # input filter if required and then remove user if present
873 # return unless $self->in_filter_route($parent);
874 $parent->del_user($uref) if $uref;
876 $parent = Route->new($ncall); # throw away
879 if (eph_dup($line)) {
880 dbg("PCPROT: dup PC17 detected") if isdbg('chanerr');
884 $uref = Route->new($ucall) unless $uref; # throw away
885 $self->route_pc17($origin, $line, $parent, $uref);
895 $self->state('init');
897 # record the type and version offered
898 if ($_[1] =~ /DXSpider Version: (\d+\.\d+) Build: (\d+\.\d+)/) {
899 $self->version(53 + $1);
900 $self->user->version(53 + $1);
901 $self->build(0 + $2);
902 $self->user->build(0 + $2);
903 unless ($self->is_spider) {
904 $self->user->sort('S');
909 $self->version(50.0);
910 $self->version($_[2] / 100) if $_[2] && $_[2] =~ /^\d+$/;
911 $self->user->version($self->version);
914 # first clear out any nodes on this dxchannel
915 my $parent = Route::Node::get($self->{call});
916 my @rout = $parent->del_nodes;
917 $self->route_pc21($origin, $line, @rout, $parent) if @rout;
918 $self->send_local_config();
922 # incoming cluster list
931 my $newline = "PC19^";
936 # first get the INTERFACE node
937 my $parent = Route::Node::get($self->{call});
939 dbg("DXPROT: my parent $self->{call} has disappeared");
944 # if the origin isn't the same as the INTERFACE, then reparent, creating nodes as necessary
945 if ($origin ne $self->call) {
946 my $op = Route::Node::get($origin);
948 $op = $parent->add($origin, 5000, Route::here(1));
949 my $user = DXUser->get_current($origin);
951 $user = DXUser->new($origin);
953 $user->priv(1); # I have relented and defaulted nodes
955 $user->homenode($origin);
956 $user->node($origin);
957 $user->wantroutepc19(1);
965 for ($i = 1; $i < $#_-1; $i += 4) {
967 my $call = uc $_[$i+1];
970 next unless defined $here && defined $conf && is_callsign($call);
972 eph_del_regex("^PC(?:21\\^$call|17\\^[^\\^]+\\^$call)");
974 # check for sane parameters
975 # $ver = 5000 if $ver eq '0000';
976 next if $ver < 5000; # only works with version 5 software
977 next if length $call < 3; # min 3 letter callsigns
978 next if $call eq $main::mycall;
980 # check that this PC19 isn't trying to alter the wrong dxchan
981 my $dxchan = DXChannel->get($call);
982 if ($dxchan && $dxchan != $self) {
983 dbg("PCPROT: PC19 from $self->{call} trying to alter wrong locally connected $call, ignored!") if isdbg('chanerr');
987 # add this station to the user database, if required (don't remove SSID from nodes)
988 my $user = DXUser->get_current($call);
990 $user = DXUser->new($call);
992 $user->priv(1); # I have relented and defaulted nodes
994 $user->homenode($call);
998 # do we believe this call?
999 my $genline = "PC19^$here^$call^$conf^$ver^$_[-1]^";
1000 unless ($call eq $self->{call} || $self->is_believed($call)) {
1001 my $pt = $user->lastping($self->{call}) || 0;
1002 if ($pt+$investigation_int < $main::systime && !Investigate::get($call, $self->{call})) {
1003 my $ivp = Investigate->new($call, $self->{call});
1004 $ivp->version($ver);
1006 $ivp->store_pcxx($pcno,$genline,$origin,'PC19',$here,$call,$conf,$ver,$_[-1]);
1008 dbg("PCPROT: We don't believe $call on $self->{call}");
1013 if (eph_dup($genline)) {
1014 dbg("PCPROT: dup PC19 for $call detected") if isdbg('chanerr');
1018 my $r = Route::Node::get($call);
1019 my $flags = Route::here($here)|Route::conf($conf);
1021 # modify the routing table if it is in it, otherwise store it in the pc19list for now
1024 if ($call ne $parent->call) {
1025 if ($self->in_filter_route($r)) {
1026 $ar = $parent->add($call, $ver, $flags);
1027 push @rout, $ar if $ar;
1032 if ($r->version ne $ver || $r->flags != $flags) {
1035 push @rout, $r unless $ar;
1039 # if he is directly connected or allowed then add him, otherwise store him up for later
1040 if ($call eq $self->{call} || $user->wantroutepc19) {
1041 my $new = Route->new($call); # throw away
1042 if ($self->in_filter_route($new)) {
1043 my $ar = $parent->add($call, $ver, $flags);
1044 $user->wantroutepc19(1) unless defined $user->wantroutepc19;
1045 push @rout, $ar if $ar;
1050 $pc19list{$call} = [] unless exists $pc19list{$call};
1051 my $nl = $pc19list{$call};
1052 push @{$pc19list{$call}}, [$self->{call}, $ver, $flags] unless grep $_->[0] eq $self->{call}, @$nl;
1056 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
1057 my $mref = DXMsg::get_busy($call);
1058 $mref->stop_msg($call) if $mref;
1060 $user->lastin($main::systime) unless DXChannel->get($call);
1065 $self->route_pc19($origin, $line, @rout) if @rout;
1068 # send local configuration
1075 $self->send_local_config();
1076 $self->send(pc22());
1077 $self->state('normal');
1078 $self->{lastping} = 0;
1081 # delete a cluster from the list
1088 my $call = uc $_[1];
1090 eph_del_regex("^PC1[679].*$call");
1092 # if I get a PC21 from the same callsign as self then treat it
1093 # as a PC39: I have gone away
1094 if ($call eq $self->call) {
1095 $self->disconnect(1);
1099 # check if we believe this
1100 unless ($call eq $self->{call} || $self->is_believed($call)) {
1101 if (my $ivp = Investigate::get($call, $self->{call})) {
1102 $ivp->store_pcxx($pcno,$line,$origin,@_);
1104 dbg("PCPROT: We don't believe $call on $self->{call}");
1108 # check to see if we are in the pc19list, if we are then don't bother with any of
1109 # this routing table manipulation, just remove it from the list and dump it
1111 if (my $nl = $pc19list{$call}) {
1112 $pc19list{$call} = [ grep {$_->[0] ne $self->{call}} @$nl ];
1113 delete $pc19list{$call} unless @{$pc19list{$call}};
1116 my $parent = Route::Node::get($self->{call});
1118 dbg("DXPROT: my parent $self->{call} has disappeared");
1122 if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
1123 my $node = Route::Node::get($call);
1126 my $dxchan = DXChannel->get($call);
1127 if ($dxchan && $dxchan != $self) {
1128 dbg("PCPROT: PC21 from $self->{call} trying to alter locally connected $call, ignored!") if isdbg('chanerr');
1133 return unless $self->in_filter_route($node);
1136 push @rout, $node->del($parent);
1139 dbg("PCPROT: I WILL _NOT_ be disconnected!") if isdbg('chanerr');
1144 $self->route_pc21($origin, $line, @rout) if @rout;
1154 $self->state('normal');
1155 $self->{lastping} = 0;
1166 # route foreign' pc27s
1168 if ($_[8] ne $main::mycall) {
1169 $self->route($_[8], $line);
1174 # only do a rspf check on PC23 (not 27)
1176 return if $rspfcheck and !$self->rspfcheck(1, $_[8], $_[7])
1180 my $d = cltounix($_[1], sprintf("%02d18Z", $_[2]));
1181 my $sfi = unpad($_[3]);
1182 my $k = unpad($_[4]);
1183 my $i = unpad($_[5]);
1184 my ($r) = $_[6] =~ /R=(\d+)/;
1186 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1187 dbg("PCPROT: WWV Date ($_[1] $_[2]) out of range") if isdbg('chanerr');
1190 if (Geomag::dup($d,$sfi,$k,$i,$_[6])) {
1191 dbg("PCPROT: Dup WWV Spot ignored\n") if isdbg('chanerr');
1194 $_[7] =~ s/-\d+$//o; # remove spotter's ssid
1196 my $wwv = Geomag::update($d, $_[2], $sfi, $k, $i, @_[6..8], $r);
1200 $rep = Local::wwv($self, $_[1], $_[2], $sfi, $k, $i, @_[6..8], $r);
1202 # dbg("Local::wwv2 error $@") if isdbg('local') if $@;
1205 # DON'T be silly and send on PC27s!
1206 return if $pcno == 27;
1208 # broadcast to the eager world
1209 send_wwv_spot($self, $line, $d, $_[2], $sfi, $k, $i, @_[6..8]);
1219 my $call = uc $_[1];
1221 $nref = Route::Node::get($call);
1222 $uref = Route::User::get($call);
1223 return unless $nref || $uref; # if we don't know where they are, it's pointless sending it on
1225 if (eph_dup($line)) {
1226 dbg("PCPROT: Dup PC24 ignored\n") if isdbg('chanerr');
1230 $nref->here($_[2]) if $nref;
1231 $uref->here($_[2]) if $uref;
1232 my $ref = $nref || $uref;
1233 return unless $self->in_filter_route($ref);
1235 $self->route_pc24($origin, $line, $ref, $_[3]);
1245 if ($_[1] ne $main::mycall) {
1246 $self->route($_[1], $line);
1249 if ($_[2] eq $main::mycall) {
1250 dbg("PCPROT: Trying to merge to myself, ignored") if isdbg('chanerr');
1254 Log('DXProt', "Merge request for $_[3] spots and $_[4] WWV from $_[2]");
1258 my @in = reverse Spot::search(1, undef, undef, 0, $_[3]);
1261 $self->send(pc26(@{$in}[0..4], $_[2]));
1267 my @in = reverse Geomag::search(0, $_[4], time, 1);
1270 $self->send(pc27(@{$in}[0..5], $_[2]));
1275 sub handle_26 {goto &handle_11}
1276 sub handle_27 {goto &handle_23}
1278 # mail/file handling
1285 if ($_[1] eq $main::mycall) {
1287 my $sub = "DXMsg::handle_$pcno";
1290 $self->route($_[1], $line) unless $self->is_clx;
1294 sub handle_29 {goto &handle_28}
1295 sub handle_30 {goto &handle_28}
1296 sub handle_31 {goto &handle_28}
1297 sub handle_32 {goto &handle_28}
1298 sub handle_33 {goto &handle_28}
1306 if (eph_dup($line, $eph_pc34_restime)) {
1307 dbg("PCPROT: dupe PC34, ignored") if isdbg('chanerr');
1309 $self->process_rcmd($_[1], $_[2], $_[2], $_[3]);
1313 # remote command replies
1320 eph_del_regex("^PC35\\^$_[2]\\^$_[1]\\^");
1321 $self->process_rcmd_reply($_[1], $_[2], $_[1], $_[3]);
1324 sub handle_36 {goto &handle_34}
1333 if ($_[1] eq $main::mycall) {
1335 my $sub = "DXDb::handle_$pcno";
1338 $self->route($_[1], $line) unless $self->is_clx;
1342 # node connected list from neighbour
1351 # incoming disconnect
1358 if ($_[1] eq $self->{call}) {
1359 $self->disconnect(1);
1361 dbg("PCPROT: came in on wrong channel") if isdbg('chanerr');
1365 sub handle_40 {goto &handle_28}
1377 $l =~ s/[\x00-\x20\x7f-\xff]+//g; # remove all funny characters and spaces for dup checking
1378 if (eph_dup($l, $eph_info_restime)) {
1379 dbg("PCPROT: dup PC41, ignored") if isdbg('chanerr');
1383 # input filter if required
1384 # my $ref = Route::get($call) || Route->new($call);
1385 # return unless $self->in_filter_route($ref);
1387 if ($_[3] eq $_[2] || $_[3] =~ /^\s*$/) {
1388 dbg('PCPROT: invalid value') if isdbg('chanerr');
1392 # add this station to the user database, if required
1393 my $user = DXUser->get_current($call);
1394 $user = DXUser->new($call) unless $user;
1398 } elsif ($_[2] == 2) {
1400 } elsif ($_[2] == 3) {
1401 if (is_latlong($_[3])) {
1402 my ($lat, $long) = DXBearing::stoll($_[3]);
1405 $user->qra(DXBearing::lltoqra($lat, $long));
1407 dbg('PCPROT: not a valid lat/long') if isdbg('chanerr');
1410 } elsif ($_[2] == 4) {
1411 $user->homenode($_[3]);
1412 } elsif ($_[2] == 5) {
1413 if (is_qra(uc $_[3])) {
1414 my ($lat, $long) = DXBearing::qratoll(uc $_[3]);
1417 $user->qra(uc $_[3]);
1419 dbg('PCPROT: not a valid QRA locator') if isdbg('chanerr');
1423 $user->lastoper($main::systime); # to cut down on excessive for/opers being generated
1426 unless ($self->{isolate}) {
1427 DXChannel::broadcast_nodes($line, $self); # send it to everyone but me
1430 # perhaps this IS what we want after all
1431 # $self->route_pc41($ref, $call, $_[2], $_[3], $_[4]);
1434 sub handle_42 {goto &handle_28}
1438 sub handle_44 {goto &handle_37}
1439 sub handle_45 {goto &handle_37}
1440 sub handle_46 {goto &handle_37}
1441 sub handle_47 {goto &handle_37}
1442 sub handle_48 {goto &handle_37}
1444 # message and database
1452 if (eph_dup($line)) {
1453 dbg("PCPROT: Dup PC49 ignored\n") if isdbg('chanerr');
1457 if ($_[1] eq $main::mycall) {
1458 DXMsg::handle_49($self, @_);
1460 $self->route($_[1], $line) unless $self->is_clx;
1464 # keep alive/user list
1473 my $node = Route::Node::get($call);
1475 return unless $node->call eq $self->{call};
1476 $node->usercount($_[2]);
1478 # input filter if required
1479 return unless $self->in_filter_route($node);
1481 $self->route_pc50($origin, $line, $node, $_[2], $_[3]) unless eph_dup($line);
1485 # incoming ping requests/answers
1498 if ($to eq $main::mycall) {
1500 $self->send(pc51($from, $to, '0'));
1502 # it's a reply, look in the ping list for this one
1503 my $ref = $pings{$from};
1505 my $tochan = DXChannel->get($from);
1507 my $r = shift @$ref;
1508 my $dxchan = DXChannel->get($r->{call});
1509 next unless $dxchan;
1510 my $t = tv_interval($r->{t}, [ gettimeofday ]);
1511 if ($dxchan->is_user) {
1512 my $s = sprintf "%.2f", $t;
1513 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
1514 $dxchan->send($dxchan->msg('pingi', $from, $s, $ave))
1515 } elsif ($dxchan->is_node) {
1517 my $nopings = $tochan->user->nopings || $obscount;
1518 push @{$tochan->{pingtime}}, $t;
1519 shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
1521 # cope with a missed ping, this means you must set the pingint large enough
1522 if ($t > $tochan->{pingint} && $t < 2 * $tochan->{pingint} ) {
1523 $t -= $tochan->{pingint};
1526 # calc smoothed RTT a la TCP
1527 if (@{$tochan->{pingtime}} == 1) {
1528 $tochan->{pingave} = $t;
1530 $tochan->{pingave} = $tochan->{pingave} + (($t - $tochan->{pingave}) / 6);
1532 $tochan->{nopings} = $nopings; # pump up the timer
1533 if (my $ivp = Investigate::get($from, $self->{call})) {
1536 } elsif (my $rref = Route::Node::get($r->{call})) {
1537 if (my $ivp = Investigate::get($from, $self->{call})) {
1546 if (eph_dup($line)) {
1547 dbg("PCPROT: dup PC51 detected") if isdbg('chanerr');
1550 # route down an appropriate thingy
1551 $self->route($to, $line);
1555 # dunno but route it
1563 if ($call ne $main::mycall) {
1564 $self->route($call, $line);
1578 my $d = cltounix($call, sprintf("%02d18Z", $_[2]));
1579 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1580 dbg("PCPROT: WCY Date ($call $_[2]) out of range") if isdbg('chanerr');
1583 @_ = map { unpad($_) } @_;
1585 dbg("PCPROT: Dup WCY Spot ignored\n") if isdbg('chanerr');
1589 my $wcy = WCY::update($d, @_[2..12]);
1593 $rep = Local::wcy($self, @_[1..12]);
1595 # dbg("Local::wcy error $@") if isdbg('local') if $@;
1598 # broadcast to the eager world
1599 send_wcy_spot($self, $line, $d, @_[2..12]);
1602 # remote commands (incoming)
1609 $self->process_rcmd($_[1], $_[2], $_[3], $_[4]);
1612 # remote command replies
1619 $self->process_rcmd_reply($_[1], $_[2], $_[3], $_[4]);
1622 # if get here then rebroadcast the thing with its Hop count decremented (if
1623 # there is one). If it has a hop count and it decrements to zero then don't
1626 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
1637 if (eph_dup($line)) {
1638 dbg("PCPROT: Ephemeral dup, dropped") if isdbg('chanerr');
1640 unless ($self->{isolate}) {
1641 DXChannel::broadcast_nodes($line, $self) if $line =~ /\^H\d+\^?~?$/; # send it to everyone but me
1647 # This is called from inside the main cluster processing loop and is used
1648 # for despatching commands that are doing some long processing job
1653 my @dxchan = DXChannel->get_all();
1657 # send out a pc50 on EVERY channel all at once
1658 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
1659 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
1664 foreach $dxchan (@dxchan) {
1665 next unless $dxchan->is_node();
1666 next if $dxchan == $main::me;
1669 $dxchan->send($pc50s) if $pc50s;
1671 # send a ping out on this channel
1672 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
1673 if ($dxchan->{nopings} <= 0) {
1674 $dxchan->disconnect;
1676 addping($main::mycall, $dxchan->call);
1677 $dxchan->{nopings} -= 1;
1678 $dxchan->{lastping} = $t;
1683 Investigate::process();
1686 if ($t - $last10 >= 10) {
1687 # clean out ephemera
1694 if ($main::systime - 3600 > $last_hour) {
1695 $last_hour = $main::systime;
1700 # finish up a pc context
1704 # some active measures
1712 my @dxchan = DXChannel->get_all();
1715 # send it if it isn't the except list and isn't isolated and still has a hop count
1716 # taking into account filtering and so on
1717 foreach $dxchan (@dxchan) {
1718 next if $dxchan == $main::me;
1719 next if $dxchan == $self && $self->is_node;
1720 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
1728 my $isolate = shift;
1729 my ($filter, $hops);
1731 if ($self->{spotsfilter}) {
1732 ($filter, $hops) = $self->{spotsfilter}->it(@_);
1733 return unless $filter;
1735 send_prot_line($self, $filter, $hops, $isolate, $line);
1740 my ($self, $filter, $hops, $isolate, $line) = @_;
1746 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1748 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1749 return unless $routeit;
1752 $self->send($routeit);
1754 $self->send($routeit) unless $self->{isolate} || $isolate;
1763 my @dxchan = DXChannel->get_all();
1765 my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
1767 # send it if it isn't the except list and isn't isolated and still has a hop count
1768 # taking into account filtering and so on
1769 foreach $dxchan (@dxchan) {
1770 next if $dxchan == $main::me;
1771 next if $dxchan == $self && $self->is_node;
1773 my ($filter, $hops);
1775 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
1783 my $isolate = shift;
1784 my ($filter, $hops);
1786 if ($self->{wwvfilter}) {
1787 ($filter, $hops) = $self->{wwvfilter}->it(@_);
1788 return unless $filter;
1790 send_prot_line($self, $filter, $hops, $isolate, $line)
1797 my @dxchan = DXChannel->get_all();
1799 my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
1801 # send it if it isn't the except list and isn't isolated and still has a hop count
1802 # taking into account filtering and so on
1803 foreach $dxchan (@dxchan) {
1804 next if $dxchan == $main::me;
1805 next if $dxchan == $self;
1807 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
1815 my $isolate = shift;
1816 my ($filter, $hops);
1818 if ($self->{wcyfilter}) {
1819 ($filter, $hops) = $self->{wcyfilter}->it(@_);
1820 return unless $filter;
1822 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
1830 my @dxchan = DXChannel->get_all();
1834 my $text = unpad($_[2]);
1836 if ($_[3] eq '*') { # sysops
1838 } elsif ($_[3] gt ' ') { # speciality list handling
1839 my ($name) = split /\./, $_[3];
1840 $target = "$name"; # put the rest in later (if bothered)
1847 $target = "ALL" if !$target;
1850 # obtain country codes etc
1851 my @a = Prefix::cty_data($_[0]);
1852 my @b = Prefix::cty_data($_[4]);
1853 if ($self->{inannfilter}) {
1854 my ($filter, $hops) =
1855 $self->{inannfilter}->it(@_, $self->{call},
1857 @b[0..2], $a[3], $b[3]);
1859 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1864 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
1865 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1869 Log('ann', $target, $_[0], $text);
1871 # send it if it isn't the except list and isn't isolated and still has a hop count
1872 # taking into account filtering and so on
1873 foreach $dxchan (@dxchan) {
1874 next if $dxchan == $main::me;
1875 next if $dxchan == $self && $self->is_node;
1876 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
1877 @a[0..2], @b[0..2]);
1886 $msgid = 1 if $msgid > 999;
1895 my @dxchan = DXChannel->get_all();
1898 my $text = unpad($_[2]);
1901 # munge the group and recast the line if required
1902 if ($target =~ s/\.LST$//) {
1906 # obtain country codes etc
1907 my @a = Prefix::cty_data($_[0]);
1908 my @b = Prefix::cty_data($_[4]);
1909 if ($self->{inannfilter}) {
1910 my ($filter, $hops) =
1911 $self->{inannfilter}->it(@_, $self->{call},
1913 @b[0..2], $a[3], $b[3]);
1915 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1920 if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
1921 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1926 Log('chat', $target, $_[0], $text);
1928 # send it if it isn't the except list and isn't isolated and still has a hop count
1929 # taking into account filtering and so on
1930 foreach $dxchan (@dxchan) {
1931 my $is_ak1a = $dxchan->is_ak1a;
1933 if ($dxchan->is_node) {
1934 next if $dxchan == $main::me;
1935 next if $dxchan == $self;
1936 next unless $dxchan->is_spider || $is_ak1a;
1937 next if $target eq 'LOCAL';
1938 if (!$ak1a_line && $is_ak1a) {
1939 $ak1a_line = DXProt::pc12($_[0], $text, $_[1], "$target.LST");
1943 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1],
1944 $text, @_, $self->{call}, @a[0..2], @b[0..2]);
1952 my $isolate = shift;
1956 my ($filter, $hops);
1958 if ($self->{annfilter}) {
1959 ($filter, $hops) = $self->{annfilter}->it(@_);
1960 return unless $filter;
1962 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
1971 sub send_local_config
1979 dbg('DXProt::send_local_config') if isdbg('trace');
1982 if ($self->{isolate}) {
1983 @localnodes = ( $main::routeroot );
1984 $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
1986 # create a list of all the nodes that are not connected to this connection
1987 # and are not themselves isolated, this to make sure that isolated nodes
1988 # don't appear outside of this node
1990 # send locally connected nodes
1991 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
1992 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
1993 $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
1996 my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
1998 for $node (@rawintcalls) {
1999 push @intcalls, $node unless grep $node eq $_, @intcalls;
2001 my $ref = Route::Node::get($self->{call});
2002 my @rnodes = $ref->nodes;
2003 for $node (@intcalls) {
2004 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
2006 $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
2009 # get all the users connected on the above nodes and send them out
2010 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
2012 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
2013 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
2015 dbg("sent a null value") if isdbg('chanerr');
2021 # route a message down an appropriate interface for a callsign
2023 # is called route(to, pcline);
2027 my ($self, $call, $line) = @_;
2029 if (ref $self && $call eq $self->{call}) {
2030 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
2034 # always send it down the local interface if available
2035 my $dxchan = DXChannel->get($call);
2037 my $cl = Route::get($call);
2038 $dxchan = $cl->dxchan if $cl;
2040 if (ref $self && $dxchan eq $self) {
2041 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
2047 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
2049 $dxchan->send($routeit) unless $dxchan == $main::me;
2052 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
2057 # obtain the hops from the list for this callsign and pc no
2063 my $hops = $DXProt::hopcount{$pcno};
2064 $hops = $DXProt::def_hopcount if !$hops;
2069 # adjust the hop count on a per node basis using the user loadable
2070 # hop table if available or else decrement an existing one
2077 my $call = $self->{call};
2080 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
2081 my ($pcno) = $s =~ /^PC(\d\d)/o;
2082 confess "$call called adjust_hops with '$s'" unless $pcno;
2083 my $ref = $nodehops{$call} if %nodehops;
2085 my $newhops = $ref->{$pcno};
2086 return "" if defined $newhops && $newhops == 0;
2087 $newhops = $ref->{default} unless $newhops;
2088 return "" if defined $newhops && $newhops == 0;
2089 $newhops = $hops if !$newhops;
2090 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
2092 # simply decrement it
2094 return "" if !$hops;
2095 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
2107 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
2108 do "$main::data/hop_table.pl";
2114 # add a ping request to the ping queues
2117 my ($from, $to, $via) = @_;
2118 my $ref = $pings{$to} || [];
2121 $r->{t} = [ gettimeofday ];
2122 if ($via && (my $dxchan = DXChannel->get($via))) {
2123 $dxchan->send(pc51($to, $main::mycall, 1));
2125 route(undef, $to, pc51($to, $main::mycall, 1));
2129 my $u = DXUser->get_current($to);
2131 $u->lastping(($via || $from), $main::systime);
2138 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
2139 if ($tonode eq $main::mycall) {
2140 my $ref = DXUser->get_current($fromnode);
2141 my $cref = Route::Node::get($fromnode);
2142 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
2143 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
2144 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
2145 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
2146 my $oldpriv = $self->{priv};
2147 $self->{priv} = $ref->{priv}; # assume the user's privilege level
2148 my @in = (DXCommandmode::run_cmd($self, $cmd));
2149 $self->{priv} = $oldpriv;
2150 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
2151 delete $self->{remotecmd};
2153 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
2156 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
2159 my $ref = DXUser->get_current($tonode);
2160 if ($ref && $ref->is_clx) {
2161 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
2163 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
2168 sub process_rcmd_reply
2170 my ($self, $tonode, $fromnode, $user, $line) = @_;
2171 if ($tonode eq $main::mycall) {
2172 my $s = $rcmds{$fromnode};
2174 my $dxchan = DXChannel->get($s->{call});
2175 my $ref = $user eq $tonode ? $dxchan : (DXChannel->get($user) || $dxchan);
2176 $ref->send($line) if $ref;
2177 delete $rcmds{$fromnode} if !$dxchan;
2179 # send unsolicited ones to the sysop
2180 my $dxchan = DXChannel->get($main::myalias);
2181 $dxchan->send($line) if $dxchan;
2184 my $ref = DXUser->get_current($tonode);
2185 if ($ref && $ref->is_clx) {
2186 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
2188 $self->route($tonode, pc35($fromnode, $tonode, $line));
2197 my $fromnode = shift;
2202 Log('rcmd', 'out', $fromnode, $line);
2203 if ($self->is_clx) {
2204 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
2206 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
2211 # add a rcmd request to the rcmd queues
2214 my ($self, $to, $cmd) = @_;
2217 $r->{call} = $self->{call};
2218 $r->{t} = $main::systime;
2222 my $ref = Route::Node::get($to);
2223 my $dxchan = $ref->dxchan;
2224 if ($dxchan && $dxchan->is_clx) {
2225 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
2227 route(undef, $to, pc34($main::mycall, $to, $cmd));
2234 my $pc39flag = shift;
2235 my $call = $self->call;
2237 return if $self->{disconnecting}++;
2239 unless ($pc39flag && $pc39flag == 1) {
2240 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
2243 # get rid of any PC16/17/19
2244 eph_del_regex("^PC1[679]*$call");
2246 # do routing stuff, remove me from routing table
2247 my $node = Route::Node::get($call);
2250 @rout = $node->del($main::routeroot);
2252 # and all my ephemera as well
2255 eph_del_regex("^PC1[679].*$c");
2259 # remove them from the pc19list as well
2260 while (my ($k,$v) = each %pc19list) {
2261 my @l = grep {$_->[0] ne $call} @{$pc19list{$k}};
2263 $pc19list{$k} = \@l;
2265 delete $pc19list{$k};
2269 eph_del_regex("^PC1[679].*$k");
2272 # unbusy and stop and outgoing mail
2273 my $mref = DXMsg::get_busy($call);
2274 $mref->stop_msg($call) if $mref;
2276 # broadcast to all other nodes that all the nodes connected to via me are gone
2277 unless ($pc39flag && $pc39flag == 2) {
2278 $self->route_pc21($main::mycall, undef, @rout) if @rout;
2281 # remove outstanding pings
2282 delete $pings{$call};
2284 # I was the last node visited
2285 $self->user->node($main::mycall);
2287 # send info to all logged in thingies
2288 $self->tell_login('logoutn');
2290 Log('DXProt', $call . " Disconnected");
2292 $self->SUPER::disconnect;
2297 # send a talk message to this thingy
2301 my ($self, $from, $to, $via, $line, $origin) = @_;
2303 $line =~ s/\^/\\5E/g; # remove any ^ characters
2304 $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
2305 Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
2308 # send it if it isn't the except list and isn't isolated and still has a hop count
2309 # taking into account filtering and so on
2315 my $generate = shift;
2316 my $no = shift; # the no of things to filter on
2318 my ($filter, $hops);
2321 for (; @_ && $no; $no--) {
2324 if (!$self->{isolate} && $self->{routefilter}) {
2327 ($filter, $hops) = $self->{routefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq, $self->{state}, $r->{state});
2331 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
2334 dbg("was sent a null value") if isdbg('chanerr');
2337 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
2341 foreach my $line (&$generate(@rin, @_)) {
2344 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
2346 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
2347 next unless $routeit;
2350 $self->send($routeit);
2359 my $generate = shift;
2361 my @dxchan = DXChannel::get_all_nodes();
2364 unless ($self->{isolate}) {
2365 foreach $dxchan (@dxchan) {
2366 next if $dxchan == $self;
2367 next if $dxchan == $main::me;
2368 next unless $dxchan->isa('DXProt');
2369 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
2371 $dxchan->send_route($origin, $generate, @_);
2379 return unless $self->user->wantpc16;
2382 broadcast_route($self, $origin, \&pc16, $line, 1, @_);
2388 return unless $self->user->wantpc16;
2391 broadcast_route($self, $origin, \&pc17, $line, 1, @_);
2399 broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
2407 broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
2415 broadcast_route($self, $origin, \&pc24, $line, 1, @_);
2423 broadcast_route($self, $origin, \&pc41, $line, 1, @_);
2431 broadcast_route($self, $origin, \&pc50, $line, 1, @_);
2438 my ($filter, $hops) = (1, 1);
2440 if ($self->{inroutefilter}) {
2441 ($filter, $hops) = $self->{inroutefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq, $self->state, $r->state);
2442 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
2450 my $t = shift || $eph_restime;
2454 $s =~ s/\^H\d\d?\^?\~?$//;
2455 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
2456 $eph{$s} = $main::systime + $t;
2457 dbg("PCPROT: emphemeral duplicate") if $r && isdbg('chan');
2465 while (($key, $val) = each %eph) {
2466 if ($key =~ m{$regex}) {
2476 while (($key, $val) = each %eph) {
2477 if ($main::systime >= $val) {
2488 while (($key, $val) = each %eph) {
2489 push @out, $key, $val;
2496 goto &DXCommandmode::run_cmd;