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
55 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
56 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
58 $last_hour = time; # last time I did an hourly periodic update
59 %rcmds = (); # outstanding rcmd requests outbound
60 %nodehops = (); # node specific hop control
61 %pc19list = (); # list of outstanding PC19s that haven't had PC16s on them
63 $censorpc = 1; # Do a BadWords::check on text fields and reject things
64 # loads of 'bad things'
65 $baddx = new DXHash "baddx";
66 $badspotter = new DXHash "badspotter";
67 $badnode = new DXHash "badnode";
68 $last10 = $last_pc50 = time;
72 $eph_info_restime = 60*60;
73 $eph_pc34_restime = 30;
76 $chatdupeage = 20 * 60 * 60;
77 $chatimportfn = "$main::root/chat_import";
78 $investigation_int = 12*60*60; # time between checks to see if we can see this node
79 $pc19_version = 5466; # the visible version no for outgoing PC19s generated from pc59
80 $handle_xml = 0; # handle XML sentences
84 [ qw(i c c m bp bc c) ], # pc10
85 [ qw(i f bm d t m c c h) ], # pc11
86 [ qw(i c bm m bm bm p h) ], # pc12
90 undef , # pc16 has to be validated manually
91 [ qw(i c c h) ], # pc17
93 undef , # pc19 has to be validated manually
94 undef , # pc20 no validation
95 [ qw(i c m h) ], # pc21
96 undef , # pc22 no validation
97 [ qw(i d n n n n m c c h) ], # pc23
98 [ qw(i c p h) ], # pc24
99 [ qw(i c c n n) ], # pc25
100 [ qw(i f m d t m c c bc) ], # pc26
101 [ qw(i d n n n n m c c bc) ], # pc27
102 [ qw(i c c m c d t p m bp n p bp bc) ], # pc28
103 [ qw(i c c n m) ], # pc29
104 [ qw(i c c n) ], # pc30
105 [ qw(i c c n) ], # pc31
106 [ qw(i c c n) ], # pc32
107 [ qw(i c c n) ], # pc33
108 [ qw(i c c m) ], # pc34
109 [ qw(i c c m) ], # pc35
110 [ qw(i c c m) ], # pc36
111 [ qw(i c c n m) ], # pc37
112 undef, # pc38 not interested
113 [ qw(i c m) ], # pc39
114 [ qw(i c c m p n) ], # pc40
115 [ qw(i c n m h) ], # pc41
116 [ qw(i c c n) ], # pc42
117 undef, # pc43 don't handle it
118 [ qw(i c c n m m c) ], # pc44
119 [ qw(i c c n m) ], # pc45
120 [ qw(i c c n) ], # pc46
123 [ qw(i c m h) ], # pc49
124 [ qw(i c n h) ], # pc50
125 [ qw(i c c n) ], # pc51
147 [ qw(i d n n n n n n m m m c c h) ], # pc73
158 [ qw(i c c c m) ], # pc84
159 [ qw(i c c c m) ], # pc85
164 [ qw(i c n) ], # pc90
167 # use the entry in the check list to check the field list presented
168 # return OK if line NOT in check list (for now)
173 return 0 if $n < 0 || $n > @checklist;
174 my $ref = $checklist[$n];
175 return 0 unless ref $ref;
178 for ($i = 1; $i < @$ref; $i++) {
179 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
180 return 0 unless $act;
181 next if $blank && $_[$i] =~ /^[ \*]$/;
183 return $i unless is_callsign($_[$i]);
184 } elsif ($act eq 'i') {
186 } elsif ($act eq 'm') {
187 return $i unless is_pctext($_[$i]);
188 } elsif ($act eq 'p') {
189 return $i unless is_pcflag($_[$i]);
190 } elsif ($act eq 'f') {
191 return $i unless is_freq($_[$i]);
192 } elsif ($act eq 'n') {
193 return $i unless $_[$i] =~ /^[\d ]+$/;
194 } elsif ($act eq 'h') {
195 return $i unless $_[$i] =~ /^H\d\d?$/;
196 } elsif ($act eq 'd') {
197 return $i unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
198 } elsif ($act eq 't') {
199 return $i unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
207 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
210 my $user = DXUser->get($main::mycall);
211 die "User $main::mycall not setup or disappeared RTFM" unless $user;
213 $myprot_version += $main::version*100;
214 $main::me = DXProt->new($main::mycall, 0, $user);
215 $main::me->{here} = 1;
216 $main::me->{state} = "indifferent";
217 $main::me->{sort} = 'S'; # S for spider
218 $main::me->{priv} = 9;
219 $main::me->{metric} = 0;
220 $main::me->{pingave} = 0;
221 $main::me->{registered} = 1;
222 $main::me->{version} = $main::version;
223 $main::me->{build} = $main::build;
227 # obtain a new connection this is derived from dxchannel
232 my $self = DXChannel::alloc(@_);
234 # add this node to the table, the values get filled in later
237 $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
242 # this is how a pc connection starts (for an incoming connection)
243 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
244 # all the crap that comes between).
247 my ($self, $line, $sort) = @_;
248 my $call = $self->{call};
249 my $user = $self->{user};
252 my $host = $self->{conn}->{peerhost};
253 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
256 Log('DXProt', "$call connected from $host");
258 # remember type of connection
259 $self->{consort} = $line;
260 $self->{outbound} = $sort eq 'O';
261 my $priv = $user->priv;
262 $priv = $user->priv(1) unless $priv;
263 $self->{priv} = $priv; # other clusters can always be 'normal' users
264 $self->{lang} = $user->lang || 'en';
265 $self->{isolate} = $user->{isolate};
266 $self->{consort} = $line; # save the connection type
270 # sort out registration
271 $self->{registered} = 1;
273 # get the output filters
274 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
275 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
276 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
277 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
278 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
281 # get the INPUT filters (these only pertain to Clusters)
282 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
283 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
284 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
285 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
286 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
288 # set unbuffered and no echo
289 $self->send_now('B',"0");
290 $self->send_now('E',"0");
291 $self->conn->echo(0) if $self->conn->can('echo');
293 # ping neighbour node stuff
294 my $ping = $user->pingint;
295 $ping = $pingint unless defined $ping;
296 $self->{pingint} = $ping;
297 $self->{nopings} = $user->nopings || $obscount;
298 $self->{pingtime} = [ ];
299 $self->{pingave} = 999;
300 $self->{metric} ||= 100;
301 $self->{lastping} = $main::systime;
303 # send initialisation string
304 unless ($self->{outbound}) {
308 $self->state('init');
309 $self->{pc50_t} = $main::systime;
311 # send info to all logged in thingies
312 $self->tell_login('loginn');
314 # run a script send the output to the debug file
315 my $script = new Script(lc $call) || new Script('node_default');
316 $script->run($self) if $script;
320 # send outgoing 'challenge'
330 # This is the normal pcxx despatcher
334 my ($self, $line) = @_;
336 if ($line =~ '^<\w+\s') {
337 DXXml::normal($self, $line);
341 my @field = split /\^/, $line;
342 return unless @field;
344 pop @field if $field[-1] eq '~';
346 # print join(',', @field), "\n";
349 # process PC frames, this will fail unless the frame starts PCnn
350 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
351 unless (defined $pcno && $pcno >= 10 && $pcno <= 99) {
352 dbg("PCPROT: unknown protocol") if isdbg('chanerr');
356 # check for and dump bad protocol messages
357 my $n = check($pcno, @field);
359 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
363 my $origin = $self->{call};
365 my $sub = "handle_$pcno";
367 if ($self->can($sub)) {
368 $self->$sub($pcno, $line, $origin, @field);
370 $self->handle_default($pcno, $line, $origin, @field);
374 # incoming talk commands
383 return if $rspfcheck and !$self->rspfcheck(0, $_[6], $_[1]);
385 # will we allow it at all?
388 if (@bad = BadWords::check($_[3])) {
389 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
394 # is it for me or one of mine?
395 my ($from, $to, $via, $call, $dxchan);
404 # if this is a 'nodx' node then ignore it
405 if ($badnode->in($_[6]) || ($via && $badnode->in($via))) {
406 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
410 # if this is a 'bad spotter' user then ignore it
412 $nossid =~ s/-\d+$//;
413 if ($badspotter->in($nossid)) {
414 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
418 # if we are converting announces to talk is it a dup?
420 if (AnnTalk::is_talk_candidate($from, $_[3]) && AnnTalk::dup($from, $to, $_[3])) {
421 dbg("DXPROT: Dupe talk from announce, dropped") if isdbg('chanerr');
426 # remember a route to this node and also the node on which this user is
427 RouteDB::update($_[6], $self->{call});
428 # RouteDB::update($to, $_[6]);
430 # it is here and logged on
431 $dxchan = DXChannel::get($main::myalias) if $to eq $main::mycall;
432 $dxchan = DXChannel::get($to) unless $dxchan;
433 if ($dxchan && $dxchan->is_user) {
435 $dxchan->talk($from, $to, $via, $_[3]);
439 # is it elsewhere, visible on the cluster via the to address?
440 # note: this discards the via unless the to address is on
443 if ($ref = Route::get($to)) {
444 $vref = Route::Node::get($via) if $via;
445 $vref = undef unless $vref && grep $to eq $_, $vref->users;
446 $ref->dxchan->talk($from, $to, $vref ? $via : undef, $_[3], $_[6]);
450 # can we see an interface to send it down?
452 # not visible here, send a message of condolence
454 $ref = Route::get($from);
455 $vref = $ref = Route::Node::get($_[6]) unless $ref;
457 $dxchan = $ref->dxchan;
458 $dxchan->talk($main::mycall, $from, $vref ? $vref->call : undef, $dxchan->msg('talknh', $to) );
470 # route 'foreign' pc26s
472 if ($_[7] ne $main::mycall) {
473 $self->route($_[7], $line);
479 # return if $rspfcheck and !$self->rspfcheck(1, $_[7], $_[6]);
481 # if this is a 'nodx' node then ignore it
482 if ($badnode->in($_[7])) {
483 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
487 # if this is a 'bad spotter' user then ignore it
489 $nossid =~ s/-\d+$//;
490 if ($badspotter->in($nossid)) {
491 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
495 # convert the date to a unix date
496 my $d = cltounix($_[3], $_[4]);
497 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
498 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
499 dbg("PCPROT: Spot ignored, invalid date or out of range ($_[3] $_[4])\n") if isdbg('chanerr');
504 if ($baddx->in($_[2]) || BadWords::check($_[2]) || $_[2] =~ /COCK/) {
505 dbg("PCPROT: Bad DX spot, ignored") if isdbg('chanerr');
510 $_[5] =~ s/^\s+//; # take any leading blanks off
511 $_[2] = unpad($_[2]); # take off leading and trailing blanks from spotted callsign
512 if ($_[2] =~ /BUST\w*$/) {
513 dbg("PCPROT: useless 'BUSTED' spot") if isdbg('chanerr');
518 if (@bad = BadWords::check($_[5])) {
519 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
525 # RouteDB::update($_[7], $self->{call});
526 # RouteDB::update($_[6], $_[7]);
528 my @spot = Spot::prepare($_[1], $_[2], $d, $_[5], $nossid, $_[7]);
529 # global spot filtering on INPUT
530 if ($self->{inspotsfilter}) {
531 my ($filter, $hops) = $self->{inspotsfilter}->it(@spot);
533 dbg("PCPROT: Rejected by input spot filter") if isdbg('chanerr');
538 # this goes after the input filtering, but before the add
539 # so that if it is input filtered, it isn't added to the dup
540 # list. This allows it to come in from a "legitimate" source
541 if (Spot::dup(@spot[0..4,5])) {
542 dbg("PCPROT: Duplicate Spot ignored\n") if isdbg('chanerr');
550 # @spot at this point contains:-
551 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
552 # then spotted itu, spotted cq, spotters itu, spotters cq
553 # you should be able to route on any of these
556 # fix up qra locators of known users
557 my $user = DXUser->get_current($spot[4]);
559 my $qra = $user->qra;
560 unless ($qra && is_qra($qra)) {
561 my $lat = $user->lat;
562 my $long = $user->long;
563 if (defined $lat && defined $long) {
564 $user->qra(DXBearing::lltoqra($lat, $long));
569 # send a remote command to a distant cluster if it is visible and there is no
570 # qra locator and we havn't done it for a month.
572 unless ($user->qra) {
574 my $to = $user->homenode;
575 my $last = $user->lastoper || 0;
576 if ($send_opernam && $to && $to ne $main::mycall && $main::systime > $last + $DXUser::lastoperinterval && ($node = Route::Node::get($to)) ) {
577 my $cmd = "forward/opernam $spot[4]";
578 # send the rcmd but we aren't interested in the replies...
579 my $dxchan = $node->dxchan;
580 if ($dxchan && $dxchan->is_clx) {
581 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
583 route(undef, $to, pc34($main::mycall, $to, $cmd));
587 $node = Route::Node::get($to);
589 $dxchan = $node->dxchan;
590 if ($dxchan && $dxchan->is_clx) {
591 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
593 route(undef, $to, pc34($main::mycall, $to, $cmd));
597 $user->lastoper($main::systime);
606 $r = Local::spot($self, @spot);
608 # dbg("Local::spot1 error $@") if isdbg('local') if $@;
611 # DON'T be silly and send on PC26s!
612 return if $pcno == 26;
614 # send out the filtered spots
615 send_dx_spot($self, $line, @spot) if @spot;
626 # return if $rspfcheck and !$self->rspfcheck(1, $_[5], $_[1]);
628 # announce duplicate checking
629 $_[3] =~ s/^\s+//; # remove leading blanks
633 if (@bad = BadWords::check($_[3])) {
634 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
639 # if this is a 'nodx' node then ignore it
640 if ($badnode->in($_[5])) {
641 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
645 # if this is a 'bad spotter' user then ignore it
647 $nossid =~ s/-\d+$//;
648 if ($badspotter->in($nossid)) {
649 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
656 if ((($dxchan = DXChannel::get($_[2])) && $dxchan->is_user) || $_[4] =~ /^[\#\w.]+$/){
657 $self->send_chat($line, @_[1..6]);
658 } elsif ($_[2] eq '*' || $_[2] eq $main::mycall) {
661 # RouteDB::update($_[5], $self->{call});
662 # RouteDB::update($_[1], $_[5]);
664 # ignore something that looks like a chat line coming in with sysop
665 # flag - this is a kludge...
666 if ($_[3] =~ /^\#\d+ / && $_[4] eq '*') {
667 dbg('PCPROT: Probable chat rewrite, dropped') if isdbg('chanerr');
671 # here's a bit of fun, convert incoming ann with a callsign in the first word
672 # or one saying 'to <call>' to a talk if we can route to the recipient
674 my $call = AnnTalk::is_talk_candidate($_[1], $_[3]);
676 my $ref = Route::get($call);
678 $dxchan = $ref->dxchan;
679 $dxchan->talk($_[1], $call, undef, $_[3], $_[5]) if $dxchan != $self;
686 $self->send_announce($line, @_[1..6]);
688 $self->route($_[2], $line);
703 my $newline = "PC16^";
705 # dos I want users from this channel?
706 unless ($self->user->wantpc16) {
707 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
711 if ($ncall eq $main::mycall) {
712 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
716 RouteDB::update($ncall, $self->{call});
718 # do we believe this call?
719 unless ($ncall eq $self->{call} || $self->is_believed($ncall)) {
720 if (my $ivp = Investigate::get($ncall, $self->{call})) {
721 $ivp->store_pcxx($pcno,$line,$origin,@_);
723 dbg("PCPROT: We don't believe $ncall on $self->{call}") if isdbg('chanerr');
728 if (eph_dup($line)) {
729 dbg("PCPROT: dup PC16 detected") if isdbg('chanerr');
733 my $parent = Route::Node::get($ncall);
735 # if there is a parent, proceed, otherwise if there is a latent PC19 in the PC19list,
736 # fix it up in the routing tables and issue it forth before the PC16
738 my $nl = $pc19list{$ncall};
740 if ($nl && @_ > 3) { # 3 because of the hop count!
742 # this is a new (remembered) node, now attach it to me if it isn't in filtered
743 # and we haven't disallowed it
744 my $user = DXUser->get_current($ncall);
746 $user = DXUser->new($ncall);
748 $user->priv(1); # I have relented and defaulted nodes
750 $user->homenode($ncall);
754 my $wantpc19 = $user->wantroutepc19;
755 if ($wantpc19 || !defined $wantpc19) {
756 my $new = Route->new($ncall); # throw away
757 if ($self->in_filter_route($new)) {
760 $parent = Route::Node::get($_->[0]);
761 $dxchan = $parent->dxchan if $parent;
762 if ($dxchan && $dxchan ne $self) {
763 dbg("PCPROT: PC19 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
767 my $r = $parent->add($ncall, $_->[1], $_->[2]);
768 push @nrout, $r unless @nrout;
771 $user->wantroutepc19(1) unless defined $wantpc19; # for now we work on the basis that pc16 = real route
772 $user->lastin($main::systime) unless DXChannel::get($ncall);
775 # route the pc19 - this will cause 'stuttering PC19s' for a while
776 $self->route_pc19($origin, $line, @nrout) if @nrout ;
777 $parent = Route::Node::get($ncall);
779 dbg("PCPROT: lost $ncall after sending PC19 for it?");
785 delete $pc19list{$ncall};
788 dbg("PCPROT: Node $ncall not in config") if isdbg('chanerr');
793 $dxchan = $parent->dxchan;
794 if ($dxchan && $dxchan ne $self) {
795 dbg("PCPROT: PC16 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
799 # input filter if required
800 return unless $self->in_filter_route($parent);
805 for ($i = 2; $i < $#_; $i++) {
806 my ($call, $conf, $here) = $_[$i] =~ /^(\S+) (\S) (\d)/o;
807 next unless $call && $conf && defined $here && is_callsign($call);
808 next if $call eq $main::mycall;
810 eph_del_regex("^PC17\\^$call\\^$ncall");
812 $conf = $conf eq '*';
814 # reject this if we think it is a node already
815 my $r = Route::Node::get($call);
816 my $u = DXUser->get_current($call) unless $r;
817 if ($r || ($u && $u->is_node)) {
818 dbg("PCPROT: $call is a node") if isdbg('chanerr');
822 $r = Route::User::get($call);
823 my $flags = Route::here($here)|Route::conf($conf);
826 my $au = $r->addparent($parent);
827 if ($r->flags != $flags) {
831 push @rout, $r if $au;
833 push @rout, $parent->add_user($call, $flags);
837 # add this station to the user database, if required
838 $call =~ s/-\d+$//o; # remove ssid for users
839 my $user = DXUser->get_current($call);
840 $user = DXUser->new($call) if !$user;
841 $user->homenode($parent->call) if !$user->homenode;
842 $user->node($parent->call);
843 $user->lastin($main::systime) unless DXChannel::get($call);
846 $self->route_pc16($origin, $line, $parent, @rout) if @rout;
860 eph_del_regex("^PC16\\^$ncall.*$ucall");
862 # do I want users from this channel?
863 unless ($self->user->wantpc16) {
864 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
867 if ($ncall eq $main::mycall) {
868 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
872 RouteDB::delete($ncall, $self->{call});
874 # do we believe this call?
875 unless ($ncall eq $self->{call} || $self->is_believed($ncall)) {
876 if (my $ivp = Investigate::get($ncall, $self->{call})) {
877 $ivp->store_pcxx($pcno,$line,$origin,@_);
879 dbg("PCPROT: We don't believe $ncall on $self->{call}") if isdbg('chanerr');
884 my $uref = Route::User::get($ucall);
886 dbg("PCPROT: Route::User $ucall not in config") if isdbg('chanerr');
888 my $parent = Route::Node::get($ncall);
890 dbg("PCPROT: Route::Node $ncall not in config") if isdbg('chanerr');
893 $dxchan = $parent->dxchan if $parent;
894 if ($dxchan && $dxchan ne $self) {
895 dbg("PCPROT: PC17 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
899 # input filter if required and then remove user if present
901 # return unless $self->in_filter_route($parent);
902 $parent->del_user($uref) if $uref;
904 $parent = Route->new($ncall); # throw away
907 if (eph_dup($line)) {
908 dbg("PCPROT: dup PC17 detected") if isdbg('chanerr');
912 $uref = Route->new($ucall) unless $uref; # throw away
913 $self->route_pc17($origin, $line, $parent, $uref);
923 $self->state('init');
925 # record the type and version offered
926 if ($_[1] =~ /DXSpider Version: (\d+\.\d+) Build: (\d+\.\d+)/) {
927 $self->version(53 + $1);
928 $self->user->version(53 + $1);
929 $self->build(0 + $2);
930 $self->user->build(0 + $2);
931 unless ($self->is_spider) {
932 $self->user->sort('S');
936 $self->{handle_xml}++ if $main::do_xml && $_[1] =~ /\bxml\b/;
938 $self->version(50.0);
939 $self->version($_[2] / 100) if $_[2] && $_[2] =~ /^\d+$/;
940 $self->user->version($self->version);
943 # first clear out any nodes on this dxchannel
944 my $parent = Route::Node::get($self->{call});
945 my @rout = $parent->del_nodes;
946 $self->route_pc21($origin, $line, @rout, $parent) if @rout;
947 $self->send_local_config();
951 # incoming cluster list
960 my $newline = "PC19^";
965 # first get the INTERFACE node
966 my $parent = Route::Node::get($self->{call});
968 dbg("DXPROT: my parent $self->{call} has disappeared");
973 # if the origin isn't the same as the INTERFACE, then reparent, creating nodes as necessary
974 if ($origin ne $self->call) {
975 my $op = Route::Node::get($origin);
977 $op = $parent->add($origin, 5000, Route::here(1));
978 my $user = DXUser->get_current($origin);
980 $user = DXUser->new($origin);
981 $user->priv(1); # I have relented and defaulted nodes
983 $user->homenode($origin);
984 $user->node($origin);
985 $user->wantroutepc19(1);
987 $user->sort('A') unless $user->is_node;
994 for ($i = 1; $i < $#_-1; $i += 4) {
996 my $call = uc $_[$i+1];
999 next unless defined $here && defined $conf && is_callsign($call);
1001 eph_del_regex("^PC(?:21\\^$call|17\\^[^\\^]+\\^$call)");
1003 # check for sane parameters
1004 # $ver = 5000 if $ver eq '0000';
1005 next if $ver < 5000; # only works with version 5 software
1006 next if length $call < 3; # min 3 letter callsigns
1007 next if $call eq $main::mycall;
1009 # check that this PC19 isn't trying to alter the wrong dxchan
1010 my $dxchan = DXChannel::get($call);
1011 if ($dxchan && $dxchan != $self) {
1012 dbg("PCPROT: PC19 from $self->{call} trying to alter wrong locally connected $call, ignored!") if isdbg('chanerr');
1016 # add this station to the user database, if required (don't remove SSID from nodes)
1017 my $user = DXUser->get_current($call);
1019 $user = DXUser->new($call);
1020 $user->priv(1); # I have relented and defaulted nodes
1022 $user->homenode($call);
1025 $user->sort('A') unless $user->is_node;
1027 RouteDB::update($call, $self->{call});
1029 # do we believe this call?
1030 my $genline = "PC19^$here^$call^$conf^$ver^$_[-1]^";
1031 unless ($call eq $self->{call} || $self->is_believed($call)) {
1032 my $pt = $user->lastping($self->{call}) || 0;
1033 if ($pt+$investigation_int < $main::systime && !Investigate::get($call, $self->{call})) {
1034 my $ivp = Investigate->new($call, $self->{call});
1035 $ivp->version($ver);
1037 $ivp->store_pcxx($pcno,$genline,$origin,'PC19',$here,$call,$conf,$ver,$_[-1]);
1039 dbg("PCPROT: We don't believe $call on $self->{call}") if isdbg('chanerr');
1045 if (eph_dup($genline)) {
1046 dbg("PCPROT: dup PC19 for $call detected") if isdbg('chanerr');
1050 my $r = Route::Node::get($call);
1051 my $flags = Route::here($here)|Route::conf($conf);
1053 # modify the routing table if it is in it, otherwise store it in the pc19list for now
1056 if ($call ne $parent->call) {
1057 if ($self->in_filter_route($r)) {
1058 $ar = $parent->add($call, $ver, $flags);
1059 push @rout, $ar if $ar;
1064 if ($r->version ne $ver || $r->flags != $flags) {
1067 push @rout, $r unless $ar;
1071 # if he is directly connected or allowed then add him, otherwise store him up for later
1072 if ($call eq $self->{call} || $user->wantroutepc19) {
1073 my $new = Route->new($call); # throw away
1074 if ($self->in_filter_route($new)) {
1075 my $ar = $parent->add($call, $ver, $flags);
1076 $user->wantroutepc19(1) unless defined $user->wantroutepc19;
1077 push @rout, $ar if $ar;
1082 $pc19list{$call} = [] unless exists $pc19list{$call};
1083 my $nl = $pc19list{$call};
1084 push @{$pc19list{$call}}, [$self->{call}, $ver, $flags] unless grep $_->[0] eq $self->{call}, @$nl;
1088 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
1089 my $mref = DXMsg::get_busy($call);
1090 $mref->stop_msg($call) if $mref;
1092 $user->lastin($main::systime) unless DXChannel::get($call);
1097 $self->route_pc19($origin, $line, @rout) if @rout;
1100 # send local configuration
1107 $self->send_local_config();
1108 $self->send(pc22());
1109 $self->state('normal');
1110 $self->{lastping} = 0;
1113 # delete a cluster from the list
1120 my $call = uc $_[1];
1122 eph_del_regex("^PC1[679].*$call");
1124 # if I get a PC21 from the same callsign as self then treat it
1125 # as a PC39: I have gone away
1126 if ($call eq $self->call) {
1127 $self->disconnect(1);
1131 RouteDB::delete($call, $self->{call});
1133 # check if we believe this
1134 unless ($call eq $self->{call} || $self->is_believed($call)) {
1135 if (my $ivp = Investigate::get($call, $self->{call})) {
1136 $ivp->store_pcxx($pcno,$line,$origin,@_);
1138 dbg("PCPROT: We don't believe $call on $self->{call}") if isdbg('chanerr');
1143 # check to see if we are in the pc19list, if we are then don't bother with any of
1144 # this routing table manipulation, just remove it from the list and dump it
1146 if (my $nl = $pc19list{$call}) {
1147 $pc19list{$call} = [ grep {$_->[0] ne $self->{call}} @$nl ];
1148 delete $pc19list{$call} unless @{$pc19list{$call}};
1151 my $parent = Route::Node::get($self->{call});
1153 dbg("DXPROT: my parent $self->{call} has disappeared");
1157 if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
1158 my $node = Route::Node::get($call);
1161 my $dxchan = DXChannel::get($call);
1162 if ($dxchan && $dxchan != $self) {
1163 dbg("PCPROT: PC21 from $self->{call} trying to alter locally connected $call, ignored!") if isdbg('chanerr');
1168 return unless $self->in_filter_route($node);
1171 push @rout, $node->del($parent);
1174 dbg("PCPROT: I WILL _NOT_ be disconnected!") if isdbg('chanerr');
1179 $self->route_pc21($origin, $line, @rout) if @rout;
1189 $self->state('normal');
1190 $self->{lastping} = 0;
1201 # route foreign' pc27s
1203 if ($_[8] ne $main::mycall) {
1204 $self->route($_[8], $line);
1209 # only do a rspf check on PC23 (not 27)
1211 return if $rspfcheck and !$self->rspfcheck(1, $_[8], $_[7])
1215 my $d = cltounix($_[1], sprintf("%02d18Z", $_[2]));
1216 my $sfi = unpad($_[3]);
1217 my $k = unpad($_[4]);
1218 my $i = unpad($_[5]);
1219 my ($r) = $_[6] =~ /R=(\d+)/;
1221 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1222 dbg("PCPROT: WWV Date ($_[1] $_[2]) out of range") if isdbg('chanerr');
1226 # global wwv filtering on INPUT
1227 my @dxcc = ((Prefix::cty_data($_[7]))[0..2], (Prefix::cty_data($_[8]))[0..2]);
1228 if ($self->{inwwvfilter}) {
1229 my ($filter, $hops) = $self->{inwwvfilter}->it(@_[7,8], $origin, @dxcc);
1231 dbg("PCPROT: Rejected by input wwv filter") if isdbg('chanerr');
1235 $_[7] =~ s/-\d+$//o; # remove spotter's ssid
1236 if (Geomag::dup($d,$sfi,$k,$i,$_[6],$_[7])) {
1237 dbg("PCPROT: Dup WWV Spot ignored\n") if isdbg('chanerr');
1241 # note this only takes the first one it gets
1242 Geomag::update($d, $_[2], $sfi, $k, $i, @_[6..8], $r);
1246 $rep = Local::wwv($self, $_[1], $_[2], $sfi, $k, $i, @_[6..8], $r);
1248 # dbg("Local::wwv2 error $@") if isdbg('local') if $@;
1251 # DON'T be silly and send on PC27s!
1252 return if $pcno == 27;
1254 # broadcast to the eager world
1255 send_wwv_spot($self, $line, $d, $_[2], $sfi, $k, $i, @_[6..8]);
1265 my $call = uc $_[1];
1267 $nref = Route::Node::get($call);
1268 $uref = Route::User::get($call);
1269 return unless $nref || $uref; # if we don't know where they are, it's pointless sending it on
1271 if (eph_dup($line)) {
1272 dbg("PCPROT: Dup PC24 ignored\n") if isdbg('chanerr');
1276 $nref->here($_[2]) if $nref;
1277 $uref->here($_[2]) if $uref;
1278 my $ref = $nref || $uref;
1279 return unless $self->in_filter_route($ref);
1281 $self->route_pc24($origin, $line, $ref, $_[3]);
1291 if ($_[1] ne $main::mycall) {
1292 $self->route($_[1], $line);
1295 if ($_[2] eq $main::mycall) {
1296 dbg("PCPROT: Trying to merge to myself, ignored") if isdbg('chanerr');
1300 Log('DXProt', "Merge request for $_[3] spots and $_[4] WWV from $_[2]");
1304 my @in = reverse Spot::search(1, undef, undef, 0, $_[3]);
1307 $self->send(pc26(@{$in}[0..4], $_[2]));
1313 my @in = reverse Geomag::search(0, $_[4], time, 1);
1316 $self->send(pc27(@{$in}[0..5], $_[2]));
1321 sub handle_26 {goto &handle_11}
1322 sub handle_27 {goto &handle_23}
1324 # mail/file handling
1331 if ($_[1] eq $main::mycall) {
1333 my $sub = "DXMsg::handle_$pcno";
1336 $self->route($_[1], $line) unless $self->is_clx;
1340 sub handle_29 {goto &handle_28}
1341 sub handle_30 {goto &handle_28}
1342 sub handle_31 {goto &handle_28}
1343 sub handle_32 {goto &handle_28}
1344 sub handle_33 {goto &handle_28}
1352 if (eph_dup($line, $eph_pc34_restime)) {
1353 dbg("PCPROT: dupe PC34, ignored") if isdbg('chanerr');
1355 $self->process_rcmd($_[1], $_[2], $_[2], $_[3]);
1359 # remote command replies
1366 eph_del_regex("^PC35\\^$_[2]\\^$_[1]\\^");
1367 $self->process_rcmd_reply($_[1], $_[2], $_[1], $_[3]);
1370 sub handle_36 {goto &handle_34}
1379 if ($_[1] eq $main::mycall) {
1381 my $sub = "DXDb::handle_$pcno";
1384 $self->route($_[1], $line) unless $self->is_clx;
1388 # node connected list from neighbour
1397 # incoming disconnect
1404 if ($_[1] eq $self->{call}) {
1405 $self->disconnect(1);
1407 dbg("PCPROT: came in on wrong channel") if isdbg('chanerr');
1411 sub handle_40 {goto &handle_28}
1423 $l =~ s/[\x00-\x20\x7f-\xff]+//g; # remove all funny characters and spaces for dup checking
1424 if (eph_dup($l, $eph_info_restime)) {
1425 dbg("PCPROT: dup PC41, ignored") if isdbg('chanerr');
1429 # input filter if required
1430 # my $ref = Route::get($call) || Route->new($call);
1431 # return unless $self->in_filter_route($ref);
1433 if ($_[3] eq $_[2] || $_[3] =~ /^\s*$/) {
1434 dbg('PCPROT: invalid value') if isdbg('chanerr');
1438 # add this station to the user database, if required
1439 my $user = DXUser->get_current($call);
1440 $user = DXUser->new($call) unless $user;
1444 } elsif ($_[2] == 2) {
1446 } elsif ($_[2] == 3) {
1447 if (is_latlong($_[3])) {
1448 my ($lat, $long) = DXBearing::stoll($_[3]);
1451 $user->qra(DXBearing::lltoqra($lat, $long));
1453 dbg('PCPROT: not a valid lat/long') if isdbg('chanerr');
1456 } elsif ($_[2] == 4) {
1457 $user->homenode($_[3]);
1458 } elsif ($_[2] == 5) {
1459 if (is_qra(uc $_[3])) {
1460 my ($lat, $long) = DXBearing::qratoll(uc $_[3]);
1463 $user->qra(uc $_[3]);
1465 dbg('PCPROT: not a valid QRA locator') if isdbg('chanerr');
1469 $user->lastoper($main::systime); # to cut down on excessive for/opers being generated
1472 unless ($self->{isolate}) {
1473 DXChannel::broadcast_nodes($line, $self); # send it to everyone but me
1476 # perhaps this IS what we want after all
1477 # $self->route_pc41($ref, $call, $_[2], $_[3], $_[4]);
1480 sub handle_42 {goto &handle_28}
1484 sub handle_44 {goto &handle_37}
1485 sub handle_45 {goto &handle_37}
1486 sub handle_46 {goto &handle_37}
1487 sub handle_47 {goto &handle_37}
1488 sub handle_48 {goto &handle_37}
1490 # message and database
1498 if (eph_dup($line)) {
1499 dbg("PCPROT: Dup PC49 ignored\n") if isdbg('chanerr');
1503 if ($_[1] eq $main::mycall) {
1504 DXMsg::handle_49($self, @_);
1506 $self->route($_[1], $line) unless $self->is_clx;
1510 # keep alive/user list
1520 RouteDB::update($call, $self->{call});
1522 my $node = Route::Node::get($call);
1524 return unless $node->call eq $self->{call};
1525 $node->usercount($_[2]);
1527 # input filter if required
1528 return unless $self->in_filter_route($node);
1530 $self->route_pc50($origin, $line, $node, $_[2], $_[3]) unless eph_dup($line);
1534 # incoming ping requests/answers
1547 if ($to eq $main::mycall) {
1549 $self->send(pc51($from, $to, '0'));
1551 DXXml::Ping::handle_ping_reply($self, $from);
1555 RouteDB::update($from, $self->{call});
1557 if (eph_dup($line)) {
1558 dbg("PCPROT: dup PC51 detected") if isdbg('chanerr');
1561 # route down an appropriate thingy
1562 $self->route($to, $line);
1566 # dunno but route it
1574 if ($call ne $main::mycall) {
1575 $self->route($call, $line);
1589 my $d = cltounix($call, sprintf("%02d18Z", $_[2]));
1590 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1591 dbg("PCPROT: WCY Date ($call $_[2]) out of range") if isdbg('chanerr');
1594 @_ = map { unpad($_) } @_;
1596 dbg("PCPROT: Dup WCY Spot ignored\n") if isdbg('chanerr');
1600 my $wcy = WCY::update($d, @_[2..12]);
1604 $rep = Local::wcy($self, @_[1..12]);
1606 # dbg("Local::wcy error $@") if isdbg('local') if $@;
1609 # broadcast to the eager world
1610 send_wcy_spot($self, $line, $d, @_[2..12]);
1613 # remote commands (incoming)
1620 $self->process_rcmd($_[1], $_[2], $_[3], $_[4]);
1623 # remote command replies
1630 $self->process_rcmd_reply($_[1], $_[2], $_[3], $_[4]);
1633 # if get here then rebroadcast the thing with its Hop count decremented (if
1634 # there is one). If it has a hop count and it decrements to zero then don't
1637 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
1648 if (eph_dup($line)) {
1649 dbg("PCPROT: Ephemeral dup, dropped") if isdbg('chanerr');
1651 unless ($self->{isolate}) {
1652 DXChannel::broadcast_nodes($line, $self) if $line =~ /\^H\d+\^?~?$/; # send it to everyone but me
1658 # This is called from inside the main cluster processing loop and is used
1659 # for despatching commands that are doing some long processing job
1664 my @dxchan = DXChannel::get_all();
1668 # send out a pc50 on EVERY channel all at once
1669 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
1670 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
1675 foreach $dxchan (@dxchan) {
1676 next unless $dxchan->is_node;
1677 next if $dxchan->handle_xml;
1678 next if $dxchan == $main::me;
1681 $dxchan->send($pc50s) if $pc50s;
1683 # send a ping out on this channel
1684 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
1685 if ($dxchan->{nopings} <= 0) {
1686 $dxchan->disconnect;
1688 DXXml::Ping::add($main::me, $dxchan->call);
1689 $dxchan->{nopings} -= 1;
1690 $dxchan->{lastping} = $t;
1691 $dxchan->{lastping} += $dxchan->{pingint} / 2 unless @{$dxchan->{pingtime}};
1696 Investigate::process();
1699 if ($t - $last10 >= 10) {
1700 # clean out ephemera
1709 if ($main::systime - 3600 > $last_hour) {
1710 $last_hour = $main::systime;
1715 # finish up a pc context
1719 # some active measures
1727 my @dxchan = DXChannel::get_all();
1730 # send it if it isn't the except list and isn't isolated and still has a hop count
1731 # taking into account filtering and so on
1732 foreach $dxchan (@dxchan) {
1733 next if $dxchan == $main::me;
1734 next if $dxchan == $self && $self->is_node;
1735 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
1743 my $isolate = shift;
1744 my ($filter, $hops);
1746 if ($self->{spotsfilter}) {
1747 ($filter, $hops) = $self->{spotsfilter}->it(@_);
1748 return unless $filter;
1750 send_prot_line($self, $filter, $hops, $isolate, $line);
1755 my ($self, $filter, $hops, $isolate, $line) = @_;
1761 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1763 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1764 return unless $routeit;
1767 $self->send($routeit);
1769 $self->send($routeit) unless $self->{isolate} || $isolate;
1778 my @dxchan = DXChannel::get_all();
1780 my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
1782 # send it if it isn't the except list and isn't isolated and still has a hop count
1783 # taking into account filtering and so on
1784 foreach $dxchan (@dxchan) {
1785 next if $dxchan == $main::me;
1786 next if $dxchan == $self && $self->is_node;
1788 my ($filter, $hops);
1790 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
1798 my $isolate = shift;
1799 my ($filter, $hops);
1801 if ($self->{wwvfilter}) {
1802 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_]);
1803 return unless $filter;
1805 send_prot_line($self, $filter, $hops, $isolate, $line)
1812 my @dxchan = DXChannel::get_all();
1814 my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
1816 # send it if it isn't the except list and isn't isolated and still has a hop count
1817 # taking into account filtering and so on
1818 foreach $dxchan (@dxchan) {
1819 next if $dxchan == $main::me;
1820 next if $dxchan == $self;
1822 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
1830 my $isolate = shift;
1831 my ($filter, $hops);
1833 if ($self->{wcyfilter}) {
1834 ($filter, $hops) = $self->{wcyfilter}->it(@_);
1835 return unless $filter;
1837 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
1845 my @dxchan = DXChannel::get_all();
1849 my $text = unpad($_[2]);
1851 if ($_[3] eq '*') { # sysops
1853 } elsif ($_[3] gt ' ') { # speciality list handling
1854 my ($name) = split /\./, $_[3];
1855 $target = "$name"; # put the rest in later (if bothered)
1862 $target = "ALL" if !$target;
1865 # obtain country codes etc
1866 my @a = Prefix::cty_data($_[0]);
1867 my @b = Prefix::cty_data($_[4]);
1868 if ($self->{inannfilter}) {
1869 my ($filter, $hops) =
1870 $self->{inannfilter}->it(@_, $self->{call},
1872 @b[0..2], $a[3], $b[3]);
1874 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1879 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
1880 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1884 Log('ann', $target, $_[0], $text);
1886 # send it if it isn't the except list and isn't isolated and still has a hop count
1887 # taking into account filtering and so on
1888 foreach $dxchan (@dxchan) {
1889 next if $dxchan == $main::me;
1890 next if $dxchan == $self && $self->is_node;
1891 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
1892 @a[0..2], @b[0..2]);
1901 $msgid = 1 if $msgid > 999;
1910 my @dxchan = DXChannel::get_all();
1913 my $text = unpad($_[2]);
1916 # munge the group and recast the line if required
1917 if ($target =~ s/\.LST$//) {
1921 # obtain country codes etc
1922 my @a = Prefix::cty_data($_[0]);
1923 my @b = Prefix::cty_data($_[4]);
1924 if ($self->{inannfilter}) {
1925 my ($filter, $hops) =
1926 $self->{inannfilter}->it(@_, $self->{call},
1928 @b[0..2], $a[3], $b[3]);
1930 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1935 if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
1936 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1941 Log('chat', $target, $_[0], $text);
1943 # send it if it isn't the except list and isn't isolated and still has a hop count
1944 # taking into account filtering and so on
1945 foreach $dxchan (@dxchan) {
1946 my $is_ak1a = $dxchan->is_ak1a;
1948 if ($dxchan->is_node) {
1949 next if $dxchan == $main::me;
1950 next if $dxchan == $self;
1951 next unless $dxchan->is_spider || $is_ak1a;
1952 next if $target eq 'LOCAL';
1953 if (!$ak1a_line && $is_ak1a) {
1954 $ak1a_line = DXProt::pc12($_[0], $text, $_[1], "$target.LST");
1958 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1],
1959 $text, @_, $self->{call}, @a[0..2], @b[0..2]);
1967 my $isolate = shift;
1971 my ($filter, $hops);
1973 if ($self->{annfilter}) {
1974 ($filter, $hops) = $self->{annfilter}->it(@_);
1975 return unless $filter;
1977 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
1986 sub send_local_config
1994 dbg('DXProt::send_local_config') if isdbg('trace');
1997 if ($self->{isolate}) {
1998 @localnodes = ( $main::routeroot );
1999 $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
2001 # create a list of all the nodes that are not connected to this connection
2002 # and are not themselves isolated, this to make sure that isolated nodes
2003 # don't appear outside of this node
2005 # send locally connected nodes
2006 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
2007 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
2008 $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
2011 my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
2013 for $node (@rawintcalls) {
2014 push @intcalls, $node unless grep $node eq $_, @intcalls;
2016 my $ref = Route::Node::get($self->{call});
2017 my @rnodes = $ref->nodes;
2018 for $node (@intcalls) {
2019 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
2021 $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
2024 # get all the users connected on the above nodes and send them out
2025 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
2027 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
2028 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
2030 dbg("sent a null value") if isdbg('chanerr');
2036 # route a message down an appropriate interface for a callsign
2038 # is called route(to, pcline);
2043 my ($self, $call, $line) = @_;
2045 if (ref $self && $call eq $self->{call}) {
2046 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
2050 # always send it down the local interface if available
2051 my $dxchan = DXChannel::get($call);
2053 dbg("route: $call -> $dxchan->{call} direct" ) if isdbg('route');
2055 my $cl = Route::get($call);
2056 $dxchan = $cl->dxchan if $cl;
2058 if (ref $self && $dxchan eq $self) {
2059 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
2062 dbg("route: $call -> $dxchan->{call} using normal route" ) if isdbg('route');
2066 # try the backstop method
2068 my $rcall = RouteDB::get($call);
2070 if ($self && $rcall eq $self->{call}) {
2071 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
2074 $dxchan = DXChannel::get($rcall);
2075 dbg("route: $call -> $rcall using RouteDB" ) if isdbg('route') && $dxchan;
2080 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
2082 $dxchan->send($routeit) unless $dxchan == $main::me;
2085 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
2090 # obtain the hops from the list for this callsign and pc no
2096 my $hops = $DXProt::hopcount{$pcno};
2097 $hops = $DXProt::def_hopcount if !$hops;
2102 # adjust the hop count on a per node basis using the user loadable
2103 # hop table if available or else decrement an existing one
2110 my $call = $self->{call};
2113 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
2114 my ($pcno) = $s =~ /^PC(\d\d)/o;
2115 confess "$call called adjust_hops with '$s'" unless $pcno;
2116 my $ref = $nodehops{$call} if %nodehops;
2118 my $newhops = $ref->{$pcno};
2119 return "" if defined $newhops && $newhops == 0;
2120 $newhops = $ref->{default} unless $newhops;
2121 return "" if defined $newhops && $newhops == 0;
2122 $newhops = $hops if !$newhops;
2123 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
2125 # simply decrement it
2127 return "" if !$hops;
2128 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
2140 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
2141 do "$main::data/hop_table.pl";
2148 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
2149 if ($tonode eq $main::mycall) {
2150 my $ref = DXUser->get_current($fromnode);
2151 my $cref = Route::Node::get($fromnode);
2152 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
2153 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
2154 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
2155 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
2156 my $oldpriv = $self->{priv};
2157 $self->{priv} = $ref->{priv}; # assume the user's privilege level
2158 my @in = (DXCommandmode::run_cmd($self, $cmd));
2159 $self->{priv} = $oldpriv;
2160 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
2161 delete $self->{remotecmd};
2163 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
2166 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
2169 my $ref = DXUser->get_current($tonode);
2170 if ($ref && $ref->is_clx) {
2171 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
2173 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
2178 sub process_rcmd_reply
2180 my ($self, $tonode, $fromnode, $user, $line) = @_;
2181 if ($tonode eq $main::mycall) {
2182 my $s = $rcmds{$fromnode};
2184 my $dxchan = DXChannel::get($s->{call});
2185 my $ref = $user eq $tonode ? $dxchan : (DXChannel::get($user) || $dxchan);
2186 $ref->send($line) if $ref;
2187 delete $rcmds{$fromnode} if !$dxchan;
2189 # send unsolicited ones to the sysop
2190 my $dxchan = DXChannel::get($main::myalias);
2191 $dxchan->send($line) if $dxchan;
2194 my $ref = DXUser->get_current($tonode);
2195 if ($ref && $ref->is_clx) {
2196 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
2198 $self->route($tonode, pc35($fromnode, $tonode, $line));
2207 my $fromnode = shift;
2212 Log('rcmd', 'out', $fromnode, $line);
2213 if ($self->is_clx) {
2214 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
2216 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
2221 # add a rcmd request to the rcmd queues
2224 my ($self, $to, $cmd) = @_;
2227 $r->{call} = $self->{call};
2228 $r->{t} = $main::systime;
2232 my $ref = Route::Node::get($to);
2233 my $dxchan = $ref->dxchan;
2234 if ($dxchan && $dxchan->is_clx) {
2235 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
2237 route(undef, $to, pc34($main::mycall, $to, $cmd));
2244 my $pc39flag = shift;
2245 my $call = $self->call;
2247 return if $self->{disconnecting}++;
2249 unless ($pc39flag && $pc39flag == 1) {
2250 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
2253 # get rid of any PC16/17/19
2254 eph_del_regex("^PC1[679]*$call");
2256 # do routing stuff, remove me from routing table
2257 my $node = Route::Node::get($call);
2260 @rout = $node->del($main::routeroot);
2262 # and all my ephemera as well
2265 eph_del_regex("^PC1[679].*$c");
2269 RouteDB::delete_interface($call);
2271 # remove them from the pc19list as well
2272 while (my ($k,$v) = each %pc19list) {
2273 my @l = grep {$_->[0] ne $call} @{$pc19list{$k}};
2275 $pc19list{$k} = \@l;
2277 delete $pc19list{$k};
2281 eph_del_regex("^PC1[679].*$k");
2284 # unbusy and stop and outgoing mail
2285 my $mref = DXMsg::get_busy($call);
2286 $mref->stop_msg($call) if $mref;
2288 # broadcast to all other nodes that all the nodes connected to via me are gone
2289 unless ($pc39flag && $pc39flag == 2) {
2290 $self->route_pc21($main::mycall, undef, @rout) if @rout;
2293 # remove outstanding pings
2294 delete $pings{$call};
2296 # I was the last node visited
2297 $self->user->node($main::mycall);
2299 # send info to all logged in thingies
2300 $self->tell_login('logoutn');
2302 Log('DXProt', $call . " Disconnected");
2304 $self->SUPER::disconnect;
2309 # send a talk message to this thingy
2313 my ($self, $from, $to, $via, $line, $origin) = @_;
2315 $line =~ s/\^/\\5E/g; # remove any ^ characters
2316 $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
2317 Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
2320 # send it if it isn't the except list and isn't isolated and still has a hop count
2321 # taking into account filtering and so on
2327 my $generate = shift;
2328 my $no = shift; # the no of things to filter on
2330 my ($filter, $hops);
2333 for (; @_ && $no; $no--) {
2336 if (!$self->{isolate} && $self->{routefilter}) {
2339 ($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});
2343 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
2346 dbg("was sent a null value") if isdbg('chanerr');
2349 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
2353 foreach my $line (&$generate(@rin, @_)) {
2356 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
2358 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
2359 next unless $routeit;
2362 $self->send($routeit);
2371 my $generate = shift;
2373 my @dxchan = DXChannel::get_all_nodes();
2376 unless ($self->{isolate}) {
2377 foreach $dxchan (@dxchan) {
2378 next if $dxchan == $self;
2379 next if $dxchan == $main::me;
2380 next unless $dxchan->isa('DXProt');
2381 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
2383 $dxchan->send_route($origin, $generate, @_);
2391 return unless $self->user->wantpc16;
2394 broadcast_route($self, $origin, \&pc16, $line, 1, @_);
2400 return unless $self->user->wantpc16;
2403 broadcast_route($self, $origin, \&pc17, $line, 1, @_);
2411 broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
2419 broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
2427 broadcast_route($self, $origin, \&pc24, $line, 1, @_);
2435 broadcast_route($self, $origin, \&pc41, $line, 1, @_);
2443 broadcast_route($self, $origin, \&pc50, $line, 1, @_);
2450 my ($filter, $hops) = (1, 1);
2452 if ($self->{inroutefilter}) {
2453 ($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);
2454 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
2462 my $t = shift || $eph_restime;
2466 $s =~ s/\^H\d\d?\^?\~?$//;
2467 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
2468 $eph{$s} = $main::systime + $t;
2469 dbg("PCPROT: emphemeral duplicate") if $r && isdbg('chanerr');
2477 while (($key, $val) = each %eph) {
2478 if ($key =~ m{$regex}) {
2488 while (($key, $val) = each %eph) {
2489 if ($main::systime >= $val) {
2500 while (($key, $val) = each %eph) {
2501 push @out, $key, $val;
2508 goto &DXCommandmode::run_cmd;
2512 # import any msgs in the chat directory
2513 # the messages are sent to the chat group which forms the
2514 # the first part of the name (eg: solar.1243.txt would be
2515 # sent to chat group SOLAR)
2517 # Each message found is sent: one non-blank line to one chat
2518 # message. So 4 lines = 4 chat messages.
2520 # The special name LOCAL is for local users ANN
2521 # The special name ALL is for ANN/FULL
2522 # The special name SYSOP is for ANN/SYSOP
2526 # are there any to do in this directory?
2527 return unless -d $chatimportfn;
2528 unless (opendir(DIR, $chatimportfn)) {
2529 dbg("can\'t open $chatimportfn $!") if isdbg('msg');
2530 Log('msg', "can\'t open $chatimportfn $!");
2534 my @names = readdir(DIR);
2537 foreach $name (@names) {
2538 next if $name =~ /^\./;
2539 my $splitit = $name =~ /^split/;
2540 my $fn = "$chatimportfn/$name";
2542 unless (open(MSG, $fn)) {
2543 dbg("can\'t open import file $fn $!") if isdbg('msg');
2544 Log('msg', "can\'t open import file $fn $!");
2548 my @msg = map { s/\r?\n$//; $_ } <MSG>;
2552 my @cat = split /\./, $name;
2553 my $target = uc $cat[0];
2555 foreach my $text (@msg) {
2556 next unless $text && $text !~ /^\s*#/;
2557 if ($target eq 'ALL' || $target eq 'LOCAL' || $target eq 'SYSOP') {
2558 my $sysopflag = $target eq 'SYSOP' ? '*' : ' ';
2559 if ($target ne 'LOCAL') {
2560 send_announce($main::me, pc12($main::mycall, $text, '*', $sysopflag), $main::mycall, '*', $text, $sysopflag, $main::mycall, '0');
2562 Log('ann', 'LOCAL', $main::mycall, $text);
2563 DXChannel::broadcast_list("To LOCAL de ${main::mycall}: $text\a", 'ann', undef, DXCommandmode->get_all());
2566 my $msgid = nextchatmsgid();
2567 $text = "#$msgid $text";
2568 send_chat($main::me, pc12($main::mycall, $text, '*', $target), $main::mycall, '*', $text, $target, $main::mycall, '0');