+ if ($pcno == 16) { # add a user
+ my $node = DXCluster->get_exact($field[1]);
+ my $dxchan;
+ if (!$node && ($dxchan = DXChannel->get($field[1]))) {
+ # add it to the node table if it isn't present and it's
+ # connected locally
+ $node = DXNode->new($dxchan, $field[1], 0, 1, 5400);
+ dbg('chan', "PCPROT: $field[1] no PC19 yet, autovivified as node");
+# broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
+
+ }
+ 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[2] eq $main::myalias && DXChannel->get($field[1])) {
+ dbg('chan', "PCPROT: trying to connect sysop from outside!");
+ return;
+ }
+ unless ($node) {
+ dbg('chan', "PCPROT: Node $field[1] not in config");
+ return;
+ }
+ unless ($node->isa('DXNode')) {
+ dbg('chan', "PCPROT: $field[1] is not a node");
+ return;
+ }
+ if ($node->dxchan != $self) {
+ dbg('chan', "PCPROT: $field[1] came in on wrong channel");
+ return;
+ }
+ if (($dxchan = DXChannel->get($field[1])) && $dxchan != $self) {
+ dbg('chan', "PCPROT: $field[1] connected locally");
+ return;
+ }
+ my $i;
+
+ for ($i = 2; $i < $#field; $i++) {
+ my ($call, $confmode, $here) = $field[$i] =~ /^(\S+) (\S) (\d)/o;
+ next unless $call && $confmode && defined $here && is_callsign($call);
+ my $ref = DXCluster->get_exact($call);
+ if ($ref) {
+ if ($ref->isa('DXNode')) {
+ dbg('chan', "PCPROT: $call is a node");
+ next;
+ }
+ my $rcall = $ref->mynode->call;
+ dbg('chan', "PCPROT: already have $call on $rcall");
+ next;
+ }
+
+ $confmode = $confmode eq '*';
+ DXNodeuser->new($self, $node, $call, $confmode, $here);
+
+ # add this station to the user database, if required
+ $call =~ s/-\d+$//o; # remove ssid for users
+ my $user = DXUser->get_current($call);
+ $user = DXUser->new($call) if !$user;
+ $user->homenode($node->call) if !$user->homenode;
+ $user->node($node->call);
+ $user->lastin($main::systime) unless DXChannel->get($call);
+ $user->put;
+ }
+
+ # queue up any messages (look for privates only)
+ DXMsg::queue_msg(1) if $self->state eq 'normal';
+ last SWITCH;
+ }
+
+ if ($pcno == 17) { # remove a user
+ my $node = DXCluster->get_exact($field[2]);
+ my $dxchan;
+ if (!$node && ($dxchan = DXChannel->get($field[2]))) {
+ # add it to the node table if it isn't present and it's
+ # connected locally
+ $node = DXNode->new($dxchan, $field[2], 0, 1, 5400);
+ dbg('chan', "PCPROT: $field[2] no PC19 yet, autovivified as node");
+# broadcast_ak1a(pc19($dxchan, $node), $dxchan, $self) unless $dxchan->{isolate};
+ }
+ 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;
+ }
+ unless ($node) {
+ dbg('chan', "PCPROT: Node $field[2] not in config");
+ return;
+ }
+ unless ($node->isa('DXNode')) {
+ dbg('chan', "PCPROT: $field[2] is not a node");
+ return;
+ }
+ if ($node->dxchan != $self) {
+ dbg('chan', "PCPROT: $field[2] came in on wrong channel");
+ return;
+ }
+ if ($dxchan = DXChannel->get($field[1])) {
+ dbg('chan', "PCPROT: $field[1] connected locally");
+ return;
+ }
+ my $ref = DXCluster->get_exact($field[1]);
+ if ($ref) {
+ if ($ref->mynode != $node) {
+ dbg('chan', "PCPROT: $field[1] came in from wrong node $field[2]");
+ return;
+ }
+ $ref->del;
+ } else {
+ dbg('chan', "PCPROT: $field[1] not known" );
+ return;
+ }
+ last SWITCH;
+ }
+
+ if ($pcno == 18) { # link request
+ $self->state('init');
+
+ # first clear out any nodes on this dxchannel
+ my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
+ foreach my $node (@gonenodes) {
+ next if $node->dxchan == $DXProt::me;
+ broadcast_ak1a(pc21($node->call, 'Gone, re-init') , $self) unless $self->{isolate};
+ $node->del();
+ }
+ $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^";
+ for ($i = 1; $i < $#field-1; $i += 4) {
+ my $here = $field[$i];
+ my $call = uc $field[$i+1];
+ my $confmode = $field[$i+2];
+ my $ver = $field[$i+3];
+ next unless defined $here && defined $confmode && is_callsign($call);
+
+ $ver = 5400 if !$ver && $allowzero;
+
+ # now check the call over
+ my $node = DXCluster->get_exact($call);
+ if ($node) {
+ my $dxchan;
+ if (($dxchan = DXChannel->get($call)) && $dxchan != $self) {
+ dbg('chan', "PCPROT: $call connected locally");
+ }
+ if ($node->dxchan != $self) {
+ dbg('chan', "PCPROT: $call come in on wrong channel");
+ next;
+ }
+ my $rcall = $node->mynode->call;
+ dbg('chan', "PCPROT: already have $call on $rcall");
+ next;
+ }
+
+ # check for sane parameters
+ next if $ver < 5000; # only works with version 5 software
+ next if length $call < 3; # min 3 letter callsigns
+
+ # add it to the nodes table and outgoing line
+ $newline .= "$here^$call^$confmode^$ver^";
+ DXNode->new($self, $call, $confmode, $here, $ver);
+
+ # 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;
+ }
+
+ return if $newline eq "PC19^";
+
+ # add hop count
+ $newline .= get_hops(19) . "^";
+ $line = $newline;
+ last SWITCH;
+ }
+
+ 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];
+ if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
+ my $node = DXCluster->get_exact($call);
+ if ($node) {
+ unless ($node->isa('DXNode')) {
+ dbg('chan', "PCPROT: $call is not a node");
+ return;
+ }
+ if ($call eq $self->{call}) {
+ dbg('chan', "PCPROT: Trying to disconnect myself with PC21");
+ return;
+ }
+ if ($node->dxchan != $self) {
+ dbg('chan', "PCPROT: $call come in on wrong channel");
+ return;
+ }
+ my $dxchan;
+ if ($dxchan = DXChannel->get($call)) {
+ dbg('chan', "PCPROT: $call connected locally");
+ return;
+ }
+ $node->del();
+ } else {
+ dbg('chan', "PCPROT: $call not in table, dropped");
+ return;
+ }
+ } else {
+ dbg('chan', "PCPROT: I WILL _NOT_ be disconnected!");
+ return;
+ }
+ last SWITCH;
+ }