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);
39 use vars qw($VERSION $BRANCH);
40 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
41 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
42 $main::build += $VERSION;
43 $main::branch += $BRANCH;
45 use vars qw($pc11_max_age $pc23_max_age $last_pc50 $eph_restime $eph_info_restime $eph_pc34_restime
46 $last_hour $last10 %eph %pings %rcmds $ann_to_talk
47 $pingint $obscount %pc19list $chatdupeage
48 %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
49 $allowzero $decode_dk0wcy $send_opernam @checklist);
51 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
52 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
54 $last_hour = time; # last time I did an hourly periodic update
55 %pings = (); # outstanding ping requests outbound
56 %rcmds = (); # outstanding rcmd requests outbound
57 %nodehops = (); # node specific hop control
58 %pc19list = (); # list of outstanding PC19s that haven't had PC16s on them
60 $censorpc = 1; # Do a BadWords::check on text fields and reject things
61 # loads of 'bad things'
62 $baddx = new DXHash "baddx";
63 $badspotter = new DXHash "badspotter";
64 $badnode = new DXHash "badnode";
65 $last10 = $last_pc50 = time;
69 $eph_info_restime = 60*60;
70 $eph_pc34_restime = 30;
73 $chatdupeage = 20 * 60 * 60;
77 [ qw(i c c m bp bc c) ], # pc10
78 [ qw(i f m d t m c c h) ], # pc11
79 [ qw(i c bm m bm bm p h) ], # pc12
83 undef , # pc16 has to be validated manually
84 [ qw(i c c h) ], # pc17
86 undef , # pc19 has to be validated manually
87 undef , # pc20 no validation
88 [ qw(i c m h) ], # pc21
89 undef , # pc22 no validation
90 [ qw(i d n n n n m c c h) ], # pc23
91 [ qw(i c p h) ], # pc24
92 [ qw(i c c n n) ], # pc25
93 [ qw(i f m d t m c c bc) ], # pc26
94 [ qw(i d n n n n m c c bc) ], # pc27
95 [ qw(i c c m c d t p m bp n p bp bc) ], # pc28
96 [ qw(i c c n m) ], # pc29
97 [ qw(i c c n) ], # pc30
98 [ qw(i c c n) ], # pc31
99 [ qw(i c c n) ], # pc32
100 [ qw(i c c n) ], # pc33
101 [ qw(i c c m) ], # pc34
102 [ qw(i c c m) ], # pc35
103 [ qw(i c c m) ], # pc36
104 [ qw(i c c n m) ], # pc37
105 undef, # pc38 not interested
106 [ qw(i c m) ], # pc39
107 [ qw(i c c m p n) ], # pc40
108 [ qw(i c n m h) ], # pc41
109 [ qw(i c c n) ], # pc42
110 undef, # pc43 don't handle it
111 [ qw(i c c n m m c) ], # pc44
112 [ qw(i c c n m) ], # pc45
113 [ qw(i c c n) ], # pc46
116 [ qw(i c m h) ], # pc49
117 [ qw(i c n h) ], # pc50
118 [ qw(i c c n) ], # pc51
140 [ qw(i d n n n n n n m m m c c h) ], # pc73
151 [ qw(i c c c m) ], # pc84
152 [ qw(i c c c m) ], # pc85
157 [ qw(i c n) ], # pc90
160 # use the entry in the check list to check the field list presented
161 # return OK if line NOT in check list (for now)
166 return 0 if $n < 0 || $n > @checklist;
167 my $ref = $checklist[$n];
168 return 0 unless ref $ref;
171 for ($i = 1; $i < @$ref; $i++) {
172 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
173 return 0 unless $act;
174 next if $blank && $_[$i] =~ /^[ \*]$/;
176 return $i unless is_callsign($_[$i]);
177 } elsif ($act eq 'i') {
179 } elsif ($act eq 'm') {
180 return $i unless is_pctext($_[$i]);
181 } elsif ($act eq 'p') {
182 return $i unless is_pcflag($_[$i]);
183 } elsif ($act eq 'f') {
184 return $i unless is_freq($_[$i]);
185 } elsif ($act eq 'n') {
186 return $i unless $_[$i] =~ /^[\d ]+$/;
187 } elsif ($act eq 'h') {
188 return $i unless $_[$i] =~ /^H\d\d?$/;
189 } elsif ($act eq 'd') {
190 return $i unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
191 } elsif ($act eq 't') {
192 return $i unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
200 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
203 my $user = DXUser->get($main::mycall);
204 $DXProt::myprot_version += $main::version*100;
205 $main::me = DXProt->SUPER::alloc($main::mycall, 0, $user);
206 $main::me->{here} = 1;
207 $main::me->{state} = "indifferent";
208 $main::me->{sort} = 'S'; # S for spider
209 $main::me->{priv} = 9;
210 $main::me->{metric} = 0;
211 $main::me->{pingave} = 0;
212 $main::me->{registered} = 1;
213 $main::me->{version} = $main::version;
214 $main::me->{build} = $main::build;
218 # obtain a new connection this is derived from dxchannel
223 my $self = DXChannel::alloc(@_);
225 # add this node to the table, the values get filled in later
229 my $uref = Route::Node::get($call) || Route::Node->new($call);
232 $uref->version(5000);
233 $main::routeroot->link_node($uref, $self);
237 # this is how a pc connection starts (for an incoming connection)
238 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
239 # all the crap that comes between).
242 my ($self, $line, $sort) = @_;
243 my $call = $self->{call};
244 my $user = $self->{user};
247 my $host = $self->{conn}->{peerhost} || "unknown";
248 Log('DXProt', "$call connected from $host");
250 # remember type of connection
251 $self->{consort} = $line;
252 $self->{outbound} = $sort eq 'O';
253 my $priv = $user->priv;
254 $priv = $user->priv(1) unless $priv;
255 $self->{priv} = $priv; # other clusters can always be 'normal' users
256 $self->{lang} = $user->lang || 'en';
257 $self->{isolate} = $user->{isolate};
258 $self->{consort} = $line; # save the connection type
262 # sort out registration
263 $self->{registered} = 1;
265 # get the output filters
266 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
267 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
268 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
269 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
270 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
273 # get the INPUT filters (these only pertain to Clusters)
274 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
275 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
276 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
277 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
278 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
280 # set unbuffered and no echo
281 $self->send_now('B',"0");
282 $self->send_now('E',"0");
283 $self->conn->echo(0) if $self->conn->can('echo');
285 # ping neighbour node stuff
286 my $ping = $user->pingint;
287 $ping = $pingint unless defined $ping;
288 $self->{pingint} = $ping;
289 $self->{nopings} = $user->nopings || $obscount;
290 $self->{pingtime} = [ ];
291 $self->{pingave} = 999;
292 $self->{metric} ||= 100;
293 $self->{lastping} = $main::systime;
295 # send initialisation string
296 unless ($self->{outbound}) {
300 $self->state('init');
301 $self->{pc50_t} = $main::systime;
303 # send info to all logged in thingies
304 $self->tell_login('loginn');
306 # run a script send the output to the debug file
307 my $script = new Script(lc $call) || new Script('node_default');
308 $script->run($self) if $script;
312 # send outgoing 'challenge'
323 $_[0] =~ s/^PC90\^[-A-Z0-9]+\^\d+\^//;
324 $_[0] =~ s/^PC91\^[-A-Z0-9]+\^\d+\^[-A-Z0-9]+\^//;
332 # $self->SUPER::send($line);
337 # This is the normal pcxx despatcher
341 my ($self, $line) = @_;
343 # remove any incoming PC90 frames
346 my @field = split /\^/, $line;
347 return unless @field;
349 pop @field if $field[-1] eq '~';
351 # print join(',', @field), "\n";
354 # process PC frames, this will fail unless the frame starts PCnn
355 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
356 unless (defined $pcno && $pcno >= 10 && $pcno <= 99) {
357 dbg("PCPROT: unknown protocol") if isdbg('chanerr');
361 # check for and dump bad protocol messages
362 my $n = check($pcno, @field);
364 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
368 my $origin = $self->{call};
370 my $sub = "handle_$pcno";
372 if ($self->can($sub)) {
373 $self->$sub($pcno, $line, $origin, @field);
375 $self->handle_default($pcno, $line, $origin, @field);
379 # incoming talk commands
388 return if $rspfcheck and !$self->rspfcheck(0, $_[6], $_[1]);
390 # will we allow it at all?
393 if (@bad = BadWords::check($_[3])) {
394 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
399 # is it for me or one of mine?
400 my ($from, $to, $via, $call, $dxchan);
409 # if this is a 'nodx' node then ignore it
410 if ($badnode->in($_[6]) || ($via && $badnode->in($via))) {
411 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
415 # if this is a 'bad spotter' user then ignore it
417 $nossid =~ s/-\d+$//;
418 if ($badspotter->in($nossid)) {
419 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
423 # if we are converting announces to talk is it a dup?
425 if (AnnTalk::is_talk_candidate($from, $_[3]) && AnnTalk::dup($from, $to, $_[3])) {
426 dbg("DXPROT: Dupe talk from announce, dropped") if isdbg('chanerr');
431 # it is here and logged on
432 $dxchan = DXChannel->get($main::myalias) if $to eq $main::mycall;
433 $dxchan = DXChannel->get($to) unless $dxchan;
434 if ($dxchan && $dxchan->is_user) {
436 $dxchan->talk($from, $to, $via, $_[3]);
440 # is it elsewhere, visible on the cluster via the to address?
441 # note: this discards the via unless the to address is on
444 if ($ref = Route::get($to)) {
445 $vref = Route::Node::get($via) if $via;
446 $vref = undef unless $vref && grep $to eq $_, $vref->users;
447 $ref->bestdxchan->talk($from, $to, $vref ? $via : undef, $_[3], $_[6]);
451 # not visible here, send a message of condolence
453 $ref = Route::get($from);
454 $vref = $ref = Route::Node::get($_[6]) unless $ref;
456 $dxchan = $ref->bestdxchan;
457 $dxchan->talk($main::mycall, $from, $vref ? $vref->call : undef, $dxchan->msg('talknh', $to) );
469 # route 'foreign' pc26s
471 if ($_[7] ne $main::mycall) {
472 $self->route($_[7], $line);
478 # return if $rspfcheck and !$self->rspfcheck(1, $_[7], $_[6]);
480 # if this is a 'nodx' node then ignore it
481 if ($badnode->in($_[7])) {
482 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
486 # if this is a 'bad spotter' user then ignore it
488 $nossid =~ s/-\d+$//;
489 if ($badspotter->in($nossid)) {
490 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
494 # convert the date to a unix date
495 my $d = cltounix($_[3], $_[4]);
496 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
497 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
498 dbg("PCPROT: Spot ignored, invalid date or out of range ($_[3] $_[4])\n") if isdbg('chanerr');
503 if ($baddx->in($_[2]) || BadWords::check($_[2]) || $_[2] =~ /COCK/) {
504 dbg("PCPROT: Bad DX spot, ignored") if isdbg('chanerr');
509 $_[5] =~ s/^\s+//; # take any leading blanks off
510 $_[2] = unpad($_[2]); # take off leading and trailing blanks from spotted callsign
511 if ($_[2] =~ /BUST\w*$/) {
512 dbg("PCPROT: useless 'BUSTED' spot") if isdbg('chanerr');
517 if (@bad = BadWords::check($_[5])) {
518 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
524 my @spot = Spot::prepare($_[1], $_[2], $d, $_[5], $_[6], $_[7]);
525 # global spot filtering on INPUT
526 if ($self->{inspotsfilter}) {
527 my ($filter, $hops) = $self->{inspotsfilter}->it(@spot);
529 dbg("PCPROT: Rejected by input spot filter") if isdbg('chanerr');
534 # this goes after the input filtering, but before the add
535 # so that if it is input filtered, it isn't added to the dup
536 # list. This allows it to come in from a "legitimate" source
537 if (Spot::dup($_[1], $_[2], $d, $_[5], $_[6])) {
538 dbg("PCPROT: Duplicate Spot ignored\n") if isdbg('chanerr');
546 # @spot at this point contains:-
547 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
548 # then spotted itu, spotted cq, spotters itu, spotters cq
549 # you should be able to route on any of these
552 # fix up qra locators of known users
553 my $user = DXUser->get_current($spot[4]);
555 my $qra = $user->qra;
556 unless ($qra && is_qra($qra)) {
557 my $lat = $user->lat;
558 my $long = $user->long;
559 if (defined $lat && defined $long) {
560 $user->qra(DXBearing::lltoqra($lat, $long));
565 # send a remote command to a distant cluster if it is visible and there is no
566 # qra locator and we havn't done it for a month.
568 unless ($user->qra) {
570 my $to = $user->homenode;
571 my $last = $user->lastoper || 0;
572 if ($send_opernam && $to && $to ne $main::mycall && $main::systime > $last + $DXUser::lastoperinterval && ($node = Route::Node::get($to)) ) {
573 my $cmd = "forward/opernam $spot[4]";
574 # send the rcmd but we aren't interested in the replies...
575 my $dxchan = $node->bestdxchan;
576 if ($dxchan && $dxchan->is_clx) {
577 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
579 route(undef, $to, pc34($main::mycall, $to, $cmd));
583 $node = Route::Node::get($to);
585 $dxchan = $node->bestdxchan;
586 if ($dxchan && $dxchan->is_clx) {
587 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
589 route(undef, $to, pc34($main::mycall, $to, $cmd));
593 $user->lastoper($main::systime);
602 $r = Local::spot($self, @spot);
604 # dbg("Local::spot1 error $@") if isdbg('local') if $@;
607 # DON'T be silly and send on PC26s!
608 return if $pcno == 26;
610 # send out the filtered spots
611 send_dx_spot($self, $line, @spot) if @spot;
622 # return if $rspfcheck and !$self->rspfcheck(1, $_[5], $_[1]);
624 # announce duplicate checking
625 $_[3] =~ s/^\s+//; # remove leading blanks
629 if (@bad = BadWords::check($_[3])) {
630 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
635 # if this is a 'nodx' node then ignore it
636 if ($badnode->in($_[5])) {
637 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
641 # if this is a 'bad spotter' user then ignore it
643 $nossid =~ s/-\d+$//;
644 if ($badspotter->in($nossid)) {
645 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
651 if ((($dxchan = DXChannel->get($_[2])) && $dxchan->is_user) || $_[4] =~ /^[\#\w.]+$/){
652 $self->send_chat($line, @_[1..6]);
653 } elsif ($_[2] eq '*' || $_[2] eq $main::mycall) {
655 # ignore something that looks like a chat line coming in with sysop
656 # flag - this is a kludge...
657 if ($_[3] =~ /^\#\d+ / && $_[4] eq '*') {
658 dbg('PCPROT: Probable chat rewrite, dropped') if isdbg('chanerr');
662 # here's a bit of fun, convert incoming ann with a callsign in the first word
663 # or one saying 'to <call>' to a talk if we can route to the recipient
665 my $call = AnnTalk::is_talk_candidate($_[1], $_[3]);
667 my $ref = Route::get($call);
669 $dxchan = $ref->bestdxchan;
670 $dxchan->talk($_[1], $call, undef, $_[3], $_[5]) if $dxchan != $self;
677 $self->send_announce($line, @_[1..6]);
679 $self->route($_[2], $line);
695 my $newline = "PC16^";
697 # do I want users from this channel?
698 unless ($self->user->wantpc16) {
699 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
704 if ($ncall eq $main::mycall) {
705 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
709 # do we believe this call?
710 unless ($ncall eq $self->{call} || $self->is_believed($ncall)) {
711 dbg("PCPROT: We don't believe $ncall on $self->{call}");
715 my $node = Route::Node::get($ncall);
717 dbg("PCPROT: Node $ncall not in config") if isdbg('chanerr');
721 # dedupe only that which we potentially process
722 if (eph_dup($line)) {
723 dbg("PCPROT: dup PC16 detected") if isdbg('chanerr');
730 for ($i = 2; $i < $#_; $i++) {
731 my ($call, $conf, $here) = $_[$i] =~ /^(\S+) (\S) (\d)/o;
732 next unless $call && $conf && defined $here && is_callsign($call);
733 next if $call eq $main::mycall;
735 eph_del_regex("^PC17\\^$call\\^$ncall");
737 $conf = $conf eq '*';
739 # reject this if we think it is a node already
740 my $r = Route::Node::get($call);
741 my $u = DXUser->get_current($call) unless $r;
742 if ($r || ($u && $u->is_node)) {
743 dbg("PCPROT: $call is a node") if isdbg('chanerr');
747 $r = Route::User::get($call) || Route::User->new($call);
750 $node->lastseen($main::systime);
752 push @new, $node->add_user($r);
754 # add this station to the user database, if required
755 $call =~ s/-\d+$//o; # remove ssid for users
756 my $user = DXUser->get_current($call);
757 $user = DXUser->new($call) if !$user;
758 $user->homenode($node->call) if !$user->homenode;
759 $user->node($node->call);
760 $user->lastin($main::systime) unless DXChannel->get($call);
763 $self->route_pc16($origin, $line, $node, @new) if @new;
777 eph_del_regex("^PC16\\^$ncall.*$ucall");
779 # do I want users from this channel?
780 unless ($self->user->wantpc16) {
781 dbg("PCPROT: don't send users to $self->{call}") if isdbg('chanerr');
784 if ($ncall eq $main::mycall) {
785 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
789 # do we believe this call?
790 unless ($ncall eq $self->{call} || $self->is_believed($ncall)) {
791 dbg("PCPROT: We don't believe $ncall on $self->{call}");
795 my $uref = Route::User::get($ucall);
797 dbg("PCPROT: Route::User $ucall not in config") if isdbg('chanerr');
799 my $node = Route::Node::get($ncall);
801 dbg("PCPROT: Route::Node $ncall not in config") if isdbg('chanerr');
804 return unless $node && $uref;
808 if ($self->in_filter_route($node)) {
810 if (eph_dup($line)) {
811 dbg("PCPROT: dup PC17 detected") if isdbg('chanerr');
814 push @new, $node->del_user($uref);
817 $self->route_pc17($origin, $line, $node, $uref) if @new;
819 # get rid of orphaned users;
830 $self->state('init');
832 # record the type and version offered
833 if ($_[1] =~ /DXSpider Version: (\d+\.\d+) Build: (\d+\.\d+)/) {
834 $self->version(53 + $1);
835 $self->user->version(53 + $1);
836 $self->build(0 + $2);
837 $self->user->build(0 + $2);
838 unless ($self->is_spider) {
839 $self->user->sort('S');
844 $self->version(50.0);
845 $self->version($_[2] / 100) if $_[2] && $_[2] =~ /^\d+$/;
846 $self->user->version($self->version);
848 $self->newroute( $_[1] =~ /NewRoute/ );
850 # first clear out any nodes on this dxchannel
851 my $node = Route::Node::get($self->{call}) ;
853 foreach my $n ($node->nodes) {
854 next if $n eq $main::mycall;
855 next if $n eq $self->{call};
856 my $nref = Route::Node::get($n);
857 push @rout, $node->remove_route($nref, $self) if $nref;
859 $self->route_pc21($origin, $line, @rout) if @rout;
864 # send the new config
865 $self->send_local_config();
869 # incoming cluster list
878 my $newline = "PC19^";
880 if (eph_dup($line)) {
881 dbg("PCPROT: dup PC19 detected") if isdbg('chanerr');
888 # first get the INTERFACE node
889 my $parent = Route::Node::get($self->{call});
891 dbg("DXPROT: my parent $self->{call} has disappeared");
899 for ($i = 1; $i < $#_-1; $i += 4) {
901 my $call = uc $_[$i+1];
904 next unless defined $here && defined $conf && is_callsign($call);
906 # check for sane parameters
907 # $ver = 5000 if $ver eq '0000';
908 next if $ver < 5000; # only works with version 5 software
909 next if length $call < 3; # min 3 letter callsigns
910 next if $call eq $main::mycall;
912 # do we believe this call?
913 unless ($call eq $self->{call} || $self->is_believed($call)) {
914 dbg("PCPROT: We don't believe $call on $self->{call}");
918 eph_del_regex("^PC(?:21\\^$call|17\\^[^\\^]+\\^$call)");
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;
932 my $r = Route::Node::get($call) || Route::Node->new($call);
936 $r->lastseen($main::systime);
938 if ($self->in_filter_route($r)) {
939 push @new, $parent->link_node($r, $self);
943 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
944 my $mref = DXMsg::get_busy($call);
945 $mref->stop_msg($call) if $mref;
947 $user->lastin($main::systime) unless DXChannel->get($call);
951 # route out new nodes to legacy nodes
952 $self->route_pc19($origin, $line, @new) if @new;
953 $self->route_pc59('A', 0, $self->{call}, @rout) if @rout;
956 # send local configuration
963 $self->send_local_config();
965 $self->state('normal');
966 $self->{lastping} = 0;
969 # delete a cluster from the list
978 return if $call eq $main::mycall; # don't allow malicious buggers to disconnect me (or ignore loops)!
980 unless ($call eq $self->{call} || $self->is_believed($call)) {
981 dbg("PCPROT: We don't believe $call on $self->{call}");
985 eph_del_regex("^PC1[679].*$call");
987 # if I get a PC21 from the same callsign as self then treat it
988 # as a PC39: I have gone away
989 if ($call eq $self->call) {
990 $self->disconnect(1);
996 my $parent = Route::Node::get($self->{call});
998 dbg("DXPROT: my parent $self->{call} has disappeared");
1004 my $node = Route::Node::get($call);
1006 $node->lastseen($main::systime);
1009 return unless $self->in_filter_route($node);
1011 push @new, $node->link_node($parent, $self);
1014 $self->route_pc21($origin, $line, @new) if @new;
1015 $self->route_pc59('D', 0, $self->{call}, @rout) if @rout;
1017 # get rid of orphaned nodes;
1018 $_->delete for @new;
1028 $self->state('normal');
1029 $self->{lastping} = 0;
1040 # route foreign' pc27s
1042 if ($_[8] ne $main::mycall) {
1043 $self->route($_[8], $line);
1048 # only do a rspf check on PC23 (not 27)
1050 return if $rspfcheck and !$self->rspfcheck(1, $_[8], $_[7])
1054 my $d = cltounix($_[1], sprintf("%02d18Z", $_[2]));
1055 my $sfi = unpad($_[3]);
1056 my $k = unpad($_[4]);
1057 my $i = unpad($_[5]);
1058 my ($r) = $_[6] =~ /R=(\d+)/;
1060 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1061 dbg("PCPROT: WWV Date ($_[1] $_[2]) out of range") if isdbg('chanerr');
1064 if (Geomag::dup($d,$sfi,$k,$i,$_[6])) {
1065 dbg("PCPROT: Dup WWV Spot ignored\n") if isdbg('chanerr');
1068 $_[7] =~ s/-\d+$//o; # remove spotter's ssid
1070 my $wwv = Geomag::update($d, $_[2], $sfi, $k, $i, @_[6..8], $r);
1074 $rep = Local::wwv($self, $_[1], $_[2], $sfi, $k, $i, @_[6..8], $r);
1076 # dbg("Local::wwv2 error $@") if isdbg('local') if $@;
1079 # DON'T be silly and send on PC27s!
1080 return if $pcno == 27;
1082 # broadcast to the eager world
1083 send_wwv_spot($self, $line, $d, $_[2], $sfi, $k, $i, @_[6..8]);
1093 my $call = uc $_[1];
1095 $nref = Route::Node::get($call);
1096 $uref = Route::User::get($call);
1097 return unless $nref || $uref; # if we don't know where they are, it's pointless sending it on
1099 if (eph_dup($line)) {
1100 dbg("PCPROT: Dup PC24 ignored\n") if isdbg('chanerr');
1104 $nref->here($_[2]) if $nref;
1105 $uref->here($_[2]) if $uref;
1106 my $ref = $nref || $uref;
1107 return unless $self->in_filter_route($ref);
1109 $self->route_pc24($origin, $line, $ref, $_[3]);
1119 if ($_[1] ne $main::mycall) {
1120 $self->route($_[1], $line);
1123 if ($_[2] eq $main::mycall) {
1124 dbg("PCPROT: Trying to merge to myself, ignored") if isdbg('chanerr');
1128 Log('DXProt', "Merge request for $_[3] spots and $_[4] WWV from $_[2]");
1132 my @in = reverse Spot::search(1, undef, undef, 0, $_[3]);
1135 $self->send(pc26(@{$in}[0..4], $_[2]));
1141 my @in = reverse Geomag::search(0, $_[4], time, 1);
1144 $self->send(pc27(@{$in}[0..5], $_[2]));
1149 sub handle_26 {goto &handle_11}
1150 sub handle_27 {goto &handle_23}
1152 # mail/file handling
1159 if ($_[1] eq $main::mycall) {
1161 my $sub = "DXMsg::handle_$pcno";
1164 $self->route($_[1], $line) unless $self->is_clx;
1168 sub handle_29 {goto &handle_28}
1169 sub handle_30 {goto &handle_28}
1170 sub handle_31 {goto &handle_28}
1171 sub handle_32 {goto &handle_28}
1172 sub handle_33 {goto &handle_28}
1180 if (eph_dup($line, $eph_pc34_restime)) {
1181 dbg("PCPROT: dupe PC34, ignored") if isdbg('chanerr');
1183 $self->process_rcmd($_[1], $_[2], $_[2], $_[3]);
1187 # remote command replies
1194 eph_del_regex("^PC35\\^$_[2]\\^$_[1]\\^");
1195 $self->process_rcmd_reply($_[1], $_[2], $_[1], $_[3]);
1198 sub handle_36 {goto &handle_34}
1207 if ($_[1] eq $main::mycall) {
1209 my $sub = "DXDb::handle_$pcno";
1212 $self->route($_[1], $line) unless $self->is_clx;
1216 # node connected list from neighbour
1225 # incoming disconnect
1232 if ($_[1] eq $self->{call}) {
1233 $self->disconnect(1);
1235 dbg("PCPROT: came in on wrong channel") if isdbg('chanerr');
1239 sub handle_40 {goto &handle_28}
1251 $l =~ s/[\x00-\x20\x7f-\xff]+//g; # remove all funny characters and spaces for dup checking
1252 if (eph_dup($l, $eph_info_restime)) {
1253 dbg("PCPROT: dup PC41, ignored") if isdbg('chanerr');
1257 # input filter if required
1258 # my $ref = Route::get($call) || Route->new($call);
1259 # return unless $self->in_filter_route($ref);
1261 if ($_[3] eq $_[2] || $_[3] =~ /^\s*$/) {
1262 dbg('PCPROT: invalid value') if isdbg('chanerr');
1266 # add this station to the user database, if required
1267 my $user = DXUser->get_current($call);
1268 $user = DXUser->new($call) unless $user;
1272 } elsif ($_[2] == 2) {
1274 } elsif ($_[2] == 3) {
1275 if (is_latlong($_[3])) {
1276 my ($lat, $long) = DXBearing::stoll($_[3]);
1279 $user->qra(DXBearing::lltoqra($lat, $long));
1281 dbg('PCPROT: not a valid lat/long') if isdbg('chanerr');
1284 } elsif ($_[2] == 4) {
1285 $user->homenode($_[3]);
1286 } elsif ($_[2] == 5) {
1287 if (is_qra(uc $_[3])) {
1288 my ($lat, $long) = DXBearing::qratoll(uc $_[3]);
1291 $user->qra(uc $_[3]);
1293 dbg('PCPROT: not a valid QRA locator') if isdbg('chanerr');
1297 $user->lastoper($main::systime); # to cut down on excessive for/opers being generated
1300 unless ($self->{isolate}) {
1301 DXChannel::broadcast_nodes($line, $self); # send it to everyone but me
1304 # perhaps this IS what we want after all
1305 # $self->route_pc41($ref, $call, $_[2], $_[3], $_[4]);
1308 sub handle_42 {goto &handle_28}
1312 sub handle_44 {goto &handle_37}
1313 sub handle_45 {goto &handle_37}
1314 sub handle_46 {goto &handle_37}
1315 sub handle_47 {goto &handle_37}
1316 sub handle_48 {goto &handle_37}
1318 # message and database
1326 if (eph_dup($line)) {
1327 dbg("PCPROT: Dup PC49 ignored\n") if isdbg('chanerr');
1331 if ($_[1] eq $main::mycall) {
1332 DXMsg::handle_49($self, @_);
1334 $self->route($_[1], $line) unless $self->is_clx;
1338 # keep alive/user list
1347 my $node = Route::Node::get($call);
1349 return unless $node->call eq $self->{call};
1350 $node->usercount($_[2]);
1352 # input filter if required
1353 return unless $self->in_filter_route($node);
1355 $self->route_pc50($origin, $line, $node, $_[2], $_[3]) unless eph_dup($line);
1359 # incoming ping requests/answers
1372 if ($to eq $main::mycall) {
1374 $self->send(pc51($from, $to, '0'));
1376 # it's a reply, look in the ping list for this one
1377 my $ref = $pings{$from};
1379 my $tochan = DXChannel->get($from);
1381 my $r = shift @$ref;
1382 my $dxchan = DXChannel->get($r->{call});
1383 next unless $dxchan;
1384 my $t = tv_interval($r->{t}, [ gettimeofday ]);
1385 if ($dxchan->is_user) {
1386 my $s = sprintf "%.2f", $t;
1387 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
1388 $dxchan->send($dxchan->msg('pingi', $from, $s, $ave))
1389 } elsif ($dxchan->is_node) {
1391 my $nopings = $tochan->user->nopings || $obscount;
1392 push @{$tochan->{pingtime}}, $t;
1393 shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
1395 # cope with a missed ping, this means you must set the pingint large enough
1396 if ($t > $tochan->{pingint} && $t < 2 * $tochan->{pingint} ) {
1397 $t -= $tochan->{pingint};
1400 # calc smoothed RTT a la TCP
1401 if (@{$tochan->{pingtime}} == 1) {
1402 $tochan->{pingave} = $t;
1404 $tochan->{pingave} = $tochan->{pingave} + (($t - $tochan->{pingave}) / 6);
1406 $tochan->{nopings} = $nopings; # pump up the timer
1413 if (eph_dup($line)) {
1414 dbg("PCPROT: dup PC51 detected") if isdbg('chanerr');
1417 # route down an appropriate thingy
1418 $self->route($to, $line);
1422 # New style routing handler
1430 return unless eph_dup($line);
1432 my ($sort, $hextime, $ncall) = @_[1,2,3];
1433 if ($ncall eq $main::mycall) {
1434 dbg("PCPROT: ignoring PC59 for me") if isdbg('chan');
1438 # mark myself as NewRoute if I get a PC59
1439 $self->{newroute} = 1 if $ncall eq $self->{call};
1441 # do this once for filtering with a throwaway routing entry if a new node
1442 my $fnode = Route::Node::get($ncall) || Route::new($ncall);
1443 return unless $self->in_filter_route($fnode);
1445 # now do it properly for actions
1446 my $node = Route::Node::get($ncall) || Route::Node->new($ncall);
1449 # find each of the entries (or create new ones)
1451 for my $ent (@_[4..-1]) {
1452 my ($esort, $ehere, $ecall) = unpack "A A A*", $ent;
1455 # create user, if required
1456 my $user = DXUser->get_current($ecall);
1458 $user = DXUser->new($ecall);
1460 $user->priv(1); # I have relented and defaulted nodes
1462 $user->homenode($ncall);
1463 $user->node($ncall);
1465 if ($esort eq 'U') {
1466 $ref = Route::User::get($ecall);
1468 # create user, if required
1469 my $user = DXUser->get_current($ecall);
1471 $user = DXUser->new($ecall);
1473 $user->homenode($ncall);
1474 $user->node($ncall);
1477 $ref = Route::User->new($ecall, 0);
1479 } elsif ($esort eq 'N') {
1480 $ref = Route::Node::get($ecall);
1482 # create user, if required
1483 my $user = DXUser->get_current($ecall);
1485 $user = DXUser->new($ecall);
1486 $user->priv(1); # I have relented and defaulted nodes
1489 $user->homenode($ncall);
1490 $user->node($ncall);
1493 $ref = Route::Node->new($ecall, 0);
1496 dbg("DXPROT: unknown entity type '$esort' on $ecall for node $ncall") if isdbg('chan');
1499 $ref->here($ehere); # might as well set this here
1500 $ref->lastseen($main::systime);
1504 # if it is a delete, disconnect all the entries mentioned
1505 # from this node (which is a parent in this context).
1509 for my $ref (@refs) {
1510 next if $ref->call eq $ncall;
1511 if ($ref->isa('Route::Node')) {
1512 push @delnode, $node->unlink_node($ref, $self);
1513 } elsif ($ref->isa('Route::User')) {
1514 push @deluser, $node->del_user($ref);
1519 # if it is an add, connect all the entries
1523 for my $ref (@refs) {
1524 next if $ref->call eq $ncall;
1525 if ($ref->isa('Route::Node')) {
1526 my $new = $node->link_node($ref, $self);
1527 push @addnode, $new if $new;
1528 } elsif ($ref->isa('Route::User')) {
1529 push @adduser, $node->del_user($ref);
1534 # if it is a configure, unlink all the nodes and users that
1535 # are not in @refs but are in the node, then add all the
1536 # nodes and users that are @refs but not in the node.
1543 for my $r (map {Route::Node::get($_)} $node->nodes) {
1545 push @dn, $r unless grep $_->call eq $r->call, @refs;
1547 for my $r (map {Route::User::get($_)} $node->users) {
1549 push @du, $r unless grep $_->call eq $r->call, @refs;
1553 if ($r->isa('Route::Node')) {
1554 push @an, $r unless grep $r->call eq $_, $node->nodes;
1555 } elsif ($r->isa('Route::User')) {
1556 push @au, $r unless grep $r->call eq $_, $node->users;
1559 push @delnode, $node->unlink_node($_, $self) for @dn;
1560 push @deluser, $node->del_user($_) for @du;
1561 push @addnode, $node->link_node($_, $self) for @an;
1562 push @adduser, $node->add_user($_) for @au;
1565 $self->route_pc21($origin, $line, @delnode) if @delnode;
1566 $self->route_pc19($origin, $line, @addnode) if @addnode;
1567 $self->route_pc17($origin, $line, @deluser) if @deluser;
1568 $self->route_pc16($origin, $line, @adduser) if @adduser;
1570 $self->route_pc59($sort, $hextime, $ncall, @refs) if @refs;
1571 $_->delete for @delnode, @deluser;
1575 # dunno but route it
1583 if ($call ne $main::mycall) {
1584 $self->route($call, $line);
1598 my $d = cltounix($call, sprintf("%02d18Z", $_[2]));
1599 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $_[2] < 0 || $_[2] > 23) {
1600 dbg("PCPROT: WCY Date ($call $_[2]) out of range") if isdbg('chanerr');
1603 @_ = map { unpad($_) } @_;
1605 dbg("PCPROT: Dup WCY Spot ignored\n") if isdbg('chanerr');
1609 my $wcy = WCY::update($d, @_[2..12]);
1613 $rep = Local::wcy($self, @_[1..12]);
1615 # dbg("Local::wcy error $@") if isdbg('local') if $@;
1618 # broadcast to the eager world
1619 send_wcy_spot($self, $line, $d, @_[2..12]);
1622 # remote commands (incoming)
1629 $self->process_rcmd($_[1], $_[2], $_[3], $_[4]);
1632 # remote command replies
1639 $self->process_rcmd_reply($_[1], $_[2], $_[3], $_[4]);
1642 # if get here then rebroadcast the thing with its Hop count decremented (if
1643 # there is one). If it has a hop count and it decrements to zero then don't
1646 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
1657 if (eph_dup($line)) {
1658 dbg("PCPROT: Ephemeral dup, dropped") if isdbg('chanerr');
1660 unless ($self->{isolate}) {
1661 DXChannel::broadcast_nodes($line, $self) if $line =~ /\^H\d+\^?~?$/; # send it to everyone but me
1667 # This is called from inside the main cluster processing loop and is used
1668 # for despatching commands that are doing some long processing job
1673 my @dxchan = DXChannel->get_all();
1677 # send out a pc50 on EVERY channel all at once
1678 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
1679 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
1684 foreach $dxchan (@dxchan) {
1685 next unless $dxchan->is_node();
1686 next if $dxchan == $main::me;
1689 $dxchan->send($pc50s) if $pc50s;
1691 # send a ping out on this channel
1692 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
1693 if ($dxchan->{nopings} <= 0) {
1694 $dxchan->disconnect;
1696 addping($main::mycall, $dxchan->call);
1697 $dxchan->{nopings} -= 1;
1698 $dxchan->{lastping} = $t;
1704 if ($t - $last10 >= 10) {
1705 # clean out ephemera
1712 if ($main::systime - 3600 > $last_hour) {
1713 $last_hour = $main::systime;
1718 # finish up a pc context
1722 # some active measures
1730 my @dxchan = DXChannel->get_all();
1733 # send it if it isn't the except list and isn't isolated and still has a hop count
1734 # taking into account filtering and so on
1735 foreach $dxchan (@dxchan) {
1736 next if $dxchan == $main::me;
1737 next if $dxchan == $self && $self->is_node;
1738 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
1746 my $isolate = shift;
1747 my ($filter, $hops);
1749 if ($self->{spotsfilter}) {
1750 ($filter, $hops) = $self->{spotsfilter}->it(@_);
1751 return unless $filter;
1753 send_prot_line($self, $filter, $hops, $isolate, $line);
1758 my ($self, $filter, $hops, $isolate, $line) = @_;
1764 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1766 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1767 return unless $routeit;
1770 $self->send($routeit);
1772 $self->send($routeit) unless $self->{isolate} || $isolate;
1781 my @dxchan = DXChannel->get_all();
1783 my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
1785 # send it if it isn't the except list and isn't isolated and still has a hop count
1786 # taking into account filtering and so on
1787 foreach $dxchan (@dxchan) {
1788 next if $dxchan == $main::me;
1789 next if $dxchan == $self && $self->is_node;
1791 my ($filter, $hops);
1793 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
1801 my $isolate = shift;
1802 my ($filter, $hops);
1804 if ($self->{wwvfilter}) {
1805 ($filter, $hops) = $self->{wwvfilter}->it(@_);
1806 return unless $filter;
1808 send_prot_line($self, $filter, $hops, $isolate, $line)
1815 my @dxchan = DXChannel->get_all();
1817 my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
1819 # send it if it isn't the except list and isn't isolated and still has a hop count
1820 # taking into account filtering and so on
1821 foreach $dxchan (@dxchan) {
1822 next if $dxchan == $main::me;
1823 next if $dxchan == $self;
1825 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
1833 my $isolate = shift;
1834 my ($filter, $hops);
1836 if ($self->{wcyfilter}) {
1837 ($filter, $hops) = $self->{wcyfilter}->it(@_);
1838 return unless $filter;
1840 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
1848 my @dxchan = DXChannel->get_all();
1852 my $text = unpad($_[2]);
1854 if ($_[3] eq '*') { # sysops
1856 } elsif ($_[3] gt ' ') { # speciality list handling
1857 my ($name) = split /\./, $_[3];
1858 $target = "$name"; # put the rest in later (if bothered)
1865 $target = "ALL" if !$target;
1868 # obtain country codes etc
1869 my @a = Prefix::cty_data($_[0]);
1870 my @b = Prefix::cty_data($_[4]);
1871 if ($self->{inannfilter}) {
1872 my ($filter, $hops) =
1873 $self->{inannfilter}->it(@_, $self->{call},
1875 @b[0..2], $a[3], $b[3]);
1877 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1882 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
1883 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1887 Log('ann', $target, $_[0], $text);
1889 # send it if it isn't the except list and isn't isolated and still has a hop count
1890 # taking into account filtering and so on
1891 foreach $dxchan (@dxchan) {
1892 next if $dxchan == $main::me;
1893 next if $dxchan == $self && $self->is_node;
1894 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
1895 @a[0..2], @b[0..2]);
1904 $msgid = 1 if $msgid > 999;
1913 my @dxchan = DXChannel->get_all();
1916 my $text = unpad($_[2]);
1919 # munge the group and recast the line if required
1920 if ($target =~ s/\.LST$//) {
1924 # obtain country codes etc
1925 my @a = Prefix::cty_data($_[0]);
1926 my @b = Prefix::cty_data($_[4]);
1927 if ($self->{inannfilter}) {
1928 my ($filter, $hops) =
1929 $self->{inannfilter}->it(@_, $self->{call},
1931 @b[0..2], $a[3], $b[3]);
1933 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1938 if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
1939 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1944 Log('chat', $target, $_[0], $text);
1946 # send it if it isn't the except list and isn't isolated and still has a hop count
1947 # taking into account filtering and so on
1948 foreach $dxchan (@dxchan) {
1949 my $is_ak1a = $dxchan->is_ak1a;
1951 if ($dxchan->is_node) {
1952 next if $dxchan == $main::me;
1953 next if $dxchan == $self;
1954 next unless $dxchan->is_spider || $is_ak1a;
1955 next if $target eq 'LOCAL';
1956 if (!$ak1a_line && $is_ak1a) {
1957 $ak1a_line = DXProt::pc12($_[0], $text, $_[1], "$target.LST");
1961 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1],
1962 $text, @_, $self->{call}, @a[0..2], @b[0..2]);
1970 my $isolate = shift;
1974 my ($filter, $hops);
1976 if ($self->{annfilter}) {
1977 ($filter, $hops) = $self->{annfilter}->it(@_);
1978 return unless $filter;
1980 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
1989 sub send_local_config
1997 dbg('DXProt::send_local_config') if isdbg('trace');
1999 if ($self->{newroute}) {
2000 my @nodes = $self->{isolate} ? ($main::routeroot) : grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
2001 my @users = DXChannel::get_all_users();
2002 $self->send_route($main::mycall, \&pc59, @nodes+@users+4, 'C', 0, $main::mycall, (grep { Route::get($_) } $main::routeroot, @nodes, @users));
2005 if ($self->{isolate}) {
2006 @localnodes = ( $main::routeroot );
2007 $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
2009 # create a list of all the nodes that are not connected to this connection
2010 # and are not themselves isolated, this to make sure that isolated nodes
2011 # don't appear outside of this node
2013 # send locally connected nodes
2014 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
2015 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
2016 $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
2019 my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
2021 for $node (@rawintcalls) {
2022 push @intcalls, $node unless grep $node eq $_, @intcalls;
2024 my $ref = Route::Node::get($self->{call});
2025 my @rnodes = $ref->nodes;
2026 for $node (@intcalls) {
2027 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
2029 $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
2032 # get all the users connected on the above nodes and send them out
2033 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
2035 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
2036 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
2038 dbg("sent a null value") if isdbg('chanerr');
2045 # route a message down an appropriate interface for a callsign
2047 # is called route(to, pcline);
2051 my ($self, $call, $line) = @_;
2053 if (ref $self && $call eq $self->{call}) {
2054 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
2058 # always send it down the local interface if available
2059 my $dxchan = DXChannel->get($call);
2061 my $cl = Route::get($call);
2062 $dxchan = $cl->bestdxchan if $cl;
2064 if (ref $self && $dxchan eq $self) {
2065 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
2071 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
2073 $dxchan->send($routeit) unless $dxchan == $main::me;
2076 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
2081 # obtain the hops from the list for this callsign and pc no
2087 my $hops = $DXProt::hopcount{$pcno};
2088 $hops = $DXProt::def_hopcount if !$hops;
2093 # adjust the hop count on a per node basis using the user loadable
2094 # hop table if available or else decrement an existing one
2101 my $call = $self->{call};
2104 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
2105 my ($pcno) = $s =~ /^PC(\d\d)/o;
2106 confess "$call called adjust_hops with '$s'" unless $pcno;
2107 my $ref = $nodehops{$call} if %nodehops;
2109 my $newhops = $ref->{$pcno};
2110 return "" if defined $newhops && $newhops == 0;
2111 $newhops = $ref->{default} unless $newhops;
2112 return "" if defined $newhops && $newhops == 0;
2113 $newhops = $hops if !$newhops;
2114 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
2116 # simply decrement it
2118 return "" if !$hops;
2119 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
2131 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
2132 do "$main::data/hop_table.pl";
2138 # add a ping request to the ping queues
2141 my ($from, $to) = @_;
2142 my $ref = $pings{$to} || [];
2145 $r->{t} = [ gettimeofday ];
2146 route(undef, $to, pc51($to, $main::mycall, 1));
2153 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
2154 if ($tonode eq $main::mycall) {
2155 my $ref = DXUser->get_current($fromnode);
2156 my $cref = Route::Node::get($fromnode);
2157 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
2158 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
2159 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
2160 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
2161 my $oldpriv = $self->{priv};
2162 $self->{priv} = $ref->{priv}; # assume the user's privilege level
2163 my @in = (DXCommandmode::run_cmd($self, $cmd));
2164 $self->{priv} = $oldpriv;
2165 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
2166 delete $self->{remotecmd};
2168 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
2171 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
2174 my $ref = DXUser->get_current($tonode);
2175 if ($ref && $ref->is_clx) {
2176 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
2178 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
2183 sub process_rcmd_reply
2185 my ($self, $tonode, $fromnode, $user, $line) = @_;
2186 if ($tonode eq $main::mycall) {
2187 my $s = $rcmds{$fromnode};
2189 my $dxchan = DXChannel->get($s->{call});
2190 my $ref = $user eq $tonode ? $dxchan : (DXChannel->get($user) || $dxchan);
2191 $ref->send($line) if $ref;
2192 delete $rcmds{$fromnode} if !$dxchan;
2194 # send unsolicited ones to the sysop
2195 my $dxchan = DXChannel->get($main::myalias);
2196 $dxchan->send($line) if $dxchan;
2199 my $ref = DXUser->get_current($tonode);
2200 if ($ref && $ref->is_clx) {
2201 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
2203 $self->route($tonode, pc35($fromnode, $tonode, $line));
2212 my $fromnode = shift;
2217 Log('rcmd', 'out', $fromnode, $line);
2218 if ($self->is_clx) {
2219 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
2221 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
2226 # add a rcmd request to the rcmd queues
2229 my ($self, $to, $cmd) = @_;
2232 $r->{call} = $self->{call};
2233 $r->{t} = $main::systime;
2237 my $ref = Route::Node::get($to);
2238 my $dxchan = $ref->bestdxchan;
2239 if ($dxchan && $dxchan->is_clx) {
2240 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
2242 route(undef, $to, pc34($main::mycall, $to, $cmd));
2249 my $pc39flag = shift;
2250 my $call = $self->call;
2252 return if $self->{disconnecting}++;
2254 unless ($pc39flag && $pc39flag == 1) {
2255 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
2258 # get rid of any PC16/17/19
2259 eph_del_regex("^PC1[679]*$call");
2261 # do routing stuff, remove me from routing table
2262 my $node = Route::Node::get($call);
2266 # remove the route from this node and return a list
2267 # of nodes that have become orphanned as a result.
2268 push @rout, $main::routeroot->remove_route($node, $self);
2270 # remove all my ephemera as well
2273 eph_del_regex("^PC1[679].*$c");
2277 # unbusy and stop and outgoing mail
2278 my $mref = DXMsg::get_busy($call);
2279 $mref->stop_msg($call) if $mref;
2281 # broadcast to all other nodes that all the nodes connected to via me are gone
2282 unless ($pc39flag && $pc39flag == 2) {
2283 $self->route_pc21($main::mycall, undef, @rout) if @rout;
2284 $self->route_pc59('D', 0, $main::mycall, $node);
2287 # delete all the unwanted nodes
2288 $_->delete for @rout;
2290 # remove outstanding pings
2291 delete $pings{$call};
2293 # I was the last node visited
2294 $self->user->node($main::mycall);
2296 # send info to all logged in thingies
2297 $self->tell_login('logoutn');
2299 Log('DXProt', $call . " Disconnected");
2301 $self->SUPER::disconnect;
2306 # send a talk message to this thingy
2310 my ($self, $from, $to, $via, $line, $origin) = @_;
2312 $line =~ s/\^/\\5E/g; # remove any ^ characters
2313 $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
2314 Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
2317 # send it if it isn't the except list and isn't isolated and still has a hop count
2318 # taking into account filtering and so on
2324 my $generate = shift;
2325 my $no = shift; # the no of things to filter on
2327 my ($filter, $hops);
2330 for (; @_ && $no; $no--) {
2333 # deal with non routing parameters
2334 unless (ref $r && $r->isa('Route')) {
2339 if (!$self->{isolate} && $self->{routefilter}) {
2342 ($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});
2346 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
2349 dbg("was sent a null value") if isdbg('chanerr');
2352 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
2356 foreach my $line (&$generate(@rin, @_)) {
2359 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
2361 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
2362 next unless $routeit;
2365 $self->send($routeit);
2374 my $generate = shift;
2376 my @dxchan = DXChannel::get_all_nodes();
2379 unless ($self->{isolate}) {
2380 foreach $dxchan (@dxchan) {
2381 next if $dxchan == $self;
2382 next if $dxchan == $main::me;
2383 next unless $dxchan->isa('DXProt');
2384 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
2385 next if ($generate == \&pc19 || $generate==\&pc21) && !$dxchan->user->wantsendpc19;
2386 next if ($generate == \&pc59) && !$dxchan->{newroute};
2388 $dxchan->send_route($origin, $generate, @_);
2396 return unless $self->user->wantpc16;
2399 broadcast_route($self, $origin, \&pc16, $line, 1, @_);
2405 return unless $self->user->wantpc16;
2408 broadcast_route($self, $origin, \&pc17, $line, 1, @_);
2416 broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
2424 broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
2432 broadcast_route($self, $origin, \&pc24, $line, 1, @_);
2440 broadcast_route($self, $origin, \&pc41, $line, 1, @_);
2448 broadcast_route($self, $origin, \&pc50, $line, 1, @_);
2457 broadcast_route($self, $origin, \&pc59, $line, scalar @_, @_);
2464 my ($filter, $hops) = (1, 1);
2466 if ($self->{inroutefilter}) {
2467 ($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);
2468 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
2476 my $t = shift || $eph_restime;
2480 $s =~ s/\^H\d\d?\^?\~?$//;
2481 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
2482 $eph{$s} = $main::systime + $t;
2490 while (($key, $val) = each %eph) {
2491 if ($key =~ m{$regex}) {
2501 while (($key, $val) = each %eph) {
2502 if ($main::systime >= $val) {
2513 while (($key, $val) = each %eph) {
2514 push @out, $key, $val;
2521 goto &DXCommandmode::run_cmd;