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;
42 $main::build += $VERSION;
43 $main::branch += $BRANCH;
45 use vars qw($me $pc11_max_age $pc23_max_age $last_pc50
46 $last_hour $last10 %eph %pings %rcmds $ann_to_talk
47 %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
48 $allowzero $decode_dk0wcy $send_opernam @checklist);
50 $me = undef; # the channel id for this cluster
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 $censorpc = 1; # Do a BadWords::check on text fields and reject things
59 # loads of 'bad things'
60 $baddx = new DXHash "baddx";
61 $badspotter = new DXHash "badspotter";
62 $badnode = new DXHash "badnode";
63 $last10 = $last_pc50 = time;
69 [ qw(c c m bp bc c) ], # pc10
70 [ qw(f m d t m c c h) ], # pc11
71 [ qw(c bc m bp bm p h) ], # pc12
75 undef , # pc16 has to be validated manually
78 undef , # pc19 has to be validated manually
79 undef , # pc20 no validation
81 undef , # pc22 no validation
82 [ qw(d n n n n m c c h) ], # pc23
84 [ qw(c c n n) ], # pc25
85 [ qw(f m d t m c c bc) ], # pc26
86 [ qw(d n n n n m c c bc) ], # pc27
87 [ qw(c c m c d t p m bp n p bp bc) ], # pc28
88 [ qw(c c n m) ], # pc29
96 [ qw(c c n m) ], # pc37
97 undef, # pc38 not interested
99 [ qw(c c m p n) ], # pc40
100 [ qw(c n m h) ], # pc41
101 [ qw(c c n) ], # pc42
102 undef, # pc43 don't handle it
103 [ qw(c c n m m c) ], # pc44
104 [ qw(c c n m) ], # pc45
105 [ qw(c c n) ], # pc46
108 [ qw(c m h) ], # pc49
109 [ qw(c n h) ], # pc50
110 [ qw(c c n) ], # pc51
132 [ qw(d n n n n n n m m m c c h) ], # pc73
143 [ qw(c c c m) ], # pc84
144 [ qw(c c c m) ], # pc85
147 # use the entry in the check list to check the field list presented
148 # return OK if line NOT in check list (for now)
153 return 0 if $n < 0 || $n > @checklist;
154 my $ref = $checklist[$n];
155 return 0 unless ref $ref;
158 shift; # not interested in the first field
159 for ($i = 0; $i < @$ref; $i++) {
160 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
161 return 0 unless $act;
162 next if $blank && $_[$i] =~ /^[ \*]$/;
164 return $i+1 unless is_callsign($_[$i]);
165 } elsif ($act eq 'm') {
166 return $i+1 unless is_pctext($_[$i]);
167 } elsif ($act eq 'p') {
168 return $i+1 unless is_pcflag($_[$i]);
169 } elsif ($act eq 'f') {
170 return $i+1 unless is_freq($_[$i]);
171 } elsif ($act eq 'n') {
172 return $i+1 unless $_[$i] =~ /^[\d ]+$/;
173 } elsif ($act eq 'h') {
174 return $i+1 unless $_[$i] =~ /^H\d\d?$/;
175 } elsif ($act eq 'd') {
176 return $i+1 unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
177 } elsif ($act eq 't') {
178 return $i+1 unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
186 my $user = DXUser->get($main::mycall);
187 $DXProt::myprot_version += $main::version*100;
188 $me = DXProt->new($main::mycall, 0, $user);
190 $me->{state} = "indifferent";
191 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
193 $me->{sort} = 'S'; # S for spider
195 # $Route::Node::me->adddxchan($me);
199 # obtain a new connection this is derived from dxchannel
204 my $self = DXChannel::alloc(@_);
206 # add this node to the table, the values get filled in later
209 $main::routeroot->add($call, '0000', Route::here(1)) if $call ne $main::mycall;
214 # this is how a pc connection starts (for an incoming connection)
215 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
216 # all the crap that comes between).
219 my ($self, $line, $sort) = @_;
220 my $call = $self->{call};
221 my $user = $self->{user};
224 my $host = $self->{conn}->{peerhost} || "unknown";
225 Log('DXProt', "$call connected from $host");
227 # remember type of connection
228 $self->{consort} = $line;
229 $self->{outbound} = $sort eq 'O';
230 my $priv = $user->priv;
231 $priv = $user->priv(1) unless $priv;
232 $self->{priv} = $priv; # other clusters can always be 'normal' users
233 $self->{lang} = $user->lang || 'en';
234 $self->{isolate} = $user->{isolate};
235 $self->{consort} = $line; # save the connection type
239 # get the output filters
240 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
241 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
242 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
243 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
244 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
247 # get the INPUT filters (these only pertain to Clusters)
248 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
249 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
250 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
251 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
252 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
254 # set unbuffered and no echo
255 $self->send_now('B',"0");
256 $self->send_now('E',"0");
258 # ping neighbour node stuff
259 my $ping = $user->pingint;
260 $ping = 5*60 unless defined $ping;
261 $self->{pingint} = $ping;
262 $self->{nopings} = $user->nopings || 2;
263 $self->{pingtime} = [ ];
264 $self->{pingave} = 999;
265 $self->{lastping} = $main::systime;
267 # send initialisation string
268 unless ($self->{outbound}) {
272 $self->state('init');
273 $self->{pc50_t} = $main::systime;
275 # send info to all logged in thingies
276 $self->tell_login('loginn');
278 # run a script send the output to the debug file
279 my $script = new Script(lc $call) || new Script('node_default');
280 $script->run($self) if $script;
284 # This is the normal pcxx despatcher
288 my ($self, $line) = @_;
289 my @field = split /\^/, $line;
290 return unless @field;
292 pop @field if $field[-1] eq '~';
294 # print join(',', @field), "\n";
297 # process PC frames, this will fail unless the frame starts PCnn
298 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
300 return if $pcno < 10 || $pcno > 99;
302 # check for and dump bad protocol messages
303 my $n = check($pcno, @field);
305 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
312 $pcr = Local::pcprot($self, $pcno, @field);
314 # dbg("Local::pcprot error $@") if isdbg('local') if $@;
318 if ($pcno == 10) { # incoming talk
321 return if $rspfcheck and !$self->rspfcheck(0, $field[6], $field[1]);
323 # will we allow it at all?
326 if (@bad = BadWords::check($field[3])) {
327 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
332 # is it for me or one of mine?
333 my ($from, $to, $via, $call, $dxchan);
335 if ($field[5] gt ' ') {
342 # if we are converting announces to talk is it a dup?
344 if (AnnTalk::is_talk_candidate($from, $field[3]) && AnnTalk::dup($from, $to, $field[3])) {
345 dbg("DXPROT: Dupe talk from announce, dropped") if isdbg('chanerr');
350 # it is here and logged on
351 $dxchan = DXChannel->get($main::myalias) if $to eq $main::mycall;
352 $dxchan = DXChannel->get($to) unless $dxchan;
353 if ($dxchan && $dxchan->is_user) {
354 $field[3] =~ s/\%5E/^/g;
355 $dxchan->talk($from, $to, $via, $field[3]);
359 # is it elsewhere, visible on the cluster via the to address?
360 # note: this discards the via unless the to address is on
363 if ($ref = Route::get($to)) {
364 $vref = Route::Node::get($via) if $via;
365 $vref = undef unless $vref && grep $to eq $_, $vref->users;
366 $ref->dxchan->talk($from, $to, $vref ? $via : undef, $field[3], $field[6]);
370 # not visible here, send a message of condolence
372 $ref = Route::get($from);
373 $vref = $ref = Route::Node::get($field[6]) unless $ref;
375 $dxchan = $ref->dxchan;
376 $dxchan->talk($main::mycall, $from, $vref ? $vref->call : undef, $dxchan->msg('talknh', $to) );
381 if ($pcno == 11 || $pcno == 26) { # dx spot
383 # route 'foreign' pc26s
385 if ($field[7] ne $main::mycall) {
386 $self->route($field[7], $line);
392 return if $rspfcheck and !$self->rspfcheck(1, $field[7], $field[6]);
394 # if this is a 'nodx' node then ignore it
395 if ($badnode->in($field[7])) {
396 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
400 # if this is a 'bad spotter' user then ignore it
401 if ($badspotter->in($field[6])) {
402 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
406 # convert the date to a unix date
407 my $d = cltounix($field[3], $field[4]);
408 # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
409 if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
410 dbg("PCPROT: Spot ignored, invalid date or out of range ($field[3] $field[4])\n") if isdbg('chanerr');
415 if ($baddx->in($field[2])) {
416 dbg("PCPROT: Bad DX spot, ignored") if isdbg('chanerr');
421 $field[5] =~ s/^\s+//; # take any leading blanks off
422 $field[2] = unpad($field[2]); # take off leading and trailing blanks from spotted callsign
423 if ($field[2] =~ /BUST\w*$/) {
424 dbg("PCPROT: useless 'BUSTED' spot") if isdbg('chanerr');
427 if (Spot::dup($field[1], $field[2], $d, $field[5])) {
428 dbg("PCPROT: Duplicate Spot ignored\n") if isdbg('chanerr');
433 if (@bad = BadWords::check($field[5])) {
434 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
439 my @spot = Spot::prepare($field[1], $field[2], $d, $field[5], $field[6], $field[7]);
440 # global spot filtering on INPUT
441 if ($self->{inspotsfilter}) {
442 my ($filter, $hops) = $self->{inspotsfilter}->it(@spot);
444 dbg("PCPROT: Rejected by input spot filter") if isdbg('chanerr');
453 # @spot at this point contains:-
454 # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
455 # then spotted itu, spotted cq, spotters itu, spotters cq
456 # you should be able to route on any of these
459 # fix up qra locators of known users
460 my $user = DXUser->get_current($spot[4]);
462 my $qra = $user->qra;
463 unless ($qra && is_qra($qra)) {
464 my $lat = $user->lat;
465 my $long = $user->long;
466 if (defined $lat && defined $long) {
467 $user->qra(DXBearing::lltoqra($lat, $long));
472 # send a remote command to a distant cluster if it is visible and there is no
473 # qra locator and we havn't done it for a month.
475 unless ($user->qra) {
477 my $to = $user->homenode;
478 my $last = $user->lastoper || 0;
479 if ($send_opernam && $to && $to ne $main::mycall && $main::systime > $last + $DXUser::lastoperinterval && ($node = Route::Node::get($to)) ) {
480 my $cmd = "forward/opernam $spot[4]";
481 # send the rcmd but we aren't interested in the replies...
482 my $dxchan = $node->dxchan;
483 if ($dxchan && $dxchan->is_clx) {
484 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
486 route(undef, $to, pc34($main::mycall, $to, $cmd));
488 if ($to ne $field[7]) {
490 $node = Route::Node::get($to);
492 $dxchan = $node->dxchan;
493 if ($dxchan && $dxchan->is_clx) {
494 route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
496 route(undef, $to, pc34($main::mycall, $to, $cmd));
500 $user->lastoper($main::systime);
509 $r = Local::spot($self, @spot);
511 # dbg("Local::spot1 error $@") if isdbg('local') if $@;
514 # DON'T be silly and send on PC26s!
515 return if $pcno == 26;
517 # send out the filtered spots
518 send_dx_spot($self, $line, @spot) if @spot;
522 if ($pcno == 12) { # announces
524 return if $rspfcheck and !$self->rspfcheck(1, $field[5], $field[1]);
526 # announce duplicate checking
527 $field[3] =~ s/^\s+//; # remove leading blanks
528 if (AnnTalk::dup($field[1], $field[2], $field[3])) {
529 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
535 if (@bad = BadWords::check($field[3])) {
536 dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
541 if ($field[2] eq '*' || $field[2] eq $main::mycall) {
544 # here's a bit of fun, convert incoming ann with a callsign in the first word
545 # or one saying 'to <call>' to a talk if we can route to the recipient
547 my $call = AnnTalk::is_talk_candidate($field[1], $field[3]);
549 my $ref = Route::get($call);
551 my $dxchan = $ref->dxchan;
552 $dxchan->talk($field[1], $call, undef, $field[3], $field[5]) if $dxchan != $self;
559 $self->send_announce($line, @field[1..6]);
561 $self->route($field[2], $line);
576 if ($pcno == 16) { # add a user
580 my $ncall = $field[1];
581 my $newline = "PC16^";
583 if ($ncall eq $main::mycall) {
584 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
587 $dxchan = DXChannel->get($ncall);
588 if ($dxchan && $dxchan ne $self) {
589 dbg("PCPROT: PC16 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
592 my $parent = Route::Node::get($ncall);
594 dbg("PCPROT: Node $ncall not in config") if isdbg('chanerr');
598 # input filter if required
599 return unless $self->in_filter_route($parent);
603 for ($i = 2; $i < $#field; $i++) {
604 my ($call, $conf, $here) = $field[$i] =~ /^(\S+) (\S) (\d)/o;
605 next unless $call && $conf && defined $here && is_callsign($call);
606 next if $call eq $main::mycall;
608 eph_del_regex("^PC17\^$call\^$ncall");
610 $conf = $conf eq '*';
612 # reject this if we think it is a node already
613 my $r = Route::Node::get($call);
614 my $u = DXUser->get_current($call) unless $r;
615 if ($r || ($u && $u->is_node)) {
616 dbg("PCPROT: $call is a node") if isdbg('chanerr');
620 $r = Route::User::get($call);
621 my $flags = Route::here($here)|Route::conf($conf);
624 if ($r->flags != $flags) {
628 $r->addparent($parent);
630 push @rout, $parent->add_user($call, $flags);
633 # add this station to the user database, if required
634 $call =~ s/-\d+$//o; # remove ssid for users
635 my $user = DXUser->get_current($call);
636 $user = DXUser->new($call) if !$user;
637 $user->homenode($parent->call) if !$user->homenode;
638 $user->node($parent->call);
639 $user->lastin($main::systime) unless DXChannel->get($call);
643 if (eph_dup($line)) {
644 dbg("PCPROT: dup PC16 detected") if isdbg('chanerr');
648 # queue up any messages (look for privates only)
649 DXMsg::queue_msg(1) if $self->state eq 'normal';
651 $self->route_pc16($parent, @rout) if @rout;
655 if ($pcno == 17) { # remove a user
657 my $ncall = $field[2];
658 my $ucall = $field[1];
660 eph_del_regex("^PC16.*$ncall.*$ucall");
662 if ($ncall eq $main::mycall) {
663 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
666 $dxchan = DXChannel->get($ncall);
667 if ($dxchan && $dxchan ne $self) {
668 dbg("PCPROT: PC17 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
672 my $uref = Route::User::get($ucall);
674 dbg("PCPROT: Route::User $ucall not in config") if isdbg('chanerr');
677 my $parent = Route::Node::get($ncall);
679 dbg("PCPROT: Route::Node $ncall not in config") if isdbg('chanerr');
683 # input filter if required
684 return unless $self->in_filter_route($parent);
686 my @rout = $parent->del_user($uref);
688 if (eph_dup($line)) {
689 dbg("PCPROT: dup PC17 detected") if isdbg('chanerr');
693 $self->route_pc17($parent, @rout) if @rout;
697 if ($pcno == 18) { # link request
698 $self->state('init');
700 # first clear out any nodes on this dxchannel
701 my $parent = Route::Node::get($self->{call});
702 my @rout = $parent->del_nodes;
703 $self->route_pc21(@rout, $parent) if @rout;
704 $self->send_local_config();
706 return; # we don't pass these on
709 if ($pcno == 19) { # incoming cluster list
711 my $newline = "PC19^";
715 my $parent = Route::Node::get($self->{call});
717 dbg("DXPROT: my parent $self->{call} has disappeared");
723 for ($i = 1; $i < $#field-1; $i += 4) {
724 my $here = $field[$i];
725 my $call = uc $field[$i+1];
726 my $conf = $field[$i+2];
727 my $ver = $field[$i+3];
728 next unless defined $here && defined $conf && is_callsign($call);
730 eph_del_regex("^PC(?:21\^$call|17\^[^\^]+\^$call)");
732 # check for sane parameters
733 $ver = 5000 if $ver eq '0000';
734 next if $ver < 5000; # only works with version 5 software
735 next if length $call < 3; # min 3 letter callsigns
736 next if $call eq $main::mycall;
738 # update it if required
739 my $r = Route::Node::get($call);
740 my $flags = Route::here($here)|Route::conf($conf);
743 if ($call ne $parent->call) {
744 if ($self->in_filter_route($r)) {
745 $ar = $parent->add($call, $ver, $flags);
746 push @rout, $ar if $ar;
751 if ($r->version ne $ver || $r->flags != $flags) {
754 push @rout, $r unless $ar;
757 if ($call eq $self->{call}) {
758 dbg("DXPROT: my channel route for $call has disappeared");
762 my $new = Route->new($call); # throw away
763 if ($self->in_filter_route($new)) {
764 my $r = $parent->add($call, $ver, $flags);
771 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
772 my $mref = DXMsg::get_busy($call);
773 $mref->stop_msg($call) if $mref;
775 # add this station to the user database, if required (don't remove SSID from nodes)
776 my $user = DXUser->get_current($call);
778 $user = DXUser->new($call);
780 $user->priv(1); # I have relented and defaulted nodes
782 $user->homenode($call);
785 $user->lastin($main::systime) unless DXChannel->get($call);
789 if (eph_dup($line)) {
790 dbg("PCPROT: dup PC19 detected") if isdbg('chanerr');
794 $self->route_pc19(@rout) if @rout;
798 if ($pcno == 20) { # send local configuration
799 $self->send_local_config();
801 $self->state('normal');
802 $self->{lastping} = 0;
806 if ($pcno == 21) { # delete a cluster from the list
807 my $call = uc $field[1];
809 eph_del_regex("^PC1[79].*$call");
812 my $parent = Route::Node::get($self->{call});
814 dbg("DXPROT: my parent $self->{call} has disappeared");
818 my $node = Route::Node::get($call);
819 if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
820 if ($call eq $self->{call}) {
821 dbg("PCPROT: Trying to disconnect myself with PC21") if isdbg('chanerr');
827 return unless $self->in_filter_route($node);
830 push @rout, $node->del($parent);
833 dbg("PCPROT: I WILL _NOT_ be disconnected!") if isdbg('chanerr');
837 if (eph_dup($line)) {
838 dbg("PCPROT: dup PC21 detected") if isdbg('chanerr');
842 $self->route_pc21(@rout) if @rout;
847 $self->state('normal');
848 $self->{lastping} = 0;
852 if ($pcno == 23 || $pcno == 27) { # WWV info
854 # route 'foreign' pc27s
856 if ($field[8] ne $main::mycall) {
857 $self->route($field[8], $line);
862 return if $rspfcheck and !$self->rspfcheck(1, $field[8], $field[7]);
865 my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
866 my $sfi = unpad($field[3]);
867 my $k = unpad($field[4]);
868 my $i = unpad($field[5]);
869 my ($r) = $field[6] =~ /R=(\d+)/;
871 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
872 dbg("PCPROT: WWV Date ($field[1] $field[2]) out of range") if isdbg('chanerr');
875 if (Geomag::dup($d,$sfi,$k,$i,$field[6])) {
876 dbg("PCPROT: Dup WWV Spot ignored\n") if isdbg('chanerr');
879 $field[7] =~ s/-\d+$//o; # remove spotter's ssid
881 my $wwv = Geomag::update($d, $field[2], $sfi, $k, $i, @field[6..8], $r);
885 $rep = Local::wwv($self, $field[1], $field[2], $sfi, $k, $i, @field[6..8], $r);
887 # dbg("Local::wwv2 error $@") if isdbg('local') if $@;
890 # DON'T be silly and send on PC27s!
891 return if $pcno == 27;
893 # broadcast to the eager world
894 send_wwv_spot($self, $line, $d, $field[2], $sfi, $k, $i, @field[6..8]);
898 if ($pcno == 24) { # set here status
899 my $call = uc $field[1];
901 $nref = Route::Node::get($call);
902 $uref = Route::User::get($call);
903 return unless $nref || $uref; # if we don't know where they are, it's pointless sending it on
905 unless (eph_dup($line)) {
906 $nref->here($field[2]) if $nref;
907 $uref->here($field[2]) if $uref;
908 my $ref = $nref || $uref;
909 return unless $self->in_filter_route($ref);
910 $self->route_pc24($ref, $field[3]);
915 if ($pcno == 25) { # merge request
916 if ($field[1] ne $main::mycall) {
917 $self->route($field[1], $line);
920 if ($field[2] eq $main::mycall) {
921 dbg("PCPROT: Trying to merge to myself, ignored") if isdbg('chanerr');
925 Log('DXProt', "Merge request for $field[3] spots and $field[4] WWV from $field[2]");
929 my @in = reverse Spot::search(1, undef, undef, 0, $field[3]);
932 $self->send(pc26(@{$in}[0..4], $field[2]));
938 my @in = reverse Geomag::search(0, $field[4], time, 1);
941 $self->send(pc27(@{$in}[0..5], $field[2]));
947 if (($pcno >= 28 && $pcno <= 33) || $pcno == 40 || $pcno == 42 || $pcno == 49) { # mail/file handling
948 if ($pcno == 49 || $field[1] eq $main::mycall) {
949 DXMsg::process($self, $line);
951 $self->route($field[1], $line) unless $self->is_clx;
956 if ($pcno == 34 || $pcno == 36) { # remote commands (incoming)
957 $self->process_rcmd($field[1], $field[2], $field[2], $field[3]);
961 if ($pcno == 35) { # remote command replies
962 $self->process_rcmd_reply($field[1], $field[2], $field[1], $field[3]);
966 # for pc 37 see 44 onwards
968 if ($pcno == 38) { # node connected list from neighbour
972 if ($pcno == 39) { # incoming disconnect
973 if ($field[1] eq $self->{call}) {
974 $self->disconnect(1);
975 eph_del_regex("^PC(?:1[679]|21).*$field[1]");
977 dbg("PCPROT: came in on wrong channel") if isdbg('chanerr');
982 if ($pcno == 41) { # user info
983 my $call = $field[1];
985 # input filter if required
986 # my $ref = Route::get($call) || Route->new($call);
987 # return unless $self->in_filter_route($ref);
989 if ($field[3] eq $field[2] || $field[3] =~ /^\s*$/) {
990 dbg('PCPROT: invalid value') if isdbg('chanerr');
994 # add this station to the user database, if required
995 my $user = DXUser->get_current($call);
996 $user = DXUser->new($call) if !$user;
998 if ($field[2] == 1) {
999 $user->name($field[3]);
1000 } elsif ($field[2] == 2) {
1001 $user->qth($field[3]);
1002 } elsif ($field[2] == 3) {
1003 if (is_latlong($field[3])) {
1004 my ($lat, $long) = DXBearing::stoll($field[3]);
1007 $user->qra(DXBearing::lltoqra($lat, $long));
1009 dbg('PCPROT: not a valid lat/long') if isdbg('chanerr');
1012 } elsif ($field[2] == 4) {
1013 $user->homenode($field[3]);
1014 } elsif ($field[2] == 5) {
1015 if (is_qra($field[3])) {
1016 my ($lat, $long) = DXBearing::qratoll($field[3]);
1019 $user->qra($field[3]);
1021 dbg('PCPROT: not a valid QRA locator') if isdbg('chanerr');
1025 $user->lastoper($main::systime); # to cut down on excessive for/opers being generated
1028 # perhaps this IS what we want after all
1029 # $self->route_pc41($ref, $call, $field[2], $field[3], $field[4]);
1037 if ($pcno == 37 || $pcno == 44 || $pcno == 45 || $pcno == 46 || $pcno == 47 || $pcno == 48) {
1038 DXDb::process($self, $line);
1042 if ($pcno == 50) { # keep alive/user list
1043 my $call = $field[1];
1044 my $node = Route::Node::get($call);
1046 return unless $node->call eq $self->{call};
1047 $node->usercount($field[2]);
1049 # input filter if required
1050 return unless $self->in_filter_route($node);
1052 $self->route_pc50($node, $field[2], $field[3]) unless eph_dup($line);
1057 if ($pcno == 51) { # incoming ping requests/answers
1059 my $from = $field[2];
1060 my $flag = $field[3];
1064 if ($to eq $main::mycall) {
1066 $self->send(pc51($from, $to, '0'));
1068 # it's a reply, look in the ping list for this one
1069 my $ref = $pings{$from};
1071 my $tochan = DXChannel->get($from);
1073 my $r = shift @$ref;
1074 my $dxchan = DXChannel->get($r->{call});
1075 next unless $dxchan;
1076 my $t = tv_interval($r->{t}, [ gettimeofday ]);
1077 if ($dxchan->is_user) {
1078 my $s = sprintf "%.2f", $t;
1079 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
1080 $dxchan->send($dxchan->msg('pingi', $from, $s, $ave))
1081 } elsif ($dxchan->is_node) {
1083 my $nopings = $tochan->user->nopings || 2;
1084 push @{$tochan->{pingtime}}, $t;
1085 shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
1087 # cope with a missed ping, this means you must set the pingint large enough
1088 if ($t > $tochan->{pingint} && $t < 2 * $tochan->{pingint} ) {
1089 $t -= $tochan->{pingint};
1092 # calc smoothed RTT a la TCP
1093 if (@{$tochan->{pingtime}} == 1) {
1094 $tochan->{pingave} = $t;
1096 $tochan->{pingave} = $tochan->{pingave} + (($t - $tochan->{pingave}) / 6);
1099 # for (@{$tochan->{pingtime}}) {
1102 # $tochan->{pingave} = $st / @{$tochan->{pingtime}};
1103 $tochan->{nopings} = $nopings; # pump up the timer
1110 if (eph_dup($line)) {
1111 dbg("PCPROT: dup PC51 detected") if isdbg('chanerr');
1114 # route down an appropriate thingy
1115 $self->route($to, $line);
1120 if ($pcno == 75) { # dunno but route it
1121 my $call = $field[1];
1122 if ($call ne $main::mycall) {
1123 $self->route($call, $line);
1128 if ($pcno == 73) { # WCY broadcasts
1129 my $call = $field[1];
1132 my $d = cltounix($call, sprintf("%02d18Z", $field[2]));
1133 if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
1134 dbg("PCPROT: WCY Date ($call $field[2]) out of range") if isdbg('chanerr');
1137 @field = map { unpad($_) } @field;
1138 if (WCY::dup($d,@field[3..7])) {
1139 dbg("PCPROT: Dup WCY Spot ignored\n") if isdbg('chanerr');
1143 my $wcy = WCY::update($d, @field[2..12]);
1147 $rep = Local::wwv($self, @field[1..12]);
1149 # dbg("Local::wcy error $@") if isdbg('local') if $@;
1152 # broadcast to the eager world
1153 send_wcy_spot($self, $line, $d, @field[2..12]);
1157 if ($pcno == 84) { # remote commands (incoming)
1158 $self->process_rcmd($field[1], $field[2], $field[3], $field[4]);
1162 if ($pcno == 85) { # remote command replies
1163 $self->process_rcmd_reply($field[1], $field[2], $field[3], $field[4]);
1169 # if get here then rebroadcast the thing with its Hop count decremented (if
1170 # there is one). If it has a hop count and it decrements to zero then don't
1173 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
1177 if (eph_dup($line)) {
1178 dbg("PCPROT: Ephemeral dup, dropped") if isdbg('chanerr');
1180 unless ($self->{isolate}) {
1181 broadcast_ak1a($line, $self); # send it to everyone but me
1187 # This is called from inside the main cluster processing loop and is used
1188 # for despatching commands that are doing some long processing job
1193 my @dxchan = DXChannel->get_all();
1197 # send out a pc50 on EVERY channel all at once
1198 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
1199 $pc50s = pc50($me, scalar DXChannel::get_all_users);
1204 foreach $dxchan (@dxchan) {
1205 next unless $dxchan->is_node();
1206 next if $dxchan == $me;
1209 $dxchan->send($pc50s) if $pc50s;
1211 # send a ping out on this channel
1212 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
1213 if ($dxchan->{nopings} <= 0) {
1214 $dxchan->disconnect;
1216 addping($main::mycall, $dxchan->call);
1217 $dxchan->{nopings} -= 1;
1218 $dxchan->{lastping} = $t;
1224 if ($t - $last10 >= 10) {
1225 # clean out ephemera
1232 if ($main::systime - 3600 > $last_hour) {
1233 $last_hour = $main::systime;
1238 # finish up a pc context
1242 # some active measures
1249 my @dxchan = DXChannel->get_all();
1252 # send it if it isn't the except list and isn't isolated and still has a hop count
1253 # taking into account filtering and so on
1254 foreach $dxchan (@dxchan) {
1255 next if $dxchan == $me;
1256 next if $dxchan == $self && $self->is_node;
1257 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
1265 my $isolate = shift;
1266 my ($filter, $hops);
1268 if ($self->{spotsfilter}) {
1269 ($filter, $hops) = $self->{spotsfilter}->it(@_);
1270 return unless $filter;
1272 send_prot_line($self, $filter, $hops, $isolate, $line);
1277 my ($self, $filter, $hops, $isolate, $line) = @_;
1282 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1284 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1285 return unless $routeit;
1288 $self->send($routeit);
1290 $self->send($routeit) unless $self->{isolate} || $isolate;
1299 my @dxchan = DXChannel->get_all();
1301 my ($wwv_dxcc, $wwv_itu, $wwv_cq, $org_dxcc, $org_itu, $org_cq) = (0..0);
1302 my @dxcc = Prefix::extract($_[6]);
1304 $wwv_dxcc = $dxcc[1]->dxcc;
1305 $wwv_itu = $dxcc[1]->itu;
1306 $wwv_cq = $dxcc[1]->cq;
1308 @dxcc = Prefix::extract($_[7]);
1310 $org_dxcc = $dxcc[1]->dxcc;
1311 $org_itu = $dxcc[1]->itu;
1312 $org_cq = $dxcc[1]->cq;
1315 # send it if it isn't the except list and isn't isolated and still has a hop count
1316 # taking into account filtering and so on
1317 foreach $dxchan (@dxchan) {
1318 next if $dxchan == $me;
1319 next if $dxchan == $self && $self->is_node;
1321 my ($filter, $hops);
1323 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, $wwv_dxcc, $wwv_itu, $wwv_cq, $org_dxcc, $org_itu, $org_cq);
1332 my $isolate = shift;
1333 my ($filter, $hops);
1335 if ($self->{wwvfilter}) {
1336 ($filter, $hops) = $self->{wwvfilter}->it(@_);
1337 return unless $filter;
1339 send_prot_line($self, $filter, $hops, $isolate, $line)
1346 my @dxchan = DXChannel->get_all();
1348 my ($wcy_dxcc, $wcy_itu, $wcy_cq, $org_dxcc, $org_itu, $org_cq) = (0..0);
1349 my @dxcc = Prefix::extract($_[10]);
1351 $wcy_dxcc = $dxcc[1]->dxcc;
1352 $wcy_itu = $dxcc[1]->itu;
1353 $wcy_cq = $dxcc[1]->cq;
1355 @dxcc = Prefix::extract($_[11]);
1357 $org_dxcc = $dxcc[1]->dxcc;
1358 $org_itu = $dxcc[1]->itu;
1359 $org_cq = $dxcc[1]->cq;
1362 # send it if it isn't the except list and isn't isolated and still has a hop count
1363 # taking into account filtering and so on
1364 foreach $dxchan (@dxchan) {
1365 next if $dxchan == $me;
1366 next if $dxchan == $self;
1368 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, $wcy_dxcc, $wcy_itu, $wcy_cq, $org_dxcc, $org_itu, $org_cq);
1376 my $isolate = shift;
1377 my ($filter, $hops);
1379 if ($self->{wcyfilter}) {
1380 ($filter, $hops) = $self->{wcyfilter}->it(@_);
1381 return unless $filter;
1383 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
1391 my @dxchan = DXChannel->get_all();
1395 my $text = unpad($_[2]);
1397 if ($_[3] eq '*') { # sysops
1399 } elsif ($_[3] gt ' ') { # speciality list handling
1400 my ($name) = split /\./, $_[3];
1401 $target = "$name"; # put the rest in later (if bothered)
1408 $target = "ALL" if !$target;
1411 # obtain country codes etc
1412 my ($ann_dxcc, $ann_itu, $ann_cq, $org_dxcc, $org_itu, $org_cq) = (0..0);
1413 my @dxcc = Prefix::extract($_[0]);
1415 $ann_dxcc = $dxcc[1]->dxcc;
1416 $ann_itu = $dxcc[1]->itu;
1417 $ann_cq = $dxcc[1]->cq;
1419 @dxcc = Prefix::extract($_[4]);
1421 $org_dxcc = $dxcc[1]->dxcc;
1422 $org_itu = $dxcc[1]->itu;
1423 $org_cq = $dxcc[1]->cq;
1426 if ($self->{inannfilter}) {
1427 my ($filter, $hops) =
1428 $self->{inannfilter}->it(@_, $self->{call},
1429 $ann_dxcc, $ann_itu, $ann_cq,
1430 $org_dxcc, $org_itu, $org_cq);
1432 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1437 Log('ann', $target, $_[0], $text);
1439 # send it if it isn't the except list and isn't isolated and still has a hop count
1440 # taking into account filtering and so on
1441 foreach $dxchan (@dxchan) {
1442 next if $dxchan == $me;
1443 next if $dxchan == $self && $self->is_node;
1444 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call}, $ann_dxcc, $ann_itu, $ann_cq, $org_dxcc, $org_itu, $org_cq);
1452 my $isolate = shift;
1456 my ($filter, $hops);
1458 if ($self->{annfilter}) {
1459 ($filter, $hops) = $self->{annfilter}->it(@_);
1460 return unless $filter;
1462 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
1466 sub send_local_config
1474 dbg('DXProt::send_local_config') if isdbg('trace');
1477 if ($self->{isolate}) {
1478 @localnodes = ( $main::routeroot );
1480 # create a list of all the nodes that are not connected to this connection
1481 # and are not themselves isolated, this to make sure that isolated nodes
1482 # don't appear outside of this node
1483 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
1484 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
1485 my @intcalls = map { $_->nodes } @localnodes if @localnodes;
1486 my $ref = Route::Node::get($self->{call});
1487 my @rnodes = $ref->nodes;
1488 for my $n (@intcalls) {
1489 push @remotenodes, Route::Node::get($n) unless grep $n eq $_, @rnodes;
1491 unshift @localnodes, $main::routeroot;
1494 send_route($self, \&pc19, scalar(@localnodes)+scalar(@remotenodes), @localnodes, @remotenodes);
1496 # get all the users connected on the above nodes and send them out
1497 foreach $n (@localnodes, @remotenodes) {
1499 send_route($self, \&pc16, 1, $n, map {my $r = Route::User::get($_); $r ? ($r) : ()} $n->users);
1501 dbg("sent a null value") if isdbg('chanerr');
1507 # route a message down an appropriate interface for a callsign
1509 # is called route(to, pcline);
1513 my ($self, $call, $line) = @_;
1515 if (ref $self && $call eq $self->{call}) {
1516 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
1520 # always send it down the local interface if available
1521 my $dxchan = DXChannel->get($call);
1523 my $cl = Route::get($call);
1524 $dxchan = $cl->dxchan if $cl;
1526 if (ref $self && $dxchan eq $self) {
1527 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
1533 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
1535 $dxchan->send($routeit) unless $dxchan == $me;
1538 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
1542 # broadcast a message to all clusters taking into account isolation
1543 # [except those mentioned after buffer]
1546 my $s = shift; # the line to be rebroadcast
1547 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1548 my @dxchan = DXChannel::get_all_nodes();
1551 # send it if it isn't the except list and isn't isolated and still has a hop count
1552 foreach $dxchan (@dxchan) {
1553 next if grep $dxchan == $_, @except;
1554 next if $dxchan == $me;
1556 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1557 $dxchan->send($routeit) unless $dxchan->{isolate} || !$routeit;
1561 # broadcast a message to all clusters ignoring isolation
1562 # [except those mentioned after buffer]
1563 sub broadcast_all_ak1a
1565 my $s = shift; # the line to be rebroadcast
1566 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1567 my @dxchan = DXChannel::get_all_nodes();
1570 # send it if it isn't the except list and isn't isolated and still has a hop count
1571 foreach $dxchan (@dxchan) {
1572 next if grep $dxchan == $_, @except;
1573 next if $dxchan == $me;
1575 my $routeit = adjust_hops($dxchan, $s); # adjust its hop count by node name
1576 $dxchan->send($routeit);
1580 # broadcast to all users
1581 # storing the spot or whatever until it is in a state to receive it
1584 my $s = shift; # the line to be rebroadcast
1585 my $sort = shift; # the type of transmission
1586 my $fref = shift; # a reference to an object to filter on
1587 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
1588 my @dxchan = DXChannel::get_all_users();
1592 foreach $dxchan (@dxchan) {
1593 next if grep $dxchan == $_, @except;
1596 broadcast_list($s, $sort, $fref, @out);
1599 # broadcast to a list of users
1607 foreach $dxchan (@_) {
1609 next if $dxchan == $me;
1611 if ($sort eq 'dx') {
1612 next unless $dxchan->{dx};
1613 ($filter) = $dxchan->{spotsfilter}->it(@{$fref}) if ref $fref;
1614 next unless $filter;
1616 next if $sort eq 'ann' && !$dxchan->{ann} && $s !~ /^To\s+LOCAL\s+de\s+(?:$main::myalias|$main::mycall)/i;
1617 next if $sort eq 'wwv' && !$dxchan->{wwv};
1618 next if $sort eq 'wcy' && !$dxchan->{wcy};
1619 next if $sort eq 'wx' && !$dxchan->{wx};
1621 $s =~ s/\a//og unless $dxchan->{beep};
1623 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'talk') {
1633 # obtain the hops from the list for this callsign and pc no
1639 my $hops = $DXProt::hopcount{$pcno};
1640 $hops = $DXProt::def_hopcount if !$hops;
1645 # adjust the hop count on a per node basis using the user loadable
1646 # hop table if available or else decrement an existing one
1653 my $call = $self->{call};
1656 if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
1657 my ($pcno) = $s =~ /^PC(\d\d)/o;
1658 confess "$call called adjust_hops with '$s'" unless $pcno;
1659 my $ref = $nodehops{$call} if %nodehops;
1661 my $newhops = $ref->{$pcno};
1662 return "" if defined $newhops && $newhops == 0;
1663 $newhops = $ref->{default} unless $newhops;
1664 return "" if defined $newhops && $newhops == 0;
1665 $newhops = $hops if !$newhops;
1666 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1668 # simply decrement it
1670 return "" if !$hops;
1671 $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
1683 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
1684 do "$main::data/hop_table.pl";
1690 # add a ping request to the ping queues
1693 my ($from, $to) = @_;
1694 my $ref = $pings{$to} || [];
1697 $r->{t} = [ gettimeofday ];
1698 route(undef, $to, pc51($to, $main::mycall, 1));
1705 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
1706 if ($tonode eq $main::mycall) {
1707 my $ref = DXUser->get_current($fromnode);
1708 my $cref = Route::Node::get($fromnode);
1709 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
1710 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
1711 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
1712 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
1713 my $oldpriv = $self->{priv};
1714 $self->{priv} = $ref->{priv}; # assume the user's privilege level
1715 my @in = (DXCommandmode::run_cmd($self, $cmd));
1716 $self->{priv} = $oldpriv;
1717 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
1718 delete $self->{remotecmd};
1720 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
1723 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
1726 my $ref = DXUser->get_current($tonode);
1727 if ($ref && $ref->is_clx) {
1728 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
1730 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
1735 sub process_rcmd_reply
1737 my ($self, $tonode, $fromnode, $user, $line) = @_;
1738 if ($tonode eq $main::mycall) {
1739 my $s = $rcmds{$fromnode};
1741 my $dxchan = DXChannel->get($s->{call});
1742 my $ref = $user eq $tonode ? $dxchan : (DXChannel->get($user) || $dxchan);
1743 $ref->send($line) if $ref;
1744 delete $rcmds{$fromnode} if !$dxchan;
1746 # send unsolicited ones to the sysop
1747 my $dxchan = DXChannel->get($main::myalias);
1748 $dxchan->send($line) if $dxchan;
1751 my $ref = DXUser->get_current($tonode);
1752 if ($ref && $ref->is_clx) {
1753 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
1755 $self->route($tonode, pc35($fromnode, $tonode, $line));
1764 my $fromnode = shift;
1769 Log('rcmd', 'out', $fromnode, $line);
1770 if ($self->is_clx) {
1771 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
1773 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
1778 # add a rcmd request to the rcmd queues
1781 my ($self, $to, $cmd) = @_;
1784 $r->{call} = $self->{call};
1785 $r->{t} = $main::systime;
1789 my $ref = Route::Node::get($to);
1790 my $dxchan = $ref->dxchan;
1791 if ($dxchan && $dxchan->is_clx) {
1792 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1794 route(undef, $to, pc34($main::mycall, $to, $cmd));
1801 my $pc39flag = shift;
1802 my $call = $self->call;
1804 return if $self->{disconnecting}++;
1806 unless ($pc39flag && $pc39flag == 1) {
1807 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1811 my $node = Route::Node::get($call);
1814 @rout = $node->del($main::routeroot);
1817 # unbusy and stop and outgoing mail
1818 my $mref = DXMsg::get_busy($call);
1819 $mref->stop_msg($call) if $mref;
1821 # broadcast to all other nodes that all the nodes connected to via me are gone
1822 unless ($pc39flag && $pc39flag == 2) {
1823 $self->route_pc21(@rout) if @rout;
1826 # remove outstanding pings
1827 delete $pings{$call};
1829 # I was the last node visited
1830 $self->user->node($main::mycall);
1832 # send info to all logged in thingies
1833 $self->tell_login('logoutn');
1835 Log('DXProt', $call . " Disconnected");
1837 $self->SUPER::disconnect;
1842 # send a talk message to this thingy
1846 my ($self, $from, $to, $via, $line, $origin) = @_;
1848 $line =~ s/\^/\\5E/g; # remove any ^ characters
1849 $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
1850 Log('talk', $self->call, $from, $via?$via:$main::mycall, $line) unless $origin && $origin ne $main::mycall;
1853 # send it if it isn't the except list and isn't isolated and still has a hop count
1854 # taking into account filtering and so on
1858 my $generate = shift;
1859 my $no = shift; # the no of things to filter on
1861 my ($filter, $hops);
1864 for (; @_ && $no; $no--) {
1867 if (!$self->{isolate} && $self->{routefilter}) {
1870 ($filter, $hops) = $self->{routefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq);
1874 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
1877 dbg("was sent a null value") if isdbg('chanerr');
1880 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
1884 foreach my $line (&$generate(@rin, @_)) {
1887 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1889 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1890 next unless $routeit;
1892 $self->send($routeit);
1900 my $generate = shift;
1901 my @dxchan = DXChannel::get_all_nodes();
1905 unless ($self->{isolate}) {
1906 foreach $dxchan (@dxchan) {
1907 next if $dxchan == $self;
1908 next if $dxchan == $me;
1909 $dxchan->send_route($generate, @_);
1917 broadcast_route($self, \&pc16, 1, @_);
1923 broadcast_route($self, \&pc17, 1, @_);
1929 broadcast_route($self, \&pc19, scalar @_, @_);
1935 broadcast_route($self, \&pc21, scalar @_, @_);
1941 broadcast_route($self, \&pc24, 1, @_);
1947 broadcast_route($self, \&pc41, 1, @_);
1953 broadcast_route($self, \&pc50, 1, @_);
1960 my ($filter, $hops) = (1, 1);
1962 if ($self->{inroutefilter}) {
1963 ($filter, $hops) = $self->{inroutefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq);
1964 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
1975 $s =~ s/\^H\d\d?\^?\~?$//;
1976 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
1977 $eph{$s} = $main::systime;
1985 while (($key, $val) = each %eph) {
1986 if ($key =~ m{$regex}) {
1996 while (($key, $val) = each %eph) {
1997 if ($main::systime - $val > 180) {