Advertisement
Guest User

MusicBot

a guest
Sep 18th, 2010
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 30.80 KB | None | 0 0
  1. /*
  2.  * TeamSpeak 3 demo plugin
  3.  *
  4.  * Copyright (c) 2008-2010 TeamSpeak Systems GmbH
  5.  */
  6.  
  7. #ifdef WINDOWS
  8. #pragma warning (disable : 4100)  /* Disable Unreferenced parameter warning */
  9. #endif
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <windows.h>
  15. #include <tchar.h>
  16. #include <iostream>
  17. #include "public_errors.h"
  18. #include "public_definitions.h"
  19. #include "public_rare_definitions.h"
  20. #include "ts3_functions.h"
  21. #include "plugin_events.h"
  22. #include "plugin.h"
  23.  
  24.  
  25. static struct TS3Functions ts3Functions;
  26.  
  27. #ifdef WINDOWS
  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 PATH_BUFSIZE 512
  35. #define COMMAND_BUFSIZE 128
  36. #define INFODATA_BUFSIZE 128
  37. #define SERVERINFO_BUFSIZE 256
  38. #define CHANNELINFO_BUFSIZE 512
  39.  
  40. static char* pluginCommandID = NULL;
  41. const char* winampTitle;
  42.  
  43. /*********************************** Required functions ************************************/
  44. /*
  45.  * If any of these required functions is not implemented, TS3 will refuse to load the plugin
  46.  */
  47.  
  48. /* Unique name identifying this plugin */
  49. const char* ts3plugin_name() {
  50.     return "MusicBot";
  51. }
  52.  
  53. /* Plugin version */
  54. const char* ts3plugin_version() {
  55.     return "0.1";
  56. }
  57.  
  58. /* Plugin API version. Must be the same as the clients API major version, else the plugin fails to load. */
  59. int ts3plugin_apiVersion() {
  60.     return 8;
  61. }
  62.  
  63. /* Plugin author */
  64. const char* ts3plugin_author() {
  65.     return "SteZZz";
  66. }
  67.  
  68. /* Plugin description */
  69. const char* ts3plugin_description() {
  70.     return "This plugin makes a MusicBot out of your TS3 Client.";
  71. }
  72.  
  73. /* Set TeamSpeak 3 callback functions */
  74. void ts3plugin_setFunctionPointers(const struct TS3Functions funcs) {
  75.     ts3Functions = funcs;
  76. }
  77.  
  78. /*
  79.  * Custom code called right after loading the plugin. Returns 0 on success, 1 on failure.
  80.  * If the function returns 1 on failure, the plugin will be unloaded again.
  81.  */
  82. int ts3plugin_init() {
  83.     //char appPath[PATH_BUFSIZE];
  84.     //char resourcesPath[PATH_BUFSIZE];
  85.     //char configPath[PATH_BUFSIZE];
  86.     //char pluginPath[PATH_BUFSIZE];
  87.  
  88.     /* Your plugin init code here */
  89.    // printf("PLUGIN: init\n");
  90.  
  91.     /* Show API versions */
  92.     //printf("PLUGIN: Client API Version: %d, Plugin API Version: %d\n", ts3Functions.getAPIVersion(), ts3plugin_apiVersion());
  93.  
  94.     /* Example on how to query application, resources and configuration paths from client */
  95.     /* Note: Console client returns empty string for app and resources path */
  96.    // ts3Functions.getAppPath(appPath, PATH_BUFSIZE);
  97.    // ts3Functions.getResourcesPath(resourcesPath, PATH_BUFSIZE);
  98.    // ts3Functions.getConfigPath(configPath, PATH_BUFSIZE);
  99.     //ts3Functions.getPluginPath(pluginPath, PATH_BUFSIZE);
  100.  
  101.     //printf("PLUGIN: App path: %s\nResources path: %s\nConfig path: %s\nPlugin path: %s\n", appPath, resourcesPath, configPath, pluginPath);
  102.  
  103.     return 0;  /* 0 = success, 1 = failure */
  104. }
  105.  
  106. /* Custom code called right before the plugin is unloaded */
  107. void ts3plugin_shutdown() {
  108.     /* Your plugin cleanup code here */
  109.     printf("MusicBot PLUGIN: shutdown\n");
  110.  
  111.     /* Free pluginCommandID if we registered it */
  112.     if(pluginCommandID) {
  113.         free(pluginCommandID);
  114.         pluginCommandID = NULL;
  115.     }
  116. }
  117.  
  118. /****************************** Optional functions ********************************/
  119. /*
  120.  * Following functions are optional, if not needed you don't need to implement them.
  121.  */
  122.  
  123. /* Tell client if plugin offers a configuration window. If this function is not implemented, it's an assumed "does not offer" (PLUGIN_OFFERS_NO_CONFIGURE). */
  124. //int ts3plugin_offersConfigure() {
  125. //  printf("PLUGIN: offersConfigure\n");
  126.     /*
  127.      * Return values:
  128.      * PLUGIN_OFFERS_NO_CONFIGURE         - Plugin does not implement ts3plugin_configure
  129.      * PLUGIN_OFFERS_CONFIGURE_NEW_THREAD - Plugin does implement ts3plugin_configure and requests to run this function in an own thread
  130.      * PLUGIN_OFFERS_CONFIGURE_QT_THREAD  - Plugin does implement ts3plugin_configure and requests to run this function in the Qt GUI thread
  131.      */
  132.     //return PLUGIN_OFFERS_NO_CONFIGURE;  /* In this case ts3plugin_configure does not need to be implemented */
  133. //}
  134.  
  135. /* Plugin might offer a configuration window.I f ts3plugin_offersConfigure returns 0, this function does not need to be implemented. */
  136. //void ts3plugin_configure(void* handle, void* qParentWidget) {
  137. //    printf("PLUGIN: configure\n");
  138. //}
  139.  
  140. /*
  141.  * If the plugin wants to use plugin commands, it needs to register a command ID. This function will be automatically called after
  142.  * the plugin was initialized. This function is optional. If you don't use plugin commands, the function can be omitted.
  143.  * Note the passed commandID parameter is no longer valid after calling this function, so you *must* copy it and store it in the plugin.
  144.  */
  145. void ts3plugin_registerPluginCommandID(const char* commandID) {
  146.     const size_t sz = strlen(commandID) + 1;
  147.     pluginCommandID = (char*)malloc(sz * sizeof(char));
  148.     _strcpy(pluginCommandID, sz, commandID);  /* The commandID buffer will invalidate after existing this function */
  149.     printf("PLUGIN: registerPluginCommandID: %s\n", pluginCommandID);
  150. }
  151.  
  152. /* Plugin command keyword. Return NULL or "" if not used. */
  153. const char* ts3plugin_commandKeyword() {
  154.     return "";
  155. }
  156.  
  157. /* Plugin processes console command. Return 0 if plugin handled the command, 1 if not handled. */
  158. int ts3plugin_processCommand(uint64 serverConnectionHandlerID, const char* command) {
  159.     char buf[COMMAND_BUFSIZE];
  160.     char *s, *param1 = NULL, *param2 = NULL;
  161.     int i = 0;
  162.     enum { CMD_NONE = 0, CMD_JOIN, CMD_COMMAND, CMD_SERVERINFO, CMD_CHANNELINFO } cmd = CMD_NONE;
  163. #ifdef WINDOWS
  164.     char* context = NULL;
  165. #endif
  166.  
  167.     printf("PLUGIN: process command: '%s'\n", command);
  168.  
  169.     /* Test command: "join <channelID> [password]" */
  170.     _strcpy(buf, COMMAND_BUFSIZE, command);
  171. #ifdef WINDOWS
  172.     s = strtok_s(buf, " ", &context);
  173. #else
  174.     s = strtok(buf, " ");
  175. #endif
  176.     while(s != NULL) {
  177.         if(i == 0) {
  178.             if(!strcmp(s, "join")) {
  179.                 cmd = CMD_JOIN;
  180.             } else if(!strcmp(s, "command")) {
  181.                 cmd = CMD_COMMAND;
  182.             } else if(!strcmp(s, "serverinfo")) {
  183.                 cmd = CMD_SERVERINFO;
  184.             } else if(!strcmp(s, "channelinfo")) {
  185.                 cmd = CMD_CHANNELINFO;
  186.             }
  187.         } else if(i == 1) {
  188.             param1 = s;
  189.         } else {
  190.             param2 = s;
  191.         }
  192. #ifdef WINDOWS
  193.         s = strtok_s(NULL, " ", &context);
  194. #else
  195.         s = strtok(NULL, " ");
  196. #endif
  197.         i++;
  198.     }
  199.  
  200.     switch(cmd) {
  201.         case CMD_NONE:
  202.             return 1;  /* Command not handled by plugin */
  203.         case CMD_JOIN:
  204.             if(param1) {
  205.                 uint64 channelID = (uint64)atoi(param1);
  206.                 char* password = param2 ? param2 : "";
  207.                 anyID myID;
  208.  
  209.                 /* Get own clientID */
  210.                 if(ts3Functions.getClientID(serverConnectionHandlerID, &myID) != ERROR_ok) {
  211.                     ts3Functions.logMessage("Error querying client ID", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  212.                     break;
  213.                 }
  214.  
  215.                 /* Join specified channel */
  216.                 if(ts3Functions.requestClientMove(serverConnectionHandlerID, myID, channelID, password, NULL) != ERROR_ok) {
  217.                     ts3Functions.logMessage("Error requesting client move", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  218.                 }
  219.             } else {
  220.                 ts3Functions.printMessageToCurrentTab("Missing channel ID parameter.");
  221.             }
  222.             break;
  223.         case CMD_COMMAND:
  224.             if(param1) {
  225.                 /* Send plugin command to all clients in current channel. In this case targetIds is unused and can be NULL. */
  226.                 if(pluginCommandID) {
  227.                     /* See ts3plugin_registerPluginCommandID for how to obtain pluginCommandID */
  228.                     printf("PLUGIN: Sending plugin command to current channel: %s\n", param1);
  229.                     ts3Functions.sendPluginCommand(serverConnectionHandlerID, pluginCommandID, param1, PluginCommandTarget_CURRENT_CHANNEL, NULL);
  230.                 } else {
  231.                     printf("PLUGIN: Failed to send plugin command, was not registered.\n");
  232.                 }
  233.             } else {
  234.                 ts3Functions.printMessageToCurrentTab("Missing command parameter.");
  235.             }
  236.             break;
  237.         case CMD_SERVERINFO: {
  238.             /* Query host, port and server password of current server tab.
  239.              * The password parameter can be NULL if the plugin does not want to receive the server password.
  240.              * Note: Server password is only available if the user has actually used it when connecting. If a user has
  241.              * connected with the permission to ignore passwords (b_virtualserver_join_ignore_password) and the password,
  242.              * was not entered, it will not be available.
  243.              * getServerConnectInfo returns 0 on success, 1 on error or if current server tab is disconnected. */
  244.             char host[SERVERINFO_BUFSIZE];
  245.             /*char password[SERVERINFO_BUFSIZE];*/
  246.             char* password = NULL;  /* Don't receive server password */
  247.             unsigned short port;
  248.             if(!ts3Functions.getServerConnectInfo(ts3Functions.getCurrentServerConnectionHandlerID(), host, &port, password, SERVERINFO_BUFSIZE)) {
  249.                 char msg[SERVERINFO_BUFSIZE];
  250.                 snprintf(msg, sizeof(msg), "Server Connect Info: %s:%d", host, port);
  251.                 ts3Functions.printMessageToCurrentTab(msg);
  252.             } else {
  253.                 ts3Functions.printMessageToCurrentTab("No server connect info available.");
  254.             }
  255.             break;
  256.         }
  257.         case CMD_CHANNELINFO: {
  258.             /* Query channel path and password of current server tab.
  259.              * The password parameter can be NULL if the plugin does not want to receive the channel password.
  260.              * Note: Channel password is only available if the user has actually used it when entering the channel. If a user has
  261.              * entered a channel with the permission to ignore passwords (b_channel_join_ignore_password) and the password,
  262.              * was not entered, it will not be available.
  263.              * getChannelConnectInfo returns 0 on success, 1 on error or if current server tab is disconnected. */
  264.             char path[CHANNELINFO_BUFSIZE];
  265.             /*char password[CHANNELINFO_BUFSIZE];*/
  266.             char* password = NULL;  /* Don't receive channel password */
  267.  
  268.             /* Get own clientID and channelID */
  269.             anyID myID;
  270.             uint64 myChannelID;
  271.             if(ts3Functions.getClientID(serverConnectionHandlerID, &myID) != ERROR_ok) {
  272.                 ts3Functions.logMessage("Error querying client ID", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  273.                 break;
  274.             }
  275.             /* Get own channel ID */
  276.             if(ts3Functions.getChannelOfClient(serverConnectionHandlerID, myID, &myChannelID) != ERROR_ok) {
  277.                 ts3Functions.logMessage("Error querying channel ID", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  278.                 break;
  279.             }
  280.  
  281.             /* Get channel connect info of own channel */
  282.             if(!ts3Functions.getChannelConnectInfo(ts3Functions.getCurrentServerConnectionHandlerID(), myChannelID, path, password, CHANNELINFO_BUFSIZE)) {
  283.                 char msg[CHANNELINFO_BUFSIZE];
  284.                 snprintf(msg, sizeof(msg), "Channel Connect Info: %s", path);
  285.                 ts3Functions.printMessageToCurrentTab(msg);
  286.             } else {
  287.                 ts3Functions.printMessageToCurrentTab("No channel connect info available.");
  288.             }
  289.             break;
  290.         }
  291.     }
  292.  
  293.     return 1;  /* Plugin handled command */
  294. }
  295.  
  296. /* Client changed current server connection handler */
  297. /**
  298. void ts3plugin_currentServerConnectionChanged(uint64 serverConnectionHandlerID) {
  299.     printf("PLUGIN: currentServerConnectionChanged %llu (%llu)\n", (long long unsigned int)serverConnectionHandlerID, (long long unsigned int)ts3Functions.getCurrentServerConnectionHandlerID());
  300. }
  301. **/
  302. /**
  303. void ts3plugin_pluginEvent(unsigned short data, const char* message) {
  304.     char type, subtype;
  305.  
  306.     printf("PLUGIN: pluginEvent data = %u\n", data);
  307.     if(message) {
  308.         printf("Message: %s\n", message);
  309.     }
  310.  
  311.     type = data >> 8;
  312.     subtype = data & 0xFF;
  313.     printf("Type = %d, subtype = %d\n", type, subtype);
  314.  
  315.     switch(type) {
  316.         case PLUGIN_EVENT_TYPE_HOTKEY:
  317.             switch(subtype) {
  318.                 case PLUGIN_EVENT_SUBTYPE_HOTKEY_TOGGLE_MICRO_ON:
  319.                     printf("Micro on\n");
  320.                     break;
  321.                 case PLUGIN_EVENT_SUBTYPE_HOTKEY_TOGGLE_MICRO_OFF:
  322.                     printf("Micro off\n");
  323.                     break;
  324.                 case PLUGIN_EVENT_SUBTYPE_HOTKEY_TOGGLE_SPEAKER_ON:
  325.                     printf("Speaker on\n");
  326.                     break;
  327.                 case PLUGIN_EVENT_SUBTYPE_HOTKEY_TOGGLE_SPEAKER_OFF:
  328.                     printf("Speaker off\n");
  329.                     break;
  330.                 case PLUGIN_EVENT_SUBTYPE_HOTKEY_TOGGLE_AWAY_ON:
  331.                     printf("Away on\n");
  332.                     break;
  333.                 case PLUGIN_EVENT_SUBTYPE_HOTKEY_TOGGLE_AWAY_OFF:
  334.                     printf("Away off\n");
  335.                     break;
  336.                 case PLUGIN_EVENT_SUBTYPE_HOTKEY_ACTIVATE_MICRO:
  337.                     printf("Activate micro\n");
  338.                     break;
  339.                 case PLUGIN_EVENT_SUBTYPE_HOTKEY_ACTIVATE_SPEAKER:
  340.                     printf("Activate speaker\n");
  341.                     break;
  342.                 case PLUGIN_EVENT_SUBTYPE_HOTKEY_ACTIVATE_AWAY:
  343.                     printf("Activate away\n");
  344.                     break;
  345.                 case PLUGIN_EVENT_SUBTYPE_HOTKEY_DEACTIVATE_MICRO:
  346.                     printf("Deactivate micro\n");
  347.                     break;
  348.                 case PLUGIN_EVENT_SUBTYPE_HOTKEY_DEACTIVATE_SPEAKER:
  349.                     printf("Deactivate speakers\n");
  350.                     break;
  351.                 case PLUGIN_EVENT_SUBTYPE_HOTKEY_DEACTIVATE_AWAY:
  352.                     printf("Deactivate away\n");
  353.                     break;
  354.                 default:
  355.                     break;
  356.             }
  357.             break;
  358.         default:
  359.             break;
  360.     }
  361. }
  362. **/
  363.  
  364. /* Required to release the memory for parameter "data" allocated in ts3plugin_infoData */
  365. void ts3plugin_freeMemory(void* data) {
  366.     free(data);
  367. }
  368.  
  369. /*
  370.  * Plugin requests to be always automatically loaded by the TeamSpeak 3 client unless
  371.  * the user manually disabled it in the plugin dialog.
  372.  * This function is optional. If missing, no autoload is assumed.
  373.  */
  374. int ts3plugin_requestAutoload() {
  375.     return 1;  /* 1 = request autoloaded, 0 = do not request autoload */
  376. }
  377.  
  378. /************************** TeamSpeak callbacks ***************************/
  379. /*
  380.  * Following functions are optional, feel free to remove unused callbacks.
  381.  * See the clientlib documentation for details on each function.
  382.  */
  383.  
  384. /* Clientlib */
  385.  
  386. void ts3plugin_onNewChannelEvent(uint64 serverConnectionHandlerID, uint64 channelID, uint64 channelParentID) {
  387. }
  388.  
  389. void ts3plugin_onNewChannelCreatedEvent(uint64 serverConnectionHandlerID, uint64 channelID, uint64 channelParentID, anyID invokerID, const char* invokerName, const char* invokerUniqueIdentifier) {
  390. }
  391.  
  392. void ts3plugin_onDelChannelEvent(uint64 serverConnectionHandlerID, uint64 channelID, anyID invokerID, const char* invokerName, const char* invokerUniqueIdentifier) {
  393. }
  394.  
  395. void ts3plugin_onChannelMoveEvent(uint64 serverConnectionHandlerID, uint64 channelID, uint64 newChannelParentID, anyID invokerID, const char* invokerName, const char* invokerUniqueIdentifier) {
  396. }
  397.  
  398. void ts3plugin_onUpdateChannelEvent(uint64 serverConnectionHandlerID, uint64 channelID) {
  399. }
  400.  
  401. void ts3plugin_onUpdateChannelEditedEvent(uint64 serverConnectionHandlerID, uint64 channelID, anyID invokerID, const char* invokerName, const char* invokerUniqueIdentifier) {
  402. }
  403.  
  404. void ts3plugin_onUpdateClientEvent(uint64 serverConnectionHandlerID, anyID clientID) {
  405. }
  406.  
  407. void ts3plugin_onClientMoveEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility, const char* moveMessage) {
  408. }
  409.  
  410. void ts3plugin_onClientMoveSubscriptionEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility) {
  411. }
  412.  
  413. void ts3plugin_onClientMoveTimeoutEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility, const char* timeoutMessage) {
  414. }
  415.  
  416. void ts3plugin_onClientMoveMovedEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility, anyID moverID, const char* moverName, const char* moverUniqueIdentifier, const char* moveMessage) {
  417. }
  418.  
  419. void ts3plugin_onClientKickFromChannelEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility, anyID kickerID, const char* kickerName, const char* kickerUniqueIdentifier, const char* kickMessage) {
  420. }
  421.  
  422. void ts3plugin_onClientKickFromServerEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility, anyID kickerID, const char* kickerName, const char* kickerUniqueIdentifier, const char* kickMessage) {
  423. }
  424.  
  425. void ts3plugin_onServerEditedEvent(uint64 serverConnectionHandlerID, anyID editerID, const char* editerName, const char* editerUniqueIdentifier) {
  426. }
  427.  
  428. void ts3plugin_onServerUpdatedEvent(uint64 serverConnectionHandlerID) {
  429. }
  430.  
  431. void ts3plugin_onServerErrorEvent(uint64 serverConnectionHandlerID, const char* errorMessage, unsigned int error, const char* returnCode, const char* extraMessage) {
  432. }
  433.  
  434. void ts3plugin_onServerStopEvent(uint64 serverConnectionHandlerID, const char* shutdownMessage) {
  435. }
  436.  
  437. int ts3plugin_onTextMessageEvent(uint64 serverConnectionHandlerID, anyID targetMode, anyID toID, anyID fromID, const char* fromName, const char* fromUniqueIdentifier, const char* message, int ffIgnored) {
  438.     printf("PLUGIN: onTextMessageEvent %llu %d %d %s %s %d\n", (long long unsigned int)serverConnectionHandlerID, targetMode, fromID, fromName, message, ffIgnored);
  439.  
  440.     ts3Functions.setClientSelfVariableAsString(serverConnectionHandlerID, CLIENT_META_DATA, titleWinamp());
  441.    
  442.    
  443.  
  444.     //const char* aMessage = message;
  445.     //ts3plugin_TestWinamp()
  446.  
  447.     /* Friend/Foe manager has ignored the message, so ignore here as well. */
  448.     if(ffIgnored) {
  449.         return 0; /* Client will ignore the message anyways, so return value here doesn't matter */
  450.     }
  451.  
  452. #if 1
  453.     {
  454.         /* Example code: Autoreply to sender */
  455.         /* Disabled because quite annoying, but should give you some ideas what is possible here */
  456.         /* Careful, when two clients use this, they will get banned quickly... */
  457.         anyID myID;
  458.         if(ts3Functions.getClientID(serverConnectionHandlerID, &myID) != ERROR_ok) {
  459.             ts3Functions.logMessage("Error querying own client id", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  460.             return 0;
  461.         }
  462.         if(fromID != myID) {  /* Don't reply when source is own client */
  463.  
  464.             //if ( strcmp ( message, "!winamp" ) == 0 ){
  465.             //if(starts_with("!winamp",message)){
  466.             if(strcmp(message,"!winamp next") == 0){
  467.                 controlWinamp("next");
  468.                 return 0;
  469.             } else if(strcmp(message,"!winamp prev") == 0){
  470.                 controlWinamp("prev");
  471.                 return 0;
  472.             } else if(strcmp(message,"!winamp stop") == 0){
  473.                 controlWinamp("stop");
  474.                 return 0;
  475.             } else if(strcmp(message,"!winamp play") == 0){
  476.                 controlWinamp("play");
  477.                 return 0;
  478.             } else if(strcmp(message,"!winamp title") == 0){
  479.                 if(ts3Functions.requestSendPrivateTextMsg(serverConnectionHandlerID, titleWinamp() , fromID, NULL) != ERROR_ok) {
  480.                     ts3Functions.logMessage("Error requesting send text message", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  481.                 }
  482.                 return 0;
  483.             } else if(starts_with(message,"!winamp ")){
  484.                 if(ts3Functions.requestSendPrivateTextMsg(serverConnectionHandlerID, message , fromID, NULL) != ERROR_ok) {
  485.                     ts3Functions.logMessage("Error requesting send text message", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  486.                 }
  487.                 return 0;
  488.             } else if(ts3Functions.requestSendPrivateTextMsg(serverConnectionHandlerID, "Hoi" , fromID, NULL) != ERROR_ok) {
  489.                 ts3Functions.logMessage("Error requesting send text message", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  490.             }
  491.             return 0;
  492.         }
  493.     }
  494. #endif
  495.  
  496.     return 0;  /* 0 = handle normally, 1 = client will ignore the text message */
  497. }
  498.  
  499. void ts3plugin_onTalkStatusChangeEvent(uint64 serverConnectionHandlerID, int status, int isReceivedWhisper, anyID clientID) {
  500. }
  501.  
  502. void ts3plugin_onConnectionInfoEvent(uint64 serverConnectionHandlerID, anyID clientID) {
  503. }
  504.  
  505. void ts3plugin_onServerConnectionInfoEvent(uint64 serverConnectionHandlerID) {
  506. }
  507.  
  508. void ts3plugin_onChannelSubscribeEvent(uint64 serverConnectionHandlerID, uint64 channelID) {
  509. }
  510.  
  511. void ts3plugin_onChannelSubscribeFinishedEvent(uint64 serverConnectionHandlerID) {
  512. }
  513.  
  514. void ts3plugin_onChannelUnsubscribeEvent(uint64 serverConnectionHandlerID, uint64 channelID) {
  515. }
  516.  
  517. void ts3plugin_onChannelUnsubscribeFinishedEvent(uint64 serverConnectionHandlerID) {
  518. }
  519.  
  520. void ts3plugin_onChannelDescriptionUpdateEvent(uint64 serverConnectionHandlerID, uint64 channelID) {
  521. }
  522.  
  523. void ts3plugin_onChannelPasswordChangedEvent(uint64 serverConnectionHandlerID, uint64 channelID) {
  524. }
  525.  
  526. void ts3plugin_onCustomCaptureDeviceCloseEvent(uint64 serverConnectionHandlerID, void* fmodSystem) {
  527. }
  528.  
  529. void ts3plugin_onCustomPlaybackDeviceCloseEvent(uint64 serverConnectionHandlerID, void* fmodSystem) {
  530. }
  531.  
  532. void ts3plugin_onFMODChannelCreatedEvent(uint64 serverConnectionHandlerID, anyID clientID, void* fmodChannel) {
  533. }
  534.  
  535. void ts3plugin_onPlaybackShutdownCompleteEvent(uint64 serverConnectionHandlerID) {
  536. }
  537.  
  538. void ts3plugin_onUserLoggingMessageEvent(const char* logMessage, int logLevel, const char* logChannel, uint64 logID, const char* logTime, const char* completeLogString) {
  539. }
  540.  
  541. void ts3plugin_onVoiceRecordDataEvent(const float* data, unsigned int dataSize) {
  542. }
  543.  
  544. /* Clientlib rare */
  545.  
  546. void ts3plugin_onClientBanFromServerEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility, anyID kickerID, const char* kickerName, const char* kickerUniqueIdentifier, uint64 time, const char* kickMessage) {
  547. }
  548.  
  549. int ts3plugin_onClientPokeEvent(uint64 serverConnectionHandlerID, anyID fromClientID, const char* pokerName, const char* pokerUniqueIdentity, const char* message, int ffIgnored) {
  550.     anyID myID;
  551.  
  552.     printf("PLUGIN onClientPokeEvent: %llu %d %s %s %d\n", (long long unsigned int)serverConnectionHandlerID, fromClientID, pokerName, message, ffIgnored);
  553.  
  554.     /* Check if the Friend/Foe manager has already blocked this poke */
  555.     if(ffIgnored) {
  556.         return 0;  /* Client will block anyways, doesn't matter what we return */
  557.     }
  558.  
  559.     /* Example code: Send text message back to poking client */
  560.     if(ts3Functions.getClientID(serverConnectionHandlerID, &myID) != ERROR_ok) {  /* Get own client ID */
  561.         ts3Functions.logMessage("Error querying own client id", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  562.         return 0;
  563.     }
  564.     if(fromClientID != myID) {  /* Don't reply when source is own client */
  565.         if(ts3Functions.requestSendPrivateTextMsg(serverConnectionHandlerID, "Received your poke!", fromClientID, NULL) != ERROR_ok) {
  566.             ts3Functions.logMessage("Error requesting send text message", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  567.         }
  568.     }
  569.  
  570.     return 0;  /* 0 = handle normally, 1 = client will ignore the poke */
  571. }
  572.  
  573. void ts3plugin_onClientSelfVariableUpdateEvent(uint64 serverConnectionHandlerID, int flag, const char* oldValue, const char* newValue) {
  574. }
  575.  
  576. void ts3plugin_onFileListEvent(uint64 serverConnectionHandlerID, uint64 channelID, const char* path, const char* name, uint64 size, uint64 datetime, int type) {
  577. }
  578.  
  579. void ts3plugin_onFileListFinishedEvent(uint64 serverConnectionHandlerID, uint64 channelID, const char* path) {
  580. }
  581.  
  582. void ts3plugin_onFileInfoEvent(uint64 serverConnectionHandlerID, uint64 channelID, const char* name, uint64 size, uint64 datetime) {
  583. }
  584.  
  585. void ts3plugin_onServerGroupListEvent(uint64 serverConnectionHandlerID, uint64 serverGroupID, const char* name, int type, int iconID, int saveDB) {
  586. }
  587.  
  588. void ts3plugin_onServerGroupListFinishedEvent(uint64 serverConnectionHandlerID) {
  589. }
  590.  
  591. void ts3plugin_onServerGroupByClientIDEvent(uint64 serverConnectionHandlerID, const char* name, uint64 serverGroupList, uint64 clientDatabaseID) {
  592. }
  593.  
  594. void ts3plugin_onServerGroupPermListEvent(uint64 serverConnectionHandlerID, uint64 serverGroupID, anyID permissionID, int permissionValue, int permissionNegated, int permissionSkip) {
  595. }
  596.  
  597. void ts3plugin_onServerGroupPermListFinishedEvent(uint64 serverConnectionHandlerID, uint64 serverGroupID) {
  598. }
  599.  
  600. void ts3plugin_onServerGroupClientListEvent(uint64 serverConnectionHandlerID, uint64 serverGroupID, uint64 clientDatabaseID, const char* clientNameIdentifier, const char* clientUniqueID) {
  601. }
  602.  
  603. void ts3plugin_onChannelGroupListEvent(uint64 serverConnectionHandlerID, uint64 channelGroupID, const char* name, int type, int iconID, int saveDB) {
  604. }
  605.  
  606. void ts3plugin_onChannelGroupListFinishedEvent(uint64 serverConnectionHandlerID) {
  607. }
  608.  
  609. void ts3plugin_onChannelGroupPermListEvent(uint64 serverConnectionHandlerID, uint64 channelGroupID, anyID permissionID, int permissionValue, int permissionNegated, int permissionSkip) {
  610. }
  611.  
  612. void ts3plugin_onChannelGroupPermListFinishedEvent(uint64 serverConnectionHandlerID, uint64 channelGroupID) {
  613. }
  614.  
  615. void ts3plugin_onChannelPermListEvent(uint64 serverConnectionHandlerID, uint64 channelID, anyID permissionID, int permissionValue, int permissionNegated, int permissionSkip) {
  616. }
  617.  
  618. void ts3plugin_onChannelPermListFinishedEvent(uint64 serverConnectionHandlerID, uint64 channelID) {
  619. }
  620.  
  621. void ts3plugin_onClientPermListEvent(uint64 serverConnectionHandlerID, uint64 clientDatabaseID, anyID permissionID, int permissionValue, int permissionNegated, int permissionSkip) {
  622. }
  623.  
  624. void ts3plugin_onClientPermListFinishedEvent(uint64 serverConnectionHandlerID, uint64 clientDatabaseID) {
  625. }
  626.  
  627. void ts3plugin_onChannelClientPermListEvent(uint64 serverConnectionHandlerID, uint64 channelID, uint64 clientDatabaseID, anyID permissionID, int permissionValue, int permissionNegated, int permissionSkip) {
  628. }
  629.  
  630. void ts3plugin_onChannelClientPermListFinishedEvent(uint64 serverConnectionHandlerID, uint64 channelID, uint64 clientDatabaseID) {
  631. }
  632.  
  633. void ts3plugin_onClientChannelGroupChangedEvent(uint64 serverConnectionHandlerID, uint64 channelGroupID, uint64 channelID, anyID clientID, anyID invokerClientID, const char* invokerName, const char* invokerUniqueIdentity) {
  634. }
  635.  
  636. void ts3plugin_onServerPermissionErrorEvent(uint64 serverConnectionHandlerID, const char* errorMessage, unsigned int error, const char* returnCode, anyID failedPermissionID) {
  637. }
  638.  
  639. void ts3plugin_onPermissionListEvent(uint64 serverConnectionHandlerID, anyID permissionID, const char* permissionName, const char* permissionDescription) {
  640. }
  641.  
  642. void ts3plugin_onPermissionListFinishedEvent(uint64 serverConnectionHandlerID) {
  643. }
  644.  
  645. void ts3plugin_onPermissionOverviewEvent(uint64 serverConnectionHandlerID, uint64 clientDatabaseID, uint64 channelID, int overviewType, uint64 overviewID1, uint64 overviewID2, anyID permissionID, int permissionValue, int permissionNegated, int permissionSkip) {
  646. }
  647.  
  648. void ts3plugin_onPermissionOverviewFinishedEvent(uint64 serverConnectionHandlerID) {
  649. }
  650.  
  651. void ts3plugin_onServerGroupClientAddedEvent(uint64 serverConnectionHandlerID, anyID clientID, const char* clientName, const char* clientUniqueIdentity, uint64 serverGroupID, anyID invokerClientID, const char* invokerName, const char* invokerUniqueIdentity) {
  652. }
  653.  
  654. void ts3plugin_onServerGroupClientDeletedEvent(uint64 serverConnectionHandlerID, anyID clientID, const char* clientName, const char* clientUniqueIdentity, uint64 serverGroupID, anyID invokerClientID, const char* invokerName, const char* invokerUniqueIdentity) {
  655. }
  656.  
  657. void ts3plugin_onClientNeededPermissionsEvent(uint64 serverConnectionHandlerID, anyID permissionID, int permissionValue) {
  658. }
  659.  
  660. void ts3plugin_onClientNeededPermissionsFinishedEvent(uint64 serverConnectionHandlerID) {
  661. }
  662.  
  663. void ts3plugin_onFileTransferStatusEvent(anyID transferID, unsigned int status, const char* statusMessage, uint64 remotefileSize, uint64 serverConnectionHandlerID) {
  664. }
  665.  
  666. void ts3plugin_onClientChatClosedEvent(uint64 serverConnectionHandlerID, anyID clientID) {
  667. }
  668.  
  669. void ts3plugin_onClientChatComposingEvent(uint64 serverConnectionHandlerID, anyID clientID) {
  670. }
  671.  
  672. void ts3plugin_onServerLogEvent(uint64 serverConnectionHandlerID, const char* logTimestamp, const char* logChannel, int logLevel, const char* logMsg) {
  673. }
  674.  
  675. void ts3plugin_onServerLogFinishedEvent(uint64 serverConnectionHandlerID) {
  676. }
  677.  
  678. void ts3plugin_onServerQueryEvent(uint64 serverConnectionHandlerID, const char* result) {
  679. }
  680.  
  681. void ts3plugin_onMessageListEvent(uint64 serverConnectionHandlerID, uint64 messageID, const char* fromClientUniqueIdentity, const char* subject, uint64 timestamp, int flagRead) {
  682. }
  683.  
  684. void ts3plugin_onMessageGetEvent(uint64 serverConnectionHandlerID, uint64 messageID, const char* fromClientUniqueIdentity, const char* subject, const char* message, uint64 timestamp) {
  685. }
  686.  
  687. void ts3plugin_onClientDBIDfromUIDEvent(uint64 serverConnectionHandlerID, const char* uniqueClientIdentifier, uint64 clientDatabaseID) {
  688. }
  689.  
  690. void ts3plugin_onClientNamefromUIDEvent(uint64 serverConnectionHandlerID, const char* uniqueClientIdentifier, uint64 clientDatabaseID, const char* clientNickName) {
  691. }
  692.  
  693. void ts3plugin_onClientNamefromDBIDEvent(uint64 serverConnectionHandlerID, const char* uniqueClientIdentifier, uint64 clientDatabaseID, const char* clientNickName) {
  694. }
  695.  
  696. void ts3plugin_onComplainListEvent(uint64 serverConnectionHandlerID, uint64 targetClientDatabaseID, const char* targetClientNickName, uint64 fromClientDatabaseID, const char* fromClientNickName, const char* complainReason, uint64 timestamp) {
  697. }
  698.  
  699. void ts3plugin_onBanListEvent(uint64 serverConnectionHandlerID, uint64 banid, const char* ip, const char* name, const char* uid, uint64 creationTime, uint64 durationTime, const char* invokerName,
  700.                               uint64 invokercldbid, const char* invokeruid, const char* reason, int numberOfEnforcements) {
  701. }
  702.  
  703. void ts3plugin_onClientServerQueryLoginPasswordEvent(uint64 serverConnectionHandlerID, const char* loginPassword) {
  704. }
  705.  
  706. void ts3plugin_onPluginCommandEvent(uint64 serverConnectionHandlerID, const char* pluginName, const char* pluginCommand) {
  707.     printf("ON PLUGIN COMMAND: %s %s\n", pluginName, pluginCommand);
  708. }
  709.  
  710. void controlWinamp(const char* option){
  711.     HWND hwndWinamp = FindWindow(_T("Winamp v1.x"),NULL); //Finding window
  712.    
  713.     if(strcmp(option, "next") == 0){
  714.         SendMessage(hwndWinamp,WM_COMMAND, 40048, 1); // Next track button 40048
  715.         titleWinamp(); //update the winamp title
  716.     } else if(strcmp(option, "prev") == 0){
  717.         SendMessage(hwndWinamp,WM_COMMAND, 40044, 1); // Next track button 40048
  718.         titleWinamp();
  719.     } else if(strcmp(option, "stop") == 0){
  720.         SendMessage(hwndWinamp,WM_COMMAND, 40047, 1); // Next track button 40048
  721.         titleWinamp();
  722.     } else if(strcmp(option, "play") == 0){
  723.         SendMessage(hwndWinamp,WM_COMMAND, 40045, 1); // Next track button 40048
  724.         titleWinamp();
  725.     }
  726. }
  727.  
  728. const char* titleWinamp(){
  729.     HWND hwndWinamp = FindWindow(_T("Winamp v1.x"),NULL); //Finding window
  730.     //------------------------------------------------
  731.     //THIS IS HOW TO GET THE TITLE OF THE CURRENT SONG
  732.     char this_title[2048],*p;
  733.     //GetWindowText(hwndWinamp,this_title,sizeof(this_title));
  734.     GetWindowTextA(hwndWinamp,this_title,sizeof(this_title));
  735.     p = this_title+strlen(this_title)-8;
  736.     while (p >= this_title)
  737.     {
  738.         if (!_strnicmp(p,"- Winamp",8)) break;
  739.         p--;
  740.     }
  741.     if (p >= this_title) p--;
  742.     while (p >= this_title && *p == ' ') p--;
  743.     *++p=0;
  744.     //THIS IS HOW TO GET THE TITLE OF THE CURRENT SONG
  745.     //------------------------------------------------
  746.  
  747.     //std::cout << this_title; // Prints the current title
  748.     winampTitle = this_title;  //cast to const char*
  749.     //Sleep(3000);
  750.     //Sleep(1000);
  751.     return winampTitle;
  752. }
  753.  
  754. bool starts_with(const std::string& text, const std::string& token)
  755. {
  756.   return token.length()>=text.length()
  757.       && std::equal(text.begin(),text.end(),token.begin());
  758. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement