diff --git a/Plugin/Plugin.cpp b/Plugin/Plugin.cpp index f3d07fb..b661302 100644 --- a/Plugin/Plugin.cpp +++ b/Plugin/Plugin.cpp @@ -36,7 +36,7 @@ static SimpleRadio::Plugin plugin; namespace SimpleRadio { const char* Plugin::NAME = "DCS-SimpleRadio"; - const char* Plugin::VERSION = "1.1.6"; + const char* Plugin::VERSION = "1.1.7"; const char* Plugin::AUTHOR = "Ciribob - GitHub.com/ciribob"; const char* Plugin::DESCRIPTION = "DCS-SimpleRadio "; const char* Plugin::COMMAND_KEYWORD = "sr"; @@ -62,6 +62,8 @@ namespace SimpleRadio //Delete other things?! delete[] this->pluginId; } + + } void Plugin::start() @@ -299,35 +301,44 @@ namespace SimpleRadio return data; } + void Plugin::toggleMuteOnNonUsers() + { + this->allowNonPlayers = !this->allowNonPlayers; + + if (this->allowNonPlayers) + { + this->teamspeak.printMessageToCurrentTab("Un-muting clients NOT in an aircraft"); + } + else + { + this->teamspeak.printMessageToCurrentTab("Muting clients NOT in an aircraft"); + } + } + + void Plugin::toggleForceON() { + this->forceOn = !this->forceOn; + + if (this->forceOn) + { + this->teamspeak.printMessageToCurrentTab("Forcing ON in Ground Mode"); + } + else + { + this->teamspeak.printMessageToCurrentTab("Forcing OFF in Ground Mode"); + } + } + void Plugin::onHotKeyEvent(const char * hotkeyCommand) { if (strcmp("DCS-SR-TOGGLE-MUTE", hotkeyCommand) == 0) { - this->allowNonPlayers = !this->allowNonPlayers; - - if (this->allowNonPlayers) - { - this->teamspeak.printMessageToCurrentTab("Un-muting clients NOT in an aircraft"); - } - else - { - this->teamspeak.printMessageToCurrentTab("Muting clients NOT in an aircraft"); - } + this->toggleMuteOnNonUsers(); return; } else if (strcmp("DCS-SR-TOGGLE-FORCE-ON", hotkeyCommand) == 0) { - this->forceOn = !this->forceOn; - - if (this->forceOn) - { - this->teamspeak.printMessageToCurrentTab("Forcing ON in Ground Mode"); - } - else - { - this->teamspeak.printMessageToCurrentTab("Forcing OFF in Ground Mode"); - } + this->toggleForceON(); return; } @@ -476,6 +487,7 @@ namespace SimpleRadio update.selected = this->myClientData.selected; update.hasRadio = this->myClientData.hasRadio; update.allowNonPlayers = this->allowNonPlayers; + update.caMode = this->forceOn; for (int i = 0; i < 3; i++) { @@ -505,7 +517,7 @@ namespace SimpleRadio int len = sizeof(SOCKADDR_IN); //JSON Encode - sprintf(sbuf, "%s\r\n", update.serialize(false).c_str()); + sprintf(sbuf, "%s\r\n", update.serialize().c_str()); //teamspeak.printMessageToCurrentTab(update.serialize(false).c_str()); @@ -554,7 +566,7 @@ namespace SimpleRadio void Plugin::onClientUpdated(uint64 serverConnectionHandlerId, anyID clientId, anyID invokerId) { - + //Called every time and update happens on a client char* bufferForMetaData; DWORD error; @@ -563,7 +575,7 @@ namespace SimpleRadio anyID myID; if (this->teamspeak.getClientID(serverConnectionHandlerId, &myID) != ERROR_ok) { - + return; } else { @@ -586,7 +598,6 @@ namespace SimpleRadio catch (...) { this->teamspeak.logMessage("Failed to parse my metadata", LogLevel_ERROR, Plugin::NAME, 0); - } } @@ -594,38 +605,29 @@ namespace SimpleRadio return; } - } - - //Called every time and update happens on a client - - - if ((error = this->teamspeak.getClientVariableAsString(serverConnectionHandlerId, clientId, CLIENT_META_DATA, &bufferForMetaData)) != ERROR_ok) { - - } - else - { - - try { - - ClientMetaData metadata = ClientMetaData::deserialize(bufferForMetaData, false); + else + { + if ((error = this->teamspeak.getClientVariableAsString(serverConnectionHandlerId, clientId, CLIENT_META_DATA, &bufferForMetaData)) != ERROR_ok) { + return; + } + else + { + try { - auto ret = this->connectedClient.insert(std::pair(clientId, metadata)); + ClientMetaData metadata = ClientMetaData::deserialize(bufferForMetaData, false); - if (!ret.second) - { - this->connectedClient[clientId] = metadata; + this->connectedClient[clientId] = metadata; + } + catch (...) + { + this->teamspeak.logMessage("Failed to parse client metadata", LogLevel_ERROR, Plugin::NAME, 0); + } + this->teamspeak.freeMemory(bufferForMetaData); + return; } } - catch (...) - { - this->teamspeak.logMessage("Failed to parse client metadata", LogLevel_ERROR, Plugin::NAME, 0); - - } } - - - this->teamspeak.freeMemory(bufferForMetaData); } void Plugin::onEditPlaybackVoiceDataEvent(uint64 serverConnectionHandlerId, anyID clientId, short* samples, int sampleCount, int channels) @@ -1167,17 +1169,20 @@ namespace SimpleRadio { ReceiveBuf[ByteReceived - 1] = 0; //add terminator + RadioUpdateCommand updateCommand = RadioUpdateCommand::deserialize(ReceiveBuf); + //only allow on FC3 aircraft - if (this->myClientData.hasRadio == false) + if (this->myClientData.hasRadio == false || updateCommand.cmdType >=4) { - RadioUpdateCommand updateCommand = RadioUpdateCommand::deserialize(ReceiveBuf); if (updateCommand.radio >= 0) { /* - FREQUENCY=1, + FREQUENCY=1, VOLUME=2, SELECT=3, + TOGGLE_MUTE_NON_RADIO = 4, + TOGGLE_FORCE_RADIO_ON = 5 */ switch (updateCommand.cmdType) { case 1: @@ -1189,6 +1194,15 @@ namespace SimpleRadio case 3: this->teamSpeakControlledClientData.selected = updateCommand.radio; break; + case 4: + this->toggleMuteOnNonUsers(); + this->sendUpdateToGUI(); + break; + case 5: + this->toggleForceON(); + this->sendUpdateToGUI(); + break; + default: break; @@ -1271,6 +1285,7 @@ void ts3plugin_setFunctionPointers(const struct TS3Functions funcs) */ int ts3plugin_init() { + //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); try { diff --git a/Plugin/Plugin.h b/Plugin/Plugin.h index 2f39125..9cbe264 100644 --- a/Plugin/Plugin.h +++ b/Plugin/Plugin.h @@ -7,6 +7,10 @@ #define DLL_EXPORT __declspec(dllimport) #endif +//#define _CRTDBG_MAP_ALLOC +//#include +//#include + #include #include #include @@ -47,6 +51,10 @@ namespace SimpleRadio std::string getClientInfoData(uint64 serverConnectionHandlerId, uint64 clientId) const; std::string getClientMetaData(uint64 serverConnectionHandlerId, uint64 clientId) const; + void toggleMuteOnNonUsers(); + + void toggleForceON(); + void onClientUpdated(uint64 serverConnectionHandlerId, anyID clientId, anyID invokerId); void onHotKeyEvent(const char * hotkeyCommand); diff --git a/Plugin/Plugin.rc b/Plugin/Plugin.rc index b2dba30..6306781 100644 Binary files a/Plugin/Plugin.rc and b/Plugin/Plugin.rc differ diff --git a/Plugin/Plugin.vcxproj b/Plugin/Plugin.vcxproj index b8b3026..4635726 100644 --- a/Plugin/Plugin.vcxproj +++ b/Plugin/Plugin.vcxproj @@ -205,7 +205,7 @@ true true WIN32;NDEBUG;_WINDOWS;_USRDLL;PLUGIN_EXPORTS;%(PreprocessorDefinitions) - $(SolutionDir)DSPFilters\include;%(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) MultiThreaded @@ -229,7 +229,8 @@ true true WIN32;NDEBUG;_WINDOWS;_USRDLL;PLUGIN_EXPORTS;%(PreprocessorDefinitions) - $(SolutionDir)DSPFilters\include;%(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) + MultiThreaded Windows @@ -259,6 +260,7 @@ + @@ -266,6 +268,7 @@ + diff --git a/Plugin/Plugin.vcxproj.filters b/Plugin/Plugin.vcxproj.filters index e51f318..a2fcc25 100644 --- a/Plugin/Plugin.vcxproj.filters +++ b/Plugin/Plugin.vcxproj.filters @@ -60,6 +60,9 @@ Header Files + + Header Files + @@ -77,6 +80,9 @@ Source Files + + Source Files + diff --git a/Plugin/RadioUpdate.cpp b/Plugin/RadioUpdate.cpp index 73f25d8..fcb62ca 100644 --- a/Plugin/RadioUpdate.cpp +++ b/Plugin/RadioUpdate.cpp @@ -13,6 +13,7 @@ namespace SimpleRadio , unit("None") , selected(0) , hasRadio(true) + , caMode(false) { for (int i = 0; i < 3; i++) { @@ -23,7 +24,7 @@ namespace SimpleRadio } } - string RadioUpdate::serialize(bool formatted) const + string RadioUpdate::serialize() const { Json::Value root; @@ -32,6 +33,7 @@ namespace SimpleRadio root["selected"] = this->selected; root["hasRadio"] = this->hasRadio; root["allowNonPlayers"] = this->allowNonPlayers; //if false, non players are muted + root["caMode"] = this->caMode; Json::Value array; for (int i = 0; i < 3; i++) @@ -45,17 +47,10 @@ namespace SimpleRadio } root["radios"] = array; - - if (formatted == true) - { - Json::StyledWriter writer; - return writer.write(root); - } - else - { - Json::FastWriter writer; - return writer.write(root); - } + + Json::FastWriter writer; + return writer.write(root); + } diff --git a/Plugin/RadioUpdate.h b/Plugin/RadioUpdate.h index ed28c8f..ef1317e 100644 --- a/Plugin/RadioUpdate.h +++ b/Plugin/RadioUpdate.h @@ -11,8 +11,8 @@ namespace SimpleRadio { public: RadioUpdate(); - std::string serialize(bool formatted = false) const; - + std::string serialize() const; + std::string name; std::string unit; int selected; @@ -20,6 +20,7 @@ namespace SimpleRadio RadioInformation radios[3]; bool hasRadio; bool allowNonPlayers; + bool caMode; }; }; diff --git a/Plugin/UDPDiscovery.cpp b/Plugin/UDPDiscovery.cpp new file mode 100644 index 0000000..b169864 --- /dev/null +++ b/Plugin/UDPDiscovery.cpp @@ -0,0 +1,12 @@ +#include "UDPDiscovery.h" + + + +UDPDiscovery::UDPDiscovery() +{ +} + + +UDPDiscovery::~UDPDiscovery() +{ +} diff --git a/Plugin/UDPDiscovery.h b/Plugin/UDPDiscovery.h new file mode 100644 index 0000000..2cec110 --- /dev/null +++ b/Plugin/UDPDiscovery.h @@ -0,0 +1,10 @@ +#pragma once +class UDPDiscovery +{ +public: + UDPDiscovery(); + ~UDPDiscovery(); + + +}; + diff --git a/RadioGui/MainWindow.xaml b/RadioGui/MainWindow.xaml index 569738b..65bc0f8 100644 --- a/RadioGui/MainWindow.xaml +++ b/RadioGui/MainWindow.xaml @@ -12,11 +12,12 @@ AllowsTransparency="True" Opacity="1.0" - Title="DCS-SimpleRadio" Height="325" Width="120"> + Title="DCS-SimpleRadio" Height="285" Width="100"> - + + + - + + diff --git a/RadioGui/MainWindow.xaml.cs b/RadioGui/MainWindow.xaml.cs index 8b1ed8e..5bfa64f 100644 --- a/RadioGui/MainWindow.xaml.cs +++ b/RadioGui/MainWindow.xaml.cs @@ -47,20 +47,20 @@ public MainWindow() //allows click and drag anywhere on the window this.containerPanel.MouseLeftButtonDown += WrapPanel_MouseLeftButtonDown; - + radio1.radioId = 0; radio2.radioId = 1; radio3.radioId = 2; - setupActiveRadio(); - setupRadioStatus(); + SetupActiveRadio(); + SetupRadioStatus(); } - private void setupRadioStatus() + private void SetupRadioStatus() { //setup UDP this.udpClient = new UdpClient(); @@ -124,24 +124,25 @@ private void setupRadioStatus() if (lastUpdate.allowNonPlayers) { - this.allowNonPlayersIndicator.Fill = new SolidColorBrush(Colors.Green); - this.allowNonPlayers.Content = "Mute OFF"; + this.muteStatusNonUsers.Fill = new SolidColorBrush(Colors.Red); + this.muteStatusNonUsers.ToolTip = "Mute Non Players OFF"; } else { - this.allowNonPlayersIndicator.Fill = new SolidColorBrush(Colors.Red); - this.allowNonPlayers.Content = "Mute ON"; + this.muteStatusNonUsers.Fill = new SolidColorBrush(Colors.Green); + this.muteStatusNonUsers.ToolTip = "Mute Non Players ON"; } - if (elapsedSpan.TotalSeconds > 5) + if (lastUpdate.caMode) { - this.statusIndicator.Fill = new SolidColorBrush(Colors.Red); - this.statusLabel.Content = "Radio Disabled"; + this.caModeStatus.Fill = new SolidColorBrush(Colors.Green); + this.caModeStatus.ToolTip = "Radio ON - CA / JTAC / Spectator Mode"; + } else { - this.statusIndicator.Fill = new SolidColorBrush(Colors.Green); - this.statusLabel.Content = "OK"; + this.caModeStatus.Fill = new SolidColorBrush(Colors.Red); + this.caModeStatus.ToolTip = "Radio OFF - CA / JTAC / Spectator Mode"; } @@ -156,7 +157,7 @@ private void setupRadioStatus() } - private void setupActiveRadio() + private void SetupActiveRadio() { //setup UDP this.activeRadioUdpClient = new UdpClient(); @@ -266,6 +267,48 @@ private void windowOpacitySlider_ValueChanged(object sender, RoutedPropertyChang { this.Opacity = e.NewValue; } + + private void SendUDPCommand(RadioCommand.CmdType type) + { + RadioCommand update = new RadioCommand(); + update.freq =1; + update.volume = 1; + update.radio = 0; + update.cmdType = type; + + byte[] bytes = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(update) + "\n"); + //multicast + Send("239.255.50.10", 5060, bytes); + //unicast + Send("127.0.0.1", 5061, bytes); + + + } + private void Send(String ipStr, int port, byte[] bytes) + { + try + { + + UdpClient client = new UdpClient(); + IPEndPoint ip = new IPEndPoint(IPAddress.Parse(ipStr), port); + + client.Send(bytes, bytes.Length, ip); + client.Close(); + } + catch (Exception e) { } + + } + + private void Button_ToggleMute(object sender, RoutedEventArgs e) + { + SendUDPCommand(RadioCommand.CmdType.TOGGLE_MUTE_NON_RADIO); + } + + + private void Button_Toggle_CA_Mode(object sender, RoutedEventArgs e) + { + SendUDPCommand(RadioCommand.CmdType.TOGGLE_FORCE_RADIO_ON); + } } } diff --git a/RadioGui/Properties/AssemblyInfo.cs b/RadioGui/Properties/AssemblyInfo.cs index 93c42f5..a6b8370 100644 --- a/RadioGui/Properties/AssemblyInfo.cs +++ b/RadioGui/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.1.6.0")] -[assembly: AssemblyFileVersion("1.1.6.0")] +[assembly: AssemblyVersion("1.1.7.0")] +[assembly: AssemblyFileVersion("1.1.7.0")] diff --git a/RadioGui/RadioCommand.cs b/RadioGui/RadioCommand.cs index 78f8757..995af47 100644 --- a/RadioGui/RadioCommand.cs +++ b/RadioGui/RadioCommand.cs @@ -13,6 +13,8 @@ public enum CmdType FREQUENCY=1, VOLUME=2, SELECT=3, + TOGGLE_MUTE_NON_RADIO = 4, + TOGGLE_FORCE_RADIO_ON = 5 } public double freq = 1; public int radio; diff --git a/RadioGui/RadioControlGroup.xaml b/RadioGui/RadioControlGroup.xaml index 6faa63c..a78e159 100644 --- a/RadioGui/RadioControlGroup.xaml +++ b/RadioGui/RadioControlGroup.xaml @@ -5,27 +5,27 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:RadioGui" - Width="120" Height="80" + Width="100" Height="70" > -