Skip to content

Commit

Permalink
Merge pull request #458 from ciribob/beta
Browse files Browse the repository at this point in the history
Release 1.8.0.4
  • Loading branch information
ciribob authored May 21, 2020
2 parents 541401b + 80b47c9 commit d72f260
Show file tree
Hide file tree
Showing 24 changed files with 579 additions and 516 deletions.
4 changes: 2 additions & 2 deletions AutoUpdater/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
78 changes: 44 additions & 34 deletions DCS-SR-Client/Network/DCS/DCSAutoConnectHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 ");
}
});
}

Expand Down Expand Up @@ -124,7 +134,7 @@ public void Stop()

try
{
_dcsUdpListener.Close();
_dcsUdpListener?.Close();
}
catch (Exception ex)
{
Expand Down
117 changes: 62 additions & 55 deletions DCS-SR-Client/Network/DCS/DCSGameGuiHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<DCSPlayerSideInfo>(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<DCSPlayerSideInfo>(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 ");
}
});
}

Expand Down
93 changes: 51 additions & 42 deletions DCS-SR-Client/Network/DCS/DCSLineOfSightHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DCSLosCheckResult[]>(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<DCSLosCheckResult[]>(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 ");
}
});
}

Expand Down
Loading

0 comments on commit d72f260

Please sign in to comment.