+ if ($pcno == 17) { # remove a user
+ my $dxchan;
+ if ($field[1] eq $main::mycall || $field[2] eq $main::mycall) {
+ dbg('chan', "PCPROT: trying to alter config on this node from outside!");
+ return;
+ }
+ if ($field[1] eq $main::myalias && DXChannel->get($field[1])) {
+ dbg('chan', "PCPROT: trying to disconnect sysop from outside!");
+ return;
+ }
+ if ($dxchan = DXChannel->get($field[1])) {
+ dbg('chan', "PCPROT: $field[1] connected locally");
+ return;
+ }
+
+ my $node = Route::Node::get($field[2]);
+ unless ($node) {
+ dbg('chan', "PCPROT: Route::Node $field[2] not in config");
+ return;
+ }
+ my @rout = $node->del_user($field[1]);
+ dbg('route', "B/C PC17 on $field[2] for: $field[1]");
+ $self->route_pc17($node, @rout) if @rout;
+ return;
+ }
+
+ if ($pcno == 18) { # link request
+ $self->state('init');
+
+ # first clear out any nodes on this dxchannel
+ my $node = Route::Node::get($self->{call});
+ my @rout;
+ for ($node->nodes) {
+ my $r = Route::Node::get($_);
+ push @rout, $r->del_node if $r;
+ }
+ $self->route_pc21(@rout, $node);
+ $self->send_local_config();
+ $self->send(pc20());
+ return; # we don't pass these on
+ }
+
+ if ($pcno == 19) { # incoming cluster list
+ my $i;
+ my $newline = "PC19^";
+
+ # new routing list
+ my @rout;
+ my $node = Route::Node::get($self->{call});
+
+ # parse the PC19
+ for ($i = 1; $i < $#field-1; $i += 4) {
+ my $here = $field[$i];
+ my $call = uc $field[$i+1];
+ my $conf = $field[$i+2];
+ my $ver = $field[$i+3];
+ next unless defined $here && defined $conf && is_callsign($call);
+ # check for sane parameters
+ $ver = 5000 if $ver eq '0000';
+ next if $ver < 5000; # only works with version 5 software
+ next if length $call < 3; # min 3 letter callsigns
+
+ # update it if required
+ if ($node->call eq $call && !$node->version) {
+ $node->version($ver);
+ $node->flags(Route::here($here)|Route::conf($conf));
+ push @rout, $node;
+ } elsif ($node->call ne $call) {
+ my $r = $node->add($call, $ver, Route::here($here)|Route::conf($conf));
+ push @rout, $r if $r;
+ }
+
+ # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
+ my $mref = DXMsg::get_busy($call);
+ $mref->stop_msg($call) if $mref;
+
+ # add this station to the user database, if required (don't remove SSID from nodes)
+ my $user = DXUser->get_current($call);
+ if (!$user) {
+ $user = DXUser->new($call);
+ $user->sort('A');
+ $user->priv(1); # I have relented and defaulted nodes
+ $self->{priv} = 1; # to user RCMDs allowed
+ $user->homenode($call);
+ $user->node($call);
+ }
+ $user->lastin($main::systime) unless DXChannel->get($call);
+ $user->put;
+ }
+
+ dbg('route', "B/C PC19 for: " . join(',', map{$_->call} @rout)) if @rout;
+
+ $self->route_pc19(@rout) if @rout;
+ return;
+ }
+
+ if ($pcno == 20) { # send local configuration
+ $self->send_local_config();
+ $self->send(pc22());
+ $self->state('normal');
+ return;
+ }
+
+ if ($pcno == 21) { # delete a cluster from the list
+ my $call = uc $field[1];
+ my @rout;
+ my $node = Route::Node::get($call);
+
+ if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
+ if ($call eq $self->{call}) {
+ dbg('chan', "PCPROT: Trying to disconnect myself with PC21");
+ return;
+ }
+
+ # routing objects
+ if ($node) {
+ push @rout, $node->del_node($call);
+ } else {
+ dbg('chan', "PCPROT: Route::Node $call not in config");
+ }
+ } else {
+ dbg('chan', "PCPROT: I WILL _NOT_ be disconnected!");
+ return;
+ }
+ dbg('route', "B/C PC21 for: " . join(',', (map{$_->call} @rout))) if @rout;
+
+ $self->route_pc21(@rout) if @rout;
+ return;
+ }
+
+ if ($pcno == 22) {
+ $self->state('normal');
+ return;
+ }
+
+ if ($pcno == 23 || $pcno == 27) { # WWV info
+
+ # route 'foreign' pc27s
+ if ($pcno == 27) {
+ if ($field[8] ne $main::mycall) {
+ $self->route($field[8], $line);
+ return;
+ }
+ }
+
+ # do some de-duping
+ my $d = cltounix($field[1], sprintf("%02d18Z", $field[2]));
+ my $sfi = unpad($field[3]);
+ my $k = unpad($field[4]);
+ my $i = unpad($field[5]);
+ my ($r) = $field[6] =~ /R=(\d+)/;
+ $r = 0 unless $r;
+ if (($pcno == 23 && $d < $main::systime - $pc23_max_age) || $d > $main::systime + 1500 || $field[2] < 0 || $field[2] > 23) {
+ dbg('chan', "PCPROT: WWV Date ($field[1] $field[2]) out of range");
+ return;
+ }
+ if (Geomag::dup($d,$sfi,$k,$i,$field[6])) {
+ dbg('chan', "PCPROT: Dup WWV Spot ignored\n");
+ return;
+ }
+ $field[7] =~ s/-\d+$//o; # remove spotter's ssid
+
+ my $wwv = Geomag::update($d, $field[2], $sfi, $k, $i, @field[6..8], $r);
+
+ my $rep;
+ eval {
+ $rep = Local::wwv($self, $field[1], $field[2], $sfi, $k, $i, @field[6..8], $r);
+ };
+# dbg('local', "Local::wwv2 error $@") if $@;
+ return if $rep;
+
+ # DON'T be silly and send on PC27s!
+ return if $pcno == 27;
+
+ # broadcast to the eager world
+ send_wwv_spot($self, $line, $d, $field[2], $sfi, $k, $i, @field[6..8]);
+ return;
+ }
+
+ if ($pcno == 24) { # set here status
+ my $call = uc $field[1];
+ my $ref = Route::Node::get($call);
+ $ref->here($field[2]) if $ref;
+ $ref = Route::User::get($call);
+ $ref->here($field[2]) if $ref;
+ last SWITCH;
+ }
+
+ if ($pcno == 25) { # merge request
+ if ($field[1] ne $main::mycall) {
+ $self->route($field[1], $line);
+ return;
+ }
+ if ($field[2] eq $main::mycall) {
+ dbg('chan', "PCPROT: Trying to merge to myself, ignored");
+ return;
+ }
+
+ Log('DXProt', "Merge request for $field[3] spots and $field[4] WWV from $field[1]");
+
+ # spots
+ if ($field[3] > 0) {
+ my @in = reverse Spot::search(1, undef, undef, 0, $field[3]);
+ my $in;
+ foreach $in (@in) {
+ $self->send(pc26(@{$in}[0..4], $field[2]));
+ }
+ }
+
+ # wwv
+ if ($field[4] > 0) {
+ my @in = reverse Geomag::search(0, $field[4], time, 1);
+ my $in;
+ foreach $in (@in) {
+ $self->send(pc27(@{$in}[0..5], $field[2]));
+ }
+ }
+ return;
+ }
+
+ 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 = Route::Node::get($field[2]);
+ Log('rcmd', 'in', $ref->{priv}, $field[2], $field[3]);
+ unless (!$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[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;
+ }