Advertisement
Guest User

Untitled

a guest
Apr 28th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.31 KB | None | 0 0
  1. /*
  2.  * TeamSpeak 3 demo plugin
  3.  *
  4.  * Copyright (c) TeamSpeak Systems GmbH
  5.  */
  6.  
  7. #if defined(WIN32) || defined(__WIN32__) || defined(_WIN32)
  8. #pragma warning (disable : 4100)  /* Disable Unreferenced parameter warning */
  9. #include <Windows.h>
  10. #endif
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <assert.h>
  16. #include "teamspeak/public_errors.h"
  17. #include "teamspeak/public_errors_rare.h"
  18. #include "teamspeak/public_definitions.h"
  19. #include "teamspeak/public_rare_definitions.h"
  20. #include "teamspeak/clientlib_publicdefinitions.h"
  21. #include "ts3_functions.h"
  22. #include "plugin.h"
  23. #include <string>
  24.  
  25. static struct TS3Functions ts3Functions;
  26.  
  27. #ifdef _WIN32
  28. #define _strcpy(dest, destSize, src) strcpy_s(dest, destSize, src)
  29. #define snprintf sprintf_s
  30. #else
  31. #define _strcpy(dest, destSize, src) { strncpy(dest, src, destSize-1); (dest)[destSize-1] = '\0'; }
  32. #endif
  33.  
  34. #define PLUGIN_API_VERSION 23
  35.  
  36. #define PATH_BUFSIZE 512
  37. #define COMMAND_BUFSIZE 128
  38. #define INFODATA_BUFSIZE 128
  39. #define SERVERINFO_BUFSIZE 256
  40. #define CHANNELINFO_BUFSIZE 512
  41. #define RETURNCODE_BUFSIZE 128
  42.  
  43. static char* pluginID = NULL;
  44.  
  45. #ifdef _WIN32
  46. /* Helper function to convert wchar_T to Utf-8 encoded strings on Windows */
  47. static int wcharToUtf8(const wchar_t* str, char** result) {
  48.     int outlen = WideCharToMultiByte(CP_UTF8, 0, str, -1, 0, 0, 0, 0);
  49.     *result = (char*)malloc(outlen);
  50.     if(WideCharToMultiByte(CP_UTF8, 0, str, -1, *result, outlen, 0, 0) == 0) {
  51.         *result = NULL;
  52.         return -1;
  53.     }
  54.     return 0;
  55. }
  56. #endif
  57.  
  58. /*********************************** Required functions ************************************/
  59. /*
  60.  * If any of these required functions is not implemented, TS3 will refuse to load the plugin
  61.  */
  62.  
  63. /* Unique name identifying this plugin */
  64. const char* ts3plugin_name() {
  65.     return "Test Plugin";
  66. }
  67.  
  68. /* Plugin version */
  69. const char* ts3plugin_version() {
  70.     return "0";
  71. }
  72.  
  73. /* Plugin API version. Must be the same as the clients API major version, else the plugin fails to load. */
  74. int ts3plugin_apiVersion() {
  75.     return PLUGIN_API_VERSION;
  76. }
  77.  
  78. /* Plugin author */
  79. const char* ts3plugin_author() {
  80.     /* If you want to use wchar_t, see ts3plugin_name() on how to use */
  81.     return "Test Do NOT Use In Realease";
  82. }
  83.  
  84. /* Plugin description */
  85. const char* ts3plugin_description() {
  86.     /* If you want to use wchar_t, see ts3plugin_name() on how to use */
  87.     return "This plugin is for test purposes.";
  88. }
  89.  
  90. /* Set TeamSpeak 3 callback functions */
  91. void ts3plugin_setFunctionPointers(const struct TS3Functions funcs) {
  92.     ts3Functions = funcs;
  93. }
  94.  
  95. /*
  96.  * Custom code called right after loading the plugin. Returns 0 on success, 1 on failure.
  97.  * If the function returns 1 on failure, the plugin will be unloaded again.
  98.  */
  99. int ts3plugin_init() {
  100.     return 0;  /* 0 = success, 1 = failure, -2 = failure but client will not show a "failed to load" warning */
  101.     /* -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
  102.      * the plugin again, avoiding the show another dialog by the client telling the user the plugin failed to load.
  103.      * For normal case, if a plugin really failed to load because of an error, the correct return value is 1. */
  104. }
  105.  
  106. /* Custom code called right before the plugin is unloaded */
  107. void ts3plugin_shutdown() {
  108.     /* Your plugin cleanup code here */
  109.     printf("PLUGIN: shutdown\n");
  110.  
  111.     /*
  112.      * Note:
  113.      * If your plugin implements a settings dialog, it must be closed and deleted here, else the
  114.      * TeamSpeak client will most likely crash (DLL removed but dialog from DLL code still open).
  115.      */
  116.  
  117.     /* Free pluginID if we registered it */
  118.     if(pluginID) {
  119.         free(pluginID);
  120.         pluginID = NULL;
  121.     }
  122. }
  123.  
  124. void ts3plugin_onClientMoveEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility, const char* moveMessage) {
  125.     // check whether the client connected or changed channel
  126.     if (oldChannelID != 0) return;
  127.    
  128.     // just some variables
  129.     char* moverUniqueIdentifier;
  130.     char* moverName;
  131.     anyID me;
  132.     char* uuid = "h2XOnadFt/lGvSOMETHING123="; // replcae this with your friends UUID
  133.  
  134.     // get the uuid of the connected client
  135.     ts3Functions.getClientVariableAsString(serverConnectionHandlerID, clientID, CLIENT_UNIQUE_IDENTIFIER, &moverUniqueIdentifier);
  136.  
  137.     // check whether the client is the correct one
  138.     if (strcmp(moverUniqueIdentifier, uuid) != 0) { ts3Functions.freeMemory(moverUniqueIdentifier); return; }
  139.     // all tests passed => friend connected
  140.  
  141.     // get friends name
  142.     ts3Functions.getClientVariableAsString(serverConnectionHandlerID, clientID, CLIENT_NICKNAME, &moverName);
  143.     // get own ID to poke
  144.     ts3Functions.getClientID(serverConnectionHandlerID, &me);
  145.  
  146.     // build message for poke
  147.     const char* msg = ("Yoo, the man, " + std::string(moverName) + ", is here!").c_str();
  148.  
  149.     // send the poke
  150.     //ts3Functions.requestClientPoke(serverConnectionHandlerID, me, msg, NULL);
  151.     ts3Functions.printMessageToCurrentTab(msg);
  152.    
  153.     // play poke sound
  154.     char appPath[PATH_BUFSIZE];
  155.     ts3Functions.getAppPath(appPath, PATH_BUFSIZE);
  156.     printf("%s\n", appPath);
  157.     strcat_s(appPath, PATH_BUFSIZE-1, "sound/default/you_were_poked.wav");
  158.     ts3Functions.playWaveFile(serverConnectionHandlerID, appPath);
  159.  
  160.     // cleanup
  161.     ts3Functions.freeMemory(moverUniqueIdentifier);
  162.     ts3Functions.freeMemory(moverName);
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement