]> scm.dxcluster.org Git - spider.git/blob - perl/DXProt.pm
remove dk0wcy ann processing
[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 DXCluster;
19 use DXProtVars;
20 use DXCommandmode;
21 use DXLog;
22 use Spot;
23 use DXProtout;
24 use DXDebug;
25 use Filter;
26 use Local;
27 use DXDb;
28 use AnnTalk;
29 use Geomag;
30 use WCY;
31 use Time::HiRes qw(gettimeofday tv_interval);
32
33 use strict;
34 use vars qw($me $pc11_max_age $pc23_max_age
35                         $last_hour %pings %rcmds
36                         %nodehops @baddx $baddxfn 
37                         $allowzero $decode_dk0wcy);
38
39 $me = undef;                                    # the channel id for this cluster
40 $pc11_max_age = 1*3600;                 # the maximum age for an incoming 'real-time' pc11
41 $pc23_max_age = 1*3600;                 # the maximum age for an incoming 'real-time' pc23
42
43 $last_hour = time;                              # last time I did an hourly periodic update
44 %pings = ();                    # outstanding ping requests outbound
45 %rcmds = ();                    # outstanding rcmd requests outbound
46 %nodehops = ();                 # node specific hop control
47 @baddx = ();                    # list of illegal spotted callsigns
48
49
50 $baddxfn = "$main::data/baddx.pl";
51
52 sub init
53 {
54         my $user = DXUser->get($main::mycall);
55         $DXProt::myprot_version += $main::version*100;
56         $me = DXProt->new($main::mycall, 0, $user); 
57         $me->{here} = 1;
58         $me->{state} = "indifferent";
59         do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
60         confess $@ if $@;
61         #  $me->{sort} = 'M';    # M for me
62
63         # now prime the spot and wwv  duplicates file with data
64     my @today = Julian::unixtoj(time);
65         for (Spot::readfile(@today), Spot::readfile(Julian::sub(@today, 1))) {
66                 Spot::dup(@{$_}[0..3]);
67         }
68         for (Geomag::readfile(time)) {
69                 Geomag::dup(@{$_}[1..5]);
70         }
71
72         # load the baddx file
73         do "$baddxfn" if -e "$baddxfn";
74         print "$@\n" if $@;
75 }
76
77 #
78 # obtain a new connection this is derived from dxchannel
79 #
80
81 sub new 
82 {
83         my $self = DXChannel::alloc(@_);
84         return $self;
85 }
86
87 # this is how a pc connection starts (for an incoming connection)
88 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
89 # all the crap that comes between).
90 sub start
91 {
92         my ($self, $line, $sort) = @_;
93         my $call = $self->{call};
94         my $user = $self->{user};
95         
96         # remember type of connection
97         $self->{consort} = $line;
98         $self->{outbound} = $sort eq 'O';
99         $self->{priv} = $user->priv;
100         $self->{lang} = $user->lang;
101         $self->{isolate} = $user->{isolate};
102         $self->{consort} = $line;       # save the connection type
103         $self->{here} = 1;
104
105         # get the INPUT filters (these only pertain to Clusters)
106         $self->{inspotfilter} = Filter::read_in('spots', $call, 1);
107         $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1);
108         $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1);
109         $self->{inannfilter} = Filter::read_in('ann', $call, 1);
110         
111         # set unbuffered and no echo
112         $self->send_now('B',"0");
113         $self->send_now('E',"0");
114         
115         # ping neighbour node stuff
116         my $ping = $user->pingint;
117         $ping = 5*60 unless defined $ping;
118         $self->{pingint} = $ping;
119         $self->{nopings} = $user->nopings || 2;
120         $self->{pingtime} = [ ];
121         $self->{pingave} = 0;
122
123         # send initialisation string
124         unless ($self->{outbound}) {
125                 $self->send(pc38()) if DXNode->get_all();
126                 $self->send(pc18());
127                 $self->{lastping} = $main::systime;
128         } else {
129                 # remove from outstanding connects queue
130                 @main::outstanding_connects = grep {$_->{call} ne $call} @main::outstanding_connects;
131                 $self->{lastping} = $main::systime + $self->pingint / 2;
132         }
133         $self->state('init');
134         $self->pc50_t(time);
135
136         # send info to all logged in thingies
137         $self->tell_login('loginn');
138
139         Log('DXProt', "$call connected");
140 }
141
142 #
143 # This is the normal pcxx despatcher
144 #
145 sub normal
146 {
147         my ($self, $line) = @_;
148         my @field = split /\^/, $line;
149         pop @field if $field[-1] eq '~';
150         
151 #       print join(',', @field), "\n";
152                                                 
153         # ignore any lines that don't start with PC
154         return if !$field[0] =~ /^PC/;
155         
156         # process PC frames
157         my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
158         return unless $pcno;
159         return if $pcno < 10 || $pcno > 99;
160
161         # dump bad protocol messages unless it is a PC29
162         if ($line =~ /\%[0-9A-F][0-9A-F]/o && $pcno != 29) {
163                 dbg('chan', "CORRUPT protocol message - dumped");
164                 return;
165         }
166
167         # local processing 1
168         my $pcr;
169         eval {
170                 $pcr = Local::pcprot($self, $pcno, @field);
171         };
172 #       dbg('local', "Local::pcprot error $@") if $@;
173         return if $pcr;
174         
175  SWITCH: {
176                 if ($pcno == 10) {              # incoming talk
177                         
178                         # is it for me or one of mine?
179                         my $call = ($field[5] gt ' ') ? $field[5] : $field[2];
180                         if ($call eq $main::mycall || grep $_ eq $call, DXChannel::get_all_user_calls()) {
181                                 
182                                 # yes, it is
183                                 my $text = unpad($field[3]);
184                                 Log('talk', $call, $field[1], $field[6], $text);
185                                 $call = $main::myalias if $call eq $main::mycall;
186                                 my $ref = DXChannel->get($call);
187                                 $ref->send("$call de $field[1]: $text") if $ref && $ref->{talk};
188                         } else {
189                                 $self->route($field[2], $line); # relay it on its way
190                         }
191                         return;
192                 }
193                 
194                 if ($pcno == 11 || $pcno == 26) { # dx spot
195
196                         # route 'foreign' pc26s 
197                         if ($pcno == 26) {
198                                 if ($field[7] ne $main::mycall) {
199                                         $self->route($field[7], $line);
200                                         return;
201                                 }
202                         }
203                         
204                         # if this is a 'nodx' node then ignore it
205                         if (grep $field[7] =~ /^$_/,  @DXProt::nodx_node) {
206                                 dbg('chan', "Bad DXNode, dropped");
207                                 return;
208                         }
209                         
210                         # convert the date to a unix date
211                         my $d = cltounix($field[3], $field[4]);
212                         # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
213                         if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
214                                 dbg('chan', "Spot ignored, invalid date or out of range ($field[3] $field[4])\n");
215                                 return;
216                         }
217
218                         # is it 'baddx'
219                         if (grep $field[2] eq $_, @baddx) {
220                                 dbg('chan', "Bad DX spot, ignored");
221                                 return;
222                         }
223
224                         # are any of the crucial fields invalid?
225             if ($field[2] =~ /[a-z]/ || $field[6] =~ /[a-z]/ || $field[7] =~ /[a-z]/) {
226                                 dbg('chan', "Spot contains lower case callsigns, rejected");
227                                 return;
228                         }
229                         
230                         # do some de-duping
231                         if (Spot::dup($field[1], $field[2], $d, $field[5])) {
232                                 dbg('chan', "Duplicate Spot ignored\n");
233                                 return;
234                         }
235                         
236                         my @spot = Spot::add($field[1], $field[2], $d, $field[5], $field[6], $field[7]);
237
238             #
239                         # @spot at this point contains:-
240             # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
241                         # then  spotted itu, spotted cq, spotters itu, spotters cq
242                         # you should be able to route on any of these
243             #
244                         
245                         # local processing 
246                         my $r;
247                         eval {
248                                 $r = Local::spot($self, @spot);
249                         };
250 #                       dbg('local', "Local::spot1 error $@") if $@;
251                         return if $r;
252
253                         # DON'T be silly and send on PC26s!
254                         return if $pcno == 26;
255
256                         # send out the filtered spots
257                         send_dx_spot($self, $line, @spot) if @spot;
258                         return;
259                 }
260                 
261                 if ($pcno == 12) {              # announces
262                         # announce duplicate checking
263                         if (AnnTalk::dup($field[1], $field[2], $field[3])) {
264                                 dbg('chan', "Duplicate Announce ignored\n");
265                                 return;
266                         }
267                         
268                         if ($field[2] eq '*' || $field[2] eq $main::mycall) {
269                                 
270                                 # global ann filtering on INPUT
271                                 if ($self->{inannfilter}) {
272                                         my ($filter, $hops) = Filter::it($self->{inannfilter}, @field[1..6], $self->{call} );
273                                         unless ($filter) {
274                                                 dbg('chan', "Rejected by filter");
275                                                 return;
276                                         }
277                                 }
278
279                                 # send it
280                                 $self->send_announce($line, @field[1..6]);
281                         } else {
282                                 $self->route($field[2], $line);
283                         }
284                         
285                         return;
286                 }
287                 
288                 if ($pcno == 13) {
289                         last SWITCH;
290                 }
291                 if ($pcno == 14) {
292                         last SWITCH;
293                 }
294                 if ($pcno == 15) {
295                         last SWITCH;
296                 }
297                 
298                 if ($pcno == 16) {              # add a user
299                         my $node = DXCluster->get_exact($field[1]); 
300                         my $dxchan;
301                         if (!$node && ($dxchan = DXChannel->get($field[1]))) {
302                                 # add it to the node table if it isn't present and it's
303                                 # connected locally
304                                 $node = DXNode->new($dxchan, $field[1], 0, 1, 5400);
305                                 broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
306                                 
307                         }
308                         return unless $node; # ignore if havn't seen a PC19 for this one yet
309                         return unless $node->isa('DXNode');
310                         if ($node->dxchan != $self) {
311                                 dbg('chan', "LOOP: $field[1] came in on wrong channel");
312                                 return;
313                         }
314                         if (($dxchan = DXChannel->get($field[1])) && $dxchan != $self) {
315                                 dbg('chan', "LOOP: $field[1] connected locally");
316                                 return;
317                         }
318                         my $i;
319                                                 
320                         for ($i = 2; $i < $#field; $i++) {
321                                 my ($call, $confmode, $here) = $field[$i] =~ /^(\S+) (\S) (\d)/o;
322                                 next if !$call || length $call < 3 || length $call > 8;
323                                 next if !$confmode;
324                                 $call = uc $call;
325                                 next if DXCluster->get_exact($call); # we already have this (loop?)
326                                 
327                                 $confmode = $confmode eq '*';
328                                 DXNodeuser->new($self, $node, $call, $confmode, $here);
329                                 
330                                 # add this station to the user database, if required
331                                 $call =~ s/-\d+$//o;        # remove ssid for users
332                                 my $user = DXUser->get_current($call);
333                                 $user = DXUser->new($call) if !$user;
334                                 $user->homenode($node->call) if !$user->homenode;
335                                 $user->node($node->call);
336                                 $user->lastin($main::systime) unless DXChannel->get($call);
337                                 $user->put;
338                         }
339                         
340                         # queue up any messages (look for privates only)
341                         DXMsg::queue_msg(1) if $self->state eq 'normal';     
342                         last SWITCH;
343                 }
344                 
345                 if ($pcno == 17) {              # remove a user
346                         my $node = DXCluster->get_exact($field[2]);
347                         my $dxchan;
348                         if (!$node && ($dxchan = DXChannel->get($field[2]))) {
349                                 # add it to the node table if it isn't present and it's
350                                 # connected locally
351                                 $node = DXNode->new($dxchan, $field[2], 0, 1, 5400);
352                                 broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
353                                 return;
354                         }
355                         return unless $node;
356                         return unless $node->isa('DXNode');
357                         if ($node->dxchan != $self) {
358                                 dbg('chan', "LOOP: $field[2] came in on wrong channel");
359                                 return;
360                         }
361                         if (($dxchan = DXChannel->get($field[2])) && $dxchan != $self) {
362                                 dbg('chan', "LOOP: $field[2] connected locally");
363                                 return;
364                         }
365                         my $ref = DXCluster->get_exact($field[1]);
366                         $ref->del() if $ref;
367                         last SWITCH;
368                 }
369                 
370                 if ($pcno == 18) {              # link request
371                         $self->state('init');   
372
373                         # first clear out any nodes on this dxchannel
374                         my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
375                         foreach my $node (@gonenodes) {
376                                 next if $node->dxchan == $DXProt::me;
377                                 broadcast_ak1a(pc21($node->call, 'Gone, re-init') , $self) unless $self->{isolate}; 
378                                 $node->del();
379                         }
380                         $self->send_local_config();
381                         $self->send(pc20());
382                         return;             # we don't pass these on
383                 }
384                 
385                 if ($pcno == 19) {              # incoming cluster list
386                         my $i;
387                         my $newline = "PC19^";
388                         for ($i = 1; $i < $#field-1; $i += 4) {
389                                 my $here = $field[$i];
390                                 my $call = uc $field[$i+1];
391                                 my $confmode = $field[$i+2];
392                                 my $ver = $field[$i+3];
393
394                                 $ver = 5400 if !$ver && $allowzero;
395                                 
396                                 # now check the call over
397                                 my $node = DXCluster->get_exact($call);
398                                 if ($node) {
399                                         my $dxchan;
400                                         if (($dxchan = DXChannel->get($call)) && $dxchan != $self) {
401                                                 dbg('chan', "LOOP: $call connected locally");
402                                         }
403                                     if ($node->dxchan != $self) {
404                                                 dbg('chan', "LOOP: $call come in on wrong channel");
405                                                 next;
406                                         }
407                                         dbg('chan', "already have $call");
408                                         next;
409                                 }
410                                 
411                                 # check for sane parameters
412                                 next if $ver < 5000; # only works with version 5 software
413                                 next if length $call < 3; # min 3 letter callsigns
414
415                                 # add it to the nodes table and outgoing line
416                                 $newline .= "$here^$call^$confmode^$ver^";
417                                 DXNode->new($self, $call, $confmode, $here, $ver);
418                                 
419                                 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
420                                 my $mref = DXMsg::get_busy($call);
421                                 $mref->stop_msg($call) if $mref;
422                                 
423                                 # add this station to the user database, if required (don't remove SSID from nodes)
424                                 my $user = DXUser->get_current($call);
425                                 if (!$user) {
426                                         $user = DXUser->new($call);
427                                         $user->sort('A');
428                                         $user->priv(1);                   # I have relented and defaulted nodes
429                                         $self->{priv} = 1;                # to user RCMDs allowed
430                                         $user->homenode($call);
431                                         $user->node($call);
432                                 }
433                                 $user->lastin($main::systime) unless DXChannel->get($call);
434                                 $user->put;
435                         }
436                         
437                         return if $newline eq "PC19^";
438
439                         # add hop count 
440                         $newline .=  get_hops(19) . "^";
441                         $line = $newline;
442                         last SWITCH;
443                 }
444                 
445                 if ($pcno == 20) {              # send local configuration
446                         $self->send_local_config();
447                         $self->send(pc22());
448                         $self->state('normal');
449                         return;
450                 }
451                 
452                 if ($pcno == 21) {              # delete a cluster from the list
453                         my $call = uc $field[1];
454                         if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
455                                 my $node = DXCluster->get_exact($call);
456                                 if ($node) {
457                                         if ($node->dxchan != $self) {
458                                                 dbg('chan', "LOOP: $call come in on wrong channel");
459                                                 return;
460                                         }
461                                         my $dxchan;
462                                         if (($dxchan = DXChannel->get($call)) && $dxchan != $self) {
463                                                 dbg('chan', "LOOP: $call connected locally");
464                                                 return;
465                                         }
466                                         $node->del();
467                                 } else {
468                                         dbg('chan', "$call not in table, dropped");
469                                         return;
470                                 }
471                         }
472                         last SWITCH;
473                 }
474                 
475                 if ($pcno == 22) {
476                         $self->state('normal');
477                         return;
478                 }
479                                 
480                 if ($pcno == 23 || $pcno == 27) { # WWV info
481                         
482                         # route 'foreign' pc27s 
483                         if ($pcno == 27) {
484                                 if ($field[8] ne $main::mycall) {
485                                         $self->route($field[8], $line);
486                                         return;
487                                 }
488                         }
489
490                         # do some de-duping
491                         my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
492                         my $sfi = unpad($field[3]);
493                         my $k = unpad($field[4]);
494                         my $i = unpad($field[5]);
495                         my ($r) = $field[6] =~ /R=(\d+)/;
496                         $r = 0 unless $r;
497                         if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
498                                 dbg('chan', "WWV Date ($field[1] $field[2]) out of range");
499                                 return;
500                         }
501                         if (Geomag::dup($d,$sfi,$k,$i,$field[6])) {
502                                 dbg('chan', "Dup WWV Spot ignored\n");
503                                 return;
504                         }
505                         $field[7] =~ s/-\d+$//o;            # remove spotter's ssid
506                 
507                         my $wwv = Geomag::update($d, $field[2], $sfi, $k, $i, @field[6..8], $r);
508
509                         my $rep;
510                         eval {
511                                 $rep = Local::wwv($self, $field[1], $field[2], $sfi, $k, $i, @field[6..8], $r);
512                         };
513 #                       dbg('local', "Local::wwv2 error $@") if $@;
514                         return if $rep;
515
516                         # DON'T be silly and send on PC27s!
517                         return if $pcno == 27;
518
519                         # broadcast to the eager world
520                         send_wwv_spot($self, $line, $d, $field[2], $sfi, $k, $i, @field[6..8]);
521                         return;
522                 }
523                 
524                 if ($pcno == 24) {              # set here status
525                         my $call = uc $field[1];
526                         my $ref = DXCluster->get_exact($call);
527                         $ref->here($field[2]) if $ref;
528                         last SWITCH;
529                 }
530                 
531                 if ($pcno == 25) {      # merge request
532                         if ($field[1] ne $main::mycall) {
533                                 $self->route($field[1], $line);
534                                 return;
535                         }
536                         if ($field[2] eq $main::mycall) {
537                                 dbg('chan', "Trying to merge to myself, ignored");
538                                 return;
539                         }
540
541                         Log('DXProt', "Merge request for $field[3] spots and $field[4] WWV from $field[1]");
542                         
543                         # spots
544                         if ($field[3] > 0) {
545                                 my @in = reverse Spot::search(1, undef, undef, 0, $field[3]);
546                                 my $in;
547                                 foreach $in (@in) {
548                                         $self->send(pc26(@{$in}[0..4], $field[2]));
549                                 }
550                         }
551
552                         # wwv
553                         if ($field[4] > 0) {
554                                 my @in = reverse Geomag::search(0, $field[4], time, 1);
555                                 my $in;
556                                 foreach $in (@in) {
557                                         $self->send(pc27(@{$in}[0..5], $field[2]));
558                                 }
559                         }
560                         return;
561                 }
562
563                 if (($pcno >= 28 && $pcno <= 33) || $pcno == 40 || $pcno == 42 || $pcno == 49) { # mail/file handling
564                         if ($pcno == 49 || $field[1] eq $main::mycall) {
565                                 DXMsg::process($self, $line);
566                         } else {
567                                 $self->route($field[1], $line);
568                         }
569                         return;
570                 }
571                 
572                 if ($pcno == 34 || $pcno == 36) { # remote commands (incoming)
573                         if ($field[1] eq $main::mycall) {
574                                 my $ref = DXUser->get_current($field[2]);
575                                 my $cref = DXCluster->get($field[2]);
576                                 Log('rcmd', 'in', $ref->{priv}, $field[2], $field[3]);
577                                 unless ($field[3] =~ /rcmd/i || !$cref || !$ref || $cref->mynode->call ne $ref->homenode) {    # not allowed to relay RCMDS!
578                                         if ($ref->{priv}) {     # you have to have SOME privilege, the commands have further filtering
579                                                 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
580                                                 my $oldpriv = $self->{priv};
581                                                 $self->{priv} = $ref->{priv};     # assume the user's privilege level
582                                                 my @in = (DXCommandmode::run_cmd($self, $field[3]));
583                                                 $self->{priv} = $oldpriv;
584                                                 for (@in) {
585                                                         s/\s*$//og;
586                                                         $self->send(pc35($main::mycall, $field[2], "$main::mycall:$_"));
587                                                         Log('rcmd', 'out', $field[2], $_);
588                                                 }
589                                                 delete $self->{remotecmd};
590                                         } else {
591                                                 $self->send(pc35($main::mycall, $field[2], "$main::mycall:sorry...!"));
592                                         }
593                                 } else {
594                                         $self->send(pc35($main::mycall, $field[2], "$main::mycall:your attempt is logged, Tut tut tut...!"));
595                                 }
596                         } else {
597                                 my $ref = DXUser->get_current($field[1]);
598                                 if ($ref && $ref->is_clx) {
599                                         route($field[1], pc84($field[2], $field[1], $field[2], $field[3]));
600                                 } else {
601                                         $self->route($field[1], $line);
602                                 }
603                         }
604                         return;
605                 }
606                 
607                 if ($pcno == 35) {              # remote command replies
608                         if ($field[1] eq $main::mycall) {
609                                 my $s = $rcmds{$field[2]};
610                                 if ($s) {
611                                         my $dxchan = DXChannel->get($s->{call});
612                                         $dxchan->send($field[3]) if $dxchan;
613                                         delete $rcmds{$field[2]} if !$dxchan;
614                                 }
615                         } else {
616                                 my $ref = DXUser->get_current($field[1]);
617                                 if ($ref && $ref->is_clx) {
618                                         route($field[1], pc85($field[2], $field[1], $field[2], $field[3]));
619                                 } else {
620                                         $self->route($field[1], $line);
621                                 }
622                         }
623                         return;
624                 }
625                 
626                 # for pc 37 see 44 onwards
627
628                 if ($pcno == 38) {              # node connected list from neighbour
629                         return;
630                 }
631                 
632                 if ($pcno == 39) {              # incoming disconnect
633                         $self->disconnect(1);
634                         return;
635                 }
636                 
637                 if ($pcno == 41) {              # user info
638                         # add this station to the user database, if required
639                         my $user = DXUser->get_current($field[1]);
640                         if (!$user) {
641                                 # then try without an SSID
642                                 $field[1] =~ s/-\d+$//o;
643                                 $user = DXUser->get_current($field[1]);
644                         }
645                         $user = DXUser->new($field[1]) if !$user;
646                         
647                         if ($field[2] == 1) {
648                                 $user->name($field[3]);
649                         } elsif ($field[2] == 2) {
650                                 $user->qth($field[3]);
651                         } elsif ($field[2] == 3) {
652                                 my ($lat, $long) = DXBearing::stoll($field[3]);
653                                 $user->lat($lat);
654                                 $user->long($long);
655                         } elsif ($field[2] == 4) {
656                                 $user->homenode($field[3]);
657                         }
658                         $user->put;
659                         last SWITCH;
660                 }
661                 if ($pcno == 43) {
662                         last SWITCH;
663                 }
664                 if ($pcno == 37 || $pcno == 44 || $pcno == 45 || $pcno == 46 || $pcno == 47 || $pcno == 48) {
665                         DXDb::process($self, $line);
666                         return;
667                 }
668                 
669                 if ($pcno == 50) {              # keep alive/user list
670                         my $node = DXCluster->get_exact($field[1]);
671                         if ($node) {
672                                 return unless $node->isa('DXNode');
673                                 return unless $node->dxchan == $self;
674                                 $node->update_users($field[2]);
675                         }
676                         last SWITCH;
677                 }
678                 
679                 if ($pcno == 51) {              # incoming ping requests/answers
680                         
681                         # is it for us?
682                         if ($field[1] eq $main::mycall) {
683                                 my $flag = $field[3];
684                                 if ($flag == 1) {
685                                         $self->send(pc51($field[2], $field[1], '0'));
686                                 } else {
687                                         # it's a reply, look in the ping list for this one
688                                         my $ref = $pings{$field[2]};
689                                         if ($ref) {
690                                                 my $tochan =  DXChannel->get($field[2]);
691                                                 while (@$ref) {
692                                                         my $r = shift @$ref;
693                                                         my $dxchan = DXChannel->get($r->{call});
694                                                         next unless $dxchan;
695                                                         my $t = tv_interval($r->{t}, [ gettimeofday ]);
696                                                         if ($dxchan->is_user) {
697                                                                 my $s = sprintf "%.2f", $t; 
698                                                                 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
699                                                                 $dxchan->send($dxchan->msg('pingi', $field[2], $s, $ave))
700                                                         } elsif ($dxchan->is_node) {
701                                                                 if ($tochan) {
702                                                                         $tochan->{nopings} = 2; # pump up the timer
703                                                                         push @{$tochan->{pingtime}}, $t;
704                                                                         shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
705                                                                         my $st;
706                                                                         for (@{$tochan->{pingtime}}) {
707                                                                                 $st += $_;
708                                                                         }
709                                                                         $tochan->{pingave} = $st / @{$tochan->{pingtime}};
710                                                                 }
711                                                         } 
712                                                 }
713                                         }
714                                 }
715                         } else {
716                                 # route down an appropriate thingy
717                                 $self->route($field[1], $line);
718                         }
719                         return;
720                 }
721
722                 if ($pcno == 73) {  # WCY broadcasts
723                         
724                         # do some de-duping
725                         my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
726                         if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
727                                 dbg('chan', "WCY Date ($field[1] $field[2]) out of range");
728                                 return;
729                         }
730                         @field = map { unpad($_) } @field;
731                         if (WCY::dup($d,@field[3..7])) {
732                                 dbg('chan', "Dup WCY Spot ignored\n");
733                                 return;
734                         }
735                 
736                         my $wcy = WCY::update($d, @field[2..12]);
737
738                         my $rep;
739                         eval {
740                                 $rep = Local::wwv($self, @field[1..12]);
741                         };
742                         # dbg('local', "Local::wcy error $@") if $@;
743                         return if $rep;
744
745                         # broadcast to the eager world
746                         send_wcy_spot($self, $line, $d, @field[2..12]);
747                         return;
748                 }
749
750                 if ($pcno == 84) { # remote commands (incoming)
751                         if ($field[1] eq $main::mycall) {
752                                 my $ref = DXUser->get_current($field[2]);
753                                 my $cref = DXCluster->get($field[2]);
754                                 Log('rcmd', 'in', $ref->{priv}, $field[2], $field[4]);
755                                 unless ($field[3] =~ /rcmd/i || !$cref || !$ref || $cref->mynode->call ne $ref->homenode) {    # not allowed to relay RCMDS!
756                                         if ($ref->{priv}) {     # you have to have SOME privilege, the commands have further filtering
757                                                 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
758                                                 my $oldpriv = $self->{priv};
759                                                 $self->{priv} = $ref->{priv};     # assume the user's privilege level
760                                                 my @in = (DXCommandmode::run_cmd($self, $field[4]));
761                                                 $self->{priv} = $oldpriv;
762                                                 for (@in) {
763                                                         s/\s*$//og;
764                                                         $self->send(pc85($main::mycall, $field[2], $field[3], "$main::mycall:$_"));
765                                                         Log('rcmd', 'out', $field[2], $_);
766                                                 }
767                                                 delete $self->{remotecmd};
768                                         } else {
769                                                 $self->send(pc85($main::mycall, $field[2], $field[3], "$main::mycall:sorry...!"));
770                                         }
771                                 } else {
772                                         $self->send(pc85($main::mycall, $field[2], $field[3],"$main::mycall:your attempt is logged, Tut tut tut...!"));
773                                 }
774                         } else {
775                                 my $ref = DXUser->get_current($field[1]);
776                                 if ($ref && $ref->is_clx) {
777                                         $self->route($field[1], $line);
778                                 } else {
779                                         route($field[1], pc34($field[2], $field[1], $field[3]));
780                                 }
781                         }
782                         return;
783                 }
784
785                 if ($pcno == 85) {              # remote command replies
786                         if ($field[1] eq $main::mycall) {
787                                 my $dxchan = DXChannel->get($field[3]);
788                                 if ($dxchan) {
789                                         $dxchan->send($field[4]);
790                                 } else {
791                                         my $s = $rcmds{$field[2]};
792                                         if ($s) {
793                                                 $dxchan = DXChannel->get($s->{call});
794                                                 $dxchan->send($field[4]) if $dxchan;
795                                                 delete $rcmds{$field[2]} if !$dxchan;
796                                         }
797                                 }
798                         } else {
799                                 my $ref = DXUser->get_current($field[1]);
800                                 if ($ref && $ref->is_clx) {
801                                         $self->route($field[1], $line);
802                                 } else {
803                                         route($field[1], pc35($field[2], $field[1], $field[3]));
804                                 }
805                         }
806                         return;
807                 }
808         }
809          
810         # if get here then rebroadcast the thing with its Hop count decremented (if
811         # there is one). If it has a hop count and it decrements to zero then don't
812         # rebroadcast it.
813         #
814         # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
815         #        REBROADCAST!!!!
816         #
817          
818         unless ($self->{isolate}) {
819                 broadcast_ak1a($line, $self); # send it to everyone but me
820         }
821 }
822
823 #
824 # This is called from inside the main cluster processing loop and is used
825 # for despatching commands that are doing some long processing job
826 #
827 sub process
828 {
829         my $t = time;
830         my @dxchan = DXChannel->get_all();
831         my $dxchan;
832         
833         foreach $dxchan (@dxchan) {
834                 next unless $dxchan->is_node();
835                 next if $dxchan == $me;
836                 
837                 # send a pc50 out on this channel
838                 if ($t >= $dxchan->pc50_t + $DXProt::pc50_interval) {
839                         $dxchan->send(pc50(scalar DXChannel::get_all_users));
840                         $dxchan->pc50_t($t);
841                 } 
842
843                 # send a ping out on this channel
844                 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
845                         if ($dxchan->{nopings} <= 0) {
846                                 $dxchan->disconnect;
847                         } else {
848                                 addping($main::mycall, $dxchan->call);
849                                 $dxchan->{nopings} -= 1;
850                                 $dxchan->{lastping} = $t;
851                         }
852                 }
853         }
854         
855         my $key;
856         my $val;
857         my $cutoff;
858         if ($main::systime - 3600 > $last_hour) {
859                 Spot::process;
860                 Geomag::process;
861                 AnnTalk::process;
862                 $last_hour = $main::systime;
863         }
864 }
865
866 #
867 # finish up a pc context
868 #
869 sub finish
870 {
871         my $self = shift;
872         my $call = $self->call;
873         my $conn = shift;
874         my $ref = DXCluster->get_exact($call);
875         
876         # unbusy and stop and outgoing mail
877         my $mref = DXMsg::get_busy($call);
878         $mref->stop_msg($call) if $mref;
879         
880         # broadcast to all other nodes that all the nodes connected to via me are gone
881         my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
882         my $node;
883         
884         foreach $node (@gonenodes) {
885                 next if $node->call eq $call;
886                 broadcast_ak1a(pc21($node->call, 'Gone') , $self) unless $self->{isolate}; 
887                 $node->del();
888         }
889
890         # remove outstanding pings
891         delete $pings{$call};
892         
893         # now broadcast to all other ak1a nodes that I have gone
894         broadcast_ak1a(pc21($call, 'Gone.'), $self) unless $self->{isolate};
895
896         # I was the last node visited
897     $self->user->node($main::mycall);
898
899         # send info to all logged in thingies
900         $self->tell_login('logoutn');
901
902         Log('DXProt', $call . " Disconnected");
903         $ref->del() if $ref;
904 }
905
906 #
907 # some active measures
908 #
909 sub send_dx_spot
910 {
911         my $self = shift;
912         my $line = shift;
913         my @dxchan = DXChannel->get_all();
914         my $dxchan;
915         
916         # send it if it isn't the except list and isn't isolated and still has a hop count
917         # taking into account filtering and so on
918         foreach $dxchan (@dxchan) {
919                 my $routeit;
920                 my ($filter, $hops);
921
922                 if ($dxchan->{spotfilter}) {
923                     ($filter, $hops) = Filter::it($dxchan->{spotfilter}, @_, $self->{call} );
924                         next unless $filter;
925                 }
926                 
927                 if ($dxchan->is_node) {
928                         next if $dxchan == $self;
929                         if ($hops) {
930                                 $routeit = $line;
931                                 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
932                         } else {
933                                 $routeit = adjust_hops($dxchan, $line);  # adjust its hop count by node name
934                                 next unless $routeit;
935                         }
936                         if ($filter) {
937                                 $dxchan->send($routeit) if $routeit;
938                         } else {
939                                 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
940                         }
941                 } elsif ($dxchan->is_user && $dxchan->{dx}) {
942                         my $buf = Spot::formatb($_[0], $_[1], $_[2], $_[3], $_[4]);
943                         $buf .= "\a\a" if $dxchan->{beep};
944                         if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
945                                 $dxchan->send($buf);
946                         } else {
947                                 $dxchan->delay($buf);
948                         }
949                 }                                       
950         }
951 }
952
953 sub send_wwv_spot
954 {
955         my $self = shift;
956         my $line = shift;
957         my @dxchan = DXChannel->get_all();
958         my $dxchan;
959         
960         # send it if it isn't the except list and isn't isolated and still has a hop count
961         # taking into account filtering and so on
962         foreach $dxchan (@dxchan) {
963                 my $routeit;
964                 my ($filter, $hops);
965
966                 if ($dxchan->{wwvfilter}) {
967                          ($filter, $hops) = Filter::it($dxchan->{wwvfilter}, @_, $self->{call} );
968                          next unless $filter;
969                 }
970                 if ($dxchan->is_node) {
971                         next if $dxchan == $self;
972                         if ($hops) {
973                                 $routeit = $line;
974                                 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
975                         } else {
976                                 $routeit = adjust_hops($dxchan, $line);  # adjust its hop count by node name
977                                 next unless $routeit;
978                         }
979                         if ($filter) {
980                                 $dxchan->send($routeit) if $routeit;
981                         } else {
982                                 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
983                                 
984                         }
985                 } elsif ($dxchan->is_user && $dxchan->{wwv}) {
986                         my $buf = "WWV de $_[6] <$_[1]>:   SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
987                         $buf .= "\a\a" if $dxchan->{beep};
988                         if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
989                                 $dxchan->send($buf);
990                         } else {
991                                 $dxchan->delay($buf);
992                         }
993                 }                                       
994         }
995 }
996
997 sub send_wcy_spot
998 {
999         my $self = shift;
1000         my $line = shift;
1001         my @dxchan = DXChannel->get_all();
1002         my $dxchan;
1003         
1004         # send it if it isn't the except list and isn't isolated and still has a hop count
1005         # taking into account filtering and so on
1006         foreach $dxchan (@dxchan) {
1007                 my $routeit;
1008                 my ($filter, $hops);
1009
1010                 if ($dxchan->{wcyfilter}) {
1011                          ($filter, $hops) = Filter::it($dxchan->{wcyfilter}, @_, $self->{call} );
1012                          next unless $filter;
1013                 }
1014                 if ($dxchan->is_clx || $dxchan->is_spider) {
1015                         next if $dxchan == $self;
1016                         if ($hops) {
1017                                 $routeit = $line;
1018                                 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1019                         } else {
1020                                 $routeit = adjust_hops($dxchan, $line);  # adjust its hop count by node name
1021                                 next unless $routeit;
1022                         }
1023                         if ($filter) {
1024                                 $dxchan->send($routeit) if $routeit;
1025                         } else {
1026                                 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1027                         }
1028                 } elsif ($dxchan->is_user && $dxchan->{wcy}) {
1029                         my $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
1030                         $buf .= "\a\a" if $dxchan->{beep};
1031                         if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1032                                 $dxchan->send($buf);
1033                         } else {
1034                                 $dxchan->delay($buf);
1035                         }
1036                 }                                       
1037         }
1038 }
1039
1040 # send an announce
1041 sub send_announce
1042 {
1043         my $self = shift;
1044         my $line = shift;
1045         my @dxchan = DXChannel->get_all();
1046         my $dxchan;
1047         my $text = unpad($_[2]);
1048         my $target;
1049         my $to = 'To ';
1050                                 
1051         if ($_[3] eq '*') {     # sysops
1052                 $target = "SYSOP";
1053         } elsif ($_[3] gt ' ') { # speciality list handling
1054                 my ($name) = split /\./, $_[3]; 
1055                 $target = "$name"; # put the rest in later (if bothered) 
1056         } 
1057         
1058         if ($_[5] eq '1') {
1059                 $target = "WX"; 
1060                 $to = '';
1061         }
1062         $target = "All" if !$target;
1063         
1064         Log('ann', $target, $_[0], $text);
1065
1066         # send it if it isn't the except list and isn't isolated and still has a hop count
1067         # taking into account filtering and so on
1068         foreach $dxchan (@dxchan) {
1069                 my $routeit;
1070                 my ($filter, $hops);
1071
1072                 if ($dxchan->{annfilter}) {
1073                         ($filter, $hops) = Filter::it($dxchan->{annfilter}, @_, $self->{call} );
1074                         next unless $filter;
1075                 } 
1076                 if ($dxchan->is_node && $_[1] ne $main::mycall) {  # i.e not specifically routed to me
1077                         next if $dxchan == $self;
1078                         if ($hops) {
1079                                 $routeit = $line;
1080                                 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1081                         } else {
1082                                 $routeit = adjust_hops($dxchan, $line);  # adjust its hop count by node name
1083                                 next unless $routeit;
1084                         }
1085                         if ($filter) {
1086                                 $dxchan->send($routeit) if $routeit;
1087                         } else {
1088                                 $dxchan->send($routeit) unless $dxchan->{isolate} || $self->{isolate};
1089                                 
1090                         }
1091                 } elsif ($dxchan->is_user && $dxchan->{ann}) {
1092                         next if $target eq 'SYSOP' && $dxchan->{priv} < 5;
1093                         my $buf = "$to$target de $_[0]: $text";
1094                         $buf .= "\a\a" if $dxchan->{beep};
1095                         if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1096                                 $dxchan->send($buf);
1097                         } else {
1098                                 $dxchan->delay($buf);
1099                         }
1100                 }                                       
1101         }
1102 }
1103
1104 sub send_local_config
1105 {
1106         my $self = shift;
1107         my $n;
1108         my @nodes;
1109         my @localnodes;
1110         my @remotenodes;
1111                 
1112         # send our nodes
1113         if ($self->{isolate}) {
1114                 @localnodes = (DXCluster->get_exact($main::mycall));
1115         } else {
1116                 # create a list of all the nodes that are not connected to this connection
1117                 # and are not themselves isolated, this to make sure that isolated nodes
1118         # don't appear outside of this node
1119                 @nodes = DXNode::get_all();
1120                 @nodes = grep { $_->{call} ne $main::mycall } @nodes;
1121                 @nodes = grep { $_->dxchan != $self } @nodes if @nodes;
1122                 @nodes = grep { !$_->dxchan->{isolate} } @nodes if @nodes;
1123                 @localnodes = grep { $_->dxchan->{call} eq $_->{call} } @nodes if @nodes;
1124                 unshift @localnodes, DXCluster->get_exact($main::mycall);
1125                 @remotenodes = grep { $_->dxchan->{call} ne $_->{call} } @nodes if @nodes;
1126         }
1127
1128         my @s = $me->pc19(@localnodes, @remotenodes);
1129         for (@s) {
1130                 my $routeit = adjust_hops($self, $_);
1131                 $self->send($routeit) if $routeit;
1132         }
1133         
1134         # get all the users connected on the above nodes and send them out
1135         foreach $n (@localnodes, @remotenodes) {
1136                 my @users = values %{$n->list};
1137                 my @s = pc16($n, @users);
1138                 for (@s) {
1139                         my $routeit = adjust_hops($self, $_);
1140                         $self->send($routeit) if $routeit;
1141                 }
1142         }
1143 }
1144
1145 #
1146 # route a message down an appropriate interface for a callsign
1147 #
1148 # is called route(to, pcline);
1149 #
1150 sub route
1151 {
1152         my ($self, $call, $line) = @_;
1153         my $cl = DXCluster->get_exact($call);
1154         if ($cl) {       # don't route it back down itself
1155                 if (ref $self && $call eq $self->{call}) {
1156                         dbg('chan', "Trying to route back to source, dropped");
1157                         return;
1158                 }
1159                 my $hops;
1160                 my $dxchan = $cl->{dxchan};
1161                 if ($dxchan) {
1162                         my $routeit = adjust_hops($dxchan, $line);   # adjust its hop count by node name
1163                         if ($routeit) {
1164                                 $dxchan->send($routeit) if $dxchan;
1165                         }
1166                 }
1167         }
1168 }
1169
1170 # broadcast a message to all clusters taking into account isolation
1171 # [except those mentioned after buffer]
1172 sub broadcast_ak1a
1173 {
1174         my $s = shift;                          # the line to be rebroadcast
1175         my @except = @_;                        # to all channels EXCEPT these (dxchannel refs)
1176         my @dxchan = DXChannel::get_all_ak1a();
1177         my $dxchan;
1178         
1179         # send it if it isn't the except list and isn't isolated and still has a hop count
1180         foreach $dxchan (@dxchan) {
1181                 next if grep $dxchan == $_, @except;
1182                 my $routeit = adjust_hops($dxchan, $s);      # adjust its hop count by node name
1183                 $dxchan->send($routeit) unless $dxchan->{isolate} || !$routeit;
1184         }
1185 }
1186
1187 # broadcast a message to all clusters ignoring isolation
1188 # [except those mentioned after buffer]
1189 sub broadcast_all_ak1a
1190 {
1191         my $s = shift;                          # the line to be rebroadcast
1192         my @except = @_;                        # to all channels EXCEPT these (dxchannel refs)
1193         my @dxchan = DXChannel::get_all_ak1a();
1194         my $dxchan;
1195         
1196         # send it if it isn't the except list and isn't isolated and still has a hop count
1197         foreach $dxchan (@dxchan) {
1198                 next if grep $dxchan == $_, @except;
1199                 my $routeit = adjust_hops($dxchan, $s);      # adjust its hop count by node name
1200                 $dxchan->send($routeit);
1201         }
1202 }
1203
1204 # broadcast to all users
1205 # storing the spot or whatever until it is in a state to receive it
1206 sub broadcast_users
1207 {
1208         my $s = shift;                          # the line to be rebroadcast
1209         my $sort = shift;           # the type of transmission
1210         my $fref = shift;           # a reference to an object to filter on
1211         my @except = @_;                        # to all channels EXCEPT these (dxchannel refs)
1212         my @dxchan = DXChannel::get_all_users();
1213         my $dxchan;
1214         my @out;
1215         
1216         foreach $dxchan (@dxchan) {
1217                 next if grep $dxchan == $_, @except;
1218                 push @out, $dxchan;
1219         }
1220         broadcast_list($s, $sort, $fref, @out);
1221 }
1222
1223 # broadcast to a list of users
1224 sub broadcast_list
1225 {
1226         my $s = shift;
1227         my $sort = shift;
1228         my $fref = shift;
1229         my $dxchan;
1230         
1231         foreach $dxchan (@_) {
1232                 my $filter = 1;
1233                 
1234                 if ($sort eq 'dx') {
1235                     next unless $dxchan->{dx};
1236                         ($filter) = Filter::it($dxchan->{spotfilter}, @{$fref}) if ref $fref;
1237                         next unless $filter;
1238                 }
1239                 next if $sort eq 'ann' && !$dxchan->{ann};
1240                 next if $sort eq 'wwv' && !$dxchan->{wwv};
1241                 next if $sort eq 'wcy' && !$dxchan->{wcy};
1242                 next if $sort eq 'wx' && !$dxchan->{wx};
1243
1244                 $s =~ s/\a//og unless $dxchan->{beep};
1245
1246                 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'convers') {
1247                         $dxchan->send($s);      
1248                 } else {
1249                         $dxchan->delay($s);
1250                 }
1251         }
1252 }
1253
1254
1255 #
1256 # obtain the hops from the list for this callsign and pc no 
1257 #
1258
1259 sub get_hops
1260 {
1261         my $pcno = shift;
1262         my $hops = $DXProt::hopcount{$pcno};
1263         $hops = $DXProt::def_hopcount if !$hops;
1264         return "H$hops";       
1265 }
1266
1267
1268 # adjust the hop count on a per node basis using the user loadable 
1269 # hop table if available or else decrement an existing one
1270 #
1271
1272 sub adjust_hops
1273 {
1274         my $self = shift;
1275         my $s = shift;
1276         my $call = $self->{call};
1277         my $hops;
1278         
1279         if (($hops) = $s =~ /\^H(\d+)\^~?$/o) {
1280                 my ($pcno) = $s =~ /^PC(\d\d)/o;
1281                 confess "$call called adjust_hops with '$s'" unless $pcno;
1282                 my $ref = $nodehops{$call} if %nodehops;
1283                 if ($ref) {
1284                         my $newhops = $ref->{$pcno};
1285                         return "" if defined $newhops && $newhops == 0;
1286                         $newhops = $ref->{default} unless $newhops;
1287                         return "" if defined $newhops && $newhops == 0;
1288                         $newhops = $hops if !$newhops;
1289                         $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
1290                 } else {
1291                         # simply decrement it
1292                         $hops--;
1293                         return "" if !$hops;
1294                         $s =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
1295                 }
1296         }
1297         return $s;
1298 }
1299
1300
1301 # load hop tables
1302 #
1303 sub load_hops
1304 {
1305         my $self = shift;
1306         return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
1307         do "$main::data/hop_table.pl";
1308         return $@ if $@;
1309         return 0;
1310 }
1311
1312
1313 # add a ping request to the ping queues
1314 sub addping
1315 {
1316         my ($from, $to) = @_;
1317         my $ref = $pings{$to} || [];
1318         my $r = {};
1319         $r->{call} = $from;
1320         $r->{t} = [ gettimeofday ];
1321         route(undef, $to, pc51($to, $main::mycall, 1));
1322         push @$ref, $r;
1323         $pings{$to} = $ref;
1324 }
1325
1326 # add a rcmd request to the rcmd queues
1327 sub addrcmd
1328 {
1329         my ($self, $to, $cmd) = @_;
1330
1331         my $r = {};
1332         $r->{call} = $self->{call};
1333         $r->{t} = $main::systime;
1334         $r->{cmd} = $cmd;
1335         $rcmds{$to} = $r;
1336
1337         my $ref = DXCluster->get_exact($to);
1338     if ($ref && $ref->dxchan && $ref->dxchan->is_clx) {
1339                 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1340         } else {
1341                 route(undef, $to, pc34($main::mycall, $to, $cmd));
1342         }
1343 }
1344
1345 sub disconnect
1346 {
1347         my $self = shift;
1348         my $nopc39 = shift;
1349
1350         if ($self->{conn} && !$nopc39) {
1351                 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1352         }
1353
1354         $self->SUPER::disconnect;
1355 }
1356 1;
1357 __END__