Skip to content

Commit

Permalink
Added connected client counts to full version of ingame overlay
Browse files Browse the repository at this point in the history
Improved ingame client count detection #254
Fixed incorrect radio/state sync for External AWACS Mode #131
  • Loading branch information
MorpheusXAUT committed Jun 16, 2018
1 parent 263e1f4 commit 1bd2248
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 5 deletions.
4 changes: 4 additions & 0 deletions DCS-SR-Client/Network/Models/CombinedRadioState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ public struct CombinedRadioState
public RadioSendingState RadioSendingState;

public RadioReceivingState[] RadioReceivingState;

public int ClientCountConnected;

public int ClientCountIngame;
}
}
19 changes: 18 additions & 1 deletion DCS-SR-Client/Network/RadioDCSSyncServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public void Listen()

public void StartExternalAWACSModeLoop()
{
_stopExternalAWACSMode = false;

RadioInformation[] awacsRadios;
try
{
Expand Down Expand Up @@ -105,6 +107,9 @@ public void StartExternalAWACSModeLoop()
}
}

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

Task.Factory.StartNew(() =>
{
Logger.Debug("Starting external AWACS mode loop");
Expand Down Expand Up @@ -311,14 +316,26 @@ private void SendRadioUpdateToDCS()
_dcsRadioUpdateSender.ExclusiveAddressUse = false;
}

int clientCountIngame = 0;

foreach (KeyValuePair<string, SRClient> kvp in _clients)
{
if (kvp.Value.IsIngame())
{
clientCountIngame++;
}
}

try
{
//get currently transmitting or receiving
var combinedState = new CombinedRadioState()
{
RadioInfo = _clientStateSingleton.DcsPlayerRadioInfo,
RadioSendingState = TCPVoiceHandler.RadioSendingState,
RadioReceivingState = TCPVoiceHandler.RadioReceivingState
RadioReceivingState = TCPVoiceHandler.RadioReceivingState,
ClientCountConnected = _clients.Count,
ClientCountIngame = clientCountIngame
};

var message = JsonConvert.SerializeObject(combinedState, new JsonSerializerSettings
Expand Down
11 changes: 10 additions & 1 deletion DCS-SR-Client/UI/ClientWindow/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ private void UpdateClientCount_VUMeters(object sender, EventArgs e)

foreach (KeyValuePair<string, SRClient> kvp in _clients)
{
if (!string.IsNullOrEmpty(kvp.Value.Name))
if (kvp.Value.IsIngame())
{
clientCountIngame++;
}
Expand Down Expand Up @@ -700,6 +700,9 @@ private void Stop()
_client.Disconnect();
_client = null;
}

_clientStateSingleton.DcsPlayerRadioInfo.Reset();
_clientStateSingleton.DcsPlayerSideInfo.Reset();
}

private void SaveSelectedInputAndOutput()
Expand Down Expand Up @@ -1208,6 +1211,8 @@ private void ExternalAWACSModeConnectionChanged(bool result, int coalition)
_clientStateSingleton.InExternalAWACSMode = true;
_clientStateSingleton.DcsPlayerSideInfo.side = coalition;
_clientStateSingleton.DcsPlayerSideInfo.name = _clientStateSingleton.LastSeenName;
_clientStateSingleton.DcsPlayerRadioInfo.name = _clientStateSingleton.LastSeenName;

ConnectExternalAWACSMode.Content = "Disconnect External AWACS MODE (EAM)";
ExternalAWACSModePassword.IsEnabled = false;
ExternalAWACSModeName.IsEnabled = false;
Expand All @@ -1217,6 +1222,10 @@ private void ExternalAWACSModeConnectionChanged(bool result, int coalition)
_clientStateSingleton.InExternalAWACSMode = false;
_clientStateSingleton.DcsPlayerSideInfo.side = 0;
_clientStateSingleton.DcsPlayerSideInfo.name = "";
_clientStateSingleton.DcsPlayerRadioInfo.name = "";
_clientStateSingleton.DcsPlayerRadioInfo.LastUpdate = 0;
_clientStateSingleton.LastSent = 0;

ConnectExternalAWACSMode.Content = "Connect External AWACS MODE (EAM)";
ExternalAWACSModePassword.IsEnabled = _serverSettings.GetSettingAsBool(Common.Setting.ServerSettingsKeys.EXTERNAL_AWACS_MODE);
ExternalAWACSModeName.IsEnabled = _serverSettings.GetSettingAsBool(Common.Setting.ServerSettingsKeys.EXTERNAL_AWACS_MODE);
Expand Down
11 changes: 11 additions & 0 deletions DCS-SR-Common/DCSState/DCSPlayerRadioInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ public DCSPlayerRadioInfo()
[JsonIgnore]
public long LastUpdate { get; set; }

public void Reset()
{
name = "";
pos = new DcsPosition();
ptt = false;
selected = 0;
unit = "";
simultaneousTransmission = false;
LastUpdate = 0;
}

// override object.Equals
public override bool Equals(object compare)
{
Expand Down
7 changes: 7 additions & 0 deletions DCS-SR-Common/DCSState/DCSPlayerSideInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@ public class DCSPlayerSideInfo
public string name = "";
public int side = 0;
public DcsPosition Position { get; set; } = new DcsPosition();

public void Reset()
{
name = "";
side = 0;
Position = new DcsPosition();
}
}
}
9 changes: 8 additions & 1 deletion DCS-SR-Common/Network/SRClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Net;
using System.Net.Sockets;
using Newtonsoft.Json;
Expand Down Expand Up @@ -77,6 +78,12 @@ public bool isCurrent()
// }
}

public bool IsIngame()
{
// Clients are counted as ingame if they have a name and have been updated within the last 10 seconds
return !string.IsNullOrEmpty(Name) && DateTime.Now.Ticks - LastUpdate < 100000000;
}

public override string ToString()
{
string side;
Expand Down
12 changes: 10 additions & 2 deletions Scripts/DCS-SRS-OverlayGameGUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ local _listStatics = {} -- placeholder objects
local _listMessages = {} -- data

local WIDTH = 350
local HEIGHT = 130
local HEIGHT = 140

local _lastReceived = 0

Expand Down Expand Up @@ -93,6 +93,14 @@ function srsOverlay.updateRadio()

if _radioState and _radioState.RadioInfo and _radioState.RadioInfo.radios then

if srsOverlay.getMode() == _modes.full and _radioState.ClientCountConnected and _radioState.ClientCountIngame then
local clientCountMsg = string.format("Connected clients: %i (%i ingame)", _radioState.ClientCountConnected, _radioState.ClientCountIngame)

local countMsg = {message = clientCountMsg, skin = typesMessage.normal, height = 20 }

table.insert(_listMessages, countMsg)
end

local _radioInfo =_radioState.RadioInfo

for _i,_radio in pairs(_radioInfo.radios) do
Expand Down Expand Up @@ -253,7 +261,7 @@ function srsOverlay.createWindow()

_listStatics = {}

for i = 1, 4 do
for i = 1, 5 do
local staticNew = Static.new()
table.insert(_listStatics, staticNew)
box:insertWidget(staticNew)
Expand Down

0 comments on commit 1bd2248

Please sign in to comment.