cleanup and made it working!

This commit is contained in:
2020-04-18 19:57:47 +02:00
parent b3d250dd43
commit 4544a38175
6 changed files with 548 additions and 488 deletions

4
.gitignore vendored
View File

@@ -1,4 +1,5 @@
<<<<<<< HEAD build-*
# ---> C++ # ---> C++
# Prerequisites # Prerequisites
*.d *.d
@@ -32,7 +33,6 @@
*.exe *.exe
*.out *.out
*.app *.app
=======
## Ignore Visual Studio temporary files, build results, and ## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons. ## files generated by popular Visual Studio add-ons.
## ##

View File

@@ -4,6 +4,8 @@
#TARGET = TS_WIFILED #TARGET = TS_WIFILED
TEMPLATE = lib TEMPLATE = lib
QT += core network
CONFIG += c++14
HEADERS = \ HEADERS = \
$$PWD/include/teamlog/logtypes.h \ $$PWD/include/teamlog/logtypes.h \
@@ -14,10 +16,12 @@ HEADERS = \
$$PWD/include/teamspeak/public_rare_definitions.h \ $$PWD/include/teamspeak/public_rare_definitions.h \
$$PWD/include/plugin_definitions.h \ $$PWD/include/plugin_definitions.h \
$$PWD/include/ts3_functions.h \ $$PWD/include/ts3_functions.h \
$$PWD/src/plugin.h $$PWD/src/plugin.h \ \
src/ledhandler.h
SOURCES = \ SOURCES = \
$$PWD/src/plugin.c $$PWD/src/plugin.cpp \
src/ledhandler.cpp
INCLUDEPATH = \ INCLUDEPATH = \
$$PWD/include \ $$PWD/include \

59
src/ledhandler.cpp Normal file
View File

@@ -0,0 +1,59 @@
#include "ledhandler.h"
LEDHandler::LEDHandler(QUdpSocket* sock, TS3Functions ts3Functions)
{
mSock = sock;
mTs3Functions = ts3Functions;
connect(mSock, &QUdpSocket::connected, this, &LEDHandler::connected);
connect(mSock, &QUdpSocket::disconnected, this, &LEDHandler::disconnected);
connect(mSock, &QUdpSocket::hostFound, this, &LEDHandler::hostFound);
}
void LEDHandler::talkingStarted()
{
printf("started\n");
sendColor(0, 0, 255, 255, 255);
}
void LEDHandler::talkingEnded()
{
printf("stopped\n");
sendColor(0, 0, 0, 0, 0);
}
void LEDHandler::sendColor(int R, int G, int B, int W, int t)
{
QByteArray msg;
msg[0] = 3; // protocol: DRGBW
msg[1] = t; // timeout
msg[2] = R; // R
msg[2] = B; // G
msg[2] = G; // B
msg[2] = W; // W
mSock->write(msg);
}
void LEDHandler::connected()
{
mTs3Functions.logMessage("CONNECTED", LogLevel_INFO, "Plugin", 0);
printf("CONNECTED\n");
}
void LEDHandler::disconnected()
{
mTs3Functions.logMessage("DISCONNECTED", LogLevel_INFO, "Plugin", 0);
printf("DISCONNECTED\n");
}
void LEDHandler::hostFound()
{
mTs3Functions.logMessage("HOST FOUND", LogLevel_INFO, "Plugin", 0);
printf("HOST FOUND\n");
}
//const char* LED_URL_SAVE = "http://10.0.0.222/win&PS=16&NN";
//const char* LED_URL_ON = "http://10.0.0.222/win&T=1&FX=0&R=0&B=255&G=0&W=0&A=255&NN";
//const char* LED_URL_OFF= "http://10.0.0.222/win&PL=16&NN";
//const char* LED_URL_POKE = "http://10.0.0.222/win&PL=15&NN";

30
src/ledhandler.h Normal file
View File

@@ -0,0 +1,30 @@
#ifndef LEDHANDLER_H
#define LEDHANDLER_H
#include <QUdpSocket>
#include <ts3_functions.h>
class LEDHandler : public QObject
{
public:
QString cURL = "10.0.0.222";
int cPORT = 21324;
LEDHandler(QUdpSocket* sock, TS3Functions ts3Functions);
void talkingEnded();
void talkingStarted();
public slots:
void connected();
void disconnected();
void hostFound();
private:
QUdpSocket* mSock;
TS3Functions mTs3Functions;
void sendColor(int R, int G, int B, int W, int t);
};
#endif // LEDHANDLER_H

View File

@@ -3,32 +3,22 @@
* *
* Copyright (c) TeamSpeak Systems GmbH * Copyright (c) TeamSpeak Systems GmbH
*/ */
#define CURL_STATICLIB
#
#if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) #if defined(WIN32) || defined(__WIN32__) || defined(_WIN32)
#pragma warning (disable : 4100) /* Disable Unreferenced parameter warning */ #pragma warning (disable : 4100) /* Disable Unreferenced parameter warning */
#include <Windows.h> #include <Windows.h>
#endif #endif
#include <stdio.h> #include <QtCore>
#include <stdlib.h> #include <QString>
#include <string.h>
#include <assert.h> #include "plugin.h"
#include "teamspeak/public_errors.h" #include "teamspeak/public_errors.h"
#include "teamspeak/public_errors_rare.h" #include "teamspeak/public_errors_rare.h"
#include "teamspeak/public_definitions.h" #include "teamspeak/public_definitions.h"
#include "teamspeak/public_rare_definitions.h" #include "teamspeak/public_rare_definitions.h"
#include "teamspeak/clientlib_publicdefinitions.h" #include "teamspeak/clientlib_publicdefinitions.h"
#include "ts3_functions.h"
#include "plugin.h"
//#include "curl/curl.h"
//#pragma comment (lib, "curl/libcurl_a.lib")
#pragma comment (lib, "Normaliz.lib")
#pragma comment (lib, "Ws2_32.lib")
#pragma comment (lib, "Wldap32.lib")
#pragma comment (lib, "Crypt32.lib")
#pragma comment (lib, "advapi32.lib")
static struct TS3Functions ts3Functions; static struct TS3Functions ts3Functions;
@@ -49,28 +39,10 @@ static struct TS3Functions ts3Functions;
#define RETURNCODE_BUFSIZE 128 #define RETURNCODE_BUFSIZE 128
static char* pluginID = NULL; static char* pluginID = NULL;
//CURL* curl;
//CURLcode res;
const char* LED_URL_SAVE = "http://10.0.0.222/win&PS=16&NN";
const char* LED_URL_ON = "http://10.0.0.222/win&T=1&FX=0&R=0&B=255&G=0&W=0&A=255&NN";
const char* LED_URL_OFF= "http://10.0.0.222/win&PL=16&NN";
const char* LED_URL_POKE = "http://10.0.0.222/win&PL=15&NN";
anyID myClientID = 0; anyID myClientID = 0;
#ifdef _WIN32
/* Helper function to convert wchar_T to Utf-8 encoded strings on Windows */
static int wcharToUtf8(const wchar_t* str, char** result) {
int outlen = WideCharToMultiByte(CP_UTF8, 0, str, -1, 0, 0, 0, 0);
*result = (char*)malloc(outlen);
if(WideCharToMultiByte(CP_UTF8, 0, str, -1, *result, outlen, 0, 0) == 0) {
*result = NULL;
return -1;
}
return 0;
}
#endif
/*********************************** Required functions ************************************/ /*********************************** Required functions ************************************/
/* /*
* If any of these required functions is not implemented, TS3 will refuse to load the plugin * If any of these required functions is not implemented, TS3 will refuse to load the plugin
@@ -78,24 +50,13 @@ static int wcharToUtf8(const wchar_t* str, char** result) {
/* Unique name identifying this plugin */ /* Unique name identifying this plugin */
const char* ts3plugin_name() { const char* ts3plugin_name() {
#ifdef _WIN32
/* TeamSpeak expects UTF-8 encoded characters. Following demonstrates a possibility how to convert UTF-16 wchar_t into UTF-8. */
static char* result = NULL; /* Static variable so it's allocated only once */
if(!result) {
const wchar_t* name = L"WIFILED";
if(wcharToUtf8(name, &result) == -1) { /* Convert name into UTF-8 encoded result */
result = "WIFILED"; /* Conversion failed, fallback here */
}
}
return result;
#else
return "WIFILED"; return "WIFILED";
#endif
} }
/* Plugin version */ /* Plugin version */
const char* ts3plugin_version() { const char* ts3plugin_version() {
return "0.1"; return "0.4";
} }
/* Plugin API version. Must be the same as the clients API major version, else the plugin fails to load. */ /* Plugin API version. Must be the same as the clients API major version, else the plugin fails to load. */
@@ -112,7 +73,7 @@ const char* ts3plugin_author() {
/* Plugin description */ /* Plugin description */
const char* ts3plugin_description() { const char* ts3plugin_description() {
/* If you want to use wchar_t, see ts3plugin_name() on how to use */ /* If you want to use wchar_t, see ts3plugin_name() on how to use */
return "This plugin sends HTTP Requests to an WLED Server to light LEDs."; return "This plugin sends UDP packets to an WLED Server to light LEDs.";
} }
/* Set TeamSpeak 3 callback functions */ /* Set TeamSpeak 3 callback functions */
@@ -142,8 +103,10 @@ int ts3plugin_init() {
printf("PLUGIN: App path: %s\nResources path: %s\nConfig path: %s\nPlugin path: %s\n", appPath, resourcesPath, configPath, pluginPath); printf("PLUGIN: App path: %s\nResources path: %s\nConfig path: %s\nPlugin path: %s\n", appPath, resourcesPath, configPath, pluginPath);
// curl_global_init(CURL_GLOBAL_ALL); mUdpSock = new QUdpSocket();
// curl = curl_easy_init(); mLedHandler = new LEDHandler(mUdpSock, ts3Functions);
mUdpSock->connectToHost(mLedHandler->cURL, mLedHandler->cPORT, QIODevice::WriteOnly);
return 0; /* 0 = success, 1 = failure, -2 = failure but client will not show a "failed to load" warning */ return 0; /* 0 = success, 1 = failure, -2 = failure but client will not show a "failed to load" warning */
/* -2 is a very special case and should only be used if a plugin displays a dialog (e.g. overlay) asking the user to disable /* -2 is a very special case and should only be used if a plugin displays a dialog (e.g. overlay) asking the user to disable
@@ -156,8 +119,9 @@ void ts3plugin_shutdown() {
/* Your plugin cleanup code here */ /* Your plugin cleanup code here */
printf("PLUGIN: shutdown\n"); printf("PLUGIN: shutdown\n");
// curl_easy_cleanup(curl);
// curl_global_cleanup(); delete mUdpSock;
delete mLedHandler;
/* /*
* Note: * Note:
@@ -290,7 +254,7 @@ int ts3plugin_processCommand(uint64 serverConnectionHandlerID, const char* comma
case CMD_JOIN: /* /test join <channelID> [optionalCannelPassword] */ case CMD_JOIN: /* /test join <channelID> [optionalCannelPassword] */
if(param1) { if(param1) {
uint64 channelID = (uint64)atoi(param1); uint64 channelID = (uint64)atoi(param1);
char* password = param2 ? param2 : ""; const char* password = param2 ? param2 : "";
char returnCode[RETURNCODE_BUFSIZE]; char returnCode[RETURNCODE_BUFSIZE];
anyID myID; anyID myID;
@@ -851,24 +815,12 @@ int ts3plugin_onTextMessageEvent(uint64 serverConnectionHandlerID, anyID targetM
} }
void ts3plugin_onTalkStatusChangeEvent(uint64 serverConnectionHandlerID, int status, int isReceivedWhisper, anyID clientID) { void ts3plugin_onTalkStatusChangeEvent(uint64 serverConnectionHandlerID, int status, int isReceivedWhisper, anyID clientID) {
/* Demonstrate usage of getClientDisplayName */
char name[512]; char name[512];
if(ts3Functions.getClientDisplayName(serverConnectionHandlerID, clientID, name, 512) == ERROR_ok) {
if (clientID == myClientID) { if (clientID == myClientID) {
// if (curl) { if (status == STATUS_TALKING)
// if (status == STATUS_TALKING) { mLedHandler->talkingStarted();
// curl_easy_setopt(curl, CURLOPT_URL, LED_URL_SAVE); else
// res = curl_easy_perform(curl); mLedHandler->talkingEnded();
// curl_easy_setopt(curl, CURLOPT_URL, LED_URL_ON);
// res = curl_easy_perform(curl);
// }
// else {
// curl_easy_setopt(curl, CURLOPT_URL, LED_URL_OFF);
// res = curl_easy_perform(curl);
// }
// }
}
} }
} }
@@ -1204,3 +1156,4 @@ const char* ts3plugin_keyPrefix() {
/* Called when client custom nickname changed */ /* Called when client custom nickname changed */
void ts3plugin_onClientDisplayNameChanged(uint64 serverConnectionHandlerID, anyID clientID, const char* displayName, const char* uniqueClientIdentifier) { void ts3plugin_onClientDisplayNameChanged(uint64 serverConnectionHandlerID, anyID clientID, const char* displayName, const char* uniqueClientIdentifier) {
} }

View File

@@ -7,16 +7,30 @@
#ifndef PLUGIN_H #ifndef PLUGIN_H
#define PLUGIN_H #define PLUGIN_H
#include <QUdpSocket>
#if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) #if defined(WIN32) || defined(__WIN32__) || defined(_WIN32)
#include <Windows.h>
#define PLUGINS_EXPORTDLL __declspec(dllexport) #define PLUGINS_EXPORTDLL __declspec(dllexport)
#else #else
#define PLUGINS_EXPORTDLL __attribute__ ((visibility("default"))) #define PLUGINS_EXPORTDLL __attribute__ ((visibility("default")))
#endif #endif
#include "ledhandler.h"
#include "ts3_functions.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
QUdpSocket *mUdpSock;
LEDHandler *mLedHandler;
/* Required functions */ /* Required functions */
PLUGINS_EXPORTDLL const char* ts3plugin_name(); PLUGINS_EXPORTDLL const char* ts3plugin_name();
PLUGINS_EXPORTDLL const char* ts3plugin_version(); PLUGINS_EXPORTDLL const char* ts3plugin_version();