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

Commit

Permalink
Merge pull request #2 from ciribob/newUi
Browse files Browse the repository at this point in the history
New Minimised Window
  • Loading branch information
ciribob committed Oct 11, 2015
2 parents 3c03e7f + 73804f1 commit eb11dee
Show file tree
Hide file tree
Showing 17 changed files with 271 additions and 157 deletions.
123 changes: 69 additions & 54 deletions Plugin/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -62,6 +62,8 @@ namespace SimpleRadio
//Delete other things?!
delete[] this->pluginId;
}


}

void Plugin::start()
Expand Down Expand Up @@ -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;

}
Expand Down Expand Up @@ -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++)
{
Expand Down Expand Up @@ -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());

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

Expand All @@ -563,7 +575,7 @@ namespace SimpleRadio

anyID myID;
if (this->teamspeak.getClientID(serverConnectionHandlerId, &myID) != ERROR_ok) {

return;
}
else
{
Expand All @@ -586,46 +598,36 @@ namespace SimpleRadio
catch (...)
{
this->teamspeak.logMessage("Failed to parse my metadata", LogLevel_ERROR, Plugin::NAME, 0);

}
}

this->teamspeak.freeMemory(bufferForMetaData);

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<anyID, ClientMetaData>(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)
Expand Down Expand Up @@ -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:
Expand All @@ -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;

Expand Down Expand Up @@ -1271,6 +1285,7 @@ void ts3plugin_setFunctionPointers(const struct TS3Functions funcs)
*/
int ts3plugin_init()
{
//_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
try
{

Expand Down
8 changes: 8 additions & 0 deletions Plugin/Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#define DLL_EXPORT __declspec(dllimport)
#endif

//#define _CRTDBG_MAP_ALLOC
//#include <stdlib.h>
//#include <crtdbg.h>

#include <WinSock2.h>
#include <string>
#include <map>
Expand Down Expand Up @@ -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);

Expand Down
Binary file modified Plugin/Plugin.rc
Binary file not shown.
7 changes: 5 additions & 2 deletions Plugin/Plugin.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;PLUGIN_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)DSPFilters\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
Expand All @@ -229,7 +229,8 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;PLUGIN_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)DSPFilters\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down Expand Up @@ -259,13 +260,15 @@
<ClInclude Include="RadioUpdateCommand.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="ts3_functions.h" />
<ClInclude Include="UDPDiscovery.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="ClientMetaData.cpp" />
<ClCompile Include="jsoncpp.cpp" />
<ClCompile Include="Plugin.cpp" />
<ClCompile Include="RadioUpdate.cpp" />
<ClCompile Include="RadioUpdateCommand.cpp" />
<ClCompile Include="UDPDiscovery.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Plugin.rc" />
Expand Down
6 changes: 6 additions & 0 deletions Plugin/Plugin.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
<ClInclude Include="RadioUpdateCommand.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="UDPDiscovery.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Plugin.cpp">
Expand All @@ -77,6 +80,9 @@
<ClCompile Include="RadioUpdateCommand.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="UDPDiscovery.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Plugin.rc">
Expand Down
19 changes: 7 additions & 12 deletions Plugin/RadioUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace SimpleRadio
, unit("None")
, selected(0)
, hasRadio(true)
, caMode(false)
{
for (int i = 0; i < 3; i++)
{
Expand All @@ -23,7 +24,7 @@ namespace SimpleRadio
}
}

string RadioUpdate::serialize(bool formatted) const
string RadioUpdate::serialize() const
{
Json::Value root;

Expand All @@ -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++)
Expand All @@ -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);

}


Expand Down
5 changes: 3 additions & 2 deletions Plugin/RadioUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ namespace SimpleRadio
{
public:
RadioUpdate();
std::string serialize(bool formatted = false) const;

std::string serialize() const;
std::string name;
std::string unit;
int selected;

RadioInformation radios[3];
bool hasRadio;
bool allowNonPlayers;
bool caMode;
};
};

Expand Down
12 changes: 12 additions & 0 deletions Plugin/UDPDiscovery.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "UDPDiscovery.h"



UDPDiscovery::UDPDiscovery()
{
}


UDPDiscovery::~UDPDiscovery()
{
}
10 changes: 10 additions & 0 deletions Plugin/UDPDiscovery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once
class UDPDiscovery
{
public:
UDPDiscovery();
~UDPDiscovery();


};

Loading

0 comments on commit eb11dee

Please sign in to comment.