Пример #1
0
        private void FocusDCS()
        {
            if (_settings.GetClientSetting(SettingsKeys.RefocusDCS).BoolValue)
            {
                var overlayWindow = new WindowInteropHelper(this).Handle;

                //focus DCS if needed
                var foreGround = WindowHelper.GetForegroundWindow();

                Process[] localByName = Process.GetProcessesByName("dcs");

                if (localByName != null && localByName.Length > 0)
                {
                    //either DCS is in focus OR Overlay window is not in focus
                    if (foreGround == localByName[0].MainWindowHandle || overlayWindow != foreGround ||
                        this.IsMouseOver)
                    {
                        _lastFocus = DateTime.Now.Ticks;
                    }
                    else if (DateTime.Now.Ticks > _lastFocus + 20000000 && overlayWindow == foreGround)
                    {
                        WindowHelper.BringProcessToFront(localByName[0]);
                    }
                }
            }
        }
Пример #2
0
        public App()
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler);

            var location = AppDomain.CurrentDomain.BaseDirectory;

            //var location = Assembly.GetExecutingAssembly().Location;

            //check for opus.dll
            if (!File.Exists(location + "\\opus.dll"))
            {
                MessageBox.Show(
                    $"You are missing the opus.dll - Reinstall using the Installer and don't move the client from the installation directory!",
                    "Installation Error!", MessageBoxButton.OK,
                    MessageBoxImage.Error);

                Environment.Exit(1);
            }
            if (!File.Exists(location + "\\speexdsp.dll"))
            {
                MessageBox.Show(
                    $"You are missing the speexdsp.dll - Reinstall using the Installer and don't move the client from the installation directory!",
                    "Installation Error!", MessageBoxButton.OK,
                    MessageBoxImage.Error);

                Environment.Exit(1);
            }

            SetupLogging();

#if !DEBUG
            if (IsClientRunning())
            {
                Logger logger = LogManager.GetCurrentClassLogger();

                if (_settings.GetClientSetting(SettingsKeys.AllowMultipleInstances).BoolValue)
                {
                    logger.Warn("Another SRS instance is already running, allowing multiple instances due to config setting");
                }
                else
                {
                    logger.Warn("Another SRS instance is already running, preventing second instance startup");

                    MessageBoxResult result = MessageBox.Show(
                        "Another instance of the SimpleRadio client is already running!\n\nThis one will now quit. Check your system tray for the SRS Icon",
                        "Multiple SimpleRadio clients started!",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);


                    Environment.Exit(0);
                    return;
                }
            }
#endif

            InitNotificationIcon();
        }
        private void OnRemoveSelected()
        {
            if (SelectedItem == null)
            {
                return;
            }

            _addresses.Remove(SelectedItem);

            if (_addresses.Count == 0 && !string.IsNullOrEmpty(_settings.GetClientSetting(SettingsKeys.LastServer).StringValue))
            {
                var oldAddress = new ServerAddress(_settings.GetClientSetting(SettingsKeys.LastServer).StringValue,
                                                   _settings.GetClientSetting(SettingsKeys.LastServer).StringValue, null, true);
                _addresses.Add(oldAddress);
            }

            Save();
        }
        public List <string> GetProfiles()
        {
            var profiles = _settings.GetClientSetting(SettingsKeys.InputProfiles).StringValueArray;

            if (profiles == null || profiles.Length == 0 || !profiles.Contains("default"))
            {
                profiles = new[] { "default" };
                _settings.SetClientSetting(SettingsKeys.InputProfiles, profiles);
            }

            return(new List <string>(profiles));
        }
Пример #5
0
        public void PlaySoundEffectStartReceive(int transmitOnRadio, bool encrypted, float volume)
        {
            if (_settings.GetClientSetting(SettingsKeys.RadioRxEffects_Start).BoolValue)
            {
                var _effectsBuffer = _effectsOutputBuffer[transmitOnRadio];

                if (encrypted && (_settings.GetClientSetting(SettingsKeys.RadioEncryptionEffects).BoolValue))
                {
                    _effectsBuffer.VolumeSampleProvider.Volume = volume;
                    _effectsBuffer.AddAudioSamples(
                        _cachedAudioEffects[(int)CachedAudioEffect.AudioEffectTypes.KY_58_RX].AudioEffectBytes,
                        transmitOnRadio);
                }
                else
                {
                    _effectsBuffer.VolumeSampleProvider.Volume = volume;
                    _effectsBuffer.AddAudioSamples(
                        _cachedAudioEffects[(int)CachedAudioEffect.AudioEffectTypes.RADIO_TX].AudioEffectBytes,
                        transmitOnRadio);
                }
            }
        }
        public void Listen()
        {
            _ready = false;

            //start audio processing threads
            var decoderThread = new Thread(UdpAudioDecode);

            decoderThread.Start();

            var settings = SettingsStore.Instance;

            _inputManager.StartDetectPtt(pressed =>
            {
                var radios = _clientStateSingleton.DcsPlayerRadioInfo;

                var radioSwitchPtt = _settings.GetClientSetting(SettingsKeys.RadioSwitchIsPTT).BoolValue;

                var ptt = false;
                foreach (var inputBindState in pressed)
                {
                    if (inputBindState.IsActive)
                    {
                        //radio switch?
                        if ((int)inputBindState.MainDevice.InputBind >= (int)InputBinding.Intercom &&
                            (int)inputBindState.MainDevice.InputBind <= (int)InputBinding.Switch10)
                        {
                            //gives you radio id if you minus 100
                            var radioId = (int)inputBindState.MainDevice.InputBind - 100;

                            if (radioId < _clientStateSingleton.DcsPlayerRadioInfo.radios.Length)
                            {
                                var clientRadio = _clientStateSingleton.DcsPlayerRadioInfo.radios[radioId];

                                if (clientRadio.modulation != RadioInformation.Modulation.DISABLED &&
                                    radios.control == DCSPlayerRadioInfo.RadioSwitchControls.HOTAS)
                                {
                                    radios.selected = (short)radioId;
                                }

                                //turn on PTT
                                if (radioSwitchPtt)
                                {
                                    ptt = true;
                                }
                            }
                        }
                        else if (inputBindState.MainDevice.InputBind == InputBinding.Ptt)
                        {
                            ptt = true;
                        }
                    }
                }

                //if length is zero - no keybinds or no PTT pressed set to false
                _ptt = ptt;
            });

            StartTimer();

            StartPing();

            //keep reconnecting until stop
            while (!_stop)
            {
                try
                {
                    //set to false so we sent one packet to open up the radio
                    //automatically rather than the user having to press Send
                    hasSentVoicePacket = false;

                    _packetNumber = 1; //reset packet number

                    _listener         = new TcpClient();
                    _listener.NoDelay = true;

                    _listener.Connect(_address, _port);

                    //initial packet to get audio setup
                    var udpVoicePacket = new UDPVoicePacket
                    {
                        GuidBytes        = _guidAsciiBytes,
                        AudioPart1Bytes  = new byte[] { 0, 1, 2, 3, 4, 5 },
                        AudioPart1Length = (ushort)6,
                        Frequency        = 100,
                        UnitId           = 1,
                        Encryption       = 0,
                        Modulation       = 4,
                        PacketNumber     = 1
                    }.EncodePacket();

                    _listener.Client.Send(udpVoicePacket);

                    //contains short for audio packet length
                    byte[] lengthBuffer = new byte[2];

                    _ready = true;

                    Logger.Info("Connected to VOIP TCP " + _port);

                    while (_listener.Connected && !_stop)
                    {
                        int received = _listener.Client.Receive(lengthBuffer, 2, SocketFlags.None);

                        if (received == 0)
                        {
                            // didnt receive enough, quit.
                            Logger.Warn(
                                "Didnt Receive full packet for VOIP - Disconnecting & Reconnecting if next Recieve fails");
                            //break;
                        }
                        else
                        {
                            ushort packetLength =
                                BitConverter.ToUInt16(new byte[2] {
                                lengthBuffer[0], lengthBuffer[1]
                            }, 0);

                            byte[] audioPacketBuffer = new byte[packetLength];

                            //add pack in length to full buffer for packet decode
                            audioPacketBuffer[0] = lengthBuffer[0];
                            audioPacketBuffer[1] = lengthBuffer[1];

                            received = _listener.Client.Receive(audioPacketBuffer, 2, packetLength - 2,
                                                                SocketFlags.None);

                            int offset    = received + 2;
                            int remaining = packetLength - 2 - received;
                            while (remaining > 0 && received > 0)
                            {
                                received = _listener.Client.Receive(audioPacketBuffer, offset, remaining,
                                                                    SocketFlags.None);

                                remaining = remaining - received;
                                offset    = offset + received;
                            }

                            if (remaining == 0)
                            {
                                _encodedAudio.Add(audioPacketBuffer);
                            }
                            else
                            {
                                //didnt receive enough - log and reconnect
                                Logger.Warn("Didnt Receive any packet for VOIP - Disconnecting & Reconnecting");
                                break;
                            }
                        }
                    }

                    _ready = false;
                }
                catch (Exception e)
                {
                    Logger.Error("Error with VOIP TCP Connection on port " + _port + " Reconnecting");
                }

                try
                {
                    _listener.Close();
                }
                catch (Exception e)
                {
                }
            }
        }
Пример #7
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);
        }
Пример #8
0
        public void Listen()
        {
            _udpLastReceived = 0;
            _ready           = false;
            _listener        = new UdpClient();
            _listener.AllowNatTraversal(true);
            // _listener.Connect(_serverEndpoint);

            //start 2 audio processing threads
            var decoderThread = new Thread(UdpAudioDecode);

            decoderThread.Start();

            var settings = SettingsStore.Instance;

            _inputManager.StartDetectPtt(pressed =>
            {
                var radios = _clientStateSingleton.DcsPlayerRadioInfo;

                var radioSwitchPtt = _settings.GetClientSetting(SettingsKeys.RadioSwitchIsPTT).BoolValue;

                var ptt = false;
                foreach (var inputBindState in pressed)
                {
                    if (inputBindState.IsActive)
                    {
                        //radio switch?
                        if ((int)inputBindState.MainDevice.InputBind >= (int)InputBinding.Intercom &&
                            (int)inputBindState.MainDevice.InputBind <= (int)InputBinding.Switch10)
                        {
                            //gives you radio id if you minus 100
                            var radioId = (int)inputBindState.MainDevice.InputBind - 100;

                            if (radioId < _clientStateSingleton.DcsPlayerRadioInfo.radios.Length)
                            {
                                var clientRadio = _clientStateSingleton.DcsPlayerRadioInfo.radios[radioId];

                                if (clientRadio.modulation != RadioInformation.Modulation.DISABLED &&
                                    radios.control == DCSPlayerRadioInfo.RadioSwitchControls.HOTAS)
                                {
                                    radios.selected = (short)radioId;
                                }

                                //turn on PTT
                                if (radioSwitchPtt)
                                {
                                    ptt = true;
                                }
                            }
                        }
                        else if (inputBindState.MainDevice.InputBind == InputBinding.Ptt)
                        {
                            ptt = true;
                        }
                    }
                }

                //if length is zero - no keybinds or no PTT pressed set to false
                _ptt = ptt;
            });

            StartTimer();

            StartPing();

            //set to false so we sent one packet to open up the radio
            //automatically rather than the user having to press Send
            hasSentVoicePacket = false;

            _packetNumber = 1; //reset packet number

            while (!_stop)
            {
                _ready = true;
                try
                {
                    var groupEp = new IPEndPoint(IPAddress.Any, _port);
                    //   listener.Client.ReceiveTimeout = 3000;

                    var bytes = _listener.Receive(ref groupEp);

                    if (bytes?.Length == 22)
                    {
                        _udpLastReceived = DateTime.Now.Ticks;
                        Logger.Info("Received Ping Back from Server");
                    }
                    else if (bytes?.Length > 22)
                    {
                        _udpLastReceived = DateTime.Now.Ticks;
                        _encodedAudio.Add(bytes);
                    }
                }
                catch (Exception e)
                {
                    //  logger.Error(e, "error listening for UDP Voip");
                }
            }

            _ready = false;

            //stop UI Refreshing
            _updateTimer.Stop();

            CallOnMainVOIPConnect(false);
        }
        public MainWindow()
        {
            GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency;

            InitializeComponent();

            DataContext = this;

            var client = ClientStateSingleton.Instance;

            WindowStartupLocation = WindowStartupLocation.Manual;
            Left = _settings.GetPositionSetting(SettingsKeys.ClientX).FloatValue;
            Top  = _settings.GetPositionSetting(SettingsKeys.ClientY).FloatValue;



            Title = Title + " - " + UpdaterChecker.VERSION;

            if (_settings.GetClientSetting(SettingsKeys.StartMinimised).BoolValue)
            {
                Hide();
                WindowState = WindowState.Minimized;

                Logger.Info("Started DCS-SimpleRadio Client " + UpdaterChecker.VERSION + " minimized");
            }
            else
            {
                Logger.Info("Started DCS-SimpleRadio Client " + UpdaterChecker.VERSION);
            }

            _guid = _settings.GetClientSetting(SettingsKeys.CliendIdShort).StringValue;

            Analytics.Log("Client", "Startup", _settings.GetClientSetting(SettingsKeys.ClientIdLong).RawValue);

            InitSettingsScreen();

            InitInput();

            InitAudioInput();

            InitAudioOutput();
            InitMicAudioOutput();

            _connectCommand           = new DelegateCommand(Connect, () => ServerAddress != null);
            FavouriteServersViewModel = new FavouriteServersViewModel(new CsvFavouriteServerStore());

            InitDefaultAddress();


            SpeakerBoost.Value = _settings.GetClientSetting(SettingsKeys.SpeakerBoost).DoubleValue;

            Speaker_VU.Value = -100;
            Mic_VU.Value     = -100;

            _audioManager = new AudioManager(_clients);
            _audioManager.SpeakerBoost = VolumeConversionHelper.ConvertVolumeSliderToScale((float)SpeakerBoost.Value);


            if ((SpeakerBoostLabel != null) && (SpeakerBoost != null))
            {
                SpeakerBoostLabel.Content = VolumeConversionHelper.ConvertLinearDiffToDB(_audioManager.SpeakerBoost);
            }

            UpdaterChecker.CheckForUpdate();


            InitFlowDocument();

            _dcsAutoConnectListener = new DCSAutoConnectListener(AutoConnect);

            _updateTimer = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(100)
            };
            _updateTimer.Tick += UpdateClientCount_VUMeters;
            _updateTimer.Start();
        }