Skip to content
This repository has been archived by the owner on Jun 22, 2021. It is now read-only.

Commit

Permalink
Radio GUI
Browse files Browse the repository at this point in the history
Fully working Optional Radio GUI
Fixed crashing bug when clicking on someones name in TeamSpeak due to a
buffer overflow
Added ability to force the Radio on when in game using TeamSpeak HotKeys
for spectators or JTAC to use
Added HotKey for disabling the Plugin so you can hear everyone
  • Loading branch information
Ciaran Fisher committed Aug 27, 2015
1 parent 97496a4 commit d8b83d2
Show file tree
Hide file tree
Showing 24 changed files with 1,054 additions and 68 deletions.
36 changes: 27 additions & 9 deletions DCS-SimpleRadio.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,55 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{E67088
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RadioGui", "RadioGui\RadioGui.csproj", "{3FA37CBC-5BE2-4945-802D-9CDD464AC476}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Win32 = Release|Win32
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
Test|Win32 = Test|Win32
Test|Any CPU = Test|Any CPU
Test|x64 = Test|x64
Test|x86 = Test|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Debug|Win32.ActiveCfg = Debug|Win32
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Debug|Win32.Build.0 = Debug|Win32
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Debug|Any CPU.ActiveCfg = Debug|Win32
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Debug|x64.ActiveCfg = Debug|x64
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Debug|x64.Build.0 = Debug|x64
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Debug|x86.ActiveCfg = Debug|Win32
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Debug|x86.Build.0 = Debug|Win32
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Release|Win32.ActiveCfg = Release|Win32
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Release|Win32.Build.0 = Release|Win32
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Release|Any CPU.ActiveCfg = Release|Win32
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Release|x64.ActiveCfg = Release|x64
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Release|x64.Build.0 = Release|x64
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Release|x86.ActiveCfg = Release|Win32
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Release|x86.Build.0 = Release|Win32
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Test|Win32.ActiveCfg = Test|Win32
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Test|Win32.Build.0 = Test|Win32
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Test|Any CPU.ActiveCfg = Test|Win32
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Test|x64.ActiveCfg = Test|x64
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Test|x64.Build.0 = Test|x64
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Test|x86.ActiveCfg = Test|Win32
{A48593C7-7CC3-4C46-9705-9BD264A8E95A}.Test|x86.Build.0 = Test|Win32
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Debug|x64.ActiveCfg = Debug|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Debug|x64.Build.0 = Debug|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Debug|x86.ActiveCfg = Debug|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Debug|x86.Build.0 = Debug|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Release|Any CPU.Build.0 = Release|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Release|x64.ActiveCfg = Release|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Release|x64.Build.0 = Release|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Release|x86.ActiveCfg = Release|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Release|x86.Build.0 = Release|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Release|x86.Deploy.0 = Release|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Test|Any CPU.ActiveCfg = Release|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Test|Any CPU.Build.0 = Release|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Test|x64.ActiveCfg = Release|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Test|x64.Build.0 = Release|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Test|x86.ActiveCfg = Release|Any CPU
{3FA37CBC-5BE2-4945-802D-9CDD464AC476}.Test|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
19 changes: 19 additions & 0 deletions Plugin/ClientMetaData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace SimpleRadio
, selected(0)
, position()
, hasRadio(true)
, groundCommander(false)
{
for (int i = 0; i < 3; i++)
{
Expand Down Expand Up @@ -50,6 +51,10 @@ namespace SimpleRadio

root["pos"] = position;

root["hasRadio"] = this->hasRadio;

root["groundCommander"] = this->groundCommander;

if (formatted == true)
{
Json::StyledWriter writer;
Expand Down Expand Up @@ -88,6 +93,7 @@ namespace SimpleRadio
data.radio[i].modulation = root["radios"][i]["modulation"].asInt();
}


try {
data.hasRadio = root["hasRadio"].asBool();
}
Expand All @@ -96,6 +102,19 @@ namespace SimpleRadio
//catch older versions
data.hasRadio = true;
}


try {

data.groundCommander = root["groundCommander"].asBool();
}
catch (...)
{
//catch older versions
data.groundCommander = false;
}


}
else
{
Expand Down
4 changes: 3 additions & 1 deletion Plugin/ClientMetaData.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

#include <string>
#include "DCSPosition.h"
#include "RadioInformation.h"

namespace SimpleRadio
{
struct RadioInformation
struct RadioInformation
{
std::string name;
double frequency;
Expand All @@ -29,6 +30,7 @@ namespace SimpleRadio
DCSPosition position;
RadioInformation radio[3];
bool hasRadio;
bool groundCommander;
};
};

Expand Down
160 changes: 121 additions & 39 deletions Plugin/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "ts3_functions.h"
#include "Plugin.h"
#include "ClientMetaData.h"
#include "RadioUpdate.h"
#include "json/json.h"

#include <winsock2.h>
Expand All @@ -32,7 +33,7 @@ static SimpleRadio::Plugin plugin;
namespace SimpleRadio
{
const char* Plugin::NAME = "DCS-SimpleRadio";
const char* Plugin::VERSION = "1.0.3";
const char* Plugin::VERSION = "1.0.6";
const char* Plugin::AUTHOR = "Ciribob - GitHub.com/ciribob";
const char* Plugin::DESCRIPTION = "DCS-SimpleRadio ";
const char* Plugin::COMMAND_KEYWORD = "sr";
Expand All @@ -46,6 +47,8 @@ namespace SimpleRadio
, connectedClient()
, allowNonPlayers(true)
, switchToUnicast(false)
, forceOn(false)
, disablePlugin(false)
{
}

Expand Down Expand Up @@ -130,7 +133,7 @@ namespace SimpleRadio
//const int MHz = 1000000;
char buffer[BUFFER_SIZE] = { 0 };


try
{

Expand All @@ -154,8 +157,8 @@ namespace SimpleRadio

if (clientInfoData.lastUpdate > 5000ull)
{
RadioInformation currentRadio = clientInfoData.radio[myClientData.selected];
char status[128] = { 0 };
RadioInformation currentRadio = clientInfoData.radio[clientInfoData.selected];
char status[256] = { 0 };
const double MHZ = 1000000;

//catch divide by zero
Expand All @@ -164,24 +167,27 @@ namespace SimpleRadio
currentRadio.frequency = -1;
}

if (clientInfoData.lastUpdate > (GetTickCount64() - 5000ull))

if (myID == clientId)
{
sprintf_s(status, 128, "Status Good: %s, is flying %s \nSelected Radio %s\nFreq (MHz): %.4f %s", clientInfoData.name.c_str(), clientInfoData.unit.c_str(), currentRadio.name.c_str(), currentRadio.frequency / MHZ, currentRadio.modulation == 0 ? "AM" : "FM");
strcat_s(buffer, BUFFER_SIZE, status);
sprintf_s(status, 256, "Status %s: %s, is in %s \nSelected Radio %s\nFreq (MHz): %.4f %s\nCA Mode:%s\nPlugin:%s", clientInfoData.isCurrent() ? "Live" : "Unknown", clientInfoData.name.c_str(), clientInfoData.unit.c_str(), currentRadio.name.c_str(), currentRadio.frequency / MHZ, currentRadio.modulation == 0 ? "AM" : "FM", clientInfoData.groundCommander ? "ON" : "OFF", this->disablePlugin ? "DISABLED" : "Enabled");

}
else
{
sprintf_s(status, 128, "Status Unknown: %s, was flying %s - Currently Unknown\nSelected Radio %s\nFreq (MHz): %.4f %s", clientInfoData.name.c_str(), clientInfoData.unit.c_str(), currentRadio.name.c_str(), currentRadio.frequency / MHZ, currentRadio.modulation == 0 ? "AM" : "FM");
strcat_s(buffer, BUFFER_SIZE, status);
sprintf_s(status, 256, "Status %s: %s, is in %s \nSelected Radio %s\nFreq (MHz): %.4f %s\nCA Mode:%s",clientInfoData.isCurrent()?"Live":"Unknown", clientInfoData.name.c_str(), clientInfoData.unit.c_str(), currentRadio.name.c_str(), currentRadio.frequency / MHZ, currentRadio.modulation == 0 ? "AM" : "FM", clientInfoData.groundCommander ? "ON" : "OFF");

}
strcat_s(buffer, BUFFER_SIZE, status);


}
else
{
strcat_s(buffer, BUFFER_SIZE, "Status: Not In Game\n");
}
}
catch (std::out_of_range)
catch (...)
{
// Client not in map, return
strcat_s(buffer, BUFFER_SIZE, "Status: Not In Game or Not Running Plugin\n");
Expand All @@ -204,22 +210,6 @@ namespace SimpleRadio
}

void Plugin::onHotKeyEvent(const char * hotkeyCommand) {
/*
CREATE_HOTKEY("DCS-SR-TRANSMIT-UHF", "Select UHF AM");
CREATE_HOTKEY("DCS-SR-TRANSMIT-VHF", "Select VHF AM");
CREATE_HOTKEY("DCS-SR-TRANSMIT-FM", "Select FM");
CREATE_HOTKEY("DCS-SR-FREQ-10-UP", "Frequency Up - 10MHz");
CREATE_HOTKEY("DCS-SR-FREQ-10-DOWN", "Frequency Down - 10MHz");
CREATE_HOTKEY("DCS-SR-FREQ-1-UP", "Frequency Up - 1MHz");
CREATE_HOTKEY("DCS-SR-FREQ-1-DOWN", "Frequency Down - 1MHz");
CREATE_HOTKEY("DCS-SR-FREQ-01-UP", "Frequency Up - 0.1MHz");
CREATE_HOTKEY("DCS-SR-FREQ-01-DOWN", "Frequency Down - 0.1MHz");
*/
//RadioInformation selectedRadio = this->teamSpeakControlledClientData.radio[teamSpeakControlledClientData.selected];

if (strcmp("DCS-SR-TOGGLE-MUTE", hotkeyCommand) == 0)
{
Expand All @@ -236,6 +226,36 @@ namespace SimpleRadio
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");
}
return;

}
else if (strcmp("DCS-SR-TOGGLE-ENABLE", hotkeyCommand) == 0)
{
this->disablePlugin = !this->disablePlugin;

if (this->disablePlugin)
{
this->teamspeak.printMessageToCurrentTab("Disabling DCS-SimpleRadio");
}
else
{
this->teamspeak.printMessageToCurrentTab("Enabling DCS-SimpleRadio");
}
return;

}


RadioInformation &selectedRadio = this->teamSpeakControlledClientData.radio[teamSpeakControlledClientData.selected];
Expand Down Expand Up @@ -327,6 +347,58 @@ namespace SimpleRadio

}

void Plugin::sendUpdateToGUI()
{
RadioUpdate update;

update.name = this->myClientData.name;
update.unit = this->myClientData.unit;
update.selected = this->myClientData.selected;
update.hasRadio = this->myClientData.hasRadio;
update.allowNonPlayers = this->allowNonPlayers;

for (int i = 0; i < 3; i++)
{
update.radios[i] = this->myClientData.radio[i];
}

/*
SEND
*/
try
{
SOCKET s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (s == -1)
{
return;
}
SOCKADDR_IN serveraddr;
struct hostent *hostentry;


serveraddr.sin_family = AF_INET;
serveraddr.sin_port = htons(35024);

inet_pton(AF_INET, "239.255.50.10", &(serveraddr.sin_addr.s_addr));

char sbuf[1024];
int len = sizeof(SOCKADDR_IN);

//JSON Encode
sprintf(sbuf, "%s\r\n", update.serialize(false).c_str());

//teamspeak.printMessageToCurrentTab(update.serialize(false).c_str());

sendto(s, sbuf, strlen(sbuf), 0, (SOCKADDR*)&serveraddr, len);
::closesocket(s);

}
catch (...)
{

}
}

void Plugin::onClientUpdated(uint64 serverConnectionHandlerId, anyID clientId, anyID invokerId)
{

Expand Down Expand Up @@ -354,6 +426,9 @@ namespace SimpleRadio
ClientMetaData metadata = ClientMetaData::deserialize(bufferForMetaData, false);

this->myClientData = metadata;

sendUpdateToGUI();

}
catch (...)
{
Expand Down Expand Up @@ -696,22 +771,25 @@ namespace SimpleRadio
}
}

//TODO: modify as appropriate with locally set frequency or selected Radio
//if hasRadio == false then
//use the teamspeak settings
//if hasRadio == true, ignore TS

std::string serialised = clientMetaData.serialize();

//////Send Client METADATA
if (this->teamspeak.setClientSelfVariableAsString(serverHandlerID, CLIENT_META_DATA, serialised.c_str()) != ERROR_ok) {
//printf("Error setting CLIENT_META_DATA!!!\n");

}
else
//only send if plugin is not disabled and if we're in Ground Commander mode, if the user has enabled forced on
if (!this->disablePlugin
&& ((this->forceOn && clientMetaData.groundCommander)
|| clientMetaData.groundCommander == false ))
{
this->teamspeak.flushClientSelfUpdates(serverHandlerID, NULL);
//////Send Client METADATA
if (this->teamspeak.setClientSelfVariableAsString(serverHandlerID, CLIENT_META_DATA, serialised.c_str()) != ERROR_ok) {
//printf("Error setting CLIENT_META_DATA!!!\n");

}
else
{
this->teamspeak.flushClientSelfUpdates(serverHandlerID, NULL);
}
}


}
catch (...)
{
Expand Down Expand Up @@ -909,7 +987,7 @@ void ts3plugin_initHotkeys(struct PluginHotkey*** hotkeys) {
/* Register hotkeys giving a keyword and a description.
* The keyword will be later passed to ts3plugin_onHotkeyEvent to identify which hotkey was triggered.
* The description is shown in the clients hotkey dialog. */
BEGIN_CREATE_HOTKEYS(10); /* Create 3 hotkeys. Size must be correct for allocating memory. */
BEGIN_CREATE_HOTKEYS(12); /* Create 3 hotkeys. Size must be correct for allocating memory. */
CREATE_HOTKEY("DCS-SR-TRANSMIT-UHF", "Select UHF AM");
CREATE_HOTKEY("DCS-SR-TRANSMIT-VHF", "Select VHF AM");
CREATE_HOTKEY("DCS-SR-TRANSMIT-FM", "Select FM");
Expand All @@ -925,6 +1003,10 @@ void ts3plugin_initHotkeys(struct PluginHotkey*** hotkeys) {

CREATE_HOTKEY("DCS-SR-TOGGLE-MUTE", "Toggle Mute on Outsiders");

CREATE_HOTKEY("DCS-SR-TOGGLE-FORCE-ON", "Toggles Radio ON/OFF for Spectating or CA");

CREATE_HOTKEY("DCS-SR-TOGGLE-ENABLE", "Toggles Plugin On/Off");

END_CREATE_HOTKEYS;

/* The client will call ts3plugin_freeMemory to release all allocated memory */
Expand Down
Loading

0 comments on commit d8b83d2

Please sign in to comment.