3 # This module impliments the protocal mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
41 use vars qw($VERSION $BRANCH);
42 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
43 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
44 $main::build += $VERSION;
45 $main::branch += $BRANCH;
47 use vars qw($pc11_max_age $pc23_max_age $last_pc50 $eph_restime $eph_info_restime $eph_pc34_restime
48 $last_hour $last10 %eph %pings %rcmds $ann_to_talk
49 $pingint $obscount %pc19list $chatdupeage $chatimportfn
50 $investigation_int $pc19_version $myprot_version
51 %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
52 $allowzero $decode_dk0wcy $send_opernam @checklist
56 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
57 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
59 $last_hour = time; # last time I did an hourly periodic update
60 %rcmds = (); # outstanding rcmd requests outbound
61 %nodehops = (); # node specific hop control
62 %pc19list = (); # list of outstanding PC19s that haven't had PC16s on them
64 $censorpc = 1; # Do a BadWords::check on text fields and reject things
65 # loads of 'bad things'
66 $baddx = new DXHash "baddx";
67 $badspotter = new DXHash "badspotter";
68 $badnode = new DXHash "badnode";
69 $last10 = $last_pc50 = time;
73 $eph_info_restime = 60*60;
74 $eph_pc15_restime = 6*60;
75 $eph_pc34_restime = 30;
78 $chatdupeage = 20 * 60 * 60;
79 $chatimportfn = "$main::root/chat_import";
80 $investigation_int = 12*60*60; # time between checks to see if we can see this node
81 $pc19_version = 5466; # the visible version no for outgoing PC19s generated from pc59
85 [ qw(i c c m bp bc c) ], # pc10
86 [ qw(i f m d t m c c h) ], # pc11
87 [ qw(i c bm m bm bm p h) ], # pc12
91 undef , # pc16 has to be validated manually
92 [ qw(i c c h) ], # pc17
94 undef , # pc19 has to be validated manually
95 undef , # pc20 no validation
96 [ qw(i c m h) ], # pc21
97 undef , # pc22 no validation
98 [ qw(i d n n n n m c c h) ], # pc23
99 [ qw(i c p h) ], # pc24
100 [ qw(i c c n n) ], # pc25
101 [ qw(i f m d t m c c bc) ], # pc26
102 [ qw(i d n n n n m c c bc) ], # pc27
103 [ qw(i c c m c d t p m bp n p bp bc) ], # pc28
104 [ qw(i c c n m) ], # pc29
105 [ qw(i c c n) ], # pc30
106 [ qw(i c c n) ], # pc31
107 [ qw(i c c n) ], # pc32
108 [ qw(i c c n) ], # pc33
109 [ qw(i c c m) ], # pc34
110 [ qw(i c c m) ], # pc35
111 [ qw(i c c m) ], # pc36
112 [ qw(i c c n m) ], # pc37
113 undef, # pc38 not interested
114 [ qw(i c m) ], # pc39
115 [ qw(i c c m p n) ], # pc40
116 [ qw(i c n m h) ], # pc41
117 [ qw(i c c n) ], # pc42
118 undef, # pc43 don't handle it
119 [ qw(i c c n m m c) ], # pc44
120 [ qw(i c c n m) ], # pc45
121 [ qw(i c c n) ], # pc46
124 [ qw(i c m h) ], # pc49
125 [ qw(i c n h) ], # pc50
126 [ qw(i c c n) ], # pc51
148 [ qw(i d n n n n n n m m m c c h) ], # pc73
159 [ qw(i c c c m) ], # pc84
160 [ qw(i c c c m) ], # pc85
165 [ qw(i c n) ], # pc90
168 # use the entry in the check list to check the field list presented
169 # return OK if line NOT in check list (for now)
174 return 0 if $n < 0 || $n > @checklist;
175 my $ref = $checklist[$n];
176 return 0 unless ref $ref;
179 for ($i = 1; $i < @$ref; $i++) {
180 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
181 return 0 unless $act;
182 next if $blank && $_[$i] =~ /^[ \*]$/;
184 return $i unless is_callsign($_[$i]);
185 } elsif ($act eq 'i') {
187 } elsif ($act eq 'm') {
188 return $i unless is_pctext($_[$i]);
189 } elsif ($act eq 'p') {
190 return $i unless is_pcflag($_[$i]);
191 } elsif ($act eq 'f') {
192 return $i unless is_freq($_[$i]);
193 } elsif ($act eq 'n') {
194 return $i unless $_[$i] =~ /^[\d ]+$/;
195 } elsif ($act eq 'h') {
196 return $i unless $_[$i] =~ /^H\d\d?$/;
197 } elsif ($act eq 'd') {
198 return $i unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
199 } elsif ($act eq 't') {
200 return $i unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
208 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
211 my $user = DXUser->get($main::mycall);
212 die "User $main::mycall not setup or disappeared RTFM" unless $user;
214 $myprot_version += $main::version*100;
215 $main::me = DXProt->new($main::mycall, 0, $user);
216 $main::me->{here} = 1;
217 $main::me->{state} = "indifferent";
218 $main::me->{sort} = 'S'; # S for spider
219 $main::me->{priv} = 9;
220 $main::me->{metric} = 0;
221 $main::me->{pingave} = 0;
222 $main::me->{registered} = 1;
223 $main::me->{version} = $main::version;
224 $main::me->{build} = $main::build;
228 # obtain a new connection this is derived from dxchannel
233 my $self = DXChannel::alloc(@_);
235 # add this node to the table, the values get filled in later
238 $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
243 # this is how a pc connection starts (for an incoming connection)
244 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
245 # all the crap that comes between).
248 my ($self, $line, $sort) = @_;
249 my $call = $self->{call};
250 my $user = $self->{user};
253 my $host = $self->{conn}->{peerhost};
254 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
257 Log('DXProt', "$call connected from $host");
259 # remember type of connection
260 $self->{consort} = $line;
261 $self->{outbound} = $sort eq 'O';
262 my $priv = $user->priv;
263 $priv = $user->priv(1) unless $priv;
264 $self->{priv} = $priv; # other clusters can always be 'normal' users
265 $self->{lang} = $user->lang || 'en';
266 $self->{isolate} = $user->{isolate};
267 $self->{consort} = $line; # save the connection type
271 # sort out registration
272 $self->{registered} = 1;
274 # get the output filters
275 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
276 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
277 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
278 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
279 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
282 # get the INPUT filters (these only pertain to Clusters)
283 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
284 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
285 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
286 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
287 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
289 # set unbuffered and no echo
290 $self->send_now('B',"0");
291 $self->send_now('E',"0");
292 $self->conn->echo(0) if $self->conn->can('echo');
294 # ping neighbour node stuff
295 my $ping = $user->pingint;
296 $ping = $pingint unless defined $ping;
297 $self->{pingint} = $ping;
298 $self->{nopings} = $user->nopings || $obscount;
299 $self->{pingtime} = [ ];
300 $self->{pingave} = 999;
301 $self->{metric} ||= 100;
302 $self->{lastping} = $main::systime;
304 # send initialisation string
305 unless ($self->{outbound}) {
309 $self->state('init');
310 $self->{pc50_t} = $main::systime;
312 # send info to all logged in thingies
313 $self->tell_login('loginn');
315 # run a script send the output to the debug file
316 my $script = new Script(lc $call) || new Script('node_default');
317 $script->run($self) if $script;
321 # send outgoing 'challenge'
331 # This is the normal pcxx despatcher
335 my ($self, $line) = @_;
337 if ($line =~ '^<\w+\s' && $main::do_xml) {
338 DXXml::normal($self, $line);
342 my @field = split /\^/, $line;
343 return unless @field;
345 pop @field if $field[-1] eq '~';
347 # print join(',', @field), "\n";
350 # process PC frames, this will fail unless the frame starts PCnn
351 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
352 unless (defined $pcno && $pcno >= 10 && $pcno <= 99) {
353 dbg("PCPROT: unknown protocol") if isdbg('chanerr');
357 # check for and dump bad protocol messages
358 my $n = check($pcno, @field);
360 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
364 my $origin = $self->{call};
366 my $sub = "handle_$pcno";
368 if ($self->can($sub)) {
369 $self->$sub($pcno, $line, $origin, @field);
371 $self->handle_default($pcno, $line, $origin, @field);
375 # incoming talk commands
384 return if $rspfcheck and !$self->rspfcheck(0, $_[6], $_[1]);
386 # will we allow it at all?
389 if (@bad = BadWords::check($_[3])) {
390 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
395 # is it for me or one of mine?
396 my ($from, $to, $via, $call, $dxchan);
405 # if this is a 'nodx' node then ignore it
406 if ($badnode->in($_[6]) || ($via && $badnode->in($via))) {
407 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
411 # if this is a 'bad spotter' user then ignore it
413 $nossid =~ s/-\d+$//;
414 if ($badspotter->in($nossid)) {
415 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
419 # if we are converting announces to talk is it a dup?
421 if (AnnTalk::is_talk_candidate($from, $_[3]) && AnnTalk::dup($from, $to, $_[3])) {
422 dbg("DXPROT: Dupe talk from announce, dropped") if isdbg('chanerr');
427 # remember a route to this node and also the node on which this user is
428 RouteDB::update($_[6], $self->{call});
429 # RouteDB::update($to, $_[6]);
431 # it is here and logged on
432 $dxchan = DXChannel::get($main::myalias) if $to eq $main::mycall;
433 $dxchan = DXChannel::get($to) unless $dxchan;
434 if ($dxchan && $dxchan->is_user) {
436 $dxchan->talk($from, $to, $via, $_[3]);
440 # is it elsewhere, visible on the cluster via the to address?
441 # note: this discards the via unless the to address is on
444 if ($ref = Route::get($to)) {
445 $vref = Route::Node::get($via) if $via;
446 $vref = undef unless $vref && grep $to eq $_, $vref->users;
447 $ref->dxchan->talk($from, $to, $vref ? $via : undef, $_[3], $_[6]);
451 # can we see an interface to send it down?
453 # not visible here, send a message of condolence
455 $ref = Route::get($from);
456 $vref = $ref = Route::Node::get($_[6]) unless $ref;
458 $dxchan = $ref->dxchan;
459 $dxchan->talk($main::mycall, $from, $vref ? $vref->call : undef, $dxchan->msg('talknh', $to) );
471 # route 'foreign' pc26s
473 if ($_[7] ne $main::mycall) {
474 $self->route($_[7], $line);
480 # return if $rspfcheck and !$self->rspfcheck(1, $_[7], $_[6]);
482 # is the spotted callsign blank? This should really be trapped earlier but it
483 # could break other protocol sentences. Also check for lower case characters.
484 if ($_[2] =~ /^\s*$/) {
485 dbg("PCPROT: blank callsign, dropped") if isdbg('chanerr');
488 if ($_[2] =~ /[a-z]/) {
489 dbg("PCPROT: lowercase characters, dropped") if isdbg('chanerr');
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]) || $_[2] =~ /COCK/) {
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], $nossid, $_[7]);
542 # global spot filtering on INPUT
543 if ($self->{inspotsfilter}) {
544 my ($filter, $hops) = $self->{inspotsfilter}->it(@spot);
546 dbg("PCPROT: Rejected by input spot filter") if isdbg('chanerr');
551 # this goes after the input filtering, but before the add
552 # so that if it is input filtered, it isn't added to the dup
553 # list. This allows it to come in from a "legitimate" source
554 if (Spot::dup(@spot[0..4,5])) {
555 dbg("PCPROT: Duplicate Spot ignored\n") if isdbg('chanerr');
563 # @spot at this point contains:-
564 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
565 # then spotted itu, spotted cq, spotters itu, spotters cq
566 # you should be able to route on any of these
569 # fix up qra locators of known users
570 my $user = DXUser->get_current($spot[4]);
572 my $qra = $user->qra;
573 unless ($qra && is_qra($qra)) {
574 my $lat = $user->lat;
575 my $long = $user->long;
576 if (defined $lat && defined $long) {
577 $user->qra(DXBearing::lltoqra($lat, $long));
582 # send a remote command to a distant cluster if it is visible and there is no
583 # qra locator and we havn't done it for a month.
585 unless ($user->qra) {
587 my $to = $user->homenode;
588 my $last = $user->lastoper || 0;
589 if ($send_opernam && $to && $to ne $main::mycall && $main::systime > $last + $DXUser::lastoperinterval && ($node = Route::Node::get($to)) ) {
590 my $cmd = "forward/opernam $spot[4]";
591 # send the rcmd but we aren't interested in the replies...
592 my $dxchan = $node->dxchan;
593 if ($dxchan && $dxchan->is_clx) {
594 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
596 route(undef, $to, pc34($main::mycall, $to, $cmd));
600 $node = Route::Node::get($to);
602 $dxchan = $node->dxchan;
603 if ($dxchan && $dxchan->is_clx) {
604 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
606 route(undef, $to, pc34($main::mycall, $to, $cmd));
610 $user->lastoper($main::systime);
619 $r = Local::spot($self, @spot);
621 # dbg("Local::spot1 error $@") if isdbg('local') if $@;
624 # DON'T be silly and send on PC26s!
625 return if $pcno == 26;
627 # send out the filtered spots
628 send_dx_spot($self, $line, @spot) if @spot;
639 # return if $rspfcheck and !$self->rspfcheck(1, $_[5], $_[1]);
641 # announce duplicate checking
642 $_[3] =~ s/^\s+//; # remove leading blanks
646 if (@bad = BadWords::check($_[3])) {
647 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
652 # if this is a 'nodx' node then ignore it
653 if ($badnode->in($_[5])) {
654 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
658 # if this is a 'bad spotter' user then ignore it
660 $nossid =~ s/-\d+$//;
661 if ($badspotter->in($nossid)) {
662 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
669 if ((($dxchan = DXChannel::get($_[2])) && $dxchan->is_user) || $_[4] =~ /^[\#\w.]+$/){
670 $self->send_chat($line, @_[1..6]);
671 } elsif ($_[2] eq '*' || $_[2] eq $main::mycall) {
674 # RouteDB::update($_[5], $self->{call});
675 # RouteDB::update($_[1], $_[5]);
677 # ignore something that looks like a chat line coming in with sysop
678 # flag - this is a kludge...
679 if ($_[3] =~ /^\#\d+ / && $_[4] eq '*') {
680 dbg('PCPROT: Probable chat rewrite, dropped') if isdbg('chanerr');
684 # here's a bit of fun, convert incoming ann with a callsign in the first word
685 # or one saying 'to <call>' to a talk if we can route to the recipient
687 my $call = AnnTalk::is_talk_candidate($_[1], $_[3]);
689 my $ref = Route::get($call);
691 $dxchan = $ref->dxchan;
692 $dxchan->talk($_[1], $call, undef, $_[3], $_[5]) if $dxchan != $self;
699 $self->send_announce($line, @_[1..6]);
701 $self->route($_[2], $line);
713 if (eph_dup($line, $eph_pc15_restime)) {
714 dbg("PCPROT: Ephemeral dup, dropped") if isdbg('chanerr');
716 unless ($self->{isolate}) {
717 DXChannel::broadcast_nodes($line, $self) if $line =~ /\^H\d+\^?~?$/; # send it to everyone but me
733 my $newline = "PC16^";
735 # dos I want users from this channel?
736 unless ($self->user->wantpc16) {
737 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
741 if ($ncall eq $main::mycall) {
742 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
746 RouteDB::update($ncall, $self->{call});
748 # do we believe this call?
749 unless ($ncall eq $self->{call} || $self->is_believed($ncall)) {
750 if (my $ivp = Investigate::get($ncall, $self->{call})) {
751 $ivp->store_pcxx($pcno,$line,$origin,@_);
753 dbg("PCPROT: We don't believe $ncall on $self->{call}") if isdbg('chanerr');
758 if (eph_dup($line)) {
759 dbg("PCPROT: dup PC16 detected") if isdbg('chanerr');
763 my $parent = Route::Node::get($ncall);
765 # if there is a parent, proceed, otherwise if there is a latent PC19 in the PC19list,
766 # fix it up in the routing tables and issue it forth before the PC16
768 my $nl = $pc19list{$ncall};
770 if ($nl && @_ > 3) { # 3 because of the hop count!
772 # this is a new (remembered) node, now attach it to me if it isn't in filtered
773 # and we haven't disallowed it
774 my $user = DXUser->get_current($ncall);
776 $user = DXUser->new($ncall);
778 $user->priv(1); # I have relented and defaulted nodes
780 $user->homenode($ncall);
784 my $wantpc19 = $user->wantroutepc19;
785 if ($wantpc19 || !defined $wantpc19) {
786 my $new = Route->new($ncall); # throw away
787 if ($self->in_filter_route($new)) {
790 $parent = Route::Node::get($_->[0]);
791 $dxchan = $parent->dxchan if $parent;
792 if ($dxchan && $dxchan ne $self) {
793 dbg("PCPROT: PC19 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
797 my $r = $parent->add($ncall, $_->[1], $_->[2]);
798 push @nrout, $r unless @nrout;
801 $user->wantroutepc19(1) unless defined $wantpc19; # for now we work on the basis that pc16 = real route
802 $user->lastin($main::systime) unless DXChannel::get($ncall);
805 # route the pc19 - this will cause 'stuttering PC19s' for a while
806 $self->route_pc19($origin, $line, @nrout) if @nrout ;
807 $parent = Route::Node::get($ncall);
809 dbg("PCPROT: lost $ncall after sending PC19 for it?");
815 delete $pc19list{$ncall};
818 dbg("PCPROT: Node $ncall not in config") if isdbg('chanerr');
823 $dxchan = $parent->dxchan;
824 if ($dxchan && $dxchan ne $self) {
825 dbg("PCPROT: PC16 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
829 # input filter if required
830 return unless $self->in_filter_route($parent);
835 for ($i = 2; $i < $#_; $i++) {
836 my ($call, $conf, $here) = $_[$i] =~ /^(\S+) (\S) (\d)/o;
837 next unless $call && $conf && defined $here && is_callsign($call);
838 next if $call eq $main::mycall;
840 eph_del_regex("^PC17\\^$call\\^$ncall");
842 $conf = $conf eq '*';
844 # reject this if we think it is a node already
845 my $r = Route::Node::get($call);
846 my $u = DXUser->get_current($call) unless $r;
847 if ($r || ($u && $u->is_node)) {
848 dbg("PCPROT: $call is a node") if isdbg('chanerr');
852 $r = Route::User::get($call);
853 my $flags = Route::here($here)|Route::conf($conf);
856 my $au = $r->addparent($parent);
857 if ($r->flags != $flags) {
861 push @rout, $r if $au;
863 push @rout, $parent->add_user($call, $flags);
866 # send info to all logged in thingies
867 $self->tell_login('loginu', "$ncall: $call") if DXUser->get_current($ncall)->is_local_node;
868 $self->tell_buddies('loginb', $call, $ncall);
870 # add this station to the user database, if required
871 # $call =~ s/-\d+$//o; # remove ssid for users
872 my $user = DXUser->get_current($call);
873 $user = DXUser->new($call) if !$user;
874 $user->homenode($parent->call) if !$user->homenode;
875 $user->node($parent->call);
876 $user->lastin($main::systime) unless DXChannel::get($call);
879 $self->route_pc16($origin, $line, $parent, @rout) if @rout;
893 eph_del_regex("^PC16\\^$ncall.*$ucall");
895 # do I want users from this channel?
896 unless ($self->user->wantpc16) {
897 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
900 if ($ncall eq $main::mycall) {
901 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
905 RouteDB::delete($ncall, $self->{call});
907 # do we believe this call?
908 unless ($ncall eq $self->{call} || $self->is_believed($ncall)) {
909 if (my $ivp = Investigate::get($ncall, $self->{call})) {
910 $ivp->store_pcxx($pcno,$line,$origin,@_);
912 dbg("PCPROT: We don't believe $ncall on $self->{call}") if isdbg('chanerr');
917 my $uref = Route::User::get($ucall);
919 dbg("PCPROT: Route::User $ucall not in config") if isdbg('chanerr');
921 my $parent = Route::Node::get($ncall);
923 dbg("PCPROT: Route::Node $ncall not in config") if isdbg('chanerr');
926 $dxchan = $parent->dxchan if $parent;
927 if ($dxchan && $dxchan ne $self) {
928 dbg("PCPROT: PC17 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
932 # input filter if required and then remove user if present
934 # return unless $self->in_filter_route($parent);
935 $parent->del_user($uref) if $uref;
937 $parent = Route->new($ncall); # throw away
940 # send info to all logged in thingies
941 $self->tell_login('logoutu', "$ncall: $ucall") if DXUser->get_current($ncall)->is_local_node;
942 $self->tell_buddies('logoutb', $ucall, $ncall);
944 if (eph_dup($line)) {
945 dbg("PCPROT: dup PC17 detected") if isdbg('chanerr');
949 $uref = Route->new($ucall) unless $uref; # throw away
950 $self->route_pc17($origin, $line, $parent, $uref);
960 $self->state('init');
962 # record the type and version offered
963 if ($_[1] =~ /DXSpider Version: (\d+\.\d+) Build: (\d+\.\d+)/) {
964 $self->version(53 + $1);
965 $self->user->version(53 + $1);
966 $self->build(0 + $2);
967 $self->user->build(0 + $2);
968 unless ($self->is_spider) {
969 $self->user->sort('S');
973 $self->{handle_xml}++ if DXXml::available() && $_[1] =~ /\bxml\b/;
975 $self->version(50.0);
976 $self->version($_[2] / 100) if $_[2] && $_[2] =~ /^\d+$/;
977 $self->user->version($self->version);
980 # first clear out any nodes on this dxchannel
981 my $parent = Route::Node::get($self->{call});
982 my @rout = $parent->del_nodes;
983 $self->route_pc21($origin, $line, @rout, $parent) if @rout;
984 $self->send_local_config();
988 # incoming cluster list
997 my $newline = "PC19^";
1002 # first get the INTERFACE node
1003 my $parent = Route::Node::get($self->{call});
1005 dbg("DXPROT: my parent $self->{call} has disappeared");
1010 # if the origin isn't the same as the INTERFACE, then reparent, creating nodes as necessary
1011 if ($origin ne $self->call) {
1012 my $op = Route::Node::get($origin);
1014 $op = $parent->add($origin, 5000, Route::here(1));
1015 my $user = DXUser->get_current($origin);
1017 $user = DXUser->new($origin);
1018 $user->priv(1); # I have relented and defaulted nodes
1020 $user->homenode($origin);
1021 $user->node($origin);
1022 $user->wantroutepc19(1);
1024 $user->sort('A') unless $user->is_node;
1031 for ($i = 1; $i < $#_-1; $i += 4) {
1033 my $call = uc $_[$i+1];
1034 my $conf = $_[$i+2];
1036 next unless defined $here && defined $conf && is_callsign($call);
1038 eph_del_regex("^PC(?:21\\^$call|17\\^[^\\^]+\\^$call)");
1040 # check for sane parameters
1041 # $ver = 5000 if $ver eq '0000';
1042 next unless $ver && $ver =~ /^\d+$/;
1043 next if $ver < 5000; # only works with version 5 software
1044 next if length $call < 3; # min 3 letter callsigns
1045 next if $call eq $main::mycall;
1047 # check that this PC19 isn't trying to alter the wrong dxchan
1048 my $dxchan = DXChannel::get($call);
1049 if ($dxchan && $dxchan != $self) {
1050 dbg("PCPROT: PC19 from $self->{call} trying to alter wrong locally connected $call, ignored!") if isdbg('chanerr');
1054 # add this station to the user database, if required (don't remove SSID from nodes)
1055 my $user = DXUser->get_current($call);
1057 $user = DXUser->new($call);
1058 $user->priv(1); # I have relented and defaulted nodes
1060 $user->homenode($call);
1063 $user->sort('A') unless $user->is_node;
1065 RouteDB::update($call, $self->{call});
1067 # do we believe this call?
1068 my $genline = "PC19^$here^$call^$conf^$ver^$_[-1]^";
1069 unless ($call eq $self->{call} || $self->is_believed($call)) {
1070 my $pt = $user->lastping($self->{call}) || 0;
1071 if ($pt+$investigation_int < $main::systime && !Investigate::get($call, $self->{call})) {
1072 my $ivp = Investigate->new($call, $self->{call});
1073 $ivp->version($ver);
1075 $ivp->store_pcxx($pcno,$genline,$origin,'PC19',$here,$call,$conf,$ver,$_[-1]);
1077 dbg("PCPROT: We don't believe $call on $self->{call}") if isdbg('chanerr');
1083 if (eph_dup($genline)) {
1084 dbg("PCPROT: dup PC19 for $call detected") if isdbg('chanerr');
1088 my $r = Route::Node::get($call);
1089 my $flags = Route::here($here)|Route::conf($conf);
1091 # modify the routing table if it is in it, otherwise store it in the pc19list for now
1094 if ($call ne $parent->call) {
1095 if ($self->in_filter_route($r)) {
1096 $ar = $parent->add($call, $ver, $flags);
1097 push @rout, $ar if $ar;
1102 if ($r->version ne $ver || $r->flags != $flags) {
1105 push @rout, $r unless $ar;
1109 # if he is directly connected or allowed then add him, otherwise store him up for later
1110 if ($call eq $self->{call} || $user->wantroutepc19) {
1111 my $new = Route->new($call); # throw away
1112 if ($self->in_filter_route($new)) {
1113 my $ar = $parent->add($call, $ver, $flags);
1114 $user->wantroutepc19(1) unless defined $user->wantroutepc19;
1115 push @rout, $ar if $ar;
1120 $pc19list{$call} = [] unless exists $pc19list{$call};
1121 my $nl = $pc19list{$call};
1122 push @{$pc19list{$call}}, [$self->{call}, $ver, $flags] unless grep $_->[0] eq $self->{call}, @$nl;
1126 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
1127 my $mref = DXMsg::get_busy($call);
1128 $mref->stop_msg($call) if $mref;
1130 $user->lastin($main::systime) unless DXChannel::get($call);
1135 $self->route_pc19($origin, $line, @rout) if @rout;
1138 # send local configuration
1145 $self->send_local_config();
1146 $self->send(pc22());
1147 $self->state('normal');
1148 $self->{lastping} = 0;
1151 # delete a cluster from the list
1158 my $call = uc $_[1];
1160 eph_del_regex("^PC1[679].*$call");
1162 # if I get a PC21 from the same callsign as self then treat it
1163 # as a PC39: I have gone away
1164 if ($call eq $self->call) {
1165 $self->disconnect(1);
1169 RouteDB::delete($call, $self->{call});
1171 # check if we believe this
1172 unless ($call eq $self->{call} || $self->is_believed($call)) {
1173 if (my $ivp = Investigate::get($call, $self->{call})) {
1174 $ivp->store_pcxx($pcno,$line,$origin,@_);
1176 dbg("PCPROT: We don't believe $call on $self->{call}") if isdbg('chanerr');
1181 # check to see if we are in the pc19list, if we are then don't bother with any of
1182 # this routing table manipulation, just remove it from the list and dump it
1184 if (my $nl = $pc19list{$call}) {
1185 $pc19list{$call} = [ grep {$_->[0] ne $self->{call}} @$nl ];
1186 delete $pc19list{$call} unless @{$pc19list{$call}};
1189 my $parent = Route::Node::get($self->{call});
1191 dbg("DXPROT: my parent $self->{call} has disappeared");
1195 if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
1196 my $node = Route::Node::get($call);
1199 my $dxchan = DXChannel::get($call);
1200 if ($dxchan && $dxchan != $self) {
1201 dbg("PCPROT: PC21 from $self->{call} trying to alter locally connected $call, ignored!") if isdbg('chanerr');
1206 return unless $self->in_filter_route($node);
1209 push @rout, $node->del($parent);
1212 dbg("PCPROT: I WILL _NOT_ be disconnected!") if isdbg('chanerr');
1217 $self->route_pc21($origin, $line, @rout) if @rout;
1227 $self->state('normal');
1228 $self->{lastping} = 0;
1239 # route foreign' pc27s
1241 if ($_[8] ne $main::mycall) {
1242 $self->route($_[8], $line);
1247 # only do a rspf check on PC23 (not 27)
1249 return if $rspfcheck and !$self->rspfcheck(1, $_[8], $_[7])
1253 my $d = cltounix($_[1], sprintf("%02d18Z", $_[2]));
1254 my $sfi = unpad($_[3]);
1255 my $k = unpad($_[4]);
1256 my $i = unpad($_[5]);
1257 my ($r) = $_[6] =~ /R=(\d+)/;
1259 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1260 dbg("PCPROT: WWV Date ($_[1] $_[2]) out of range") if isdbg('chanerr');
1264 # global wwv filtering on INPUT
1265 my @dxcc = ((Prefix::cty_data($_[7]))[0..2], (Prefix::cty_data($_[8]))[0..2]);
1266 if ($self->{inwwvfilter}) {
1267 my ($filter, $hops) = $self->{inwwvfilter}->it(@_[7,8], $origin, @dxcc);
1269 dbg("PCPROT: Rejected by input wwv filter") if isdbg('chanerr');
1273 $_[7] =~ s/-\d+$//o; # remove spotter's ssid
1274 if (Geomag::dup($d,$sfi,$k,$i,$_[6],$_[7])) {
1275 dbg("PCPROT: Dup WWV Spot ignored\n") if isdbg('chanerr');
1279 # note this only takes the first one it gets
1280 Geomag::update($d, $_[2], $sfi, $k, $i, @_[6..8], $r);
1284 $rep = Local::wwv($self, $_[1], $_[2], $sfi, $k, $i, @_[6..8], $r);
1286 # dbg("Local::wwv2 error $@") if isdbg('local') if $@;
1289 # DON'T be silly and send on PC27s!
1290 return if $pcno == 27;
1292 # broadcast to the eager world
1293 send_wwv_spot($self, $line, $d, $_[2], $sfi, $k, $i, @_[6..8]);
1303 my $call = uc $_[1];
1305 $nref = Route::Node::get($call);
1306 $uref = Route::User::get($call);
1307 return unless $nref || $uref; # if we don't know where they are, it's pointless sending it on
1309 if (eph_dup($line)) {
1310 dbg("PCPROT: Dup PC24 ignored\n") if isdbg('chanerr');
1314 $nref->here($_[2]) if $nref;
1315 $uref->here($_[2]) if $uref;
1316 my $ref = $nref || $uref;
1317 return unless $self->in_filter_route($ref);
1319 $self->route_pc24($origin, $line, $ref, $_[3]);
1329 if ($_[1] ne $main::mycall) {
1330 $self->route($_[1], $line);
1333 if ($_[2] eq $main::mycall) {
1334 dbg("PCPROT: Trying to merge to myself, ignored") if isdbg('chanerr');
1338 Log('DXProt', "Merge request for $_[3] spots and $_[4] WWV from $_[2]");
1342 my @in = reverse Spot::search(1, undef, undef, 0, $_[3]);
1345 $self->send(pc26(@{$in}[0..4], $_[2]));
1351 my @in = reverse Geomag::search(0, $_[4], time, 1);
1354 $self->send(pc27(@{$in}[0..5], $_[2]));
1359 sub handle_26 {goto &handle_11}
1360 sub handle_27 {goto &handle_23}
1362 # mail/file handling
1369 if ($_[1] eq $main::mycall) {
1371 my $sub = "DXMsg::handle_$pcno";
1374 $self->route($_[1], $line) unless $self->is_clx;
1378 sub handle_29 {goto &handle_28}
1379 sub handle_30 {goto &handle_28}
1380 sub handle_31 {goto &handle_28}
1381 sub handle_32 {goto &handle_28}
1382 sub handle_33 {goto &handle_28}
1390 if (eph_dup($line, $eph_pc34_restime)) {
1391 dbg("PCPROT: dupe PC34, ignored") if isdbg('chanerr');
1393 $self->process_rcmd($_[1], $_[2], $_[2], $_[3]);
1397 # remote command replies
1404 eph_del_regex("^PC35\\^$_[2]\\^$_[1]\\^");
1405 $self->process_rcmd_reply($_[1], $_[2], $_[1], $_[3]);
1408 sub handle_36 {goto &handle_34}
1417 if ($_[1] eq $main::mycall) {
1419 my $sub = "DXDb::handle_$pcno";
1422 $self->route($_[1], $line) unless $self->is_clx;
1426 # node connected list from neighbour
1435 # incoming disconnect
1442 if ($_[1] eq $self->{call}) {
1443 $self->disconnect(1);
1445 dbg("PCPROT: came in on wrong channel") if isdbg('chanerr');
1449 sub handle_40 {goto &handle_28}
1461 $l =~ s/[\x00-\x20\x7f-\xff]+//g; # remove all funny characters and spaces for dup checking
1462 if (eph_dup($l, $eph_info_restime)) {
1463 dbg("PCPROT: dup PC41, ignored") if isdbg('chanerr');
1467 # input filter if required
1468 # my $ref = Route::get($call) || Route->new($call);
1469 # return unless $self->in_filter_route($ref);
1471 if ($_[3] eq $_[2] || $_[3] =~ /^\s*$/) {
1472 dbg('PCPROT: invalid value') if isdbg('chanerr');
1476 # add this station to the user database, if required
1477 my $user = DXUser->get_current($call);
1478 $user = DXUser->new($call) unless $user;
1482 } elsif ($_[2] == 2) {
1484 } elsif ($_[2] == 3) {
1485 if (is_latlong($_[3])) {
1486 my ($lat, $long) = DXBearing::stoll($_[3]);
1489 $user->qra(DXBearing::lltoqra($lat, $long));
1491 dbg('PCPROT: not a valid lat/long') if isdbg('chanerr');
1494 } elsif ($_[2] == 4) {
1495 $user->homenode($_[3]);
1496 } elsif ($_[2] == 5) {
1497 if (is_qra(uc $_[3])) {
1498 my ($lat, $long) = DXBearing::qratoll(uc $_[3]);
1501 $user->qra(uc $_[3]);
1503 dbg('PCPROT: not a valid QRA locator') if isdbg('chanerr');
1507 $user->lastoper($main::systime); # to cut down on excessive for/opers being generated
1510 unless ($self->{isolate}) {
1511 DXChannel::broadcast_nodes($line, $self); # send it to everyone but me
1514 # perhaps this IS what we want after all
1515 # $self->route_pc41($ref, $call, $_[2], $_[3], $_[4]);
1518 sub handle_42 {goto &handle_28}
1522 sub handle_44 {goto &handle_37}
1523 sub handle_45 {goto &handle_37}
1524 sub handle_46 {goto &handle_37}
1525 sub handle_47 {goto &handle_37}
1526 sub handle_48 {goto &handle_37}
1528 # message and database
1536 if (eph_dup($line)) {
1537 dbg("PCPROT: Dup PC49 ignored\n") if isdbg('chanerr');
1541 if ($_[1] eq $main::mycall) {
1542 DXMsg::handle_49($self, @_);
1544 $self->route($_[1], $line) unless $self->is_clx;
1548 # keep alive/user list
1558 RouteDB::update($call, $self->{call});
1560 my $node = Route::Node::get($call);
1562 return unless $node->call eq $self->{call};
1563 $node->usercount($_[2]);
1565 # input filter if required
1566 return unless $self->in_filter_route($node);
1568 $self->route_pc50($origin, $line, $node, $_[2], $_[3]) unless eph_dup($line);
1572 # incoming ping requests/answers
1585 if ($to eq $main::mycall) {
1587 $self->send(pc51($from, $to, '0'));
1589 DXXml::Ping::handle_ping_reply($self, $from);
1593 RouteDB::update($from, $self->{call});
1595 if (eph_dup($line)) {
1596 dbg("PCPROT: dup PC51 detected") if isdbg('chanerr');
1599 # route down an appropriate thingy
1600 $self->route($to, $line);
1604 # dunno but route it
1612 if ($call ne $main::mycall) {
1613 $self->route($call, $line);
1627 my $d = cltounix($call, sprintf("%02d18Z", $_[2]));
1628 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1629 dbg("PCPROT: WCY Date ($call $_[2]) out of range") if isdbg('chanerr');
1632 @_ = map { unpad($_) } @_;
1634 dbg("PCPROT: Dup WCY Spot ignored\n") if isdbg('chanerr');
1638 my $wcy = WCY::update($d, @_[2..12]);
1642 $rep = Local::wcy($self, @_[1..12]);
1644 # dbg("Local::wcy error $@") if isdbg('local') if $@;
1647 # broadcast to the eager world
1648 send_wcy_spot($self, $line, $d, @_[2..12]);
1651 # remote commands (incoming)
1658 $self->process_rcmd($_[1], $_[2], $_[3], $_[4]);
1661 # remote command replies
1668 $self->process_rcmd_reply($_[1], $_[2], $_[3], $_[4]);
1671 # if get here then rebroadcast the thing with its Hop count decremented (if
1672 # there is one). If it has a hop count and it decrements to zero then don't
1675 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
1686 if (eph_dup($line)) {
1687 dbg("PCPROT: Ephemeral dup, dropped") if isdbg('chanerr');
1689 unless ($self->{isolate}) {
1690 DXChannel::broadcast_nodes($line, $self) if $line =~ /\^H\d+\^?~?$/; # send it to everyone but me
1696 # This is called from inside the main cluster processing loop and is used
1697 # for despatching commands that are doing some long processing job
1702 my @dxchan = DXChannel::get_all();
1706 # send out a pc50 on EVERY channel all at once
1707 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
1708 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
1713 foreach $dxchan (@dxchan) {
1714 next unless $dxchan->is_node;
1715 next if $dxchan->handle_xml;
1716 next if $dxchan == $main::me;
1719 $dxchan->send($pc50s) if $pc50s;
1721 # send a ping out on this channel
1722 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
1723 if ($dxchan->{nopings} <= 0) {
1724 $dxchan->disconnect;
1726 DXXml::Ping::add($main::me, $dxchan->call);
1727 $dxchan->{nopings} -= 1;
1728 $dxchan->{lastping} = $t;
1729 $dxchan->{lastping} += $dxchan->{pingint} / 2 unless @{$dxchan->{pingtime}};
1734 Investigate::process();
1737 if ($t - $last10 >= 10) {
1738 # clean out ephemera
1747 if ($main::systime - 3600 > $last_hour) {
1748 $last_hour = $main::systime;
1753 # finish up a pc context
1757 # some active measures
1765 my @dxchan = DXChannel::get_all();
1768 # send it if it isn't the except list and isn't isolated and still has a hop count
1769 # taking into account filtering and so on
1770 foreach $dxchan (@dxchan) {
1771 next if $dxchan == $main::me;
1772 next if $dxchan == $self && $self->is_node;
1773 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
1781 my $isolate = shift;
1782 my ($filter, $hops);
1784 if ($self->{spotsfilter}) {
1785 ($filter, $hops) = $self->{spotsfilter}->it(@_);
1786 return unless $filter;
1788 send_prot_line($self, $filter, $hops, $isolate, $line);
1793 my ($self, $filter, $hops, $isolate, $line) = @_;
1799 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1801 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1802 return unless $routeit;
1805 $self->send($routeit);
1807 $self->send($routeit) unless $self->{isolate} || $isolate;
1816 my @dxchan = DXChannel::get_all();
1818 my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
1820 # send it if it isn't the except list and isn't isolated and still has a hop count
1821 # taking into account filtering and so on
1822 foreach $dxchan (@dxchan) {
1823 next if $dxchan == $main::me;
1824 next if $dxchan == $self && $self->is_node;
1826 my ($filter, $hops);
1828 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
1836 my $isolate = shift;
1837 my ($filter, $hops);
1839 if ($self->{wwvfilter}) {
1840 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_]);
1841 return unless $filter;
1843 send_prot_line($self, $filter, $hops, $isolate, $line)
1850 my @dxchan = DXChannel::get_all();
1852 my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
1854 # send it if it isn't the except list and isn't isolated and still has a hop count
1855 # taking into account filtering and so on
1856 foreach $dxchan (@dxchan) {
1857 next if $dxchan == $main::me;
1858 next if $dxchan == $self;
1860 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
1868 my $isolate = shift;
1869 my ($filter, $hops);
1871 if ($self->{wcyfilter}) {
1872 ($filter, $hops) = $self->{wcyfilter}->it(@_);
1873 return unless $filter;
1875 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
1883 my @dxchan = DXChannel::get_all();
1887 my $text = unpad($_[2]);
1889 if ($_[3] eq '*') { # sysops
1891 } elsif ($_[3] gt ' ') { # speciality list handling
1892 my ($name) = split /\./, $_[3];
1893 $target = "$name"; # put the rest in later (if bothered)
1900 $target = "ALL" if !$target;
1903 # obtain country codes etc
1904 my @a = Prefix::cty_data($_[0]);
1905 my @b = Prefix::cty_data($_[4]);
1906 if ($self->{inannfilter}) {
1907 my ($filter, $hops) =
1908 $self->{inannfilter}->it(@_, $self->{call},
1910 @b[0..2], $a[3], $b[3]);
1912 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1917 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
1918 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1922 Log('ann', $target, $_[0], $text);
1924 # send it if it isn't the except list and isn't isolated and still has a hop count
1925 # taking into account filtering and so on
1926 foreach $dxchan (@dxchan) {
1927 next if $dxchan == $main::me;
1928 next if $dxchan == $self && $self->is_node;
1929 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
1930 @a[0..2], @b[0..2]);
1939 $msgid = 1 if $msgid > 999;
1948 my @dxchan = DXChannel::get_all();
1951 my $text = unpad($_[2]);
1954 # munge the group and recast the line if required
1955 if ($target =~ s/\.LST$//) {
1959 # obtain country codes etc
1960 my @a = Prefix::cty_data($_[0]);
1961 my @b = Prefix::cty_data($_[4]);
1962 if ($self->{inannfilter}) {
1963 my ($filter, $hops) =
1964 $self->{inannfilter}->it(@_, $self->{call},
1966 @b[0..2], $a[3], $b[3]);
1968 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1973 if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
1974 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1979 Log('chat', $target, $_[0], $text);
1981 # send it if it isn't the except list and isn't isolated and still has a hop count
1982 # taking into account filtering and so on
1983 foreach $dxchan (@dxchan) {
1984 my $is_ak1a = $dxchan->is_ak1a;
1986 if ($dxchan->is_node) {
1987 next if $dxchan == $main::me;
1988 next if $dxchan == $self;
1989 next unless $dxchan->is_spider || $is_ak1a;
1990 next if $target eq 'LOCAL';
1991 if (!$ak1a_line && $is_ak1a) {
1992 $ak1a_line = DXProt::pc12($_[0], $text, $_[1], "$target.LST");
1996 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1],
1997 $text, @_, $self->{call}, @a[0..2], @b[0..2]);
2005 my $isolate = shift;
2009 my ($filter, $hops);
2011 if ($self->{annfilter}) {
2012 ($filter, $hops) = $self->{annfilter}->it(@_);
2013 return unless $filter;
2015 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
2024 sub send_local_config
2032 dbg('DXProt::send_local_config') if isdbg('trace');
2035 if ($self->{isolate}) {
2036 @localnodes = ( $main::routeroot );
2037 $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
2039 # create a list of all the nodes that are not connected to this connection
2040 # and are not themselves isolated, this to make sure that isolated nodes
2041 # don't appear outside of this node
2043 # send locally connected nodes
2044 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
2045 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
2046 $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
2049 my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
2051 for $node (@rawintcalls) {
2052 push @intcalls, $node unless grep $node eq $_, @intcalls;
2054 my $ref = Route::Node::get($self->{call});
2055 my @rnodes = $ref->nodes;
2056 for $node (@intcalls) {
2057 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
2059 $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
2062 # get all the users connected on the above nodes and send them out
2063 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
2065 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
2066 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
2068 dbg("sent a null value") if isdbg('chanerr');
2074 # route a message down an appropriate interface for a callsign
2076 # is called route(to, pcline);
2081 my ($self, $call, $line) = @_;
2083 if (ref $self && $call eq $self->{call}) {
2084 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
2088 # always send it down the local interface if available
2089 my $dxchan = DXChannel::get($call);
2091 dbg("route: $call -> $dxchan->{call} direct" ) if isdbg('route');
2093 my $cl = Route::get($call);
2094 $dxchan = $cl->dxchan if $cl;
2096 if (ref $self && $dxchan eq $self) {
2097 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
2100 dbg("route: $call -> $dxchan->{call} using normal route" ) if isdbg('route');
2104 # try the backstop method
2106 my $rcall = RouteDB::get($call);
2108 if ($self && $rcall eq $self->{call}) {
2109 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
2112 $dxchan = DXChannel::get($rcall);
2113 dbg("route: $call -> $rcall using RouteDB" ) if isdbg('route') && $dxchan;
2118 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
2120 $dxchan->send($routeit) unless $dxchan == $main::me;
2123 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
2128 # obtain the hops from the list for this callsign and pc no
2134 my $hops = $DXProt::hopcount{$pcno};
2135 $hops = $DXProt::def_hopcount if !$hops;
2140 # adjust the hop count on a per node basis using the user loadable
2141 # hop table if available or else decrement an existing one
2148 my $call = $self->{call};
2151 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
2152 my ($pcno) = $s =~ /^PC(\d\d)/o;
2153 confess "$call called adjust_hops with '$s'" unless $pcno;
2154 my $ref = $nodehops{$call} if %nodehops;
2156 my $newhops = $ref->{$pcno};
2157 return "" if defined $newhops && $newhops == 0;
2158 $newhops = $ref->{default} unless $newhops;
2159 return "" if defined $newhops && $newhops == 0;
2160 $newhops = $hops if !$newhops;
2161 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
2163 # simply decrement it
2165 return "" if !$hops;
2166 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
2178 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
2179 do "$main::data/hop_table.pl";
2186 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
2187 if ($tonode eq $main::mycall) {
2188 my $ref = DXUser->get_current($fromnode);
2189 my $cref = Route::Node::get($fromnode);
2190 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
2191 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
2192 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
2193 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
2194 my $oldpriv = $self->{priv};
2195 $self->{priv} = $ref->{priv}; # assume the user's privilege level
2196 my @in = (DXCommandmode::run_cmd($self, $cmd));
2197 $self->{priv} = $oldpriv;
2198 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
2199 delete $self->{remotecmd};
2201 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
2204 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
2207 my $ref = DXUser->get_current($tonode);
2208 if ($ref && $ref->is_clx) {
2209 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
2211 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
2216 sub process_rcmd_reply
2218 my ($self, $tonode, $fromnode, $user, $line) = @_;
2219 if ($tonode eq $main::mycall) {
2220 my $s = $rcmds{$fromnode};
2222 my $dxchan = DXChannel::get($s->{call});
2223 my $ref = $user eq $tonode ? $dxchan : (DXChannel::get($user) || $dxchan);
2224 $ref->send($line) if $ref;
2225 delete $rcmds{$fromnode} if !$dxchan;
2227 # send unsolicited ones to the sysop
2228 my $dxchan = DXChannel::get($main::myalias);
2229 $dxchan->send($line) if $dxchan;
2232 my $ref = DXUser->get_current($tonode);
2233 if ($ref && $ref->is_clx) {
2234 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
2236 $self->route($tonode, pc35($fromnode, $tonode, $line));
2245 my $fromnode = shift;
2250 Log('rcmd', 'out', $fromnode, $line);
2251 if ($self->is_clx) {
2252 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
2254 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
2259 # add a rcmd request to the rcmd queues
2262 my ($self, $to, $cmd) = @_;
2265 $r->{call} = $self->{call};
2266 $r->{t} = $main::systime;
2270 my $ref = Route::Node::get($to);
2271 my $dxchan = $ref->dxchan;
2272 if ($dxchan && $dxchan->is_clx) {
2273 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
2275 route(undef, $to, pc34($main::mycall, $to, $cmd));
2282 my $pc39flag = shift;
2283 my $call = $self->call;
2285 return if $self->{disconnecting}++;
2287 unless ($pc39flag && $pc39flag == 1) {
2288 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
2291 # get rid of any PC16/17/19
2292 eph_del_regex("^PC1[679]*$call");
2294 # do routing stuff, remove me from routing table
2295 my $node = Route::Node::get($call);
2298 @rout = $node->del($main::routeroot);
2300 # and all my ephemera as well
2303 eph_del_regex("^PC1[679].*$c");
2307 RouteDB::delete_interface($call);
2309 # remove them from the pc19list as well
2310 while (my ($k,$v) = each %pc19list) {
2311 my @l = grep {$_->[0] ne $call} @{$pc19list{$k}};
2313 $pc19list{$k} = \@l;
2315 delete $pc19list{$k};
2319 eph_del_regex("^PC1[679].*$k");
2322 # unbusy and stop and outgoing mail
2323 my $mref = DXMsg::get_busy($call);
2324 $mref->stop_msg($call) if $mref;
2326 # broadcast to all other nodes that all the nodes connected to via me are gone
2327 unless ($pc39flag && $pc39flag == 2) {
2328 $self->route_pc21($main::mycall, undef, @rout) if @rout;
2331 # remove outstanding pings
2332 delete $pings{$call};
2334 # I was the last node visited
2335 $self->user->node($main::mycall);
2337 # send info to all logged in thingies
2338 $self->tell_login('logoutn');
2340 Log('DXProt', $call . " Disconnected");
2342 $self->SUPER::disconnect;
2347 # send a talk message to this thingy
2351 my ($self, $from, $to, $via, $line, $origin) = @_;
2353 $line =~ s/\^/\\5E/g; # remove any ^ characters
2354 $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
2355 Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
2358 # send it if it isn't the except list and isn't isolated and still has a hop count
2359 # taking into account filtering and so on
2365 my $generate = shift;
2366 my $no = shift; # the no of things to filter on
2368 my ($filter, $hops);
2371 for (; @_ && $no; $no--) {
2374 if (!$self->{isolate} && $self->{routefilter}) {
2377 ($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});
2381 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
2384 dbg("was sent a null value") if isdbg('chanerr');
2387 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
2391 foreach my $line (&$generate(@rin, @_)) {
2394 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
2396 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
2397 next unless $routeit;
2400 $self->send($routeit);
2409 my $generate = shift;
2411 my @dxchan = DXChannel::get_all_nodes();
2414 unless ($self->{isolate}) {
2415 foreach $dxchan (@dxchan) {
2416 next if $dxchan == $self;
2417 next if $dxchan == $main::me;
2418 next unless $dxchan->isa('DXProt');
2419 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
2421 $dxchan->send_route($origin, $generate, @_);
2429 return unless $self->user->wantpc16;
2432 broadcast_route($self, $origin, \&pc16, $line, 1, @_);
2438 return unless $self->user->wantpc16;
2441 broadcast_route($self, $origin, \&pc17, $line, 1, @_);
2449 broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
2457 broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
2465 broadcast_route($self, $origin, \&pc24, $line, 1, @_);
2473 broadcast_route($self, $origin, \&pc41, $line, 1, @_);
2481 broadcast_route($self, $origin, \&pc50, $line, 1, @_);
2488 my ($filter, $hops) = (1, 1);
2490 if ($self->{inroutefilter}) {
2491 ($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);
2492 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
2500 my $t = shift || $eph_restime;
2504 $s =~ s/\^H\d\d?\^?\~?$//;
2505 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
2506 $eph{$s} = $main::systime + $t;
2507 dbg("PCPROT: emphemeral duplicate") if $r && isdbg('chanerr');
2515 while (($key, $val) = each %eph) {
2516 if ($key =~ m{$regex}) {
2526 while (($key, $val) = each %eph) {
2527 if ($main::systime >= $val) {
2538 while (($key, $val) = each %eph) {
2539 push @out, $key, $val;
2546 goto &DXCommandmode::run_cmd;
2550 # import any msgs in the chat directory
2551 # the messages are sent to the chat group which forms the
2552 # the first part of the name (eg: solar.1243.txt would be
2553 # sent to chat group SOLAR)
2555 # Each message found is sent: one non-blank line to one chat
2556 # message. So 4 lines = 4 chat messages.
2558 # The special name LOCAL is for local users ANN
2559 # The special name ALL is for ANN/FULL
2560 # The special name SYSOP is for ANN/SYSOP
2564 # are there any to do in this directory?
2565 return unless -d $chatimportfn;
2566 unless (opendir(DIR, $chatimportfn)) {
2567 dbg("can\'t open $chatimportfn $!") if isdbg('msg');
2568 Log('msg', "can\'t open $chatimportfn $!");
2572 my @names = readdir(DIR);
2575 foreach $name (@names) {
2576 next if $name =~ /^\./;
2577 my $splitit = $name =~ /^split/;
2578 my $fn = "$chatimportfn/$name";
2580 unless (open(MSG, $fn)) {
2581 dbg("can\'t open import file $fn $!") if isdbg('msg');
2582 Log('msg', "can\'t open import file $fn $!");
2586 my @msg = map { s/\r?\n$//; $_ } <MSG>;
2590 my @cat = split /\./, $name;
2591 my $target = uc $cat[0];
2593 foreach my $text (@msg) {
2594 next unless $text && $text !~ /^\s*#/;
2595 if ($target eq 'ALL' || $target eq 'LOCAL' || $target eq 'SYSOP') {
2596 my $sysopflag = $target eq 'SYSOP' ? '*' : ' ';
2597 if ($target ne 'LOCAL') {
2598 send_announce($main::me, pc12($main::mycall, $text, '*', $sysopflag), $main::mycall, '*', $text, $sysopflag, $main::mycall, '0');
2600 Log('ann', 'LOCAL', $main::mycall, $text);
2601 DXChannel::broadcast_list("To LOCAL de ${main::mycall}: $text\a", 'ann', undef, DXCommandmode->get_all());
2604 my $msgid = nextchatmsgid();
2605 $text = "#$msgid $text";
2606 send_chat($main::me, pc12($main::mycall, $text, '*', $target), $main::mycall, '*', $text, $target, $main::mycall, '0');