- if (($pcno >= 28 && $pcno <= 33) || $pcno == 40 || $pcno == 42 || $pcno == 49) { # mail/file handling
- if ($pcno == 49 || $field[1] eq $main::mycall) {
- DXMsg::process($self, $line);
- } else {
- $self->route($field[1], $line) unless $self->is_clx;
- }
- return;
- }
-
- if ($pcno == 34 || $pcno == 36) { # remote commands (incoming)
- if ($field[1] eq $main::mycall) {
- my $ref = DXUser->get_current($field[2]);
- my $cref = DXCluster->get($field[2]);
- Log('rcmd', 'in', $ref->{priv}, $field[2], $field[3]);
- unless (!$cref || !$ref || $cref->mynode->call ne $ref->homenode) { # not allowed to relay RCMDS!
- if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
- $self->{remotecmd} = 1; # for the benefit of any command that needs to know
- my $oldpriv = $self->{priv};
- $self->{priv} = $ref->{priv}; # assume the user's privilege level
- my @in = (DXCommandmode::run_cmd($self, $field[3]));
- $self->{priv} = $oldpriv;
- for (@in) {
- s/\s*$//og;
- $self->send(pc35($main::mycall, $field[2], "$main::mycall:$_"));
- Log('rcmd', 'out', $field[2], $_);
- }
- delete $self->{remotecmd};
- } else {
- $self->send(pc35($main::mycall, $field[2], "$main::mycall:sorry...!"));
- }
- } else {
- $self->send(pc35($main::mycall, $field[2], "$main::mycall:your attempt is logged, Tut tut tut...!"));
- }
- } else {
- my $ref = DXUser->get_current($field[1]);
- if ($ref && $ref->is_clx) {
- $self->route($field[1], pc84($field[2], $field[1], $field[2], $field[3]));
- } else {
- $self->route($field[1], $line);
- }
- }
- return;
- }
-
- if ($pcno == 35) { # remote command replies
- if ($field[1] eq $main::mycall) {
- my $s = $rcmds{$field[2]};
- if ($s) {
- my $dxchan = DXChannel->get($s->{call});
- $dxchan->send($field[3]) if $dxchan;
- delete $rcmds{$field[2]} if !$dxchan;
- } else {
- # send unsolicited ones to the sysop
- my $dxchan = DXChannel->get($main::myalias);
- $dxchan->send($field[3]) if $dxchan;
- }
- } else {
- my $ref = DXUser->get_current($field[1]);
- if ($ref && $ref->is_clx) {
- $self->route($field[1], pc85($field[2], $field[1], $field[2], $field[3]));
- } else {
- $self->route($field[1], $line);
- }
- }
- return;
- }
-
- # for pc 37 see 44 onwards
-
- if ($pcno == 38) { # node connected list from neighbour
- return;
- }
-
- if ($pcno == 39) { # incoming disconnect
- if ($field[1] eq $self->{call}) {
- $self->disconnect(1);
- } else {
- dbg('chan', "PCPROT: came in on wrong channel");
- }
- return;
- }
-
- if ($pcno == 41) { # user info
- # add this station to the user database, if required
- my $user = DXUser->get_current($field[1]);
- $user = DXUser->new($field[1]) if !$user;
-
- if ($field[2] == 1) {
- $user->name($field[3]);
- } elsif ($field[2] == 2) {
- $user->qth($field[3]);
- } elsif ($field[2] == 3) {
- my ($lat, $long) = DXBearing::stoll($field[3]);
- $user->lat($lat);
- $user->long($long);
- $user->qra(DXBearing::lltoqra($lat, $long)) unless $user->qra && DXBearing::is_qra($user->qra);
- } elsif ($field[2] == 4) {
- $user->homenode($field[3]);
- }
- $user->lastoper($main::systime); # to cut down on excessive for/opers being generated
- $user->put;
- last SWITCH;
- }
- if ($pcno == 43) {
- last SWITCH;
- }
- if ($pcno == 37 || $pcno == 44 || $pcno == 45 || $pcno == 46 || $pcno == 47 || $pcno == 48) {
- DXDb::process($self, $line);
- return;
- }
-
- if ($pcno == 50) { # keep alive/user list
- my $node = DXCluster->get_exact($field[1]);
- if ($node) {
- return unless $node->isa('DXNode');
- return unless $node->dxchan == $self;
- $node->update_users($field[2]);
- }
- last SWITCH;
- }
-
- if ($pcno == 51) { # incoming ping requests/answers
-
- # is it for us?
- if ($field[1] eq $main::mycall) {
- my $flag = $field[3];
- if ($flag == 1) {
- $self->send(pc51($field[2], $field[1], '0'));
- } else {
- # it's a reply, look in the ping list for this one
- my $ref = $pings{$field[2]};
- if ($ref) {
- my $tochan = DXChannel->get($field[2]);
- while (@$ref) {
- my $r = shift @$ref;
- my $dxchan = DXChannel->get($r->{call});
- next unless $dxchan;
- my $t = tv_interval($r->{t}, [ gettimeofday ]);
- if ($dxchan->is_user) {
- my $s = sprintf "%.2f", $t;
- my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
- $dxchan->send($dxchan->msg('pingi', $field[2], $s, $ave))
- } elsif ($dxchan->is_node) {
- if ($tochan) {
- $tochan->{nopings} = $tochan->user->nopings || 2; # pump up the timer
- push @{$tochan->{pingtime}}, $t;
- shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
- my $st;
- for (@{$tochan->{pingtime}}) {
- $st += $_;
- }
- $tochan->{pingave} = $st / @{$tochan->{pingtime}};
- }
- }
- }
- }
- }
- } else {
- # route down an appropriate thingy
- $self->route($field[1], $line);
- }
- return;
- }
-
- if ($pcno == 75) { # dunno but route it
- if ($field[1] ne $main::mycall) {
- $self->route($field[1], $line);
- }
- return;
- }
-
- if ($pcno == 73) { # WCY broadcasts
-
- # do some de-duping
- my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
- if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
- dbg('chan', "PCPROT: WCY Date ($field[1] $field[2]) out of range");
- return;
- }
- @field = map { unpad($_) } @field;
- if (WCY::dup($d,@field[3..7])) {
- dbg('chan', "PCPROT: Dup WCY Spot ignored\n");
- return;
- }
-
- my $wcy = WCY::update($d, @field[2..12]);
-
- my $rep;
- eval {
- $rep = Local::wwv($self, @field[1..12]);
- };
- # dbg('local', "Local::wcy error $@") if $@;
- return if $rep;
-
- # broadcast to the eager world
- send_wcy_spot($self, $line, $d, @field[2..12]);
- return;
- }
-
- if ($pcno == 84) { # remote commands (incoming)
- if ($field[1] eq $main::mycall) {
- my $ref = DXUser->get_current($field[2]);
- my $cref = DXCluster->get($field[2]);
- Log('rcmd', 'in', $ref->{priv}, $field[2], $field[4]);
- unless ($field[4] =~ /rcmd/i || !$cref || !$ref || $cref->mynode->call ne $ref->homenode) { # not allowed to relay RCMDS!
- if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
- $self->{remotecmd} = 1; # for the benefit of any command that needs to know
- my $oldpriv = $self->{priv};
- $self->{priv} = $ref->{priv}; # assume the user's privilege level
- my @in = (DXCommandmode::run_cmd($self, $field[4]));
- $self->{priv} = $oldpriv;
- for (@in) {
- s/\s*$//og;
- $self->send(pc85($main::mycall, $field[2], $field[3], "$main::mycall:$_"));
- Log('rcmd', 'out', $field[2], $_);
- }
- delete $self->{remotecmd};
- } else {
- $self->send(pc85($main::mycall, $field[2], $field[3], "$main::mycall:sorry...!"));
- }
- } else {
- $self->send(pc85($main::mycall, $field[2], $field[3],"$main::mycall:your attempt is logged, Tut tut tut...!"));
- }
- } else {
- my $ref = DXUser->get_current($field[1]);
- if ($ref && $ref->is_clx) {
- $self->route($field[1], $line);
- } else {
- $self->route($field[1], pc34($field[2], $field[1], $field[4]));
- }
- }
- return;
- }
-
- if ($pcno == 85) { # remote command replies
- if ($field[1] eq $main::mycall) {
- my $dxchan = DXChannel->get($field[3]);
- if ($dxchan) {
- $dxchan->send($field[4]);
- } else {
- my $s = $rcmds{$field[2]};
- if ($s) {
- $dxchan = DXChannel->get($s->{call});
- $dxchan->send($field[4]) if $dxchan;
- delete $rcmds{$field[2]} if !$dxchan;
- } else {
- # send unsolicited ones to the sysop
- my $dxchan = DXChannel->get($main::myalias);
- $dxchan->send($field[4]) if $dxchan;
- }
- }
- } else {
- my $ref = DXUser->get_current($field[1]);
- if ($ref && $ref->is_clx) {
- $self->route($field[1], $line);
- } else {
- $self->route($field[1], pc35($field[2], $field[1], $field[4]));
- }
- }
- return;
- }
- }
-
- # if get here then rebroadcast the thing with its Hop count decremented (if
- # there is one). If it has a hop count and it decrements to zero then don't
- # rebroadcast it.
- #
- # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
- # REBROADCAST!!!!
- #
-
- unless ($self->{isolate}) {
- broadcast_ak1a($line, $self); # send it to everyone but me
- }
-}
-
-#
-# This is called from inside the main cluster processing loop and is used
-# for despatching commands that are doing some long processing job
-#
-sub process