- # local processing 1
- my $pcr;
- eval {
- $pcr = Local::pcprot($self, $pcno, @field);
- };
-# dbg("Local::pcprot error $@") if isdbg('local') if $@;
- return if $pcr;
-
- SWITCH: {
- if ($pcno == 10) { # incoming talk
-
- # will we allow it at all?
- if ($censorpc) {
- my @bad;
- if (@bad = BadWords::check($field[3])) {
- dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
- return;
- }
- }
-
- # is it for me or one of mine?
- my ($to, $via, $call, $dxchan);
- if ($field[5] gt ' ') {
- $call = $via = $field[2];
- $to = $field[5];
- } else {
- $call = $to = $field[2];
- }
- $dxchan = DXChannel->get($main::myalias) if $call eq $main::mycall;
- $dxchan = DXChannel->get($call) unless $dxchan;
- if ($dxchan && $dxchan->is_user) {
- $field[3] =~ s/\%5E/^/g;
- $dxchan->talk($field[1], $to, $via, $field[3]);
- } else {
- $self->route($field[2], $line); # relay it on its way
- }
- return;
- }
-
- if ($pcno == 11 || $pcno == 26) { # dx spot
-
- # route 'foreign' pc26s
- if ($pcno == 26) {
- if ($field[7] ne $main::mycall) {
- $self->route($field[7], $line);
- return;
- }
- }
-
- # if this is a 'nodx' node then ignore it
- if ($badnode->in($field[7])) {
- dbg("PCPROT: Bad Node, dropped") if isdbg('chanerr');
- return;
- }
-
- # if this is a 'bad spotter' user then ignore it
- if ($badspotter->in($field[6])) {
- dbg("PCPROT: Bad Spotter, dropped") if isdbg('chanerr');
- return;
- }
-
- # convert the date to a unix date
- my $d = cltounix($field[3], $field[4]);
- # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
- if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
- dbg("PCPROT: Spot ignored, invalid date or out of range ($field[3] $field[4])\n") if isdbg('chanerr');
- return;
- }
-
- # is it 'baddx'
- if ($baddx->in($field[2])) {
- dbg("PCPROT: Bad DX spot, ignored") if isdbg('chanerr');
- return;
- }
-
- # do some de-duping
- $field[5] =~ s/^\s+//; # take any leading blanks off
- $field[2] = unpad($field[2]); # take off leading and trailing blanks from spotted callsign
- if ($field[2] =~ /BUST\w*$/) {
- dbg("PCPROT: useless 'BUSTED' spot") if isdbg('chanerr');
- return;
- }
- if (Spot::dup($field[1], $field[2], $d, $field[5])) {
- dbg("PCPROT: Duplicate Spot ignored\n") if isdbg('chanerr');
- return;
- }
- if ($censorpc) {
- my @bad;
- if (@bad = BadWords::check($field[5])) {
- dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
- return;
- }
- }
-
- my @spot = Spot::prepare($field[1], $field[2], $d, $field[5], $field[6], $field[7]);
- # global spot filtering on INPUT
- if ($self->{inspotsfilter}) {
- my ($filter, $hops) = $self->{inspotsfilter}->it(@spot);
- unless ($filter) {
- dbg("PCPROT: Rejected by input spot filter") if isdbg('chanerr');
- return;
- }
- }
-
- # add it
- Spot::add(@spot);
-
- #
- # @spot at this point contains:-
- # freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
- # then spotted itu, spotted cq, spotters itu, spotters cq
- # you should be able to route on any of these
- #
-
- # fix up qra locators of known users
- my $user = DXUser->get_current($spot[4]);
- if ($user) {
- my $qra = $user->qra;
- unless ($qra && is_qra($qra)) {
- my $lat = $user->lat;
- my $long = $user->long;
- if (defined $lat && defined $long) {
- $user->qra(DXBearing::lltoqra($lat, $long));
- $user->put;
- }
- }
-
- # send a remote command to a distant cluster if it is visible and there is no
- # qra locator and we havn't done it for a month.
-
- unless ($user->qra) {
- my $node;
- my $to = $user->homenode;
- my $last = $user->lastoper || 0;
- if ($send_opernam && $to && $to ne $main::mycall && $main::systime > $last + $DXUser::lastoperinterval && ($node = Route::Node::get($to)) ) {
- my $cmd = "forward/opernam $spot[4]";
- # send the rcmd but we aren't interested in the replies...
- my $dxchan = $node->dxchan;
- if ($dxchan && $dxchan->is_clx) {
- route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
- } else {
- route(undef, $to, pc34($main::mycall, $to, $cmd));
- }
- if ($to ne $field[7]) {
- $to = $field[7];
- $node = Route::Node::get($to);
- if ($node) {
- $dxchan = $node->dxchan;
- if ($dxchan && $dxchan->is_clx) {
- route(undef, $to, pc84($main::mycall, $to, $main::mycall, $cmd));
- } else {
- route(undef, $to, pc34($main::mycall, $to, $cmd));
- }
- }
- }
- $user->lastoper($main::systime);
- $user->put;
- }
- }
- }
-
- # local processing
- my $r;
- eval {
- $r = Local::spot($self, @spot);
- };
-# dbg("Local::spot1 error $@") if isdbg('local') if $@;
- return if $r;
-
- # DON'T be silly and send on PC26s!
- return if $pcno == 26;
-
- # send out the filtered spots
- send_dx_spot($self, $line, @spot) if @spot;
- return;
- }
-
- if ($pcno == 12) { # announces
- # announce duplicate checking
- $field[3] =~ s/^\s+//; # remove leading blanks
- if (AnnTalk::dup($field[1], $field[2], $field[3])) {
- dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
- return;
- }
-
- if ($censorpc) {
- my @bad;
- if (@bad = BadWords::check($field[3])) {
- dbg("PCPROT: Bad words: @bad, dropped") if isdbg('chanerr');
- return;
- }
- }
-
- if ($field[2] eq '*' || $field[2] eq $main::mycall) {
-
- # global ann filtering on INPUT
- if ($self->{inannfilter}) {
- my ($ann_dxcc, $ann_itu, $ann_cq, $org_dxcc, $org_itu, $org_cq) = (0..0);
- my @dxcc = Prefix::extract($field[1]);
- if (@dxcc > 0) {
- $ann_dxcc = $dxcc[1]->dxcc;
- $ann_itu = $dxcc[1]->itu;
- $ann_cq = $dxcc[1]->cq();
- }
- @dxcc = Prefix::extract($field[5]);
- if (@dxcc > 0) {
- $org_dxcc = $dxcc[1]->dxcc;
- $org_itu = $dxcc[1]->itu;
- $org_cq = $dxcc[1]->cq();
- }
- my ($filter, $hops) = $self->{inannfilter}->it(@field[1..6], $self->{call},
- $ann_dxcc, $ann_itu, $ann_cq, $org_dxcc, $org_itu, $org_cq);
- unless ($filter) {
- dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
- return;
- }
- }
-
- # send it
- $self->send_announce($line, @field[1..6]);
- } else {
- $self->route($field[2], $line);
- }
-
- return;
- }
-
- if ($pcno == 13) {
- last SWITCH;
- }
- if ($pcno == 14) {
- last SWITCH;
- }
- if ($pcno == 15) {
- last SWITCH;
- }
-
- if ($pcno == 16) { # add a user
-
- # general checks
- my $dxchan;
- my $ncall = $field[1];
- my $newline = "PC16^";
-
- if ($ncall eq $main::mycall) {
- dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
- return;
- }
- $dxchan = DXChannel->get($ncall);
- if ($dxchan && $dxchan ne $self) {
- dbg("PCPROT: PC16 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
- return;
- }
- my $parent = Route::Node::get($ncall);
- unless ($parent) {
- dbg("PCPROT: Node $ncall not in config") if isdbg('chanerr');
- return;
- }
-
- # input filter if required
- return unless $self->in_filter_route($parent);
-
- my $i;
- my @rout;
- for ($i = 2; $i < $#field; $i++) {
- my ($call, $conf, $here) = $field[$i] =~ /^(\S+) (\S) (\d)/o;
- next unless $call && $conf && defined $here && is_callsign($call);
- next if $call eq $main::mycall;
-
- eph_del_regex("^PC17\^$call\^$ncall");
-
- $conf = $conf eq '*';
-
- # reject this if we think it is a node already
- my $r = Route::Node::get($call);
- my $u = DXUser->get_current($call) unless $r;
- if ($r || ($u && $u->is_node)) {
- dbg("PCPROT: $call is a node") if isdbg('chanerr');
- next;
- }
-
- $r = Route::User::get($call);
- my $flags = Route::here($here)|Route::conf($conf);
-
- if ($r) {
- if ($r->flags != $flags) {
- $r->flags($flags);
- push @rout, $r;
- }
- $r->addparent($parent);
- } else {
- push @rout, $parent->add_user($call, $flags);
- }
-
- # 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($parent->call) if !$user->homenode;
- $user->node($parent->call);
- $user->lastin($main::systime) unless DXChannel->get($call);
- $user->put;
- }
-
- if (eph_dup($line)) {
- dbg("PCPROT: dup PC16 detected") if isdbg('chanerr');
- return;
- }
-
- # queue up any messages (look for privates only)
- DXMsg::queue_msg(1) if $self->state eq 'normal';
-
- $self->route_pc16($parent, @rout) if @rout;
- return;
- }
-
- if ($pcno == 17) { # remove a user
- my $dxchan;
- my $ncall = $field[2];
- my $ucall = $field[1];
-
- eph_del_regex("^PC16.*$ncall.*$ucall");
-
- if ($ncall eq $main::mycall) {
- dbg("PCPROT: trying to alter config on this node from outside!") if isdbg('chanerr');
- return;
- }
- $dxchan = DXChannel->get($ncall);
- if ($dxchan && $dxchan ne $self) {
- dbg("PCPROT: PC17 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
- return;
- }
-
- my $uref = Route::User::get($ucall);
- unless ($uref) {
- dbg("PCPROT: Route::User $ucall not in config") if isdbg('chanerr');
- return;
- }
- my $parent = Route::Node::get($ncall);
- unless ($parent) {
- dbg("PCPROT: Route::Node $ncall not in config") if isdbg('chanerr');
- return;
- }
-
- # input filter if required
- return unless $self->in_filter_route($parent);
-
- my @rout = $parent->del_user($uref);
-
- if (eph_dup($line)) {
- dbg("PCPROT: dup PC17 detected") if isdbg('chanerr');
- return;
- }
-
- $self->route_pc17($parent, @rout) if @rout;
- return;
- }
-
- if ($pcno == 18) { # link request
- $self->state('init');
-
- # first clear out any nodes on this dxchannel
- my $parent = Route::Node::get($self->{call});
- my @rout = $parent->del_nodes;
- $self->route_pc21(@rout, $parent) if @rout;
- $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 $parent = Route::Node::get($self->{call});
- unless ($parent) {
- dbg("DXPROT: my parent $self->{call} has disappeared");
- $self->disconnect;
- return;
- }
-
- # 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);
-
- eph_del_regex("^PC(?:21\^$call|17\^[^\^]+\^$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
- next if $call eq $main::mycall;
-
- # update it if required
- my $r = Route::Node::get($call);
- my $flags = Route::here($here)|Route::conf($conf);
- if ($r) {
- my $ar;
- if ($call ne $parent->call) {
- if ($self->in_filter_route($r)) {
- $ar = $parent->add($call, $ver, $flags);
- push @rout, $ar if $ar;
- } else {
- next;
- }
- }
- if ($r->version ne $ver || $r->flags != $flags) {
- $r->version($ver);
- $r->flags($flags);
- push @rout, $r unless $ar;
- }
- } else {
- if ($call eq $self->{call}) {
- dbg("DXPROT: my channel route for $call has disappeared");
- next;
- };
-
- my $new = Route->new($call); # throw away
- if ($self->in_filter_route($new)) {
- my $r = $parent->add($call, $ver, $flags);
- push @rout, $r;
- } else {
- next;
- }
- }
-
- # 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
- $user->lockout(1);
- $user->homenode($call);
- $user->node($call);
- }
- $user->lastin($main::systime) unless DXChannel->get($call);
- $user->put;
- }
-
- if (eph_dup($line)) {
- dbg("PCPROT: dup PC19 detected") if isdbg('chanerr');
- return;
- }
-
- $self->route_pc19(@rout) if @rout;
- return;
- }
-
- if ($pcno == 20) { # send local configuration
- $self->send_local_config();
- $self->send(pc22());
- $self->state('normal');
- $self->{lastping} = 0;
- return;