+sub dx_spot
+{
+ my $self = shift;
+ my $dxchan = shift;
+ my $quality = shift;
+ my $spot = shift;
+
+ my $strength = 100; # because it could if we talk about FTx
+ my $saver;
+
+ my %zone;
+ my %qrg;
+ my $respot;
+ my $qra;
+
+ foreach my $r (@$spot) {
+ # $r = [$origin, $qrg, $call, $mode, $s, $t, $utz, $respot, $qra];
+ # Spot::prepare($qrg, $call, $utz, $comment, $origin);
+
+ my $comment = sprintf "%-3s %2ddB $quality", $r->[3], $r->[4];
+ $respot = 1 if $r->[7];
+ $qra = $r->[8] if !$qra && $r->[8] && is_qra($r->[8]);
+
+ my $s = $r->[9]; # the prepared spot
+ $s->[3] = $comment; # apply new generated comment
+
+
+ ++$zone{$s->[11]}; # save the spotter's zone
+ ++$qrg{$s->[0]}; # and the qrg
+
+
+ my $want = 0;
+ my $rf = $dxchan->{rbnfilter} || $dxchan->{spotsfilter};
+ if ($rf) {
+ ($want, undef) = $rf->it($s);
+ next unless $want;
+ $saver = $s;
+ dbg("RBN: FILTERED call: $s->[1] qrg: $s->[0] origin: $s->[4] dB: $r->[4]") if isdbg 'rbn';
+ last;
+ }
+
+ # save the lowest strength one
+ if ($r->[4] < $strength) {
+ $strength = $r->[4];
+ $saver = $s;
+ dbg("RBN: STRENGTH call: $s->[1] qrg: $s->[0] origin: $s->[4] dB: $r->[4]") if isdbg 'rbn';
+ }
+ }
+
+ if ($saver) {
+ my $buf;
+ # create a zone list of spotters
+ delete $zone{$saver->[11]}; # remove this spotter's zone (leaving all the other zones)
+ my $z = join ',', sort {$a <=> $b} keys %zone;
+
+ # determine the most likely qrg and then set it
+ my $mv = 0;
+ my $fk;
+ my $c = 0;
+ while (my ($k, $v) = each %qrg) {
+ $fk = $k, $mv = $v if $v > $mv;
+ ++$c;
+ }
+ $saver->[0] = $fk;
+ $saver->[3] .= '*' if $c > 1;
+ $saver->[3] .= '+' if $respot;
+ $saver->[3] .= " Z:$z" if $z;
+
+ dbg("RBN: SENDING call: $saver->[1] qrg: $saver->[0] origin: $saver->[4] $saver->[3]") if isdbg 'rbn';
+ if ($dxchan->{ve7cc}) {
+ my $call = $saver->[4];
+ $saver->[4] .= '-#';
+ $buf = VE7CC::dx_spot($dxchan, @$saver);
+ $saver->[4] = $call;
+ } else {
+ $buf = $dxchan->format_dx_spot(@$saver);
+ }
+ $buf =~ s/^DX/RB/;
+ $dxchan->local_send('N', $buf);
+
+ if ($qra) {
+ my $user = DXUser::get_current($saver->[1]) || DXUser->new($saver->[1]);
+ unless ($user->qra && is_qra($user->qra)) {
+ $user->qra($qra);
+ dbg("RBN: update qra on $saver->[1] to $qra");
+ $user->put;
+ }
+ }
+ }
+}