From b8d7ebd67bdfe92c7d90f9599788f6e3a3104778 Mon Sep 17 00:00:00 2001 From: Ciaran Fisher Date: Sun, 17 May 2020 10:12:45 +0100 Subject: [PATCH 1/5] Re-arrange lock Update NetCoreServer --- .../Network/NetCoreServer/TcpServer.cs | 8 ++ .../Network/NetCoreServer/TcpSession.cs | 73 ++++--------------- 2 files changed, 23 insertions(+), 58 deletions(-) diff --git a/DCS-SimpleRadio Server/Network/NetCoreServer/TcpServer.cs b/DCS-SimpleRadio Server/Network/NetCoreServer/TcpServer.cs index 2681d14e6..46ffc6db3 100644 --- a/DCS-SimpleRadio Server/Network/NetCoreServer/TcpServer.cs +++ b/DCS-SimpleRadio Server/Network/NetCoreServer/TcpServer.cs @@ -98,6 +98,14 @@ public TcpServer(IPEndPoint endpoint) /// This option will enable/disable SO_EXCLUSIVEADDRUSE if the OS support this feature /// public bool OptionExclusiveAddressUse { get; set; } + /// + /// Option: receive buffer size + /// + public int OptionReceiveBufferSize { get; set; } = 8192; + /// + /// Option: send buffer size + /// + public int OptionSendBufferSize { get; set; } = 8192; #region Start/Stop server diff --git a/DCS-SimpleRadio Server/Network/NetCoreServer/TcpSession.cs b/DCS-SimpleRadio Server/Network/NetCoreServer/TcpSession.cs index 9b16f4759..45b0d87c4 100644 --- a/DCS-SimpleRadio Server/Network/NetCoreServer/TcpSession.cs +++ b/DCS-SimpleRadio Server/Network/NetCoreServer/TcpSession.cs @@ -20,6 +20,8 @@ public TcpSession(TcpServer server) { Id = Guid.NewGuid(); Server = server; + OptionReceiveBufferSize = server.OptionReceiveBufferSize; + OptionSendBufferSize = server.OptionSendBufferSize; } /// @@ -56,49 +58,11 @@ public TcpSession(TcpServer server) /// /// Option: receive buffer size /// - public int OptionReceiveBufferSize - { - get => Socket.ReceiveBufferSize; - set => Socket.ReceiveBufferSize = value; - } + public int OptionReceiveBufferSize { get; set; } = 8192; /// /// Option: send buffer size /// - public int OptionSendBufferSize - { - get => Socket.SendBufferSize; - set => Socket.SendBufferSize = value; - } - /// - /// Option: receive timeout in milliseconds - /// - /// - /// The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period. - /// - public int OptionReceiveTimeout - { - get => Socket.ReceiveTimeout; - set => Socket.ReceiveTimeout = value; - } - /// - /// Option: send timeout in milliseconds - /// - /// - /// The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period. - /// - public int OptionSendTimeout - { - get => Socket.SendTimeout; - set => Socket.SendTimeout = value; - } - /// - /// Option: linger state - /// - public LingerOption OptionLingerState - { - get => Socket.LingerState; - set => Socket.LingerState = value; - } + public int OptionSendBufferSize { get; set; } = 8192; #region Connect/Disconnect session @@ -170,8 +134,7 @@ internal void Connect(Socket socket) /// 'true' if the section was successfully disconnected, 'false' if the section is already disconnected public virtual bool Disconnect() { - lock (_sendLock) - { + if (!IsConnected) return false; @@ -197,7 +160,7 @@ public virtual bool Disconnect() // Update the session socket disposed flag IsSocketDisposed = true; } - catch (ObjectDisposedException) { } + catch (Exception) { } // Update the connected flag IsConnected = false; @@ -217,9 +180,9 @@ public virtual bool Disconnect() // Unregister session Server.UnregisterSession(Id); - } + - return true; + return true; } #endregion @@ -305,15 +268,14 @@ public virtual long Send(byte[] buffer, long offset, long size) /// 'true' if the data was successfully sent, 'false' if the session is not connected public virtual bool SendAsync(byte[] buffer, long offset, long size) { - lock (_sendLock) - { if (!IsConnected) return false; if (size == 0) return true; - + lock (_sendLock) + { // Detect multiple send handlers bool sendRequired = _sendBufferMain.IsEmpty || _sendBufferFlush.IsEmpty; @@ -326,11 +288,11 @@ public virtual bool SendAsync(byte[] buffer, long offset, long size) // Avoid multiple send handlers if (!sendRequired) return true; - + } // Try to send the main buffer Task.Factory.StartNew(TrySend); - } + return true; } @@ -440,9 +402,6 @@ private void TryReceive() /// private void TrySend() { - // lock the whole method - lock (_sendLock) - { if (_sending) return; @@ -455,9 +414,8 @@ private void TrySend() { process = false; - if (!IsConnected) - return; - + lock (_sendLock) + { if (_sending) return; @@ -476,7 +434,7 @@ private void TrySend() } else return; - + } // Check if the flush buffer is empty if (_sendBufferFlush.IsEmpty) @@ -498,7 +456,6 @@ private void TrySend() OnTrySendException(ex); } } - } } /// From be0401cc233cb494816db0c0645b610b683bf442 Mon Sep 17 00:00:00 2001 From: Ciaran Fisher Date: Tue, 19 May 2020 21:11:12 +0100 Subject: [PATCH 2/5] Removed Duplex Removed duplex from MIDS Fixed F5 Volume Added UH1 Cockpit radio off / on controls Added F16 UHF Guard via DED Added F5 HQ --- DCS-SR-Client/Network/UDPVoiceHandler.cs | 7 +- .../Scripts/DCS-SimpleRadioStandalone.lua | 69 ++++++++++++++++--- 2 files changed, 66 insertions(+), 10 deletions(-) diff --git a/DCS-SR-Client/Network/UDPVoiceHandler.cs b/DCS-SR-Client/Network/UDPVoiceHandler.cs index 71d5e503a..731983201 100644 --- a/DCS-SR-Client/Network/UDPVoiceHandler.cs +++ b/DCS-SR-Client/Network/UDPVoiceHandler.cs @@ -505,9 +505,12 @@ private List CurrentlyBlockedRadios() var currentRadio = _clientStateSingleton.DcsPlayerRadioInfo.radios[_clientStateSingleton.DcsPlayerRadioInfo.selected]; - if (currentRadio.modulation == RadioInformation.Modulation.FM || currentRadio.modulation == RadioInformation.Modulation.AM) + if (currentRadio.modulation == RadioInformation.Modulation.FM + || currentRadio.modulation == RadioInformation.Modulation.AM + || currentRadio.modulation == RadioInformation.Modulation.MIDS + || currentRadio.modulation == RadioInformation.Modulation.HAVEQUICK) { - //only AM and FM block - MIDS etc dont + //only AM and FM block - SATCOM etc dont transmitting.Add(_clientStateSingleton.DcsPlayerRadioInfo.selected); } diff --git a/Scripts/DCS-SRS/Scripts/DCS-SimpleRadioStandalone.lua b/Scripts/DCS-SRS/Scripts/DCS-SimpleRadioStandalone.lua index b4d6677e7..0fe5c3c39 100644 --- a/Scripts/DCS-SRS/Scripts/DCS-SimpleRadioStandalone.lua +++ b/Scripts/DCS-SRS/Scripts/DCS-SimpleRadioStandalone.lua @@ -754,16 +754,27 @@ function SR.exportRadioUH1H(_data) _data.capabilities = { dcsPtt = true, dcsIFF = true, dcsRadioSwitch = true, intercomHotMic = false, desc = "" } + local intercomOn = SR.getButtonPosition(27) _data.radios[1].name = "Intercom" _data.radios[1].freq = 100.0 _data.radios[1].modulation = 2 --Special intercom modulation _data.radios[1].volume = SR.getRadioVolume(0, 29, { 0.3, 1.0 }, true) + if intercomOn < 0.5 then + _data.radios[1].modulation = 3 + end + + local fmOn = SR.getButtonPosition(23) _data.radios[2].name = "AN/ARC-131" _data.radios[2].freq = SR.getRadioFrequency(23) _data.radios[2].modulation = 1 _data.radios[2].volume = SR.getRadioVolume(0, 37, { 0.3, 1.0 }, true) + if fmOn < 0.5 then + _data.radios[2].freq = 1 + end + + local uhfOn = SR.getButtonPosition(24) _data.radios[3].name = "AN/ARC-51BX - UHF" _data.radios[3].freq = SR.getRadioFrequency(22) _data.radios[3].modulation = 0 @@ -776,18 +787,29 @@ function SR.exportRadioUH1H(_data) _data.radios[3].channel = SR.getSelectorPosition(16, 0.05) + 1 --add 1 as channel 0 is channel 1 end - _data.radios[4].name = "AN/ARC-134" - _data.radios[4].freq = SR.getRadioFrequency(20) - _data.radios[4].modulation = 0 - _data.radios[4].volume = SR.getRadioVolume(0, 9, { 0.0, 0.60 }, false) + if uhfOn < 0.5 then + _data.radios[3].freq = 1 + _data.radios[3].channel = -1 + end - --_device:get_argument_value(_arg) --guard mode for UHF Radio local uhfModeKnob = SR.getSelectorPosition(17, 0.1) if uhfModeKnob == 2 and _data.radios[3].freq > 1000 then _data.radios[3].secFreq = 243.0 * 1000000 end + local vhfOn = SR.getButtonPosition(25) + _data.radios[4].name = "AN/ARC-134" + _data.radios[4].freq = SR.getRadioFrequency(20) + _data.radios[4].modulation = 0 + _data.radios[4].volume = SR.getRadioVolume(0, 9, { 0.0, 0.60 }, false) + + if vhfOn < 0.5 then + _data.radios[4].freq = 1 + end + + --_device:get_argument_value(_arg) + local _panel = GetDevice(0) local switch = _panel:get_argument_value(30) @@ -1694,6 +1716,10 @@ function SR.exportRadioFA18C(_data) return _data end +local _f16 = {} +_f16.radio1 = {} +_f16.radio1.guard = 0 + function SR.exportRadioF16C(_data) _data.capabilities = { dcsPtt = false, dcsIFF = true, dcsRadioSwitch = false, intercomHotMic = false, desc = "" } @@ -1723,7 +1749,26 @@ function SR.exportRadioF16C(_data) local _channel = SR.getSelectorPosition(410, 0.05) + 1 --add 1 as channel 0 is channel 1 _data.radios[2].channel = _channel end - end + else + -- Parse the UFC - LOOK FOR BOTH (OR MAIN) + local ded = SR.getListIndicatorValue(6) + --PANEL 6{"Active Frequency or Channel":"305.00","Asterisks on Scratchpad_lhs":"*","Asterisks on Scratchpad_rhs":"*","Bandwidth":"NB","Bandwidth_placeholder":"","COM 1 Mode":"UHF","Preset Frequency":"305.00","Preset Frequency_placeholder":"","Preset Label":"PRE a","Preset Number":" 1","Preset Number_placeholder":"","Receiver Mode":"BOTH","Scratchpad":"305.00","Scratchpad_placeholder":"","TOD Label":"TOD"} + + if ded["Receiver Mode"] ~= nil and ded["COM 1 Mode"] == "UHF" then + if ded["Receiver Mode"] == "BOTH" then + _f16.radio1.guard= 243.0 * 1000000 + else + _f16.radio1.guard= 0 + end + else + if _data.radios[2].freq < 1000 then + _f16.radio1.guard= 0 + end + end + + _data.radios[2].secFreq = _f16.radio1.guard + + end -- VHF _data.radios[3].name = "AN/ARC-222" @@ -2037,8 +2082,16 @@ function SR.exportRadioF5E(_data) _data.radios[2].name = "AN/ARC-164" _data.radios[2].freq = SR.getRadioFrequency(23) - _data.radios[2].modulation = 0 - _data.radios[2].volume = SR.getRadioVolume(0, 309, { 0.1, 0.9 }, false) + _data.radios[2].volume = SR.getRadioVolume(0, 309, { 0.0, 1.0 }, false) + + local modulation = SR.getSelectorPosition(327, 0.1) + + --is HQ selected (A on the Radio) + if modulation == 0 then + _data.radios[2].modulation = 4 + else + _data.radios[2].modulation = 0 + end -- get channel selector local _selector = SR.getSelectorPosition(307, 0.1) From 97658d5b3ebc8a88d214add627a61c152ab5f806 Mon Sep 17 00:00:00 2001 From: Ciaran Fisher Date: Thu, 21 May 2020 20:14:33 +0100 Subject: [PATCH 3/5] Better error handling for installer Error handling for server startup Refactored the UDP listeners to busy wait and keep trying until they can bind --- .../Network/DCS/DCSAutoConnectHandler.cs | 78 ++++---- .../Network/DCS/DCSGameGuiHandler.cs | 117 ++++++------ .../Network/DCS/DCSLineOfSightHandler.cs | 93 +++++---- .../Network/DCS/DCSRadioSyncHandler.cs | 107 +++++------ .../Network/LotATC/LotATCSyncHandler.cs | 91 +++++---- DCS-SR-Client/Network/UDPCommandHandler.cs | 180 +++++++++--------- .../Network/VAICOM/VAICOMSyncHandler.cs | 31 +-- DCS-SR-Client/Settings/GlobalSettingsStore.cs | 4 + DCS-SimpleRadio Server/Network/ServerSync.cs | 22 ++- .../Network/UDPPositionHandler.cs | 3 +- Installer/MainWindow.xaml.cs | 39 +++- .../Scripts/DCS-SimpleRadioStandalone.lua | 132 ++++--------- 12 files changed, 469 insertions(+), 428 deletions(-) diff --git a/DCS-SR-Client/Network/DCS/DCSAutoConnectHandler.cs b/DCS-SR-Client/Network/DCS/DCSAutoConnectHandler.cs index f156a82c6..294077316 100644 --- a/DCS-SR-Client/Network/DCS/DCSAutoConnectHandler.cs +++ b/DCS-SR-Client/Network/DCS/DCSAutoConnectHandler.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Threading; +using Ciribob.DCS.SimpleRadio.Standalone.Client.Settings; using Ciribob.DCS.SimpleRadio.Standalone.Client.UI; using NLog; @@ -42,53 +43,62 @@ public DCSAutoConnectHandler(MainWindow.ReceivedAutoConnect receivedAutoConnect) private void StartDcsBroadcastListener() { - _dcsUdpListener = new UdpClient(); - _dcsUdpListener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); - _dcsUdpListener.ExclusiveAddressUse = false; - - var localEp = new IPEndPoint(IPAddress.Any, 5069); - _dcsUdpListener.Client.Bind(localEp); - + Task.Factory.StartNew(() => { - using (_dcsUdpListener) + while(!_stop) { - while (!_stop) + var localEp = new IPEndPoint(IPAddress.Any, + GlobalSettingsStore.Instance.GetNetworkSetting(GlobalSettingsKeys.DCSAutoConnectUDP)); + try { - try - { - var groupEp = new IPEndPoint(IPAddress.Any, 5069); - var bytes = _dcsUdpListener.Receive(ref groupEp); - - var message = Encoding.UTF8.GetString( - bytes, 0, bytes.Length); - - HandleMessage(message); - } - catch (SocketException e) - { - // SocketException is raised when closing app/disconnecting, ignore so we don't log "irrelevant" exceptions - if (!_stop) - { - Logger.Error(e, "SocketException Handling DCS AutoConnect Message"); - } - } - catch (Exception e) - { - Logger.Error(e, "Exception Handling DCS AutoConnect Message"); - } + _dcsUdpListener = new UdpClient(localEp); + break; + } + catch(Exception ex) + { + Logger.Warn(ex, $"Unable to bind to the AutoConnect Socket Port: {localEp.Port}"); + Thread.Sleep(500); } + + } + while (!_stop) + { try { - _dcsUdpListener.Close(); + var groupEp = new IPEndPoint(IPAddress.Any, 0); + var bytes = _dcsUdpListener.Receive(ref groupEp); + + var message = Encoding.UTF8.GetString( + bytes, 0, bytes.Length); + + HandleMessage(message); + } + catch (SocketException e) + { + // SocketException is raised when closing app/disconnecting, ignore so we don't log "irrelevant" exceptions + if (!_stop) + { + Logger.Error(e, "SocketException Handling DCS AutoConnect Message"); + } } catch (Exception e) { - Logger.Error(e, "Exception stoping DCS AutoConnect listener "); + Logger.Error(e, "Exception Handling DCS AutoConnect Message"); } } + + + try + { + _dcsUdpListener.Close(); + } + catch (Exception e) + { + Logger.Error(e, "Exception stoping DCS AutoConnect listener "); + } }); } @@ -124,7 +134,7 @@ public void Stop() try { - _dcsUdpListener.Close(); + _dcsUdpListener?.Close(); } catch (Exception ex) { diff --git a/DCS-SR-Client/Network/DCS/DCSGameGuiHandler.cs b/DCS-SR-Client/Network/DCS/DCSGameGuiHandler.cs index d55ebc7fb..b3d6f866e 100644 --- a/DCS-SR-Client/Network/DCS/DCSGameGuiHandler.cs +++ b/DCS-SR-Client/Network/DCS/DCSGameGuiHandler.cs @@ -4,6 +4,7 @@ using System.Net; using System.Net.Sockets; using System.Text; +using System.Threading; using System.Threading.Tasks; using Ciribob.DCS.SimpleRadio.Standalone.Client.Settings; using Ciribob.DCS.SimpleRadio.Standalone.Client.Singletons; @@ -33,84 +34,90 @@ public DCSGameGuiHandler(DCSRadioSyncManager.ClientSideUpdate clientSideUpdate) public void Start() { - _dcsGameGuiUdpListener = new UdpClient(); - _dcsGameGuiUdpListener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, - true); - _dcsGameGuiUdpListener.ExclusiveAddressUse = false; // only if you want to send/receive on same machine. - - var localEp = new IPEndPoint(IPAddress.Any, - _globalSettings.GetNetworkSetting(GlobalSettingsKeys.DCSIncomingGameGUIUDP)); - _dcsGameGuiUdpListener.Client.Bind(localEp); - // activeRadioUdpClient.Client.ReceiveTimeout = 10000; _clientStateSingleton.LastPostionCoalitionSent = 0; Task.Factory.StartNew(() => { - using (_dcsGameGuiUdpListener) + while (!_stop) { - // var count = 0; - while (!_stop) + var localEp = new IPEndPoint(IPAddress.Any, + _globalSettings.GetNetworkSetting(GlobalSettingsKeys.DCSIncomingGameGUIUDP)); + try { - try - { - var groupEp = new IPEndPoint(IPAddress.Any, - _globalSettings.GetNetworkSetting(GlobalSettingsKeys.DCSIncomingGameGUIUDP)); - var bytes = _dcsGameGuiUdpListener.Receive(ref groupEp); + _dcsGameGuiUdpListener = new UdpClient(localEp); + break; + } + catch (Exception ex) + { + Logger.Warn(ex, $"Unable to bind to the DCS GameGUI Socket Port: {localEp.Port}"); + Thread.Sleep(500); + } - var updatedPlayerInfo = - JsonConvert.DeserializeObject(Encoding.UTF8.GetString( - bytes, 0, bytes.Length)); + } - if (updatedPlayerInfo != null) - { - var shouldUpdate = _serverSettings.GetSettingAsBool(ServerSettingsKeys.DISTANCE_ENABLED) || _serverSettings.GetSettingAsBool(ServerSettingsKeys.LOS_ENABLED); + // var count = 0; + while (!_stop) + { + try + { + var groupEp = new IPEndPoint(IPAddress.Any,0); + var bytes = _dcsGameGuiUdpListener.Receive(ref groupEp); + + var updatedPlayerInfo = + JsonConvert.DeserializeObject(Encoding.UTF8.GetString( + bytes, 0, bytes.Length)); + + if (updatedPlayerInfo != null) + { + var shouldUpdate = _serverSettings.GetSettingAsBool(ServerSettingsKeys.DISTANCE_ENABLED) || _serverSettings.GetSettingAsBool(ServerSettingsKeys.LOS_ENABLED); - var currentInfo = _clientStateSingleton.PlayerCoaltionLocationMetadata; + var currentInfo = _clientStateSingleton.PlayerCoaltionLocationMetadata; - bool changed = !updatedPlayerInfo.Equals(currentInfo); - //copy the bits we need - leave position + bool changed = !updatedPlayerInfo.Equals(currentInfo); + //copy the bits we need - leave position - currentInfo.name = updatedPlayerInfo.name; - currentInfo.side = updatedPlayerInfo.side; - currentInfo.seat = updatedPlayerInfo.seat; + currentInfo.name = updatedPlayerInfo.name; + currentInfo.side = updatedPlayerInfo.side; + currentInfo.seat = updatedPlayerInfo.seat; - //this will clear any stale positions if nothing is currently connected - _clientStateSingleton.ClearPositionsIfExpired(); - - //only update if position is changed - if (_clientStateSingleton.DcsPlayerRadioInfo.IsCurrent() && (changed || shouldUpdate)) - { - _clientSideUpdate(); - } - - // count = 0; + //this will clear any stale positions if nothing is currently connected + _clientStateSingleton.ClearPositionsIfExpired(); - _clientStateSingleton.DcsGameGuiLastReceived = DateTime.Now.Ticks; - } - } - catch (SocketException e) - { - // SocketException is raised when closing app/disconnecting, ignore so we don't log "irrelevant" exceptions - if (!_stop) + //only update if position is changed + if (_clientStateSingleton.DcsPlayerRadioInfo.IsCurrent() && (changed || shouldUpdate)) { - Logger.Error(e, "SocketException Handling DCS GameGUI Message"); + _clientSideUpdate(); } - } - catch (Exception e) - { - Logger.Error(e, "Exception Handling DCS GameGUI Message"); + + // count = 0; + + _clientStateSingleton.DcsGameGuiLastReceived = DateTime.Now.Ticks; } } - - try + catch (SocketException e) { - _dcsGameGuiUdpListener.Close(); + // SocketException is raised when closing app/disconnecting, ignore so we don't log "irrelevant" exceptions + if (!_stop) + { + Logger.Error(e, "SocketException Handling DCS GameGUI Message"); + } } catch (Exception e) { - Logger.Error(e, "Exception stoping DCS listener "); + Logger.Error(e, "Exception Handling DCS GameGUI Message"); } } + + try + { + _dcsGameGuiUdpListener.Close(); + } + catch (Exception e) + { + Logger.Error(e, "Exception stoping DCS listener "); + } + + }); } diff --git a/DCS-SR-Client/Network/DCS/DCSLineOfSightHandler.cs b/DCS-SR-Client/Network/DCS/DCSLineOfSightHandler.cs index 066b94fe7..441751ba6 100644 --- a/DCS-SR-Client/Network/DCS/DCSLineOfSightHandler.cs +++ b/DCS-SR-Client/Network/DCS/DCSLineOfSightHandler.cs @@ -42,68 +42,77 @@ public void Start() //used for the result private void StartDCSLOSBroadcastListener() { - _dcsLOSListener = new UdpClient(); - _dcsLOSListener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, - true); - _dcsLOSListener.ExclusiveAddressUse = false; // only if you want to send/receive on same machine. - var localEp = new IPEndPoint(IPAddress.Any, _globalSettings.GetNetworkSetting(GlobalSettingsKeys.DCSLOSIncomingUDP)); - _dcsLOSListener.Client.Bind(localEp); + Task.Factory.StartNew(() => { - using (_dcsLOSListener) + + while (!_stop) { - // var count = 0; - while (!_stop) + var localEp = new IPEndPoint(IPAddress.Any, _globalSettings.GetNetworkSetting(GlobalSettingsKeys.DCSLOSIncomingUDP)); + try { - try - { - var groupEp = new IPEndPoint(IPAddress.Any, - _globalSettings.GetNetworkSetting(GlobalSettingsKeys.DCSLOSIncomingUDP)); - var bytes = _dcsLOSListener.Receive(ref groupEp); - - /* Logger.Debug(Encoding.UTF8.GetString( - bytes, 0, bytes.Length));*/ - var playerInfo = - JsonConvert.DeserializeObject(Encoding.UTF8.GetString( - bytes, 0, bytes.Length)); + _dcsLOSListener = new UdpClient(localEp); + break; + } + catch (Exception ex) + { + Logger.Warn(ex, $"Unable to bind to the DCS LOS Listner Socket Port: {localEp.Port}"); + Thread.Sleep(500); + } - foreach (var player in playerInfo) - { - SRClient client; + } + + // var count = 0; + while (!_stop) + { + try + { + var groupEp = new IPEndPoint(IPAddress.Any,0); + var bytes = _dcsLOSListener.Receive(ref groupEp); - if (_clients.TryGetValue(player.id, out client)) - { - client.LineOfSightLoss = player.los; + /* Logger.Debug(Encoding.UTF8.GetString( + bytes, 0, bytes.Length));*/ + var playerInfo = + JsonConvert.DeserializeObject(Encoding.UTF8.GetString( + bytes, 0, bytes.Length)); - // Logger.Debug(client.ToString()); - } - } - } - catch (SocketException e) + foreach (var player in playerInfo) { - // SocketException is raised when closing app/disconnecting, ignore so we don't log "irrelevant" exceptions - if (!_stop) + SRClient client; + + if (_clients.TryGetValue(player.id, out client)) { - Logger.Error(e, "SocketException Handling DCS Los Result Message"); + client.LineOfSightLoss = player.los; + + // Logger.Debug(client.ToString()); } } - catch (Exception e) - { - Logger.Error(e, "Exception Handling DCS Los Result Message"); - } } - - try + catch (SocketException e) { - _dcsLOSListener.Close(); + // SocketException is raised when closing app/disconnecting, ignore so we don't log "irrelevant" exceptions + if (!_stop) + { + Logger.Error(e, "SocketException Handling DCS Los Result Message"); + } } catch (Exception e) { - Logger.Error(e, "Exception stoping DCS LOS Result listener "); + Logger.Error(e, "Exception Handling DCS Los Result Message"); } } + + try + { + _dcsLOSListener.Close(); + } + catch (Exception e) + { + Logger.Error(e, "Exception stoping DCS LOS Result listener "); + } + }); } diff --git a/DCS-SR-Client/Network/DCS/DCSRadioSyncHandler.cs b/DCS-SR-Client/Network/DCS/DCSRadioSyncHandler.cs index d31248cbe..3f1b44ba1 100644 --- a/DCS-SR-Client/Network/DCS/DCSRadioSyncHandler.cs +++ b/DCS-SR-Client/Network/DCS/DCSRadioSyncHandler.cs @@ -18,6 +18,7 @@ using Ciribob.DCS.SimpleRadio.Standalone.Common.Network; using Newtonsoft.Json; using NLog; +using System.Threading; namespace Ciribob.DCS.SimpleRadio.Standalone.Client.Network.DCS { @@ -54,75 +55,76 @@ public DCSRadioSyncHandler(DCSRadioSyncManager.SendRadioUpdate radioUpdate, NewA public void Start() { - _dcsUdpListener = new UdpClient(); - _dcsUdpListener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); - _dcsUdpListener.ExclusiveAddressUse = false; // only if you want to send/receive on same machine. - - // var multicastaddress = IPAddress.Parse("239.255.50.10"); - // _dcsUdpListener.JoinMulticastGroup(multicastaddress); - - var localEp = new IPEndPoint(IPAddress.Any, _globalSettings.GetNetworkSetting(GlobalSettingsKeys.DCSIncomingUDP)); - _dcsUdpListener.Client.Bind(localEp); - // activeRadioUdpClient.Client.ReceiveTimeout = 10000; - //reset last sent _clientStateSingleton.LastSent = 0; Task.Factory.StartNew(() => { - using (_dcsUdpListener) + while (!_stop) { - while (!_stop) + var localEp = new IPEndPoint(IPAddress.Any, _globalSettings.GetNetworkSetting(GlobalSettingsKeys.DCSIncomingUDP)); + try { - try - { - var groupEp = new IPEndPoint(IPAddress.Any, - _globalSettings.GetNetworkSetting(GlobalSettingsKeys.DCSIncomingUDP)); - var bytes = _dcsUdpListener.Receive(ref groupEp); - - var str = Encoding.UTF8.GetString( - bytes, 0, bytes.Length).Trim(); - - var message = - JsonConvert.DeserializeObject(str); + _dcsUdpListener = new UdpClient(localEp); + break; + } + catch (Exception ex) + { + Logger.Warn(ex, $"Unable to bind to the DCS Export Listener Socket Port: {localEp.Port}"); + Thread.Sleep(500); + } + } - Logger.Debug($"Recevied Message from DCS {str}"); + while (!_stop) + { + try + { + var groupEp = new IPEndPoint(IPAddress.Any,0); + var bytes = _dcsUdpListener.Receive(ref groupEp); - if (!string.IsNullOrWhiteSpace(message.name) && message.name != "Unknown" && message.name != _clientStateSingleton.LastSeenName) - { - _clientStateSingleton.LastSeenName = message.name; - } + var str = Encoding.UTF8.GetString( + bytes, 0, bytes.Length).Trim(); - _clientStateSingleton.DcsExportLastReceived = DateTime.Now.Ticks; + var message = + JsonConvert.DeserializeObject(str); - //sync with others - //Radio info is marked as Stale for FC3 aircraft after every frequency change + Logger.Debug($"Recevied Message from DCS {str}"); - ProcessRadioInfo(message); - } - catch (SocketException e) - { - // SocketException is raised when closing app/disconnecting, ignore so we don't log "irrelevant" exceptions - if (!_stop) - { - Logger.Error(e, "SocketException Handling DCS Message"); - } - } - catch (Exception e) + if (!string.IsNullOrWhiteSpace(message.name) && message.name != "Unknown" && message.name != _clientStateSingleton.LastSeenName) { - Logger.Error(e, "Exception Handling DCS Message"); + _clientStateSingleton.LastSeenName = message.name; } - } - try + _clientStateSingleton.DcsExportLastReceived = DateTime.Now.Ticks; + + //sync with others + //Radio info is marked as Stale for FC3 aircraft after every frequency change + + ProcessRadioInfo(message); + } + catch (SocketException e) { - _dcsUdpListener.Close(); + // SocketException is raised when closing app/disconnecting, ignore so we don't log "irrelevant" exceptions + if (!_stop) + { + Logger.Error(e, "SocketException Handling DCS Message"); + } } catch (Exception e) { - Logger.Error(e, "Exception stoping DCS listener "); + Logger.Error(e, "Exception Handling DCS Message"); } } + + try + { + _dcsUdpListener.Close(); + } + catch (Exception e) + { + Logger.Error(e, "Exception stoping DCS listener "); + } + }); } @@ -155,14 +157,7 @@ private void SendRadioUpdateToDCS() { if (_dcsRadioUpdateSender == null) { - _dcsRadioUpdateSender = new UdpClient - { - ExclusiveAddressUse = false, - EnableBroadcast = true - }; - _dcsRadioUpdateSender.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, - true); - _dcsRadioUpdateSender.ExclusiveAddressUse = false; + _dcsRadioUpdateSender = new UdpClient(); } try diff --git a/DCS-SR-Client/Network/LotATC/LotATCSyncHandler.cs b/DCS-SR-Client/Network/LotATC/LotATCSyncHandler.cs index 58018b702..ecce836b9 100644 --- a/DCS-SR-Client/Network/LotATC/LotATCSyncHandler.cs +++ b/DCS-SR-Client/Network/LotATC/LotATCSyncHandler.cs @@ -48,66 +48,73 @@ public LotATCSyncHandler(DCSRadioSyncManager.ClientSideUpdate clientSideUpdate, public void Start() { - _lotATCPositionListener = new UdpClient(); - _lotATCPositionListener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, - true); - _lotATCPositionListener.ExclusiveAddressUse = false; // only if you want to send/receive on same machine. - - var localEp = new IPEndPoint(IPAddress.Any, - _globalSettings.GetNetworkSetting(GlobalSettingsKeys.LotATCIncomingUDP)); - _lotATCPositionListener.Client.Bind(localEp); + + Task.Factory.StartNew(() => { - using (_lotATCPositionListener) + while (!_stop) { - while (!_stop) + var localEp = new IPEndPoint(IPAddress.Any, + _globalSettings.GetNetworkSetting(GlobalSettingsKeys.LotATCIncomingUDP)); + try { - try - { - var groupEp = new IPEndPoint(IPAddress.Any, - _globalSettings.GetNetworkSetting(GlobalSettingsKeys.LotATCIncomingUDP)); - var bytes = _lotATCPositionListener.Receive(ref groupEp); + _lotATCPositionListener = new UdpClient(localEp); + break; + } + catch (Exception ex) + { + Logger.Warn(ex, $"Unable to bind to the LotATC Export Listener Socket Port: {localEp.Port}"); + Thread.Sleep(500); + } + } + + while (!_stop) + { + try + { + var groupEp = new IPEndPoint(IPAddress.Any,0); + var bytes = _lotATCPositionListener.Receive(ref groupEp); - var lotAtcPositionWrapper = - JsonConvert.DeserializeObject(Encoding.UTF8.GetString( - bytes, 0, bytes.Length)); + var lotAtcPositionWrapper = + JsonConvert.DeserializeObject(Encoding.UTF8.GetString( + bytes, 0, bytes.Length)); - if (lotAtcPositionWrapper != null ) - { - - if (lotAtcPositionWrapper.los != null) - { - HandleLOSResponse(lotAtcPositionWrapper.los); - } - else if (lotAtcPositionWrapper.controller !=null) - { - HandleLotATCUpdate(lotAtcPositionWrapper.controller); - } - } - } - catch (SocketException e) + if (lotAtcPositionWrapper != null ) { - if (!_stop) + + if (lotAtcPositionWrapper.los != null) + { + HandleLOSResponse(lotAtcPositionWrapper.los); + } + else if (lotAtcPositionWrapper.controller !=null) { - Logger.Error(e, "SocketException Handling LotATC UDP Message"); + HandleLotATCUpdate(lotAtcPositionWrapper.controller); } } - catch (Exception e) - { - Logger.Error(e, "Exception Handling LotATC UDP Message"); - } } - - try + catch (SocketException e) { - _lotATCPositionListener.Close(); + if (!_stop) + { + Logger.Error(e, "SocketException Handling LotATC UDP Message"); + } } catch (Exception e) { - Logger.Error(e, "Exception stoping LotATC UDP listener"); + Logger.Error(e, "Exception Handling LotATC UDP Message"); } } + + try + { + _lotATCPositionListener.Close(); + } + catch (Exception e) + { + Logger.Error(e, "Exception stoping LotATC UDP listener"); + } + }); StartLotATCLOSSender(); diff --git a/DCS-SR-Client/Network/UDPCommandHandler.cs b/DCS-SR-Client/Network/UDPCommandHandler.cs index 943da57d9..2ca2272c3 100644 --- a/DCS-SR-Client/Network/UDPCommandHandler.cs +++ b/DCS-SR-Client/Network/UDPCommandHandler.cs @@ -9,6 +9,7 @@ using System.Net; using System.Net.Sockets; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace Ciribob.DCS.SimpleRadio.Standalone.Client.Network @@ -27,111 +28,118 @@ public void Start() private void StartUDPCommandListener() { - _udpCommandListener = new UdpClient(); - _udpCommandListener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); - _udpCommandListener.ExclusiveAddressUse = false; // only if you want to send/receive on same machine. - - var localEp = new IPEndPoint(IPAddress.Any, _globalSettings.GetNetworkSetting(GlobalSettingsKeys.CommandListenerUDP)); - _udpCommandListener.Client.Bind(localEp); + Task.Factory.StartNew(() => { - using (_udpCommandListener) + while (!_stop) { - while (!_stop) + var localEp = new IPEndPoint(IPAddress.Any, _globalSettings.GetNetworkSetting(GlobalSettingsKeys.CommandListenerUDP)); + try { - try - { - var groupEp = new IPEndPoint(IPAddress.Any, - _globalSettings.GetNetworkSetting(GlobalSettingsKeys.CommandListenerUDP)); - var bytes = _udpCommandListener.Receive(ref groupEp); + _udpCommandListener = new UdpClient(localEp); + break; + } + catch (Exception ex) + { + Logger.Warn(ex, $"Unable to bind to the UDP Command Listener Socket Port: {localEp.Port}"); + Thread.Sleep(500); + } + } + + while (!_stop) + { + try + { + var groupEp = new IPEndPoint(IPAddress.Any,0); + var bytes = _udpCommandListener.Receive(ref groupEp); - //Logger.Info("Recevied Message from UDP COMMAND INTERFACE: "+ Encoding.UTF8.GetString( - // bytes, 0, bytes.Length)); - var message = - JsonConvert.DeserializeObject(Encoding.UTF8.GetString( - bytes, 0, bytes.Length)); + //Logger.Info("Recevied Message from UDP COMMAND INTERFACE: "+ Encoding.UTF8.GetString( + // bytes, 0, bytes.Length)); + var message = + JsonConvert.DeserializeObject(Encoding.UTF8.GetString( + bytes, 0, bytes.Length)); - if (message?.Command == UDPInterfaceCommand.UDPCommandType.FREQUENCY_DELTA) - { - RadioHelper.UpdateRadioFrequency(message.Frequency, message.RadioId); - } - else if (message?.Command == UDPInterfaceCommand.UDPCommandType.FREQUENCY_SET) - { - RadioHelper.UpdateRadioFrequency(message.Frequency, message.RadioId,false,true); - } - else if (message?.Command == UDPInterfaceCommand.UDPCommandType.ACTIVE_RADIO) - { - RadioHelper.SelectRadio(message.RadioId); - } - else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TOGGLE_GUARD) - { - RadioHelper.ToggleGuard(message.RadioId); - } - else if (message?.Command == UDPInterfaceCommand.UDPCommandType.GUARD) - { - RadioHelper.SetGuard(message.RadioId, message.Enabled); - } - else if (message?.Command == UDPInterfaceCommand.UDPCommandType.CHANNEL_UP) - { - RadioHelper.RadioChannelUp(message.RadioId); - } - else if (message?.Command == UDPInterfaceCommand.UDPCommandType.CHANNEL_DOWN) - { - RadioHelper.RadioChannelDown(message.RadioId); - } - else if (message?.Command == UDPInterfaceCommand.UDPCommandType.SET_VOLUME) - { - RadioHelper.SetRadioVolume(message.Volume, message.RadioId); - } - else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TRANSPONDER_POWER) - { - TransponderHelper.SetPower(message.Enabled); - } - else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TRANSPONDER_M1_CODE) - { - TransponderHelper.SetMode1(message.Code); - } - else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TRANSPONDER_M3_CODE) - { - TransponderHelper.SetMode3(message.Code); - } - else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TRANSPONDER_M4) - { - TransponderHelper.SetMode4(message.Enabled); - } - else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TRANSPONDER_IDENT) - { - TransponderHelper.SetIdent(message.Enabled); - } - else - { - Logger.Error("Unknown UDP Command!"); - } + if (message?.Command == UDPInterfaceCommand.UDPCommandType.FREQUENCY_DELTA) + { + RadioHelper.UpdateRadioFrequency(message.Frequency, message.RadioId); + } + else if (message?.Command == UDPInterfaceCommand.UDPCommandType.FREQUENCY_SET) + { + RadioHelper.UpdateRadioFrequency(message.Frequency, message.RadioId,false,true); + } + else if (message?.Command == UDPInterfaceCommand.UDPCommandType.ACTIVE_RADIO) + { + RadioHelper.SelectRadio(message.RadioId); + } + else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TOGGLE_GUARD) + { + RadioHelper.ToggleGuard(message.RadioId); + } + else if (message?.Command == UDPInterfaceCommand.UDPCommandType.GUARD) + { + RadioHelper.SetGuard(message.RadioId, message.Enabled); + } + else if (message?.Command == UDPInterfaceCommand.UDPCommandType.CHANNEL_UP) + { + RadioHelper.RadioChannelUp(message.RadioId); } - catch (SocketException e) + else if (message?.Command == UDPInterfaceCommand.UDPCommandType.CHANNEL_DOWN) { - // SocketException is raised when closing app/disconnecting, ignore so we don't log "irrelevant" exceptions - if (!_stop) - { - Logger.Error(e, "SocketException Handling DCS Message"); - } + RadioHelper.RadioChannelDown(message.RadioId); } - catch (Exception e) + else if (message?.Command == UDPInterfaceCommand.UDPCommandType.SET_VOLUME) { - Logger.Error(e, "Exception Handling DCS Message"); + RadioHelper.SetRadioVolume(message.Volume, message.RadioId); + } + else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TRANSPONDER_POWER) + { + TransponderHelper.SetPower(message.Enabled); + } + else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TRANSPONDER_M1_CODE) + { + TransponderHelper.SetMode1(message.Code); + } + else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TRANSPONDER_M3_CODE) + { + TransponderHelper.SetMode3(message.Code); + } + else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TRANSPONDER_M4) + { + TransponderHelper.SetMode4(message.Enabled); + } + else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TRANSPONDER_IDENT) + { + TransponderHelper.SetIdent(message.Enabled); + } + else + { + Logger.Error("Unknown UDP Command!"); } } - - try + catch (SocketException e) { - _udpCommandListener.Close(); + // SocketException is raised when closing app/disconnecting, ignore so we don't log "irrelevant" exceptions + if (!_stop) + { + Logger.Error(e, "SocketException Handling DCS Message"); + } } catch (Exception e) { - Logger.Error(e, "Exception stoping DCS listener "); + Logger.Error(e, "Exception Handling DCS Message"); } } + + try + { + _udpCommandListener.Close(); + } + catch (Exception e) + { + Logger.Error(e, "Exception stoping DCS listener "); + } + }); } diff --git a/DCS-SR-Client/Network/VAICOM/VAICOMSyncHandler.cs b/DCS-SR-Client/Network/VAICOM/VAICOMSyncHandler.cs index 8698510df..a165aad7c 100644 --- a/DCS-SR-Client/Network/VAICOM/VAICOMSyncHandler.cs +++ b/DCS-SR-Client/Network/VAICOM/VAICOMSyncHandler.cs @@ -36,25 +36,30 @@ public VAICOMSyncHandler() public void Start() { - _vaicomUDPListener = new UdpClient(); - _vaicomUDPListener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, - true); - _vaicomUDPListener.ExclusiveAddressUse = false; // only if you want to send/receive on same machine. - - var localEp = new IPEndPoint(IPAddress.Any, - _globalSettings.GetNetworkSetting(GlobalSettingsKeys.VAICOMIncomingUDP)); - _vaicomUDPListener.Client.Bind(localEp); + Task.Factory.StartNew(() => { - using (_vaicomUDPListener) + while (!_stop) { - while (!_stop) + var localEp = new IPEndPoint(IPAddress.Any, + _globalSettings.GetNetworkSetting(GlobalSettingsKeys.VAICOMIncomingUDP)); + try + { + _vaicomUDPListener = new UdpClient(localEp); + break; + } + catch (Exception ex) + { + Logger.Warn(ex, $"Unable to bind to the VAICOM Listener Socket Port: {localEp.Port}"); + Thread.Sleep(500); + } + } + while (!_stop) { try { - var groupEp = new IPEndPoint(IPAddress.Any, - _globalSettings.GetNetworkSetting(GlobalSettingsKeys.VAICOMIncomingUDP)); + var groupEp = new IPEndPoint(IPAddress.Any,0); var bytes = _vaicomUDPListener.Receive(ref groupEp); var vaicomMessageWrapper = @@ -94,7 +99,7 @@ public void Start() { Logger.Error(e, "Exception stoping VAICOM UDP listener"); } - } + }); diff --git a/DCS-SR-Client/Settings/GlobalSettingsStore.cs b/DCS-SR-Client/Settings/GlobalSettingsStore.cs index 8dd6e789b..619746c17 100644 --- a/DCS-SR-Client/Settings/GlobalSettingsStore.cs +++ b/DCS-SR-Client/Settings/GlobalSettingsStore.cs @@ -82,6 +82,8 @@ public enum GlobalSettingsKeys VAICOMTXInhibitEnabled, LotATCHeightOffset, + + DCSAutoConnectUDP // 5069 } public enum InputBinding @@ -354,6 +356,8 @@ public void SetClientSetting(GlobalSettingsKeys key, string[] strArray) {GlobalSettingsKeys.OutgoingDCSUDPOther.ToString(), "7082"}, {GlobalSettingsKeys.DCSIncomingGameGUIUDP.ToString(), "5068"}, {GlobalSettingsKeys.DCSLOSIncomingUDP.ToString(), "9085"}, + {GlobalSettingsKeys.DCSAutoConnectUDP.ToString(), "5069"}, + {GlobalSettingsKeys.AGC.ToString(), "true"}, {GlobalSettingsKeys.AGCTarget.ToString(), "30000"}, diff --git a/DCS-SimpleRadio Server/Network/ServerSync.cs b/DCS-SimpleRadio Server/Network/ServerSync.cs index e89d5cf9b..420ca8c61 100644 --- a/DCS-SimpleRadio Server/Network/ServerSync.cs +++ b/DCS-SimpleRadio Server/Network/ServerSync.cs @@ -5,6 +5,7 @@ using System.Net.Sockets; using System.Text; using System.Threading; +using System.Windows; using Caliburn.Micro; using Ciribob.DCS.SimpleRadio.Standalone.Common; using Ciribob.DCS.SimpleRadio.Standalone.Common.Network; @@ -72,7 +73,26 @@ protected override void OnError(SocketError error) public void StartListening() { OptionKeepAlive = true; - Start(); + try + { + Start(); + } + catch(Exception ex) + { + try + { + _natHandler?.CloseNAT(); + } + catch + { + } + + Logger.Error(ex,$"Unable to start the SRS Server"); + + MessageBox.Show($"Unable to start the SRS Server\n\nPort {_serverSettings.GetServerPort()} in use\n\nChange the port by editing the .cfg", "Port in use", + MessageBoxButton.OK, MessageBoxImage.Error); + Environment.Exit(0); + } } public void HandleDisconnect(SRSClientSession state) diff --git a/DCS-SimpleRadio Server/Network/UDPPositionHandler.cs b/DCS-SimpleRadio Server/Network/UDPPositionHandler.cs index 57cefb4b1..8919ea43e 100644 --- a/DCS-SimpleRadio Server/Network/UDPPositionHandler.cs +++ b/DCS-SimpleRadio Server/Network/UDPPositionHandler.cs @@ -58,14 +58,13 @@ public void Listen() } catch { } - _listener.ExclusiveAddressUse = true; _listener.DontFragment = true; _listener.Client.DontFragment = true; _listener.Client.Bind(new IPEndPoint(IPAddress.Any, port)); while (!_stop) try { - var groupEP = new IPEndPoint(IPAddress.Any, port); + var groupEP = new IPEndPoint(IPAddress.Any, 0); var rawBytes = _listener.Receive(ref groupEP); if (rawBytes?.Length == 22) diff --git a/Installer/MainWindow.xaml.cs b/Installer/MainWindow.xaml.cs index 00da9643d..39d02f85e 100644 --- a/Installer/MainWindow.xaml.cs +++ b/Installer/MainWindow.xaml.cs @@ -202,6 +202,25 @@ private void SetupLogging() private async void InstallReleaseButton(object sender, RoutedEventArgs e) { + var dcScriptsPath = dcsScriptsPath.Text; + if ((bool)!InstallScriptsCheckbox.IsChecked) + { + dcScriptsPath = null; + } + else + { + var paths = FindValidDCSFolders(dcScriptsPath); + + if (paths.Count == 0) + { + MessageBox.Show( + "Unable to find DCS Folder in Saved Games!\n\nPlease check the path to the \"Saved Games\" folder\n\nMake sure you are selecting the \"Saved Games\" folder - NOT the DCS folder inside \"Saved Games\" and NOT the DCS installation directory", + "SR Standalone Installer", + MessageBoxButton.OK, MessageBoxImage.Error); + } + return; + } + InstallButton.IsEnabled = false; RemoveButton.IsEnabled = false; @@ -212,15 +231,9 @@ private async void InstallReleaseButton(object sender, RoutedEventArgs e) _progressBarDialog.Show(); var srsPath = srPath.Text; - var dcScriptsPath = dcsScriptsPath.Text; + var shortcut = CreateStartMenuShortcut.IsChecked ?? true; - if ((bool) !InstallScriptsCheckbox.IsChecked) - { - dcScriptsPath = null; - } - - new Action(async () => { int result = await Task.Run(() => InstallRelease(srsPath,dcScriptsPath, shortcut)); @@ -653,6 +666,11 @@ private static List FindValidDCSFolders(string path) Logger.Info($"Finding DCS Saved Games Path"); var paths = new List(); + if(path == null || path.Length == 0) + { + return paths; + } + foreach (var directory in Directory.EnumerateDirectories(path)) { if (directory.ToUpper().Contains("DCS.") || directory.ToUpper().EndsWith("DCS")) @@ -981,6 +999,13 @@ private void CreateDirectory(string path) private async void Remove_Plugin(object sender, RoutedEventArgs e) { + + if (!Directory.Exists(dcsScriptsPath.Text)) + { + dcsScriptsPath.Text = ""; + Logger.Info($"SRS Scripts path not valid - ignoring uninstall of scripts: {dcsScriptsPath.Text}"); + } + _progressBarDialog = new ProgressBarDialog(); _progressBarDialog.Owner = this; _progressBarDialog.Show(); diff --git a/Scripts/DCS-SRS/Scripts/DCS-SimpleRadioStandalone.lua b/Scripts/DCS-SRS/Scripts/DCS-SimpleRadioStandalone.lua index 0fe5c3c39..da3bface5 100644 --- a/Scripts/DCS-SRS/Scripts/DCS-SimpleRadioStandalone.lua +++ b/Scripts/DCS-SRS/Scripts/DCS-SimpleRadioStandalone.lua @@ -2802,109 +2802,61 @@ local newJF17Interface = nil function SR.exportRadioJF17(_data) - if newJF17Interface == nil then - newJF17Interface = false - pcall(function() - - GetDevice(25):get_guard_plus_freq() - - newJF17Interface = true - end) - - end - - if newJF17Interface then - _data.capabilities = { dcsPtt = false, dcsIFF = true, dcsRadioSwitch = false, intercomHotMic = false, desc = "" } - - _data.radios[2].name = "COMM1 VHF Radio" - _data.radios[2].freq = SR.getRadioFrequency(25) - _data.radios[2].modulation = SR.getRadioModulation(25) - _data.radios[2].volume = SR.getRadioVolume(0, 934, { 0.0, 1.0 }, false) - _data.radios[2].secFreq = GetDevice(25):get_guard_plus_freq() - - _data.radios[3].name = "COMM2 UHF Radio" - _data.radios[3].freq = SR.getRadioFrequency(26) - _data.radios[3].modulation = SR.getRadioModulation(26) - _data.radios[3].volume = SR.getRadioVolume(0, 938, { 0.0, 1.0 }, false) - _data.radios[3].secFreq = GetDevice(26):get_guard_plus_freq() - - -- Expansion Radio - Server Side Controlled - _data.radios[4].name = "VHF/UHF Expansion" - _data.radios[4].freq = 251.0 * 1000000 --225-399.975 MHZ - _data.radios[4].modulation = 0 - _data.radios[4].secFreq = 243.0 * 1000000 - _data.radios[4].volume = 1.0 - _data.radios[4].freqMin = 115 * 1000000 - _data.radios[4].freqMax = 399.975 * 1000000 - _data.radios[4].volMode = 1 - _data.radios[4].freqMode = 1 - _data.radios[4].expansion = true - _data.radios[4].encKey = 1 - _data.radios[4].encMode = 1 -- FC3 Gui Toggle + Gui Enc key setting + _data.capabilities = { dcsPtt = false, dcsIFF = true, dcsRadioSwitch = false, intercomHotMic = false, desc = "" } - _data.selected = 1 - _data.control = 0; -- partial radio, allows hotkeys + _data.radios[2].name = "COMM1 VHF Radio" + _data.radios[2].freq = SR.getRadioFrequency(25) + _data.radios[2].modulation = SR.getRadioModulation(25) + _data.radios[2].volume = SR.getRadioVolume(0, 934, { 0.0, 1.0 }, false) + _data.radios[2].secFreq = GetDevice(25):get_guard_plus_freq() - -- SR.log(SR.tableShow(_G).."\n\n") + _data.radios[3].name = "COMM2 UHF Radio" + _data.radios[3].freq = SR.getRadioFrequency(26) + _data.radios[3].modulation = SR.getRadioModulation(26) + _data.radios[3].volume = SR.getRadioVolume(0, 938, { 0.0, 1.0 }, false) + _data.radios[3].secFreq = GetDevice(26):get_guard_plus_freq() - _data.iff = {status=0,mode1=0,mode3=0,mode4=false,control=0,expansion=false} + -- Expansion Radio - Server Side Controlled + _data.radios[4].name = "VHF/UHF Expansion" + _data.radios[4].freq = 251.0 * 1000000 --225-399.975 MHZ + _data.radios[4].modulation = 0 + _data.radios[4].secFreq = 243.0 * 1000000 + _data.radios[4].volume = 1.0 + _data.radios[4].freqMin = 115 * 1000000 + _data.radios[4].freqMax = 399.975 * 1000000 + _data.radios[4].volMode = 1 + _data.radios[4].freqMode = 1 + _data.radios[4].expansion = true + _data.radios[4].encKey = 1 + _data.radios[4].encMode = 1 -- FC3 Gui Toggle + Gui Enc key setting - local _iff = GetDevice(15) + _data.selected = 1 + _data.control = 0; -- partial radio, allows hotkeys - if _iff:is_m1_trs_on() or _iff:is_m2_trs_on() or _iff:is_m3_trs_on() or _iff:is_m6_trs_on() then - _data.iff.status = 1 - end + -- SR.log(SR.tableShow(_G).."\n\n") - if _iff:is_m1_trs_on() then - _data.iff.mode1 = _iff:get_m1_trs_code() - else - _data.iff.mode1 = -1 - end + _data.iff = {status=0,mode1=0,mode3=0,mode4=false,control=0,expansion=false} - if _iff:is_m3_trs_on() then - _data.iff.mode3 = _iff:get_m3_trs_code() - else - _data.iff.mode3 = -1 - end + local _iff = GetDevice(15) - _data.iff.mode4 = _iff:is_m6_trs_on() + if _iff:is_m1_trs_on() or _iff:is_m2_trs_on() or _iff:is_m3_trs_on() or _iff:is_m6_trs_on() then + _data.iff.status = 1 + end + if _iff:is_m1_trs_on() then + _data.iff.mode1 = _iff:get_m1_trs_code() else + _data.iff.mode1 = -1 + end - _data.capabilities = { dcsPtt = false, dcsIFF = false, dcsRadioSwitch = false, intercomHotMic = false, desc = "" } - - _data.radios[2].name = "COMM1 VHF Radio" - _data.radios[2].freq = SR.getRadioFrequency(25) - _data.radios[2].modulation = SR.getRadioModulation(25) - _data.radios[2].volume = SR.getRadioVolume(0, 934, { 0.0, 1.0 }, false) - _data.radios[2].guardFreqMode = 1 - _data.radios[2].secFreq = 121.5 * 1000000 - - _data.radios[3].name = "COMM2 UHF Radio" - _data.radios[3].freq = SR.getRadioFrequency(26) - _data.radios[3].modulation = SR.getRadioModulation(26) - _data.radios[3].volume = SR.getRadioVolume(0, 938, { 0.0, 1.0 }, false) - _data.radios[3].guardFreqMode = 1 - _data.radios[3].secFreq = 243.0 * 1000000 - - -- Expansion Radio - Server Side Controlled - _data.radios[4].name = "VHF/UHF Expansion" - _data.radios[4].freq = 251.0 * 1000000 --225-399.975 MHZ - _data.radios[4].modulation = 0 - _data.radios[4].secFreq = 243.0 * 1000000 - _data.radios[4].volume = 1.0 - _data.radios[4].freqMin = 115 * 1000000 - _data.radios[4].freqMax = 399.975 * 1000000 - _data.radios[4].volMode = 1 - _data.radios[4].freqMode = 1 - _data.radios[4].expansion = true - _data.radios[4].encKey = 1 - _data.radios[4].encMode = 1 -- FC3 Gui Toggle + Gui Enc key setting - - _data.selected = 1 - _data.control = 0; -- partial radio, allows hotkeys + if _iff:is_m3_trs_on() then + _data.iff.mode3 = _iff:get_m3_trs_code() + else + _data.iff.mode3 = -1 end + _data.iff.mode4 = _iff:is_m6_trs_on() + return _data end From 15a21e00d322d4283e5602b1b525de894e3ccecf Mon Sep 17 00:00:00 2001 From: Ciaran Fisher Date: Thu, 21 May 2020 20:28:19 +0100 Subject: [PATCH 4/5] Version Bump --- AutoUpdater/Properties/AssemblyInfo.cs | 4 ++-- DCS-SR-Client/Properties/AssemblyInfo.cs | 4 ++-- DCS-SR-Common/Network/UpdaterChecker.cs | 2 +- DCS-SimpleRadio Server/Properties/AssemblyInfo.cs | 4 ++-- Installer/Properties/AssemblyInfo.cs | 4 ++-- Scripts/DCS-SRS-AutoConnectGameGUI.lua | 4 ++-- Scripts/DCS-SRS/Scripts/DCS-SRS-OverlayGameGUI.lua | 6 +++--- Scripts/DCS-SRS/Scripts/DCS-SRSGameGUI.lua | 6 +++--- Scripts/DCS-SRS/Scripts/DCS-SimpleRadioStandalone.lua | 4 ++-- Scripts/DCS-SRS/entry.lua | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/AutoUpdater/Properties/AssemblyInfo.cs b/AutoUpdater/Properties/AssemblyInfo.cs index 3cc874fbb..65165fcf8 100644 --- a/AutoUpdater/Properties/AssemblyInfo.cs +++ b/AutoUpdater/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.8.0.3")] -[assembly: AssemblyFileVersion("1.8.0.3")] +[assembly: AssemblyVersion("1.8.0.4")] +[assembly: AssemblyFileVersion("1.8.0.4")] diff --git a/DCS-SR-Client/Properties/AssemblyInfo.cs b/DCS-SR-Client/Properties/AssemblyInfo.cs index 951ae9dba..968656ee7 100644 --- a/DCS-SR-Client/Properties/AssemblyInfo.cs +++ b/DCS-SR-Client/Properties/AssemblyInfo.cs @@ -52,5 +52,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.8.0.3")] -[assembly: AssemblyFileVersion("1.8.0.3")] \ No newline at end of file +[assembly: AssemblyVersion("1.8.0.4")] +[assembly: AssemblyFileVersion("1.8.0.4")] \ No newline at end of file diff --git a/DCS-SR-Common/Network/UpdaterChecker.cs b/DCS-SR-Common/Network/UpdaterChecker.cs index b2dbd37a2..b186208d4 100644 --- a/DCS-SR-Common/Network/UpdaterChecker.cs +++ b/DCS-SR-Common/Network/UpdaterChecker.cs @@ -21,7 +21,7 @@ public class UpdaterChecker public static readonly string MINIMUM_PROTOCOL_VERSION = "1.8.0.0"; - public static readonly string VERSION = "1.8.0.3"; + public static readonly string VERSION = "1.8.0.4"; private static readonly Logger _logger = LogManager.GetCurrentClassLogger(); diff --git a/DCS-SimpleRadio Server/Properties/AssemblyInfo.cs b/DCS-SimpleRadio Server/Properties/AssemblyInfo.cs index 06325615d..b22aff889 100644 --- a/DCS-SimpleRadio Server/Properties/AssemblyInfo.cs +++ b/DCS-SimpleRadio Server/Properties/AssemblyInfo.cs @@ -52,5 +52,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.8.0.3")] -[assembly: AssemblyFileVersion("1.8.0.3")] \ No newline at end of file +[assembly: AssemblyVersion("1.8.0.4")] +[assembly: AssemblyFileVersion("1.8.0.4")] \ No newline at end of file diff --git a/Installer/Properties/AssemblyInfo.cs b/Installer/Properties/AssemblyInfo.cs index 8e8e3d529..eeeb7feef 100644 --- a/Installer/Properties/AssemblyInfo.cs +++ b/Installer/Properties/AssemblyInfo.cs @@ -52,5 +52,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.8.0.3")] -[assembly: AssemblyFileVersion("1.8.0.3")] \ No newline at end of file +[assembly: AssemblyVersion("1.8.0.4")] +[assembly: AssemblyFileVersion("1.8.0.4")] \ No newline at end of file diff --git a/Scripts/DCS-SRS-AutoConnectGameGUI.lua b/Scripts/DCS-SRS-AutoConnectGameGUI.lua index 87ca00196..e773514d4 100644 --- a/Scripts/DCS-SRS-AutoConnectGameGUI.lua +++ b/Scripts/DCS-SRS-AutoConnectGameGUI.lua @@ -1,4 +1,4 @@ --- Version 1.8.0.3 +-- Version 1.8.0.4 -- ONLY COPY THIS WHOLE FILE IS YOU ARE GOING TO HOST A SERVER! -- The file must be in Saved Games\DCS\Scripts\Hooks or Saved Games\DCS.openalpha\Scripts\Hooks -- Make sure you enter the correct address into SERVER_SRS_HOST and SERVER_SRS_PORT (5002 by default) below. @@ -225,4 +225,4 @@ SRSAuto.sendMessage = function(msg, showTime, gid) end DCS.setUserCallbacks(SRSAuto) -net.log("Loaded - DCS-SRS-AutoConnect 1.8.0.3") \ No newline at end of file +net.log("Loaded - DCS-SRS-AutoConnect 1.8.0.4") \ No newline at end of file diff --git a/Scripts/DCS-SRS/Scripts/DCS-SRS-OverlayGameGUI.lua b/Scripts/DCS-SRS/Scripts/DCS-SRS-OverlayGameGUI.lua index 55f376a39..2e5b461b0 100644 --- a/Scripts/DCS-SRS/Scripts/DCS-SRS-OverlayGameGUI.lua +++ b/Scripts/DCS-SRS/Scripts/DCS-SRS-OverlayGameGUI.lua @@ -1,9 +1,9 @@ --- Version 1.8.0.3 +-- Version 1.8.0.4 -- Make sure you COPY this file to the same location as the Export.lua as well! -- Otherwise the Overlay will not work -net.log("Loading - DCS-SRS Overlay GameGUI - Ciribob: 1.8.0.3 ") +net.log("Loading - DCS-SRS Overlay GameGUI - Ciribob: 1.8.0.4 ") local base = _G @@ -583,4 +583,4 @@ end DCS.setUserCallbacks(srsOverlay) -net.log("Loaded - DCS-SRS Overlay GameGUI - Ciribob: 1.8.0.3 ") \ No newline at end of file +net.log("Loaded - DCS-SRS Overlay GameGUI - Ciribob: 1.8.0.4 ") \ No newline at end of file diff --git a/Scripts/DCS-SRS/Scripts/DCS-SRSGameGUI.lua b/Scripts/DCS-SRS/Scripts/DCS-SRSGameGUI.lua index ce2afdbb4..2e422efc2 100644 --- a/Scripts/DCS-SRS/Scripts/DCS-SRSGameGUI.lua +++ b/Scripts/DCS-SRS/Scripts/DCS-SRSGameGUI.lua @@ -1,8 +1,8 @@ --- Version 1.8.0.3 +-- Version 1.8.0.4 -- Make sure you COPY this file to the same location as the Export.lua as well! -- Otherwise the Radio Might not work -net.log("Loading - DCS-SRS GameGUI - Ciribob: 1.8.0.3") +net.log("Loading - DCS-SRS GameGUI - Ciribob: 1.8.0.4") local SRS = {} SRS.CLIENT_ACCEPT_AUTO_CONNECT = true --- Set to false if you want to disable AUTO CONNECT @@ -369,4 +369,4 @@ end DCS.setUserCallbacks(SRS) -net.log("Loaded - DCS-SRS GameGUI - Ciribob: 1.8.0.3") \ No newline at end of file +net.log("Loaded - DCS-SRS GameGUI - Ciribob: 1.8.0.4") \ No newline at end of file diff --git a/Scripts/DCS-SRS/Scripts/DCS-SimpleRadioStandalone.lua b/Scripts/DCS-SRS/Scripts/DCS-SimpleRadioStandalone.lua index da3bface5..98522b5e8 100644 --- a/Scripts/DCS-SRS/Scripts/DCS-SimpleRadioStandalone.lua +++ b/Scripts/DCS-SRS/Scripts/DCS-SimpleRadioStandalone.lua @@ -1,4 +1,4 @@ --- Version 1.8.0.3 +-- Version 1.8.0.4 -- Special thanks to Cap. Zeen, Tarres and Splash for all the help -- with getting the radio information :) -- Add (without the --) To the END OF your Export.lua to enable Simple Radio Standalone : @@ -3434,4 +3434,4 @@ function SR.tableShow(tbl, loc, indent, tableshow_tbls) --based on serialize_slm end end -SR.log("Loaded SimpleRadio Standalone Export version: 1.8.0.3") \ No newline at end of file +SR.log("Loaded SimpleRadio Standalone Export version: 1.8.0.4") \ No newline at end of file diff --git a/Scripts/DCS-SRS/entry.lua b/Scripts/DCS-SRS/entry.lua index 815884715..33d1f59f2 100644 --- a/Scripts/DCS-SRS/entry.lua +++ b/Scripts/DCS-SRS/entry.lua @@ -4,7 +4,7 @@ declare_plugin("DCS-SRS", { developerName = _("Ciribob"), developerLink = _("https://github.com/ciribob/DCS-SimpleRadioStandalone"), displayName = _("DCS SimpleRadio Standalone"), - version = "1.8.0.3", + version = "1.8.0.4", state = "installed", info = _("DCS-SimpleRadio Standalone\n\nBrings realistic VoIP comms to DCS with a cockpit integration with every aircraft\n\nCheck Special Settings for SRS integration settings\n\nSRS Discord for Support: https://discord.gg/baw7g3t"), binaries = {"srs.dll"}, From 80b47c9eee7632894658cf7153e6df7610b359c5 Mon Sep 17 00:00:00 2001 From: Ciaran Fisher Date: Thu, 21 May 2020 21:02:16 +0100 Subject: [PATCH 5/5] Install fix --- Installer/MainWindow.xaml.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Installer/MainWindow.xaml.cs b/Installer/MainWindow.xaml.cs index 39d02f85e..9c5c3fe79 100644 --- a/Installer/MainWindow.xaml.cs +++ b/Installer/MainWindow.xaml.cs @@ -217,8 +217,9 @@ private async void InstallReleaseButton(object sender, RoutedEventArgs e) "Unable to find DCS Folder in Saved Games!\n\nPlease check the path to the \"Saved Games\" folder\n\nMake sure you are selecting the \"Saved Games\" folder - NOT the DCS folder inside \"Saved Games\" and NOT the DCS installation directory", "SR Standalone Installer", MessageBoxButton.OK, MessageBoxImage.Error); + return; } - return; + } InstallButton.IsEnabled = false;