+# }
+# }
+
+# we should get the spot record minus the time, so just an array of record (arrays)
+sub send_dx_spot
+{
+ my $self = shift;
+ my $quality = shift;
+ my $spot = shift;
+
+ # $r = [$origin, $qrg, $call, $mode, $s, $utz, $respot];
+
+ my $mode = $spot->[0]->[3]; # as all the modes will be the same;
+
+ my @dxchan = DXChannel::get_all();
+
+ foreach my $dxchan (@dxchan) {
+ next unless $dxchan->is_user;
+ my $user = $dxchan->{user};
+ next unless $user && $user->wantrbn;
+
+ # does this user want this sort of spot at all?
+ my $want = 0;
+ ++$want if $user->wantbeacon && $mode =~ /^BCN|DXF/;
+ ++$want if $user->wantcw && $mode =~ /^CW/;
+ ++$want if $user->wantrtty && $mode =~ /^RTT/;
+ ++$want if $user->wantpsk && $mode =~ /^PSK/;
+ ++$want if $user->wantcw && $mode =~ /^CW/;
+ ++$want if $user->wantft && $mode =~ /^FT/;
+ ++$want unless $want; # send everything if nothing is selected.
+
+ next unless $want;
+
+ # send one spot to one user out of the ones that we have
+ $self->dx_spot($dxchan, $quality, $spot) if $want;
+ }
+}
+
+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;
+
+
+ foreach my $r (@$spot) {
+ # $r = [$origin, $qrg, $call, $mode, $s, $t, $utz, $respot];
+ # Spot::prepare($qrg, $call, $utz, $comment, $origin);
+
+ my $comment = sprintf "%-3s %2ddB $quality", $r->[3], $r->[4];
+ my @s = Spot::prepare($r->[1], $r->[2], $r->[6], $comment, $r->[0]);
+ $respot = 1 if $r->[7];
+ ++$zone{$s[11]}; # save the spotter's zone
+ ++$qrg{$s[0]}; # and the qrg
+
+
+ # save the highest 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';
+ }
+
+ my $filter = 0;
+
+ if ($dxchan->{rbnfilter}) {
+ ($filter, undef) = $dxchan->{rbnfilter}->it(\@s);
+ next unless $filter;
+ $saver = \@s;
+ dbg("RBN: FILTERED call: $s[1] qrg: $s[0] origin: $s[4] dB: $r->[4]") if isdbg 'rbn';
+ last;
+ }
+
+ }
+
+ 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}) {
+ $buf = VE7CC::dx_spot($dxchan, @$saver);
+ } else {
+ $buf = $dxchan->format_dx_spot(@$saver);
+ }
+ $buf =~ s/^DX/RB/;
+ $dxchan->local_send('N', $buf);
+ }
+}