3 # This module impliments the protocal mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
30 use Time::HiRes qw(gettimeofday tv_interval);
40 use vars qw($VERSION $BRANCH);
41 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
42 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
43 $main::build += $VERSION;
44 $main::branch += $BRANCH;
46 use vars qw($pc11_max_age $pc23_max_age $last_pc50 $eph_restime $eph_info_restime $eph_pc34_restime
47 $last_hour $last10 %eph %pings %rcmds $ann_to_talk
48 $pingint $obscount %pc19list $chatdupeage $investigation_int
49 %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
50 $allowzero $decode_dk0wcy $send_opernam @checklist);
52 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
53 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
55 $last_hour = time; # last time I did an hourly periodic update
56 %pings = (); # outstanding ping requests outbound
57 %rcmds = (); # outstanding rcmd requests outbound
58 %nodehops = (); # node specific hop control
59 %pc19list = (); # list of outstanding PC19s that haven't had PC16s on them
61 $censorpc = 1; # Do a BadWords::check on text fields and reject things
62 # loads of 'bad things'
63 $baddx = new DXHash "baddx";
64 $badspotter = new DXHash "badspotter";
65 $badnode = new DXHash "badnode";
66 $last10 = $last_pc50 = time;
70 $eph_info_restime = 60*60;
71 $eph_pc34_restime = 30;
74 $chatdupeage = 20 * 60 * 60;
75 $investigation_int = 7*86400; # time between checks to see if we can see this node
79 [ qw(i c c m bp bc c) ], # pc10
80 [ qw(i f m d t m c c h) ], # pc11
81 [ qw(i c bm m bm bm p h) ], # pc12
85 undef , # pc16 has to be validated manually
86 [ qw(i c c h) ], # pc17
88 undef , # pc19 has to be validated manually
89 undef , # pc20 no validation
90 [ qw(i c m h) ], # pc21
91 undef , # pc22 no validation
92 [ qw(i d n n n n m c c h) ], # pc23
93 [ qw(i c p h) ], # pc24
94 [ qw(i c c n n) ], # pc25
95 [ qw(i f m d t m c c bc) ], # pc26
96 [ qw(i d n n n n m c c bc) ], # pc27
97 [ qw(i c c m c d t p m bp n p bp bc) ], # pc28
98 [ qw(i c c n m) ], # pc29
99 [ qw(i c c n) ], # pc30
100 [ qw(i c c n) ], # pc31
101 [ qw(i c c n) ], # pc32
102 [ qw(i c c n) ], # pc33
103 [ qw(i c c m) ], # pc34
104 [ qw(i c c m) ], # pc35
105 [ qw(i c c m) ], # pc36
106 [ qw(i c c n m) ], # pc37
107 undef, # pc38 not interested
108 [ qw(i c m) ], # pc39
109 [ qw(i c c m p n) ], # pc40
110 [ qw(i c n m h) ], # pc41
111 [ qw(i c c n) ], # pc42
112 undef, # pc43 don't handle it
113 [ qw(i c c n m m c) ], # pc44
114 [ qw(i c c n m) ], # pc45
115 [ qw(i c c n) ], # pc46
118 [ qw(i c m h) ], # pc49
119 [ qw(i c n h) ], # pc50
120 [ qw(i c c n) ], # pc51
142 [ qw(i d n n n n n n m m m c c h) ], # pc73
153 [ qw(i c c c m) ], # pc84
154 [ qw(i c c c m) ], # pc85
159 [ qw(i c n) ], # pc90
162 # use the entry in the check list to check the field list presented
163 # return OK if line NOT in check list (for now)
168 return 0 if $n < 0 || $n > @checklist;
169 my $ref = $checklist[$n];
170 return 0 unless ref $ref;
173 for ($i = 1; $i < @$ref; $i++) {
174 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
175 return 0 unless $act;
176 next if $blank && $_[$i] =~ /^[ \*]$/;
178 return $i unless is_callsign($_[$i]);
179 } elsif ($act eq 'i') {
181 } elsif ($act eq 'm') {
182 return $i unless is_pctext($_[$i]);
183 } elsif ($act eq 'p') {
184 return $i unless is_pcflag($_[$i]);
185 } elsif ($act eq 'f') {
186 return $i unless is_freq($_[$i]);
187 } elsif ($act eq 'n') {
188 return $i unless $_[$i] =~ /^[\d ]+$/;
189 } elsif ($act eq 'h') {
190 return $i unless $_[$i] =~ /^H\d\d?$/;
191 } elsif ($act eq 'd') {
192 return $i unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
193 } elsif ($act eq 't') {
194 return $i unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
202 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
205 my $user = DXUser->get($main::mycall);
206 $DXProt::myprot_version += $main::version*100;
207 $main::me = DXProt->SUPER::alloc($main::mycall, 0, $user);
208 $main::me->{here} = 1;
209 $main::me->{state} = "indifferent";
210 $main::me->{sort} = 'S'; # S for spider
211 $main::me->{priv} = 9;
212 $main::me->{metric} = 0;
213 $main::me->{pingave} = 0;
214 $main::me->{registered} = 1;
215 $main::me->{version} = $main::version;
216 $main::me->{build} = $main::build;
220 # obtain a new connection this is derived from dxchannel
225 my $self = DXChannel::alloc(@_);
227 # add this node to the table, the values get filled in later
231 my $uref = Route::Node::get($call) || Route::Node->new($call);
234 $uref->version(5000);
235 $main::routeroot->link_node($uref, $self);
239 # this is how a pc connection starts (for an incoming connection)
240 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
241 # all the crap that comes between).
244 my ($self, $line, $sort) = @_;
245 my $call = $self->{call};
246 my $user = $self->{user};
249 my $host = $self->{conn}->{peerhost} || "unknown";
250 Log('DXProt', "$call connected from $host");
252 # remember type of connection
253 $self->{consort} = $line;
254 $self->{outbound} = $sort eq 'O';
255 my $priv = $user->priv;
256 $priv = $user->priv(1) unless $priv;
257 $self->{priv} = $priv; # other clusters can always be 'normal' users
258 $self->{lang} = $user->lang || 'en';
259 $self->{isolate} = $user->{isolate};
260 $self->{consort} = $line; # save the connection type
264 # sort out registration
265 $self->{registered} = 1;
267 # get the output filters
268 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
269 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
270 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
271 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
272 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
275 # get the INPUT filters (these only pertain to Clusters)
276 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
277 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
278 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
279 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
280 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
282 # set unbuffered and no echo
283 $self->send_now('B',"0");
284 $self->send_now('E',"0");
285 $self->conn->echo(0) if $self->conn->can('echo');
287 # ping neighbour node stuff
288 my $ping = $user->pingint;
289 $ping = $pingint unless defined $ping;
290 $self->{pingint} = $ping;
291 $self->{nopings} = $user->nopings || $obscount;
292 $self->{pingtime} = [ ];
293 $self->{pingave} = 999;
294 $self->{metric} ||= 100;
295 $self->{lastping} = $main::systime;
297 # send initialisation string
298 unless ($self->{outbound}) {
302 $self->state('init');
303 $self->{pc50_t} = $main::systime;
305 # send info to all logged in thingies
306 $self->tell_login('loginn');
308 # run a script send the output to the debug file
309 my $script = new Script(lc $call) || new Script('node_default');
310 $script->run($self) if $script;
314 # send outgoing 'challenge'
325 $_[0] =~ s/^PC90\^[-A-Z0-9]+\^\d+\^//;
326 $_[0] =~ s/^PC91\^[-A-Z0-9]+\^\d+\^[-A-Z0-9]+\^//;
334 # $self->SUPER::send($line);
339 # This is the normal pcxx despatcher
343 my ($self, $line) = @_;
345 # remove any incoming PC90 frames
348 my @field = split /\^/, $line;
349 return unless @field;
351 pop @field if $field[-1] eq '~';
353 # print join(',', @field), "\n";
356 # process PC frames, this will fail unless the frame starts PCnn
357 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
358 unless (defined $pcno && $pcno >= 10 && $pcno <= 99) {
359 dbg("PCPROT: unknown protocol") if isdbg('chanerr');
363 # check for and dump bad protocol messages
364 my $n = check($pcno, @field);
366 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
370 my $origin = $self->{call};
372 my $sub = "handle_$pcno";
374 if ($self->can($sub)) {
375 $self->$sub($pcno, $line, $origin, @field);
377 $self->handle_default($pcno, $line, $origin, @field);
381 # incoming talk commands
390 return if $rspfcheck and !$self->rspfcheck(0, $_[6], $_[1]);
392 # will we allow it at all?
395 if (@bad = BadWords::check($_[3])) {
396 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
401 # is it for me or one of mine?
402 my ($from, $to, $via, $call, $dxchan);
411 # if this is a 'nodx' node then ignore it
412 if ($badnode->in($_[6]) || ($via && $badnode->in($via))) {
413 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
417 # if this is a 'bad spotter' user then ignore it
419 $nossid =~ s/-\d+$//;
420 if ($badspotter->in($nossid)) {
421 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
425 # if we are converting announces to talk is it a dup?
427 if (AnnTalk::is_talk_candidate($from, $_[3]) && AnnTalk::dup($from, $to, $_[3])) {
428 dbg("DXPROT: Dupe talk from announce, dropped") if isdbg('chanerr');
433 # it is here and logged on
434 $dxchan = DXChannel->get($main::myalias) if $to eq $main::mycall;
435 $dxchan = DXChannel->get($to) unless $dxchan;
436 if ($dxchan && $dxchan->is_user) {
438 $dxchan->talk($from, $to, $via, $_[3]);
442 # is it elsewhere, visible on the cluster via the to address?
443 # note: this discards the via unless the to address is on
446 if ($ref = Route::get($to)) {
447 $vref = Route::Node::get($via) if $via;
448 $vref = undef unless $vref && grep $to eq $_, $vref->users;
449 $ref->bestdxchan->talk($from, $to, $vref ? $via : undef, $_[3], $_[6]);
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->bestdxchan;
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 # if this is a 'nodx' node then ignore it
483 if ($badnode->in($_[7])) {
484 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
488 # if this is a 'bad spotter' user then ignore it
490 $nossid =~ s/-\d+$//;
491 if ($badspotter->in($nossid)) {
492 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
496 # convert the date to a unix date
497 my $d = cltounix($_[3], $_[4]);
498 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
499 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
500 dbg("PCPROT: Spot ignored, invalid date or out of range ($_[3] $_[4])\n") if isdbg('chanerr');
505 if ($baddx->in($_[2]) || BadWords::check($_[2]) || $_[2] =~ /COCK/) {
506 dbg("PCPROT: Bad DX spot, ignored") if isdbg('chanerr');
511 $_[5] =~ s/^\s+//; # take any leading blanks off
512 $_[2] = unpad($_[2]); # take off leading and trailing blanks from spotted callsign
513 if ($_[2] =~ /BUST\w*$/) {
514 dbg("PCPROT: useless 'BUSTED' spot") if isdbg('chanerr');
519 if (@bad = BadWords::check($_[5])) {
520 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
526 my @spot = Spot::prepare($_[1], $_[2], $d, $_[5], $_[6], $_[7]);
527 # global spot filtering on INPUT
528 if ($self->{inspotsfilter}) {
529 my ($filter, $hops) = $self->{inspotsfilter}->it(@spot);
531 dbg("PCPROT: Rejected by input spot filter") if isdbg('chanerr');
536 # this goes after the input filtering, but before the add
537 # so that if it is input filtered, it isn't added to the dup
538 # list. This allows it to come in from a "legitimate" source
539 if (Spot::dup($_[1], $_[2], $d, $_[5], $_[6])) {
540 dbg("PCPROT: Duplicate Spot ignored\n") if isdbg('chanerr');
548 # @spot at this point contains:-
549 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
550 # then spotted itu, spotted cq, spotters itu, spotters cq
551 # you should be able to route on any of these
554 # fix up qra locators of known users
555 my $user = DXUser->get_current($spot[4]);
557 my $qra = $user->qra;
558 unless ($qra && is_qra($qra)) {
559 my $lat = $user->lat;
560 my $long = $user->long;
561 if (defined $lat && defined $long) {
562 $user->qra(DXBearing::lltoqra($lat, $long));
567 # send a remote command to a distant cluster if it is visible and there is no
568 # qra locator and we havn't done it for a month.
570 unless ($user->qra) {
572 my $to = $user->homenode;
573 my $last = $user->lastoper || 0;
574 if ($send_opernam && $to && $to ne $main::mycall && $main::systime > $last + $DXUser::lastoperinterval && ($node = Route::Node::get($to)) ) {
575 my $cmd = "forward/opernam $spot[4]";
576 # send the rcmd but we aren't interested in the replies...
577 my $dxchan = $node->bestdxchan;
578 if ($dxchan && $dxchan->is_clx) {
579 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
581 route(undef, $to, pc34($main::mycall, $to, $cmd));
585 $node = Route::Node::get($to);
587 $dxchan = $node->bestdxchan;
588 if ($dxchan && $dxchan->is_clx) {
589 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
591 route(undef, $to, pc34($main::mycall, $to, $cmd));
595 $user->lastoper($main::systime);
604 $r = Local::spot($self, @spot);
606 # dbg("Local::spot1 error $@") if isdbg('local') if $@;
609 # DON'T be silly and send on PC26s!
610 return if $pcno == 26;
612 # send out the filtered spots
613 send_dx_spot($self, $line, @spot) if @spot;
624 # return if $rspfcheck and !$self->rspfcheck(1, $_[5], $_[1]);
626 # announce duplicate checking
627 $_[3] =~ s/^\s+//; # remove leading blanks
631 if (@bad = BadWords::check($_[3])) {
632 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
637 # if this is a 'nodx' node then ignore it
638 if ($badnode->in($_[5])) {
639 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
643 # if this is a 'bad spotter' user then ignore it
645 $nossid =~ s/-\d+$//;
646 if ($badspotter->in($nossid)) {
647 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
653 if ((($dxchan = DXChannel->get($_[2])) && $dxchan->is_user) || $_[4] =~ /^[\#\w.]+$/){
654 $self->send_chat($line, @_[1..6]);
655 } elsif ($_[2] eq '*' || $_[2] eq $main::mycall) {
657 # ignore something that looks like a chat line coming in with sysop
658 # flag - this is a kludge...
659 if ($_[3] =~ /^\#\d+ / && $_[4] eq '*') {
660 dbg('PCPROT: Probable chat rewrite, dropped') if isdbg('chanerr');
664 # here's a bit of fun, convert incoming ann with a callsign in the first word
665 # or one saying 'to <call>' to a talk if we can route to the recipient
667 my $call = AnnTalk::is_talk_candidate($_[1], $_[3]);
669 my $ref = Route::get($call);
671 $dxchan = $ref->bestdxchan;
672 $dxchan->talk($_[1], $call, undef, $_[3], $_[5]) if $dxchan != $self;
679 $self->send_announce($line, @_[1..6]);
681 $self->route($_[2], $line);
697 my $newline = "PC16^";
699 # do I want users from this channel?
700 unless ($self->user->wantpc16) {
701 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
706 if ($ncall eq $main::mycall) {
707 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
711 # do we believe this call?
712 unless ($ncall eq $self->{call} || $self->is_believed($ncall)) {
713 if (my $ivp = Investigate::get($ncall, $self->{call})) {
714 $ivp->store_pcxx($pcno,$line,$origin,@_);
716 dbg("PCPROT: We don't believe $ncall on $self->{call}");
720 my $node = Route::Node::get($ncall);
722 dbg("PCPROT: Node $ncall not in config") if isdbg('chanerr');
726 # dedupe only that which we potentially process
727 if (eph_dup($line)) {
728 dbg("PCPROT: dup PC16 detected") if isdbg('chanerr');
735 for ($i = 2; $i < $#_; $i++) {
736 my ($call, $conf, $here) = $_[$i] =~ /^(\S+) (\S) (\d)/o;
737 next unless $call && $conf && defined $here && is_callsign($call);
738 next if $call eq $main::mycall;
740 eph_del_regex("^PC17\\^$call\\^$ncall");
742 $conf = $conf eq '*';
744 # reject this if we think it is a node already
745 my $r = Route::Node::get($call);
746 my $u = DXUser->get_current($call) unless $r;
747 if ($r || ($u && $u->is_node)) {
748 dbg("PCPROT: $call is a node") if isdbg('chanerr');
752 $r = Route::User::get($call) || Route::User->new($call);
755 $node->lastseen($main::systime);
757 push @new, $node->add_user($r);
759 # add this station to the user database, if required
760 $call =~ s/-\d+$//o; # remove ssid for users
761 my $user = DXUser->get_current($call);
762 $user = DXUser->new($call) if !$user;
763 $user->homenode($node->call) if !$user->homenode;
764 $user->node($node->call);
765 $user->lastin($main::systime) unless DXChannel->get($call);
768 $self->route_pc16($origin, $line, $node, @new) if @new;
782 eph_del_regex("^PC16\\^$ncall.*$ucall");
784 # do I want users from this channel?
785 unless ($self->user->wantpc16) {
786 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
789 if ($ncall eq $main::mycall) {
790 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
794 # do we believe this call?
795 unless ($ncall eq $self->{call} || $self->is_believed($ncall)) {
796 if (my $ivp = Investigate::get($ncall, $self->{call})) {
797 $ivp->store_pcxx($pcno,$line,$origin,@_);
799 dbg("PCPROT: We don't believe $ncall on $self->{call}");
803 my $uref = Route::User::get($ucall);
805 dbg("PCPROT: Route::User $ucall not in config") if isdbg('chanerr');
807 my $node = Route::Node::get($ncall);
809 dbg("PCPROT: Route::Node $ncall not in config") if isdbg('chanerr');
812 return unless $node && $uref;
816 if ($self->in_filter_route($node)) {
818 if (eph_dup($line)) {
819 dbg("PCPROT: dup PC17 detected") if isdbg('chanerr');
822 push @new, $node->del_user($uref);
825 $self->route_pc17($origin, $line, $node, $uref) if @new;
827 # get rid of orphaned users;
838 $self->state('init');
840 # record the type and version offered
841 if ($_[1] =~ /DXSpider Version: (\d+\.\d+) Build: (\d+\.\d+)/) {
842 $self->version(53 + $1);
843 $self->user->version(53 + $1);
844 $self->build(0 + $2);
845 $self->user->build(0 + $2);
846 unless ($self->is_spider) {
847 $self->user->sort('S');
852 $self->version(50.0);
853 $self->version($_[2] / 100) if $_[2] && $_[2] =~ /^\d+$/;
854 $self->user->version($self->version);
856 $self->newroute( $_[1] =~ /NewRoute/ );
858 # first clear out any nodes on this dxchannel
859 my $node = Route::Node::get($self->{call}) ;
861 foreach my $n ($node->nodes) {
862 next if $n eq $main::mycall;
863 next if $n eq $self->{call};
864 my $nref = Route::Node::get($n);
865 push @rout, $node->remove_route($nref, $self) if $nref;
867 $self->route_pc21($origin, $line, @rout) if @rout;
872 # send the new config
873 $self->send_local_config();
877 # incoming cluster list
886 my $newline = "PC19^";
888 if (eph_dup($line)) {
889 dbg("PCPROT: dup PC19 detected") if isdbg('chanerr');
896 # first get the INTERFACE node
897 my $parent = Route::Node::get($self->{call});
899 dbg("DXPROT: my parent $self->{call} has disappeared");
907 for ($i = 1; $i < $#_-1; $i += 4) {
909 my $call = uc $_[$i+1];
912 next unless defined $here && defined $conf && is_callsign($call);
914 # check for sane parameters
915 # $ver = 5000 if $ver eq '0000';
916 next if $ver < 5000; # only works with version 5 software
917 next if length $call < 3; # min 3 letter callsigns
918 next if $call eq $main::mycall;
920 # add this station to the user database, if required (don't remove SSID from nodes)
921 my $user = DXUser->get_current($call);
923 $user = DXUser->new($call);
925 $user->priv(1); # I have relented and defaulted nodes
927 $user->homenode($call);
930 $user->wantroutepc19(1) unless defined $user->wantroutepc19;
931 $user->lastin($main::systime) unless DXChannel->get($call);
934 # do we believe this call?
935 unless ($call eq $self->{call} || $self->is_believed($call)) {
936 my $pt = $user->lastping || 0;
937 if ($pt+$investigation_int < $main::systime && !Investigate::get($call, $self->{call})) {
938 my $ivp = Investigate->new($call, $self->{call});
941 $ivp->store_pcxx($pcno,$line,$origin,'PC19',$here,$call,$conf,$ver,$_[-1]);
943 dbg("PCPROT: We don't believe $call on $self->{call}");
947 eph_del_regex("^PC(?:21\\^$call|17\\^[^\\^]+\\^$call)");
949 my $r = Route::Node::get($call) || Route::Node->new($call);
953 $r->lastseen($main::systime);
955 if ($self->in_filter_route($r)) {
956 push @new, $parent->link_node($r, $self);
960 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
961 my $mref = DXMsg::get_busy($call);
962 $mref->stop_msg($call) if $mref;
965 # route out new nodes to legacy nodes
966 $self->route_pc19($origin, $line, @new) if @new;
967 $self->route_pc59('A', 0, $self->{call}, @rout) if @rout;
970 # send local configuration
977 $self->send_local_config();
979 $self->state('normal');
980 $self->{lastping} = 0;
983 # delete a cluster from the list
992 return if $call eq $main::mycall; # don't allow malicious buggers to disconnect me (or ignore loops)!
994 unless ($call eq $self->{call} || $self->is_believed($call)) {
995 if (my $ivp = Investigate::get($call, $self->{call})) {
996 $ivp->store_pcxx($pcno,$line,$origin,@_);
998 dbg("PCPROT: We don't believe $call on $self->{call}");
1002 eph_del_regex("^PC1[679].*$call");
1004 # if I get a PC21 from the same callsign as self then treat it
1005 # as a PC39: I have gone away
1006 if ($call eq $self->call) {
1007 $self->disconnect(1);
1013 my $parent = Route::Node::get($self->{call});
1015 dbg("DXPROT: my parent $self->{call} has disappeared");
1021 my $node = Route::Node::get($call);
1023 $node->lastseen($main::systime);
1026 return unless $self->in_filter_route($node);
1028 push @new, $node->link_node($parent, $self);
1031 $self->route_pc21($origin, $line, @new) if @new;
1032 $self->route_pc59('D', 0, $self->{call}, @rout) if @rout;
1034 # get rid of orphaned nodes;
1035 $_->delete for @new;
1045 $self->state('normal');
1046 $self->{lastping} = 0;
1057 # route foreign' pc27s
1059 if ($_[8] ne $main::mycall) {
1060 $self->route($_[8], $line);
1065 # only do a rspf check on PC23 (not 27)
1067 return if $rspfcheck and !$self->rspfcheck(1, $_[8], $_[7])
1071 my $d = cltounix($_[1], sprintf("%02d18Z", $_[2]));
1072 my $sfi = unpad($_[3]);
1073 my $k = unpad($_[4]);
1074 my $i = unpad($_[5]);
1075 my ($r) = $_[6] =~ /R=(\d+)/;
1077 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1078 dbg("PCPROT: WWV Date ($_[1] $_[2]) out of range") if isdbg('chanerr');
1081 if (Geomag::dup($d,$sfi,$k,$i,$_[6])) {
1082 dbg("PCPROT: Dup WWV Spot ignored\n") if isdbg('chanerr');
1085 $_[7] =~ s/-\d+$//o; # remove spotter's ssid
1087 my $wwv = Geomag::update($d, $_[2], $sfi, $k, $i, @_[6..8], $r);
1091 $rep = Local::wwv($self, $_[1], $_[2], $sfi, $k, $i, @_[6..8], $r);
1093 # dbg("Local::wwv2 error $@") if isdbg('local') if $@;
1096 # DON'T be silly and send on PC27s!
1097 return if $pcno == 27;
1099 # broadcast to the eager world
1100 send_wwv_spot($self, $line, $d, $_[2], $sfi, $k, $i, @_[6..8]);
1110 my $call = uc $_[1];
1112 $nref = Route::Node::get($call);
1113 $uref = Route::User::get($call);
1114 return unless $nref || $uref; # if we don't know where they are, it's pointless sending it on
1116 if (eph_dup($line)) {
1117 dbg("PCPROT: Dup PC24 ignored\n") if isdbg('chanerr');
1121 $nref->here($_[2]) if $nref;
1122 $uref->here($_[2]) if $uref;
1123 my $ref = $nref || $uref;
1124 return unless $self->in_filter_route($ref);
1126 $self->route_pc24($origin, $line, $ref, $_[3]);
1136 if ($_[1] ne $main::mycall) {
1137 $self->route($_[1], $line);
1140 if ($_[2] eq $main::mycall) {
1141 dbg("PCPROT: Trying to merge to myself, ignored") if isdbg('chanerr');
1145 Log('DXProt', "Merge request for $_[3] spots and $_[4] WWV from $_[2]");
1149 my @in = reverse Spot::search(1, undef, undef, 0, $_[3]);
1152 $self->send(pc26(@{$in}[0..4], $_[2]));
1158 my @in = reverse Geomag::search(0, $_[4], time, 1);
1161 $self->send(pc27(@{$in}[0..5], $_[2]));
1166 sub handle_26 {goto &handle_11}
1167 sub handle_27 {goto &handle_23}
1169 # mail/file handling
1176 if ($_[1] eq $main::mycall) {
1178 my $sub = "DXMsg::handle_$pcno";
1181 $self->route($_[1], $line) unless $self->is_clx;
1185 sub handle_29 {goto &handle_28}
1186 sub handle_30 {goto &handle_28}
1187 sub handle_31 {goto &handle_28}
1188 sub handle_32 {goto &handle_28}
1189 sub handle_33 {goto &handle_28}
1197 if (eph_dup($line, $eph_pc34_restime)) {
1198 dbg("PCPROT: dupe PC34, ignored") if isdbg('chanerr');
1200 $self->process_rcmd($_[1], $_[2], $_[2], $_[3]);
1204 # remote command replies
1211 eph_del_regex("^PC35\\^$_[2]\\^$_[1]\\^");
1212 $self->process_rcmd_reply($_[1], $_[2], $_[1], $_[3]);
1215 sub handle_36 {goto &handle_34}
1224 if ($_[1] eq $main::mycall) {
1226 my $sub = "DXDb::handle_$pcno";
1229 $self->route($_[1], $line) unless $self->is_clx;
1233 # node connected list from neighbour
1242 # incoming disconnect
1249 if ($_[1] eq $self->{call}) {
1250 $self->disconnect(1);
1252 dbg("PCPROT: came in on wrong channel") if isdbg('chanerr');
1256 sub handle_40 {goto &handle_28}
1268 $l =~ s/[\x00-\x20\x7f-\xff]+//g; # remove all funny characters and spaces for dup checking
1269 if (eph_dup($l, $eph_info_restime)) {
1270 dbg("PCPROT: dup PC41, ignored") if isdbg('chanerr');
1274 # input filter if required
1275 # my $ref = Route::get($call) || Route->new($call);
1276 # return unless $self->in_filter_route($ref);
1278 if ($_[3] eq $_[2] || $_[3] =~ /^\s*$/) {
1279 dbg('PCPROT: invalid value') if isdbg('chanerr');
1283 # add this station to the user database, if required
1284 my $user = DXUser->get_current($call);
1285 $user = DXUser->new($call) unless $user;
1289 } elsif ($_[2] == 2) {
1291 } elsif ($_[2] == 3) {
1292 if (is_latlong($_[3])) {
1293 my ($lat, $long) = DXBearing::stoll($_[3]);
1296 $user->qra(DXBearing::lltoqra($lat, $long));
1298 dbg('PCPROT: not a valid lat/long') if isdbg('chanerr');
1301 } elsif ($_[2] == 4) {
1302 $user->homenode($_[3]);
1303 } elsif ($_[2] == 5) {
1304 if (is_qra(uc $_[3])) {
1305 my ($lat, $long) = DXBearing::qratoll(uc $_[3]);
1308 $user->qra(uc $_[3]);
1310 dbg('PCPROT: not a valid QRA locator') if isdbg('chanerr');
1314 $user->lastoper($main::systime); # to cut down on excessive for/opers being generated
1317 unless ($self->{isolate}) {
1318 DXChannel::broadcast_nodes($line, $self); # send it to everyone but me
1321 # perhaps this IS what we want after all
1322 # $self->route_pc41($ref, $call, $_[2], $_[3], $_[4]);
1325 sub handle_42 {goto &handle_28}
1329 sub handle_44 {goto &handle_37}
1330 sub handle_45 {goto &handle_37}
1331 sub handle_46 {goto &handle_37}
1332 sub handle_47 {goto &handle_37}
1333 sub handle_48 {goto &handle_37}
1335 # message and database
1343 if (eph_dup($line)) {
1344 dbg("PCPROT: Dup PC49 ignored\n") if isdbg('chanerr');
1348 if ($_[1] eq $main::mycall) {
1349 DXMsg::handle_49($self, @_);
1351 $self->route($_[1], $line) unless $self->is_clx;
1355 # keep alive/user list
1364 my $node = Route::Node::get($call);
1366 return unless $node->call eq $self->{call};
1367 $node->usercount($_[2]);
1369 # input filter if required
1370 return unless $self->in_filter_route($node);
1372 $self->route_pc50($origin, $line, $node, $_[2], $_[3]) unless eph_dup($line);
1376 # incoming ping requests/answers
1389 if ($to eq $main::mycall) {
1391 $self->send(pc51($from, $to, '0'));
1393 # it's a reply, look in the ping list for this one
1394 my $ref = $pings{$from};
1396 my $tochan = DXChannel->get($from);
1398 my $r = shift @$ref;
1399 my $dxchan = DXChannel->get($r->{call});
1400 next unless $dxchan;
1401 my $t = tv_interval($r->{t}, [ gettimeofday ]);
1402 if ($dxchan->is_user) {
1403 my $s = sprintf "%.2f", $t;
1404 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
1405 $dxchan->send($dxchan->msg('pingi', $from, $s, $ave))
1406 } elsif ($dxchan->is_node) {
1408 my $nopings = $tochan->user->nopings || $obscount;
1409 push @{$tochan->{pingtime}}, $t;
1410 shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
1412 # cope with a missed ping, this means you must set the pingint large enough
1413 if ($t > $tochan->{pingint} && $t < 2 * $tochan->{pingint} ) {
1414 $t -= $tochan->{pingint};
1417 # calc smoothed RTT a la TCP
1418 if (@{$tochan->{pingtime}} == 1) {
1419 $tochan->{pingave} = $t;
1421 $tochan->{pingave} = $tochan->{pingave} + (($t - $tochan->{pingave}) / 6);
1423 my $rref = Route::Node::get($tochan->{call});
1424 $rref->pingtime($tochan->{pingave}) if $rref;
1425 $tochan->{nopings} = $nopings; # pump up the timer
1426 if (my $ivp = Investigate::get($from, $self->{call})) {
1429 } elsif (my $rref = Route::Node::get($r->{call})) {
1430 if (defined $rref->pingtime) {
1431 $rref->pingtime($rref->pingtime + (($t - $rref->pingtime) / 6));
1433 $rref->pingtime($t);
1435 if (my $ivp = Investigate::get($from, $self->{call})) {
1444 if (eph_dup($line)) {
1445 dbg("PCPROT: dup PC51 detected") if isdbg('chanerr');
1448 # route down an appropriate thingy
1449 $self->route($to, $line);
1453 # New style routing handler
1461 my ($sort, $hextime, $ncall) = @_[1,2,3];
1462 if ($ncall eq $main::mycall) {
1463 dbg("PCPROT: ignoring PC59 for me") if isdbg('chan');
1467 # do this once for filtering with a throwaway routing entry if a new node
1468 my $fnode = Route::Node::get($ncall) || Route::new($ncall);
1469 return unless $self->in_filter_route($fnode);
1471 return if eph_dup($line);
1473 # mark myself as NewRoute if I get a PC59
1474 $self->{newroute} = 1 if $ncall eq $self->{call};
1476 # now do it properly for actions
1477 my $node = Route::Node::get($ncall) || Route::Node->new($ncall);
1480 # find each of the entries (or create new ones)
1482 for my $ent (@_[4..$#_]) {
1483 next if $ent =~ /^H\d+$/;
1485 my ($esort, $ehere, $ecall) = unpack "A A A*", $ent;
1488 next unless $esort && defined $ehere && $ecall;
1490 # create user, if required
1491 my $user = DXUser->get_current($ecall);
1493 $user = DXUser->new($ecall);
1495 $user->priv(1); # I have relented and defaulted nodes
1497 $user->homenode($ncall);
1498 $user->node($ncall);
1500 if ($esort eq 'U') {
1501 $ref = Route::User::get($ecall);
1503 # create user, if required
1504 my $user = DXUser->get_current($ecall);
1506 $user = DXUser->new($ecall);
1508 $user->homenode($ncall);
1509 $user->node($ncall);
1512 $ref = Route::User->new($ecall, 0);
1514 } elsif ($esort eq 'N') {
1515 $ref = Route::Node::get($ecall);
1517 # create user, if required
1518 my $user = DXUser->get_current($ecall);
1520 $user = DXUser->new($ecall);
1521 $user->priv(1); # I have relented and defaulted nodes
1524 $user->homenode($ncall);
1525 $user->node($ncall);
1528 $ref = Route::Node->new($ecall, 0);
1531 dbg("DXPROT: unknown entity type '$esort' on $ecall for node $ncall") if isdbg('chan');
1534 $ref->here($ehere); # might as well set this here
1535 $ref->lastseen($main::systime);
1539 # if it is a delete, disconnect all the entries mentioned
1540 # from this node (which is a parent in this context).
1544 for my $ref (@refs) {
1545 next if $ref->call eq $ncall;
1546 next if $ref->call eq $main::mycall;
1547 if ($ref->isa('Route::Node')) {
1548 push @delnode, $node->unlink_node($ref, $self);
1549 } elsif ($ref->isa('Route::User')) {
1550 push @deluser, $node->del_user($ref);
1555 # if it is an add, connect all the entries
1559 for my $ref (@refs) {
1560 next if $ref->call eq $ncall;
1561 next if $ref->call eq $main::mycall;
1562 if ($ref->isa('Route::Node')) {
1563 my $new = $node->link_node($ref, $self);
1564 push @addnode, $new if $new;
1565 } elsif ($ref->isa('Route::User')) {
1566 push @adduser, $node->del_user($ref);
1571 # if it is a configure, unlink all the nodes and users that
1572 # are not in @refs but are in the node, then add all the
1573 # nodes and users that are @refs but not in the node.
1580 for my $r (map {Route::Node::get($_)} $node->nodes) {
1582 next if $r->call eq $ncall;
1583 next if $r->call eq $main::mycall;
1584 push @dn, $r unless grep $_->call eq $r->call, @refs;
1586 for my $r (map {Route::User::get($_)} $node->users) {
1588 push @du, $r unless grep $_->call eq $r->call, @refs;
1592 next if $r->call eq $ncall;
1593 next if $r->call eq $main::mycall;
1594 if ($r->isa('Route::Node')) {
1595 push @an, $r unless grep $r->call eq $_, $node->nodes;
1596 } elsif ($r->isa('Route::User')) {
1597 push @au, $r unless grep $r->call eq $_, $node->users;
1600 push @delnode, $node->unlink_node($_, $self) for @dn;
1601 push @deluser, $node->del_user($_) for @du;
1602 push @addnode, $node->link_node($_, $self) for @an;
1603 push @adduser, $node->add_user($_) for @au;
1606 $self->route_pc21($origin, $line, @delnode) if @delnode;
1607 $self->route_pc19($origin, $line, @addnode) if @addnode;
1608 $self->route_pc17($origin, $line, @deluser) if @deluser;
1609 $self->route_pc16($origin, $line, @adduser) if @adduser;
1611 $self->route_pc59($sort, $hextime, $ncall, @refs) if @refs;
1612 $_->delete for @delnode, @deluser;
1616 # dunno but route it
1624 if ($call ne $main::mycall) {
1625 $self->route($call, $line);
1639 my $d = cltounix($call, sprintf("%02d18Z", $_[2]));
1640 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1641 dbg("PCPROT: WCY Date ($call $_[2]) out of range") if isdbg('chanerr');
1644 @_ = map { unpad($_) } @_;
1646 dbg("PCPROT: Dup WCY Spot ignored\n") if isdbg('chanerr');
1650 my $wcy = WCY::update($d, @_[2..12]);
1654 $rep = Local::wcy($self, @_[1..12]);
1656 # dbg("Local::wcy error $@") if isdbg('local') if $@;
1659 # broadcast to the eager world
1660 send_wcy_spot($self, $line, $d, @_[2..12]);
1663 # remote commands (incoming)
1670 $self->process_rcmd($_[1], $_[2], $_[3], $_[4]);
1673 # remote command replies
1680 $self->process_rcmd_reply($_[1], $_[2], $_[3], $_[4]);
1683 # if get here then rebroadcast the thing with its Hop count decremented (if
1684 # there is one). If it has a hop count and it decrements to zero then don't
1687 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
1698 if (eph_dup($line)) {
1699 dbg("PCPROT: Ephemeral dup, dropped") if isdbg('chanerr');
1701 unless ($self->{isolate}) {
1702 DXChannel::broadcast_nodes($line, $self) if $line =~ /\^H\d+\^?~?$/; # send it to everyone but me
1708 # This is called from inside the main cluster processing loop and is used
1709 # for despatching commands that are doing some long processing job
1711 # It is called once per second
1716 my @dxchan = DXChannel->get_all();
1720 # send out a pc50 on EVERY channel all at once
1721 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
1722 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
1727 foreach $dxchan (@dxchan) {
1728 next unless $dxchan->is_node();
1729 next if $dxchan == $main::me;
1732 $dxchan->send($pc50s) if $pc50s;
1734 # send a ping out on this channel
1735 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
1736 if ($dxchan->{nopings} <= 0) {
1737 $dxchan->disconnect;
1739 addping($main::mycall, $dxchan->call);
1740 $dxchan->{nopings} -= 1;
1741 $dxchan->{lastping} = $t;
1746 Investigate::process();
1749 if ($t - $last10 >= 10) {
1750 # clean out ephemera
1757 if ($main::systime - 3600 > $last_hour) {
1758 $last_hour = $main::systime;
1763 # finish up a pc context
1767 # some active measures
1775 my @dxchan = DXChannel->get_all();
1778 # send it if it isn't the except list and isn't isolated and still has a hop count
1779 # taking into account filtering and so on
1780 foreach $dxchan (@dxchan) {
1781 next if $dxchan == $main::me;
1782 next if $dxchan == $self && $self->is_node;
1783 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
1791 my $isolate = shift;
1792 my ($filter, $hops);
1794 if ($self->{spotsfilter}) {
1795 ($filter, $hops) = $self->{spotsfilter}->it(@_);
1796 return unless $filter;
1798 send_prot_line($self, $filter, $hops, $isolate, $line);
1803 my ($self, $filter, $hops, $isolate, $line) = @_;
1809 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1811 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1812 return unless $routeit;
1815 $self->send($routeit);
1817 $self->send($routeit) unless $self->{isolate} || $isolate;
1826 my @dxchan = DXChannel->get_all();
1828 my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
1830 # send it if it isn't the except list and isn't isolated and still has a hop count
1831 # taking into account filtering and so on
1832 foreach $dxchan (@dxchan) {
1833 next if $dxchan == $main::me;
1834 next if $dxchan == $self && $self->is_node;
1836 my ($filter, $hops);
1838 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
1846 my $isolate = shift;
1847 my ($filter, $hops);
1849 if ($self->{wwvfilter}) {
1850 ($filter, $hops) = $self->{wwvfilter}->it(@_);
1851 return unless $filter;
1853 send_prot_line($self, $filter, $hops, $isolate, $line)
1860 my @dxchan = DXChannel->get_all();
1862 my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
1864 # send it if it isn't the except list and isn't isolated and still has a hop count
1865 # taking into account filtering and so on
1866 foreach $dxchan (@dxchan) {
1867 next if $dxchan == $main::me;
1868 next if $dxchan == $self;
1870 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
1878 my $isolate = shift;
1879 my ($filter, $hops);
1881 if ($self->{wcyfilter}) {
1882 ($filter, $hops) = $self->{wcyfilter}->it(@_);
1883 return unless $filter;
1885 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
1893 my @dxchan = DXChannel->get_all();
1897 my $text = unpad($_[2]);
1899 if ($_[3] eq '*') { # sysops
1901 } elsif ($_[3] gt ' ') { # speciality list handling
1902 my ($name) = split /\./, $_[3];
1903 $target = "$name"; # put the rest in later (if bothered)
1910 $target = "ALL" if !$target;
1913 # obtain country codes etc
1914 my @a = Prefix::cty_data($_[0]);
1915 my @b = Prefix::cty_data($_[4]);
1916 if ($self->{inannfilter}) {
1917 my ($filter, $hops) =
1918 $self->{inannfilter}->it(@_, $self->{call},
1920 @b[0..2], $a[3], $b[3]);
1922 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1927 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
1928 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1932 Log('ann', $target, $_[0], $text);
1934 # send it if it isn't the except list and isn't isolated and still has a hop count
1935 # taking into account filtering and so on
1936 foreach $dxchan (@dxchan) {
1937 next if $dxchan == $main::me;
1938 next if $dxchan == $self && $self->is_node;
1939 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
1940 @a[0..2], @b[0..2]);
1949 $msgid = 1 if $msgid > 999;
1958 my @dxchan = DXChannel->get_all();
1961 my $text = unpad($_[2]);
1964 # munge the group and recast the line if required
1965 if ($target =~ s/\.LST$//) {
1969 # obtain country codes etc
1970 my @a = Prefix::cty_data($_[0]);
1971 my @b = Prefix::cty_data($_[4]);
1972 if ($self->{inannfilter}) {
1973 my ($filter, $hops) =
1974 $self->{inannfilter}->it(@_, $self->{call},
1976 @b[0..2], $a[3], $b[3]);
1978 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1983 if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
1984 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1989 Log('chat', $target, $_[0], $text);
1991 # send it if it isn't the except list and isn't isolated and still has a hop count
1992 # taking into account filtering and so on
1993 foreach $dxchan (@dxchan) {
1994 my $is_ak1a = $dxchan->is_ak1a;
1996 if ($dxchan->is_node) {
1997 next if $dxchan == $main::me;
1998 next if $dxchan == $self;
1999 next unless $dxchan->is_spider || $is_ak1a;
2000 next if $target eq 'LOCAL';
2001 if (!$ak1a_line && $is_ak1a) {
2002 $ak1a_line = DXProt::pc12($_[0], $text, $_[1], "$target.LST");
2006 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1],
2007 $text, @_, $self->{call}, @a[0..2], @b[0..2]);
2015 my $isolate = shift;
2019 my ($filter, $hops);
2021 if ($self->{annfilter}) {
2022 ($filter, $hops) = $self->{annfilter}->it(@_);
2023 return unless $filter;
2025 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
2034 sub send_local_config
2042 dbg('DXProt::send_local_config') if isdbg('trace');
2044 if ($self->{newroute}) {
2045 my @nodes = $self->{isolate} ? ($main::routeroot) : grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
2046 my @users = DXChannel::get_all_users();
2047 @localnodes = map { Route::Node::get($_->{call}) } @nodes;
2048 my @localusers = map { Route::User::get($_->{call}) } @users;
2049 $self->send_route($main::mycall, \&pc59, @nodes+@users+4, 'C', 0, $main::mycall, $main::routeroot, @localnodes, @localusers);
2052 if ($self->{isolate}) {
2053 @localnodes = ( $main::routeroot );
2054 $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
2056 # create a list of all the nodes that are not connected to this connection
2057 # and are not themselves isolated, this to make sure that isolated nodes
2058 # don't appear outside of this node
2060 # send locally connected nodes
2061 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
2062 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
2063 $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
2066 my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
2068 for $node (@rawintcalls) {
2069 push @intcalls, $node unless grep $node eq $_, @intcalls;
2071 my $ref = Route::Node::get($self->{call});
2072 my @rnodes = $ref->nodes;
2073 for $node (@intcalls) {
2074 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
2076 $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
2079 # get all the users connected on the above nodes and send them out
2080 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
2082 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
2083 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
2085 dbg("sent a null value") if isdbg('chanerr');
2092 # route a message down an appropriate interface for a callsign
2094 # is called route(to, pcline);
2098 my ($self, $call, $line) = @_;
2100 if (ref $self && $call eq $self->{call}) {
2101 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
2105 # always send it down the local interface if available
2106 my $dxchan = DXChannel->get($call);
2108 my $cl = Route::get($call);
2109 $dxchan = $cl->bestdxchan if $cl;
2111 if (ref $self && $dxchan eq $self) {
2112 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
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";
2185 # add a ping request to the ping queues
2188 my ($from, $to, $via) = @_;
2189 my $ref = $pings{$to} || [];
2192 $r->{t} = [ gettimeofday ];
2193 if ($via && (my $dxchan = DXChannel->get($via))) {
2194 $dxchan->send(pc51($to, $main::mycall, 1));
2196 route(undef, $to, pc51($to, $main::mycall, 1));
2200 my $u = DXUser->get_current($to);
2202 $u->lastping($main::systime);
2209 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
2210 if ($tonode eq $main::mycall) {
2211 my $ref = DXUser->get_current($fromnode);
2212 my $cref = Route::Node::get($fromnode);
2213 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
2214 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
2215 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
2216 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
2217 my $oldpriv = $self->{priv};
2218 $self->{priv} = $ref->{priv}; # assume the user's privilege level
2219 my @in = (DXCommandmode::run_cmd($self, $cmd));
2220 $self->{priv} = $oldpriv;
2221 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
2222 delete $self->{remotecmd};
2224 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
2227 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
2230 my $ref = DXUser->get_current($tonode);
2231 if ($ref && $ref->is_clx) {
2232 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
2234 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
2239 sub process_rcmd_reply
2241 my ($self, $tonode, $fromnode, $user, $line) = @_;
2242 if ($tonode eq $main::mycall) {
2243 my $s = $rcmds{$fromnode};
2245 my $dxchan = DXChannel->get($s->{call});
2246 my $ref = $user eq $tonode ? $dxchan : (DXChannel->get($user) || $dxchan);
2247 $ref->send($line) if $ref;
2248 delete $rcmds{$fromnode} if !$dxchan;
2250 # send unsolicited ones to the sysop
2251 my $dxchan = DXChannel->get($main::myalias);
2252 $dxchan->send($line) if $dxchan;
2255 my $ref = DXUser->get_current($tonode);
2256 if ($ref && $ref->is_clx) {
2257 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
2259 $self->route($tonode, pc35($fromnode, $tonode, $line));
2268 my $fromnode = shift;
2273 Log('rcmd', 'out', $fromnode, $line);
2274 if ($self->is_clx) {
2275 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
2277 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
2282 # add a rcmd request to the rcmd queues
2285 my ($self, $to, $cmd) = @_;
2288 $r->{call} = $self->{call};
2289 $r->{t} = $main::systime;
2293 my $ref = Route::Node::get($to);
2294 my $dxchan = $ref->bestdxchan;
2295 if ($dxchan && $dxchan->is_clx) {
2296 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
2298 route(undef, $to, pc34($main::mycall, $to, $cmd));
2305 my $pc39flag = shift;
2306 my $call = $self->call;
2308 return if $self->{disconnecting}++;
2310 unless ($pc39flag && $pc39flag == 1) {
2311 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
2314 # get rid of any PC16/17/19
2315 eph_del_regex("^PC1[679]*$call");
2317 # do routing stuff, remove me from routing table
2318 my $node = Route::Node::get($call);
2322 # remove the route from this node and return a list
2323 # of nodes that have become orphanned as a result.
2324 push @rout, $main::routeroot->remove_route($node, $self);
2326 # remove all my ephemera as well
2329 eph_del_regex("^PC1[679].*$c");
2333 # unbusy and stop and outgoing mail
2334 my $mref = DXMsg::get_busy($call);
2335 $mref->stop_msg($call) if $mref;
2337 # broadcast to all other nodes that all the nodes connected to via me are gone
2338 unless ($pc39flag && $pc39flag == 2) {
2339 $self->route_pc21($main::mycall, undef, @rout) if @rout;
2340 $self->route_pc59('D', 0, $main::mycall, $node);
2343 # delete all the unwanted nodes
2344 $_->delete for @rout;
2346 # remove outstanding pings
2347 delete $pings{$call};
2349 # I was the last node visited
2350 $self->user->node($main::mycall);
2352 # send info to all logged in thingies
2353 $self->tell_login('logoutn');
2355 Log('DXProt', $call . " Disconnected");
2357 $self->SUPER::disconnect;
2362 # send a talk message to this thingy
2366 my ($self, $from, $to, $via, $line, $origin) = @_;
2368 $line =~ s/\^/\\5E/g; # remove any ^ characters
2369 $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
2370 Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
2373 # send it if it isn't the except list and isn't isolated and still has a hop count
2374 # taking into account filtering and so on
2380 my $generate = shift;
2381 my $no = shift; # the no of things to filter on
2383 my ($filter, $hops);
2386 for (; @_ && $no; $no--) {
2389 # deal with non routing parameters
2390 unless (ref $r && $r->isa('Route')) {
2395 if (!$self->{isolate} && $self->{routefilter}) {
2398 ($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});
2402 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
2405 dbg("was sent a null value") if isdbg('chanerr');
2408 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
2412 foreach my $line (&$generate(@rin, @_)) {
2415 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
2417 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
2418 next unless $routeit;
2421 $self->send($routeit);
2430 my $generate = shift;
2432 my @dxchan = DXChannel::get_all_nodes();
2435 unless ($self->{isolate}) {
2436 foreach $dxchan (@dxchan) {
2437 next if $dxchan == $self;
2438 next if $dxchan == $main::me;
2439 next unless $dxchan->isa('DXProt');
2440 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
2441 if ($dxchan->{newroute}) {
2442 next if ($generate == \&pc19 || $generate==\&pc21);
2444 next if ($generate == \&pc19 || $generate==\&pc21) && !$dxchan->user->wantroutepc19;
2445 next if ($generate == \&pc59);
2448 $dxchan->send_route($origin, $generate, @_);
2456 return unless $self->user->wantpc16;
2459 broadcast_route($self, $origin, \&pc16, $line, 1, @_);
2465 return unless $self->user->wantpc16;
2468 broadcast_route($self, $origin, \&pc17, $line, 1, @_);
2476 broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
2484 broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
2492 broadcast_route($self, $origin, \&pc24, $line, 1, @_);
2500 broadcast_route($self, $origin, \&pc41, $line, 1, @_);
2508 broadcast_route($self, $origin, \&pc50, $line, 1, @_);
2517 broadcast_route($self, $origin, \&pc59, $line, scalar @_, @_);
2524 my ($filter, $hops) = (1, 1);
2526 if ($self->{inroutefilter}) {
2527 ($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);
2528 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
2536 my $t = shift || $eph_restime;
2540 $s =~ s/\^H\d\d?\^?\~?$//;
2541 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
2542 $eph{$s} = $main::systime + $t;
2550 while (($key, $val) = each %eph) {
2551 if ($key =~ m{$regex}) {
2561 while (($key, $val) = each %eph) {
2562 if ($main::systime >= $val) {
2573 while (($key, $val) = each %eph) {
2574 push @out, $key, $val;
2581 goto &DXCommandmode::run_cmd;