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);
48 use vars qw($VERSION $BRANCH);
50 main::mkver($VERSION = q$Revision$);
52 use vars qw($pc11_max_age $pc23_max_age $last_pc50 $eph_restime $eph_info_restime $eph_pc34_restime
53 $last_hour $last10 %eph %pings %rcmds $ann_to_talk
54 $pingint $obscount %pc19list $chatdupeage $chatimportfn
55 $investigation_int $pc19_version $myprot_version
56 %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
57 $allowzero $decode_dk0wcy $send_opernam @checklist);
59 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
60 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
62 $last_hour = time; # last time I did an hourly periodic update
63 %pings = (); # outstanding ping requests outbound
64 %rcmds = (); # outstanding rcmd requests outbound
65 %nodehops = (); # node specific hop control
66 %pc19list = (); # list of outstanding PC19s that haven't had PC16s on them
68 $censorpc = 1; # Do a BadWords::check on text fields and reject things
69 # loads of 'bad things'
70 $baddx = new DXHash "baddx";
71 $badspotter = new DXHash "badspotter";
72 $badnode = new DXHash "badnode";
73 $last10 = $last_pc50 = time;
77 $eph_info_restime = 60*60;
78 $eph_pc34_restime = 30;
81 $chatdupeage = 20 * 60 * 60;
82 $chatimportfn = "$main::root/chat_import";
83 $investigation_int = 12*60*60; # time between checks to see if we can see this node
84 $pc19_version = 5466; # the visible version no for outgoing PC19s generated from pc59
88 [ qw(i c c m bp bc c) ], # pc10
89 [ qw(i f m d t m c c h) ], # pc11
90 [ qw(i c bm m bm bm p h) ], # pc12
94 undef , # pc16 has to be validated manually
95 [ qw(i c c h) ], # pc17
97 undef , # pc19 has to be validated manually
98 undef , # pc20 no validation
99 [ qw(i c m h) ], # pc21
100 undef , # pc22 no validation
101 [ qw(i d n n n n m c c h) ], # pc23
102 [ qw(i c p h) ], # pc24
103 [ qw(i c c n n) ], # pc25
104 [ qw(i f m d t m c c bc) ], # pc26
105 [ qw(i d n n n n m c c bc) ], # pc27
106 [ qw(i c c m c d t p m bp n p bp bc) ], # pc28
107 [ qw(i c c n m) ], # pc29
108 [ qw(i c c n) ], # pc30
109 [ qw(i c c n) ], # pc31
110 [ qw(i c c n) ], # pc32
111 [ qw(i c c n) ], # pc33
112 [ qw(i c c m) ], # pc34
113 [ qw(i c c m) ], # pc35
114 [ qw(i c c m) ], # pc36
115 [ qw(i c c n m) ], # pc37
116 undef, # pc38 not interested
117 [ qw(i c m) ], # pc39
118 [ qw(i c c m p n) ], # pc40
119 [ qw(i c n m h) ], # pc41
120 [ qw(i c c n) ], # pc42
121 undef, # pc43 don't handle it
122 [ qw(i c c n m m c) ], # pc44
123 [ qw(i c c n m) ], # pc45
124 [ qw(i c c n) ], # pc46
127 [ qw(i c m h) ], # pc49
128 [ qw(i c n h) ], # pc50
129 [ qw(i c c n) ], # pc51
151 [ qw(i d n n n n n n m m m c c h) ], # pc73
162 [ qw(i c c c m) ], # pc84
163 [ qw(i c c c m) ], # pc85
168 [ qw(i c n) ], # pc90
171 # use the entry in the check list to check the field list presented
172 # return OK if line NOT in check list (for now)
177 return 0 if $n < 0 || $n > @checklist;
178 my $ref = $checklist[$n];
179 return 0 unless ref $ref;
182 for ($i = 1; $i < @$ref; $i++) {
183 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
184 return 0 unless $act;
185 next if $blank && $_[$i] =~ /^[ \*]$/;
187 return $i unless is_callsign($_[$i]);
188 } elsif ($act eq 'i') {
190 } elsif ($act eq 'm') {
191 return $i unless is_pctext($_[$i]);
192 } elsif ($act eq 'p') {
193 return $i unless is_pcflag($_[$i]);
194 } elsif ($act eq 'f') {
195 return $i unless is_freq($_[$i]);
196 } elsif ($act eq 'n') {
197 return $i unless $_[$i] =~ /^[\d ]+$/;
198 } elsif ($act eq 'h') {
199 return $i unless $_[$i] =~ /^H\d\d?$/;
200 } elsif ($act eq 'd') {
201 return $i unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
202 } elsif ($act eq 't') {
203 return $i unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
211 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
214 my $user = DXUser->get($main::mycall);
215 die "User $main::mycall not setup or disappeared RTFM" unless $user;
217 $myprot_version += $main::version*100;
218 $main::me = DXProt->new($main::mycall, 0, $user);
219 $main::me->{here} = 1;
220 $main::me->{state} = "indifferent";
221 $main::me->{sort} = 'S'; # S for spider
222 $main::me->{priv} = 9;
223 $main::me->{metric} = 0;
224 $main::me->{pingave} = 0;
225 $main::me->{registered} = 1;
226 $main::me->{version} = 5252 + $main::version;
227 $main::me->{build} = $main::build;
231 # obtain a new connection this is derived from dxchannel
236 my $self = DXChannel::alloc(@_);
238 # add this node to the table, the values get filled in later
241 $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
242 if ($self->{call} ne $main::mycall) {
243 my $thing = Thingy::Hello->new(user=>$call);
244 $thing->broadcast($self);
250 # this is how a pc connection starts (for an incoming connection)
251 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
252 # all the crap that comes between).
255 my ($self, $line, $sort) = @_;
256 my $call = $self->{call};
257 my $user = $self->{user};
260 my $host = $self->{conn}->{peerhost} || "unknown";
261 Log('DXProt', "$call connected from $host");
263 # remember type of connection
264 $self->{consort} = $line;
265 $self->{outbound} = $sort eq 'O';
266 my $priv = $user->priv;
267 $priv = $user->priv(1) unless $priv;
268 $self->{priv} = $priv; # other clusters can always be 'normal' users
269 $self->{lang} = $user->lang || 'en';
270 $self->{isolate} = $user->{isolate};
271 $self->{consort} = $line; # save the connection type
275 # sort out registration
276 $self->{registered} = 1;
278 # get the output filters
279 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
280 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
281 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
282 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
283 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
286 # get the INPUT filters (these only pertain to Clusters)
287 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
288 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
289 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
290 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
291 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
293 # set unbuffered and no echo
294 $self->send_now('B',"0");
295 $self->send_now('E',"0");
296 $self->conn->echo(0) if $self->conn->can('echo');
298 # ping neighbour node stuff
299 my $ping = $user->pingint;
300 $ping = $pingint unless defined $ping;
301 $self->{pingint} = $ping;
302 $self->{nopings} = $user->nopings || $obscount;
303 $self->{pingtime} = [ ];
304 $self->{pingave} = 999;
305 $self->{metric} ||= 100;
306 $self->{lastping} = $main::systime;
308 # send initialisation string
309 unless ($self->{outbound}) {
313 $self->state('init');
314 $self->{pc50_t} = $main::systime;
316 my $thing = Thingy::Hello->new(origin=>$main::mycall, user=>$call);
317 $thing->broadcast($self);
319 # send info to all logged in thingies
320 $self->tell_login('loginn');
322 # run a script send the output to the debug file
323 my $script = new Script(lc $call) || new Script('node_default');
324 $script->run($self) if $script;
328 # send outgoing 'challenge'
339 # This is the normal pcxx despatcher
343 my ($self, $line) = @_;
345 my @field = split /\^/, $line;
346 return unless @field;
348 pop @field if $field[-1] eq '~';
350 # print join(',', @field), "\n";
352 # process PC frames, this will fail unless the frame starts PCnn
353 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
354 unless (defined $pcno && $pcno >= 10 && $pcno <= 99) {
355 dbg("PCPROT: unknown protocol") if isdbg('chanerr');
359 # check for and dump bad protocol messages
360 my $n = check($pcno, @field);
362 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
366 # decrement any hop fields at this point
367 if ($line =~ /\^H(\d\d?)\^?~?$/) {
370 dbg("PCPROT: zero hop count, dumped") if isdbg('chanerr');
373 $line =~ s/\^H\d\d?(\^?~?)$/^H$hops$1/;
376 my $origin = $self->{call};
378 my $sub = "handle_$pcno";
380 if ($self->can($sub)) {
381 $self->$sub($pcno, $line, $origin, @field);
383 $self->handle_default($pcno, $line, $origin, @field);
387 # incoming talk commands
396 return if $rspfcheck and !$self->rspfcheck(0, $_[6], $_[1]);
398 # will we allow it at all?
401 if (@bad = BadWords::check($_[3])) {
402 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
407 # is it for me or one of mine?
408 my ($from, $to, $via, $call, $dxchan);
417 # if this is a 'nodx' node then ignore it
418 if ($badnode->in($_[6]) || ($via && $badnode->in($via))) {
419 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
423 # if this is a 'bad spotter' user then ignore it
425 $nossid =~ s/-\d+$//;
426 if ($badspotter->in($nossid)) {
427 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
431 # if we are converting announces to talk is it a dup?
433 if (AnnTalk::is_talk_candidate($from, $_[3]) && AnnTalk::dup($from, $to, $_[3])) {
434 dbg("DXPROT: Dupe talk from announce, dropped") if isdbg('chanerr');
439 # remember a route to this node and also the node on which this user is
440 RouteDB::update($_[6], $origin);
441 # RouteDB::update($to, $_[6]);
443 # it is here and logged on
444 $dxchan = DXChannel::get($main::myalias) if $to eq $main::mycall;
445 $dxchan = DXChannel::get($to) unless $dxchan;
446 if ($dxchan && $dxchan->is_user) {
448 $dxchan->talk($from, $to, $via, $_[3]);
452 # is it elsewhere, visible on the cluster via the to address?
453 # note: this discards the via unless the to address is on
456 if ($ref = Route::get($to)) {
457 $vref = Route::Node::get($via) if $via;
458 $vref = undef unless $vref && grep $to eq $_, $vref->users;
459 $ref->dxchan->talk($from, $to, $vref ? $via : undef, $_[3], $_[6]);
463 # can we see an interface to send it down?
465 # not visible here, send a message of condolence
467 $ref = Route::get($from);
468 $vref = $ref = Route::Node::get($_[6]) unless $ref;
470 $dxchan = $ref->dxchan;
471 $dxchan->talk($main::mycall, $from, $vref ? $vref->call : undef, $dxchan->msg('talknh', $to) );
483 # route 'foreign' pc26s
485 if ($_[7] ne $main::mycall) {
486 $self->route($_[7], $line);
492 # return if $rspfcheck and !$self->rspfcheck(1, $_[7], $_[6]);
494 # if this is a 'nodx' node then ignore it
495 if ($badnode->in($_[7])) {
496 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
500 # if this is a 'bad spotter' user then ignore it
502 $nossid =~ s/-\d+$//;
503 if ($badspotter->in($nossid)) {
504 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
508 # convert the date to a unix date
509 my $d = cltounix($_[3], $_[4]);
510 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
511 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
512 dbg("PCPROT: Spot ignored, invalid date or out of range ($_[3] $_[4])\n") if isdbg('chanerr');
517 if ($baddx->in($_[2]) || BadWords::check($_[2])) {
518 dbg("PCPROT: Bad DX spot, ignored") if isdbg('chanerr');
523 $_[5] =~ s/^\s+//; # take any leading blanks off
524 $_[2] = unpad($_[2]); # take off leading and trailing blanks from spotted callsign
525 if ($_[2] =~ /BUST\w*$/) {
526 dbg("PCPROT: useless 'BUSTED' spot") if isdbg('chanerr');
531 if (@bad = BadWords::check($_[5])) {
532 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
538 # RouteDB::update($_[7], $self->{call});
539 # RouteDB::update($_[6], $_[7]);
541 my @spot = Spot::prepare($_[1], $_[2], $d, $_[5], $_[6], $_[7]);
543 my $thing = Thingy::Dx->new(origin=>$main::mycall);
544 $thing->from_DXProt(DXProt=>$line,spotdata=>\@spot);
545 $thing->process($self);
547 # this goes after the input filtering, but before the add
548 # so that if it is input filtered, it isn't added to the dup
549 # list. This allows it to come in from a "legitimate" source
551 # @spot at this point contains:-
552 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
553 # then spotted itu, spotted cq, spotters itu, spotters cq
554 # you should be able to route on any of these
557 # fix up qra locators of known users
558 my $user = DXUser->get_current($spot[4]);
560 my $qra = $user->qra;
561 unless ($qra && is_qra($qra)) {
562 my $lat = $user->lat;
563 my $long = $user->long;
564 if (defined $lat && defined $long) {
565 $user->qra(DXBearing::lltoqra($lat, $long));
570 # send a remote command to a distant cluster if it is visible and there is no
571 # qra locator and we havn't done it for a month.
573 unless ($user->qra) {
575 my $to = $user->homenode;
576 my $last = $user->lastoper || 0;
577 if ($send_opernam && $to && $to ne $main::mycall && $main::systime > $last + $DXUser::lastoperinterval && ($node = Route::Node::get($to)) ) {
578 my $cmd = "forward/opernam $spot[4]";
579 # send the rcmd but we aren't interested in the replies...
580 my $dxchan = $node->dxchan;
581 if ($dxchan && $dxchan->is_clx) {
582 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
584 route(undef, $to, pc34($main::mycall, $to, $cmd));
588 $node = Route::Node::get($to);
590 $dxchan = $node->dxchan;
591 if ($dxchan && $dxchan->is_clx) {
592 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
594 route(undef, $to, pc34($main::mycall, $to, $cmd));
598 $user->lastoper($main::systime);
613 # return if $rspfcheck and !$self->rspfcheck(1, $_[5], $_[1]);
615 # announce duplicate checking
616 $_[3] =~ s/^\s+//; # remove leading blanks
620 if (@bad = BadWords::check($_[3])) {
621 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
626 # if this is a 'nodx' node then ignore it
627 if ($badnode->in($_[5])) {
628 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
632 # if this is a 'bad spotter' user then ignore it
634 $nossid =~ s/-\d+$//;
635 if ($badspotter->in($nossid)) {
636 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
643 if ((($dxchan = DXChannel::get($_[2])) && $dxchan->is_user) || $_[4] =~ /^[\#\w.]+$/){
644 $self->send_chat($line, @_[1..6]);
645 } elsif ($_[2] eq '*' || $_[2] eq $main::mycall) {
648 # RouteDB::update($_[5], $self->{call});
649 # RouteDB::update($_[1], $_[5]);
651 # ignore something that looks like a chat line coming in with sysop
652 # flag - this is a kludge...
653 if ($_[3] =~ /^\#\d+ / && $_[4] eq '*') {
654 dbg('PCPROT: Probable chat rewrite, dropped') if isdbg('chanerr');
658 # here's a bit of fun, convert incoming ann with a callsign in the first word
659 # or one saying 'to <call>' to a talk if we can route to the recipient
661 my $call = AnnTalk::is_talk_candidate($_[1], $_[3]);
663 my $ref = Route::get($call);
665 $dxchan = $ref->dxchan;
666 $dxchan->talk($_[1], $call, undef, $_[3], $_[5]) if $dxchan != $self;
673 $self->send_announce($line, @_[1..6]);
675 $self->route($_[2], $line);
690 my $newline = "PC16^";
692 # dos I want users from this channel?
693 unless ($self->user->wantpc16) {
694 dbg("PCPROT: don't send users to $origin") if isdbg('chanerr');
698 if ($ncall eq $main::mycall) {
699 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
703 RouteDB::update($ncall, $self->{call});
705 # do we believe this call?
706 unless ($ncall eq $self->{call} || $self->is_believed($ncall)) {
707 if (my $ivp = Investigate::get($ncall, $self->{call})) {
708 $ivp->store_pcxx($pcno,$line,$origin,@_);
710 dbg("PCPROT: We don't believe $ncall on $self->{call}") if isdbg('chanerr');
715 if (eph_dup($line)) {
716 dbg("PCPROT: dup PC16 detected") if isdbg('chanerr');
720 my $parent = Route::Node::get($ncall);
722 # if there is a parent, proceed, otherwise if there is a latent PC19 in the PC19list,
723 # fix it up in the routing tables and issue it forth before the PC16
725 my $nl = $pc19list{$ncall};
727 if ($nl && @_ > 3) { # 3 because of the hop count!
729 # this is a new (remembered) node, now attach it to me if it isn't in filtered
730 # and we haven't disallowed it
731 my $user = DXUser->get_current($ncall);
733 $user = DXUser->new($ncall);
735 $user->priv(1); # I have relented and defaulted nodes
737 $user->homenode($ncall);
741 my $wantpc19 = $user->wantroutepc19;
742 if ($wantpc19 || !defined $wantpc19) {
743 my $new = Route->new($ncall); # throw away
744 if ($self->in_filter_route($new)) {
747 $parent = Route::Node::get($_->[0]);
748 $dxchan = $parent->dxchan if $parent;
749 if ($dxchan && $dxchan ne $self) {
750 dbg("PCPROT: PC19 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
754 my $r = $parent->add($ncall, $_->[1], $_->[2]);
755 push @nrout, $r unless @nrout;
758 $user->wantroutepc19(1) unless defined $wantpc19; # for now we work on the basis that pc16 = real route
759 $user->lastin($main::systime) unless DXChannel::get($ncall);
762 # route the pc19 - this will cause 'stuttering PC19s' for a while
763 $self->route_pc19($origin, $line, @nrout) if @nrout ;
764 $parent = Route::Node::get($ncall);
766 dbg("PCPROT: lost $ncall after sending PC19 for it?");
772 delete $pc19list{$ncall};
775 dbg("PCPROT: Node $ncall not in config") if isdbg('chanerr');
780 $dxchan = $parent->dxchan;
781 if ($dxchan && $dxchan ne $self) {
782 dbg("PCPROT: PC16 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
786 # input filter if required
787 return unless $self->in_filter_route($parent);
792 for ($i = 2; $i < $#_; $i++) {
793 my ($call, $conf, $here) = $_[$i] =~ /^(\S+) (\S) (\d)/o;
794 next unless $call && $conf && defined $here && is_callsign($call);
795 next if $call eq $main::mycall;
797 eph_del_regex("^PC17\\^$call\\^$ncall");
799 $conf = $conf eq '*';
801 # reject this if we think it is a node already
802 my $r = Route::Node::get($call);
803 my $u = DXUser->get_current($call) unless $r;
804 if ($r || ($u && $u->is_node)) {
805 dbg("PCPROT: $call is a node") if isdbg('chanerr');
809 $r = Route::User::get($call);
810 my $flags = Route::here($here)|Route::conf($conf);
813 my $au = $r->addparent($parent);
814 if ($r->flags != $flags) {
818 push @rout, $r if $au;
820 push @rout, $parent->add_user($call, $flags);
824 # add this station to the user database, if required
825 $call =~ s/-\d+$//o; # remove ssid for users
826 my $user = DXUser->get_current($call);
827 $user = DXUser->new($call) if !$user;
828 $user->homenode($parent->call) if !$user->homenode;
829 $user->node($parent->call);
830 $user->lastin($main::systime) unless DXChannel::get($call);
833 $self->route_pc16($origin, $line, $parent, @rout) if @rout;
847 eph_del_regex("^PC16\\^$ncall.*$ucall");
849 # do I want users from this channel?
850 unless ($self->user->wantpc16) {
851 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
854 if ($ncall eq $main::mycall) {
855 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
859 RouteDB::delete($ncall, $self->{call});
861 # do we believe this call?
862 unless ($ncall eq $self->{call} || $self->is_believed($ncall)) {
863 if (my $ivp = Investigate::get($ncall, $self->{call})) {
864 $ivp->store_pcxx($pcno,$line,$origin,@_);
866 dbg("PCPROT: We don't believe $ncall on $self->{call}") if isdbg('chanerr');
871 my $uref = Route::User::get($ucall);
873 dbg("PCPROT: Route::User $ucall not in config") if isdbg('chanerr');
875 my $parent = Route::Node::get($ncall);
877 dbg("PCPROT: Route::Node $ncall not in config") if isdbg('chanerr');
880 $dxchan = $parent->dxchan if $parent;
881 if ($dxchan && $dxchan ne $self) {
882 dbg("PCPROT: PC17 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
886 # input filter if required and then remove user if present
888 # return unless $self->in_filter_route($parent);
889 $parent->del_user($uref) if $uref;
891 $parent = Route->new($ncall); # throw away
894 if (eph_dup($line)) {
895 dbg("PCPROT: dup PC17 detected") if isdbg('chanerr');
899 $uref = Route->new($ucall) unless $uref; # throw away
900 $self->route_pc17($origin, $line, $parent, $uref);
910 $self->state('init');
912 # record the type and version offered
913 if ($_[1] =~ /DXSpider Version: (\d+\.\d+) Build: (\d+\.\d+)/) {
914 $self->version(52.51 + $1);
915 $self->user->version(52.51 + $1);
916 $self->build(0 + $2);
917 $self->user->build(0 + $2);
918 unless ($self->is_spider) {
919 $self->user->sort('S');
924 $self->version(50.0);
925 $self->version($_[2] / 100) if $_[2] && $_[2] =~ /^\d+$/;
926 $self->user->version($self->version);
929 # first clear out any nodes on this dxchannel
930 my $parent = Route::Node::get($origin);
931 my @rout = $parent->del_nodes;
932 $self->route_pc21($origin, $line, @rout, $parent) if @rout;
933 $self->send_local_config();
937 # incoming cluster list
946 my $newline = "PC19^";
951 # first get the INTERFACE node
952 my $parent = Route::Node::get($origin);
954 dbg("DXPROT: my parent $origin has disappeared");
959 # if the origin isn't the same as the INTERFACE, then reparent, creating nodes as necessary
960 if ($origin ne $self->call) {
961 my $op = Route::Node::get($origin);
963 $op = $parent->add($origin, 5000, Route::here(1));
964 my $user = DXUser->get_current($origin);
966 $user = DXUser->new($origin);
967 $user->priv(1); # I have relented and defaulted nodes
969 $user->homenode($origin);
970 $user->node($origin);
971 $user->wantroutepc19(1);
973 $user->sort('A') unless $user->is_node;
980 for ($i = 1; $i < $#_-1; $i += 4) {
982 my $call = uc $_[$i+1];
985 next unless defined $here && defined $conf && is_callsign($call);
987 eph_del_regex("^PC(?:21\\^$call|17\\^[^\\^]+\\^$call)");
989 # check for sane parameters
990 # $ver = 5000 if $ver eq '0000';
991 next if $ver < 5000; # only works with version 5 software
992 next if length $call < 3; # min 3 letter callsigns
993 next if $call eq $main::mycall;
995 # check that this PC19 isn't trying to alter the wrong dxchan
996 my $dxchan = DXChannel::get($call);
997 if ($dxchan && $dxchan != $self) {
998 dbg("PCPROT: PC19 from $origin trying to alter wrong locally connected $call, ignored!") if isdbg('chanerr');
1002 # add this station to the user database, if required (don't remove SSID from nodes)
1003 my $user = DXUser->get_current($call);
1005 $user = DXUser->new($call);
1006 $user->priv(1); # I have relented and defaulted nodes
1008 $user->homenode($call);
1011 $user->sort('A') unless $user->is_node;
1013 RouteDB::update($call, $origin);
1015 # do we believe this call?
1016 my $genline = "PC19^$here^$call^$conf^$ver^$_[-1]^";
1017 unless ($call eq $origin || $self->is_believed($call)) {
1018 my $pt = $user->lastping($origin) || 0;
1019 if ($pt+$investigation_int < $main::systime && !Investigate::get($call, $origin)) {
1020 my $ivp = Investigate->new($call, $origin);
1021 $ivp->version($ver);
1023 $ivp->store_pcxx($pcno,$genline,$origin,'PC19',$here,$call,$conf,$ver,$_[-1]);
1025 dbg("PCPROT: We don't believe $call on $origin") if isdbg('chanerr');
1031 if (eph_dup($genline)) {
1032 dbg("PCPROT: dup PC19 for $call detected") if isdbg('chanerr');
1036 my $r = Route::Node::get($call);
1037 my $flags = Route::here($here)|Route::conf($conf);
1039 # modify the routing table if it is in it, otherwise store it in the pc19list for now
1042 if ($call ne $parent->call) {
1043 if ($self->in_filter_route($r)) {
1044 $ar = $parent->add($call, $ver, $flags);
1045 push @rout, $ar if $ar;
1050 if ($r->version ne $ver || $r->flags != $flags) {
1053 push @rout, $r unless $ar;
1057 # if he is directly connected or allowed then add him, otherwise store him up for later
1058 if ($call eq $origin || $user->wantroutepc19) {
1059 my $new = Route->new($call); # throw away
1060 if ($self->in_filter_route($new)) {
1061 my $ar = $parent->add($call, $ver, $flags);
1062 $user->wantroutepc19(1) unless defined $user->wantroutepc19;
1063 push @rout, $ar if $ar;
1068 $pc19list{$call} = [] unless exists $pc19list{$call};
1069 my $nl = $pc19list{$call};
1070 push @{$pc19list{$call}}, [$origin, $ver, $flags] unless grep $_->[0] eq $origin, @$nl;
1074 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
1075 my $mref = DXMsg::get_busy($call);
1076 $mref->stop_msg($call) if $mref;
1078 $user->lastin($main::systime) unless DXChannel::get($call);
1083 $self->route_pc19($origin, $line, @rout) if @rout;
1086 # send local configuration
1093 $self->send_local_config();
1094 $self->send(pc22());
1095 $self->state('normal');
1096 $self->{lastping} = 0;
1099 # delete a cluster from the list
1106 my $call = uc $_[1];
1108 eph_del_regex("^PC1[679].*$call");
1110 # if I get a PC21 from the same callsign as self then treat it
1111 # as a PC39: I have gone away
1112 if ($call eq $self->call) {
1113 $self->disconnect(1);
1117 RouteDB::delete($call, $origin);
1119 # check if we believe this
1120 unless ($call eq $origin || $self->is_believed($call)) {
1121 if (my $ivp = Investigate::get($call, $origin)) {
1122 $ivp->store_pcxx($pcno,$line,$origin,@_);
1124 dbg("PCPROT: We don't believe $call on $origin") if isdbg('chanerr');
1129 # check to see if we are in the pc19list, if we are then don't bother with any of
1130 # this routing table manipulation, just remove it from the list and dump it
1132 if (my $nl = $pc19list{$call}) {
1133 $pc19list{$call} = [ grep {$_->[0] ne $origin} @$nl ];
1134 delete $pc19list{$call} unless @{$pc19list{$call}};
1137 my $parent = Route::Node::get($origin);
1139 dbg("DXPROT: my parent $origin has disappeared");
1143 if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
1144 my $node = Route::Node::get($call);
1147 my $dxchan = DXChannel::get($call);
1148 if ($dxchan && $dxchan != $self) {
1149 dbg("PCPROT: PC21 from $origin trying to alter locally connected $call, ignored!") if isdbg('chanerr');
1154 return unless $self->in_filter_route($node);
1157 push @rout, $node->del($parent);
1160 dbg("PCPROT: I WILL _NOT_ be disconnected!") if isdbg('chanerr');
1165 $self->route_pc21($origin, $line, @rout) if @rout;
1175 $self->state('normal');
1176 $self->{lastping} = 0;
1187 # route foreign' pc27s
1189 if ($_[8] ne $main::mycall) {
1190 $self->route($_[8], $line);
1195 # only do a rspf check on PC23 (not 27)
1197 return if $rspfcheck and !$self->rspfcheck(1, $_[8], $_[7])
1201 my $d = cltounix($_[1], sprintf("%02d18Z", $_[2]));
1202 my $sfi = unpad($_[3]);
1203 my $k = unpad($_[4]);
1204 my $i = unpad($_[5]);
1205 my ($r) = $_[6] =~ /R=(\d+)/;
1207 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1208 dbg("PCPROT: WWV Date ($_[1] $_[2]) out of range") if isdbg('chanerr');
1211 if (Geomag::dup($d,$sfi,$k,$i,$_[6])) {
1212 dbg("PCPROT: Dup WWV Spot ignored\n") if isdbg('chanerr');
1215 $_[7] =~ s/-\d+$//o; # remove spotter's ssid
1217 my $wwv = Geomag::update($d, $_[2], $sfi, $k, $i, @_[6..8], $r);
1221 $rep = Local::wwv($self, $_[1], $_[2], $sfi, $k, $i, @_[6..8], $r);
1223 # dbg("Local::wwv2 error $@") if isdbg('local') if $@;
1226 # DON'T be silly and send on PC27s!
1227 return if $pcno == 27;
1229 # broadcast to the eager world
1230 send_wwv_spot($self, $line, $d, $_[2], $sfi, $k, $i, @_[6..8]);
1240 my $call = uc $_[1];
1242 $nref = Route::Node::get($call);
1243 $uref = Route::User::get($call);
1244 return unless $nref || $uref; # if we don't know where they are, it's pointless sending it on
1246 if (eph_dup($line)) {
1247 dbg("PCPROT: Dup PC24 ignored\n") if isdbg('chanerr');
1251 $nref->here($_[2]) if $nref;
1252 $uref->here($_[2]) if $uref;
1253 my $ref = $nref || $uref;
1254 return unless $self->in_filter_route($ref);
1256 $self->route_pc24($origin, $line, $ref, $_[3]);
1266 if ($_[1] ne $main::mycall) {
1267 $self->route($_[1], $line);
1270 if ($_[2] eq $main::mycall) {
1271 dbg("PCPROT: Trying to merge to myself, ignored") if isdbg('chanerr');
1275 Log('DXProt', "Merge request for $_[3] spots and $_[4] WWV from $_[2]");
1279 my @in = reverse Spot::search(1, undef, undef, 0, $_[3]);
1282 $self->send(pc26(@{$in}[0..4], $_[2]));
1288 my @in = reverse Geomag::search(0, $_[4], time, 1);
1291 $self->send(pc27(@{$in}[0..5], $_[2]));
1296 sub handle_26 {goto &handle_11}
1297 sub handle_27 {goto &handle_23}
1299 # mail/file handling
1306 if ($_[1] eq $main::mycall) {
1308 my $sub = "DXMsg::handle_$pcno";
1311 $self->route($_[1], $line) unless $self->is_clx;
1315 sub handle_29 {goto &handle_28}
1316 sub handle_30 {goto &handle_28}
1317 sub handle_31 {goto &handle_28}
1318 sub handle_32 {goto &handle_28}
1319 sub handle_33 {goto &handle_28}
1327 if (eph_dup($line, $eph_pc34_restime)) {
1328 dbg("PCPROT: dupe PC34, ignored") if isdbg('chanerr');
1330 $self->process_rcmd($_[1], $_[2], $_[2], $_[3]);
1334 # remote command replies
1341 eph_del_regex("^PC35\\^$_[2]\\^$_[1]\\^");
1342 $self->process_rcmd_reply($_[1], $_[2], $_[1], $_[3]);
1345 sub handle_36 {goto &handle_34}
1354 if ($_[1] eq $main::mycall) {
1356 my $sub = "DXDb::handle_$pcno";
1359 $self->route($_[1], $line) unless $self->is_clx;
1363 # node connected list from neighbour
1372 # incoming disconnect
1379 if ($_[1] eq $origin) {
1380 $self->disconnect(1);
1382 dbg("PCPROT: came in on wrong channel") if isdbg('chanerr');
1386 sub handle_40 {goto &handle_28}
1398 $l =~ s/[\x00-\x20\x7f-\xff]+//g; # remove all funny characters and spaces for dup checking
1399 if (eph_dup($l, $eph_info_restime)) {
1400 dbg("PCPROT: dup PC41, ignored") if isdbg('chanerr');
1404 # input filter if required
1405 # my $ref = Route::get($call) || Route->new($call);
1406 # return unless $self->in_filter_route($ref);
1408 if ($_[3] eq $_[2] || $_[3] =~ /^\s*$/) {
1409 dbg('PCPROT: invalid value') if isdbg('chanerr');
1413 # add this station to the user database, if required
1414 my $user = DXUser->get_current($call);
1415 $user = DXUser->new($call) unless $user;
1419 } elsif ($_[2] == 2) {
1421 } elsif ($_[2] == 3) {
1422 if (is_latlong($_[3])) {
1423 my ($lat, $long) = DXBearing::stoll($_[3]);
1426 $user->qra(DXBearing::lltoqra($lat, $long));
1428 dbg('PCPROT: not a valid lat/long') if isdbg('chanerr');
1431 } elsif ($_[2] == 4) {
1432 $user->homenode($_[3]);
1433 } elsif ($_[2] == 5) {
1434 if (is_qra(uc $_[3])) {
1435 my ($lat, $long) = DXBearing::qratoll(uc $_[3]);
1438 $user->qra(uc $_[3]);
1440 dbg('PCPROT: not a valid QRA locator') if isdbg('chanerr');
1444 $user->lastoper($main::systime); # to cut down on excessive for/opers being generated
1447 unless ($self->{isolate}) {
1448 DXChannel::broadcast_nodes($line, $self); # send it to everyone but me
1451 # perhaps this IS what we want after all
1452 # $self->route_pc41($ref, $call, $_[2], $_[3], $_[4]);
1455 sub handle_42 {goto &handle_28}
1459 sub handle_44 {goto &handle_37}
1460 sub handle_45 {goto &handle_37}
1461 sub handle_46 {goto &handle_37}
1462 sub handle_47 {goto &handle_37}
1463 sub handle_48 {goto &handle_37}
1465 # message and database
1473 if (eph_dup($line)) {
1474 dbg("PCPROT: Dup PC49 ignored\n") if isdbg('chanerr');
1478 if ($_[1] eq $main::mycall) {
1479 DXMsg::handle_49($self, @_);
1481 $self->route($_[1], $line) unless $self->is_clx;
1485 # keep alive/user list
1495 RouteDB::update($call, $origin);
1497 my $node = Route::Node::get($call);
1499 return unless $node->call eq $origin;
1500 $node->usercount($_[2]);
1502 # input filter if required
1503 return unless $self->in_filter_route($node);
1505 $self->route_pc50($origin, $line, $node, $_[2], $_[3]) unless eph_dup($line);
1509 # incoming ping requests/answers
1522 if ($to eq $main::mycall) {
1524 $self->send(pc51($from, $to, '0'));
1526 # it's a reply, look in the ping list for this one
1527 my $ref = $pings{$from};
1529 my $tochan = DXChannel::get($from);
1531 my $r = shift @$ref;
1532 my $dxchan = DXChannel::get($r->{call});
1533 next unless $dxchan;
1534 my $t = tv_interval($r->{t}, [ gettimeofday ]);
1535 if ($dxchan->is_user) {
1536 my $s = sprintf "%.2f", $t;
1537 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
1538 $dxchan->send($dxchan->msg('pingi', $from, $s, $ave))
1539 } elsif ($dxchan->is_node) {
1541 my $nopings = $tochan->user->nopings || $obscount;
1542 push @{$tochan->{pingtime}}, $t;
1543 shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
1545 # cope with a missed ping, this means you must set the pingint large enough
1546 if ($t > $tochan->{pingint} && $t < 2 * $tochan->{pingint} ) {
1547 $t -= $tochan->{pingint};
1550 # calc smoothed RTT a la TCP
1551 if (@{$tochan->{pingtime}} == 1) {
1552 $tochan->{pingave} = $t;
1554 $tochan->{pingave} = $tochan->{pingave} + (($t - $tochan->{pingave}) / 6);
1556 $tochan->{nopings} = $nopings; # pump up the timer
1557 if (my $ivp = Investigate::get($from, $origin)) {
1560 } elsif (my $rref = Route::Node::get($r->{call})) {
1561 if (my $ivp = Investigate::get($from, $origin)) {
1571 RouteDB::update($from, $origin);
1573 if (eph_dup($line)) {
1574 dbg("PCPROT: dup PC51 detected") if isdbg('chanerr');
1577 # route down an appropriate thingy
1578 $self->route($to, $line);
1582 # dunno but route it
1590 if ($call ne $main::mycall) {
1591 $self->route($call, $line);
1605 my $d = cltounix($call, sprintf("%02d18Z", $_[2]));
1606 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1607 dbg("PCPROT: WCY Date ($call $_[2]) out of range") if isdbg('chanerr');
1610 @_ = map { unpad($_) } @_;
1612 dbg("PCPROT: Dup WCY Spot ignored\n") if isdbg('chanerr');
1616 my $wcy = WCY::update($d, @_[2..12]);
1620 $rep = Local::wcy($self, @_[1..12]);
1622 # dbg("Local::wcy error $@") if isdbg('local') if $@;
1625 # broadcast to the eager world
1626 send_wcy_spot($self, $line, $d, @_[2..12]);
1629 # remote commands (incoming)
1636 $self->process_rcmd($_[1], $_[2], $_[3], $_[4]);
1639 # remote command replies
1646 $self->process_rcmd_reply($_[1], $_[2], $_[3], $_[4]);
1649 # if get here then rebroadcast the thing with its Hop count decremented (if
1650 # there is one). If it has a hop count and it decrements to zero then don't
1653 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
1664 if (eph_dup($line)) {
1665 dbg("PCPROT: Ephemeral dup, dropped") if isdbg('chanerr');
1667 unless ($self->{isolate}) {
1668 DXChannel::broadcast_nodes($line, $self) if $line =~ /\^H\d+\^?~?$/; # send it to everyone but me
1674 # This is called from inside the main cluster processing loop and is used
1675 # for despatching commands that are doing some long processing job
1680 my @dxchan = DXChannel::get_all();
1684 # send out a pc50 on EVERY channel all at once
1685 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
1686 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
1691 foreach $dxchan (@dxchan) {
1692 next unless $dxchan->is_node();
1693 next if $dxchan == $main::me;
1696 $dxchan->send($pc50s) if $pc50s;
1698 # send a ping out on this channel
1699 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
1700 if ($dxchan->{nopings} <= 0) {
1701 $dxchan->disconnect;
1703 addping($main::mycall, $dxchan->call);
1704 $dxchan->{nopings} -= 1;
1705 $dxchan->{lastping} = $t;
1710 Investigate::process();
1713 if ($t - $last10 >= 10) {
1714 # clean out ephemera
1723 if ($main::systime - 3600 > $last_hour) {
1724 $last_hour = $main::systime;
1729 # finish up a pc context
1733 # some active measures
1739 my ($self, $filter, $hops, $isolate, $line) = @_;
1745 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1747 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1748 return unless $routeit;
1751 $self->send($routeit);
1753 $self->send($routeit) unless $self->{isolate} || $isolate;
1762 my @dxchan = DXChannel::get_all();
1764 my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
1766 # send it if it isn't the except list and isn't isolated and still has a hop count
1767 # taking into account filtering and so on
1768 foreach $dxchan (@dxchan) {
1769 next if $dxchan == $main::me;
1770 next if $dxchan == $self && $self->is_node;
1772 my ($filter, $hops);
1774 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
1782 my $isolate = shift;
1783 my ($filter, $hops);
1785 if ($self->{wwvfilter}) {
1786 ($filter, $hops) = $self->{wwvfilter}->it(@_);
1787 return unless $filter;
1789 send_prot_line($self, $filter, $hops, $isolate, $line)
1796 my @dxchan = DXChannel::get_all();
1798 my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
1800 # send it if it isn't the except list and isn't isolated and still has a hop count
1801 # taking into account filtering and so on
1802 foreach $dxchan (@dxchan) {
1803 next if $dxchan == $main::me;
1804 next if $dxchan == $self;
1806 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
1814 my $isolate = shift;
1815 my ($filter, $hops);
1817 if ($self->{wcyfilter}) {
1818 ($filter, $hops) = $self->{wcyfilter}->it(@_);
1819 return unless $filter;
1821 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
1829 my @dxchan = DXChannel::get_all();
1833 my $text = unpad($_[2]);
1835 if ($_[3] eq '*') { # sysops
1837 } elsif ($_[3] gt ' ') { # speciality list handling
1838 my ($name) = split /\./, $_[3];
1839 $target = "$name"; # put the rest in later (if bothered)
1846 $target = "ALL" if !$target;
1849 # obtain country codes etc
1850 my @a = Prefix::cty_data($_[0]);
1851 my @b = Prefix::cty_data($_[4]);
1852 if ($self->{inannfilter}) {
1853 my ($filter, $hops) =
1854 $self->{inannfilter}->it(@_, $self->{call},
1856 @b[0..2], $a[3], $b[3]);
1858 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1863 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
1864 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1868 Log('ann', $target, $_[0], $text);
1870 # send it if it isn't the except list and isn't isolated and still has a hop count
1871 # taking into account filtering and so on
1872 foreach $dxchan (@dxchan) {
1873 next if $dxchan == $main::me;
1874 next if $dxchan == $self && $self->is_node;
1875 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
1876 @a[0..2], @b[0..2]);
1885 $msgid = 1 if $msgid > 999;
1894 my @dxchan = DXChannel::get_all();
1897 my $text = unpad($_[2]);
1900 # munge the group and recast the line if required
1901 if ($target =~ s/\.LST$//) {
1905 # obtain country codes etc
1906 my @a = Prefix::cty_data($_[0]);
1907 my @b = Prefix::cty_data($_[4]);
1908 if ($self->{inannfilter}) {
1909 my ($filter, $hops) =
1910 $self->{inannfilter}->it(@_, $self->{call},
1912 @b[0..2], $a[3], $b[3]);
1914 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1919 if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
1920 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1925 Log('chat', $target, $_[0], $text);
1927 # send it if it isn't the except list and isn't isolated and still has a hop count
1928 # taking into account filtering and so on
1929 foreach $dxchan (@dxchan) {
1930 my $is_ak1a = $dxchan->is_ak1a;
1932 if ($dxchan->is_node) {
1933 next if $dxchan == $main::me;
1934 next if $dxchan == $self;
1935 next unless $dxchan->is_spider || $is_ak1a;
1936 next if $target eq 'LOCAL';
1937 if (!$ak1a_line && $is_ak1a) {
1938 $ak1a_line = DXProt::pc12($_[0], $text, $_[1], "$target.LST");
1942 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1],
1943 $text, @_, $self->{call}, @a[0..2], @b[0..2]);
1951 my $isolate = shift;
1955 my ($filter, $hops);
1957 if ($self->{annfilter}) {
1958 ($filter, $hops) = $self->{annfilter}->it(@_);
1959 return unless $filter;
1961 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
1970 sub send_local_config
1978 dbg('DXProt::send_local_config') if isdbg('trace');
1981 if ($self->{isolate}) {
1982 @localnodes = ( $main::routeroot );
1983 $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
1985 # create a list of all the nodes that are not connected to this connection
1986 # and are not themselves isolated, this to make sure that isolated nodes
1987 # don't appear outside of this node
1989 # send locally connected nodes
1990 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && ($_->is_node || $_->is_aranea) } DXChannel::get_all();
1991 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
1992 $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
1995 my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
1997 for $node (@rawintcalls) {
1998 push @intcalls, $node unless grep $node eq $_, @intcalls;
2000 my $ref = Route::Node::get($self->{call});
2001 my @rnodes = $ref->nodes;
2002 for $node (@intcalls) {
2003 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
2005 $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
2008 # get all the users connected on the above nodes and send them out
2009 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
2011 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
2012 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
2014 dbg("sent a null value") if isdbg('chanerr');
2020 # route a message down an appropriate interface for a callsign
2022 # 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 dbg("route: $call -> $dxchan->{call} direct" ) if isdbg('route');
2039 my $cl = Route::get($call);
2040 $dxchan = $cl->dxchan if $cl;
2042 if (ref $self && $dxchan eq $self) {
2043 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
2046 dbg("route: $call -> $dxchan->{call} using normal route" ) if isdbg('route');
2050 # try the backstop method
2052 my $rcall = RouteDB::get($call);
2054 if ($self && $rcall eq $self->{call}) {
2055 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
2058 $dxchan = DXChannel::get($rcall);
2059 dbg("route: $call -> $rcall using RouteDB" ) if isdbg('route') && $dxchan;
2064 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
2066 $dxchan->send($routeit) unless $dxchan == $main::me;
2069 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
2074 # obtain the hops from the list for this callsign and pc no
2080 my $hops = $DXProt::hopcount{$pcno};
2081 $hops = $DXProt::def_hopcount if !$hops;
2086 # adjust the hop count on a per node basis using the user loadable
2087 # hop table if available or else decrement an existing one
2094 my $call = $self->{call};
2097 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
2098 my ($pcno) = $s =~ /^PC(\d\d)/o;
2099 confess "$call called adjust_hops with '$s'" unless $pcno;
2100 my $ref = $nodehops{$call} if %nodehops;
2102 my $newhops = $ref->{$pcno};
2103 return "" if defined $newhops && $newhops == 0;
2104 $newhops = $ref->{default} unless $newhops;
2105 return "" if defined $newhops && $newhops == 0;
2106 $newhops = $hops if !$newhops;
2107 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
2109 # simply decrement it
2110 # $hops--; this is done on receipt now
2111 return "" if !$hops;
2112 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
2124 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
2125 do "$main::data/hop_table.pl";
2131 # add a ping request to the ping queues
2134 my ($from, $to, $via) = @_;
2135 my $ref = $pings{$to} || [];
2138 $r->{t} = [ gettimeofday ];
2139 if ($via && (my $dxchan = DXChannel::get($via))) {
2140 $dxchan->send(pc51($to, $main::mycall, 1));
2142 route(undef, $to, pc51($to, $main::mycall, 1));
2146 my $u = DXUser->get_current($to);
2148 $u->lastping(($via || $from), $main::systime);
2155 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
2156 if ($tonode eq $main::mycall) {
2157 my $ref = DXUser->get_current($fromnode);
2158 my $cref = Route::Node::get($fromnode);
2159 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
2160 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
2161 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
2162 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
2163 my $oldpriv = $self->{priv};
2164 $self->{priv} = $ref->{priv}; # assume the user's privilege level
2165 my @in = (DXCommandmode::run_cmd($self, $cmd));
2166 $self->{priv} = $oldpriv;
2167 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
2168 delete $self->{remotecmd};
2170 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
2173 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
2176 my $ref = DXUser->get_current($tonode);
2177 if ($ref && $ref->is_clx) {
2178 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
2180 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
2185 sub process_rcmd_reply
2187 my ($self, $tonode, $fromnode, $user, $line) = @_;
2188 if ($tonode eq $main::mycall) {
2189 my $s = $rcmds{$fromnode};
2191 my $dxchan = DXChannel::get($s->{call});
2192 my $ref = $user eq $tonode ? $dxchan : (DXChannel::get($user) || $dxchan);
2193 $ref->send($line) if $ref;
2194 delete $rcmds{$fromnode} if !$dxchan;
2196 # send unsolicited ones to the sysop
2197 my $dxchan = DXChannel::get($main::myalias);
2198 $dxchan->send($line) if $dxchan;
2201 my $ref = DXUser->get_current($tonode);
2202 if ($ref && $ref->is_clx) {
2203 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
2205 $self->route($tonode, pc35($fromnode, $tonode, $line));
2214 my $fromnode = shift;
2219 Log('rcmd', 'out', $fromnode, $line);
2220 if ($self->is_clx) {
2221 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
2223 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
2228 # add a rcmd request to the rcmd queues
2231 my ($self, $to, $cmd) = @_;
2234 $r->{call} = $self->{call};
2235 $r->{t} = $main::systime;
2239 my $ref = Route::Node::get($to);
2240 my $dxchan = $ref->dxchan;
2241 if ($dxchan && $dxchan->is_clx) {
2242 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
2244 route(undef, $to, pc34($main::mycall, $to, $cmd));
2251 my $pc39flag = shift;
2252 my $call = $self->call;
2254 return if $self->{disconnecting}++;
2256 unless ($pc39flag && $pc39flag == 1) {
2257 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
2260 # get rid of any PC16/17/19
2261 eph_del_regex("^PC1[679]*$call");
2263 # do routing stuff, remove me from routing table
2264 my $node = Route::Node::get($call);
2267 @rout = $node->del($main::routeroot);
2269 # and all my ephemera as well
2272 eph_del_regex("^PC1[679].*$c");
2276 RouteDB::delete_interface($call);
2278 # remove them from the pc19list as well
2279 while (my ($k,$v) = each %pc19list) {
2280 my @l = grep {$_->[0] ne $call} @{$pc19list{$k}};
2282 $pc19list{$k} = \@l;
2284 delete $pc19list{$k};
2288 eph_del_regex("^PC1[679].*$k");
2291 # unbusy and stop and outgoing mail
2292 my $mref = DXMsg::get_busy($call);
2293 $mref->stop_msg($call) if $mref;
2295 # broadcast to all other nodes that all the nodes connected to via me are gone
2296 unless ($pc39flag && $pc39flag == 2) {
2297 my $thing = Thingy::Bye->new(user=>$call);
2298 $thing->broadcast($self);
2300 $self->route_pc21($main::mycall, undef, @rout) if @rout;
2303 # remove outstanding pings
2304 delete $pings{$call};
2306 # I was the last node visited
2307 $self->user->node($main::mycall);
2309 # send info to all logged in thingies
2310 $self->tell_login('logoutn');
2312 Log('DXProt', $call . " Disconnected");
2314 $self->SUPER::disconnect;
2319 # send a talk message to this thingy
2323 my ($self, $from, $to, $via, $line, $origin) = @_;
2325 $line =~ s/\^/\\5E/g; # remove any ^ characters
2326 $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
2327 Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
2330 # send it if it isn't the except list and isn't isolated and still has a hop count
2331 # taking into account filtering and so on
2337 my $generate = shift;
2338 my $no = shift; # the no of things to filter on
2340 my ($filter, $hops);
2343 for (; @_ && $no; $no--) {
2346 if (!$self->{isolate} && $self->{routefilter}) {
2349 ($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});
2353 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
2356 dbg("was sent a null value") if isdbg('chanerr');
2359 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
2363 foreach my $line (&$generate(@rin, @_)) {
2366 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
2368 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
2369 next unless $routeit;
2372 $self->send($routeit);
2381 my $generate = shift;
2383 my @dxchan = DXChannel::get_all_nodes();
2386 unless ($self->{isolate}) {
2387 foreach $dxchan (@dxchan) {
2388 next if $dxchan == $self;
2389 next if $dxchan == $main::me;
2390 next unless $dxchan->isa('DXProt');
2391 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
2393 $dxchan->send_route($origin, $generate, @_);
2401 return unless $self->user->wantpc16;
2404 broadcast_route($self, $origin, \&pc16, $line, 1, @_);
2410 return unless $self->user->wantpc16;
2413 broadcast_route($self, $origin, \&pc17, $line, 1, @_);
2421 broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
2429 broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
2437 broadcast_route($self, $origin, \&pc24, $line, 1, @_);
2445 broadcast_route($self, $origin, \&pc41, $line, 1, @_);
2453 broadcast_route($self, $origin, \&pc50, $line, 1, @_);
2460 my ($filter, $hops) = (1, 1);
2462 if ($self->{inroutefilter}) {
2463 ($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);
2464 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
2472 my $t = shift || $eph_restime;
2476 $s =~ s/\^H\d\d?\^?\~?$//;
2477 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
2478 $eph{$s} = $main::systime + $t;
2479 dbg("PCPROT: emphemeral duplicate") if $r && isdbg('chanerr');
2487 while (($key, $val) = each %eph) {
2488 if ($key =~ m{$regex}) {
2498 while (($key, $val) = each %eph) {
2499 if ($main::systime >= $val) {
2510 while (($key, $val) = each %eph) {
2511 push @out, $key, $val;
2518 goto &DXCommandmode::run_cmd;
2522 # import any msgs in the chat directory
2523 # the messages are sent to the chat group which forms the
2524 # the first part of the name (eg: solar.1243.txt would be
2525 # sent to chat group SOLAR)
2527 # Each message found is sent: one non-blank line to one chat
2528 # message. So 4 lines = 4 chat messages.
2530 # The special name LOCAL is for local users ANN
2531 # The special name ALL is for ANN/FULL
2532 # The special name SYSOP is for ANN/SYSOP
2536 # are there any to do in this directory?
2537 return unless -d $chatimportfn;
2538 unless (opendir(DIR, $chatimportfn)) {
2539 dbg("can\'t open $chatimportfn $!") if isdbg('msg');
2540 Log('msg', "can\'t open $chatimportfn $!");
2544 my @names = readdir(DIR);
2547 foreach $name (@names) {
2548 next if $name =~ /^\./;
2549 my $splitit = $name =~ /^split/;
2550 my $fn = "$chatimportfn/$name";
2552 unless (open(MSG, $fn)) {
2553 dbg("can\'t open import file $fn $!") if isdbg('msg');
2554 Log('msg', "can\'t open import file $fn $!");
2558 my @msg = map { s/\r?\n$//; $_ } <MSG>;
2562 my @cat = split /\./, $name;
2563 my $target = uc $cat[0];
2565 foreach my $text (@msg) {
2566 next unless $text && $text !~ /^\s*#/;
2567 if ($target eq 'ALL' || $target eq 'LOCAL' || $target eq 'SYSOP') {
2568 my $sysopflag = $target eq 'SYSOP' ? '*' : ' ';
2569 if ($target ne 'LOCAL') {
2570 send_announce($main::me, pc12($main::mycall, $text, '*', $sysopflag), $main::mycall, '*', $text, $sysopflag, $main::mycall, '0');
2572 Log('ann', 'LOCAL', $main::mycall, $text);
2573 DXChannel::broadcast_list("To LOCAL de ${main::mycall}: $text\a", 'ann', undef, DXCommandmode->get_all());
2576 my $msgid = nextchatmsgid();
2577 $text = "#$msgid $text";
2578 send_chat($main::me, pc12($main::mycall, $text, '*', $target), $main::mycall, '*', $text, $target, $main::mycall, '0');