]> dxcluster.org Git - spider.git/blob - perl/DXProt.pm
version with the 'final' version of PC90 line in it
[spider.git] / perl / DXProt.pm
1 #!/usr/bin/perl
2 #
3 # This module impliments the protocal mode for a dx cluster
4 #
5 # Copyright (c) 1998 Dirk Koopman G1TLH
6 #
7 # $Id$
8
9
10 package DXProt;
11
12 @ISA = qw(DXChannel);
13
14 use DXUtil;
15 use DXChannel;
16 use DXUser;
17 use DXM;
18 use DXProtVars;
19 use DXCommandmode;
20 use DXLog;
21 use Spot;
22 use DXProtout;
23 use DXDebug;
24 use Filter;
25 use Local;
26 use DXDb;
27 use AnnTalk;
28 use Geomag;
29 use WCY;
30 use Time::HiRes qw(gettimeofday tv_interval);
31 use BadWords;
32 use DXHash;
33 use Route;
34 use Route::Node;
35 use Script;
36
37 use strict;
38
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;
44
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                         %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
48                         $allowzero $decode_dk0wcy $send_opernam @checklist);
49
50 $pc11_max_age = 1*3600;                 # the maximum age for an incoming 'real-time' pc11
51 $pc23_max_age = 1*3600;                 # the maximum age for an incoming 'real-time' pc23
52
53 $last_hour = time;                              # last time I did an hourly periodic update
54 %pings = ();                    # outstanding ping requests outbound
55 %rcmds = ();                    # outstanding rcmd requests outbound
56 %nodehops = ();                 # node specific hop control
57 $censorpc = 1;                                  # Do a BadWords::check on text fields and reject things
58                                                                 # loads of 'bad things'
59 $baddx = new DXHash "baddx";
60 $badspotter = new DXHash "badspotter";
61 $badnode = new DXHash "badnode";
62 $last10 = $last_pc50 = time;
63 $ann_to_talk = 1;
64 $rspfcheck = 1;
65 $eph_restime = 180;
66 $eph_info_restime = 60*60;
67 $eph_pc34_restime = 30;
68
69 @checklist = 
70 (
71  [ qw(c c m bp bc c) ],                 # pc10
72  [ qw(f m d t m c c h) ],               # pc11
73  [ qw(c bc m bp bm p h) ],              # pc12
74  [ qw(c h) ],                                   # 
75  [ qw(c h) ],                                   # 
76  [ qw(c m h) ],                                 # 
77  undef ,                                                # pc16 has to be validated manually
78  [ qw(c c h) ],                                 # pc17
79  [ qw(m n) ],                                   # pc18
80  undef ,                                                # pc19 has to be validated manually
81  undef ,                                                # pc20 no validation
82  [ qw(c m h) ],                                 # pc21
83  undef ,                                                # pc22 no validation
84  [ qw(d n n n n m c c h) ],             # pc23
85  [ qw(c p h) ],                                 # pc24
86  [ qw(c c n n) ],                               # pc25
87  [ qw(f m d t m c c bc) ],              # pc26
88  [ qw(d n n n n m c c bc) ],    # pc27
89  [ qw(c c m c d t p m bp n p bp bc) ], # pc28
90  [ qw(c c n m) ],                               # pc29
91  [ qw(c c n) ],                                 # pc30
92  [ qw(c c n) ],                                 # pc31
93  [ qw(c c n) ],                                 # pc32
94  [ qw(c c n) ],                                 # pc33
95  [ qw(c c m) ],                                 # pc34
96  [ qw(c c m) ],                                 # pc35
97  [ qw(c c m) ],                                 # pc36
98  [ qw(c c n m) ],                               # pc37
99  undef,                                                 # pc38 not interested
100  [ qw(c m) ],                                   # pc39
101  [ qw(c c m p n) ],                             # pc40
102  [ qw(c n m h) ],                               # pc41
103  [ qw(c c n) ],                                 # pc42
104  undef,                                                 # pc43 don't handle it
105  [ qw(c c n m m c) ],                   # pc44
106  [ qw(c c n m) ],                               # pc45
107  [ qw(c c n) ],                                 # pc46
108  undef,                                                 # pc47
109  undef,                                                 # pc48
110  [ qw(c m h) ],                                 # pc49
111  [ qw(c n h) ],                                 # pc50
112  [ qw(c c n) ],                                 # pc51
113  undef,
114  undef,
115  undef,
116  undef,
117  undef,
118  undef,
119  undef,
120  undef,
121  undef,                                                 # pc60
122  undef,
123  undef,
124  undef,
125  undef,
126  undef,
127  undef,
128  undef,
129  undef,
130  undef,
131  undef,                                                 # pc70
132  undef,
133  undef,
134  [ qw(d n n n n n n m m m c c h) ],     # pc73
135  undef,
136  undef,
137  undef,
138  undef,
139  undef,
140  undef,
141  undef,                                                 # pc80
142  undef,
143  undef,
144  undef,
145  [ qw(c c c m) ],                               # pc84
146  [ qw(c c c m) ],                               # pc85
147 );
148
149 # use the entry in the check list to check the field list presented
150 # return OK if line NOT in check list (for now)
151 sub check
152 {
153         my $n = shift;
154         $n -= 10;
155         return 0 if $n < 0 || $n > @checklist; 
156         my $ref = $checklist[$n];
157         return 0 unless ref $ref;
158         
159         my $i;
160         shift;    # not interested in the first field
161         for ($i = 0; $i < @$ref; $i++) {
162                 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
163                 return 0 unless $act;
164                 next if $blank && $_[$i] =~ /^[ \*]$/;
165                 if ($act eq 'c') {
166                         return $i+1 unless is_callsign($_[$i]);
167                 } elsif ($act eq 'm') {
168                         return $i+1 unless is_pctext($_[$i]);
169                 } elsif ($act eq 'p') {
170                         return $i+1 unless is_pcflag($_[$i]);
171                 } elsif ($act eq 'f') {
172                         return $i+1 unless is_freq($_[$i]);
173                 } elsif ($act eq 'n') {
174                         return $i+1 unless $_[$i] =~ /^[\d ]+$/;
175                 } elsif ($act eq 'h') {
176                         return $i+1 unless $_[$i] =~ /^H\d\d?$/;
177                 } elsif ($act eq 'd') {
178                         return $i+1 unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
179                 } elsif ($act eq 't') {
180                         return $i+1 unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
181                 }
182         }
183         return 0;
184 }
185
186 sub init
187 {
188         my $user = DXUser->get($main::mycall);
189         $DXProt::myprot_version += $main::version*100;
190         $main::me = DXProt->new($main::mycall, 0, $user); 
191         $main::me->{here} = 1;
192         $main::me->{state} = "indifferent";
193         do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
194         confess $@ if $@;
195         $main::me->{sort} = 'S';    # S for spider
196         $main::me->{priv} = 9;
197         $main::me->{metric} = 0;
198         $main::me->{pingave} = 0;
199         $main::me->{version} = $main::version;
200         $main::me->{build} = $main::build;
201                 
202 #       $Route::Node::me->adddxchan($main::me);
203 }
204
205 #
206 # obtain a new connection this is derived from dxchannel
207 #
208
209 sub new 
210 {
211         my $self = DXChannel::alloc(@_);
212
213         # add this node to the table, the values get filled in later
214         my $pkg = shift;
215         my $call = shift;
216         $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
217
218         return $self;
219 }
220
221 # this is how a pc connection starts (for an incoming connection)
222 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
223 # all the crap that comes between).
224 sub start
225 {
226         my ($self, $line, $sort) = @_;
227         my $call = $self->{call};
228         my $user = $self->{user};
229
230         # log it
231         my $host = $self->{conn}->{peerhost} || "unknown";
232         Log('DXProt', "$call connected from $host");
233         
234         # remember type of connection
235         $self->{consort} = $line;
236         $self->{outbound} = $sort eq 'O';
237         my $priv = $user->priv;
238         $priv = $user->priv(1) unless $priv;
239         $self->{priv} = $priv;     # other clusters can always be 'normal' users
240         $self->{lang} = $user->lang || 'en';
241         $self->{isolate} = $user->{isolate};
242         $self->{consort} = $line;       # save the connection type
243         $self->{here} = 1;
244         $self->{width} = 80;
245
246         # sort out registration
247         $self->{registered} = 1;
248
249         # get the output filters
250         $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
251         $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
252         $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
253         $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
254         $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
255
256
257         # get the INPUT filters (these only pertain to Clusters)
258         $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
259         $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
260         $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
261         $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
262         $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
263         
264         # set unbuffered and no echo
265         $self->send_now('B',"0");
266         $self->send_now('E',"0");
267         $self->conn->echo(0) if $self->conn->can('echo');
268         
269         # ping neighbour node stuff
270         my $ping = $user->pingint;
271         $ping = 5*60 unless defined $ping;
272         $self->{pingint} = $ping;
273         $self->{nopings} = $user->nopings || 2;
274         $self->{pingtime} = [ ];
275         $self->{pingave} = 999;
276         $self->{metric} ||= 100;
277         $self->{lastping} = $main::systime;
278
279         # send initialisation string
280         unless ($self->{outbound}) {
281                 $self->send(pc18());
282         }
283         
284         $self->state('init');
285         $self->{pc50_t} = $main::systime;
286
287         # send info to all logged in thingies
288         $self->tell_login('loginn');
289
290         # run a script send the output to the debug file
291         my $script = new Script(lc $call) || new Script('node_default');
292         $script->run($self) if $script;
293 }
294
295 #
296 # This is the normal pcxx despatcher
297 #
298 sub normal
299 {
300         my ($self, $line) = @_;
301         my @field = split /\^/, $line;
302         return unless @field;
303         
304         pop @field if $field[-1] eq '~';
305         
306 #       print join(',', @field), "\n";
307                                                 
308         
309         # process PC frames, this will fail unless the frame starts PCnn
310         my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
311         return unless $pcno;
312         return if $pcno < 10 || $pcno > 99;
313
314         # check for and dump bad protocol messages
315         my $n = check($pcno, @field);
316         if ($n) {
317                 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
318                 return;
319         }
320
321         # local processing 1
322         my $pcr;
323         eval {
324                 $pcr = Local::pcprot($self, $pcno, @field);
325         };
326 #       dbg("Local::pcprot error $@") if isdbg('local') if $@;
327         return if $pcr;
328         
329  SWITCH: {
330                 if ($pcno == 10) {              # incoming talk
331
332                         # rsfp check
333                         return if $rspfcheck and !$self->rspfcheck(0, $field[6], $field[1]);
334                         
335                         # will we allow it at all?
336                         if ($censorpc) {
337                                 my @bad;
338                                 if (@bad = BadWords::check($field[3])) {
339                                         dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
340                                         return;
341                                 }
342                         }
343
344                         # is it for me or one of mine?
345                         my ($from, $to, $via, $call, $dxchan);
346                         $from = $field[1];
347                         if ($field[5] gt ' ') {
348                                 $via = $field[2];
349                                 $to = $field[5];
350                         } else {
351                                 $to = $field[2];
352                         }
353
354                         # if this is a 'nodx' node then ignore it
355                         if ($badnode->in($field[6]) || ($via && $badnode->in($via))) {
356                                 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
357                                 return;
358                         }
359
360                         # if this is a 'bad spotter' user then ignore it
361                         my $nossid = $from;
362                         $nossid =~ s/-\d+$//;
363                         if ($badspotter->in($nossid)) {
364                                 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
365                                 return;
366                         }
367
368                         # if we are converting announces to talk is it a dup?
369                         if ($ann_to_talk) {
370                                 if (AnnTalk::is_talk_candidate($from, $field[3]) && AnnTalk::dup($from, $to, $field[3])) {
371                                         dbg("DXPROT: Dupe talk from announce, dropped") if isdbg('chanerr');
372                                         return;
373                                 }
374                         }
375
376                         # it is here and logged on
377                         $dxchan = DXChannel->get($main::myalias) if $to eq $main::mycall;
378                         $dxchan = DXChannel->get($to) unless $dxchan;
379                         if ($dxchan && $dxchan->is_user) {
380                                 $field[3] =~ s/\%5E/^/g;
381                                 $dxchan->talk($from, $to, $via, $field[3]);
382                                 return;
383                         }
384
385                         # is it elsewhere, visible on the cluster via the to address?
386                         # note: this discards the via unless the to address is on
387                         # the via address
388                         my ($ref, $vref);
389                         if ($ref = Route::get($to)) {
390                                 $vref = Route::Node::get($via) if $via;
391                                 $vref = undef unless $vref && grep $to eq $_, $vref->users;
392                                 $ref->dxchan->talk($from, $to, $vref ? $via : undef, $field[3], $field[6]);
393                                 return;
394                         }
395
396                         # not visible here, send a message of condolence
397                         $vref = undef;
398                         $ref = Route::get($from);
399                         $vref = $ref = Route::Node::get($field[6]) unless $ref; 
400                         if ($ref) {
401                                 $dxchan = $ref->dxchan;
402                                 $dxchan->talk($main::mycall, $from, $vref ? $vref->call : undef, $dxchan->msg('talknh', $to) );
403                         }
404                         return;
405                 }
406                 
407                 if ($pcno == 11 || $pcno == 26) { # dx spot
408
409                         # route 'foreign' pc26s 
410                         if ($pcno == 26) {
411                                 if ($field[7] ne $main::mycall) {
412                                         $self->route($field[7], $line);
413                                         return;
414                                 }
415                         }
416                         
417                         # rsfp check
418 #                       return if $rspfcheck and !$self->rspfcheck(1, $field[7], $field[6]);
419
420                         # if this is a 'nodx' node then ignore it
421                         if ($badnode->in($field[7])) {
422                                 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
423                                 return;
424                         }
425                         
426                         # if this is a 'bad spotter' user then ignore it
427                         my $nossid = $field[6];
428                         $nossid =~ s/-\d+$//;
429                         if ($badspotter->in($nossid)) {
430                                 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
431                                 return;
432                         }
433                         
434                         # convert the date to a unix date
435                         my $d = cltounix($field[3], $field[4]);
436                         # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
437                         if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
438                                 dbg("PCPROT: Spot ignored, invalid date or out of range ($field[3] $field[4])\n") if isdbg('chanerr');
439                                 return;
440                         }
441
442                         # is it 'baddx'
443                         if ($baddx->in($field[2]) || BadWords::check($field[2]) || $field[2] =~ /COCK/) {
444                                 dbg("PCPROT: Bad DX spot, ignored") if isdbg('chanerr');
445                                 return;
446                         }
447                         
448                         # do some de-duping
449                         $field[5] =~ s/^\s+//;      # take any leading blanks off
450                         $field[2] = unpad($field[2]);   # take off leading and trailing blanks from spotted callsign
451                         if ($field[2] =~ /BUST\w*$/) {
452                                 dbg("PCPROT: useless 'BUSTED' spot") if isdbg('chanerr');
453                                 return;
454                         }
455                         if ($censorpc) {
456                                 my @bad;
457                                 if (@bad = BadWords::check($field[5])) {
458                                         dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
459                                         return;
460                                 }
461                         }
462
463
464                         my @spot = Spot::prepare($field[1], $field[2], $d, $field[5], $field[6], $field[7]);
465                         # global spot filtering on INPUT
466                         if ($self->{inspotsfilter}) {
467                                 my ($filter, $hops) = $self->{inspotsfilter}->it(@spot);
468                                 unless ($filter) {
469                                         dbg("PCPROT: Rejected by input spot filter") if isdbg('chanerr');
470                                         return;
471                                 }
472                         }
473
474                         # this goes after the input filtering, but before the add
475                         # so that if it is input filtered, it isn't added to the dup
476                         # list. This allows it to come in from a "legitimate" source
477                         if (Spot::dup($field[1], $field[2], $d, $field[5])) {
478                                 dbg("PCPROT: Duplicate Spot ignored\n") if isdbg('chanerr');
479                                 return;
480                         }
481
482                         # add it 
483                         Spot::add(@spot);
484
485             #
486                         # @spot at this point contains:-
487             # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
488                         # then  spotted itu, spotted cq, spotters itu, spotters cq
489                         # you should be able to route on any of these
490             #
491                         
492                         # fix up qra locators of known users 
493                         my $user = DXUser->get_current($spot[4]);
494                         if ($user) {
495                                 my $qra = $user->qra;
496                                 unless ($qra && is_qra($qra)) {
497                                         my $lat = $user->lat;
498                                         my $long = $user->long;
499                                         if (defined $lat && defined $long) {
500                                                 $user->qra(DXBearing::lltoqra($lat, $long)); 
501                                                 $user->put;
502                                         }
503                                 }
504
505                                 # send a remote command to a distant cluster if it is visible and there is no
506                                 # qra locator and we havn't done it for a month.
507
508                                 unless ($user->qra) {
509                                         my $node;
510                                         my $to = $user->homenode;
511                                         my $last = $user->lastoper || 0;
512                                         if ($send_opernam && $to && $to ne $main::mycall && $main::systime > $last + $DXUser::lastoperinterval && ($node = Route::Node::get($to)) ) {
513                                                 my $cmd = "forward/opernam $spot[4]";
514                                                 # send the rcmd but we aren't interested in the replies...
515                                                 my $dxchan = $node->dxchan;
516                                                 if ($dxchan && $dxchan->is_clx) {
517                                                         route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
518                                                 } else {
519                                                         route(undef, $to, pc34($main::mycall, $to, $cmd));
520                                                 }
521                                                 if ($to ne $field[7]) {
522                                                         $to = $field[7];
523                                                         $node = Route::Node::get($to);
524                                                         if ($node) {
525                                                                 $dxchan = $node->dxchan;
526                                                                 if ($dxchan && $dxchan->is_clx) {
527                                                                         route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
528                                                                 } else {
529                                                                         route(undef, $to, pc34($main::mycall, $to, $cmd));
530                                                                 }
531                                                         }
532                                                 }
533                                                 $user->lastoper($main::systime);
534                                                 $user->put;
535                                         }
536                                 }
537                         }
538                                 
539                         # local processing 
540                         my $r;
541                         eval {
542                                 $r = Local::spot($self, @spot);
543                         };
544 #                       dbg("Local::spot1 error $@") if isdbg('local') if $@;
545                         return if $r;
546
547                         # DON'T be silly and send on PC26s!
548                         return if $pcno == 26;
549
550                         # send out the filtered spots
551                         send_dx_spot($self, $line, @spot) if @spot;
552                         return;
553                 }
554                 
555                 if ($pcno == 12) {              # announces
556
557 #                       return if $rspfcheck and !$self->rspfcheck(1, $field[5], $field[1]);
558
559                         # announce duplicate checking
560                         $field[3] =~ s/^\s+//;  # remove leading blanks
561
562                         if ($censorpc) {
563                                 my @bad;
564                                 if (@bad = BadWords::check($field[3])) {
565                                         dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
566                                         return;
567                                 }
568                         }
569
570                         # if this is a 'nodx' node then ignore it
571                         if ($badnode->in($field[5])) {
572                                 dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
573                                 return;
574                         }
575
576                         # if this is a 'bad spotter' user then ignore it
577                         my $nossid = $field[1];
578                         $nossid =~ s/-\d+$//;
579                         if ($badspotter->in($nossid)) {
580                                 dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
581                                 return;
582                         }
583
584                         if ($field[2] eq '*' || $field[2] eq $main::mycall) {
585
586
587                                 # here's a bit of fun, convert incoming ann with a callsign in the first word
588                                 # or one saying 'to <call>' to a talk if we can route to the recipient
589                                 if ($ann_to_talk) {
590                                         my $call = AnnTalk::is_talk_candidate($field[1], $field[3]);
591                                         if ($call) {
592                                                 my $ref = Route::get($call);
593                                                 if ($ref) {
594                                                         my $dxchan = $ref->dxchan;
595                                                         $dxchan->talk($field[1], $call, undef, $field[3], $field[5]) if $dxchan != $self;
596                                                         return;
597                                                 }
598                                         }
599                                 }
600         
601                                 # send it
602                                 $self->send_announce($line, @field[1..6]);
603                         } else {
604                                 $self->route($field[2], $line);
605                         }
606                         return;
607                 }
608                 
609                 if ($pcno == 13) {
610                         last SWITCH;
611                 }
612                 if ($pcno == 14) {
613                         last SWITCH;
614                 }
615                 if ($pcno == 15) {
616                         last SWITCH;
617                 }
618                 
619                 if ($pcno == 16) {              # add a user
620
621                         if (eph_dup($line)) {
622                                 dbg("PCPROT: dup PC16 detected") if isdbg('chanerr');
623                                 return;
624                         }
625
626                         # general checks
627                         my $dxchan;
628                         my $ncall = $field[1];
629                         my $newline = "PC16^";
630                         
631                         if ($ncall eq $main::mycall) {
632                                 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
633                                 return;
634                         }
635                         my $parent = Route::Node::get($ncall); 
636                         unless ($parent) {
637                                 dbg("PCPROT: Node $ncall not in config") if isdbg('chanerr');
638                                 return;
639                         }
640                         $dxchan = $parent->dxchan;
641                         if ($dxchan && $dxchan ne $self) {
642                                 dbg("PCPROT: PC16 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
643                                 return;
644                         }
645
646                         # input filter if required
647                         return unless $self->in_filter_route($parent);
648                         
649                         my $i;
650                         my @rout;
651                         for ($i = 2; $i < $#field; $i++) {
652                                 my ($call, $conf, $here) = $field[$i] =~ /^(\S+) (\S) (\d)/o;
653                                 next unless $call && $conf && defined $here && is_callsign($call);
654                                 next if $call eq $main::mycall;
655
656                                 eph_del_regex("^PC17\\^$call\\^$ncall");
657                                 
658                                 $conf = $conf eq '*';
659
660                                 # reject this if we think it is a node already
661                                 my $r = Route::Node::get($call);
662                                 my $u = DXUser->get_current($call) unless $r;
663                                 if ($r || ($u && $u->is_node)) {
664                                         dbg("PCPROT: $call is a node") if isdbg('chanerr');
665                                         next;
666                                 }
667                                 
668                                 $r = Route::User::get($call);
669                                 my $flags = Route::here($here)|Route::conf($conf);
670                                 
671                                 if ($r) {
672                                         if ($r->flags != $flags) {
673                                                 $r->flags($flags);
674                                                 push @rout, $r;
675                                         }
676                                         $r->addparent($parent);
677                                 } else {
678                                         push @rout, $parent->add_user($call, $flags);
679                                 }
680                                 
681                                 # add this station to the user database, if required
682                                 $call =~ s/-\d+$//o;        # remove ssid for users
683                                 my $user = DXUser->get_current($call);
684                                 $user = DXUser->new($call) if !$user;
685                                 $user->homenode($parent->call) if !$user->homenode;
686                                 $user->node($parent->call);
687                                 $user->lastin($main::systime) unless DXChannel->get($call);
688                                 $user->put;
689                         }
690                         
691                         # queue up any messages (look for privates only)
692                         DXMsg::queue_msg(1) if $self->state eq 'normal';     
693
694                         $self->route_pc16($parent, @rout) if @rout;
695                         return;
696                 }
697                 
698                 if ($pcno == 17) {              # remove a user
699                         my $dxchan;
700                         my $ncall = $field[2];
701                         my $ucall = $field[1];
702
703                         eph_del_regex("^PC16\\^$ncall.*$ucall");
704                         
705                         if ($ncall eq $main::mycall) {
706                                 dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
707                                 return;
708                         }
709
710                         my $uref = Route::User::get($ucall);
711                         unless ($uref) {
712                                 dbg("PCPROT: Route::User $ucall not in config") if isdbg('chanerr');
713                                 return;
714                         }
715                         my $parent = Route::Node::get($ncall);
716                         unless ($parent) {
717                                 dbg("PCPROT: Route::Node $ncall not in config") if isdbg('chanerr');
718                                 return;
719                         }                       
720
721                         $dxchan = $parent->dxchan;
722                         if ($dxchan && $dxchan ne $self) {
723                                 dbg("PCPROT: PC17 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
724                                 return;
725                         }
726
727                         # input filter if required
728                         return unless $self->in_filter_route($parent);
729                         
730                         $parent->del_user($uref);
731
732                         if (eph_dup($line)) {
733                                 dbg("PCPROT: dup PC17 detected") if isdbg('chanerr');
734                                 return;
735                         }
736
737                         $self->route_pc17($parent, $uref);
738                         return;
739                 }
740                 
741                 if ($pcno == 18) {              # link request
742                         $self->state('init');   
743
744                         # record the type and version offered
745                         if ($field[1] =~ /DXSpider Version: (\d+\.\d+) Build: (\d+\.\d+)/) {
746                                 $self->version(53 + $1);
747                                 $self->user->version(53 + $1);
748                                 $self->build(0 + $2);
749                                 $self->user->build(0 + $2);
750                                 unless ($self->is_spider) {
751                                         $self->user->sort('S');
752                                         $self->user->put;
753                                         $self->sort('S');
754                                 }
755                         } else {
756                                 $self->version(50.0);
757                                 $self->version($field[2] / 100) if $field[2] && $field[2] =~ /^\d+$/;
758                                 $self->user->version($self->version);
759                         }
760
761                         # first clear out any nodes on this dxchannel
762                         my $parent = Route::Node::get($self->{call});
763                         my @rout = $parent->del_nodes;
764                         $self->route_pc21(@rout, $parent) if @rout;
765                         $self->send_local_config();
766                         $self->send(pc20());
767                         return;             # we don't pass these on
768                 }
769                 
770                 if ($pcno == 19) {              # incoming cluster list
771                         my $i;
772                         my $newline = "PC19^";
773
774                         if (eph_dup($line)) {
775                                 dbg("PCPROT: dup PC19 detected") if isdbg('chanerr');
776                                 return;
777                         }
778
779                         # new routing list
780                         my @rout;
781                         my $parent = Route::Node::get($self->{call});
782                         unless ($parent) {
783                                 dbg("DXPROT: my parent $self->{call} has disappeared");
784                                 $self->disconnect;
785                                 return;
786                         }
787
788                         # parse the PC19
789                         for ($i = 1; $i < $#field-1; $i += 4) {
790                                 my $here = $field[$i];
791                                 my $call = uc $field[$i+1];
792                                 my $conf = $field[$i+2];
793                                 my $ver = $field[$i+3];
794                                 next unless defined $here && defined $conf && is_callsign($call);
795
796                                 eph_del_regex("^PC(?:21\\^$call|17\\^[^\\^]+\\^$call)");
797                                 
798                                 # check for sane parameters
799 #                               $ver = 5000 if $ver eq '0000';
800                                 next if $ver < 5000; # only works with version 5 software
801                                 next if length $call < 3; # min 3 letter callsigns
802                                 next if $call eq $main::mycall;
803
804                                 # check that this PC19 isn't trying to alter the wrong dxchan
805                                 my $dxchan = DXChannel->get($call);
806                                 if ($dxchan && $dxchan != $self) {
807                                         dbg("PCPROT: PC19 from $self->{call} trying to alter wrong locally connected $call, ignored!") if isdbg('chanerr');
808                                         next;
809                                 }
810
811                                 # update it if required
812                                 my $r = Route::Node::get($call);
813                                 my $flags = Route::here($here)|Route::conf($conf);
814                                 if ($r) {
815                                         my $ar;
816                                         if ($call ne $parent->call) {
817                                                 if ($self->in_filter_route($r)) {
818                                                         $ar = $parent->add($call, $ver, $flags);
819                                                         push @rout, $ar if $ar;
820                                                 } else {
821                                                         next;
822                                                 }
823                                         }
824                                         if ($r->version ne $ver || $r->flags != $flags) {
825                                                 $r->version($ver);
826                                                 $r->flags($flags);
827                                                 push @rout, $r unless $ar;
828                                         }
829                                 } else {
830                                         if ($call eq $self->{call}) {
831                                                 dbg("DXPROT: my channel route for $call has disappeared");
832                                                 next;
833                                         };
834                                         
835                                         my $new = Route->new($call);          # throw away
836                                     if ($self->in_filter_route($new)) {
837                                                 my $r = $parent->add($call, $ver, $flags);
838                                                 push @rout, $r;
839                                         } else {
840                                                 next;
841                                         }
842                                 }
843
844                                 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
845                                 my $mref = DXMsg::get_busy($call);
846                                 $mref->stop_msg($call) if $mref;
847                                 
848                                 # add this station to the user database, if required (don't remove SSID from nodes)
849                                 my $user = DXUser->get_current($call);
850                                 if (!$user) {
851                                         $user = DXUser->new($call);
852                                         $user->sort('A');
853                                         $user->priv(1);                   # I have relented and defaulted nodes
854                                         $user->lockout(1);
855                                         $user->homenode($call);
856                                         $user->node($call);
857                                 }
858                                 $user->lastin($main::systime) unless DXChannel->get($call);
859                                 $user->put;
860                         }
861
862
863                         $self->route_pc19(@rout) if @rout;
864                         return;
865                 }
866                 
867                 if ($pcno == 20) {              # send local configuration
868                         $self->send_local_config();
869                         $self->send(pc22());
870                         $self->state('normal');
871                         $self->{lastping} = 0;
872                         return;
873                 }
874                 
875                 if ($pcno == 21) {              # delete a cluster from the list
876                         my $call = uc $field[1];
877
878                         eph_del_regex("^PC1[79].*$call");
879                         
880                         # if I get a PC21 from the same callsign as self then treat it
881                         # as a PC39: I have gone away
882                         if ($call eq $self->call) {
883                                 $self->disconnect(1);
884                                 return;
885                         }
886
887                         my @rout;
888                         my $parent = Route::Node::get($self->{call});
889                         unless ($parent) {
890                                 dbg("DXPROT: my parent $self->{call} has disappeared");
891                                 $self->disconnect;
892                                 return;
893                         }
894                         if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
895                                 my $node = Route::Node::get($call);
896                                 if ($node) {
897
898                                         my $dxchan = DXChannel->get($call);
899                                         if ($dxchan && $dxchan != $self) {
900                                                 dbg("PCPROT: PC21 from $self->{call} trying to alter locally connected $call, ignored!") if isdbg('chanerr');
901                                                 return;
902                                         }
903
904                                         # input filter it
905                                         return unless $self->in_filter_route($node);
906
907                                         # routing objects
908                                         push @rout, $node->del($parent);
909                                 }
910                         } else {
911                                 dbg("PCPROT: I WILL _NOT_ be disconnected!") if isdbg('chanerr');
912                                 return;
913                         }
914
915 #                       if (eph_dup($line)) {
916 #                               dbg("PCPROT: dup PC21 detected") if isdbg('chanerr');
917 #                               return;
918 #                       }
919
920                         $self->route_pc21(@rout) if @rout;
921                         return;
922                 }
923                 
924                 if ($pcno == 22) {
925                         $self->state('normal');
926                         $self->{lastping} = 0;
927                         return;
928                 }
929                                 
930                 if ($pcno == 23 || $pcno == 27) { # WWV info
931                         
932                         # route 'foreign' pc27s 
933                         if ($pcno == 27) {
934                                 if ($field[8] ne $main::mycall) {
935                                         $self->route($field[8], $line);
936                                         return;
937                                 }
938                         }
939
940                         return if $rspfcheck and !$self->rspfcheck(1, $field[8], $field[7]);
941
942                         # do some de-duping
943                         my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
944                         my $sfi = unpad($field[3]);
945                         my $k = unpad($field[4]);
946                         my $i = unpad($field[5]);
947                         my ($r) = $field[6] =~ /R=(\d+)/;
948                         $r = 0 unless $r;
949                         if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
950                                 dbg("PCPROT: WWV Date ($field[1] $field[2]) out of range") if isdbg('chanerr');
951                                 return;
952                         }
953                         if (Geomag::dup($d,$sfi,$k,$i,$field[6])) {
954                                 dbg("PCPROT: Dup WWV Spot ignored\n") if isdbg('chanerr');
955                                 return;
956                         }
957                         $field[7] =~ s/-\d+$//o;            # remove spotter's ssid
958                 
959                         my $wwv = Geomag::update($d, $field[2], $sfi, $k, $i, @field[6..8], $r);
960
961                         my $rep;
962                         eval {
963                                 $rep = Local::wwv($self, $field[1], $field[2], $sfi, $k, $i, @field[6..8], $r);
964                         };
965 #                       dbg("Local::wwv2 error $@") if isdbg('local') if $@;
966                         return if $rep;
967
968                         # DON'T be silly and send on PC27s!
969                         return if $pcno == 27;
970
971                         # broadcast to the eager world
972                         send_wwv_spot($self, $line, $d, $field[2], $sfi, $k, $i, @field[6..8]);
973                         return;
974                 }
975                 
976                 if ($pcno == 24) {              # set here status
977                         my $call = uc $field[1];
978                         my ($nref, $uref);
979                         $nref = Route::Node::get($call);
980                         $uref = Route::User::get($call);
981                         return unless $nref || $uref;   # if we don't know where they are, it's pointless sending it on
982                         
983                         unless (eph_dup($line)) {
984                                 $nref->here($field[2]) if $nref;
985                                 $uref->here($field[2]) if $uref;
986                                 my $ref = $nref || $uref;
987                                 return unless $self->in_filter_route($ref);
988                                 $self->route_pc24($ref, $field[3]);
989                         }
990                         return;
991                 }
992                 
993                 if ($pcno == 25) {      # merge request
994                         if ($field[1] ne $main::mycall) {
995                                 $self->route($field[1], $line);
996                                 return;
997                         }
998                         if ($field[2] eq $main::mycall) {
999                                 dbg("PCPROT: Trying to merge to myself, ignored") if isdbg('chanerr');
1000                                 return;
1001                         }
1002
1003                         Log('DXProt', "Merge request for $field[3] spots and $field[4] WWV from $field[2]");
1004                         
1005                         # spots
1006                         if ($field[3] > 0) {
1007                                 my @in = reverse Spot::search(1, undef, undef, 0, $field[3]);
1008                                 my $in;
1009                                 foreach $in (@in) {
1010                                         $self->send(pc26(@{$in}[0..4], $field[2]));
1011                                 }
1012                         }
1013
1014                         # wwv
1015                         if ($field[4] > 0) {
1016                                 my @in = reverse Geomag::search(0, $field[4], time, 1);
1017                                 my $in;
1018                                 foreach $in (@in) {
1019                                         $self->send(pc27(@{$in}[0..5], $field[2]));
1020                                 }
1021                         }
1022                         return;
1023                 }
1024
1025                 if (($pcno >= 28 && $pcno <= 33) || $pcno == 40 || $pcno == 42 || $pcno == 49) { # mail/file handling
1026                         return if $pcno == 49 && eph_dup($line);
1027                         if ($pcno == 49 || $field[1] eq $main::mycall) {
1028                                 DXMsg::process($self, $line);
1029                         } else {
1030                                 $self->route($field[1], $line) unless $self->is_clx;
1031                         }
1032                         return;
1033                 }
1034                 
1035                 if ($pcno == 34 || $pcno == 36) { # remote commands (incoming)
1036                         if (eph_dup($line, $eph_pc34_restime)) {
1037                                 dbg("PCPROT: dupe") if isdbg('chanerr');
1038                         } else {
1039                                 $self->process_rcmd($field[1], $field[2], $field[2], $field[3]);
1040                         }
1041                         return;
1042                 }
1043                 
1044                 if ($pcno == 35) {              # remote command replies
1045                         eph_del_regex("^PC35\\^$field[2]\\^$field[1]\\^");
1046                         $self->process_rcmd_reply($field[1], $field[2], $field[1], $field[3]);
1047                         return;
1048                 }
1049                 
1050                 # for pc 37 see 44 onwards
1051
1052                 if ($pcno == 38) {              # node connected list from neighbour
1053                         return;
1054                 }
1055                 
1056                 if ($pcno == 39) {              # incoming disconnect
1057                         if ($field[1] eq $self->{call}) {
1058                                 $self->disconnect(1);
1059                         } else {
1060                                 dbg("PCPROT: came in on wrong channel") if isdbg('chanerr');
1061                         }
1062                         return;
1063                 }
1064                 
1065                 if ($pcno == 41) {              # user info
1066                         my $call = $field[1];
1067
1068                         if (eph_dup($line, $eph_info_restime)) {
1069                                 dbg("PCPROT: dupe") if isdbg('chanerr');
1070                                 return;
1071                         }
1072                         
1073                         # input filter if required
1074 #                       my $ref = Route::get($call) || Route->new($call);
1075 #                       return unless $self->in_filter_route($ref);
1076
1077                         if ($field[3] eq $field[2] || $field[3] =~ /^\s*$/) {
1078                                 dbg('PCPROT: invalid value') if isdbg('chanerr');
1079                                 return;
1080                         }
1081
1082                         # add this station to the user database, if required
1083                         my $user = DXUser->get_current($call);
1084                         $user = DXUser->new($call) if !$user;
1085                         
1086                         if ($field[2] == 1) {
1087                                 $user->name($field[3]);
1088                         } elsif ($field[2] == 2) {
1089                                 $user->qth($field[3]);
1090                         } elsif ($field[2] == 3) {
1091                                 if (is_latlong($field[3])) {
1092                                         my ($lat, $long) = DXBearing::stoll($field[3]);
1093                                         $user->lat($lat);
1094                                         $user->long($long);
1095                                         $user->qra(DXBearing::lltoqra($lat, $long));
1096                                 } else {
1097                                         dbg('PCPROT: not a valid lat/long') if isdbg('chanerr');
1098                                         return;
1099                                 }
1100                         } elsif ($field[2] == 4) {
1101                                 $user->homenode($field[3]);
1102                         } elsif ($field[2] == 5) {
1103                                 if (is_qra(uc $field[3])) {
1104                                         my ($lat, $long) = DXBearing::qratoll(uc $field[3]);
1105                                         $user->lat($lat);
1106                                         $user->long($long);
1107                                         $user->qra(uc $field[3]);
1108                                 } else {
1109                                         dbg('PCPROT: not a valid QRA locator') if isdbg('chanerr');
1110                                         return;
1111                                 }
1112                         }
1113                         $user->lastoper($main::systime);   # to cut down on excessive for/opers being generated
1114                         $user->put;
1115
1116                         unless ($self->{isolate}) {
1117                                 DXChannel::broadcast_nodes($line, $self); # send it to everyone but me
1118                         }
1119
1120 #  perhaps this IS what we want after all
1121 #                       $self->route_pc41($ref, $call, $field[2], $field[3], $field[4]);
1122                         return;
1123                 }
1124
1125                 if ($pcno == 43) {
1126                         last SWITCH;
1127                 }
1128
1129                 if ($pcno == 37 || $pcno == 44 || $pcno == 45 || $pcno == 46 || $pcno == 47 || $pcno == 48) {
1130                         DXDb::process($self, $line);
1131                         return;
1132                 }
1133                 
1134                 if ($pcno == 50) {              # keep alive/user list
1135                         my $call = $field[1];
1136                         my $node = Route::Node::get($call);
1137                         if ($node) {
1138                                 return unless $node->call eq $self->{call};
1139                                 $node->usercount($field[2]);
1140
1141                                 # input filter if required
1142                                 return unless $self->in_filter_route($node);
1143
1144                                 $self->route_pc50($node, $field[2], $field[3]) unless eph_dup($line);
1145                         }
1146                         return;
1147                 }
1148                 
1149                 if ($pcno == 51) {              # incoming ping requests/answers
1150                         my $to = $field[1];
1151                         my $from = $field[2];
1152                         my $flag = $field[3];
1153
1154                         
1155                         # is it for us?
1156                         if ($to eq $main::mycall) {
1157                                 if ($flag == 1) {
1158                                         $self->send(pc51($from, $to, '0'));
1159                                 } else {
1160                                         # it's a reply, look in the ping list for this one
1161                                         my $ref = $pings{$from};
1162                                         if ($ref) {
1163                                                 my $tochan =  DXChannel->get($from);
1164                                                 while (@$ref) {
1165                                                         my $r = shift @$ref;
1166                                                         my $dxchan = DXChannel->get($r->{call});
1167                                                         next unless $dxchan;
1168                                                         my $t = tv_interval($r->{t}, [ gettimeofday ]);
1169                                                         if ($dxchan->is_user) {
1170                                                                 my $s = sprintf "%.2f", $t; 
1171                                                                 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
1172                                                                 $dxchan->send($dxchan->msg('pingi', $from, $s, $ave))
1173                                                         } elsif ($dxchan->is_node) {
1174                                                                 if ($tochan) {
1175                                                                         my $nopings = $tochan->user->nopings || 2;
1176                                                                         push @{$tochan->{pingtime}}, $t;
1177                                                                         shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
1178
1179                                                                         # cope with a missed ping, this means you must set the pingint large enough
1180                                                                         if ($t > $tochan->{pingint}  && $t < 2 * $tochan->{pingint} ) {
1181                                                                                 $t -= $tochan->{pingint};
1182                                                                         }
1183
1184                                                                         # calc smoothed RTT a la TCP
1185                                                                         if (@{$tochan->{pingtime}} == 1) {
1186                                                                                 $tochan->{pingave} = $t;
1187                                                                         } else {
1188                                                                                 $tochan->{pingave} = $tochan->{pingave} + (($t - $tochan->{pingave}) / 6);
1189                                                                         }
1190                                                                         $tochan->{nopings} = $nopings; # pump up the timer
1191                                                                 }
1192                                                         } 
1193                                                 }
1194                                         }
1195                                 }
1196                         } else {
1197                                 if (eph_dup($line)) {
1198                                         dbg("PCPROT: dup PC51 detected") if isdbg('chanerr');
1199                                         return;
1200                                 }
1201                                 # route down an appropriate thingy
1202                                 $self->route($to, $line);
1203                         }
1204                         return;
1205                 }
1206
1207                 if ($pcno == 75) {              # dunno but route it
1208                         my $call = $field[1];
1209                         if ($call ne $main::mycall) {
1210                                 $self->route($call, $line);
1211                         }
1212                         return;
1213                 }
1214
1215                 if ($pcno == 73) {  # WCY broadcasts
1216                         my $call = $field[1];
1217                         
1218                         # do some de-duping
1219                         my $d = cltounix($call, sprintf("%02d18Z", $field[2]));
1220                         if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
1221                                 dbg("PCPROT: WCY Date ($call $field[2]) out of range") if isdbg('chanerr');
1222                                 return;
1223                         }
1224                         @field = map { unpad($_) } @field;
1225                         if (WCY::dup($d)) {
1226                                 dbg("PCPROT: Dup WCY Spot ignored\n") if isdbg('chanerr');
1227                                 return;
1228                         }
1229                 
1230                         my $wcy = WCY::update($d, @field[2..12]);
1231
1232                         my $rep;
1233                         eval {
1234                                 $rep = Local::wcy($self, @field[1..12]);
1235                         };
1236                         # dbg("Local::wcy error $@") if isdbg('local') if $@;
1237                         return if $rep;
1238
1239                         # broadcast to the eager world
1240                         send_wcy_spot($self, $line, $d, @field[2..12]);
1241                         return;
1242                 }
1243
1244                 if ($pcno == 84) { # remote commands (incoming)
1245                         $self->process_rcmd($field[1], $field[2], $field[3], $field[4]);
1246                         return;
1247                 }
1248
1249                 if ($pcno == 85) {              # remote command replies
1250                         $self->process_rcmd_reply($field[1], $field[2], $field[3], $field[4]);
1251                         
1252                         return;
1253                 }
1254                 if ($pcno == 90) {              # new style PC16,17,19,21
1255                         my $node = $field[1];
1256
1257                         # mark this node as wanting PC90s
1258                         my $parent = Route::Node::get($node);
1259                         if ($parent) {
1260                                 my $t = hex $field[2];
1261                                 my $last = $parent->lastpc90 || 0;
1262                                 if ($last < $t) {
1263                                         $parent->pc90(1);
1264                                         $parent->lastpc90($t); 
1265                                         my ($updsort, $n) = unpack "AA*", $field[3];
1266                                         for (my $i = 4; $i < $#field; $i++) {
1267                                                 my ($sort, $flag, $node, $ping) = $field[$i] =~ m{(\w)(\d)([-\w+])(,\d+)?};
1268                                                 $ping /= 10 if (defined $ping); 
1269                                         }
1270                                 }
1271                         }
1272                         
1273                         return;
1274                 }
1275         }
1276          
1277         # if get here then rebroadcast the thing with its Hop count decremented (if
1278         # there is one). If it has a hop count and it decrements to zero then don't
1279         # rebroadcast it.
1280         #
1281         # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
1282         #        REBROADCAST!!!!
1283         #
1284
1285         if (eph_dup($line)) {
1286                 dbg("PCPROT: Ephemeral dup, dropped") if isdbg('chanerr');
1287         } else {
1288                 unless ($self->{isolate}) {
1289                         DXChannel::broadcast_nodes($line, $self); # send it to everyone but me
1290                 }
1291         }
1292 }
1293
1294 #
1295 # This is called from inside the main cluster processing loop and is used
1296 # for despatching commands that are doing some long processing job
1297 #
1298 sub process
1299 {
1300         my $t = time;
1301         my @dxchan = DXChannel->get_all();
1302         my $dxchan;
1303         my $pc50s;
1304         
1305         # send out a pc50 on EVERY channel all at once
1306         if ($t >= $last_pc50 + $DXProt::pc50_interval) {
1307                 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
1308                 eph_dup($pc50s);
1309                 $last_pc50 = $t;
1310         }
1311
1312         foreach $dxchan (@dxchan) {
1313                 next unless $dxchan->is_node();
1314                 next if $dxchan == $main::me;
1315
1316                 # send the pc50 or PC90
1317                 if ($pc50s && $dxchan->user->wantpc90) {
1318                         $dxchan->send_route(\&pc90, 1, $main::me, 'T', @dxchan);
1319                 } else {
1320                         $dxchan->send($pc50s) if $pc50s;
1321                 }
1322                 
1323                 # send a ping out on this channel
1324                 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
1325                         if ($dxchan->{nopings} <= 0) {
1326                                 $dxchan->disconnect;
1327                         } else {
1328                                 addping($main::mycall, $dxchan->call);
1329                                 $dxchan->{nopings} -= 1;
1330                                 $dxchan->{lastping} = $t;
1331                         }
1332                 }
1333         }
1334
1335         # every ten seconds
1336         if ($t - $last10 >= 10) {       
1337                 # clean out ephemera 
1338
1339                 eph_clean();
1340
1341                 $last10 = $t;
1342         }
1343         
1344         if ($main::systime - 3600 > $last_hour) {
1345                 $last_hour = $main::systime;
1346         }
1347 }
1348
1349 #
1350 # finish up a pc context
1351 #
1352
1353 #
1354 # some active measures
1355 #
1356
1357
1358 sub send_dx_spot
1359 {
1360         my $self = shift;
1361         my $line = shift;
1362         my @dxchan = DXChannel->get_all();
1363         my $dxchan;
1364         
1365         # send it if it isn't the except list and isn't isolated and still has a hop count
1366         # taking into account filtering and so on
1367         foreach $dxchan (@dxchan) {
1368                 next if $dxchan == $main::me;
1369                 next if $dxchan == $self && $self->is_node;
1370                 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
1371         }
1372 }
1373
1374 sub dx_spot
1375 {
1376         my $self = shift;
1377         my $line = shift;
1378         my $isolate = shift;
1379         my ($filter, $hops);
1380
1381         if ($self->{spotsfilter}) {
1382                 ($filter, $hops) = $self->{spotsfilter}->it(@_);
1383                 return unless $filter;
1384         }
1385         send_prot_line($self, $filter, $hops, $isolate, $line);
1386 }
1387
1388 sub send_prot_line
1389 {
1390         my ($self, $filter, $hops, $isolate, $line) = @_;
1391         my $routeit;
1392         
1393         if ($hops) {
1394                 $routeit = $line;
1395                 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1396         } else {
1397                 $routeit = adjust_hops($self, $line);  # adjust its hop count by node name
1398                 return unless $routeit;
1399         }
1400         if ($filter) {
1401                 $self->send($routeit);
1402         } else {
1403                 $self->send($routeit) unless $self->{isolate} || $isolate;
1404         }
1405 }
1406
1407
1408 sub send_wwv_spot
1409 {
1410         my $self = shift;
1411         my $line = shift;
1412         my @dxchan = DXChannel->get_all();
1413         my $dxchan;
1414         my ($wwv_dxcc, $wwv_itu, $wwv_cq, $org_dxcc, $org_itu, $org_cq) = (0..0);
1415         my @dxcc = Prefix::extract($_[6]);
1416         if (@dxcc > 0) {
1417                 $wwv_dxcc = $dxcc[1]->dxcc;
1418                 $wwv_itu = $dxcc[1]->itu;
1419                 $wwv_cq = $dxcc[1]->cq;                                         
1420         }
1421         @dxcc = Prefix::extract($_[7]);
1422         if (@dxcc > 0) {
1423                 $org_dxcc = $dxcc[1]->dxcc;
1424                 $org_itu = $dxcc[1]->itu;
1425                 $org_cq = $dxcc[1]->cq;                                         
1426         }
1427         
1428         # send it if it isn't the except list and isn't isolated and still has a hop count
1429         # taking into account filtering and so on
1430         foreach $dxchan (@dxchan) {
1431                 next if $dxchan == $main::me;
1432                 next if $dxchan == $self && $self->is_node;
1433                 my $routeit;
1434                 my ($filter, $hops);
1435
1436                 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, $wwv_dxcc, $wwv_itu, $wwv_cq, $org_dxcc, $org_itu, $org_cq);
1437         }
1438         
1439 }
1440
1441 sub wwv
1442 {
1443         my $self = shift;
1444         my $line = shift;
1445         my $isolate = shift;
1446         my ($filter, $hops);
1447         
1448         if ($self->{wwvfilter}) {
1449                 ($filter, $hops) = $self->{wwvfilter}->it(@_);
1450                 return unless $filter;
1451         }
1452         send_prot_line($self, $filter, $hops, $isolate, $line)
1453 }
1454
1455 sub send_wcy_spot
1456 {
1457         my $self = shift;
1458         my $line = shift;
1459         my @dxchan = DXChannel->get_all();
1460         my $dxchan;
1461         my ($wcy_dxcc, $wcy_itu, $wcy_cq, $org_dxcc, $org_itu, $org_cq) = (0..0);
1462         my @dxcc = Prefix::extract($_[10]);
1463         if (@dxcc > 0) {
1464                 $wcy_dxcc = $dxcc[1]->dxcc;
1465                 $wcy_itu = $dxcc[1]->itu;
1466                 $wcy_cq = $dxcc[1]->cq;                                         
1467         }
1468         @dxcc = Prefix::extract($_[11]);
1469         if (@dxcc > 0) {
1470                 $org_dxcc = $dxcc[1]->dxcc;
1471                 $org_itu = $dxcc[1]->itu;
1472                 $org_cq = $dxcc[1]->cq;                                         
1473         }
1474         
1475         # send it if it isn't the except list and isn't isolated and still has a hop count
1476         # taking into account filtering and so on
1477         foreach $dxchan (@dxchan) {
1478                 next if $dxchan == $main::me;
1479                 next if $dxchan == $self;
1480
1481                 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, $wcy_dxcc, $wcy_itu, $wcy_cq, $org_dxcc, $org_itu, $org_cq);
1482         }
1483 }
1484
1485 sub wcy
1486 {
1487         my $self = shift;
1488         my $line = shift;
1489         my $isolate = shift;
1490         my ($filter, $hops);
1491
1492         if ($self->{wcyfilter}) {
1493                 ($filter, $hops) = $self->{wcyfilter}->it(@_);
1494                 return unless $filter;
1495         }
1496         send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
1497 }
1498
1499 # send an announce
1500 sub send_announce
1501 {
1502         my $self = shift;
1503         my $line = shift;
1504         my @dxchan = DXChannel->get_all();
1505         my $dxchan;
1506         my $target;
1507         my $to = 'To ';
1508         my $text = unpad($_[2]);
1509                                 
1510         if ($_[3] eq '*') {     # sysops
1511                 $target = "SYSOP";
1512         } elsif ($_[3] gt ' ') { # speciality list handling
1513                 my ($name) = split /\./, $_[3]; 
1514                 $target = "$name"; # put the rest in later (if bothered) 
1515         } 
1516         
1517         if ($_[5] eq '1') {
1518                 $target = "WX"; 
1519                 $to = '';
1520         }
1521         $target = "ALL" if !$target;
1522
1523
1524         # obtain country codes etc 
1525         my ($ann_dxcc, $ann_itu, $ann_cq, $org_dxcc, $org_itu, $org_cq) = (0..0);
1526         my @dxcc = Prefix::extract($_[0]);
1527         if (@dxcc > 0) {
1528                 $ann_dxcc = $dxcc[1]->dxcc;
1529                 $ann_itu = $dxcc[1]->itu;
1530                 $ann_cq = $dxcc[1]->cq;                                         
1531         }
1532         @dxcc = Prefix::extract($_[4]);
1533         if (@dxcc > 0) {
1534                 $org_dxcc = $dxcc[1]->dxcc;
1535                 $org_itu = $dxcc[1]->itu;
1536                 $org_cq = $dxcc[1]->cq;                                         
1537         }
1538
1539         if ($self->{inannfilter}) {
1540                 my ($filter, $hops) = 
1541                         $self->{inannfilter}->it(@_, $self->{call}, 
1542                                                                          $ann_dxcc, $ann_itu, $ann_cq,
1543                                                                          $org_dxcc, $org_itu, $org_cq);
1544                 unless ($filter) {
1545                         dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
1546                         return;
1547                 }
1548         }
1549
1550         if (AnnTalk::dup($_[0], $_[1], $_[2])) {
1551                 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
1552                 return;
1553         }
1554
1555         Log('ann', $target, $_[0], $text);
1556
1557         # send it if it isn't the except list and isn't isolated and still has a hop count
1558         # taking into account filtering and so on
1559         foreach $dxchan (@dxchan) {
1560                 next if $dxchan == $main::me;
1561                 next if $dxchan == $self && $self->is_node;
1562                 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call}, $ann_dxcc, $ann_itu, $ann_cq, $org_dxcc, $org_itu, $org_cq);
1563         }
1564 }
1565
1566 sub announce
1567 {
1568         my $self = shift;
1569         my $line = shift;
1570         my $isolate = shift;
1571         my $to = shift;
1572         my $target = shift;
1573         my $text = shift;
1574         my ($filter, $hops);
1575
1576         if ($self->{annfilter}) {
1577                 ($filter, $hops) = $self->{annfilter}->it(@_);
1578                 return unless $filter;
1579         }
1580         send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
1581 }
1582
1583
1584 sub send_local_config
1585 {
1586         my $self = shift;
1587         my $n;
1588         my @nodes;
1589         my @localnodes;
1590         my @remotenodes;
1591
1592         dbg('DXProt::send_local_config') if isdbg('trace');
1593         
1594         # send our nodes
1595         if ($self->{isolate}) {
1596                 @localnodes = ( $main::routeroot );
1597         } else {
1598                 # create a list of all the nodes that are not connected to this connection
1599                 # and are not themselves isolated, this to make sure that isolated nodes
1600         # don't appear outside of this node
1601                 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
1602                 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
1603                 my @intcalls = map { $_->nodes } @localnodes if @localnodes;
1604                 my $ref = Route::Node::get($self->{call});
1605                 my @rnodes = $ref->nodes;
1606                 for my $n (@intcalls) {
1607                         push @remotenodes, Route::Node::get($n) unless grep $n eq $_, @rnodes;
1608                 }
1609                 unshift @localnodes, $main::routeroot;
1610         }
1611         
1612
1613         send_route($self, \&pc19, scalar(@localnodes)+scalar(@remotenodes), @localnodes, @remotenodes);
1614         
1615         # get all the users connected on the above nodes and send them out
1616         foreach $n (@localnodes, @remotenodes) {
1617                 if ($n) {
1618                         send_route($self, \&pc16, 1, $n, map {my $r = Route::User::get($_); $r ? ($r) : ()} $n->users);
1619                 } else {
1620                         dbg("sent a null value") if isdbg('chanerr');
1621                 }
1622         }
1623         $self->send_route(\&pc90, 1, $main::me, 'T', DXChannel::get_all()) if $self->user->wantpc90;
1624 }
1625
1626 #
1627 # route a message down an appropriate interface for a callsign
1628 #
1629 # is called route(to, pcline);
1630 #
1631 sub route
1632 {
1633         my ($self, $call, $line) = @_;
1634
1635         if (ref $self && $call eq $self->{call}) {
1636                 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
1637                 return;
1638         }
1639
1640         # always send it down the local interface if available
1641         my $dxchan = DXChannel->get($call);
1642         unless ($dxchan) {
1643                 my $cl = Route::get($call);
1644                 $dxchan = $cl->dxchan if $cl;
1645                 if (ref $dxchan) {
1646                         if (ref $self && $dxchan eq $self) {
1647                                 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
1648                                 return;
1649                         }
1650                 }
1651         }
1652         if ($dxchan) {
1653                 my $routeit = adjust_hops($dxchan, $line);   # adjust its hop count by node name
1654                 if ($routeit) {
1655                         $dxchan->send($routeit) unless $dxchan == $main::me;
1656                 }
1657         } else {
1658                 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
1659         }
1660 }
1661
1662 #
1663 # obtain the hops from the list for this callsign and pc no 
1664 #
1665
1666 sub get_hops
1667 {
1668         my $pcno = shift;
1669         my $hops = $DXProt::hopcount{$pcno};
1670         $hops = $DXProt::def_hopcount if !$hops;
1671         return "H$hops";       
1672 }
1673
1674
1675 # adjust the hop count on a per node basis using the user loadable 
1676 # hop table if available or else decrement an existing one
1677 #
1678
1679 sub adjust_hops
1680 {
1681         my $self = shift;
1682         my $s = shift;
1683         my $call = $self->{call};
1684         my $hops;
1685         
1686         if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
1687                 my ($pcno) = $s =~ /^PC(\d\d)/o;
1688                 confess "$call called adjust_hops with '$s'" unless $pcno;
1689                 my $ref = $nodehops{$call} if %nodehops;
1690                 if ($ref) {
1691                         my $newhops = $ref->{$pcno};
1692                         return "" if defined $newhops && $newhops == 0;
1693                         $newhops = $ref->{default} unless $newhops;
1694                         return "" if defined $newhops && $newhops == 0;
1695                         $newhops = $hops if !$newhops;
1696                         $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1697                 } else {
1698                         # simply decrement it
1699                         $hops--;
1700                         return "" if !$hops;
1701                         $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
1702                 }
1703         }
1704         return $s;
1705 }
1706
1707
1708 # load hop tables
1709 #
1710 sub load_hops
1711 {
1712         my $self = shift;
1713         return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
1714         do "$main::data/hop_table.pl";
1715         return $@ if $@;
1716         return 0;
1717 }
1718
1719
1720 # add a ping request to the ping queues
1721 sub addping
1722 {
1723         my ($from, $to) = @_;
1724         my $ref = $pings{$to} || [];
1725         my $r = {};
1726         $r->{call} = $from;
1727         $r->{t} = [ gettimeofday ];
1728         route(undef, $to, pc51($to, $main::mycall, 1));
1729         push @$ref, $r;
1730         $pings{$to} = $ref;
1731 }
1732
1733 sub process_rcmd
1734 {
1735         my ($self, $tonode, $fromnode, $user, $cmd) = @_;
1736         if ($tonode eq $main::mycall) {
1737                 my $ref = DXUser->get_current($fromnode);
1738                 my $cref = Route::Node::get($fromnode);
1739                 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
1740                 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
1741                         if ($ref->{priv}) {             # you have to have SOME privilege, the commands have further filtering
1742                                 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
1743                                 my $oldpriv = $self->{priv};
1744                                 $self->{priv} = $ref->{priv}; # assume the user's privilege level
1745                                 my @in = (DXCommandmode::run_cmd($self, $cmd));
1746                                 $self->{priv} = $oldpriv;
1747                                 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
1748                                 delete $self->{remotecmd};
1749                         } else {
1750                                 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
1751                         }
1752                 } else {
1753                         $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
1754                 }
1755         } else {
1756                 my $ref = DXUser->get_current($tonode);
1757                 if ($ref && $ref->is_clx) {
1758                         $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
1759                 } else {
1760                         $self->route($tonode, pc34($fromnode, $tonode, $cmd));
1761                 }
1762         }
1763 }
1764
1765 sub process_rcmd_reply
1766 {
1767         my ($self, $tonode, $fromnode, $user, $line) = @_;
1768         if ($tonode eq $main::mycall) {
1769                 my $s = $rcmds{$fromnode};
1770                 if ($s) {
1771                         my $dxchan = DXChannel->get($s->{call});
1772                         my $ref = $user eq $tonode ? $dxchan : (DXChannel->get($user) || $dxchan);
1773                         $ref->send($line) if $ref;
1774                         delete $rcmds{$fromnode} if !$dxchan;
1775                 } else {
1776                         # send unsolicited ones to the sysop
1777                         my $dxchan = DXChannel->get($main::myalias);
1778                         $dxchan->send($line) if $dxchan;
1779                 }
1780         } else {
1781                 my $ref = DXUser->get_current($tonode);
1782                 if ($ref && $ref->is_clx) {
1783                         $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
1784                 } else {
1785                         $self->route($tonode, pc35($fromnode, $tonode, $line));
1786                 }
1787         }
1788 }
1789
1790 sub send_rcmd_reply
1791 {
1792         my $self = shift;
1793         my $tonode = shift;
1794         my $fromnode = shift;
1795         my $user = shift;
1796         while (@_) {
1797                 my $line = shift;
1798                 $line =~ s/\s*$//;
1799                 Log('rcmd', 'out', $fromnode, $line);
1800                 if ($self->is_clx) {
1801                         $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
1802                 } else {
1803                         $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
1804                 }
1805         }
1806 }
1807
1808 # add a rcmd request to the rcmd queues
1809 sub addrcmd
1810 {
1811         my ($self, $to, $cmd) = @_;
1812
1813         my $r = {};
1814         $r->{call} = $self->{call};
1815         $r->{t} = $main::systime;
1816         $r->{cmd} = $cmd;
1817         $rcmds{$to} = $r;
1818         
1819         my $ref = Route::Node::get($to);
1820         my $dxchan = $ref->dxchan;
1821         if ($dxchan && $dxchan->is_clx) {
1822                 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1823         } else {
1824                 route(undef, $to, pc34($main::mycall, $to, $cmd));
1825         }
1826 }
1827
1828 sub disconnect
1829 {
1830         my $self = shift;
1831         my $pc39flag = shift;
1832         my $call = $self->call;
1833
1834         return if $self->{disconnecting}++;
1835         
1836         unless ($pc39flag && $pc39flag == 1) {
1837                 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1838         }
1839
1840         # get rid of any PC16 and 19s
1841         eph_del_regex("^PC16\\^$call");
1842         eph_del_regex("^PC19\\^.*$call");
1843
1844         # do routing stuff
1845         my $node = Route::Node::get($call);
1846         my @rout;
1847         if ($node) {
1848                 @rout = $node->del($main::routeroot);
1849         }
1850         
1851         # unbusy and stop and outgoing mail
1852         my $mref = DXMsg::get_busy($call);
1853         $mref->stop_msg($call) if $mref;
1854         
1855         # broadcast to all other nodes that all the nodes connected to via me are gone
1856         unless ($pc39flag && $pc39flag == 2) {
1857                 $self->route_pc21(@rout) if @rout;
1858         }
1859
1860         # remove outstanding pings
1861         delete $pings{$call};
1862         
1863         # I was the last node visited
1864     $self->user->node($main::mycall);
1865
1866         # send info to all logged in thingies
1867         $self->tell_login('logoutn');
1868
1869         Log('DXProt', $call . " Disconnected");
1870
1871         $self->SUPER::disconnect;
1872 }
1873
1874
1875
1876 # send a talk message to this thingy
1877 #
1878 sub talk
1879 {
1880         my ($self, $from, $to, $via, $line, $origin) = @_;
1881         
1882         $line =~ s/\^/\\5E/g;                   # remove any ^ characters
1883         $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
1884         Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
1885 }
1886
1887 # send it if it isn't the except list and isn't isolated and still has a hop count
1888 # taking into account filtering and so on
1889 sub send_route
1890 {
1891         my $self = shift;
1892         my $generate = shift;
1893         my $no = shift;     # the no of things to filter on 
1894         my $routeit;
1895         my ($filter, $hops);
1896         my @rin;
1897         
1898         for (; @_ && $no; $no--) {
1899                 my $r = shift;
1900                 
1901                 if (!$self->{isolate} && $self->{routefilter}) {
1902                         $filter = undef;
1903                         if ($r) {
1904                                 ($filter, $hops) = $self->{routefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq);
1905                                 if ($filter) {
1906                                         push @rin, $r;
1907                                 } else {
1908                                         dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
1909                                 }
1910                         } else {
1911                                 dbg("was sent a null value") if isdbg('chanerr');
1912                         }
1913                 } else {
1914                         push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
1915                 }
1916         }
1917         if (@rin) {
1918                 foreach my $line (&$generate(@rin, @_)) {
1919                         if ($hops) {
1920                                 $routeit = $line;
1921                                 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1922                         } else {
1923                                 $routeit = adjust_hops($self, $line);  # adjust its hop count by node name
1924                                 next unless $routeit;
1925                         }
1926                         $self->send($routeit);
1927                 }
1928         }
1929 }
1930
1931 sub broadcast_route
1932 {
1933         my $self = shift;
1934         my $generate = shift;
1935         my @dxchan = DXChannel::get_all_nodes();
1936         my $dxchan;
1937         my $line;
1938         
1939         unless ($self->{isolate}) {
1940                 foreach $dxchan (@dxchan) {
1941                         next if $dxchan == $self;
1942                         next if $dxchan == $main::me;
1943                         $dxchan->send_route($generate, @_);
1944                 }
1945         }
1946 }
1947
1948 sub route_pc16
1949 {
1950         my $self = shift;
1951         broadcast_route($self, \&pc16, 1, @_);
1952 }
1953
1954 sub route_pc17
1955 {
1956         my $self = shift;
1957         broadcast_route($self, \&pc17, 1, @_);
1958 }
1959
1960 sub route_pc19
1961 {
1962         my $self = shift;
1963         broadcast_route($self, \&pc19, scalar @_, @_);
1964 }
1965
1966 sub route_pc21
1967 {
1968         my $self = shift;
1969         broadcast_route($self, \&pc21, scalar @_, @_);
1970 }
1971
1972 sub route_pc24
1973 {
1974         my $self = shift;
1975         broadcast_route($self, \&pc24, 1, @_);
1976 }
1977
1978 sub route_pc41
1979 {
1980         my $self = shift;
1981         broadcast_route($self, \&pc41, 1, @_);
1982 }
1983
1984 sub route_pc50
1985 {
1986         my $self = shift;
1987         broadcast_route($self, \&pc50, 1, @_);
1988 }
1989
1990 sub route_pc90
1991 {
1992         my $self = shift;
1993         broadcast_route($self, \&pc90, 1, @_);
1994 }
1995
1996 sub in_filter_route
1997 {
1998         my $self = shift;
1999         my $r = shift;
2000         my ($filter, $hops) = (1, 1);
2001         
2002         if ($self->{inroutefilter}) {
2003                 ($filter, $hops) = $self->{inroutefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq);
2004                 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
2005         }
2006         return $filter;
2007 }
2008
2009 sub eph_dup
2010 {
2011         my $s = shift;
2012         my $t = shift || $eph_restime;
2013         my $r;
2014
2015         # chop the end off
2016         $s =~ s/\^H\d\d?\^?\~?$//;
2017         $r = 1 if exists $eph{$s};    # pump up the dup if it keeps circulating
2018         $eph{$s} = $main::systime + $t;
2019         return $r;
2020 }
2021
2022 sub eph_del_regex
2023 {
2024         my $regex = shift;
2025         my ($key, $val);
2026         while (($key, $val) = each %eph) {
2027                 if ($key =~ m{$regex}) {
2028                         delete $eph{$key};
2029                 }
2030         }
2031 }
2032
2033 sub eph_clean
2034 {
2035         my ($key, $val);
2036         
2037         while (($key, $val) = each %eph) {
2038                 if ($main::systime >= $val) {
2039                         delete $eph{$key};
2040                 }
2041         }
2042 }
2043
2044 sub eph_list
2045 {
2046         my ($key, $val);
2047         my @out;
2048
2049         while (($key, $val) = each %eph) {
2050                 push @out, $key, $val;
2051         }
2052         return @out;
2053 }
2054
2055 sub run_cmd
2056 {
2057         goto &DXCommandmode::run_cmd;
2058 }
2059 1;
2060 __END__