public SRSClientSyncHandler(string guid, DCSPlayerRadioInfo gameState, string name, int coalition)
 {
     _guid          = guid;
     this.gameState = gameState;
     this.name      = name;
     this.coalition = coalition;
 }
        } = new VAICOMMessageWrapper();                                                   //used to temporarily stop PTT for VAICOM

        private ClientStateSingleton()
        {
            ShortGUID                      = ShortGuid.NewGuid();
            DcsPlayerRadioInfo             = new DCSPlayerRadioInfo();
            PlayerCoaltionLocationMetadata = new DCSPlayerSideInfo();

            // The following members are not updated due to events. Therefore we need to setup a polling action so that they are
            // periodically checked.
            DcsGameGuiLastReceived = 0;
            DcsExportLastReceived  = 0;
            _timer.Interval        = TimeSpan.FromSeconds(1);
            _timer.Tick           += (s, e) => {
                NotifyPropertyChanged("IsGameConnected");
                NotifyPropertyChanged("IsLotATCConnected");
                NotifyPropertyChanged("ExternalAWACSModeConnected");
            };
            _timer.Start();

            FixedChannels = new PresetChannelsViewModel[10];

            for (int i = 0; i < FixedChannels.Length; i++)
            {
                FixedChannels[i] = new PresetChannelsViewModel(new FilePresetChannelsStore(), i + 1);
            }

            LastSent = 0;

            IsConnected = false;
            ExternalAWACSModelSelected = false;

            LastSeenName = Settings.GlobalSettingsStore.Instance.GetClientSetting(Settings.GlobalSettingsKeys.LastSeenName).StringValue;
        }
        public void Start()
        {
            MessageHub.Instance.Subscribe <ReadyMessage>(ReadyToSend);
            MessageHub.Instance.Subscribe <DisconnectedMessage>(Disconnected);

            gameState = new DCSPlayerRadioInfo();
            gameState.radios[1].modulation = modulation[0];
            gameState.radios[1].freq       = freq[0]; // get into Hz
            gameState.radios[1].name       = name;

            Logger.Info($"Starting with params:");
            Logger.Info($"Path or Text to Say: {mp3Path} ");
            for (int i = 0; i < freq.Length; i++)
            {
                Logger.Info($"Frequency: {freq[i]} Hz - {modulation[i]} ");
            }
            Logger.Info($"Coalition: {coalition} ");
            Logger.Info($"IP: 127.0.0.1 ");
            Logger.Info($"Port: {port} ");
            Logger.Info($"Client Name: {name} ");
            Logger.Info($"Volume: {volume} ");

            var srsClientSyncHandler = new SRSClientSyncHandler(Guid, gameState, name, coalition);

            srsClientSyncHandler.TryConnect(new IPEndPoint(IPAddress.Loopback, port));

            //wait for it to end
            finished.Token.WaitHandle.WaitOne();
            Logger.Info("Finished - Closing");

            udpVoiceHandler?.RequestStop();
            srsClientSyncHandler?.Disconnect();

            MessageHub.Instance.ClearSubscriptions();
        }
        private ClientStateSingleton()
        {
            DcsPlayerRadioInfo = new DCSPlayerRadioInfo();
            DcsPlayerSideInfo  = new DCSPlayerSideInfo();

            DcsGameGuiLastReceived = 0;
            DcsExportLastReceived  = 0;

            FixedChannels = new PresetChannelsViewModel[10];

            for (int i = 0; i < FixedChannels.Length; i++)
            {
                FixedChannels[i] = new PresetChannelsViewModel(new FilePresetChannelsStore(), i + 1);
            }

            MicrophoneAvailable = true;

            LastSent = 0;

            IsConnected = false;

            InExternalAWACSMode = false;

            LastSeenName = Settings.SettingsStore.Instance.GetClientSetting(Settings.SettingsKeys.LastSeenName).StringValue;
        }
Beispiel #5
0
        private bool IsRadioInfoStale(DCSPlayerRadioInfo radioUpdate)
        {
            //send update if our metadata is nearly stale
            if (Environment.TickCount - LastSent < 5000)
            {
                return(false);
            }

            return(true);
        }
Beispiel #6
0
        public UdpVoiceHandler(string guid, IPAddress address, int port, DCSPlayerRadioInfo gameState)
        {
            _guidAsciiBytes = Encoding.ASCII.GetBytes(guid);

            _address       = address;
            _port          = port;
            this.gameState = gameState;

            _serverEndpoint = new IPEndPoint(_address, _port);
        }
Beispiel #7
0
        public AudioManager(DCSPlayerRadioInfo playerRadioInfo)
        {
            PlayerRadioInfo = playerRadioInfo;
            LogClientId     = PlayerRadioInfo.radios[0].name;
            Client          = new Network.Client(this, playerRadioInfo);

            BotAudioProvider = new BotAudioProvider(Client.DcsPlayerRadioInfo.radios[0], ResponseQueue)
            {
                SpeechRecognitionListener = { VoiceHandler = Client.SrsAudioClient, SrsClient = Client }
            };
        }
Beispiel #8
0
 private bool IsRadioInfoStale(DCSPlayerRadioInfo radioUpdate)
 {
     //send update if our metadata is nearly stale (1 tick = 100ns, 50000000 ticks = 5s stale timer)
     if (DateTime.Now.Ticks - _clientStateSingleton.LastSent < 50000000)
     {
         Logger.Debug($"Not Stale - Tick: {DateTime.Now.Ticks} Last sent: {_clientStateSingleton.LastSent} ");
         return(false);
     }
     Logger.Debug($"Stale Radio - Tick: {DateTime.Now.Ticks} Last sent: {_clientStateSingleton.LastSent} ");
     return(true);
 }
        private ClientStateSingleton()
        {
            DcsPlayerRadioInfo = new DCSPlayerRadioInfo();
            DcsPlayerSideInfo  = new DCSPlayerSideInfo();

            FixedChannels = new PresetChannelsViewModel[10];

            for (int i = 0; i < FixedChannels.Length; i++)
            {
                FixedChannels[i] = new PresetChannelsViewModel(new FilePresetChannelsStore(), i + 1);
            }
        }
Beispiel #10
0
        /**
         * Used to determine if we should send an update to the server or not
         * We only need to do that if something that would stop us Receiving happens which
         * is frequencies and modulation
         */

        public override bool Equals(object obj)
        {
            if ((obj == null) || (GetType() != obj.GetType()))
            {
                return(false);
            }

            var compare = (RadioInformation)obj;

            if (!name.Equals(compare.name))
            {
                return(false);
            }
            if (!DCSPlayerRadioInfo.FreqCloseEnough(freq, compare.freq))
            {
                return(false);
            }
            if (modulation != compare.modulation)
            {
                return(false);
            }
            if (enc != compare.enc)
            {
                return(false);
            }
            if (encKey != compare.encKey)
            {
                return(false);
            }
            if (!DCSPlayerRadioInfo.FreqCloseEnough(secFreq, compare.secFreq))
            {
                return(false);
            }
            //if (volume != compare.volume)
            //{
            //    return false;
            //}
            //if (freqMin != compare.freqMin)
            //{
            //    return false;
            //}
            //if (freqMax != compare.freqMax)
            //{
            //    return false;
            //}


            return(true);
        }
        public void ProcessRadioInfo(DCSPlayerRadioInfo message)
        {
            var update = UpdateRadio(message);

            //send to DCS UI
            SendRadioUpdateToDCS();

            Logger.Debug("Update sent to DCS");

            if (update || IsRadioInfoStale(message))
            {
                Logger.Debug("Sending Radio Info To Server - Stale");
                _clientStateSingleton.LastSent = DateTime.Now.Ticks;
                _radioUpdate();
            }
        }
        private void HandleEncryptionSettingsFullFidelity(DCSPlayerRadioInfo radioUpdate)
        {
            // handle encryption type
            for (var i = 0; i < radioUpdate.radios.Length; i++)
            {
                var updatedRadio = radioUpdate.radios[i];
                var currentRadio = DcsPlayerRadioInfo.radios[i];

                if (updatedRadio.encMode == RadioInformation.EncryptionMode.ENCRYPTION_COCKPIT_TOGGLE_OVERLAY_CODE)
                {
                    if (currentRadio.encKey != 0)
                    {
                        updatedRadio.encKey = currentRadio.encKey;
                    }
                }
            }
        }
Beispiel #13
0
        public Client(AudioManager audioManager, DCSPlayerRadioInfo playerRadioInfo)
        {
            AudioManager       = audioManager;
            ShortGuid          = Ciribob.DCS.SimpleRadio.Standalone.Common.Network.ShortGuid.NewGuid();
            DcsPlayerRadioInfo = playerRadioInfo;
            PlayerCoalitionLocationMetadata = new DCSPlayerSideInfo();
            SrsDataClient = new SrsDataClient(this);

            LogClientId = audioManager.LogClientId;

            ExternalAwacsModePassword = playerRadioInfo.radios.First().coalitionPassword;

            LastSent = 0;

            IsDataConnected           = false;
            ExternalAwacsModeSelected = false;

            LastSeenName = playerRadioInfo.name;
        }
Beispiel #14
0
        public void UpdateClientRadio(StationClient statClient)
        {
            DCSPlayerRadioInfo radioInfo = statClient.Client.RadioInfo;

            var frequencies = new List <double>(1);
            var encryptions = new List <byte>(1);
            var modulations = new List <byte>(1);

            if (radioInfo != null)
            {
                frequencies.Add(radioInfo.radios[0].freq);
                encryptions.Add(radioInfo.radios[0].enc ? radioInfo.radios[0].encKey : (byte)0);
                modulations.Add((byte)radioInfo.radios[0].modulation);

                musicClient.UnitId      = radioInfo.unitId;
                musicClient.Frequencies = frequencies;
                musicClient.Encryptions = encryptions;
                musicClient.Modulations = modulations;
            }
        }
        public void ProcessRadioInfo(DCSPlayerRadioInfo message)
        {
            // determine if its changed by comparing old to new
            var update = UpdateRadio(message);

            //send to DCS UI
            SendRadioUpdateToDCS();

            Logger.Debug("Update sent to DCS");

            var diff = new TimeSpan(DateTime.Now.Ticks - _clientStateSingleton.LastSent);

            if (update ||
                _clientStateSingleton.LastSent < 1 ||
                diff.TotalSeconds > 60)
            {
                Logger.Debug("Sending Radio Info To Server - Update");
                _clientStateSingleton.LastSent = DateTime.Now.Ticks;
                _radioUpdate();
            }
        }
Beispiel #16
0
        public StationClient(int num, IPEndPoint endPoint)
        {
            stationNumber  = num;
            serverEndpoint = endPoint;

            var name = "SR-MUSIC Station " + (stationNumber + 1).ToString();

            DCSPlayerRadioInfo radioInfo = new DCSPlayerRadioInfo();

            radioInfo.unit = name;

            Client = new SRClient
            {
                Name       = name,
                Coalition  = 2,
                ClientGuid = ShortGuid.NewGuid().ToString(),
                Position   = new DCSPosition {
                    x = 0, y = 0, z = 0
                },
                LatLngPosition = new DCSLatLngPosition(),
                RadioInfo      = radioInfo
            };
        }
Beispiel #17
0
        public Client(AudioManager audioManager, DCSPlayerRadioInfo playerRadioInfo)
        {
            AudioManager       = audioManager;
            ShortGuid          = Ciribob.DCS.SimpleRadio.Standalone.Common.Network.ShortGuid.NewGuid();
            DcsPlayerRadioInfo = playerRadioInfo;
            PlayerCoalitionLocationMetadata = new DCSPlayerSideInfo();
            SrsDataClient = new SrsDataClient(this);

            LogClientId = audioManager.LogClientId;

            ExternalAwacsModePassword = playerRadioInfo.radios.First().coalitionPassword;

            LastSent = 0;

            IsDataConnected           = false;
            ExternalAwacsModeSelected = false;

            LastSeenName = playerRadioInfo.name;

            _connectionMonitorTimer = new DispatcherTimer {
                Interval = TimeSpan.FromSeconds(1)
            };
            _connectionMonitorTimer.Tick += MonitorConnectionStatus;
        }
        public void Start()
        {
            MessageHub.Instance.Subscribe <ReadyMessage>(ReadyToSend);
            MessageHub.Instance.Subscribe <DisconnectedMessage>(Disconnected);

            gameState = new DCSPlayerRadioInfo();
            gameState.radios[1].modulation = modulation[0];
            gameState.radios[1].freq       = freq[0]; // get into Hz
            gameState.radios[1].name       = opts.Name;

            Logger.Info($"Starting with params:");
            for (int i = 0; i < freq.Length; i++)
            {
                Logger.Info($"Frequency: {freq[i]} Hz - {modulation[i]} ");
            }

            DCSLatLngPosition position = new DCSLatLngPosition()
            {
                alt = opts.Altitude,
                lat = opts.Latitude,
                lng = opts.Longitude
            };

            var srsClientSyncHandler = new SRSClientSyncHandler(Guid, gameState, opts.Name, opts.Coalition, position);

            srsClientSyncHandler.TryConnect(new IPEndPoint(IPAddress.Loopback, opts.Port));

            //wait for it to end
            finished.Token.WaitHandle.WaitOne();
            Logger.Info("Finished - Closing");

            udpVoiceHandler?.RequestStop();
            srsClientSyncHandler?.Disconnect();

            MessageHub.Instance.ClearSubscriptions();
        }
        private bool UpdateRadio(DCSPlayerRadioInfo message)
        {
            var changed = false;

            var expansion = _serverSettings.GetSettingAsBool(ServerSettingsKeys.RADIO_EXPANSION);

            var playerRadioInfo = _clientStateSingleton.DcsPlayerRadioInfo;

            //update common parts
            playerRadioInfo.name           = message.name;
            playerRadioInfo.inAircraft     = message.inAircraft;
            playerRadioInfo.intercomHotMic = message.intercomHotMic;

            if (_globalSettings.ProfileSettingsStore.GetClientSettingBool(ProfileSettingsKeys.AlwaysAllowHotasControls))
            {
                message.control         = DCSPlayerRadioInfo.RadioSwitchControls.HOTAS;
                playerRadioInfo.control = DCSPlayerRadioInfo.RadioSwitchControls.HOTAS;
            }
            else
            {
                playerRadioInfo.control = message.control;
            }

            playerRadioInfo.simultaneousTransmissionControl = message.simultaneousTransmissionControl;

            playerRadioInfo.unit = message.unit;


            if (!_clientStateSingleton.ShouldUseLotATCPosition())
            {
                _clientStateSingleton.UpdatePlayerPosition(message.pos, message.latLng);
            }

            var overrideFreqAndVol = false;

            var newAircraft = playerRadioInfo.unitId != message.unitId || !playerRadioInfo.IsCurrent();

            if (message.unitId >= DCSPlayerRadioInfo.UnitIdOffset &&
                playerRadioInfo.unitId >= DCSPlayerRadioInfo.UnitIdOffset)
            {
                //overriden so leave as is
            }
            else
            {
                overrideFreqAndVol     = playerRadioInfo.unitId != message.unitId;
                playerRadioInfo.unitId = message.unitId;
            }

            if (newAircraft)
            {
                if (_globalSettings.GetClientSettingBool(GlobalSettingsKeys.AutoSelectSettingsProfile))
                {
                    _newAircraftCallback(message.unit);
                }

                playerRadioInfo.iff = message.iff;
            }

            if (overrideFreqAndVol)
            {
                playerRadioInfo.selected = message.selected;
                changed = true;
            }

            if (playerRadioInfo.control == DCSPlayerRadioInfo.RadioSwitchControls.IN_COCKPIT)
            {
                playerRadioInfo.selected = message.selected;
            }

            bool simul = false;


            //copy over radio names, min + max
            for (var i = 0; i < playerRadioInfo.radios.Length; i++)
            {
                var clientRadio = playerRadioInfo.radios[i];

                //if awacs NOT open -  disable radios over 3
                if (i >= message.radios.Length ||
                    (RadioOverlayWindow.AwacsActive == false &&
                     (i > 3 || i == 0)
                     // disable intercom and all radios over 3 if awacs panel isnt open and we're a spectator given by the UnitId
                     && playerRadioInfo.unitId >= DCSPlayerRadioInfo.UnitIdOffset))
                {
                    clientRadio.freq       = 1;
                    clientRadio.freqMin    = 1;
                    clientRadio.freqMax    = 1;
                    clientRadio.secFreq    = 0;
                    clientRadio.modulation = RadioInformation.Modulation.DISABLED;
                    clientRadio.name       = "No Radio";

                    clientRadio.freqMode      = RadioInformation.FreqMode.COCKPIT;
                    clientRadio.guardFreqMode = RadioInformation.FreqMode.COCKPIT;
                    clientRadio.encMode       = RadioInformation.EncryptionMode.NO_ENCRYPTION;
                    clientRadio.volMode       = RadioInformation.VolumeMode.COCKPIT;

                    continue;
                }

                var updateRadio = message.radios[i];


                if ((updateRadio.expansion && !expansion) ||
                    (updateRadio.modulation == RadioInformation.Modulation.DISABLED))
                {
                    //expansion radio, not allowed
                    clientRadio.freq       = 1;
                    clientRadio.freqMin    = 1;
                    clientRadio.freqMax    = 1;
                    clientRadio.secFreq    = 0;
                    clientRadio.modulation = RadioInformation.Modulation.DISABLED;
                    clientRadio.name       = "No Radio";

                    clientRadio.freqMode      = RadioInformation.FreqMode.COCKPIT;
                    clientRadio.guardFreqMode = RadioInformation.FreqMode.COCKPIT;
                    clientRadio.encMode       = RadioInformation.EncryptionMode.NO_ENCRYPTION;
                    clientRadio.volMode       = RadioInformation.VolumeMode.COCKPIT;
                }
                else
                {
                    //update common parts
                    clientRadio.freqMin = updateRadio.freqMin;
                    clientRadio.freqMax = updateRadio.freqMax;

                    if (playerRadioInfo.simultaneousTransmissionControl == DCSPlayerRadioInfo.SimultaneousTransmissionControl.EXTERNAL_DCS_CONTROL)
                    {
                        clientRadio.simul = updateRadio.simul;
                    }

                    if (updateRadio.simul)
                    {
                        simul = true;
                    }

                    clientRadio.name = updateRadio.name;

                    clientRadio.modulation = updateRadio.modulation;

                    //update modes
                    clientRadio.freqMode      = updateRadio.freqMode;
                    clientRadio.guardFreqMode = updateRadio.guardFreqMode;

                    if (_serverSettings.GetSettingAsBool(ServerSettingsKeys.ALLOW_RADIO_ENCRYPTION))
                    {
                        clientRadio.encMode = updateRadio.encMode;
                    }
                    else
                    {
                        clientRadio.encMode = RadioInformation.EncryptionMode.NO_ENCRYPTION;
                    }

                    clientRadio.volMode = updateRadio.volMode;

                    if ((updateRadio.freqMode == RadioInformation.FreqMode.COCKPIT) || overrideFreqAndVol)
                    {
                        if (clientRadio.freq != updateRadio.freq)
                        {
                            changed = true;
                        }

                        if (clientRadio.secFreq != updateRadio.secFreq)
                        {
                            changed = true;
                        }

                        clientRadio.freq = updateRadio.freq;

                        if (newAircraft && updateRadio.guardFreqMode == RadioInformation.FreqMode.OVERLAY)
                        {
                            //default guard to off
                            clientRadio.secFreq = 0;
                        }
                        else
                        {
                            if (clientRadio.secFreq != 0 && updateRadio.guardFreqMode == RadioInformation.FreqMode.OVERLAY)
                            {
                                //put back
                                clientRadio.secFreq = updateRadio.secFreq;
                            }
                            else if (clientRadio.secFreq == 0 && updateRadio.guardFreqMode == RadioInformation.FreqMode.OVERLAY)
                            {
                                clientRadio.secFreq = 0;
                            }
                            else
                            {
                                clientRadio.secFreq = updateRadio.secFreq;
                            }
                        }



                        clientRadio.channel = updateRadio.channel;
                    }
                    else
                    {
                        if (clientRadio.secFreq != 0)
                        {
                            //put back
                            clientRadio.secFreq = updateRadio.secFreq;
                        }

                        //check we're not over a limit
                        if (clientRadio.freq > clientRadio.freqMax)
                        {
                            clientRadio.freq = clientRadio.freqMax;
                        }
                        else if (clientRadio.freq < clientRadio.freqMin)
                        {
                            clientRadio.freq = clientRadio.freqMin;
                        }
                    }

                    //reset encryption
                    if (overrideFreqAndVol)
                    {
                        clientRadio.enc    = false;
                        clientRadio.encKey = 0;
                    }

                    //Handle Encryption
                    if (updateRadio.encMode == RadioInformation.EncryptionMode.ENCRYPTION_JUST_OVERLAY)
                    {
                        if (clientRadio.encKey == 0)
                        {
                            clientRadio.encKey = 1;
                        }
                    }
                    else if (clientRadio.encMode ==
                             RadioInformation.EncryptionMode.ENCRYPTION_COCKPIT_TOGGLE_OVERLAY_CODE)
                    {
                        clientRadio.enc = updateRadio.enc;

                        if (clientRadio.encKey == 0)
                        {
                            clientRadio.encKey = 1;
                        }
                    }
                    else if (clientRadio.encMode == RadioInformation.EncryptionMode.ENCRYPTION_FULL)
                    {
                        clientRadio.enc    = updateRadio.enc;
                        clientRadio.encKey = updateRadio.encKey;
                    }
                    else
                    {
                        clientRadio.enc    = false;
                        clientRadio.encKey = 0;
                    }

                    //handle volume
                    if ((updateRadio.volMode == RadioInformation.VolumeMode.COCKPIT) || overrideFreqAndVol)
                    {
                        clientRadio.volume = updateRadio.volume;
                    }

                    //handle Channels load for radios
                    if (newAircraft && i > 0)
                    {
                        if (clientRadio.freqMode == RadioInformation.FreqMode.OVERLAY)
                        {
                            var channelModel = _clientStateSingleton.FixedChannels[i - 1];
                            channelModel.Max = clientRadio.freqMax;
                            channelModel.Min = clientRadio.freqMin;
                            channelModel.Reload();
                            clientRadio.channel = -1; //reset channel

                            if (_globalSettings.ProfileSettingsStore.GetClientSettingBool(ProfileSettingsKeys.AutoSelectPresetChannel))
                            {
                                RadioHelper.RadioChannelUp(i);
                            }
                        }
                        else
                        {
                            _clientStateSingleton.FixedChannels[i - 1].Clear();
                            //clear
                        }
                    }
                }
            }


            if (playerRadioInfo.simultaneousTransmissionControl ==
                DCSPlayerRadioInfo.SimultaneousTransmissionControl.EXTERNAL_DCS_CONTROL)
            {
                playerRadioInfo.simultaneousTransmission = simul;
            }

            //change PTT last
            if (!_globalSettings.ProfileSettingsStore.GetClientSettingBool(ProfileSettingsKeys.AllowDCSPTT))
            {
                playerRadioInfo.ptt = false;
            }
            else
            {
                playerRadioInfo.ptt = message.ptt;
            }

            //HANDLE IFF/TRANSPONDER UPDATE
            //TODO tidy up the IFF/Transponder handling and this giant function in general as its silly big :(
            if (message.iff.control == Transponder.IFFControlMode.COCKPIT)
            {
                playerRadioInfo.iff = message.iff;
            }

            //HANDLE MIC IDENT
            if (!playerRadioInfo.ptt && playerRadioInfo.iff.mic > 0 && UdpVoiceHandler.RadioSendingState.IsSending)
            {
                if (UdpVoiceHandler.RadioSendingState.SendingOn == playerRadioInfo.iff.mic)
                {
                    playerRadioInfo.iff.status = Transponder.IFFStatus.IDENT;
                }
            }


            //                }
            //            }

            //update
            playerRadioInfo.LastUpdate = DateTime.Now.Ticks;

            return(changed);
        }
Beispiel #20
0
        private bool UpdateRadio(DCSPlayerRadioInfo message)
        {
            var changed = false;


            var expansion = ClientSync.ServerSettings[(int)ServerSettingType.RADIO_EXPANSION];

            var playerRadioInfo = _clientStateSingleton.DcsPlayerRadioInfo;

            //update common parts
            playerRadioInfo.name = message.name;


            if (_settings.GetClientSetting(SettingsKeys.AlwaysAllowHotasControls).BoolValue)
            {
                playerRadioInfo.control = DCSPlayerRadioInfo.RadioSwitchControls.HOTAS;
            }
            else
            {
                playerRadioInfo.control = message.control;
            }

            playerRadioInfo.unit = message.unit;
            playerRadioInfo.pos  = message.pos;

            var overrideFreqAndVol = false;

            var newAircraft = playerRadioInfo.unitId != message.unitId || !playerRadioInfo.IsCurrent();

            if (message.unitId >= DCSPlayerRadioInfo.UnitIdOffset &&
                playerRadioInfo.unitId >= DCSPlayerRadioInfo.UnitIdOffset)
            {
                //overriden so leave as is
            }
            else
            {
                overrideFreqAndVol     = playerRadioInfo.unitId != message.unitId;
                playerRadioInfo.unitId = message.unitId;
            }


            if (overrideFreqAndVol)
            {
                playerRadioInfo.selected = message.selected;
                changed = true;
            }

            if (message.control == DCSPlayerRadioInfo.RadioSwitchControls.IN_COCKPIT)
            {
                playerRadioInfo.selected = message.selected;
            }


            //copy over radio names, min + max
            for (var i = 0; i < playerRadioInfo.radios.Length; i++)
            {
                var clientRadio = playerRadioInfo.radios[i];

                //if awacs NOT open -  disable radios over 3
                if (i >= message.radios.Length ||
                    (RadioOverlayWindow.AwacsActive == false &&
                     (i > 3 || i == 0)
                     // disable intercom and all radios over 3 if awacs panel isnt open and we're a spectator given by the UnitId
                     && playerRadioInfo.unitId >= DCSPlayerRadioInfo.UnitIdOffset))
                {
                    clientRadio.freq       = 1;
                    clientRadio.freqMin    = 1;
                    clientRadio.freqMax    = 1;
                    clientRadio.secFreq    = 0;
                    clientRadio.modulation = RadioInformation.Modulation.DISABLED;
                    clientRadio.name       = "No Radio";

                    clientRadio.freqMode = RadioInformation.FreqMode.COCKPIT;
                    clientRadio.encMode  = RadioInformation.EncryptionMode.NO_ENCRYPTION;
                    clientRadio.volMode  = RadioInformation.VolumeMode.COCKPIT;

                    continue;
                }

                var updateRadio = message.radios[i];


                if ((updateRadio.expansion && !expansion) ||
                    (updateRadio.modulation == RadioInformation.Modulation.DISABLED))
                {
                    //expansion radio, not allowed
                    clientRadio.freq       = 1;
                    clientRadio.freqMin    = 1;
                    clientRadio.freqMax    = 1;
                    clientRadio.secFreq    = 0;
                    clientRadio.modulation = RadioInformation.Modulation.DISABLED;
                    clientRadio.name       = "No Radio";

                    clientRadio.freqMode = RadioInformation.FreqMode.COCKPIT;
                    clientRadio.encMode  = RadioInformation.EncryptionMode.NO_ENCRYPTION;
                    clientRadio.volMode  = RadioInformation.VolumeMode.COCKPIT;
                }
                else
                {
                    //update common parts
                    clientRadio.freqMin = updateRadio.freqMin;
                    clientRadio.freqMax = updateRadio.freqMax;

                    clientRadio.name = updateRadio.name;

                    clientRadio.modulation = updateRadio.modulation;

                    //update modes
                    clientRadio.freqMode = updateRadio.freqMode;
                    clientRadio.encMode  = updateRadio.encMode;
                    clientRadio.volMode  = updateRadio.volMode;

                    if ((updateRadio.freqMode == RadioInformation.FreqMode.COCKPIT) || overrideFreqAndVol)
                    {
                        if (clientRadio.freq != updateRadio.freq)
                        {
                            changed = true;
                        }

                        if (clientRadio.secFreq != updateRadio.secFreq)
                        {
                            changed = true;
                        }

                        clientRadio.freq = updateRadio.freq;

                        //default overlay to off
                        if (updateRadio.freqMode == RadioInformation.FreqMode.OVERLAY)
                        {
                            clientRadio.secFreq = 0;
                        }
                        else
                        {
                            clientRadio.secFreq = updateRadio.secFreq;
                        }

                        clientRadio.channel = updateRadio.channel;
                    }
                    else
                    {
                        if (clientRadio.secFreq != 0)
                        {
                            //put back
                            clientRadio.secFreq = updateRadio.secFreq;
                        }

                        //check we're not over a limit
                        if (clientRadio.freq > clientRadio.freqMax)
                        {
                            clientRadio.freq = clientRadio.freqMax;
                        }
                        else if (clientRadio.freq < clientRadio.freqMin)
                        {
                            clientRadio.freq = clientRadio.freqMin;
                        }
                    }

                    //reset encryption
                    if (overrideFreqAndVol)
                    {
                        clientRadio.enc    = false;
                        clientRadio.encKey = 0;
                    }

                    //Handle Encryption
                    if (updateRadio.encMode == RadioInformation.EncryptionMode.ENCRYPTION_JUST_OVERLAY)
                    {
                        if (clientRadio.encKey == 0)
                        {
                            clientRadio.encKey = 1;
                        }
                    }
                    else if (clientRadio.encMode ==
                             RadioInformation.EncryptionMode.ENCRYPTION_COCKPIT_TOGGLE_OVERLAY_CODE)
                    {
                        clientRadio.enc = updateRadio.enc;

                        if (clientRadio.encKey == 0)
                        {
                            clientRadio.encKey = 1;
                        }
                    }
                    else if (clientRadio.encMode == RadioInformation.EncryptionMode.ENCRYPTION_FULL)
                    {
                        clientRadio.enc    = updateRadio.enc;
                        clientRadio.encKey = updateRadio.encKey;
                    }
                    else
                    {
                        clientRadio.enc    = false;
                        clientRadio.encKey = 0;
                    }

                    //handle volume
                    if ((updateRadio.volMode == RadioInformation.VolumeMode.COCKPIT) || overrideFreqAndVol)
                    {
                        clientRadio.volume = updateRadio.volume;
                    }

                    //handle Channels load for radios
                    if (newAircraft && i > 0)
                    {
                        if (clientRadio.freqMode == RadioInformation.FreqMode.OVERLAY)
                        {
                            var channelModel = _clientStateSingleton.FixedChannels[i - 1];
                            channelModel.Max = clientRadio.freqMax;
                            channelModel.Min = clientRadio.freqMin;
                            channelModel.Reload();
                            clientRadio.channel = -1; //reset channel

                            if (_settings.GetClientSetting(SettingsKeys.AutoSelectPresetChannel).BoolValue)
                            {
                                RadioHelper.RadioChannelUp(i);
                            }
                        }
                        else
                        {
                            _clientStateSingleton.FixedChannels[i - 1].Clear();
                            //clear
                        }
                    }
                }
            }

            //change PTT last
            if (!_settings.GetClientSetting(SettingsKeys.AllowDCSPTT).BoolValue)
            {
                playerRadioInfo.ptt = false;
            }
            else
            {
                playerRadioInfo.ptt = message.ptt;
            }

            //                }
            //            }

            //update
            playerRadioInfo.LastUpdate = DateTime.Now.Ticks;

            return(changed);
        }
Beispiel #21
0
        public MainWindow()
        {
            GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency;

            InitializeComponent();

            WindowStartupLocation = WindowStartupLocation.Manual;
            Left   = _settings.GetPositionSetting(SettingsKeys.ClientX).DoubleValue;
            Top    = _settings.GetPositionSetting(SettingsKeys.ClientY).DoubleValue;
            Title += " - 1.12.0.0 - ";
            Title += Properties.Settings.Default.ServerShortName;

            _logger.Debug("Connecting on Startup");

            var resolvedAddresses = Dns.GetHostAddresses(Properties.Settings.Default.SRSHost);

            _resolvedIp = resolvedAddresses.FirstOrDefault(xa => xa.AddressFamily == AddressFamily.InterNetwork); // Ensure we get an IPv4 address in case the host resolves to both IPv6 and IPv4

            if (_resolvedIp == null)
            {
                throw new Exception($"Could not determine IPv4 address for {Properties.Settings.Default.SRSHost}");
            }

            _port = Properties.Settings.Default.SRSPort;

            ServerName.Text     = Properties.Settings.Default.ServerName;
            ServerEndpoint.Text = Properties.Settings.Default.SRSHost + ":" + _port;

            var radioJson   = File.ReadAllText(AwacsRadiosFile);
            var awacsRadios = JsonConvert.DeserializeObject <List <RadioInformation> >(radioJson);

            var speechAuthenticated = false;

            // Wait until we have authorization with Azure before continuing. No point connecting to
            // SRS if we cannot process anything.
            var t = Task.Run(() => {
                while (speechAuthenticated == false)
                {
                    var authorizationToken = SpeechAuthorizationToken.AuthorizationToken;
                    if (authorizationToken == null)
                    {
                        Thread.Sleep(10000);
                    }
                    else
                    {
                        speechAuthenticated = true;
                    }
                }
            });

            t.Wait();

            foreach (var radio in awacsRadios)
            {
                var playerRadioInfo = new DCSPlayerRadioInfo
                {
                    LastUpdate = DateTime.Now.Ticks,
                    name       = radio.name,
                    ptt        = false,
                    radios     = new List <RadioInformation> {
                        radio
                    },
                    selected = 1,
                    latLng   = new DCSLatLngPosition {
                        lat = 0, lng = 0, alt = 0
                    },
                    simultaneousTransmission        = false,
                    simultaneousTransmissionControl = DCSPlayerRadioInfo.SimultaneousTransmissionControl.ENABLED_INTERNAL_SRS_CONTROLS,
                    unit       = "External AWACS",
                    unitId     = 100000001,
                    inAircraft = false,
                    iff        = new Transponder()
                };

                var audioManager = new AudioManager(playerRadioInfo);
                audioManager.ConnectToSrs(new IPEndPoint(_resolvedIp, _port));
                AudioManagers.Add(audioManager);
            }
            if (!string.IsNullOrEmpty(OverlordBot.Properties.Settings.Default.NewRelicApiKey))
            {
                MetricsManager.Start();
            }
        }
        public void StartExternalAWACSModeLoop()
        {
            _stopExternalAWACSMode = false;

            RadioInformation[] awacsRadios;
            try
            {
                string radioJson = File.ReadAllText(AWACS_RADIOS_FILE);
                awacsRadios = JsonConvert.DeserializeObject <RadioInformation[]>(radioJson);
            }
            catch (Exception ex)
            {
                Logger.Warn(ex, "Failed to load AWACS radio file");

                awacsRadios = new RadioInformation[11];
                for (int i = 0; i < 11; i++)
                {
                    awacsRadios[i] = new RadioInformation
                    {
                        freq       = 1,
                        freqMin    = 1,
                        freqMax    = 1,
                        secFreq    = 0,
                        modulation = RadioInformation.Modulation.DISABLED,
                        name       = "No Radio",
                        freqMode   = RadioInformation.FreqMode.COCKPIT,
                        encMode    = RadioInformation.EncryptionMode.NO_ENCRYPTION,
                        volMode    = RadioInformation.VolumeMode.COCKPIT
                    };
                }
            }

            // Force an immediate update of radio information
            _clientStateSingleton.LastSent = 0;

            Task.Factory.StartNew(() =>
            {
                Logger.Debug("Starting external AWACS mode loop");

                _clientStateSingleton.IntercomOffset = 1;
                while (!_stopExternalAWACSMode)
                {
                    var unitId = DCSPlayerRadioInfo.UnitIdOffset + _clientStateSingleton.IntercomOffset;

                    //save
                    _dcsRadioSyncHandler.ProcessRadioInfo(new DCSPlayerRadioInfo
                    {
                        LastUpdate = 0,
                        control    = DCSPlayerRadioInfo.RadioSwitchControls.HOTAS,
                        name       = _clientStateSingleton.LastSeenName,
                        ptt        = false,
                        radios     = awacsRadios,
                        selected   = 1,
                        latLng     = new DCSLatLngPosition()
                        {
                            lat = 0, lng = 0, alt = 0
                        },
                        simultaneousTransmission        = false,
                        simultaneousTransmissionControl = DCSPlayerRadioInfo.SimultaneousTransmissionControl.ENABLED_INTERNAL_SRS_CONTROLS,
                        unit       = "External AWACS",
                        unitId     = (uint)unitId,
                        inAircraft = false
                    });

                    Thread.Sleep(200);
                }

                var radio = new DCSPlayerRadioInfo();
                radio.Reset();
                _dcsRadioSyncHandler.ProcessRadioInfo(radio);
                _clientStateSingleton.IntercomOffset = 1;

                Logger.Debug("Stopping external AWACS mode loop");
            });
        }
        private void RetransmitAudio(UDPVoicePacket udpVoicePacket, List <RadioReceivingPriority> radioReceivingPriorities)
        {
            if (udpVoicePacket.Guid == _guid) //|| udpVoicePacket.OriginalClientGuid == _guid
            {
                return;
                //my own transmission - throw away - stops test frequencies
            }

            //Hop count can limit the retransmission too
            var nodeLimit = _serverSettings.RetransmitNodeLimit;

            if (nodeLimit < udpVoicePacket.RetransmissionCount)
            {
                //Reached hop limit - no retransmit
                return;
            }

            //Check if Global
            List <double> globalFrequencies = _serverSettings.GlobalFrequencies;

            // filter radios by ability to hear it AND decryption works
            List <RadioReceivingPriority> retransmitOn = new List <RadioReceivingPriority>();
            //artificially limit some retransmissions - if encryption fails dont retransmit

            //from the subset of receiving radios - find any other radios that have retransmit - and dont retransmit on any with the same frequency
            //to stop loops
            //and ignore global frequencies
            //and only if we can decrypt it (or no encryption)
            //and not received on Guard
            var receivingWithRetransmit = radioReceivingPriorities.Where(receivingRadio =>
                                                                         (receivingRadio.Decryptable || (receivingRadio.Encryption == 0)) &&
                                                                         receivingRadio.ReceivingRadio.retransmit
                                                                         //check global
                                                                         && !globalFrequencies.Any(freq => DCSPlayerRadioInfo.FreqCloseEnough(receivingRadio.ReceivingRadio.freq, freq)) &&
                                                                         !receivingRadio.ReceivingState.IsSecondary).ToList();

            //didnt receive on any radios that we could decrypt
            //stop
            if (receivingWithRetransmit.Count == 0)
            {
                return;
            }

            //radios able to retransmit
            var radiosWithRetransmit = _clientStateSingleton.DcsPlayerRadioInfo.radios.Where(radio => radio.retransmit);

            //Check we're not retransmitting through a radio we just received on?
            foreach (var receivingRadio in receivingWithRetransmit)
            {
                radiosWithRetransmit = radiosWithRetransmit.Where(radio => !DCSPlayerRadioInfo.FreqCloseEnough(radio.freq, receivingRadio.Frequency));
            }

            var finalList = radiosWithRetransmit.ToList();

            if (finalList.Count == 0)
            {
                //quit
                return;
            }

            //From the remaining list - build up a new outgoing packet
            var frequencies = new double[finalList.Count];
            var encryptions = new byte[finalList.Count];
            var modulations = new byte[finalList.Count];

            for (int i = 0; i < finalList.Count; i++)
            {
                frequencies[i] = finalList[i].freq;
                encryptions[i] = finalList[i].enc ? (byte)finalList[i].encKey:(byte)0;
                modulations[i] = (byte)finalList[i].modulation;
            }

            //generate packet
            var relayedPacket = new UDPVoicePacket
            {
                GuidBytes               = _guidAsciiBytes,
                AudioPart1Bytes         = udpVoicePacket.AudioPart1Bytes,
                AudioPart1Length        = udpVoicePacket.AudioPart1Length,
                Frequencies             = frequencies,
                UnitId                  = _clientStateSingleton.DcsPlayerRadioInfo.unitId,
                Encryptions             = encryptions,
                Modulations             = modulations,
                PacketNumber            = udpVoicePacket.PacketNumber,
                OriginalClientGuidBytes = udpVoicePacket.OriginalClientGuidBytes,
                RetransmissionCount     = (byte)(udpVoicePacket.RetransmissionCount + 1u),
            };

            var packet = relayedPacket.EncodePacket();

            try
            {
                _listener.Send(packet, packet.Length,
                               new IPEndPoint(_address, _port));
            }
            catch (Exception)
            {
            }
        }
        private bool UpdateRadio(DCSPlayerRadioInfo message)
        {
            var expansion = _serverSettings.GetSettingAsBool(ServerSettingsKeys.RADIO_EXPANSION);

            var playerRadioInfo = _clientStateSingleton.DcsPlayerRadioInfo;

            //copy and compare to look for changes
            var beforeUpdate = playerRadioInfo.DeepClone();

            //update common parts
            playerRadioInfo.name           = message.name;
            playerRadioInfo.inAircraft     = message.inAircraft;
            playerRadioInfo.intercomHotMic = message.intercomHotMic;
            playerRadioInfo.capabilities   = message.capabilities;

            if (_globalSettings.ProfileSettingsStore.GetClientSettingBool(ProfileSettingsKeys.AlwaysAllowHotasControls))
            {
                message.control         = DCSPlayerRadioInfo.RadioSwitchControls.HOTAS;
                playerRadioInfo.control = DCSPlayerRadioInfo.RadioSwitchControls.HOTAS;
            }
            else
            {
                playerRadioInfo.control = message.control;
            }

            playerRadioInfo.simultaneousTransmissionControl = message.simultaneousTransmissionControl;

            playerRadioInfo.unit = message.unit;

            if (!_clientStateSingleton.ShouldUseLotATCPosition())
            {
                _clientStateSingleton.UpdatePlayerPosition(message.latLng);
            }

            var overrideFreqAndVol = false;

            var newAircraft = playerRadioInfo.unitId != message.unitId || !playerRadioInfo.IsCurrent();

            overrideFreqAndVol = playerRadioInfo.unitId != message.unitId;

            //save unit id
            playerRadioInfo.unitId = message.unitId;


            if (newAircraft)
            {
                if (_globalSettings.GetClientSettingBool(GlobalSettingsKeys.AutoSelectSettingsProfile))
                {
                    _newAircraftCallback(message.unit);
                }

                playerRadioInfo.iff = message.iff;
            }

            if (overrideFreqAndVol)
            {
                playerRadioInfo.selected = message.selected;
            }

            if (playerRadioInfo.control == DCSPlayerRadioInfo.RadioSwitchControls.IN_COCKPIT)
            {
                playerRadioInfo.selected = message.selected;
            }

            bool simul = false;


            //copy over radio names, min + max
            for (var i = 0; i < playerRadioInfo.radios.Length; i++)
            {
                var clientRadio = playerRadioInfo.radios[i];

                //if we have more radios than the message has
                if (i >= message.radios.Length)
                {
                    clientRadio.freq       = 1;
                    clientRadio.freqMin    = 1;
                    clientRadio.freqMax    = 1;
                    clientRadio.secFreq    = 0;
                    clientRadio.retransmit = false;
                    clientRadio.modulation = RadioInformation.Modulation.DISABLED;
                    clientRadio.name       = "No Radio";
                    clientRadio.rtMode     = RadioInformation.RetransmitMode.DISABLED;
                    clientRadio.retransmit = false;

                    clientRadio.freqMode      = RadioInformation.FreqMode.COCKPIT;
                    clientRadio.guardFreqMode = RadioInformation.FreqMode.COCKPIT;
                    clientRadio.encMode       = RadioInformation.EncryptionMode.NO_ENCRYPTION;
                    clientRadio.volMode       = RadioInformation.VolumeMode.COCKPIT;

                    continue;
                }

                var updateRadio = message.radios[i];


                if ((updateRadio.expansion && !expansion) ||
                    (updateRadio.modulation == RadioInformation.Modulation.DISABLED))
                {
                    //expansion radio, not allowed
                    clientRadio.freq       = 1;
                    clientRadio.freqMin    = 1;
                    clientRadio.freqMax    = 1;
                    clientRadio.secFreq    = 0;
                    clientRadio.retransmit = false;
                    clientRadio.modulation = RadioInformation.Modulation.DISABLED;
                    clientRadio.name       = "No Radio";
                    clientRadio.rtMode     = RadioInformation.RetransmitMode.DISABLED;
                    clientRadio.retransmit = false;

                    clientRadio.freqMode      = RadioInformation.FreqMode.COCKPIT;
                    clientRadio.guardFreqMode = RadioInformation.FreqMode.COCKPIT;
                    clientRadio.encMode       = RadioInformation.EncryptionMode.NO_ENCRYPTION;
                    clientRadio.volMode       = RadioInformation.VolumeMode.COCKPIT;
                }
                else
                {
                    //update common parts
                    clientRadio.freqMin = updateRadio.freqMin;
                    clientRadio.freqMax = updateRadio.freqMax;

                    if (playerRadioInfo.simultaneousTransmissionControl == DCSPlayerRadioInfo.SimultaneousTransmissionControl.EXTERNAL_DCS_CONTROL)
                    {
                        clientRadio.simul = updateRadio.simul;
                    }

                    if (updateRadio.simul)
                    {
                        simul = true;
                    }

                    clientRadio.name = updateRadio.name;

                    clientRadio.modulation = updateRadio.modulation;

                    //update modes
                    clientRadio.freqMode      = updateRadio.freqMode;
                    clientRadio.guardFreqMode = updateRadio.guardFreqMode;
                    clientRadio.rtMode        = updateRadio.rtMode;

                    if (_serverSettings.GetSettingAsBool(ServerSettingsKeys.ALLOW_RADIO_ENCRYPTION))
                    {
                        clientRadio.encMode = updateRadio.encMode;
                    }
                    else
                    {
                        clientRadio.encMode = RadioInformation.EncryptionMode.NO_ENCRYPTION;
                    }

                    clientRadio.volMode = updateRadio.volMode;

                    if ((updateRadio.freqMode == RadioInformation.FreqMode.COCKPIT) || overrideFreqAndVol)
                    {
                        clientRadio.freq = updateRadio.freq;

                        if (newAircraft && updateRadio.guardFreqMode == RadioInformation.FreqMode.OVERLAY)
                        {
                            //default guard to off
                            clientRadio.secFreq = 0;
                        }
                        else
                        {
                            if (clientRadio.secFreq != 0 && updateRadio.guardFreqMode == RadioInformation.FreqMode.OVERLAY)
                            {
                                //put back
                                clientRadio.secFreq = updateRadio.secFreq;
                            }
                            else if (clientRadio.secFreq == 0 && updateRadio.guardFreqMode == RadioInformation.FreqMode.OVERLAY)
                            {
                                clientRadio.secFreq = 0;
                            }
                            else
                            {
                                clientRadio.secFreq = updateRadio.secFreq;
                            }
                        }

                        clientRadio.channel = updateRadio.channel;
                    }
                    else
                    {
                        if (clientRadio.secFreq != 0)
                        {
                            //put back
                            clientRadio.secFreq = updateRadio.secFreq;
                        }

                        //check we're not over a limit
                        if (clientRadio.freq > clientRadio.freqMax)
                        {
                            clientRadio.freq = clientRadio.freqMax;
                        }
                        else if (clientRadio.freq < clientRadio.freqMin)
                        {
                            clientRadio.freq = clientRadio.freqMin;
                        }
                    }

                    //reset encryption
                    if (overrideFreqAndVol)
                    {
                        clientRadio.enc    = false;
                        clientRadio.encKey = 0;
                    }

                    //Handle Encryption
                    if (updateRadio.encMode == RadioInformation.EncryptionMode.ENCRYPTION_JUST_OVERLAY)
                    {
                        if (clientRadio.encKey == 0)
                        {
                            clientRadio.encKey = 1;
                        }
                    }
                    else if (clientRadio.encMode ==
                             RadioInformation.EncryptionMode.ENCRYPTION_COCKPIT_TOGGLE_OVERLAY_CODE)
                    {
                        clientRadio.enc = updateRadio.enc;

                        if (clientRadio.encKey == 0)
                        {
                            clientRadio.encKey = 1;
                        }
                    }
                    else if (clientRadio.encMode == RadioInformation.EncryptionMode.ENCRYPTION_FULL)
                    {
                        clientRadio.enc    = updateRadio.enc;
                        clientRadio.encKey = updateRadio.encKey;
                    }
                    else
                    {
                        clientRadio.enc    = false;
                        clientRadio.encKey = 0;
                    }

                    //handle volume
                    if ((updateRadio.volMode == RadioInformation.VolumeMode.COCKPIT) || overrideFreqAndVol)
                    {
                        clientRadio.volume = updateRadio.volume;
                    }

                    //handle Retransmit mode
                    if ((updateRadio.rtMode == RadioInformation.RetransmitMode.COCKPIT))
                    {
                        clientRadio.rtMode     = updateRadio.rtMode;
                        clientRadio.retransmit = updateRadio.retransmit;
                    }
                    else if (updateRadio.rtMode == RadioInformation.RetransmitMode.DISABLED)
                    {
                        clientRadio.rtMode     = updateRadio.rtMode;
                        clientRadio.retransmit = false;
                    }

                    //handle Channels load for radios
                    if (newAircraft && i > 0)
                    {
                        if (clientRadio.freqMode == RadioInformation.FreqMode.OVERLAY)
                        {
                            var channelModel = _clientStateSingleton.FixedChannels[i - 1];
                            channelModel.Max = clientRadio.freqMax;
                            channelModel.Min = clientRadio.freqMin;
                            channelModel.Reload();
                            clientRadio.channel = -1; //reset channel

                            if (_globalSettings.ProfileSettingsStore.GetClientSettingBool(ProfileSettingsKeys.AutoSelectPresetChannel))
                            {
                                RadioHelper.RadioChannelUp(i);
                            }
                        }
                        else
                        {
                            _clientStateSingleton.FixedChannels[i - 1].Clear();
                            //clear
                        }
                    }
                }
            }


            if (playerRadioInfo.simultaneousTransmissionControl ==
                DCSPlayerRadioInfo.SimultaneousTransmissionControl.EXTERNAL_DCS_CONTROL)
            {
                playerRadioInfo.simultaneousTransmission = simul;
            }

            //change PTT last
            if (!_globalSettings.ProfileSettingsStore.GetClientSettingBool(ProfileSettingsKeys.AllowDCSPTT))
            {
                playerRadioInfo.ptt = false;
            }
            else
            {
                playerRadioInfo.ptt = message.ptt;
            }

            //HANDLE IFF/TRANSPONDER UPDATE
            //TODO tidy up the IFF/Transponder handling and this giant function in general as its silly big :(


            if (_globalSettings.ProfileSettingsStore.GetClientSettingBool(ProfileSettingsKeys
                                                                          .AlwaysAllowTransponderOverlay))
            {
                if (message.iff.control != Transponder.IFFControlMode.DISABLED)
                {
                    playerRadioInfo.iff.control = Transponder.IFFControlMode.OVERLAY;
                    message.iff.control         = Transponder.IFFControlMode.OVERLAY;
                }
            }

            if (message.iff.control == Transponder.IFFControlMode.COCKPIT)
            {
                playerRadioInfo.iff = message.iff;
            }


            //HANDLE MIC IDENT
            if (!playerRadioInfo.ptt && playerRadioInfo.iff.mic > 0 && _clientStateSingleton.RadioSendingState.IsSending)
            {
                if (_clientStateSingleton.RadioSendingState.SendingOn == playerRadioInfo.iff.mic)
                {
                    playerRadioInfo.iff.status = Transponder.IFFStatus.IDENT;
                }
            }

            //Handle IDENT only lasting for 40 seconds at most - need to toggle it
            if (playerRadioInfo.iff.status == Transponder.IFFStatus.IDENT)
            {
                if (_identStart == 0)
                {
                    _identStart = DateTime.Now.Ticks;
                }

                if (TimeSpan.FromTicks(DateTime.Now.Ticks - _identStart).TotalSeconds > 40)
                {
                    playerRadioInfo.iff.status = Transponder.IFFStatus.NORMAL;
                }
            }
            else
            {
                _identStart = 0;
            }

            //                }
            //            }

            //update
            playerRadioInfo.LastUpdate = DateTime.Now.Ticks;

            return(!beforeUpdate.Equals(playerRadioInfo));
        }
        private bool UpdateRadio(DCSPlayerRadioInfo message)
        {
            var changed = false;

            if (message.radioType == DCSPlayerRadioInfo.AircraftRadioType.FULL_COCKPIT_INTEGRATION)
            // Full radio, all from DCS
            {
                changed = !DcsPlayerRadioInfo.Equals(message);

                HandleEncryptionSettingsFullFidelity(message);

                DcsPlayerRadioInfo = message;
            }
            else if (message.radioType == DCSPlayerRadioInfo.AircraftRadioType.PARTIAL_COCKPIT_INTEGRATION)
            // Partial radio - can select radio but the rest is from DCS
            {
                //check if its changed frequency wise
                changed = !DcsPlayerRadioInfo.Equals(message);

                //update common parts
                DcsPlayerRadioInfo.name      = message.name;
                DcsPlayerRadioInfo.radioType = message.radioType;
                DcsPlayerRadioInfo.unit      = message.unit;
                DcsPlayerRadioInfo.unitId    = message.unitId;
                DcsPlayerRadioInfo.pos       = message.pos;

                HandleEncryptionSettingsFullFidelity(message);

                //copy over the radios
                DcsPlayerRadioInfo.radios = message.radios;

                //change PTT last
                DcsPlayerRadioInfo.ptt = message.ptt;
            }
            else // FC3 Radio - Take nothing from DCS, just update the last tickcount, UPDATE triggered a different way
            {
                if (DcsPlayerRadioInfo.unitId != message.unitId)
                {
                    //replace it all - new aircraft
                    DcsPlayerRadioInfo = message;
                    changed            = true;
                }
                else // same aircraft
                {
                    //update common parts
                    DcsPlayerRadioInfo.name      = message.name;
                    DcsPlayerRadioInfo.radioType = message.radioType;
                    DcsPlayerRadioInfo.unit      = message.unit;
                    DcsPlayerRadioInfo.pos       = message.pos;

                    DcsPlayerRadioInfo.unitId = message.unitId;

                    //copy over radio names, min + max
                    for (var i = 0; i < DcsPlayerRadioInfo.radios.Length; i++)
                    {
                        var updateRadio = message.radios[i];

                        var clientRadio = DcsPlayerRadioInfo.radios[i];

                        clientRadio.freqMin = updateRadio.freqMin;
                        clientRadio.freqMax = updateRadio.freqMax;

                        clientRadio.name = updateRadio.name;

                        if (clientRadio.secondaryFrequency == 0)
                        {
                            //currently turned off
                            clientRadio.secondaryFrequency = 0;
                        }
                        else
                        {
                            //put back
                            clientRadio.secondaryFrequency = updateRadio.secondaryFrequency;
                        }

                        clientRadio.modulation = updateRadio.modulation;

                        //check we're not over a limit

                        if (clientRadio.frequency > clientRadio.freqMax)
                        {
                            clientRadio.frequency = clientRadio.freqMax;
                        }
                        else if (clientRadio.frequency < clientRadio.freqMin)
                        {
                            clientRadio.frequency = clientRadio.freqMin;
                        }

                        clientRadio.encMode = updateRadio.encMode;

                        //Handle Encryption
                        if (updateRadio.encMode == RadioInformation.EncryptionMode.ENCRYPTION_JUST_OVERLAY)
                        {
                            if (clientRadio.encKey == 0)
                            {
                                clientRadio.encKey = 1;
                            }
                        }
                    }

                    //change PTT last
                    DcsPlayerRadioInfo.ptt = message.ptt;
                }
            }

            //update
            DcsPlayerRadioInfo.LastUpdate = Environment.TickCount;

            return(changed);
        }
Beispiel #26
0
        private OutgoingUDPPackets GenerateOutgoingPacket(UDPVoicePacket udpVoice, PendingPacket pendingPacket,
                                                          SRClient fromClient)
        {
            var nodeHopCount =
                _serverSettings.GetGeneralSetting(ServerSettingsKeys.RETRANSMISSION_NODE_LIMIT).IntValue;

            if (udpVoice.RetransmissionCount > nodeHopCount)
            {
                //not allowed to retransmit any further
                return(null);
            }

            var outgoingList = new HashSet <IPEndPoint>();

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

            var guid = fromClient.ClientGuid;

            foreach (var client in _clientsList)
            {
                if (!client.Key.Equals(guid))
                {
                    var  ip     = client.Value.VoipPort;
                    bool global = false;
                    if (ip != null)
                    {
                        for (int i = 0; i < udpVoice.Frequencies.Length; i++)
                        {
                            foreach (var testFrequency in _globalFrequencies)
                            {
                                if (DCSPlayerRadioInfo.FreqCloseEnough(testFrequency, udpVoice.Frequencies[i]))
                                {
                                    //ignore everything as its global frequency
                                    global = true;
                                    break;
                                }
                            }
                        }

                        if (global)
                        {
                            outgoingList.Add(ip);
                        }
                        // check that either coalition radio security is disabled OR the coalitions match
                        else if ((!coalitionSecurity || (client.Value.Coalition == fromClient.Coalition)))
                        {
                            var radioInfo = client.Value.RadioInfo;

                            if (radioInfo != null)
                            {
                                for (int i = 0; i < udpVoice.Frequencies.Length; i++)
                                {
                                    RadioReceivingState radioReceivingState = null;
                                    bool decryptable;
                                    var  receivingRadio = radioInfo.CanHearTransmission(udpVoice.Frequencies[i],
                                                                                        (RadioInformation.Modulation)udpVoice.Modulations[i],
                                                                                        udpVoice.Encryptions[i],
                                                                                        udpVoice.UnitId,
                                                                                        _emptyBlockedRadios,
                                                                                        out radioReceivingState,
                                                                                        out decryptable);

                                    //only send if we can hear!
                                    if (receivingRadio != null)
                                    {
                                        outgoingList.Add(ip);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    var ip = client.Value.VoipPort;

                    if (ip != null)
                    {
                        foreach (var frequency in udpVoice.Frequencies)
                        {
                            foreach (var testFrequency in _testFrequencies)
                            {
                                if (DCSPlayerRadioInfo.FreqCloseEnough(testFrequency, frequency))
                                {
                                    //send back to sending client as its a test frequency
                                    outgoingList.Add(ip);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            if (outgoingList.Count > 0)
            {
                return(new OutgoingUDPPackets
                {
                    OutgoingEndPoints = outgoingList.ToList(),
                    ReceivedPacket = pendingPacket.RawBytes
                });
            }
            else
            {
                return(null);
            }
        }
Beispiel #27
0
 public AudioManager(DCSPlayerRadioInfo playerRadioInfo)
 {
     PlayerRadioInfo = playerRadioInfo;
     LogClientId     = PlayerRadioInfo.radios[0].name;
     Client          = new Network.Client(this, playerRadioInfo);
 }