public void PlaySoundEffectEndReceive(int transmitOnRadio, float volume, RadioInformation.Modulation modulation)
        {
            if (!_globalSettings.ProfileSettingsStore.GetClientSettingBool(ProfileSettingsKeys.RadioRxEffects_End))
            {
                return;
            }

            var _effectsBuffer = _effectsOutputBuffer[transmitOnRadio];

            _effectsBuffer.VolumeSampleProvider.Volume = volume;
            _effectsBuffer.AddAudioSamples(
                _cachedAudioEffects[(int)CachedAudioEffect.AudioEffectTypes.RADIO_RX].AudioEffectBytes,
                transmitOnRadio);
        }
Beispiel #2
0
        public int ClientsOnFreq(double freq, RadioInformation.Modulation modulation)
        {
            if (!_serverSettings.GetSettingAsBool(ServerSettingsKeys.SHOW_TUNED_COUNT))
            {
                return(0);
            }
            var currentClientPos  = ClientStateSingleton.Instance.PlayerCoaltionLocationMetadata;
            var currentUnitId     = ClientStateSingleton.Instance.DcsPlayerRadioInfo.unitId;
            var coalitionSecurity = SyncedServerSettings.Instance.GetSettingAsBool(ServerSettingsKeys.COALITION_AUDIO_SECURITY);
            var globalFrequencies = _serverSettings.GlobalFrequencies;
            var global            = globalFrequencies.Contains(freq);
            int count             = 0;

            foreach (var client in _clients)
            {
                if (!client.Key.Equals(_guid))
                {
                    // check that either coalition radio security is disabled OR the coalitions match
                    if (global || (!coalitionSecurity || (client.Value.Coalition == currentClientPos.side)))
                    {
                        var radioInfo = client.Value.RadioInfo;

                        if (radioInfo != null)
                        {
                            RadioReceivingState radioReceivingState = null;
                            bool decryptable;
                            var  receivingRadio = radioInfo.CanHearTransmission(freq,
                                                                                modulation,
                                                                                0,
                                                                                false,
                                                                                currentUnitId,
                                                                                new List <int>(),
                                                                                out radioReceivingState,
                                                                                out decryptable);

                            //only send if we can hear!
                            if (receivingRadio != null)
                            {
                                count++;
                            }
                        }
                    }
                }
            }

            return(count);
        }
Beispiel #3
0
        private void ProcessPackets()
        {
            while (!_stop)
            {
                try
                {
                    PendingPacket udpPacket = null;
                    _pendingProcessingPackets.TryTake(out udpPacket, 100000, _pendingProcessingCancellationToken.Token);

                    if (udpPacket != null)
                    {
                        //last 22 bytes are guid!
                        var guid = Encoding.ASCII.GetString(
                            udpPacket.RawBytes, udpPacket.RawBytes.Length - 22, 22);

                        if (_clientsList.ContainsKey(guid))
                        {
                            var client = _clientsList[guid];
                            client.VoipPort = udpPacket.ReceivedFrom;

                            var spectatorAudioDisabled =
                                _serverSettings.GetGeneralSetting(ServerSettingsKeys.SPECTATORS_AUDIO_DISABLED).BoolValue;

                            if ((client.Coalition == 0 && spectatorAudioDisabled) || client.Muted)
                            {
                                // IGNORE THE AUDIO
                            }
                            else
                            {
                                try
                                {
                                    //decode
                                    var udpVoicePacket = UDPVoicePacket.DecodeVoicePacket(udpPacket.RawBytes);

                                    if (udpVoicePacket != null)
                                    //magical ping ignore message 4 - its an empty voip packet to intialise VoIP if
                                    //someone doesnt transmit
                                    {
                                        var outgoingVoice = GenerateOutgoingPacket(udpVoicePacket, udpPacket, client);

                                        if (outgoingVoice != null)
                                        {
                                            //Add to the processing queue
                                            _outGoing.Add(outgoingVoice);

                                            //mark as transmitting for the UI
                                            double mainFrequency = udpVoicePacket.Frequencies.FirstOrDefault();
                                            // Only trigger transmitting frequency update for "proper" packets (excluding invalid frequencies and magic ping packets with modulation 4)
                                            if (mainFrequency > 0)
                                            {
                                                RadioInformation.Modulation mainModulation = (RadioInformation.Modulation)udpVoicePacket.Modulations[0];
                                                if (mainModulation == RadioInformation.Modulation.INTERCOM)
                                                {
                                                    client.TransmittingFrequency = "INTERCOM";
                                                }
                                                else
                                                {
                                                    client.TransmittingFrequency = $"{(mainFrequency / 1000000).ToString("0.000", CultureInfo.InvariantCulture)} {mainModulation}";
                                                }
                                                client.LastTransmissionReceived = DateTime.Now;
                                            }
                                        }
                                    }
                                }
                                catch (Exception)
                                {
                                    //Hide for now, slows down loop to much....
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Info("Failed to Process UDP Packet: " + ex.Message);
                }
            }
        }
Beispiel #4
0
        public RadioInformation CanHearTransmission(double frequency,
                                                    RadioInformation.Modulation modulation,
                                                    byte encryptionKey,
                                                    uint sendingUnitId,
                                                    List <int> blockedRadios,
                                                    out RadioReceivingState receivingState,
                                                    out bool decryptable)
        {
            if (!IsCurrent())
            {
                receivingState = null;
                decryptable    = false;
                return(null);
            }

            RadioInformation    bestMatchingRadio      = null;
            RadioReceivingState bestMatchingRadioState = null;
            bool bestMatchingDecryptable = false;

            for (var i = 0; i < radios.Length; i++)
            {
                var receivingRadio = radios[i];

                if (receivingRadio != null)
                {
                    //handle INTERCOM Modulation is 2
                    if ((receivingRadio.modulation == RadioInformation.Modulation.INTERCOM) &&
                        (modulation == RadioInformation.Modulation.INTERCOM))
                    {
                        if ((unitId > 0) && (sendingUnitId > 0) &&
                            (unitId == sendingUnitId))
                        {
                            receivingState = new RadioReceivingState
                            {
                                IsSecondary    = false,
                                LastReceviedAt = DateTime.Now.Ticks,
                                ReceivedOn     = i
                            };
                            decryptable = true;
                            return(receivingRadio);
                        }
                        decryptable    = false;
                        receivingState = null;
                        return(null);
                    }

                    if (modulation == RadioInformation.Modulation.DISABLED ||
                        receivingRadio.modulation == RadioInformation.Modulation.DISABLED)
                    {
                        continue;
                    }

                    //within 1khz
                    if ((FreqCloseEnough(receivingRadio.freq, frequency)) &&
                        (receivingRadio.modulation == modulation) &&
                        (receivingRadio.freq > 10000))
                    {
                        bool isDecryptable = (encryptionKey == 0 || (receivingRadio.enc ? receivingRadio.encKey : (byte)0) == encryptionKey);

                        if (isDecryptable && !blockedRadios.Contains(i))
                        {
                            receivingState = new RadioReceivingState
                            {
                                IsSecondary    = false,
                                LastReceviedAt = DateTime.Now.Ticks,
                                ReceivedOn     = i
                            };
                            decryptable = true;
                            return(receivingRadio);
                        }

                        bestMatchingRadio      = receivingRadio;
                        bestMatchingRadioState = new RadioReceivingState
                        {
                            IsSecondary    = false,
                            LastReceviedAt = DateTime.Now.Ticks,
                            ReceivedOn     = i
                        };
                        bestMatchingDecryptable = isDecryptable;
                    }
                    if ((receivingRadio.secFreq == frequency) &&
                        (receivingRadio.secFreq > 10000))
                    {
                        if (encryptionKey == 0 || (receivingRadio.enc ? receivingRadio.encKey : (byte)0) == encryptionKey)
                        {
                            receivingState = new RadioReceivingState
                            {
                                IsSecondary    = true,
                                LastReceviedAt = DateTime.Now.Ticks,
                                ReceivedOn     = i
                            };
                            decryptable = true;
                            return(receivingRadio);
                        }

                        bestMatchingRadio      = receivingRadio;
                        bestMatchingRadioState = new RadioReceivingState
                        {
                            IsSecondary    = true,
                            LastReceviedAt = DateTime.Now.Ticks,
                            ReceivedOn     = i
                        };
                    }
                }
            }

            decryptable    = bestMatchingDecryptable;
            receivingState = bestMatchingRadioState;
            return(bestMatchingRadio);
        }
        public RadioInformation CanHearTransmission(double frequency,
                                                    RadioInformation.Modulation modulation,
                                                    long sendingUnitId,
                                                    long sendingVehicleId,
                                                    List <int> blockedRadios,
                                                    out RadioReceivingState receivingState)
        {
            RadioInformation    bestMatchingRadio      = null;
            RadioReceivingState bestMatchingRadioState = null;

            for (var i = 0; i < radios.Length; i++)
            {
                var receivingRadio = radios[i];

                if (receivingRadio != null)
                {
                    //handle INTERCOM Modulation is 2
                    if ((receivingRadio.modulation == RadioInformation.Modulation.INTERCOM) &&
                        (modulation == RadioInformation.Modulation.INTERCOM))
                    {
                        if (((unitId == vehicleId && unitId > -1) ||
                             (vehicleId == sendingVehicleId && vehicleId > -1)))
                        {
                            receivingState = new RadioReceivingState
                            {
                                IsSecondary    = false,
                                LastReceivedAt = DateTime.Now.Ticks,
                                ReceivedOn     = i
                            };
                            return(receivingRadio);
                        }
                        receivingState = null;
                        return(null);
                    }

                    if (modulation == RadioInformation.Modulation.DISABLED ||
                        receivingRadio.modulation == RadioInformation.Modulation.DISABLED)
                    {
                        continue;
                    }

                    //within 1khz
                    if ((FreqCloseEnough(receivingRadio.freq, frequency)) &&
                        (receivingRadio.modulation == modulation) &&
                        (receivingRadio.freq > 10000))
                    {
                        if (!blockedRadios.Contains(i))
                        {
                            receivingState = new RadioReceivingState
                            {
                                IsSecondary    = false,
                                LastReceivedAt = DateTime.Now.Ticks,
                                ReceivedOn     = i
                            };
                            return(receivingRadio);
                        }

                        bestMatchingRadio      = receivingRadio;
                        bestMatchingRadioState = new RadioReceivingState
                        {
                            IsSecondary    = false,
                            LastReceivedAt = DateTime.Now.Ticks,
                            ReceivedOn     = i
                        };
                    }
                }
            }
            receivingState = bestMatchingRadioState;
            return(bestMatchingRadio);
        }
        public RadioInformation CanHearTransmission(double frequency, RadioInformation.Modulation modulation,
                                                    uint sendingUnitId,
                                                    out RadioReceivingState receivingState)
        {
            if (!IsCurrent())
            {
                receivingState = null;
                return(null);
            }
            for (var i = 0; i < radios.Length; i++)
            {
                var receivingRadio = radios[i];

                if (receivingRadio != null)
                {
                    //handle INTERCOM Modulation is 2
                    if ((receivingRadio.modulation == RadioInformation.Modulation.INTERCOM) &&
                        (modulation == RadioInformation.Modulation.INTERCOM))
                    {
                        if ((unitId > 0) && (sendingUnitId > 0) &&
                            (unitId == sendingUnitId))
                        {
                            receivingState = new RadioReceivingState
                            {
                                IsSecondary    = false,
                                LastReceviedAt = DateTime.Now.Ticks,
                                ReceivedOn     = i
                            };


                            return(receivingRadio);
                        }
                        receivingState = null;
                        return(null);
                    }

                    if (modulation == RadioInformation.Modulation.DISABLED ||
                        receivingRadio.modulation == RadioInformation.Modulation.DISABLED)
                    {
                        continue;
                    }

                    if ((receivingRadio.freq == frequency) &&
                        (receivingRadio.modulation == modulation) &&
                        (receivingRadio.freq > 10000))
                    {
                        receivingState = new RadioReceivingState
                        {
                            IsSecondary    = false,
                            LastReceviedAt = DateTime.Now.Ticks,
                            ReceivedOn     = i
                        };

                        return(receivingRadio);
                    }
                    if ((receivingRadio.secFreq == frequency) &&
                        (receivingRadio.secFreq > 10000))
                    {
                        receivingState = new RadioReceivingState
                        {
                            IsSecondary    = true,
                            LastReceviedAt = DateTime.Now.Ticks,
                            ReceivedOn     = i
                        };

                        return(receivingRadio);
                    }
                }
            }
            receivingState = null;
            return(null);
        }
Beispiel #7
0
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            var byteBuffer = message as IByteBuffer;

            if (byteBuffer != null)
            {
                byte[] udpData = new byte[byteBuffer.ReadableBytes];
                byteBuffer.GetBytes(0, udpData);

                var decodedPacket = UDPVoicePacket.DecodeVoicePacket(udpData, false);

                SRClient srClient;
                if (_clientsList.TryGetValue(decodedPacket.Guid, out srClient))
                {
                    srClient.ClientChannelId = context.Channel.Id.AsShortText();

                    var spectatorAudioDisabled =
                        _serverSettings.GetGeneralSetting(ServerSettingsKeys.SPECTATORS_AUDIO_DISABLED).BoolValue;

                    if ((srClient.Coalition == 0 && spectatorAudioDisabled) || srClient.Muted)
                    {
                        byteBuffer.Release();
                        return;
                    }
                    else
                    {
                        HashSet <string> matchingClients = new HashSet <string>();

                        for (int i = 0; i < decodedPacket.Frequencies.Length; i++)
                        {
                            // Magical ignore message 4 - just used for ping
                            if (decodedPacket.Modulations[0] == 4)
                            {
                                continue;
                            }

                            var coalitionSecurity =
                                _serverSettings.GetGeneralSetting(ServerSettingsKeys.COALITION_AUDIO_SECURITY).BoolValue;

                            foreach (KeyValuePair <string, SRClient> _client in _clientsList)
                            {
                                //dont send to receiver
                                if (_client.Value.ClientGuid != decodedPacket.Guid)
                                {
                                    //check frequencies
                                    if ((!coalitionSecurity || (_client.Value.Coalition == srClient.Coalition)))
                                    {
                                        var radioInfo = _client.Value.RadioInfo;

                                        if (radioInfo != null)
                                        {
                                            RadioReceivingState radioReceivingState = null;
                                            bool decryptable;
                                            var  receivingRadio = radioInfo.CanHearTransmission(decodedPacket.Frequencies[i],
                                                                                                (RadioInformation.Modulation)decodedPacket.Modulations[i],
                                                                                                decodedPacket.Encryptions[i],
                                                                                                decodedPacket.UnitId,
                                                                                                emptyBlockedRadios,
                                                                                                out radioReceivingState,
                                                                                                out decryptable);

                                            //only send if we can hear!
                                            if (receivingRadio != null && !matchingClients.Contains(_client.Value.ClientChannelId))
                                            {
                                                matchingClients.Add(_client.Value.ClientChannelId);
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        double mainFrequency = decodedPacket.Frequencies.FirstOrDefault();
                        // Only trigger transmitting frequency update for "proper" packets (excluding invalid frequencies and magic ping packets with modulation 4)
                        if (mainFrequency > 0 && decodedPacket.Modulations[0] != 4)
                        {
                            RadioInformation.Modulation mainModulation = (RadioInformation.Modulation)decodedPacket.Modulations[0];
                            if (mainModulation == RadioInformation.Modulation.INTERCOM)
                            {
                                srClient.TransmittingFrequency = "INTERCOM";
                            }
                            else
                            {
                                srClient.TransmittingFrequency = $"{(mainFrequency / 1000000).ToString("0.000", CultureInfo.InvariantCulture)} {mainModulation}";
                            }
                            srClient.LastTransmissionReceived = DateTime.Now;
                        }

                        //send to other connected clients
                        if (matchingClients.Count > 0)
                        {
                            group.WriteAndFlushAsync(message, new AllMatchingChannels(matchingClients));
                        }
                        else
                        {
                            byteBuffer.Release();
                        }
                    }
                }
                else
                {
                    byteBuffer.Release();
                }
            }
        }