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

Commit eb11dee

Browse files
committed
Merge pull request #2 from ciribob/newUi
New Minimised Window
2 parents 3c03e7f + 73804f1 commit eb11dee

File tree

17 files changed

+271
-157
lines changed

17 files changed

+271
-157
lines changed

Plugin/Plugin.cpp

Lines changed: 69 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static SimpleRadio::Plugin plugin;
3636
namespace SimpleRadio
3737
{
3838
const char* Plugin::NAME = "DCS-SimpleRadio";
39-
const char* Plugin::VERSION = "1.1.6";
39+
const char* Plugin::VERSION = "1.1.7";
4040
const char* Plugin::AUTHOR = "Ciribob - GitHub.com/ciribob";
4141
const char* Plugin::DESCRIPTION = "DCS-SimpleRadio ";
4242
const char* Plugin::COMMAND_KEYWORD = "sr";
@@ -62,6 +62,8 @@ namespace SimpleRadio
6262
//Delete other things?!
6363
delete[] this->pluginId;
6464
}
65+
66+
6567
}
6668

6769
void Plugin::start()
@@ -299,35 +301,44 @@ namespace SimpleRadio
299301
return data;
300302
}
301303

304+
void Plugin::toggleMuteOnNonUsers()
305+
{
306+
this->allowNonPlayers = !this->allowNonPlayers;
307+
308+
if (this->allowNonPlayers)
309+
{
310+
this->teamspeak.printMessageToCurrentTab("Un-muting clients NOT in an aircraft");
311+
}
312+
else
313+
{
314+
this->teamspeak.printMessageToCurrentTab("Muting clients NOT in an aircraft");
315+
}
316+
}
317+
318+
void Plugin::toggleForceON() {
319+
this->forceOn = !this->forceOn;
320+
321+
if (this->forceOn)
322+
{
323+
this->teamspeak.printMessageToCurrentTab("Forcing ON in Ground Mode");
324+
}
325+
else
326+
{
327+
this->teamspeak.printMessageToCurrentTab("Forcing OFF in Ground Mode");
328+
}
329+
}
330+
302331
void Plugin::onHotKeyEvent(const char * hotkeyCommand) {
303332

304333
if (strcmp("DCS-SR-TOGGLE-MUTE", hotkeyCommand) == 0)
305334
{
306-
this->allowNonPlayers = !this->allowNonPlayers;
307-
308-
if (this->allowNonPlayers)
309-
{
310-
this->teamspeak.printMessageToCurrentTab("Un-muting clients NOT in an aircraft");
311-
}
312-
else
313-
{
314-
this->teamspeak.printMessageToCurrentTab("Muting clients NOT in an aircraft");
315-
}
335+
this->toggleMuteOnNonUsers();
316336
return;
317337

318338
}
319339
else if (strcmp("DCS-SR-TOGGLE-FORCE-ON", hotkeyCommand) == 0)
320340
{
321-
this->forceOn = !this->forceOn;
322-
323-
if (this->forceOn)
324-
{
325-
this->teamspeak.printMessageToCurrentTab("Forcing ON in Ground Mode");
326-
}
327-
else
328-
{
329-
this->teamspeak.printMessageToCurrentTab("Forcing OFF in Ground Mode");
330-
}
341+
this->toggleForceON();
331342
return;
332343

333344
}
@@ -476,6 +487,7 @@ namespace SimpleRadio
476487
update.selected = this->myClientData.selected;
477488
update.hasRadio = this->myClientData.hasRadio;
478489
update.allowNonPlayers = this->allowNonPlayers;
490+
update.caMode = this->forceOn;
479491

480492
for (int i = 0; i < 3; i++)
481493
{
@@ -505,7 +517,7 @@ namespace SimpleRadio
505517
int len = sizeof(SOCKADDR_IN);
506518

507519
//JSON Encode
508-
sprintf(sbuf, "%s\r\n", update.serialize(false).c_str());
520+
sprintf(sbuf, "%s\r\n", update.serialize().c_str());
509521

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

@@ -554,7 +566,7 @@ namespace SimpleRadio
554566

555567
void Plugin::onClientUpdated(uint64 serverConnectionHandlerId, anyID clientId, anyID invokerId)
556568
{
557-
569+
//Called every time and update happens on a client
558570
char* bufferForMetaData;
559571
DWORD error;
560572

@@ -563,7 +575,7 @@ namespace SimpleRadio
563575

564576
anyID myID;
565577
if (this->teamspeak.getClientID(serverConnectionHandlerId, &myID) != ERROR_ok) {
566-
578+
return;
567579
}
568580
else
569581
{
@@ -586,46 +598,36 @@ namespace SimpleRadio
586598
catch (...)
587599
{
588600
this->teamspeak.logMessage("Failed to parse my metadata", LogLevel_ERROR, Plugin::NAME, 0);
589-
590601
}
591602
}
592603

593604
this->teamspeak.freeMemory(bufferForMetaData);
594605

595606
return;
596607
}
597-
}
598-
599-
//Called every time and update happens on a client
600-
601-
602-
if ((error = this->teamspeak.getClientVariableAsString(serverConnectionHandlerId, clientId, CLIENT_META_DATA, &bufferForMetaData)) != ERROR_ok) {
603-
604-
}
605-
else
606-
{
607-
608-
try {
609-
610-
ClientMetaData metadata = ClientMetaData::deserialize(bufferForMetaData, false);
608+
else
609+
{
610+
if ((error = this->teamspeak.getClientVariableAsString(serverConnectionHandlerId, clientId, CLIENT_META_DATA, &bufferForMetaData)) != ERROR_ok) {
611+
return;
612+
}
613+
else
614+
{
615+
try {
611616

612-
auto ret = this->connectedClient.insert(std::pair<anyID, ClientMetaData>(clientId, metadata));
617+
ClientMetaData metadata = ClientMetaData::deserialize(bufferForMetaData, false);
613618

614-
if (!ret.second)
615-
{
616-
this->connectedClient[clientId] = metadata;
619+
this->connectedClient[clientId] = metadata;
620+
}
621+
catch (...)
622+
{
623+
this->teamspeak.logMessage("Failed to parse client metadata", LogLevel_ERROR, Plugin::NAME, 0);
617624

625+
}
626+
this->teamspeak.freeMemory(bufferForMetaData);
627+
return;
618628
}
619629
}
620-
catch (...)
621-
{
622-
this->teamspeak.logMessage("Failed to parse client metadata", LogLevel_ERROR, Plugin::NAME, 0);
623-
624-
}
625630
}
626-
627-
628-
this->teamspeak.freeMemory(bufferForMetaData);
629631
}
630632

631633
void Plugin::onEditPlaybackVoiceDataEvent(uint64 serverConnectionHandlerId, anyID clientId, short* samples, int sampleCount, int channels)
@@ -1167,17 +1169,20 @@ namespace SimpleRadio
11671169
{
11681170
ReceiveBuf[ByteReceived - 1] = 0; //add terminator
11691171

1172+
RadioUpdateCommand updateCommand = RadioUpdateCommand::deserialize(ReceiveBuf);
1173+
11701174
//only allow on FC3 aircraft
1171-
if (this->myClientData.hasRadio == false)
1175+
if (this->myClientData.hasRadio == false || updateCommand.cmdType >=4)
11721176
{
1173-
RadioUpdateCommand updateCommand = RadioUpdateCommand::deserialize(ReceiveBuf);
11741177

11751178
if (updateCommand.radio >= 0)
11761179
{
11771180
/*
1178-
FREQUENCY=1,
1181+
FREQUENCY=1,
11791182
VOLUME=2,
11801183
SELECT=3,
1184+
TOGGLE_MUTE_NON_RADIO = 4,
1185+
TOGGLE_FORCE_RADIO_ON = 5
11811186
*/
11821187
switch (updateCommand.cmdType) {
11831188
case 1:
@@ -1189,6 +1194,15 @@ namespace SimpleRadio
11891194
case 3:
11901195
this->teamSpeakControlledClientData.selected = updateCommand.radio;
11911196
break;
1197+
case 4:
1198+
this->toggleMuteOnNonUsers();
1199+
this->sendUpdateToGUI();
1200+
break;
1201+
case 5:
1202+
this->toggleForceON();
1203+
this->sendUpdateToGUI();
1204+
break;
1205+
11921206
default:
11931207
break;
11941208

@@ -1271,6 +1285,7 @@ void ts3plugin_setFunctionPointers(const struct TS3Functions funcs)
12711285
*/
12721286
int ts3plugin_init()
12731287
{
1288+
//_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
12741289
try
12751290
{
12761291

Plugin/Plugin.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#define DLL_EXPORT __declspec(dllimport)
88
#endif
99

10+
//#define _CRTDBG_MAP_ALLOC
11+
//#include <stdlib.h>
12+
//#include <crtdbg.h>
13+
1014
#include <WinSock2.h>
1115
#include <string>
1216
#include <map>
@@ -47,6 +51,10 @@ namespace SimpleRadio
4751
std::string getClientInfoData(uint64 serverConnectionHandlerId, uint64 clientId) const;
4852
std::string getClientMetaData(uint64 serverConnectionHandlerId, uint64 clientId) const;
4953

54+
void toggleMuteOnNonUsers();
55+
56+
void toggleForceON();
57+
5058
void onClientUpdated(uint64 serverConnectionHandlerId, anyID clientId, anyID invokerId);
5159
void onHotKeyEvent(const char * hotkeyCommand);
5260

Plugin/Plugin.rc

0 Bytes
Binary file not shown.

Plugin/Plugin.vcxproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
<FunctionLevelLinking>true</FunctionLevelLinking>
206206
<IntrinsicFunctions>true</IntrinsicFunctions>
207207
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;PLUGIN_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
208-
<AdditionalIncludeDirectories>$(SolutionDir)DSPFilters\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
208+
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
209209
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
210210
</ClCompile>
211211
<Link>
@@ -229,7 +229,8 @@
229229
<FunctionLevelLinking>true</FunctionLevelLinking>
230230
<IntrinsicFunctions>true</IntrinsicFunctions>
231231
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;PLUGIN_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
232-
<AdditionalIncludeDirectories>$(SolutionDir)DSPFilters\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
232+
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
233+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
233234
</ClCompile>
234235
<Link>
235236
<SubSystem>Windows</SubSystem>
@@ -259,13 +260,15 @@
259260
<ClInclude Include="RadioUpdateCommand.h" />
260261
<ClInclude Include="resource.h" />
261262
<ClInclude Include="ts3_functions.h" />
263+
<ClInclude Include="UDPDiscovery.h" />
262264
</ItemGroup>
263265
<ItemGroup>
264266
<ClCompile Include="ClientMetaData.cpp" />
265267
<ClCompile Include="jsoncpp.cpp" />
266268
<ClCompile Include="Plugin.cpp" />
267269
<ClCompile Include="RadioUpdate.cpp" />
268270
<ClCompile Include="RadioUpdateCommand.cpp" />
271+
<ClCompile Include="UDPDiscovery.cpp" />
269272
</ItemGroup>
270273
<ItemGroup>
271274
<ResourceCompile Include="Plugin.rc" />

Plugin/Plugin.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
<ClInclude Include="RadioUpdateCommand.h">
6161
<Filter>Header Files</Filter>
6262
</ClInclude>
63+
<ClInclude Include="UDPDiscovery.h">
64+
<Filter>Header Files</Filter>
65+
</ClInclude>
6366
</ItemGroup>
6467
<ItemGroup>
6568
<ClCompile Include="Plugin.cpp">
@@ -77,6 +80,9 @@
7780
<ClCompile Include="RadioUpdateCommand.cpp">
7881
<Filter>Source Files</Filter>
7982
</ClCompile>
83+
<ClCompile Include="UDPDiscovery.cpp">
84+
<Filter>Source Files</Filter>
85+
</ClCompile>
8086
</ItemGroup>
8187
<ItemGroup>
8288
<ResourceCompile Include="Plugin.rc">

Plugin/RadioUpdate.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace SimpleRadio
1313
, unit("None")
1414
, selected(0)
1515
, hasRadio(true)
16+
, caMode(false)
1617
{
1718
for (int i = 0; i < 3; i++)
1819
{
@@ -23,7 +24,7 @@ namespace SimpleRadio
2324
}
2425
}
2526

26-
string RadioUpdate::serialize(bool formatted) const
27+
string RadioUpdate::serialize() const
2728
{
2829
Json::Value root;
2930

@@ -32,6 +33,7 @@ namespace SimpleRadio
3233
root["selected"] = this->selected;
3334
root["hasRadio"] = this->hasRadio;
3435
root["allowNonPlayers"] = this->allowNonPlayers; //if false, non players are muted
36+
root["caMode"] = this->caMode;
3537

3638
Json::Value array;
3739
for (int i = 0; i < 3; i++)
@@ -45,17 +47,10 @@ namespace SimpleRadio
4547
}
4648

4749
root["radios"] = array;
48-
49-
if (formatted == true)
50-
{
51-
Json::StyledWriter writer;
52-
return writer.write(root);
53-
}
54-
else
55-
{
56-
Json::FastWriter writer;
57-
return writer.write(root);
58-
}
50+
51+
Json::FastWriter writer;
52+
return writer.write(root);
53+
5954
}
6055

6156

Plugin/RadioUpdate.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ namespace SimpleRadio
1111
{
1212
public:
1313
RadioUpdate();
14-
std::string serialize(bool formatted = false) const;
15-
14+
std::string serialize() const;
15+
1616
std::string name;
1717
std::string unit;
1818
int selected;
1919

2020
RadioInformation radios[3];
2121
bool hasRadio;
2222
bool allowNonPlayers;
23+
bool caMode;
2324
};
2425
};
2526

Plugin/UDPDiscovery.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "UDPDiscovery.h"
2+
3+
4+
5+
UDPDiscovery::UDPDiscovery()
6+
{
7+
}
8+
9+
10+
UDPDiscovery::~UDPDiscovery()
11+
{
12+
}

Plugin/UDPDiscovery.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
class UDPDiscovery
3+
{
4+
public:
5+
UDPDiscovery();
6+
~UDPDiscovery();
7+
8+
9+
};
10+

0 commit comments

Comments
 (0)