Skip to content

Commit 368941a

Browse files
author
Jon
committed
First build
1 parent 5a4fe10 commit 368941a

27 files changed

Lines changed: 30596 additions & 0 deletions

API.cpp

Lines changed: 402 additions & 0 deletions
Large diffs are not rendered by default.

API.h

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#pragma once
2+
#include <cstdio>
3+
#include <cstdlib>
4+
5+
#include <thread>
6+
#include <mutex>
7+
8+
#ifdef _WIN32
9+
#pragma comment( lib, "WSock32.Lib" )
10+
#include <winsock2.h>
11+
#endif
12+
#include <map>
13+
#include "teamspeak/public_definitions.h"
14+
#include "dependencies/nlohmann/json.hpp"
15+
16+
class TS3_API {
17+
TS3_API();
18+
~TS3_API();
19+
public:
20+
struct TS3User {
21+
char name[256];
22+
anyID id = 0;
23+
uint64 channel_id = 0;
24+
char is_talking = 0;
25+
char speakers_muted = 0;
26+
char mic_muted = 0;
27+
int toJson(nlohmann::json* json);
28+
};
29+
struct TS3Server {
30+
uint64 id;
31+
anyID my_client_id;
32+
char name[256];
33+
char welcome_message[512];
34+
char host[256];
35+
unsigned short port = 0;
36+
char password[128];
37+
int toJson(nlohmann::json* json);
38+
void reset();
39+
} server;
40+
int is_websocket_connection = 1; // Used for identifying websocket connections in request->user_data
41+
private:
42+
enum {
43+
MAX_WSCONN = 5
44+
};
45+
std::thread runner;
46+
std::recursive_mutex mutex;
47+
int shutting_down = false;
48+
int last_error_code = 0;
49+
int ws_connection_count = 0;
50+
WSADATA wsa_data;
51+
struct WebbyConnection* ws_connections[MAX_WSCONN];
52+
void* ws_memory = nullptr;
53+
struct WebbyServer* ws_server = nullptr;
54+
55+
std::map<anyID, TS3User*> clients;
56+
57+
int removeClient(struct WebbyConnection* connection);
58+
int addClient(struct WebbyConnection* connection);
59+
int stopWebserver();
60+
static void onWebsocketDebugMessage(const char* message);
61+
62+
// Raw packet received via HTTP request
63+
static int onHttpRequest(struct WebbyConnection* connection);
64+
// Raw connection started from a websocket client
65+
static int onWebsocketConnection(struct WebbyConnection* connection);
66+
// Client successfully connected via websocket
67+
static void onWebsocketConnected(struct WebbyConnection* connection);
68+
// Client disconnected via websocket
69+
static void onWebsocketDisconnect(struct WebbyConnection* connection);
70+
// Packet has been collated into a message; process it.
71+
static int onClientMessage(const char* message, struct WebbyConnection* connection);
72+
// Raw packet frame received via websocket
73+
static int onWebsocketMessage(struct WebbyConnection* connection, const struct WebbyWsFrame* frame);
74+
// Spin up the server!
75+
int startWebserver();
76+
// Send JSON object of current state of play
77+
int sendServerInfo();
78+
int writeJson(struct WebbyConnection* connection, std::string& message);
79+
int writeJson(struct WebbyConnection* connection, nlohmann::json & json);
80+
// Write out to a connection
81+
int write(struct WebbyConnection* connection, const char* response, struct WebbyHeader* headers = nullptr, int header_count = 0);
82+
bool isWebsocketConnection(struct WebbyConnection* connection);
83+
public:
84+
static TS3_API& Instance() {
85+
static TS3_API instance;
86+
return instance;
87+
}
88+
void resetServerVariables();
89+
// Call once per frame
90+
void update();
91+
// Log message recieved from Webby
92+
static void onLogMessage(const char* message, ...);
93+
TS3User* getUser(anyID clientId);
94+
// Update (or add) a client.
95+
TS3User* updateUser(anyID clientId, TS3User* client, bool* changed_bool = nullptr);
96+
// Remove a client.
97+
int deleteUser(anyID clientId);
98+
// Send a specific client JSON message to any connected sockets
99+
int sendClient(anyID clientId, struct WebbyConnection* connection = nullptr);
100+
// Send all clients in a JSON array to any connected sockets
101+
int sendAllClients(struct WebbyConnection* connection = nullptr);
102+
// Send all info including server data
103+
int sendAllInfo(struct WebbyConnection* connection = nullptr);
104+
// Trigger when message is received
105+
int onTeamspeakMessage(TS3User* from, TS3User* to, const char* message);
106+
};

Teamspeak3_Win_API.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30225.117
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Teamspeak3_WinAPI", "Teamspeak3_Win_API.vcxproj", "{192D646D-748B-450B-AF3D-BF8EDD5FC897}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{192D646D-748B-450B-AF3D-BF8EDD5FC897}.Debug|x64.ActiveCfg = Debug|x64
17+
{192D646D-748B-450B-AF3D-BF8EDD5FC897}.Debug|x64.Build.0 = Debug|x64
18+
{192D646D-748B-450B-AF3D-BF8EDD5FC897}.Debug|x86.ActiveCfg = Debug|Win32
19+
{192D646D-748B-450B-AF3D-BF8EDD5FC897}.Debug|x86.Build.0 = Debug|Win32
20+
{192D646D-748B-450B-AF3D-BF8EDD5FC897}.Release|x64.ActiveCfg = Release|x64
21+
{192D646D-748B-450B-AF3D-BF8EDD5FC897}.Release|x64.Build.0 = Release|x64
22+
{192D646D-748B-450B-AF3D-BF8EDD5FC897}.Release|x86.ActiveCfg = Release|Win32
23+
{192D646D-748B-450B-AF3D-BF8EDD5FC897}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {A93CBF3D-487C-4C38-8249-27B9EDEDA01F}
30+
EndGlobalSection
31+
EndGlobal

Teamspeak3_Win_API.vcxproj

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Debug|x64">
9+
<Configuration>Debug</Configuration>
10+
<Platform>x64</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Release|Win32">
13+
<Configuration>Release</Configuration>
14+
<Platform>Win32</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<ProjectGuid>{192D646D-748B-450B-AF3D-BF8EDD5FC897}</ProjectGuid>
23+
<RootNamespace>test_plugin</RootNamespace>
24+
<Keyword>Win32Proj</Keyword>
25+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
26+
<ProjectName>ts3_json_api</ProjectName>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
30+
<ConfigurationType>DynamicLibrary</ConfigurationType>
31+
<PlatformToolset>v120_xp</PlatformToolset>
32+
<CharacterSet>Unicode</CharacterSet>
33+
</PropertyGroup>
34+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
35+
<ConfigurationType>DynamicLibrary</ConfigurationType>
36+
<PlatformToolset>v120_xp</PlatformToolset>
37+
<CharacterSet>Unicode</CharacterSet>
38+
</PropertyGroup>
39+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
40+
<ConfigurationType>DynamicLibrary</ConfigurationType>
41+
<PlatformToolset>v142</PlatformToolset>
42+
<CharacterSet>MultiByte</CharacterSet>
43+
</PropertyGroup>
44+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
45+
<ConfigurationType>DynamicLibrary</ConfigurationType>
46+
<PlatformToolset>v142</PlatformToolset>
47+
<CharacterSet>MultiByte</CharacterSet>
48+
</PropertyGroup>
49+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
50+
<ImportGroup Label="ExtensionSettings">
51+
</ImportGroup>
52+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
53+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
54+
</ImportGroup>
55+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
56+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
57+
</ImportGroup>
58+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
59+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
60+
</ImportGroup>
61+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
62+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
63+
</ImportGroup>
64+
<PropertyGroup Label="UserMacros" />
65+
<PropertyGroup>
66+
<_ProjectFileVersion>12.0.30501.0</_ProjectFileVersion>
67+
</PropertyGroup>
68+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
69+
<OutDir>bin</OutDir>
70+
<IntDir>$(Configuration)\</IntDir>
71+
<TargetName>$(ProjectName)_plugin_win32</TargetName>
72+
</PropertyGroup>
73+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
74+
<TargetName>$(ProjectName)_plugin_win64</TargetName>
75+
</PropertyGroup>
76+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
77+
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
78+
<IntDir>$(Configuration)\</IntDir>
79+
</PropertyGroup>
80+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
81+
<ClCompile>
82+
<Optimization>Disabled</Optimization>
83+
<AdditionalIncludeDirectories>include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
84+
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
85+
<PrecompiledHeader />
86+
<WarningLevel>Level3</WarningLevel>
87+
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
88+
</ClCompile>
89+
<Link>
90+
<GenerateDebugInformation>true</GenerateDebugInformation>
91+
<SubSystem>Console</SubSystem>
92+
<DataExecutionPrevention />
93+
<TargetMachine>NotSet</TargetMachine>
94+
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
95+
</Link>
96+
</ItemDefinitionGroup>
97+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
98+
<ClCompile>
99+
<Optimization>Disabled</Optimization>
100+
<AdditionalIncludeDirectories>include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
101+
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
102+
<PrecompiledHeader>
103+
</PrecompiledHeader>
104+
<WarningLevel>Level3</WarningLevel>
105+
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
106+
</ClCompile>
107+
<Link>
108+
<GenerateDebugInformation>true</GenerateDebugInformation>
109+
<SubSystem>Windows</SubSystem>
110+
<DataExecutionPrevention>
111+
</DataExecutionPrevention>
112+
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
113+
</Link>
114+
</ItemDefinitionGroup>
115+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
116+
<ClCompile>
117+
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;TEST_PLUGIN_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
118+
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
119+
<PrecompiledHeader />
120+
<WarningLevel>Level3</WarningLevel>
121+
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
122+
<AdditionalIncludeDirectories>..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
123+
</ClCompile>
124+
<Link>
125+
<SubSystem>Windows</SubSystem>
126+
<DataExecutionPrevention />
127+
<TargetMachine>MachineX86</TargetMachine>
128+
</Link>
129+
</ItemDefinitionGroup>
130+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
131+
<ClCompile>
132+
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;TEST_PLUGIN_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
133+
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
134+
<PrecompiledHeader>
135+
</PrecompiledHeader>
136+
<WarningLevel>Level3</WarningLevel>
137+
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
138+
<AdditionalIncludeDirectories>..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
139+
</ClCompile>
140+
<Link>
141+
<SubSystem>Windows</SubSystem>
142+
<DataExecutionPrevention>
143+
</DataExecutionPrevention>
144+
</Link>
145+
</ItemDefinitionGroup>
146+
<ItemGroup>
147+
<ClCompile Include="API.cpp" />
148+
<ClCompile Include="dependencies\Scanner.cpp" />
149+
<ClCompile Include="plugin.cpp" />
150+
</ItemGroup>
151+
<ItemGroup>
152+
<ClInclude Include="..\include\plugin_definitions.h" />
153+
<ClInclude Include="..\include\teamlog\logtypes.h" />
154+
<ClInclude Include="..\include\teamspeak\clientlib_publicdefinitions.h" />
155+
<ClInclude Include="..\include\teamspeak\public_definitions.h" />
156+
<ClInclude Include="..\include\teamspeak\public_errors.h" />
157+
<ClInclude Include="..\include\teamspeak\public_errors_rare.h" />
158+
<ClInclude Include="..\include\teamspeak\public_rare_definitions.h" />
159+
<ClInclude Include="..\include\ts3_functions.h" />
160+
<ClInclude Include="API.h" />
161+
<ClInclude Include="plugin.h" />
162+
</ItemGroup>
163+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
164+
<ImportGroup Label="ExtensionTargets">
165+
</ImportGroup>
166+
</Project>

Teamspeak3_Win_API.vcxproj.filters

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Header Files\teamspeak">
13+
<UniqueIdentifier>{424f4ce9-e47e-43e3-91bc-85bbfec2c680}</UniqueIdentifier>
14+
</Filter>
15+
<Filter Include="Header Files\teamlog">
16+
<UniqueIdentifier>{d76dfa87-907d-4936-a5cf-59462dba95d7}</UniqueIdentifier>
17+
</Filter>
18+
<Filter Include="include">
19+
<UniqueIdentifier>{fc5914af-4792-4c44-920d-36a63b17d831}</UniqueIdentifier>
20+
</Filter>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ClInclude Include="plugin.h">
24+
<Filter>Header Files</Filter>
25+
</ClInclude>
26+
<ClInclude Include="..\include\ts3_functions.h">
27+
<Filter>Header Files</Filter>
28+
</ClInclude>
29+
<ClInclude Include="..\include\teamspeak\clientlib_publicdefinitions.h">
30+
<Filter>Header Files\teamspeak</Filter>
31+
</ClInclude>
32+
<ClInclude Include="..\include\teamspeak\public_definitions.h">
33+
<Filter>Header Files\teamspeak</Filter>
34+
</ClInclude>
35+
<ClInclude Include="..\include\teamspeak\public_errors.h">
36+
<Filter>Header Files\teamspeak</Filter>
37+
</ClInclude>
38+
<ClInclude Include="..\include\teamspeak\public_errors_rare.h">
39+
<Filter>Header Files\teamspeak</Filter>
40+
</ClInclude>
41+
<ClInclude Include="..\include\teamspeak\public_rare_definitions.h">
42+
<Filter>Header Files\teamspeak</Filter>
43+
</ClInclude>
44+
<ClInclude Include="..\include\teamlog\logtypes.h">
45+
<Filter>Header Files\teamlog</Filter>
46+
</ClInclude>
47+
<ClInclude Include="..\include\plugin_definitions.h">
48+
<Filter>Header Files</Filter>
49+
</ClInclude>
50+
<ClInclude Include="API.h">
51+
<Filter>include</Filter>
52+
</ClInclude>
53+
</ItemGroup>
54+
<ItemGroup>
55+
<ClCompile Include="plugin.cpp">
56+
<Filter>Source Files</Filter>
57+
</ClCompile>
58+
<ClCompile Include="API.cpp">
59+
<Filter>Source Files</Filter>
60+
</ClCompile>
61+
<ClCompile Include="dependencies\Scanner.cpp">
62+
<Filter>Source Files</Filter>
63+
</ClCompile>
64+
</ItemGroup>
65+
</Project>

0 commit comments

Comments
 (0)