3 # This module impliments the protocal mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
41 use vars qw($pc11_max_age $pc23_max_age $last_pc50 $eph_restime $eph_info_restime $eph_pc34_restime
42 $last_hour $last10 %eph %pings %rcmds $ann_to_talk
43 $pingint $obscount %pc19list $chatdupeage $chatimportfn
44 $investigation_int $pc19_version $myprot_version
45 %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
46 $allowzero $decode_dk0wcy $send_opernam @checklist
50 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
51 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
53 $last_hour = time; # last time I did an hourly periodic update
54 %rcmds = (); # outstanding rcmd requests outbound
55 %nodehops = (); # node specific hop control
56 %pc19list = (); # list of outstanding PC19s that haven't had PC16s on them
58 $censorpc = 1; # Do a BadWords::check on text fields and reject things
59 # loads of 'bad things'
60 $baddx = new DXHash "baddx";
61 $badspotter = new DXHash "badspotter";
62 $badnode = new DXHash "badnode";
63 $last10 = $last_pc50 = time;
67 $eph_info_restime = 60*60;
68 $eph_pc15_restime = 6*60;
69 $eph_pc34_restime = 30;
72 $chatdupeage = 20 * 60 * 60;
73 $chatimportfn = "$main::root/chat_import";
74 $investigation_int = 12*60*60; # time between checks to see if we can see this node
75 $pc19_version = 5466; # the visible version no for outgoing PC19s generated from pc59
79 [ qw(i c c m bp bc c) ], # pc10
80 [ qw(i f m d t m c c h) ], # pc11
81 [ qw(i c bm m bm bm p h) ], # pc12
85 undef , # pc16 has to be validated manually
86 [ qw(i c c h) ], # pc17
88 undef , # pc19 has to be validated manually
89 undef , # pc20 no validation
90 [ qw(i c m h) ], # pc21
91 undef , # pc22 no validation
92 [ qw(i d n n n n m c c h) ], # pc23
93 [ qw(i c p h) ], # pc24
94 [ qw(i c c n n) ], # pc25
95 [ qw(i f m d t m c c bc) ], # pc26
96 [ qw(i d n n n n m c c bc) ], # pc27
97 [ qw(i c c m c d t p m bp n p bp bc) ], # pc28
98 [ qw(i c c n m) ], # pc29
99 [ qw(i c c n) ], # pc30
100 [ qw(i c c n) ], # pc31
101 [ qw(i c c n) ], # pc32
102 [ qw(i c c n) ], # pc33
103 [ qw(i c c m) ], # pc34
104 [ qw(i c c m) ], # pc35
105 [ qw(i c c m) ], # pc36
106 [ qw(i c c n m) ], # pc37
107 undef, # pc38 not interested
108 [ qw(i c m) ], # pc39
109 [ qw(i c c m p n) ], # pc40
110 [ qw(i c n m h) ], # pc41
111 [ qw(i c c n) ], # pc42
112 undef, # pc43 don't handle it
113 [ qw(i c c n m m c) ], # pc44
114 [ qw(i c c n m) ], # pc45
115 [ qw(i c c n) ], # pc46
118 [ qw(i c m h) ], # pc49
119 [ qw(i c n h) ], # pc50
120 [ qw(i c c n) ], # pc51
142 [ qw(i d n n n n n n m m m c c h) ], # pc73
153 [ qw(i c c c m) ], # pc84
154 [ qw(i c c c m) ], # pc85
159 [ qw(i c n) ], # pc90
162 # use the entry in the check list to check the field list presented
163 # return OK if line NOT in check list (for now)
168 return 0 if $n < 0 || $n > @checklist;
169 my $ref = $checklist[$n];
170 return 0 unless ref $ref;
173 for ($i = 1; $i < @$ref; $i++) {
174 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
175 return 0 unless $act;
176 next if $blank && $_[$i] =~ /^[ \*]$/;
178 return $i unless is_callsign($_[$i]);
179 } elsif ($act eq 'i') {
181 } elsif ($act eq 'm') {
182 return $i unless is_pctext($_[$i]);
183 } elsif ($act eq 'p') {
184 return $i unless is_pcflag($_[$i]);
185 } elsif ($act eq 'f') {
186 return $i unless is_freq($_[$i]);
187 } elsif ($act eq 'n') {
188 return $i unless $_[$i] =~ /^[\d ]+$/;
189 } elsif ($act eq 'h') {
190 return $i unless $_[$i] =~ /^H\d\d?$/;
191 } elsif ($act eq 'd') {
192 return $i unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
193 } elsif ($act eq 't') {
194 return $i unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
202 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
205 my $user = DXUser->get($main::mycall);
206 die "User $main::mycall not setup or disappeared RTFM" unless $user;
208 $myprot_version += $main::version*100;
209 $main::me = DXProt->new($main::mycall, 0, $user);
210 $main::me->{here} = 1;
211 $main::me->{state} = "indifferent";
212 $main::me->{sort} = 'S'; # S for spider
213 $main::me->{priv} = 9;
214 $main::me->{metric} = 0;
215 $main::me->{pingave} = 0;
216 $main::me->{registered} = 1;
217 $main::me->{version} = $main::version;
218 $main::me->{build} = $main::build;
222 # obtain a new connection this is derived from dxchannel
227 my $self = DXChannel::alloc(@_);
229 # add this node to the table, the values get filled in later
233 # if we have an entry already, then send a PC21 to all connect
234 # old style connections, because we are about to get the real deal
235 if (my $ref = Route::Node::get($call)) {
236 dbg("ROUTE: $call is already in the routing table, deleting") if isdbg('route');
237 my @rout = $ref->delete;
238 $self->route_pc21($main::mycall, undef, @rout) if @rout;
240 $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
245 # this is how a pc connection starts (for an incoming connection)
246 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
247 # all the crap that comes between).
250 my ($self, $line, $sort) = @_;
251 my $call = $self->{call};
252 my $user = $self->{user};
255 my $host = $self->{conn}->{peerhost};
256 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
259 Log('DXProt', "$call connected from $host");
261 # remember type of connection
262 $self->{consort} = $line;
263 $self->{outbound} = $sort eq 'O';
264 my $priv = $user->priv;
265 $priv = $user->priv(1) unless $priv;
266 $self->{priv} = $priv; # other clusters can always be 'normal' users
267 $self->{lang} = $user->lang || 'en';
268 $self->{isolate} = $user->{isolate};
269 $self->{consort} = $line; # save the connection type
273 # sort out registration
274 $self->{registered} = 1;
276 # get the output filters
277 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
278 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
279 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
280 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
281 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
284 # get the INPUT filters (these only pertain to Clusters)
285 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
286 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
287 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
288 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
289 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
291 # set unbuffered and no echo
292 $self->send_now('B',"0");
293 $self->send_now('E',"0");
294 $self->conn->echo(0) if $self->conn->can('echo');
296 # ping neighbour node stuff
297 my $ping = $user->pingint;
298 $ping = $pingint unless defined $ping;
299 $self->{pingint} = $ping;
300 $self->{nopings} = $user->nopings || $obscount;
301 $self->{pingtime} = [ ];
302 $self->{pingave} = 999;
303 $self->{metric} ||= 100;
304 $self->{lastping} = $main::systime;
306 # send initialisation string
307 unless ($self->{outbound}) {
311 $self->state('init');
312 $self->{pc50_t} = $main::systime;
314 # send info to all logged in thingies
315 $self->tell_login('loginn');
317 # run a script send the output to the debug file
318 my $script = new Script(lc $call) || new Script('node_default');
319 $script->run($self) if $script;
323 # send outgoing 'challenge'
333 # This is the normal pcxx despatcher
337 my ($self, $line) = @_;
339 if ($line =~ '^<\w+\s' && $main::do_xml) {
340 DXXml::normal($self, $line);
344 my @field = split /\^/, $line;
345 return unless @field;
347 pop @field if $field[-1] eq '~';
349 # 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 <= 89) { # reject PC9x messages
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 my $origin = $self->{call};
368 my $sub = "handle_$pcno";
370 if ($self->can($sub)) {
371 $self->$sub($pcno, $line, $origin, @field);
373 $self->handle_default($pcno, $line, $origin, @field);
377 # incoming talk commands
386 return if $rspfcheck and !$self->rspfcheck(0, $_[6], $_[1]);
388 # will we allow it at all?
391 if (@bad = BadWords::check($_[3])) {
392 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
397 # is it for me or one of mine?
398 my ($from, $to, $via, $call, $dxchan);
407 # if this is a 'nodx' node then ignore it
408 if ($badnode->in($_[6]) || ($via && $badnode->in($via))) {
409 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
413 # if this is a 'bad spotter' user then ignore it
415 $nossid =~ s/-\d+$//;
416 if ($badspotter->in($nossid)) {
417 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
421 # if we are converting announces to talk is it a dup?
423 if (AnnTalk::is_talk_candidate($from, $_[3]) && AnnTalk::dup($from, $to, $_[3])) {
424 dbg("DXPROT: Dupe talk from announce, dropped") if isdbg('chanerr');
429 # remember a route to this node and also the node on which this user is
430 RouteDB::update($_[6], $self->{call});
431 # RouteDB::update($to, $_[6]);
433 # it is here and logged on
434 $dxchan = DXChannel::get($main::myalias) if $to eq $main::mycall;
435 $dxchan = DXChannel::get($to) unless $dxchan;
436 if ($dxchan && $dxchan->is_user) {
438 $dxchan->talk($from, $to, $via, $_[3]);
442 # is it elsewhere, visible on the cluster via the to address?
443 # note: this discards the via unless the to address is on
446 if ($ref = Route::get($to)) {
447 $vref = Route::Node::get($via) if $via;
448 $vref = undef unless $vref && grep $to eq $_, $vref->users;
449 $ref->dxchan->talk($from, $to, $vref ? $via : undef, $_[3], $_[6]);
453 # can we see an interface to send it down?
455 # not visible here, send a message of condolence
457 $ref = Route::get($from);
458 $vref = $ref = Route::Node::get($_[6]) unless $ref;
460 $dxchan = $ref->dxchan;
461 $dxchan->talk($main::mycall, $from, $vref ? $vref->call : undef, $dxchan->msg('talknh', $to) );
473 # route 'foreign' pc26s
475 if ($_[7] ne $main::mycall) {
476 $self->route($_[7], $line);
482 # return if $rspfcheck and !$self->rspfcheck(1, $_[7], $_[6]);
484 # is the spotted callsign blank? This should really be trapped earlier but it
485 # could break other protocol sentences. Also check for lower case characters.
486 if ($_[2] =~ /^\s*$/) {
487 dbg("PCPROT: blank callsign, dropped") if isdbg('chanerr');
490 if ($_[2] =~ /[a-z]/) {
491 dbg("PCPROT: lowercase characters, dropped") if isdbg('chanerr');
496 # if this is a 'nodx' node then ignore it
497 if ($badnode->in($_[7])) {
498 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
502 # if this is a 'bad spotter' user then ignore it
504 $nossid =~ s/-\d+$//;
505 if ($badspotter->in($nossid)) {
506 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
510 # convert the date to a unix date
511 my $d = cltounix($_[3], $_[4]);
512 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
513 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
514 dbg("PCPROT: Spot ignored, invalid date or out of range ($_[3] $_[4])\n") if isdbg('chanerr');
519 if ($baddx->in($_[2]) || BadWords::check($_[2]) || $_[2] =~ /COCK/) {
520 dbg("PCPROT: Bad DX spot, ignored") if isdbg('chanerr');
525 $_[5] =~ s/^\s+//; # take any leading blanks off
526 $_[2] = unpad($_[2]); # take off leading and trailing blanks from spotted callsign
527 if ($_[2] =~ /BUST\w*$/) {
528 dbg("PCPROT: useless 'BUSTED' spot") if isdbg('chanerr');
533 if (@bad = BadWords::check($_[5])) {
534 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
540 # RouteDB::update($_[7], $self->{call});
541 # RouteDB::update($_[6], $_[7]);
543 my @spot = Spot::prepare($_[1], $_[2], $d, $_[5], $nossid, $_[7]);
544 # global spot filtering on INPUT
545 if ($self->{inspotsfilter}) {
546 my ($filter, $hops) = $self->{inspotsfilter}->it(@spot);
548 dbg("PCPROT: Rejected by input spot filter") if isdbg('chanerr');
553 # this goes after the input filtering, but before the add
554 # so that if it is input filtered, it isn't added to the dup
555 # list. This allows it to come in from a "legitimate" source
556 if (Spot::dup(@spot[0..4,5])) {
557 dbg("PCPROT: Duplicate Spot ignored\n") if isdbg('chanerr');
565 # @spot at this point contains:-
566 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
567 # then spotted itu, spotted cq, spotters itu, spotters cq
568 # you should be able to route on any of these
571 # fix up qra locators of known users
572 my $user = DXUser->get_current($spot[4]);
574 my $qra = $user->qra;
575 unless ($qra && is_qra($qra)) {
576 my $lat = $user->lat;
577 my $long = $user->long;
578 if (defined $lat && defined $long) {
579 $user->qra(DXBearing::lltoqra($lat, $long));
584 # send a remote command to a distant cluster if it is visible and there is no
585 # qra locator and we havn't done it for a month.
587 unless ($user->qra) {
589 my $to = $user->homenode;
590 my $last = $user->lastoper || 0;
591 if ($send_opernam && $to && $to ne $main::mycall && $main::systime > $last + $DXUser::lastoperinterval && ($node = Route::Node::get($to)) ) {
592 my $cmd = "forward/opernam $spot[4]";
593 # send the rcmd but we aren't interested in the replies...
594 my $dxchan = $node->dxchan;
595 if ($dxchan && $dxchan->is_clx) {
596 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
598 route(undef, $to, pc34($main::mycall, $to, $cmd));
602 $node = Route::Node::get($to);
604 $dxchan = $node->dxchan;
605 if ($dxchan && $dxchan->is_clx) {
606 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
608 route(undef, $to, pc34($main::mycall, $to, $cmd));
612 $user->lastoper($main::systime);
621 $r = Local::spot($self, @spot);
623 # dbg("Local::spot1 error $@") if isdbg('local') if $@;
626 # DON'T be silly and send on PC26s!
627 return if $pcno == 26;
629 # send out the filtered spots
630 send_dx_spot($self, $line, @spot) if @spot;
641 # return if $rspfcheck and !$self->rspfcheck(1, $_[5], $_[1]);
643 # announce duplicate checking
644 $_[3] =~ s/^\s+//; # remove leading blanks
648 if (@bad = BadWords::check($_[3])) {
649 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
654 # if this is a 'nodx' node then ignore it
655 if ($badnode->in($_[5])) {
656 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
660 # if this is a 'bad spotter' user then ignore it
662 $nossid =~ s/-\d+$//;
663 if ($badspotter->in($nossid)) {
664 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
671 if ((($dxchan = DXChannel::get($_[2])) && $dxchan->is_user) || $_[4] =~ /^[\#\w.]+$/){
672 $self->send_chat($line, @_[1..6]);
673 } elsif ($_[2] eq '*' || $_[2] eq $main::mycall) {
676 # RouteDB::update($_[5], $self->{call});
677 # RouteDB::update($_[1], $_[5]);
679 # ignore something that looks like a chat line coming in with sysop
680 # flag - this is a kludge...
681 if ($_[3] =~ /^\#\d+ / && $_[4] eq '*') {
682 dbg('PCPROT: Probable chat rewrite, dropped') if isdbg('chanerr');
686 # here's a bit of fun, convert incoming ann with a callsign in the first word
687 # or one saying 'to <call>' to a talk if we can route to the recipient
689 my $call = AnnTalk::is_talk_candidate($_[1], $_[3]);
691 my $ref = Route::get($call);
693 $dxchan = $ref->dxchan;
694 $dxchan->talk($_[1], $call, undef, $_[3], $_[5]) if $dxchan != $self;
701 $self->send_announce($line, @_[1..6]);
703 $self->route($_[2], $line);
715 if (eph_dup($line, $eph_pc15_restime)) {
716 dbg("PCPROT: Ephemeral dup, dropped") if isdbg('chanerr');
718 unless ($self->{isolate}) {
719 DXChannel::broadcast_nodes($line, $self) if $line =~ /\^H\d+\^?~?$/; # send it to everyone but me
735 my $newline = "PC16^";
737 # dos I want users from this channel?
738 unless ($self->user->wantpc16) {
739 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
743 if ($ncall eq $main::mycall) {
744 dbg("PCPROT: trying to alter my config from outside!") if isdbg('chanerr');
747 if (DXChannel::get($ncall) && $ncall ne $self->{call}) {
748 dbg("PCPROT: trying to alter locally connected $ncall from $self->{call}, ignored") if isdbg('chanerr');
752 RouteDB::update($ncall, $self->{call});
754 # do we believe this call?
755 unless ($ncall eq $self->{call} || $self->is_believed($ncall)) {
756 if (my $ivp = Investigate::get($ncall, $self->{call})) {
757 $ivp->store_pcxx($pcno,$line,$origin,@_);
759 dbg("PCPROT: We don't believe $ncall on $self->{call}") if isdbg('chanerr');
764 if (eph_dup($line)) {
765 dbg("PCPROT: dup PC16 detected") if isdbg('chanerr');
769 my $parent = Route::Node::get($ncall);
771 # if there is a parent, proceed, otherwise if there is a latent PC19 in the PC19list,
772 # fix it up in the routing tables and issue it forth before the PC16
774 my $nl = $pc19list{$ncall};
776 if ($nl && @_ > 3) { # 3 because of the hop count!
778 # this is a new (remembered) node, now attach it to me if it isn't in filtered
779 # and we haven't disallowed it
780 my $user = DXUser->get_current($ncall);
782 $user = DXUser->new($ncall);
784 $user->priv(1); # I have relented and defaulted nodes
786 $user->homenode($ncall);
790 my $wantpc19 = $user->wantroutepc19;
791 if ($wantpc19 || !defined $wantpc19) {
792 my $new = Route->new($ncall); # throw away
793 if ($self->in_filter_route($new)) {
796 $parent = Route::Node::get($_->[0]);
797 $dxchan = $parent->dxchan if $parent;
798 if ($dxchan && $dxchan ne $self) {
799 dbg("PCPROT: PC19 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
803 my $r = $parent->add($ncall, $_->[1], $_->[2]);
804 push @nrout, $r unless @nrout;
807 $user->wantroutepc19(1) unless defined $wantpc19; # for now we work on the basis that pc16 = real route
808 $user->lastin($main::systime) unless DXChannel::get($ncall);
811 # route the pc19 - this will cause 'stuttering PC19s' for a while
812 $self->route_pc19($origin, $line, @nrout) if @nrout ;
813 $parent = Route::Node::get($ncall);
815 dbg("PCPROT: lost $ncall after sending PC19 for it?");
821 delete $pc19list{$ncall};
824 dbg("PCPROT: Node $ncall not in config") if isdbg('chanerr');
829 $dxchan = $parent->dxchan;
830 if ($dxchan && $dxchan ne $self) {
831 dbg("PCPROT: PC16 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
835 # input filter if required
836 return unless $self->in_filter_route($parent);
841 for ($i = 2; $i < $#_; $i++) {
842 my ($call, $conf, $here) = $_[$i] =~ /^(\S+) (\S) (\d)/o;
843 next unless $call && $conf && defined $here && is_callsign($call);
844 next if $call eq $main::mycall;
846 eph_del_regex("^PC17\\^$call\\^$ncall");
848 $conf = $conf eq '*';
850 # reject this if we think it is a node already
851 my $r = Route::Node::get($call);
852 my $u = DXUser->get_current($call) unless $r;
853 if ($r || ($u && $u->is_node)) {
854 dbg("PCPROT: $call is a node") if isdbg('chanerr');
858 $r = Route::User::get($call);
859 my $flags = Route::here($here)|Route::conf($conf);
862 my $au = $r->addparent($parent);
863 if ($r->flags != $flags) {
867 push @rout, $r if $au;
869 push @rout, $parent->add_user($call, $flags);
872 # send info to all logged in thingies
873 $self->tell_login('loginu', "$ncall: $call") if DXUser->get_current($ncall)->is_local_node;
874 $self->tell_buddies('loginb', $call, $ncall);
876 # add this station to the user database, if required
877 # $call =~ s/-\d+$//o; # remove ssid for users
878 my $user = DXUser->get_current($call);
879 $user = DXUser->new($call) if !$user;
880 $user->homenode($parent->call) if !$user->homenode;
881 $user->node($parent->call);
882 $user->lastin($main::systime) unless DXChannel::get($call);
885 $self->route_pc16($origin, $line, $parent, @rout) if @rout;
899 eph_del_regex("^PC16\\^$ncall.*$ucall");
901 # do I want users from this channel?
902 unless ($self->user->wantpc16) {
903 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
906 if ($ncall eq $main::mycall) {
907 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
911 RouteDB::delete($ncall, $self->{call});
913 # do we believe this call?
914 unless ($ncall eq $self->{call} || $self->is_believed($ncall)) {
915 if (my $ivp = Investigate::get($ncall, $self->{call})) {
916 $ivp->store_pcxx($pcno,$line,$origin,@_);
918 dbg("PCPROT: We don't believe $ncall on $self->{call}") if isdbg('chanerr');
923 my $uref = Route::User::get($ucall);
925 dbg("PCPROT: Route::User $ucall not in config") if isdbg('chanerr');
928 my $parent = Route::Node::get($ncall);
930 dbg("PCPROT: Route::Node $ncall not in config") if isdbg('chanerr');
934 $dxchan = DXChannel::get($ncall);
935 if ($dxchan && $dxchan ne $self) {
936 dbg("PCPROT: PC17 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
940 # input filter if required and then remove user if present
941 # return unless $self->in_filter_route($parent);
942 $parent->del_user($uref);
944 # send info to all logged in thingies
945 $self->tell_login('logoutu', "$ncall: $ucall") if DXUser->get_current($ncall)->is_local_node;
946 $self->tell_buddies('logoutb', $ucall, $ncall);
948 if (eph_dup($line)) {
949 dbg("PCPROT: dup PC17 detected") if isdbg('chanerr');
953 $self->route_pc17($origin, $line, $parent, $uref);
963 $self->state('init');
965 # record the type and version offered
966 if ($_[1] =~ /DXSpider Version: (\d+\.\d+) Build: (\d+(?:\.\d+)?)/) {
967 $self->version(53 + $1);
968 $self->user->version(53 + $1);
969 $self->build(0 + $2);
970 $self->user->build(0 + $2);
971 unless ($self->is_spider) {
972 $self->user->sort('S');
976 $self->{handle_xml}++ if DXXml::available() && $_[1] =~ /\bxml\b/;
978 $self->version(50.0);
979 $self->version($_[2] / 100) if $_[2] && $_[2] =~ /^\d+$/;
980 $self->user->version($self->version);
983 # first clear out any nodes on this dxchannel
984 my $parent = Route::Node::get($self->{call});
985 my @rout = $parent->del_nodes;
986 $self->route_pc21($origin, $line, @rout, $parent) if @rout;
987 $self->send_local_config();
991 # incoming cluster list
1000 my $newline = "PC19^";
1005 # first get the INTERFACE node
1006 my $parent = Route::Node::get($self->{call});
1008 dbg("DXPROT: my parent $self->{call} has disappeared");
1013 # if the origin isn't the same as the INTERFACE, then reparent, creating nodes as necessary
1014 if ($origin ne $self->call) {
1015 my $op = Route::Node::get($origin);
1017 $op = $parent->add($origin, 5000, Route::here(1));
1018 my $user = DXUser->get_current($origin);
1020 $user = DXUser->new($origin);
1021 $user->priv(1); # I have relented and defaulted nodes
1023 $user->homenode($origin);
1024 $user->node($origin);
1025 $user->wantroutepc19(1);
1027 $user->sort('A') unless $user->is_node;
1034 for ($i = 1; $i < $#_-1; $i += 4) {
1036 my $call = uc $_[$i+1];
1037 my $conf = $_[$i+2];
1039 next unless defined $here && defined $conf && is_callsign($call);
1041 eph_del_regex("^PC(?:21\\^$call|17\\^[^\\^]+\\^$call)");
1043 # check for sane parameters
1044 # $ver = 5000 if $ver eq '0000';
1045 next unless $ver && $ver =~ /^\d+$/;
1046 next if $ver < 5000; # only works with version 5 software
1047 next if length $call < 3; # min 3 letter callsigns
1048 next if $call eq $main::mycall;
1050 # check that this PC19 isn't trying to alter the wrong dxchan
1051 my $dxchan = DXChannel::get($call);
1052 if ($dxchan && $dxchan != $self) {
1053 dbg("PCPROT: PC19 from $self->{call} trying to alter wrong locally connected $call, ignored!") if isdbg('chanerr');
1057 # add this station to the user database, if required (don't remove SSID from nodes)
1058 my $user = DXUser->get_current($call);
1060 $user = DXUser->new($call);
1061 $user->priv(1); # I have relented and defaulted nodes
1063 $user->homenode($call);
1066 $user->sort('A') unless $user->is_node;
1068 RouteDB::update($call, $self->{call});
1070 # do we believe this call?
1071 my $genline = "PC19^$here^$call^$conf^$ver^$_[-1]^";
1072 unless ($call eq $self->{call} || $self->is_believed($call)) {
1073 my $pt = $user->lastping($self->{call}) || 0;
1074 if ($pt+$investigation_int < $main::systime && !Investigate::get($call, $self->{call})) {
1075 my $ivp = Investigate->new($call, $self->{call});
1076 $ivp->version($ver);
1078 $ivp->store_pcxx($pcno,$genline,$origin,'PC19',$here,$call,$conf,$ver,$_[-1]);
1080 dbg("PCPROT: We don't believe $call on $self->{call}") if isdbg('chanerr');
1086 if (eph_dup($genline)) {
1087 dbg("PCPROT: dup PC19 for $call detected") if isdbg('chanerr');
1091 my $r = Route::Node::get($call);
1092 my $flags = Route::here($here)|Route::conf($conf);
1094 # modify the routing table if it is in it, otherwise store it in the pc19list for now
1097 if ($call ne $parent->call) {
1098 if ($self->in_filter_route($r)) {
1099 $ar = $parent->add($call, $ver, $flags);
1100 push @rout, $ar if $ar;
1105 if ($r->version ne $ver || $r->flags != $flags) {
1108 push @rout, $r unless $ar;
1112 # if he is directly connected or allowed then add him, otherwise store him up for later
1113 if ($call eq $self->{call} || $user->wantroutepc19) {
1114 my $new = Route->new($call); # throw away
1115 if ($self->in_filter_route($new)) {
1116 my $ar = $parent->add($call, $ver, $flags);
1117 $user->wantroutepc19(1) unless defined $user->wantroutepc19;
1118 push @rout, $ar if $ar;
1123 $pc19list{$call} = [] unless exists $pc19list{$call};
1124 my $nl = $pc19list{$call};
1125 push @{$pc19list{$call}}, [$self->{call}, $ver, $flags] unless grep $_->[0] eq $self->{call}, @$nl;
1129 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
1130 my $mref = DXMsg::get_busy($call);
1131 $mref->stop_msg($call) if $mref;
1133 $user->lastin($main::systime) unless DXChannel::get($call);
1138 $self->route_pc19($origin, $line, @rout) if @rout;
1141 # send local configuration
1148 $self->send_local_config();
1149 $self->send(pc22());
1150 $self->state('normal');
1151 $self->{lastping} = 0;
1154 # delete a cluster from the list
1161 my $call = uc $_[1];
1163 eph_del_regex("^PC1[679].*$call");
1165 # if I get a PC21 from the same callsign as self then treat it
1166 # as a PC39: I have gone away
1167 if ($call eq $self->call) {
1168 $self->disconnect(1);
1172 RouteDB::delete($call, $self->{call});
1174 # check if we believe this
1175 unless ($call eq $self->{call} || $self->is_believed($call)) {
1176 if (my $ivp = Investigate::get($call, $self->{call})) {
1177 $ivp->store_pcxx($pcno,$line,$origin,@_);
1179 dbg("PCPROT: We don't believe $call on $self->{call}") if isdbg('chanerr');
1184 # check to see if we are in the pc19list, if we are then don't bother with any of
1185 # this routing table manipulation, just remove it from the list and dump it
1187 if (my $nl = $pc19list{$call}) {
1188 $pc19list{$call} = [ grep {$_->[0] ne $self->{call}} @$nl ];
1189 delete $pc19list{$call} unless @{$pc19list{$call}};
1192 my $parent = Route::Node::get($self->{call});
1194 dbg("DXPROT: my parent $self->{call} has disappeared");
1198 if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
1199 my $node = Route::Node::get($call);
1202 my $dxchan = DXChannel::get($call);
1203 if ($dxchan && $dxchan != $self) {
1204 dbg("PCPROT: PC21 from $self->{call} trying to alter locally connected $call, ignored!") if isdbg('chanerr');
1209 return unless $self->in_filter_route($node);
1212 push @rout, $node->del($parent);
1215 dbg("PCPROT: I WILL _NOT_ be disconnected!") if isdbg('chanerr');
1220 $self->route_pc21($origin, $line, @rout) if @rout;
1230 $self->state('normal');
1231 $self->{lastping} = 0;
1242 # route foreign' pc27s
1244 if ($_[8] ne $main::mycall) {
1245 $self->route($_[8], $line);
1250 # only do a rspf check on PC23 (not 27)
1252 return if $rspfcheck and !$self->rspfcheck(1, $_[8], $_[7])
1256 my $d = cltounix($_[1], sprintf("%02d18Z", $_[2]));
1257 my $sfi = unpad($_[3]);
1258 my $k = unpad($_[4]);
1259 my $i = unpad($_[5]);
1260 my ($r) = $_[6] =~ /R=(\d+)/;
1262 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1263 dbg("PCPROT: WWV Date ($_[1] $_[2]) out of range") if isdbg('chanerr');
1267 # global wwv filtering on INPUT
1268 my @dxcc = ((Prefix::cty_data($_[7]))[0..2], (Prefix::cty_data($_[8]))[0..2]);
1269 if ($self->{inwwvfilter}) {
1270 my ($filter, $hops) = $self->{inwwvfilter}->it(@_[7,8], $origin, @dxcc);
1272 dbg("PCPROT: Rejected by input wwv filter") if isdbg('chanerr');
1276 $_[7] =~ s/-\d+$//o; # remove spotter's ssid
1277 if (Geomag::dup($d,$sfi,$k,$i,$_[6],$_[7])) {
1278 dbg("PCPROT: Dup WWV Spot ignored\n") if isdbg('chanerr');
1282 # note this only takes the first one it gets
1283 Geomag::update($d, $_[2], $sfi, $k, $i, @_[6..8], $r);
1287 $rep = Local::wwv($self, $_[1], $_[2], $sfi, $k, $i, @_[6..8], $r);
1289 # dbg("Local::wwv2 error $@") if isdbg('local') if $@;
1292 # DON'T be silly and send on PC27s!
1293 return if $pcno == 27;
1295 # broadcast to the eager world
1296 send_wwv_spot($self, $line, $d, $_[2], $sfi, $k, $i, @_[6..8]);
1306 my $call = uc $_[1];
1308 $nref = Route::Node::get($call);
1309 $uref = Route::User::get($call);
1310 return unless $nref || $uref; # if we don't know where they are, it's pointless sending it on
1312 if (eph_dup($line)) {
1313 dbg("PCPROT: Dup PC24 ignored\n") if isdbg('chanerr');
1317 $nref->here($_[2]) if $nref;
1318 $uref->here($_[2]) if $uref;
1319 my $ref = $nref || $uref;
1320 return unless $self->in_filter_route($ref);
1322 $self->route_pc24($origin, $line, $ref, $_[3]);
1332 if ($_[1] ne $main::mycall) {
1333 $self->route($_[1], $line);
1336 if ($_[2] eq $main::mycall) {
1337 dbg("PCPROT: Trying to merge to myself, ignored") if isdbg('chanerr');
1341 Log('DXProt', "Merge request for $_[3] spots and $_[4] WWV from $_[2]");
1345 my @in = reverse Spot::search(1, undef, undef, 0, $_[3]);
1348 $self->send(pc26(@{$in}[0..4], $_[2]));
1354 my @in = reverse Geomag::search(0, $_[4], time, 1);
1357 $self->send(pc27(@{$in}[0..5], $_[2]));
1362 sub handle_26 {goto &handle_11}
1363 sub handle_27 {goto &handle_23}
1365 # mail/file handling
1372 if ($_[1] eq $main::mycall) {
1374 my $sub = "DXMsg::handle_$pcno";
1377 $self->route($_[1], $line) unless $self->is_clx;
1381 sub handle_29 {goto &handle_28}
1382 sub handle_30 {goto &handle_28}
1383 sub handle_31 {goto &handle_28}
1384 sub handle_32 {goto &handle_28}
1385 sub handle_33 {goto &handle_28}
1393 if (eph_dup($line, $eph_pc34_restime)) {
1394 dbg("PCPROT: dupe PC34, ignored") if isdbg('chanerr');
1396 $self->process_rcmd($_[1], $_[2], $_[2], $_[3]);
1400 # remote command replies
1407 eph_del_regex("^PC35\\^$_[2]\\^$_[1]\\^");
1408 $self->process_rcmd_reply($_[1], $_[2], $_[1], $_[3]);
1411 sub handle_36 {goto &handle_34}
1420 if ($_[1] eq $main::mycall) {
1422 my $sub = "DXDb::handle_$pcno";
1425 $self->route($_[1], $line) unless $self->is_clx;
1429 # node connected list from neighbour
1438 # incoming disconnect
1445 if ($_[1] eq $self->{call}) {
1446 $self->disconnect(1);
1448 dbg("PCPROT: came in on wrong channel") if isdbg('chanerr');
1452 sub handle_40 {goto &handle_28}
1464 $l =~ s/[\x00-\x20\x7f-\xff]+//g; # remove all funny characters and spaces for dup checking
1465 if (eph_dup($l, $eph_info_restime)) {
1466 dbg("PCPROT: dup PC41, ignored") if isdbg('chanerr');
1470 # input filter if required
1471 # my $ref = Route::get($call) || Route->new($call);
1472 # return unless $self->in_filter_route($ref);
1474 if ($_[3] eq $_[2] || $_[3] =~ /^\s*$/) {
1475 dbg('PCPROT: invalid value') if isdbg('chanerr');
1479 # add this station to the user database, if required
1480 my $user = DXUser->get_current($call);
1481 $user = DXUser->new($call) unless $user;
1484 if (($_[3] =~ /spotter/i || $_[3] =~ /self/i) && $user->name && $user->name ne $_[3]) {
1485 dbg("PCPROT: invalid name") if isdbg('chanerr');
1489 } elsif ($_[2] == 2) {
1491 } elsif ($_[2] == 3) {
1492 if (is_latlong($_[3])) {
1493 my ($lat, $long) = DXBearing::stoll($_[3]);
1496 $user->qra(DXBearing::lltoqra($lat, $long));
1498 dbg('PCPROT: not a valid lat/long') if isdbg('chanerr');
1501 } elsif ($_[2] == 4) {
1502 $user->homenode($_[3]);
1503 } elsif ($_[2] == 5) {
1504 if (is_qra(uc $_[3])) {
1505 my ($lat, $long) = DXBearing::qratoll(uc $_[3]);
1508 $user->qra(uc $_[3]);
1510 dbg('PCPROT: not a valid QRA locator') if isdbg('chanerr');
1514 $user->lastoper($main::systime); # to cut down on excessive for/opers being generated
1517 unless ($self->{isolate}) {
1518 DXChannel::broadcast_nodes($line, $self); # send it to everyone but me
1521 # perhaps this IS what we want after all
1522 # $self->route_pc41($ref, $call, $_[2], $_[3], $_[4]);
1525 sub handle_42 {goto &handle_28}
1529 sub handle_44 {goto &handle_37}
1530 sub handle_45 {goto &handle_37}
1531 sub handle_46 {goto &handle_37}
1532 sub handle_47 {goto &handle_37}
1533 sub handle_48 {goto &handle_37}
1535 # message and database
1543 if (eph_dup($line)) {
1544 dbg("PCPROT: Dup PC49 ignored\n") if isdbg('chanerr');
1548 if ($_[1] eq $main::mycall) {
1549 DXMsg::handle_49($self, @_);
1551 $self->route($_[1], $line) unless $self->is_clx;
1555 # keep alive/user list
1565 RouteDB::update($call, $self->{call});
1567 my $node = Route::Node::get($call);
1569 return unless $node->call eq $self->{call};
1570 $node->usercount($_[2]);
1572 # input filter if required
1573 return unless $self->in_filter_route($node);
1575 $self->route_pc50($origin, $line, $node, $_[2], $_[3]) unless eph_dup($line);
1579 # incoming ping requests/answers
1592 if ($to eq $main::mycall) {
1594 $self->send(pc51($from, $to, '0'));
1596 DXXml::Ping::handle_ping_reply($self, $from);
1600 RouteDB::update($from, $self->{call});
1602 if (eph_dup($line)) {
1603 dbg("PCPROT: dup PC51 detected") if isdbg('chanerr');
1606 # route down an appropriate thingy
1607 $self->route($to, $line);
1611 # dunno but route it
1619 if ($call ne $main::mycall) {
1620 $self->route($call, $line);
1634 my $d = cltounix($call, sprintf("%02d18Z", $_[2]));
1635 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1636 dbg("PCPROT: WCY Date ($call $_[2]) out of range") if isdbg('chanerr');
1639 @_ = map { unpad($_) } @_;
1641 dbg("PCPROT: Dup WCY Spot ignored\n") if isdbg('chanerr');
1645 my $wcy = WCY::update($d, @_[2..12]);
1649 $rep = Local::wcy($self, @_[1..12]);
1651 # dbg("Local::wcy error $@") if isdbg('local') if $@;
1654 # broadcast to the eager world
1655 send_wcy_spot($self, $line, $d, @_[2..12]);
1658 # remote commands (incoming)
1665 $self->process_rcmd($_[1], $_[2], $_[3], $_[4]);
1668 # remote command replies
1675 $self->process_rcmd_reply($_[1], $_[2], $_[3], $_[4]);
1678 # if get here then rebroadcast the thing with its Hop count decremented (if
1679 # there is one). If it has a hop count and it decrements to zero then don't
1682 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
1693 if (eph_dup($line)) {
1694 dbg("PCPROT: Ephemeral dup, dropped") if isdbg('chanerr');
1696 unless ($self->{isolate}) {
1697 DXChannel::broadcast_nodes($line, $self) if $line =~ /\^H\d+\^?~?$/; # send it to everyone but me
1703 # This is called from inside the main cluster processing loop and is used
1704 # for despatching commands that are doing some long processing job
1709 my @dxchan = DXChannel::get_all();
1713 # send out a pc50 on EVERY channel all at once
1714 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
1715 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
1720 foreach $dxchan (@dxchan) {
1721 next unless $dxchan->is_node;
1722 next if $dxchan->handle_xml;
1723 next if $dxchan == $main::me;
1726 $dxchan->send($pc50s) if $pc50s;
1728 # send a ping out on this channel
1729 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
1730 if ($dxchan->{nopings} <= 0) {
1731 $dxchan->disconnect;
1733 DXXml::Ping::add($main::me, $dxchan->call);
1734 $dxchan->{nopings} -= 1;
1735 $dxchan->{lastping} = $t;
1736 $dxchan->{lastping} += $dxchan->{pingint} / 2 unless @{$dxchan->{pingtime}};
1741 Investigate::process();
1744 if ($t - $last10 >= 10) {
1745 # clean out ephemera
1754 if ($main::systime - 3600 > $last_hour) {
1755 $last_hour = $main::systime;
1760 # finish up a pc context
1764 # some active measures
1772 my @dxchan = DXChannel::get_all();
1775 # send it if it isn't the except list and isn't isolated and still has a hop count
1776 # taking into account filtering and so on
1777 foreach $dxchan (@dxchan) {
1778 next if $dxchan == $main::me;
1779 next if $dxchan == $self && $self->is_node;
1780 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
1788 my $isolate = shift;
1789 my ($filter, $hops);
1791 if ($self->{spotsfilter}) {
1792 ($filter, $hops) = $self->{spotsfilter}->it(@_);
1793 return unless $filter;
1795 send_prot_line($self, $filter, $hops, $isolate, $line);
1800 my ($self, $filter, $hops, $isolate, $line) = @_;
1806 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1808 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1809 return unless $routeit;
1812 $self->send($routeit);
1814 $self->send($routeit) unless $self->{isolate} || $isolate;
1823 my @dxchan = DXChannel::get_all();
1825 my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
1827 # send it if it isn't the except list and isn't isolated and still has a hop count
1828 # taking into account filtering and so on
1829 foreach $dxchan (@dxchan) {
1830 next if $dxchan == $main::me;
1831 next if $dxchan == $self && $self->is_node;
1833 my ($filter, $hops);
1835 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
1843 my $isolate = shift;
1844 my ($filter, $hops);
1846 if ($self->{wwvfilter}) {
1847 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_]);
1848 return unless $filter;
1850 send_prot_line($self, $filter, $hops, $isolate, $line)
1857 my @dxchan = DXChannel::get_all();
1859 my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
1861 # send it if it isn't the except list and isn't isolated and still has a hop count
1862 # taking into account filtering and so on
1863 foreach $dxchan (@dxchan) {
1864 next if $dxchan == $main::me;
1865 next if $dxchan == $self;
1867 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
1875 my $isolate = shift;
1876 my ($filter, $hops);
1878 if ($self->{wcyfilter}) {
1879 ($filter, $hops) = $self->{wcyfilter}->it(@_);
1880 return unless $filter;
1882 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
1890 my @dxchan = DXChannel::get_all();
1894 my $text = unpad($_[2]);
1896 if ($_[3] eq '*') { # sysops
1898 } elsif ($_[3] gt ' ') { # speciality list handling
1899 my ($name) = split /\./, $_[3];
1900 $target = "$name"; # put the rest in later (if bothered)
1907 $target = "ALL" if !$target;
1910 # obtain country codes etc
1911 my @a = Prefix::cty_data($_[0]);
1912 my @b = Prefix::cty_data($_[4]);
1913 if ($self->{inannfilter}) {
1914 my ($filter, $hops) =
1915 $self->{inannfilter}->it(@_, $self->{call},
1917 @b[0..2], $a[3], $b[3]);
1919 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1924 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
1925 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1929 Log('ann', $target, $_[0], $text);
1931 # send it if it isn't the except list and isn't isolated and still has a hop count
1932 # taking into account filtering and so on
1933 foreach $dxchan (@dxchan) {
1934 next if $dxchan == $main::me;
1935 next if $dxchan == $self && $self->is_node;
1936 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
1937 @a[0..2], @b[0..2]);
1946 $msgid = 1 if $msgid > 999;
1955 my @dxchan = DXChannel::get_all();
1958 my $text = unpad($_[2]);
1961 # munge the group and recast the line if required
1962 if ($target =~ s/\.LST$//) {
1966 # obtain country codes etc
1967 my @a = Prefix::cty_data($_[0]);
1968 my @b = Prefix::cty_data($_[4]);
1969 if ($self->{inannfilter}) {
1970 my ($filter, $hops) =
1971 $self->{inannfilter}->it(@_, $self->{call},
1973 @b[0..2], $a[3], $b[3]);
1975 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1980 if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
1981 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1986 Log('chat', $target, $_[0], $text);
1988 # send it if it isn't the except list and isn't isolated and still has a hop count
1989 # taking into account filtering and so on
1990 foreach $dxchan (@dxchan) {
1991 my $is_ak1a = $dxchan->is_ak1a;
1993 if ($dxchan->is_node) {
1994 next if $dxchan == $main::me;
1995 next if $dxchan == $self;
1996 next unless $dxchan->is_spider || $is_ak1a;
1997 next if $target eq 'LOCAL';
1998 if (!$ak1a_line && $is_ak1a) {
1999 $ak1a_line = DXProt::pc12($_[0], $text, $_[1], "$target.LST");
2003 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1],
2004 $text, @_, $self->{call}, @a[0..2], @b[0..2]);
2012 my $isolate = shift;
2016 my ($filter, $hops);
2018 if ($self->{annfilter}) {
2019 ($filter, $hops) = $self->{annfilter}->it(@_);
2020 return unless $filter;
2022 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
2031 sub send_local_config
2039 dbg('DXProt::send_local_config') if isdbg('trace');
2042 if ($self->{isolate}) {
2043 @localnodes = ( $main::routeroot );
2044 $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
2046 # create a list of all the nodes that are not connected to this connection
2047 # and are not themselves isolated, this to make sure that isolated nodes
2048 # don't appear outside of this node
2050 # send locally connected nodes
2051 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
2052 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
2053 $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
2056 my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
2058 for $node (@rawintcalls) {
2059 push @intcalls, $node unless grep $node eq $_, @intcalls;
2061 my $ref = Route::Node::get($self->{call});
2062 my @rnodes = $ref->nodes;
2063 for $node (@intcalls) {
2064 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
2066 $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
2069 # get all the users connected on the above nodes and send them out
2070 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
2072 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
2073 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
2075 dbg("sent a null value") if isdbg('chanerr');
2081 # route a message down an appropriate interface for a callsign
2083 # is called route(to, pcline);
2088 my ($self, $call, $line) = @_;
2090 if (ref $self && $call eq $self->{call}) {
2091 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
2095 # always send it down the local interface if available
2096 my $dxchan = DXChannel::get($call);
2098 dbg("route: $call -> $dxchan->{call} direct" ) if isdbg('route');
2100 my $cl = Route::get($call);
2101 $dxchan = $cl->dxchan if $cl;
2103 if (ref $self && $dxchan eq $self) {
2104 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
2107 dbg("route: $call -> $dxchan->{call} using normal route" ) if isdbg('route');
2111 # try the backstop method
2113 my $rcall = RouteDB::get($call);
2115 if ($self && $rcall eq $self->{call}) {
2116 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
2119 $dxchan = DXChannel::get($rcall);
2120 dbg("route: $call -> $rcall using RouteDB" ) if isdbg('route') && $dxchan;
2125 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
2127 $dxchan->send($routeit) unless $dxchan == $main::me;
2130 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
2135 # obtain the hops from the list for this callsign and pc no
2141 my $hops = $DXProt::hopcount{$pcno};
2142 $hops = $DXProt::def_hopcount if !$hops;
2147 # adjust the hop count on a per node basis using the user loadable
2148 # hop table if available or else decrement an existing one
2155 my $call = $self->{call};
2158 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
2159 my ($pcno) = $s =~ /^PC(\d\d)/o;
2160 confess "$call called adjust_hops with '$s'" unless $pcno;
2161 my $ref = $nodehops{$call} if %nodehops;
2163 my $newhops = $ref->{$pcno};
2164 return "" if defined $newhops && $newhops == 0;
2165 $newhops = $ref->{default} unless $newhops;
2166 return "" if defined $newhops && $newhops == 0;
2167 $newhops = $hops if !$newhops;
2168 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
2170 # simply decrement it
2172 return "" if !$hops;
2173 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
2185 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
2186 do "$main::data/hop_table.pl";
2193 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
2194 if ($tonode eq $main::mycall) {
2195 my $ref = DXUser->get_current($fromnode);
2196 my $cref = Route::Node::get($fromnode);
2197 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
2198 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
2199 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
2200 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
2201 my $oldpriv = $self->{priv};
2202 $self->{priv} = $ref->{priv}; # assume the user's privilege level
2203 my @in = (DXCommandmode::run_cmd($self, $cmd));
2204 $self->{priv} = $oldpriv;
2205 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
2206 delete $self->{remotecmd};
2208 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
2211 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
2214 my $ref = DXUser->get_current($tonode);
2215 if ($ref && $ref->is_clx) {
2216 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
2218 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
2223 sub process_rcmd_reply
2225 my ($self, $tonode, $fromnode, $user, $line) = @_;
2226 if ($tonode eq $main::mycall) {
2227 my $s = $rcmds{$fromnode};
2229 my $dxchan = DXChannel::get($s->{call});
2230 my $ref = $user eq $tonode ? $dxchan : (DXChannel::get($user) || $dxchan);
2231 $ref->send($line) if $ref;
2232 delete $rcmds{$fromnode} if !$dxchan;
2234 # send unsolicited ones to the sysop
2235 my $dxchan = DXChannel::get($main::myalias);
2236 $dxchan->send($line) if $dxchan;
2239 my $ref = DXUser->get_current($tonode);
2240 if ($ref && $ref->is_clx) {
2241 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
2243 $self->route($tonode, pc35($fromnode, $tonode, $line));
2252 my $fromnode = shift;
2257 Log('rcmd', 'out', $fromnode, $line);
2258 if ($self->is_clx) {
2259 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
2261 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
2266 # add a rcmd request to the rcmd queues
2269 my ($self, $to, $cmd) = @_;
2272 $r->{call} = $self->{call};
2273 $r->{t} = $main::systime;
2277 my $ref = Route::Node::get($to);
2278 my $dxchan = $ref->dxchan;
2279 if ($dxchan && $dxchan->is_clx) {
2280 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
2282 route(undef, $to, pc34($main::mycall, $to, $cmd));
2289 my $pc39flag = shift;
2290 my $call = $self->call;
2292 return if $self->{disconnecting}++;
2294 unless ($pc39flag && $pc39flag == 1) {
2295 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
2298 # get rid of any PC16/17/19
2299 eph_del_regex("^PC1[679]*$call");
2301 # do routing stuff, remove me from routing table
2302 my $node = Route::Node::get($call);
2305 @rout = $node->del($main::routeroot);
2307 # and all my ephemera as well
2310 eph_del_regex("^PC1[679].*$c");
2314 RouteDB::delete_interface($call);
2316 # remove them from the pc19list as well
2317 while (my ($k,$v) = each %pc19list) {
2318 my @l = grep {$_->[0] ne $call} @{$pc19list{$k}};
2320 $pc19list{$k} = \@l;
2322 delete $pc19list{$k};
2326 eph_del_regex("^PC1[679].*$k");
2329 # unbusy and stop and outgoing mail
2330 my $mref = DXMsg::get_busy($call);
2331 $mref->stop_msg($call) if $mref;
2333 # broadcast to all other nodes that all the nodes connected to via me are gone
2334 unless ($pc39flag && $pc39flag == 2) {
2335 $self->route_pc21($main::mycall, undef, @rout) if @rout;
2338 # remove outstanding pings
2339 delete $pings{$call};
2341 # I was the last node visited
2342 $self->user->node($main::mycall);
2344 # send info to all logged in thingies
2345 $self->tell_login('logoutn');
2347 Log('DXProt', $call . " Disconnected");
2349 $self->SUPER::disconnect;
2354 # send a talk message to this thingy
2358 my ($self, $from, $to, $via, $line, $origin) = @_;
2360 $line =~ s/\^/\\5E/g; # remove any ^ characters
2361 $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
2362 Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
2365 # send it if it isn't the except list and isn't isolated and still has a hop count
2366 # taking into account filtering and so on
2372 my $generate = shift;
2373 my $no = shift; # the no of things to filter on
2375 my ($filter, $hops);
2378 for (; @_ && $no; $no--) {
2381 if (!$self->{isolate} && $self->{routefilter}) {
2384 ($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});
2388 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
2391 dbg("was sent a null value") if isdbg('chanerr');
2394 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
2398 foreach my $line (&$generate(@rin, @_)) {
2401 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
2403 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
2404 next unless $routeit;
2407 $self->send($routeit);
2416 my $generate = shift;
2418 my @dxchan = DXChannel::get_all_nodes();
2421 unless ($self->{isolate}) {
2422 foreach $dxchan (@dxchan) {
2423 next if $dxchan == $self;
2424 next if $dxchan == $main::me;
2425 next unless $dxchan->isa('DXProt');
2426 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
2428 $dxchan->send_route($origin, $generate, @_);
2436 return unless $self->user->wantpc16;
2439 broadcast_route($self, $origin, \&pc16, $line, 1, @_);
2445 return unless $self->user->wantpc16;
2448 broadcast_route($self, $origin, \&pc17, $line, 1, @_);
2456 broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
2464 broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
2472 broadcast_route($self, $origin, \&pc24, $line, 1, @_);
2480 broadcast_route($self, $origin, \&pc41, $line, 1, @_);
2488 broadcast_route($self, $origin, \&pc50, $line, 1, @_);
2495 my ($filter, $hops) = (1, 1);
2497 if ($self->{inroutefilter}) {
2498 ($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);
2499 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
2507 my $t = shift || $eph_restime;
2511 $s =~ s/\^H\d\d?\^?\~?$//;
2512 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
2513 $eph{$s} = $main::systime + $t;
2514 dbg("PCPROT: emphemeral duplicate") if $r && isdbg('chanerr');
2522 while (($key, $val) = each %eph) {
2523 if ($key =~ m{$regex}) {
2533 while (($key, $val) = each %eph) {
2534 if ($main::systime >= $val) {
2545 while (($key, $val) = each %eph) {
2546 push @out, $key, $val;
2553 goto &DXCommandmode::run_cmd;
2557 # import any msgs in the chat directory
2558 # the messages are sent to the chat group which forms the
2559 # the first part of the name (eg: solar.1243.txt would be
2560 # sent to chat group SOLAR)
2562 # Each message found is sent: one non-blank line to one chat
2563 # message. So 4 lines = 4 chat messages.
2565 # The special name LOCAL is for local users ANN
2566 # The special name ALL is for ANN/FULL
2567 # The special name SYSOP is for ANN/SYSOP
2571 # are there any to do in this directory?
2572 return unless -d $chatimportfn;
2573 unless (opendir(DIR, $chatimportfn)) {
2574 dbg("can\'t open $chatimportfn $!") if isdbg('msg');
2575 Log('msg', "can\'t open $chatimportfn $!");
2579 my @names = readdir(DIR);
2582 foreach $name (@names) {
2583 next if $name =~ /^\./;
2584 my $splitit = $name =~ /^split/;
2585 my $fn = "$chatimportfn/$name";
2587 unless (open(MSG, $fn)) {
2588 dbg("can\'t open import file $fn $!") if isdbg('msg');
2589 Log('msg', "can\'t open import file $fn $!");
2593 my @msg = map { s/\r?\n$//; $_ } <MSG>;
2597 my @cat = split /\./, $name;
2598 my $target = uc $cat[0];
2600 foreach my $text (@msg) {
2601 next unless $text && $text !~ /^\s*#/;
2602 if ($target eq 'ALL' || $target eq 'LOCAL' || $target eq 'SYSOP') {
2603 my $sysopflag = $target eq 'SYSOP' ? '*' : ' ';
2604 if ($target ne 'LOCAL') {
2605 send_announce($main::me, pc12($main::mycall, $text, '*', $sysopflag), $main::mycall, '*', $text, $sysopflag, $main::mycall, '0');
2607 Log('ann', 'LOCAL', $main::mycall, $text);
2608 DXChannel::broadcast_list("To LOCAL de ${main::mycall}: $text\a", 'ann', undef, DXCommandmode->get_all());
2611 my $msgid = nextchatmsgid();
2612 $text = "#$msgid $text";
2613 send_chat($main::me, pc12($main::mycall, $text, '*', $target), $main::mycall, '*', $text, $target, $main::mycall, '0');