Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * TeamSpeak 3 demo plugin
- *
- * Copyright (c) TeamSpeak Systems GmbH
- */
- #if defined(WIN32) || defined(__WIN32__) || defined(_WIN32)
- #pragma warning (disable : 4100) /* Disable Unreferenced parameter warning */
- #include <Windows.h>
- #endif
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <assert.h>
- #include "teamspeak/public_errors.h"
- #include "teamspeak/public_errors_rare.h"
- #include "teamspeak/public_definitions.h"
- #include "teamspeak/public_rare_definitions.h"
- #include "teamspeak/clientlib_publicdefinitions.h"
- #include "ts3_functions.h"
- #include "plugin.h"
- #include <string>
- static struct TS3Functions ts3Functions;
- #ifdef _WIN32
- #define _strcpy(dest, destSize, src) strcpy_s(dest, destSize, src)
- #define snprintf sprintf_s
- #else
- #define _strcpy(dest, destSize, src) { strncpy(dest, src, destSize-1); (dest)[destSize-1] = '\0'; }
- #endif
- #define PLUGIN_API_VERSION 23
- #define PATH_BUFSIZE 512
- #define COMMAND_BUFSIZE 128
- #define INFODATA_BUFSIZE 128
- #define SERVERINFO_BUFSIZE 256
- #define CHANNELINFO_BUFSIZE 512
- #define RETURNCODE_BUFSIZE 128
- static char* pluginID = NULL;
- #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 ************************************/
- /*
- * If any of these required functions is not implemented, TS3 will refuse to load the plugin
- */
- /* Unique name identifying this plugin */
- const char* ts3plugin_name() {
- return "Test Plugin";
- }
- /* Plugin version */
- const char* ts3plugin_version() {
- return "0";
- }
- /* Plugin API version. Must be the same as the clients API major version, else the plugin fails to load. */
- int ts3plugin_apiVersion() {
- return PLUGIN_API_VERSION;
- }
- /* Plugin author */
- const char* ts3plugin_author() {
- /* If you want to use wchar_t, see ts3plugin_name() on how to use */
- return "Test Do NOT Use In Realease";
- }
- /* Plugin description */
- const char* ts3plugin_description() {
- /* If you want to use wchar_t, see ts3plugin_name() on how to use */
- return "This plugin is for test purposes.";
- }
- /* Set TeamSpeak 3 callback functions */
- void ts3plugin_setFunctionPointers(const struct TS3Functions funcs) {
- ts3Functions = funcs;
- }
- /*
- * Custom code called right after loading the plugin. Returns 0 on success, 1 on failure.
- * If the function returns 1 on failure, the plugin will be unloaded again.
- */
- int ts3plugin_init() {
- 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
- * the plugin again, avoiding the show another dialog by the client telling the user the plugin failed to load.
- * For normal case, if a plugin really failed to load because of an error, the correct return value is 1. */
- }
- /* Custom code called right before the plugin is unloaded */
- void ts3plugin_shutdown() {
- /* Your plugin cleanup code here */
- printf("PLUGIN: shutdown\n");
- /*
- * Note:
- * If your plugin implements a settings dialog, it must be closed and deleted here, else the
- * TeamSpeak client will most likely crash (DLL removed but dialog from DLL code still open).
- */
- /* Free pluginID if we registered it */
- if(pluginID) {
- free(pluginID);
- pluginID = NULL;
- }
- }
- void ts3plugin_onClientMoveEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility, const char* moveMessage) {
- // check whether the client connected or changed channel
- if (oldChannelID != 0) return;
- // just some variables
- char* moverUniqueIdentifier;
- char* moverName;
- anyID me;
- char* uuid = "h2XOnadFt/lGvSOMETHING123="; // replcae this with your friends UUID
- // get the uuid of the connected client
- ts3Functions.getClientVariableAsString(serverConnectionHandlerID, clientID, CLIENT_UNIQUE_IDENTIFIER, &moverUniqueIdentifier);
- // check whether the client is the correct one
- if (strcmp(moverUniqueIdentifier, uuid) != 0) { ts3Functions.freeMemory(moverUniqueIdentifier); return; }
- // all tests passed => friend connected
- // get friends name
- ts3Functions.getClientVariableAsString(serverConnectionHandlerID, clientID, CLIENT_NICKNAME, &moverName);
- // get own ID to poke
- ts3Functions.getClientID(serverConnectionHandlerID, &me);
- // build message for poke
- const char* msg = ("Yoo, the man, " + std::string(moverName) + ", is here!").c_str();
- // send the poke
- //ts3Functions.requestClientPoke(serverConnectionHandlerID, me, msg, NULL);
- ts3Functions.printMessageToCurrentTab(msg);
- // play poke sound
- char appPath[PATH_BUFSIZE];
- ts3Functions.getAppPath(appPath, PATH_BUFSIZE);
- printf("%s\n", appPath);
- strcat_s(appPath, PATH_BUFSIZE-1, "sound/default/you_were_poked.wav");
- ts3Functions.playWaveFile(serverConnectionHandlerID, appPath);
- // cleanup
- ts3Functions.freeMemory(moverUniqueIdentifier);
- ts3Functions.freeMemory(moverName);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement