- my ($self, $line) = @_;
- my @field = split /[\^\~]/, $line;
-
- # ignore any lines that don't start with PC
- return if !$field[0] =~ /^PC/;
-
- # process PC frames
- my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
- return if $pcno < 10 || $pcno > 51;
-
- SWITCH: {
- if ($pcno == 10) { # incoming talk
-
- # is it for me or one of mine?
- my $call = ($field[5] gt ' ') ? $field[5] : $field[2];
- if ($call eq $main::mycall || grep $_ eq $call, get_all_user_calls()) {
-
- # yes, it is
- my $text = unpad($field[3]);
- my $ref = DXChannel->get($call);
- $ref->send("$call de $field[1]: $text") if $ref;
- } else {
- route($field[2], $line); # relay it on its way
- }
- return;
- }
-
- if ($pcno == 11 || $pcno == 26) { # dx spot
-
- # if this is a 'nodx' node then ignore it
- last SWITCH if grep $field[7] =~ /^$_/, @DXProt::nodx_node;
-
- # convert the date to a unix date
- my $d = cltounix($field[3], $field[4]);
- return if !$d || ($pcno == 11 && $d < $main::systime - $pc11_max_age); # bang out (and don't pass on) if date is invalid or the spot is too old
-
- # strip off the leading & trailing spaces from the comment
- my $text = unpad($field[5]);
-
- # store it away
- my $spotter = $field[6];
- $spotter =~ s/-\d+$//o; # strip off the ssid from the spotter
-
- # do some de-duping
- my $dupkey = "$field[1]$field[2]$d$text$field[6]";
- return if $dup{$dupkey};
- $dup{$dupkey} = $d;
-
- my $spot = Spot::add($field[1], $field[2], $d, $text, $spotter);
-
- # send orf to the users
- if ($spot && $pcno == 11) {
- my $buf = Spot::formatb($field[1], $field[2], $d, $text, $spotter);
- broadcast_users("$buf\a\a");
- }
-
- last SWITCH;
- }
-
- if ($pcno == 12) { # announces
-
- if ($field[2] eq '*' || $field[2] eq $main::mycall) {
-
- # strip leading and trailing stuff
- my $text = unpad($field[3]);
- my $target;
- my @list;
+ my ($self, $line) = @_;
+ my @field = split /\^/, $line;
+ return unless @field;
+
+ pop @field if $field[-1] eq '~';
+
+# print join(',', @field), "\n";
+
+
+ # process PC frames, this will fail unless the frame starts PCnn
+ my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
+ return unless $pcno;
+ return if $pcno < 10 || $pcno > 99;
+
+ # check for and dump bad protocol messages
+ my $n = check($pcno, @field);
+ if ($n) {
+ dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
+ return;
+ }
+
+ # 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
+
+ # rsfp check
+ return if $rspfcheck and !$self->rspfcheck(0, $field[6], $field[1]);
+
+ # 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 ($from, $to, $via, $call, $dxchan);
+ $from = $field[1];
+ if ($field[5] gt ' ') {
+ $via = $field[2];
+ $to = $field[5];
+ } else {
+ $to = $field[2];
+ }
+
+ # if we are converting announces to talk is it a dup?
+ if ($ann_to_talk) {
+ if (AnnTalk::is_talk_candidate($from, $field[3]) && AnnTalk::dup($from, $to, $field[3])) {
+ dbg("DXPROT: Dupe talk from announce, dropped") if isdbg('chanerr');
+ return;
+ }
+ }
+
+ # it is here and logged on
+ $dxchan = DXChannel->get($main::myalias) if $to eq $main::mycall;
+ $dxchan = DXChannel->get($to) unless $dxchan;
+ if ($dxchan && $dxchan->is_user) {
+ $field[3] =~ s/\%5E/^/g;
+ $dxchan->talk($from, $to, $via, $field[3]);
+ return;
+ }
+
+ # is it elsewhere, visible on the cluster via the to address?
+ # note: this discards the via unless the to address is on
+ # the via address
+ my ($ref, $vref);
+ if ($ref = Route::get($to)) {
+ $vref = Route::Node::get($via) if $via;
+ $vref = undef unless $vref && grep $to eq $_, $vref->users;
+ $ref->dxchan->talk($from, $to, $vref ? $via : undef, $field[3], $field[6]);
+ return;
+ }
+
+ # not visible here, send a message of condolence
+ $vref = undef;
+ $ref = Route::get($from);
+ $vref = $ref = Route::Node::get($field[6]) unless $ref;
+ if ($ref) {
+ $dxchan = $ref->dxchan;
+ $dxchan->talk($main::mycall, $from, $vref ? $vref->call : undef, $dxchan->msg('talknh', $to) );
+ }
+ 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;
+ }
+ }
+
+ # rsfp check
+# return if $rspfcheck and !$self->rspfcheck(1, $field[7], $field[6]);
+
+ # 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]) || BadWords::check($field[2]) || $field[2] =~ /COCK/) {
+ 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 ($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;
+ }
+ }
+
+ if (Spot::dup($field[1], $field[2], $d, $field[5])) {
+ dbg("PCPROT: Duplicate Spot ignored\n") 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
+
+# return if $rspfcheck and !$self->rspfcheck(1, $field[5], $field[1]);
+
+ # announce duplicate checking
+ $field[3] =~ s/^\s+//; # remove leading blanks
+
+ 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) {
+
+
+ # here's a bit of fun, convert incoming ann with a callsign in the first word
+ # or one saying 'to <call>' to a talk if we can route to the recipient
+ if ($ann_to_talk) {
+ my $call = AnnTalk::is_talk_candidate($field[1], $field[3]);
+ if ($call) {
+ my $ref = Route::get($call);
+ if ($ref) {
+ my $dxchan = $ref->dxchan;
+ $dxchan->talk($field[1], $call, undef, $field[3], $field[5]) if $dxchan != $self;
+ return;
+ }
+ }
+ }
+
+ # send it
+ $self->send_announce($line, @field[1..6]);
+ } else {
+ $self->route($field[2], $line);
+ }
+ return;
+ }