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