- # input filter if required
- return unless $self->in_filter_route($node);
-
- $self->route_pc50($node, $field[2], $field[3]) unless eph_dup($line);
- }
- return;
- }
-
- if ($pcno == 51) { # incoming ping requests/answers
- my $to = $field[1];
- my $from = $field[2];
- my $flag = $field[3];
-
- # is it for us?
- if ($to eq $main::mycall) {
- if ($flag == 1) {
- $self->send(pc51($from, $to, '0'));
- } else {
- # it's a reply, look in the ping list for this one
- my $ref = $pings{$from};
- if ($ref) {
- my $tochan = DXChannel->get($from);
- 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', $from, $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($to, $line);
- }
- return;
- }
-
- if ($pcno == 75) { # dunno but route it
- my $call = $field[1];
- if ($call ne $main::mycall) {
- $self->route($call, $line);
- }
- return;
- }
-
- if ($pcno == 73) { # WCY broadcasts
- my $call = $field[1];
-
- # do some de-duping
- my $d = cltounix($call, sprintf("%02d18Z", $field[2]));
- if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
- dbg("PCPROT: WCY Date ($call $field[2]) out of range") if isdbg('chanerr');
- return;
- }
- @field = map { unpad($_) } @field;
- if (WCY::dup($d,@field[3..7])) {
- dbg("PCPROT: Dup WCY Spot ignored\n") if isdbg('chanerr');
- return;
- }
-
- my $wcy = WCY::update($d, @field[2..12]);
-
- my $rep;
- eval {
- $rep = Local::wwv($self, @field[1..12]);
- };
- # dbg("Local::wcy error $@") if isdbg('local') 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)
- my $call = $field[1];
- if ($call eq $main::mycall) {
- my $ref = DXUser->get_current($field[2]);
- my $cref = Route::Node::get($field[2]);
- Log('rcmd', 'in', $ref->{priv}, $field[2], $field[4]);
- unless ($field[4] =~ /rcmd/i || !$cref || !$ref || $cref->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($call);
- if ($ref && $ref->is_clx) {
- $self->route($call, $line);
- } else {
- $self->route($call, pc34($field[2], $call, $field[4]));
- }
- }
- return;
- }
-
- if ($pcno == 85) { # remote command replies
- my $call = $field[1];
- if ($call 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($call);
- if ($ref && $ref->is_clx) {
- $self->route($call, $line);
- } else {
- $self->route($call, pc35($field[2], $call, $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!!!!
- #
-
- if (eph_dup($line)) {
- dbg("PCPROT: Ephemeral dup, dropped") if isdbg('chanerr');
- } else {
- 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
-{
- my $t = time;
- my @dxchan = DXChannel->get_all();
- my $dxchan;
-
- foreach $dxchan (@dxchan) {
- next unless $dxchan->is_node();
- next if $dxchan == $me;
-
- # send a pc50 out on this channel
- $dxchan->{pc50_t} = $main::systime unless exists $dxchan->{pc50_t};
- if ($t >= $dxchan->{pc50_t} + $DXProt::pc50_interval) {
- my $s = pc50($me, scalar DXChannel::get_all_users);
- eph_dup($s);
- $dxchan->send($s);
- $dxchan->{pc50_t} = $t;
- }
-
- # send a ping out on this channel
- if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
- if ($dxchan->{nopings} <= 0) {
- $dxchan->disconnect;
- } else {
- addping($main::mycall, $dxchan->call);
- $dxchan->{nopings} -= 1;
- $dxchan->{lastping} = $t;
- }
- }
- }
-
- # every ten seconds
- if ($t - $last10 >= 10) {
- # clean out ephemera
-
- eph_clean();
-
- $last10 = $t;
- }
-
- if ($main::systime - 3600 > $last_hour) {
- $last_hour = $main::systime;
- }
-}
-
-#
-# finish up a pc context
-#