Advertisement
Guest User

Untitled

a guest
May 31st, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 68.25 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <assert.h>
  6. #include "teamspeak/public_errors.h"
  7. #include "teamspeak/public_errors_rare.h"
  8. #include "teamspeak/public_definitions.h"
  9. #include "teamspeak/public_rare_definitions.h"
  10. #include "teamspeak/clientlib_publicdefinitions.h"
  11. #include "ts3_functions.h"
  12. #include "plugin.h"
  13. #include "sqlite3.h"
  14. #include <chrono>
  15. #include <thread>
  16. #include <atomic>
  17. #include <map>
  18. #include <string>
  19. #include <random>
  20. #include <sstream>
  21. #include <vector>
  22.  
  23. std::map<std::string, uint64> threadlist;
  24. static struct TS3Functions ts3Functions;
  25. const char * botTag = "[b][color=red][HESC][/b] "; //[/color] neni treba jaksi, b to maze asi taky
  26.  
  27. #define _strcpy(dest, destSize, src) { strncpy(dest, src, destSize-1); (dest)[destSize-1] = '\0'; }
  28.  
  29.  
  30. #define PLUGIN_API_VERSION 20
  31.  
  32. #define PATH_BUFSIZE 512
  33. #define COMMAND_BUFSIZE 128
  34. #define INFODATA_BUFSIZE 128
  35. #define SERVERINFO_BUFSIZE 256
  36. #define CHANNELINFO_BUFSIZE 512
  37. #define RETURNCODE_BUFSIZE 128
  38.  
  39. sqlite3 *db;
  40.  
  41. static char* pluginID = NULL;
  42.  
  43.  
  44. std::vector<std::string> split(const char* msg, char delim = ' ')
  45. {
  46. std::string msgstr = msg;
  47. std::vector<std::string> parameters;
  48. std::stringstream ss(msgstr);
  49. std::string item;
  50. while (std::getline(ss, item, delim)) {
  51. if (strcmp(item.c_str(), "") == 0) continue;
  52. parameters.push_back(item);
  53. }
  54. return parameters;
  55. }
  56.  
  57. /*********************************** Required functions ************************************/
  58. /*
  59. * If any of these required functions is not implemented, TS3 will refuse to load the plugin
  60. */
  61.  
  62. /* Unique name identifying this plugin */
  63. const char* ts3plugin_name() {
  64. return "Hemirt's Plugin";
  65. }
  66.  
  67. /* Plugin version */
  68. const char* ts3plugin_version() {
  69. return "1.0";
  70. }
  71.  
  72. /* Plugin API version. Must be the same as the clients API major version, else the plugin fails to load. */
  73. int ts3plugin_apiVersion() {
  74. return PLUGIN_API_VERSION;
  75. }
  76.  
  77. /* Plugin author */
  78. const char* ts3plugin_author() {
  79. /* If you want to use wchar_t, see ts3plugin_name() on how to use */
  80. return "Hemirt";
  81. }
  82.  
  83. /* Plugin description */
  84. const char* ts3plugin_description() {
  85. /* If you want to use wchar_t, see ts3plugin_name() on how to use */
  86. return "Hemirt's everything plugin.";
  87. }
  88.  
  89. /* Set TeamSpeak 3 callback functions */
  90. void ts3plugin_setFunctionPointers(const struct TS3Functions funcs) {
  91. ts3Functions = funcs;
  92. }
  93.  
  94. /*
  95. * Custom code called right after loading the plugin. Returns 0 on success, 1 on failure.
  96. * If the function returns 1 on failure, the plugin will be unloaded again.
  97. */
  98. int ts3plugin_init() {
  99. // char appPath[PATH_BUFSIZE];
  100. // char resourcesPath[PATH_BUFSIZE];
  101. // char configPath[PATH_BUFSIZE];
  102. //char pluginPath[PATH_BUFSIZE];
  103.  
  104. // /* Your plugin init code here */
  105. // printf("PLUGIN: init\n");
  106.  
  107. // /* Example on how to query application, resources and configuration paths from client */
  108. // /* Note: Console client returns empty string for app and resources path */
  109. // ts3Functions.getAppPath(appPath, PATH_BUFSIZE);
  110. // ts3Functions.getResourcesPath(resourcesPath, PATH_BUFSIZE);
  111. // ts3Functions.getConfigPath(configPath, PATH_BUFSIZE);
  112. //ts3Functions.getPluginPath(pluginPath, PATH_BUFSIZE);
  113.  
  114. //printf("PLUGIN: App path: %s\nResources path: %s\nConfig path: %s\nPlugin path: %s\n", appPath, resourcesPath, configPath, pluginPath);
  115. int rc;
  116. rc = sqlite3_open("plugins/hemirt-bot/hemirt-bot.sqlite3", &db);
  117. if (rc) {
  118. fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
  119. sqlite3_close(db);
  120. return 1;
  121. }
  122. char *error;
  123. const char *sqlCreateTable = "CREATE TABLE IF NOT EXISTS Users(id INTEGER PRIMARY KEY ASC, ts3id TEXT UNIQUE, lastname TEXT, points INTEGER);";
  124. rc = sqlite3_exec(db, sqlCreateTable, NULL, NULL, &error);
  125. if (rc)
  126. {
  127. fprintf(stderr, "Error executing SQLite3 statement: %s\n", sqlite3_errmsg(db));
  128. }
  129.  
  130.  
  131. return 0; /* 0 = success, 1 = failure, -2 = failure but client will not show a "failed to load" warning */
  132. /* -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
  133. * the plugin again, avoiding the show another dialog by the client telling the user the plugin failed to load.
  134. * For normal case, if a plugin really failed to load because of an error, the correct return value is 1. */
  135. }
  136.  
  137. /* Custom code called right before the plugin is unloaded */
  138. void ts3plugin_shutdown() {
  139. /* Your plugin cleanup code here */
  140. printf("PLUGIN: shutdown\n");
  141. sqlite3_close(db);
  142. /*
  143. * Note:
  144. * If your plugin implements a settings dialog, it must be closed and deleted here, else the
  145. * TeamSpeak client will most likely crash (DLL removed but dialog from DLL code still open).
  146. */
  147.  
  148. /* Free pluginID if we registered it */
  149.  
  150.  
  151. threadlist.clear();
  152.  
  153. if (pluginID) {
  154. free(pluginID);
  155. pluginID = NULL;
  156. }
  157. }
  158.  
  159. /****************************** Optional functions ********************************/
  160. /*
  161. * Following functions are optional, if not needed you don't need to implement them.
  162. */
  163.  
  164. /* 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). */
  165. int ts3plugin_offersConfigure() {
  166. //printf("PLUGIN: offersConfigure\n");
  167. /*
  168. * Return values:
  169. * PLUGIN_OFFERS_NO_CONFIGURE - Plugin does not implement ts3plugin_configure
  170. * PLUGIN_OFFERS_CONFIGURE_NEW_THREAD - Plugin does implement ts3plugin_configure and requests to run this function in an own thread
  171. * PLUGIN_OFFERS_CONFIGURE_QT_THREAD - Plugin does implement ts3plugin_configure and requests to run this function in the Qt GUI thread
  172. */
  173. return PLUGIN_OFFERS_NO_CONFIGURE; /* In this case ts3plugin_configure does not need to be implemented */
  174. }
  175.  
  176. /* Plugin might offer a configuration window. If ts3plugin_offersConfigure returns 0, this function does not need to be implemented. */
  177. //void ts3plugin_configure(void* handle, void* qParentWidget) {
  178. //printf("PLUGIN: configure\n");
  179. //}
  180.  
  181. /*
  182. * If the plugin wants to use error return codes, plugin commands, hotkeys or menu items, it needs to register a command ID. This function will be
  183. * automatically called after the plugin was initialized. This function is optional. If you don't use these features, this function can be omitted.
  184. * Note the passed pluginID parameter is no longer valid after calling this function, so you must copy it and store it in the plugin.
  185. */
  186. void ts3plugin_registerPluginID(const char* id) {
  187. const size_t sz = strlen(id) + 1;
  188. pluginID = (char*)malloc(sz * sizeof(char));
  189. _strcpy(pluginID, sz, id); /* The id buffer will invalidate after exiting this function */
  190. printf("PLUGIN: registerPluginID: %s\n", pluginID);
  191. }
  192.  
  193. /* Plugin command keyword. Return NULL or "" if not used. */
  194. const char* ts3plugin_commandKeyword() {
  195. return "Hemirt";
  196. }
  197.  
  198. /* Plugin processes console command. Return 0 if plugin handled the command, 1 if not handled. */
  199. //int ts3plugin_processCommand(uint64 serverConnectionHandlerID, const char* command) {
  200. // char buf[COMMAND_BUFSIZE];
  201. // char *s, *param1 = NULL, *param2 = NULL;
  202. // int i = 0;
  203. // enum { CMD_NONE = 0, CMD_JOIN, CMD_COMMAND, CMD_SERVERINFO, CMD_CHANNELINFO, CMD_AVATAR, CMD_ENABLEMENU, CMD_SUBSCRIBE, CMD_UNSUBSCRIBE, CMD_SUBSCRIBEALL, CMD_UNSUBSCRIBEALL } cmd = CMD_NONE;
  204. //#ifdef _WIN32
  205. // char* context = NULL;
  206. //#endif
  207. //
  208. // printf("PLUGIN: process command: '%s'\n", command);
  209. //
  210. // _strcpy(buf, COMMAND_BUFSIZE, command);
  211. //#ifdef _WIN32
  212. // s = strtok_s(buf, " ", &context);
  213. //#else
  214. // s = strtok(buf, " ");
  215. //#endif
  216. // while(s != NULL) {
  217. // if(i == 0) {
  218. // if(!strcmp(s, "join")) {
  219. // cmd = CMD_JOIN;
  220. // } else if(!strcmp(s, "command")) {
  221. // cmd = CMD_COMMAND;
  222. // } else if(!strcmp(s, "serverinfo")) {
  223. // cmd = CMD_SERVERINFO;
  224. // } else if(!strcmp(s, "channelinfo")) {
  225. // cmd = CMD_CHANNELINFO;
  226. // } else if(!strcmp(s, "avatar")) {
  227. // cmd = CMD_AVATAR;
  228. // } else if(!strcmp(s, "enablemenu")) {
  229. // cmd = CMD_ENABLEMENU;
  230. // } else if(!strcmp(s, "subscribe")) {
  231. // cmd = CMD_SUBSCRIBE;
  232. // } else if(!strcmp(s, "unsubscribe")) {
  233. // cmd = CMD_UNSUBSCRIBE;
  234. // } else if(!strcmp(s, "subscribeall")) {
  235. // cmd = CMD_SUBSCRIBEALL;
  236. // } else if(!strcmp(s, "unsubscribeall")) {
  237. // cmd = CMD_UNSUBSCRIBEALL;
  238. // }
  239. // } else if(i == 1) {
  240. // param1 = s;
  241. // } else {
  242. // param2 = s;
  243. // }
  244. //#ifdef _WIN32
  245. // s = strtok_s(NULL, " ", &context);
  246. //#else
  247. // s = strtok(NULL, " ");
  248. //#endif
  249. // i++;
  250. // }
  251. //
  252. // switch(cmd) {
  253. // case CMD_NONE:
  254. // return 1; /* Command not handled by plugin */
  255. // case CMD_JOIN: /* /test join <channelID> [optionalCannelPassword] */
  256. // if(param1) {
  257. // uint64 channelID = (uint64)atoi(param1);
  258. // char* password = param2 ? param2 : "";
  259. // char returnCode[RETURNCODE_BUFSIZE];
  260. // anyID myID;
  261. //
  262. // /* Get own clientID */
  263. // if(ts3Functions.getClientID(serverConnectionHandlerID, &myID) != ERROR_ok) {
  264. // ts3Functions.logMessage("Error querying client ID", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  265. // break;
  266. // }
  267. //
  268. // /* Create return code for requestClientMove function call. If creation fails, returnCode will be NULL, which can be
  269. // * passed into the client functions meaning no return code is used.
  270. // * Note: To use return codes, the plugin needs to register a plugin ID using ts3plugin_registerPluginID */
  271. // ts3Functions.createReturnCode(pluginID, returnCode, RETURNCODE_BUFSIZE);
  272. //
  273. // /* In a real world plugin, the returnCode should be remembered (e.g. in a dynamic STL vector, if it's a C++ plugin).
  274. // * onServerErrorEvent can then check the received returnCode, compare with the remembered ones and thus identify
  275. // * which function call has triggered the event and react accordingly. */
  276. //
  277. // /* Request joining specified channel using above created return code */
  278. // if(ts3Functions.requestClientMove(serverConnectionHandlerID, myID, channelID, password, returnCode) != ERROR_ok) {
  279. // ts3Functions.logMessage("Error requesting client move", LogLevel_INFO, "Plugin", serverConnectionHandlerID);
  280. // }
  281. // } else {
  282. // ts3Functions.printMessageToCurrentTab("Missing channel ID parameter.");
  283. // }
  284. // break;
  285. // case CMD_COMMAND: /* /test command <command> */
  286. // if(param1) {
  287. // /* Send plugin command to all clients in current channel. In this case targetIds is unused and can be NULL. */
  288. // if(pluginID) {
  289. // /* See ts3plugin_registerPluginID for how to obtain a pluginID */
  290. // printf("PLUGIN: Sending plugin command to current channel: %s\n", param1);
  291. // ts3Functions.sendPluginCommand(serverConnectionHandlerID, pluginID, param1, PluginCommandTarget_CURRENT_CHANNEL, NULL, NULL);
  292. // } else {
  293. // printf("PLUGIN: Failed to send plugin command, was not registered.\n");
  294. // }
  295. // } else {
  296. // ts3Functions.printMessageToCurrentTab("Missing command parameter.");
  297. // }
  298. // break;
  299. // case CMD_SERVERINFO: { /* /test serverinfo */
  300. // /* Query host, port and server password of current server tab.
  301. // * The password parameter can be NULL if the plugin does not want to receive the server password.
  302. // * Note: Server password is only available if the user has actually used it when connecting. If a user has
  303. // * connected with the permission to ignore passwords (b_virtualserver_join_ignore_password) and the password,
  304. // * was not entered, it will not be available.
  305. // * getServerConnectInfo returns 0 on success, 1 on error or if current server tab is disconnected. */
  306. // char host[SERVERINFO_BUFSIZE];
  307. // /*char password[SERVERINFO_BUFSIZE];*/
  308. // char* password = NULL; /* Don't receive server password */
  309. // unsigned short port;
  310. // if(!ts3Functions.getServerConnectInfo(serverConnectionHandlerID, host, &port, password, SERVERINFO_BUFSIZE)) {
  311. // char msg[SERVERINFO_BUFSIZE];
  312. // snprintf(msg, sizeof(msg), "Server Connect Info: %s:%d", host, port);
  313. // ts3Functions.printMessageToCurrentTab(msg);
  314. // } else {
  315. // ts3Functions.printMessageToCurrentTab("No server connect info available.");
  316. // }
  317. // break;
  318. // }
  319. // case CMD_CHANNELINFO: { /* /test channelinfo */
  320. // /* Query channel path and password of current server tab.
  321. // * The password parameter can be NULL if the plugin does not want to receive the channel password.
  322. // * Note: Channel password is only available if the user has actually used it when entering the channel. If a user has
  323. // * entered a channel with the permission to ignore passwords (b_channel_join_ignore_password) and the password,
  324. // * was not entered, it will not be available.
  325. // * getChannelConnectInfo returns 0 on success, 1 on error or if current server tab is disconnected. */
  326. // char path[CHANNELINFO_BUFSIZE];
  327. // /*char password[CHANNELINFO_BUFSIZE];*/
  328. // char* password = NULL; /* Don't receive channel password */
  329. //
  330. // /* Get own clientID and channelID */
  331. // anyID myID;
  332. // uint64 myChannelID;
  333. // if(ts3Functions.getClientID(serverConnectionHandlerID, &myID) != ERROR_ok) {
  334. // ts3Functions.logMessage("Error querying client ID", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  335. // break;
  336. // }
  337. // /* Get own channel ID */
  338. // if(ts3Functions.getChannelOfClient(serverConnectionHandlerID, myID, &myChannelID) != ERROR_ok) {
  339. // ts3Functions.logMessage("Error querying channel ID", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  340. // break;
  341. // }
  342. //
  343. // /* Get channel connect info of own channel */
  344. // if(!ts3Functions.getChannelConnectInfo(serverConnectionHandlerID, myChannelID, path, password, CHANNELINFO_BUFSIZE)) {
  345. // char msg[CHANNELINFO_BUFSIZE];
  346. // snprintf(msg, sizeof(msg), "Channel Connect Info: %s", path);
  347. // ts3Functions.printMessageToCurrentTab(msg);
  348. // } else {
  349. // ts3Functions.printMessageToCurrentTab("No channel connect info available.");
  350. // }
  351. // break;
  352. // }
  353. // case CMD_AVATAR: { /* /test avatar <clientID> */
  354. // char avatarPath[PATH_BUFSIZE];
  355. // anyID clientID = (anyID)atoi(param1);
  356. // unsigned int error;
  357. //
  358. // memset(avatarPath, 0, PATH_BUFSIZE);
  359. // error = ts3Functions.getAvatar(serverConnectionHandlerID, clientID, avatarPath, PATH_BUFSIZE);
  360. // if(error == ERROR_ok) { /* ERROR_ok means the client has an avatar set. */
  361. // if(strlen(avatarPath)) { /* Avatar path contains the full path to the avatar image in the TS3Client cache directory */
  362. // printf("Avatar path: %s\n", avatarPath);
  363. // } else { /* Empty avatar path means the client has an avatar but the image has not yet been cached. The TeamSpeak
  364. // * client will automatically start the download and call onAvatarUpdated when done */
  365. // printf("Avatar not yet downloaded, waiting for onAvatarUpdated...\n");
  366. // }
  367. // } else if(error == ERROR_database_empty_result) { /* Not an error, the client simply has no avatar set */
  368. // printf("Client has no avatar\n");
  369. // } else { /* Other error occured (invalid server connection handler ID, invalid client ID, file io error etc) */
  370. // printf("Error getting avatar: %d\n", error);
  371. // }
  372. // break;
  373. // }
  374. // case CMD_ENABLEMENU: /* /test enablemenu <menuID> <0|1> */
  375. // if(param1) {
  376. // int menuID = atoi(param1);
  377. // int enable = param2 ? atoi(param2) : 0;
  378. // ts3Functions.setPluginMenuEnabled(pluginID, menuID, enable);
  379. // } else {
  380. // ts3Functions.printMessageToCurrentTab("Usage is: /test enablemenu <menuID> <0|1>");
  381. // }
  382. // break;
  383. // case CMD_SUBSCRIBE: /* /test subscribe <channelID> */
  384. // if(param1) {
  385. // char returnCode[RETURNCODE_BUFSIZE];
  386. // uint64 channelIDArray[2];
  387. // channelIDArray[0] = (uint64)atoi(param1);
  388. // channelIDArray[1] = 0;
  389. // ts3Functions.createReturnCode(pluginID, returnCode, RETURNCODE_BUFSIZE);
  390. // if(ts3Functions.requestChannelSubscribe(serverConnectionHandlerID, channelIDArray, returnCode) != ERROR_ok) {
  391. // ts3Functions.logMessage("Error subscribing channel", LogLevel_INFO, "Plugin", serverConnectionHandlerID);
  392. // }
  393. // }
  394. // break;
  395. // case CMD_UNSUBSCRIBE: /* /test unsubscribe <channelID> */
  396. // if(param1) {
  397. // char returnCode[RETURNCODE_BUFSIZE];
  398. // uint64 channelIDArray[2];
  399. // channelIDArray[0] = (uint64)atoi(param1);
  400. // channelIDArray[1] = 0;
  401. // ts3Functions.createReturnCode(pluginID, returnCode, RETURNCODE_BUFSIZE);
  402. // if(ts3Functions.requestChannelUnsubscribe(serverConnectionHandlerID, channelIDArray, NULL) != ERROR_ok) {
  403. // ts3Functions.logMessage("Error unsubscribing channel", LogLevel_INFO, "Plugin", serverConnectionHandlerID);
  404. // }
  405. // }
  406. // break;
  407. // case CMD_SUBSCRIBEALL: { /* /test subscribeall */
  408. // char returnCode[RETURNCODE_BUFSIZE];
  409. // ts3Functions.createReturnCode(pluginID, returnCode, RETURNCODE_BUFSIZE);
  410. // if(ts3Functions.requestChannelSubscribeAll(serverConnectionHandlerID, returnCode) != ERROR_ok) {
  411. // ts3Functions.logMessage("Error subscribing channel", LogLevel_INFO, "Plugin", serverConnectionHandlerID);
  412. // }
  413. // break;
  414. // }
  415. // case CMD_UNSUBSCRIBEALL: { /* /test unsubscribeall */
  416. // char returnCode[RETURNCODE_BUFSIZE];
  417. // ts3Functions.createReturnCode(pluginID, returnCode, RETURNCODE_BUFSIZE);
  418. // if(ts3Functions.requestChannelUnsubscribeAll(serverConnectionHandlerID, returnCode) != ERROR_ok) {
  419. // ts3Functions.logMessage("Error subscribing channel", LogLevel_INFO, "Plugin", serverConnectionHandlerID);
  420. // }
  421. // break;
  422. // }
  423. // }
  424. //
  425. // return 0; /* Plugin handled command */
  426. //}
  427.  
  428. /* Client changed current server connection handler */
  429. //void ts3plugin_currentServerConnectionChanged(uint64 serverConnectionHandlerID) {
  430. // printf("PLUGIN: currentServerConnectionChanged %llu (%llu)\n", (long long unsigned int)serverConnectionHandlerID, (long long unsigned int)ts3Functions.getCurrentServerConnectionHandlerID());
  431. //}
  432.  
  433. /*
  434. * Implement the following three functions when the plugin should display a line in the server/channel/client info.
  435. * If any of ts3plugin_infoTitle, ts3plugin_infoData or ts3plugin_freeMemory is missing, the info text will not be displayed.
  436. */
  437.  
  438. /* Static title shown in the left column in the info frame */
  439. //const char* ts3plugin_infoTitle() {
  440. // return "Test plugin info";
  441. //}
  442.  
  443. /*
  444. * Dynamic content shown in the right column in the info frame. Memory for the data string needs to be allocated in this
  445. * function. The client will call ts3plugin_freeMemory once done with the string to release the allocated memory again.
  446. * Check the parameter "type" if you want to implement this feature only for specific item types. Set the parameter
  447. * "data" to NULL to have the client ignore the info data.
  448. */
  449. //void ts3plugin_infoData(uint64 serverConnectionHandlerID, uint64 id, enum PluginItemType type, char** data) {
  450. // char* name;
  451. //
  452. // /* For demonstration purpose, display the name of the currently selected server, channel or client. */
  453. // switch(type) {
  454. // case PLUGIN_SERVER:
  455. // if(ts3Functions.getServerVariableAsString(serverConnectionHandlerID, VIRTUALSERVER_NAME, &name) != ERROR_ok) {
  456. // printf("Error getting virtual server name\n");
  457. // return;
  458. // }
  459. // break;
  460. // case PLUGIN_CHANNEL:
  461. // if(ts3Functions.getChannelVariableAsString(serverConnectionHandlerID, id, CHANNEL_NAME, &name) != ERROR_ok) {
  462. // printf("Error getting channel name\n");
  463. // return;
  464. // }
  465. // break;
  466. // case PLUGIN_CLIENT:
  467. // if(ts3Functions.getClientVariableAsString(serverConnectionHandlerID, (anyID)id, CLIENT_NICKNAME, &name) != ERROR_ok) {
  468. // printf("Error getting client nickname\n");
  469. // return;
  470. // }
  471. // break;
  472. // default:
  473. // printf("Invalid item type: %d\n", type);
  474. // data = NULL; /* Ignore */
  475. // return;
  476. // }
  477. //
  478. // *data = (char*)malloc(INFODATA_BUFSIZE * sizeof(char)); /* Must be allocated in the plugin! */
  479. // snprintf(*data, INFODATA_BUFSIZE, "The nickname is [I]\"%s\"[/I]", name); /* bbCode is supported. HTML is not supported */
  480. // ts3Functions.freeMemory(name);
  481. //}
  482.  
  483. /* Required to release the memory for parameter "data" allocated in ts3plugin_infoData and ts3plugin_initMenus */
  484. void ts3plugin_freeMemory(void* data) {
  485. free(data);
  486. }
  487.  
  488. /*
  489. * Plugin requests to be always automatically loaded by the TeamSpeak 3 client unless
  490. * the user manually disabled it in the plugin dialog.
  491. * This function is optional. If missing, no autoload is assumed.
  492. */
  493. int ts3plugin_requestAutoload() {
  494. return 1; /* 1 = request autoloaded, 0 = do not request autoload */
  495. }
  496.  
  497. /* Helper function to create a menu item */
  498. //static struct PluginMenuItem* createMenuItem(enum PluginMenuType type, int id, const char* text, const char* icon) {
  499. // struct PluginMenuItem* menuItem = (struct PluginMenuItem*)malloc(sizeof(struct PluginMenuItem));
  500. // menuItem->type = type;
  501. // menuItem->id = id;
  502. // _strcpy(menuItem->text, PLUGIN_MENU_BUFSZ, text);
  503. // _strcpy(menuItem->icon, PLUGIN_MENU_BUFSZ, icon);
  504. // return menuItem;
  505. //}
  506. //
  507. ///* Some makros to make the code to create menu items a bit more readable */
  508. //#define BEGIN_CREATE_MENUS(x) const size_t sz = x + 1; size_t n = 0; *menuItems = (struct PluginMenuItem**)malloc(sizeof(struct PluginMenuItem*) * sz);
  509. //#define CREATE_MENU_ITEM(a, b, c, d) (*menuItems)[n++] = createMenuItem(a, b, c, d);
  510. //#define END_CREATE_MENUS (*menuItems)[n++] = NULL; assert(n == sz);
  511. //
  512. ///*
  513. // * Menu IDs for this plugin. Pass these IDs when creating a menuitem to the TS3 client. When the menu item is triggered,
  514. // * ts3plugin_onMenuItemEvent will be called passing the menu ID of the triggered menu item.
  515. // * These IDs are freely choosable by the plugin author. It's not really needed to use an enum, it just looks prettier.
  516. // */
  517. //enum {
  518. // MENU_ID_CLIENT_1 = 1,
  519. // MENU_ID_CLIENT_2,
  520. // MENU_ID_CHANNEL_1,
  521. // MENU_ID_CHANNEL_2,
  522. // MENU_ID_CHANNEL_3,
  523. // MENU_ID_GLOBAL_1,
  524. // MENU_ID_GLOBAL_2
  525. //};
  526. //
  527. ///*
  528. // * Initialize plugin menus.
  529. // * This function is called after ts3plugin_init and ts3plugin_registerPluginID. A pluginID is required for plugin menus to work.
  530. // * Both ts3plugin_registerPluginID and ts3plugin_freeMemory must be implemented to use menus.
  531. // * If plugin menus are not used by a plugin, do not implement this function or return NULL.
  532. // */
  533. //void ts3plugin_initMenus(struct PluginMenuItem*** menuItems, char** menuIcon) {
  534. // /*
  535. // * Create the menus
  536. // * There are three types of menu items:
  537. // * - PLUGIN_MENU_TYPE_CLIENT: Client context menu
  538. // * - PLUGIN_MENU_TYPE_CHANNEL: Channel context menu
  539. // * - PLUGIN_MENU_TYPE_GLOBAL: "Plugins" menu in menu bar of main window
  540. // *
  541. // * Menu IDs are used to identify the menu item when ts3plugin_onMenuItemEvent is called
  542. // *
  543. // * The menu text is required, max length is 128 characters
  544. // *
  545. // * The icon is optional, max length is 128 characters. When not using icons, just pass an empty string.
  546. // * Icons are loaded from a subdirectory in the TeamSpeak client plugins folder. The subdirectory must be named like the
  547. // * plugin filename, without dll/so/dylib suffix
  548. // * e.g. for "test_plugin.dll", icon "1.png" is loaded from <TeamSpeak 3 Client install dir>\plugins\test_plugin\1.png
  549. // */
  550. //
  551. // BEGIN_CREATE_MENUS(7); /* IMPORTANT: Number of menu items must be correct! */
  552. // CREATE_MENU_ITEM(PLUGIN_MENU_TYPE_CLIENT, MENU_ID_CLIENT_1, "Client item 1", "1.png");
  553. // CREATE_MENU_ITEM(PLUGIN_MENU_TYPE_CLIENT, MENU_ID_CLIENT_2, "Client item 2", "2.png");
  554. // CREATE_MENU_ITEM(PLUGIN_MENU_TYPE_CHANNEL, MENU_ID_CHANNEL_1, "Channel item 1", "1.png");
  555. // CREATE_MENU_ITEM(PLUGIN_MENU_TYPE_CHANNEL, MENU_ID_CHANNEL_2, "Channel item 2", "2.png");
  556. // CREATE_MENU_ITEM(PLUGIN_MENU_TYPE_CHANNEL, MENU_ID_CHANNEL_3, "Channel item 3", "3.png");
  557. // CREATE_MENU_ITEM(PLUGIN_MENU_TYPE_GLOBAL, MENU_ID_GLOBAL_1, "Global item 1", "1.png");
  558. // CREATE_MENU_ITEM(PLUGIN_MENU_TYPE_GLOBAL, MENU_ID_GLOBAL_2, "Global item 2", "2.png");
  559. // END_CREATE_MENUS; /* Includes an assert checking if the number of menu items matched */
  560. //
  561. // /*
  562. // * Specify an optional icon for the plugin. This icon is used for the plugins submenu within context and main menus
  563. // * If unused, set menuIcon to NULL
  564. // */
  565. // *menuIcon = (char*)malloc(PLUGIN_MENU_BUFSZ * sizeof(char));
  566. // _strcpy(*menuIcon, PLUGIN_MENU_BUFSZ, "t.png");
  567. //
  568. // /*
  569. // * Menus can be enabled or disabled with: ts3Functions.setPluginMenuEnabled(pluginID, menuID, 0|1);
  570. // * Test it with plugin command: /test enablemenu <menuID> <0|1>
  571. // * Menus are enabled by default. Please note that shown menus will not automatically enable or disable when calling this function to
  572. // * ensure Qt menus are not modified by any thread other the UI thread. The enabled or disable state will change the next time a
  573. // * menu is displayed.
  574. // */
  575. // /* For example, this would disable MENU_ID_GLOBAL_2: */
  576. // /* ts3Functions.setPluginMenuEnabled(pluginID, MENU_ID_GLOBAL_2, 0); */
  577. //
  578. // /* All memory allocated in this function will be automatically released by the TeamSpeak client later by calling ts3plugin_freeMemory */
  579. //}
  580. //
  581. ///* Helper function to create a hotkey */
  582. //static struct PluginHotkey* createHotkey(const char* keyword, const char* description) {
  583. // struct PluginHotkey* hotkey = (struct PluginHotkey*)malloc(sizeof(struct PluginHotkey));
  584. // _strcpy(hotkey->keyword, PLUGIN_HOTKEY_BUFSZ, keyword);
  585. // _strcpy(hotkey->description, PLUGIN_HOTKEY_BUFSZ, description);
  586. // return hotkey;
  587. //}
  588. //
  589. ///* Some makros to make the code to create hotkeys a bit more readable */
  590. //#define BEGIN_CREATE_HOTKEYS(x) const size_t sz = x + 1; size_t n = 0; *hotkeys = (struct PluginHotkey**)malloc(sizeof(struct PluginHotkey*) * sz);
  591. //#define CREATE_HOTKEY(a, b) (*hotkeys)[n++] = createHotkey(a, b);
  592. //#define END_CREATE_HOTKEYS (*hotkeys)[n++] = NULL; assert(n == sz);
  593. //
  594. ///*
  595. // * Initialize plugin hotkeys. If your plugin does not use this feature, this function can be omitted.
  596. // * Hotkeys require ts3plugin_registerPluginID and ts3plugin_freeMemory to be implemented.
  597. // * This function is automatically called by the client after ts3plugin_init.
  598. // */
  599. //void ts3plugin_initHotkeys(struct PluginHotkey*** hotkeys) {
  600. // /* Register hotkeys giving a keyword and a description.
  601. // * The keyword will be later passed to ts3plugin_onHotkeyEvent to identify which hotkey was triggered.
  602. // * The description is shown in the clients hotkey dialog. */
  603. // BEGIN_CREATE_HOTKEYS(3); /* Create 3 hotkeys. Size must be correct for allocating memory. */
  604. // CREATE_HOTKEY("keyword_1", "Test hotkey 1");
  605. // CREATE_HOTKEY("keyword_2", "Test hotkey 2");
  606. // CREATE_HOTKEY("keyword_3", "Test hotkey 3");
  607. // END_CREATE_HOTKEYS;
  608. //
  609. // /* The client will call ts3plugin_freeMemory to release all allocated memory */
  610. //}
  611.  
  612. /************************** TeamSpeak callbacks ***************************/
  613. /*
  614. * Following functions are optional, feel free to remove unused callbacks.
  615. * See the clientlib documentation for details on each function.
  616. */
  617.  
  618. /* Clientlib */
  619.  
  620. //void ts3plugin_onConnectStatusChangeEvent(uint64 serverConnectionHandlerID, int newStatus, unsigned int errorNumber) {
  621. // /* Some example code following to show how to use the information query functions. */
  622. //
  623. // if(newStatus == STATUS_CONNECTION_ESTABLISHED) { /* connection established and we have client and channels available */
  624. // char* s;
  625. // char msg[1024];
  626. // anyID myID;
  627. // uint64* ids;
  628. // size_t i;
  629. // unsigned int error;
  630. //
  631. // /* Print clientlib version */
  632. // if(ts3Functions.getClientLibVersion(&s) == ERROR_ok) {
  633. // printf("PLUGIN: Client lib version: %s\n", s);
  634. // ts3Functions.freeMemory(s); /* Release string */
  635. // } else {
  636. // ts3Functions.logMessage("Error querying client lib version", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  637. // return;
  638. // }
  639. //
  640. // /* Write plugin name and version to log */
  641. // snprintf(msg, sizeof(msg), "Plugin %s, Version %s, Author: %s", ts3plugin_name(), ts3plugin_version(), ts3plugin_author());
  642. // ts3Functions.logMessage(msg, LogLevel_INFO, "Plugin", serverConnectionHandlerID);
  643. //
  644. // /* Print virtual server name */
  645. // if((error = ts3Functions.getServerVariableAsString(serverConnectionHandlerID, VIRTUALSERVER_NAME, &s)) != ERROR_ok) {
  646. // if(error != ERROR_not_connected) { /* Don't spam error in this case (failed to connect) */
  647. // ts3Functions.logMessage("Error querying server name", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  648. // }
  649. // return;
  650. // }
  651. // printf("PLUGIN: Server name: %s\n", s);
  652. // ts3Functions.freeMemory(s);
  653. //
  654. // /* Print virtual server welcome message */
  655. // if(ts3Functions.getServerVariableAsString(serverConnectionHandlerID, VIRTUALSERVER_WELCOMEMESSAGE, &s) != ERROR_ok) {
  656. // ts3Functions.logMessage("Error querying server welcome message", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  657. // return;
  658. // }
  659. // printf("PLUGIN: Server welcome message: %s\n", s);
  660. // ts3Functions.freeMemory(s); /* Release string */
  661. //
  662. // /* Print own client ID and nickname on this server */
  663. // if(ts3Functions.getClientID(serverConnectionHandlerID, &myID) != ERROR_ok) {
  664. // ts3Functions.logMessage("Error querying client ID", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  665. // return;
  666. // }
  667. // if(ts3Functions.getClientSelfVariableAsString(serverConnectionHandlerID, CLIENT_NICKNAME, &s) != ERROR_ok) {
  668. // ts3Functions.logMessage("Error querying client nickname", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  669. // return;
  670. // }
  671. // printf("PLUGIN: My client ID = %d, nickname = %s\n", myID, s);
  672. // ts3Functions.freeMemory(s);
  673. //
  674. // /* Print list of all channels on this server */
  675. // if(ts3Functions.getChannelList(serverConnectionHandlerID, &ids) != ERROR_ok) {
  676. // ts3Functions.logMessage("Error getting channel list", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  677. // return;
  678. // }
  679. // printf("PLUGIN: Available channels:\n");
  680. // for(i=0; ids[i]; i++) {
  681. // /* Query channel name */
  682. // if(ts3Functions.getChannelVariableAsString(serverConnectionHandlerID, ids[i], CHANNEL_NAME, &s) != ERROR_ok) {
  683. // ts3Functions.logMessage("Error querying channel name", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  684. // return;
  685. // }
  686. // printf("PLUGIN: Channel ID = %llu, name = %s\n", (long long unsigned int)ids[i], s);
  687. // ts3Functions.freeMemory(s);
  688. // }
  689. // ts3Functions.freeMemory(ids); /* Release array */
  690. //
  691. // /* Print list of existing server connection handlers */
  692. // printf("PLUGIN: Existing server connection handlers:\n");
  693. // if(ts3Functions.getServerConnectionHandlerList(&ids) != ERROR_ok) {
  694. // ts3Functions.logMessage("Error getting server list", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  695. // return;
  696. // }
  697. // for(i=0; ids[i]; i++) {
  698. // if((error = ts3Functions.getServerVariableAsString(ids[i], VIRTUALSERVER_NAME, &s)) != ERROR_ok) {
  699. // if(error != ERROR_not_connected) { /* Don't spam error in this case (failed to connect) */
  700. // ts3Functions.logMessage("Error querying server name", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  701. // }
  702. // continue;
  703. // }
  704. // printf("- %llu - %s\n", (long long unsigned int)ids[i], s);
  705. // ts3Functions.freeMemory(s);
  706. // }
  707. // ts3Functions.freeMemory(ids);
  708. // }
  709. //}
  710. //
  711. //void ts3plugin_onNewChannelEvent(uint64 serverConnectionHandlerID, uint64 channelID, uint64 channelParentID) {
  712. //}
  713. //
  714. //void ts3plugin_onNewChannelCreatedEvent(uint64 serverConnectionHandlerID, uint64 channelID, uint64 channelParentID, anyID invokerID, const char* invokerName, const char* invokerUniqueIdentifier) {
  715. //}
  716. //
  717. //void ts3plugin_onDelChannelEvent(uint64 serverConnectionHandlerID, uint64 channelID, anyID invokerID, const char* invokerName, const char* invokerUniqueIdentifier) {
  718. //}
  719. //
  720. //void ts3plugin_onChannelMoveEvent(uint64 serverConnectionHandlerID, uint64 channelID, uint64 newChannelParentID, anyID invokerID, const char* invokerName, const char* invokerUniqueIdentifier) {
  721. //}
  722. //
  723. //void ts3plugin_onUpdateChannelEvent(uint64 serverConnectionHandlerID, uint64 channelID) {
  724. //}
  725. //
  726. //void ts3plugin_onUpdateChannelEditedEvent(uint64 serverConnectionHandlerID, uint64 channelID, anyID invokerID, const char* invokerName, const char* invokerUniqueIdentifier) {
  727. //}
  728. //
  729. //void ts3plugin_onUpdateClientEvent(uint64 serverConnectionHandlerID, anyID clientID, anyID invokerID, const char* invokerName, const char* invokerUniqueIdentifier) {
  730. //}
  731. //
  732. //void ts3plugin_onClientMoveEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility, const char* moveMessage) {
  733. //}
  734. //
  735. //void ts3plugin_onClientMoveSubscriptionEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility) {
  736. //}
  737. //
  738. //void ts3plugin_onClientMoveTimeoutEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility, const char* timeoutMessage) {
  739. //}
  740. //
  741. //void ts3plugin_onClientMoveMovedEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility, anyID moverID, const char* moverName, const char* moverUniqueIdentifier, const char* moveMessage) {
  742. //}
  743. //
  744. //void ts3plugin_onClientKickFromChannelEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility, anyID kickerID, const char* kickerName, const char* kickerUniqueIdentifier, const char* kickMessage) {
  745. //}
  746. //
  747. //void ts3plugin_onClientKickFromServerEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility, anyID kickerID, const char* kickerName, const char* kickerUniqueIdentifier, const char* kickMessage) {
  748. //}
  749. //
  750. //void ts3plugin_onClientIDsEvent(uint64 serverConnectionHandlerID, const char* uniqueClientIdentifier, anyID clientID, const char* clientName) {
  751. //}
  752. //
  753. //void ts3plugin_onClientIDsFinishedEvent(uint64 serverConnectionHandlerID) {
  754. //}
  755. //
  756. //void ts3plugin_onServerEditedEvent(uint64 serverConnectionHandlerID, anyID editerID, const char* editerName, const char* editerUniqueIdentifier) {
  757. //}
  758. //
  759. //void ts3plugin_onServerUpdatedEvent(uint64 serverConnectionHandlerID) {
  760. //}
  761. //
  762. //int ts3plugin_onServerErrorEvent(uint64 serverConnectionHandlerID, const char* errorMessage, unsigned int error, const char* returnCode, const char* extraMessage) {
  763. // printf("PLUGIN: onServerErrorEvent %llu %s %d %s\n", (long long unsigned int)serverConnectionHandlerID, errorMessage, error, (returnCode ? returnCode : ""));
  764. // if(returnCode) {
  765. // /* A plugin could now check the returnCode with previously (when calling a function) remembered returnCodes and react accordingly */
  766. // /* In case of using a a plugin return code, the plugin can return:
  767. // * 0: Client will continue handling this error (print to chat tab)
  768. // * 1: Client will ignore this error, the plugin announces it has handled it */
  769. // return 1;
  770. // }
  771. // return 0; /* If no plugin return code was used, the return value of this function is ignored */
  772. //}
  773. //
  774. //void ts3plugin_onServerStopEvent(uint64 serverConnectionHandlerID, const char* shutdownMessage) {
  775. ////}
  776. //
  777. //int ts3plugin_onTextMessageEvent(uint64 serverConnectionHandlerID, anyID targetMode, anyID toID, anyID fromID, const char* fromName, const char* fromUniqueIdentifier, const char* message, int ffIgnored) {
  778. // printf("PLUGIN: onTextMessageEvent %llu %d %d %s %s %d\n", (long long unsigned int)serverConnectionHandlerID, targetMode, fromID, fromName, message, ffIgnored);
  779. //
  780. // /* Friend/Foe manager has ignored the message, so ignore here as well. */
  781. // if(ffIgnored) {
  782. // return 0; /* Client will ignore the message anyways, so return value here doesn't matter */
  783. // }
  784. //
  785. //#if 0
  786. // {
  787. // /* Example code: Autoreply to sender */
  788. // /* Disabled because quite annoying, but should give you some ideas what is possible here */
  789. // /* Careful, when two clients use this, they will get banned quickly... */
  790. // anyID myID;
  791. // if(ts3Functions.getClientID(serverConnectionHandlerID, &myID) != ERROR_ok) {
  792. // ts3Functions.logMessage("Error querying own client id", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  793. // return 0;
  794. // }
  795. // if(fromID != myID) { /* Don't reply when source is own client */
  796. // if(ts3Functions.requestSendPrivateTextMsg(serverConnectionHandlerID, "Text message back!", fromID, NULL) != ERROR_ok) {
  797. // ts3Functions.logMessage("Error requesting send text message", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  798. // }
  799. // }
  800. // }
  801. //#endif
  802. //
  803. // return 0; /* 0 = handle normally, 1 = client will ignore the text message */
  804. //}
  805.  
  806. //void ts3plugin_onTalkStatusChangeEvent(uint64 serverConnectionHandlerID, int status, int isReceivedWhisper, anyID clientID) {
  807. // /* Demonstrate usage of getClientDisplayName */
  808. // char name[512];
  809. // if(ts3Functions.getClientDisplayName(serverConnectionHandlerID, clientID, name, 512) == ERROR_ok) {
  810. // if(status == STATUS_TALKING) {
  811. // printf("--> %s starts talking\n", name);
  812. // } else {
  813. // printf("--> %s stops talking\n", name);
  814. // }
  815. // }
  816. //}
  817. //
  818. //void ts3plugin_onConnectionInfoEvent(uint64 serverConnectionHandlerID, anyID clientID) {
  819. //}
  820. //
  821. //void ts3plugin_onServerConnectionInfoEvent(uint64 serverConnectionHandlerID) {
  822. //}
  823. //
  824. //void ts3plugin_onChannelSubscribeEvent(uint64 serverConnectionHandlerID, uint64 channelID) {
  825. //}
  826. //
  827. //void ts3plugin_onChannelSubscribeFinishedEvent(uint64 serverConnectionHandlerID) {
  828. //}
  829. //
  830. //void ts3plugin_onChannelUnsubscribeEvent(uint64 serverConnectionHandlerID, uint64 channelID) {
  831. //}
  832. //
  833. //void ts3plugin_onChannelUnsubscribeFinishedEvent(uint64 serverConnectionHandlerID) {
  834. //}
  835. //
  836. //void ts3plugin_onChannelDescriptionUpdateEvent(uint64 serverConnectionHandlerID, uint64 channelID) {
  837. //}
  838. //
  839. //void ts3plugin_onChannelPasswordChangedEvent(uint64 serverConnectionHandlerID, uint64 channelID) {
  840. //}
  841. //
  842. //void ts3plugin_onPlaybackShutdownCompleteEvent(uint64 serverConnectionHandlerID) {
  843. //}
  844. //
  845. //void ts3plugin_onSoundDeviceListChangedEvent(const char* modeID, int playOrCap) {
  846. //}
  847. //
  848. //void ts3plugin_onEditPlaybackVoiceDataEvent(uint64 serverConnectionHandlerID, anyID clientID, short* samples, int sampleCount, int channels) {
  849. //}
  850. //
  851. //void ts3plugin_onEditPostProcessVoiceDataEvent(uint64 serverConnectionHandlerID, anyID clientID, short* samples, int sampleCount, int channels, const unsigned int* channelSpeakerArray, unsigned int* channelFillMask) {
  852. //}
  853. //
  854. //void ts3plugin_onEditMixedPlaybackVoiceDataEvent(uint64 serverConnectionHandlerID, short* samples, int sampleCount, int channels, const unsigned int* channelSpeakerArray, unsigned int* channelFillMask) {
  855. //}
  856. //
  857. //void ts3plugin_onEditCapturedVoiceDataEvent(uint64 serverConnectionHandlerID, short* samples, int sampleCount, int channels, int* edited) {
  858. //}
  859. //
  860. //void ts3plugin_onCustom3dRolloffCalculationClientEvent(uint64 serverConnectionHandlerID, anyID clientID, float distance, float* volume) {
  861. //}
  862. //
  863. //void ts3plugin_onCustom3dRolloffCalculationWaveEvent(uint64 serverConnectionHandlerID, uint64 waveHandle, float distance, float* volume) {
  864. //}
  865. //
  866. //void ts3plugin_onUserLoggingMessageEvent(const char* logMessage, int logLevel, const char* logChannel, uint64 logID, const char* logTime, const char* completeLogString) {
  867. //}
  868. //
  869. ///* Clientlib rare */
  870. //
  871. //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) {
  872. //}
  873. //
  874. //int ts3plugin_onClientPokeEvent(uint64 serverConnectionHandlerID, anyID fromClientID, const char* pokerName, const char* pokerUniqueIdentity, const char* message, int ffIgnored) {
  875. // anyID myID;
  876. //
  877. // printf("PLUGIN onClientPokeEvent: %llu %d %s %s %d\n", (long long unsigned int)serverConnectionHandlerID, fromClientID, pokerName, message, ffIgnored);
  878. //
  879. // /* Check if the Friend/Foe manager has already blocked this poke */
  880. // if(ffIgnored) {
  881. // return 0; /* Client will block anyways, doesn't matter what we return */
  882. // }
  883. //
  884. // /* Example code: Send text message back to poking client */
  885. // if(ts3Functions.getClientID(serverConnectionHandlerID, &myID) != ERROR_ok) { /* Get own client ID */
  886. // ts3Functions.logMessage("Error querying own client id", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  887. // return 0;
  888. // }
  889. // if(fromClientID != myID) { /* Don't reply when source is own client */
  890. // if(ts3Functions.requestSendPrivateTextMsg(serverConnectionHandlerID, "Received your poke!", fromClientID, NULL) != ERROR_ok) {
  891. // ts3Functions.logMessage("Error requesting send text message", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  892. // }
  893. // }
  894. //
  895. // return 0; /* 0 = handle normally, 1 = client will ignore the poke */
  896. //}
  897. //
  898. //void ts3plugin_onClientSelfVariableUpdateEvent(uint64 serverConnectionHandlerID, int flag, const char* oldValue, const char* newValue) {
  899. //}
  900. //
  901. //void ts3plugin_onFileListEvent(uint64 serverConnectionHandlerID, uint64 channelID, const char* path, const char* name, uint64 size, uint64 datetime, int type, uint64 incompletesize, const char* returnCode) {
  902. //}
  903. //
  904. //void ts3plugin_onFileListFinishedEvent(uint64 serverConnectionHandlerID, uint64 channelID, const char* path) {
  905. //}
  906. //
  907. //void ts3plugin_onFileInfoEvent(uint64 serverConnectionHandlerID, uint64 channelID, const char* name, uint64 size, uint64 datetime) {
  908. //}
  909. //
  910. //void ts3plugin_onServerGroupListEvent(uint64 serverConnectionHandlerID, uint64 serverGroupID, const char* name, int type, int iconID, int saveDB) {
  911. //}
  912. //
  913. //void ts3plugin_onServerGroupListFinishedEvent(uint64 serverConnectionHandlerID) {
  914. //}
  915. //
  916. //void ts3plugin_onServerGroupByClientIDEvent(uint64 serverConnectionHandlerID, const char* name, uint64 serverGroupList, uint64 clientDatabaseID) {
  917. //}
  918. //
  919. //void ts3plugin_onServerGroupPermListEvent(uint64 serverConnectionHandlerID, uint64 serverGroupID, unsigned int permissionID, int permissionValue, int permissionNegated, int permissionSkip) {
  920. //}
  921. //
  922. //void ts3plugin_onServerGroupPermListFinishedEvent(uint64 serverConnectionHandlerID, uint64 serverGroupID) {
  923. //}
  924. //
  925. //void ts3plugin_onServerGroupClientListEvent(uint64 serverConnectionHandlerID, uint64 serverGroupID, uint64 clientDatabaseID, const char* clientNameIdentifier, const char* clientUniqueID) {
  926. //}
  927. //
  928. //void ts3plugin_onChannelGroupListEvent(uint64 serverConnectionHandlerID, uint64 channelGroupID, const char* name, int type, int iconID, int saveDB) {
  929. //}
  930. //
  931. //void ts3plugin_onChannelGroupListFinishedEvent(uint64 serverConnectionHandlerID) {
  932. //}
  933. //
  934. //void ts3plugin_onChannelGroupPermListEvent(uint64 serverConnectionHandlerID, uint64 channelGroupID, unsigned int permissionID, int permissionValue, int permissionNegated, int permissionSkip) {
  935. //}
  936. //
  937. //void ts3plugin_onChannelGroupPermListFinishedEvent(uint64 serverConnectionHandlerID, uint64 channelGroupID) {
  938. //}
  939. //
  940. //void ts3plugin_onChannelPermListEvent(uint64 serverConnectionHandlerID, uint64 channelID, unsigned int permissionID, int permissionValue, int permissionNegated, int permissionSkip) {
  941. //}
  942. //
  943. //void ts3plugin_onChannelPermListFinishedEvent(uint64 serverConnectionHandlerID, uint64 channelID) {
  944. //}
  945. //
  946. //void ts3plugin_onClientPermListEvent(uint64 serverConnectionHandlerID, uint64 clientDatabaseID, unsigned int permissionID, int permissionValue, int permissionNegated, int permissionSkip) {
  947. //}
  948. //
  949. //void ts3plugin_onClientPermListFinishedEvent(uint64 serverConnectionHandlerID, uint64 clientDatabaseID) {
  950. //}
  951. //
  952. //void ts3plugin_onChannelClientPermListEvent(uint64 serverConnectionHandlerID, uint64 channelID, uint64 clientDatabaseID, unsigned int permissionID, int permissionValue, int permissionNegated, int permissionSkip) {
  953. //}
  954. //
  955. //void ts3plugin_onChannelClientPermListFinishedEvent(uint64 serverConnectionHandlerID, uint64 channelID, uint64 clientDatabaseID) {
  956. //}
  957. //
  958. //void ts3plugin_onClientChannelGroupChangedEvent(uint64 serverConnectionHandlerID, uint64 channelGroupID, uint64 channelID, anyID clientID, anyID invokerClientID, const char* invokerName, const char* invokerUniqueIdentity) {
  959. //}
  960. //
  961. //int ts3plugin_onServerPermissionErrorEvent(uint64 serverConnectionHandlerID, const char* errorMessage, unsigned int error, const char* returnCode, unsigned int failedPermissionID) {
  962. // return 0; /* See onServerErrorEvent for return code description */
  963. //}
  964. //
  965. //void ts3plugin_onPermissionListGroupEndIDEvent(uint64 serverConnectionHandlerID, unsigned int groupEndID) {
  966. //}
  967. //
  968. //void ts3plugin_onPermissionListEvent(uint64 serverConnectionHandlerID, unsigned int permissionID, const char* permissionName, const char* permissionDescription) {
  969. //}
  970. //
  971. //void ts3plugin_onPermissionListFinishedEvent(uint64 serverConnectionHandlerID) {
  972. //}
  973. //
  974. //void ts3plugin_onPermissionOverviewEvent(uint64 serverConnectionHandlerID, uint64 clientDatabaseID, uint64 channelID, int overviewType, uint64 overviewID1, uint64 overviewID2, unsigned int permissionID, int permissionValue, int permissionNegated, int permissionSkip) {
  975. //}
  976. //
  977. //void ts3plugin_onPermissionOverviewFinishedEvent(uint64 serverConnectionHandlerID) {
  978. //}
  979. //
  980. //void ts3plugin_onServerGroupClientAddedEvent(uint64 serverConnectionHandlerID, anyID clientID, const char* clientName, const char* clientUniqueIdentity, uint64 serverGroupID, anyID invokerClientID, const char* invokerName, const char* invokerUniqueIdentity) {
  981. //}
  982. //
  983. //void ts3plugin_onServerGroupClientDeletedEvent(uint64 serverConnectionHandlerID, anyID clientID, const char* clientName, const char* clientUniqueIdentity, uint64 serverGroupID, anyID invokerClientID, const char* invokerName, const char* invokerUniqueIdentity) {
  984. //}
  985. //
  986. //void ts3plugin_onClientNeededPermissionsEvent(uint64 serverConnectionHandlerID, unsigned int permissionID, int permissionValue) {
  987. //}
  988. //
  989. //void ts3plugin_onClientNeededPermissionsFinishedEvent(uint64 serverConnectionHandlerID) {
  990. //}
  991. //
  992. //void ts3plugin_onFileTransferStatusEvent(anyID transferID, unsigned int status, const char* statusMessage, uint64 remotefileSize, uint64 serverConnectionHandlerID) {
  993. //}
  994. //
  995. //void ts3plugin_onClientChatClosedEvent(uint64 serverConnectionHandlerID, anyID clientID, const char* clientUniqueIdentity) {
  996. //}
  997. //
  998. //void ts3plugin_onClientChatComposingEvent(uint64 serverConnectionHandlerID, anyID clientID, const char* clientUniqueIdentity) {
  999. //}
  1000. //
  1001. //void ts3plugin_onServerLogEvent(uint64 serverConnectionHandlerID, const char* logMsg) {
  1002. //}
  1003. //
  1004. //void ts3plugin_onServerLogFinishedEvent(uint64 serverConnectionHandlerID, uint64 lastPos, uint64 fileSize) {
  1005. //}
  1006. //
  1007. //void ts3plugin_onMessageListEvent(uint64 serverConnectionHandlerID, uint64 messageID, const char* fromClientUniqueIdentity, const char* subject, uint64 timestamp, int flagRead) {
  1008. //}
  1009. //
  1010. //void ts3plugin_onMessageGetEvent(uint64 serverConnectionHandlerID, uint64 messageID, const char* fromClientUniqueIdentity, const char* subject, const char* message, uint64 timestamp) {
  1011. //}
  1012. //
  1013. //void ts3plugin_onClientDBIDfromUIDEvent(uint64 serverConnectionHandlerID, const char* uniqueClientIdentifier, uint64 clientDatabaseID) {
  1014. //}
  1015. //
  1016. //void ts3plugin_onClientNamefromUIDEvent(uint64 serverConnectionHandlerID, const char* uniqueClientIdentifier, uint64 clientDatabaseID, const char* clientNickName) {
  1017. //}
  1018. //
  1019. //void ts3plugin_onClientNamefromDBIDEvent(uint64 serverConnectionHandlerID, const char* uniqueClientIdentifier, uint64 clientDatabaseID, const char* clientNickName) {
  1020. //}
  1021. //
  1022. //void ts3plugin_onComplainListEvent(uint64 serverConnectionHandlerID, uint64 targetClientDatabaseID, const char* targetClientNickName, uint64 fromClientDatabaseID, const char* fromClientNickName, const char* complainReason, uint64 timestamp) {
  1023. //}
  1024. //
  1025. //void ts3plugin_onBanListEvent(uint64 serverConnectionHandlerID, uint64 banid, const char* ip, const char* name, const char* uid, uint64 creationTime, uint64 durationTime, const char* invokerName,
  1026. // uint64 invokercldbid, const char* invokeruid, const char* reason, int numberOfEnforcements, const char* lastNickName) {
  1027. //}
  1028. //
  1029. //void ts3plugin_onClientServerQueryLoginPasswordEvent(uint64 serverConnectionHandlerID, const char* loginPassword) {
  1030. //}
  1031. //
  1032. //void ts3plugin_onPluginCommandEvent(uint64 serverConnectionHandlerID, const char* pluginName, const char* pluginCommand) {
  1033. // printf("ON PLUGIN COMMAND: %s %s\n", pluginName, pluginCommand);
  1034. //}
  1035. //
  1036. //void ts3plugin_onIncomingClientQueryEvent(uint64 serverConnectionHandlerID, const char* commandText) {
  1037. //}
  1038. //
  1039. //void ts3plugin_onServerTemporaryPasswordListEvent(uint64 serverConnectionHandlerID, const char* clientNickname, const char* uniqueClientIdentifier, const char* description, const char* password, uint64 timestampStart, uint64 timestampEnd, uint64 targetChannelID, const char* targetChannelPW) {
  1040. //}
  1041. //
  1042. ///* Client UI callbacks */
  1043. //
  1044. ///*
  1045. // * Called from client when an avatar image has been downloaded to or deleted from cache.
  1046. // * This callback can be called spontaneously or in response to ts3Functions.getAvatar()
  1047. // */
  1048. //void ts3plugin_onAvatarUpdated(uint64 serverConnectionHandlerID, anyID clientID, const char* avatarPath) {
  1049. // /* If avatarPath is NULL, the avatar got deleted */
  1050. // /* If not NULL, avatarPath contains the path to the avatar file in the TS3Client cache */
  1051. // if(avatarPath != NULL) {
  1052. // printf("onAvatarUpdated: %llu %d %s\n", (long long unsigned int)serverConnectionHandlerID, clientID, avatarPath);
  1053. // } else {
  1054. // printf("onAvatarUpdated: %llu %d - deleted\n", (long long unsigned int)serverConnectionHandlerID, clientID);
  1055. // }
  1056. //}
  1057. //
  1058. ///*
  1059. // * Called when a plugin menu item (see ts3plugin_initMenus) is triggered. Optional function, when not using plugin menus, do not implement this.
  1060. // *
  1061. // * Parameters:
  1062. // * - serverConnectionHandlerID: ID of the current server tab
  1063. // * - type: Type of the menu (PLUGIN_MENU_TYPE_CHANNEL, PLUGIN_MENU_TYPE_CLIENT or PLUGIN_MENU_TYPE_GLOBAL)
  1064. // * - menuItemID: Id used when creating the menu item
  1065. // * - selectedItemID: Channel or Client ID in the case of PLUGIN_MENU_TYPE_CHANNEL and PLUGIN_MENU_TYPE_CLIENT. 0 for PLUGIN_MENU_TYPE_GLOBAL.
  1066. // */
  1067. //void ts3plugin_onMenuItemEvent(uint64 serverConnectionHandlerID, enum PluginMenuType type, int menuItemID, uint64 selectedItemID) {
  1068. // printf("PLUGIN: onMenuItemEvent: serverConnectionHandlerID=%llu, type=%d, menuItemID=%d, selectedItemID=%llu\n", (long long unsigned int)serverConnectionHandlerID, type, menuItemID, (long long unsigned int)selectedItemID);
  1069. // switch(type) {
  1070. // case PLUGIN_MENU_TYPE_GLOBAL:
  1071. // /* Global menu item was triggered. selectedItemID is unused and set to zero. */
  1072. // switch(menuItemID) {
  1073. // case MENU_ID_GLOBAL_1:
  1074. // /* Menu global 1 was triggered */
  1075. // break;
  1076. // case MENU_ID_GLOBAL_2:
  1077. // /* Menu global 2 was triggered */
  1078. // break;
  1079. // default:
  1080. // break;
  1081. // }
  1082. // break;
  1083. // case PLUGIN_MENU_TYPE_CHANNEL:
  1084. // /* Channel contextmenu item was triggered. selectedItemID is the channelID of the selected channel */
  1085. // switch(menuItemID) {
  1086. // case MENU_ID_CHANNEL_1:
  1087. // /* Menu channel 1 was triggered */
  1088. // break;
  1089. // case MENU_ID_CHANNEL_2:
  1090. // /* Menu channel 2 was triggered */
  1091. // break;
  1092. // case MENU_ID_CHANNEL_3:
  1093. // /* Menu channel 3 was triggered */
  1094. // break;
  1095. // default:
  1096. // break;
  1097. // }
  1098. // break;
  1099. // case PLUGIN_MENU_TYPE_CLIENT:
  1100. // /* Client contextmenu item was triggered. selectedItemID is the clientID of the selected client */
  1101. // switch(menuItemID) {
  1102. // case MENU_ID_CLIENT_1:
  1103. // /* Menu client 1 was triggered */
  1104. // break;
  1105. // case MENU_ID_CLIENT_2:
  1106. // /* Menu client 2 was triggered */
  1107. // break;
  1108. // default:
  1109. // break;
  1110. // }
  1111. // break;
  1112. // default:
  1113. // break;
  1114. // }
  1115. //}
  1116. //
  1117. ///* This function is called if a plugin hotkey was pressed. Omit if hotkeys are unused. */
  1118. //void ts3plugin_onHotkeyEvent(const char* keyword) {
  1119. // printf("PLUGIN: Hotkey event: %s\n", keyword);
  1120. // /* Identify the hotkey by keyword ("keyword_1", "keyword_2" or "keyword_3" in this example) and handle here... */
  1121. //}
  1122. //
  1123. ///* Called when recording a hotkey has finished after calling ts3Functions.requestHotkeyInputDialog */
  1124. //void ts3plugin_onHotkeyRecordedEvent(const char* keyword, const char* key) {
  1125. //}
  1126. //
  1127. ///* Called when client custom nickname changed */
  1128. //void ts3plugin_onClientDisplayNameChanged(uint64 serverConnectionHandlerID, anyID clientID, const char* displayName, const char* uniqueClientIdentifier) {
  1129. //}
  1130. //
  1131. //int ts3plugin_onTextMessageEvent(uint64 serverConnectionHandlerID, anyID targetMode, anyID toID, anyID fromID, const char* fromName, const char* fromUniqueIdentifier, const char* message, int ffIgnored) {
  1132. // printf("PLUGIN: onTextMessageEvent %llu %d %d %s %s %d\n", (long long unsigned int)serverConnectionHandlerID, targetMode, fromID, fromName, message, ffIgnored);
  1133. //
  1134. // /* Friend/Foe manager has ignored the message, so ignore here as well. */
  1135. // if(ffIgnored) {
  1136. // return 0; /* Client will ignore the message anyways, so return value here doesn't matter */
  1137. // }
  1138. //
  1139. //
  1140. //
  1141. //#if 0
  1142. // {
  1143. // /* Example code: Autoreply to sender */
  1144. // /* Disabled because quite annoying, but should give you some ideas what is possible here */
  1145. // /* Careful, when two clients use this, they will get banned quickly... */
  1146. // anyID myID;
  1147. // if(ts3Functions.getClientID(serverConnectionHandlerID, &myID) != ERROR_ok) {
  1148. // ts3Functions.logMessage("Error querying own client id", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  1149. // return 0;
  1150. // }
  1151. // if(fromID != myID) { /* Don't reply when source is own client */
  1152. // if(ts3Functions.requestSendPrivateTextMsg(serverConnectionHandlerID, "Text message back!", fromID, NULL) != ERROR_ok) {
  1153. // ts3Functions.logMessage("Error requesting send text message", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  1154. // }
  1155. // }
  1156. // }
  1157. //#endif
  1158. //
  1159. // return 0; /* 0 = handle normally, 1 = client will ignore the text message */
  1160. //}
  1161.  
  1162.  
  1163. void addPoints(uint64 serverConnectionHandlerID)
  1164. {
  1165.  
  1166.  
  1167. anyID* ids;
  1168. size_t i;
  1169.  
  1170. /* Print list of all clients on this server */
  1171. if (ts3Functions.getClientList(serverConnectionHandlerID, &ids) != ERROR_ok) {
  1172. return;
  1173. }
  1174.  
  1175. std::map<char *, char *> unikidsnames;
  1176.  
  1177. for (i = 0; ids[i]; i++) {
  1178.  
  1179. char* unikveid;
  1180. char* uzernejm;
  1181. unsigned int error;
  1182. error = ts3Functions.getClientVariableAsString(serverConnectionHandlerID, ids[i], CLIENT_UNIQUE_IDENTIFIER, &unikveid);
  1183. if (error != ERROR_ok) continue;
  1184. error = ts3Functions.getClientVariableAsString(serverConnectionHandlerID, ids[i], CLIENT_NICKNAME, &uzernejm);
  1185. if (error != ERROR_ok) continue;
  1186.  
  1187. std::pair<std::map<char *, char *>::iterator, bool> deg = unikidsnames.insert(std::pair<char *, char *>(unikveid, uzernejm));
  1188.  
  1189. if (deg.second == true)
  1190. {
  1191. sqlite3_stmt * statement;
  1192. sqlite3_prepare_v2(db, "INSERT OR IGNORE INTO Users('ts3id', 'lastname', 'points') VALUES(?, ?, 0);", -1, &statement, NULL);
  1193. sqlite3_bind_text(statement, 1, unikveid, -1, 0);
  1194. sqlite3_bind_text(statement, 2, uzernejm, -1, 0);
  1195. sqlite3_step(statement);
  1196. sqlite3_finalize(statement);
  1197.  
  1198. sqlite3_prepare_v2(db, "UPDATE Users SET points = points + 15, lastname = ? WHERE ts3id = ?;", -1, &statement, NULL);
  1199. sqlite3_bind_text(statement, 1, uzernejm, -1, 0);
  1200. sqlite3_bind_text(statement, 2, unikveid, -1, 0);
  1201. sqlite3_step(statement);
  1202. sqlite3_finalize(statement);
  1203. }
  1204.  
  1205. ts3Functions.freeMemory(unikveid);
  1206. ts3Functions.freeMemory(uzernejm);
  1207.  
  1208. }
  1209. ts3Functions.freeMemory(ids); /* Release array */
  1210. }
  1211.  
  1212.  
  1213. void pointsMinute(char* result, uint64 serverConnectionHandlerID)
  1214. {
  1215. while (threadlist.find(result) != threadlist.end())
  1216. {
  1217. char* resultc;
  1218. unsigned int error;
  1219. //printf("wut\n");
  1220. error = ts3Functions.getServerVariableAsString(serverConnectionHandlerID, VIRTUALSERVER_UNIQUE_IDENTIFIER, &resultc);
  1221. if (strcmp(resultc, result) != 0 || error != ERROR_ok)
  1222. {
  1223. if (error == ERROR_ok) ts3Functions.freeMemory(resultc);
  1224.  
  1225.  
  1226. std::map<std::string, uint64>::iterator it;
  1227. it = threadlist.find(result);
  1228. threadlist.erase(it);
  1229. //printf("erase %s\n", result);
  1230.  
  1231.  
  1232.  
  1233. uint64* resulti;
  1234. unsigned int errorz;
  1235. errorz = ts3Functions.getServerConnectionHandlerList(&resulti);
  1236. if (errorz != ERROR_ok) break;
  1237.  
  1238. //printf("checking\n");
  1239. for (int i = 0; resulti[i] != NULL; i++)
  1240. {
  1241. char* resultg;
  1242. errorz = ts3Functions.getServerVariableAsString(resulti[i], VIRTUALSERVER_UNIQUE_IDENTIFIER, &resultg);
  1243. if (errorz != ERROR_ok) continue;
  1244. //printf("unique sv ids: %llu result: %s \n", resulti[i], resultg);
  1245.  
  1246. if (strcmp(resultg, result) == 0)
  1247. {
  1248. std::pair<std::map<std::string, uint64>::iterator, bool> ret = threadlist.insert(std::pair<std::string, uint64>(resultg, resulti[i]));
  1249.  
  1250. if (ret.second == true)
  1251. {
  1252. std::thread repeat(pointsMinute, resultg, resulti[i]);
  1253. repeat.detach();
  1254. //printf("thread made %s\n", resultg);
  1255. }
  1256. //else printf("no thread made (from thread) %s \n", resultg); //fnguje
  1257. }
  1258.  
  1259. }
  1260.  
  1261. ts3Functions.freeMemory(resulti);
  1262.  
  1263.  
  1264.  
  1265. break;
  1266. }
  1267. //printf("deges 5\n");
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273. addPoints(serverConnectionHandlerID);
  1274. using namespace std::chrono_literals;
  1275. auto start = std::chrono::high_resolution_clock::now();
  1276. std::this_thread::sleep_for(5s);
  1277. auto end = std::chrono::high_resolution_clock::now();
  1278. }
  1279. ts3Functions.freeMemory(result);
  1280. return;
  1281. }
  1282.  
  1283.  
  1284.  
  1285. void ts3plugin_onConnectStatusChangeEvent(uint64 serverConnectionHandlerID, int newStatus, unsigned int errorNumber) {
  1286. /* Some example code following to show how to use the information query functions. */
  1287.  
  1288. if (newStatus == STATUS_CONNECTION_ESTABLISHED) { /* connection established and we have client and channels available */
  1289. char* result;
  1290. unsigned int error;
  1291. error = ts3Functions.getServerVariableAsString(serverConnectionHandlerID, VIRTUALSERVER_UNIQUE_IDENTIFIER, &result);
  1292. if (error != ERROR_ok) return;
  1293. std::pair<std::map<std::string, uint64>::iterator, bool> ret = threadlist.insert(std::pair<std::string, uint64>(result, serverConnectionHandlerID));
  1294.  
  1295. if (ret.second == true)
  1296. {
  1297. std::thread repeat(pointsMinute, result, serverConnectionHandlerID);
  1298. repeat.detach();
  1299. //printf("thread made %s\n", result);
  1300. }
  1301. //else printf("no thread made %s \n", result); //fnguje
  1302. }
  1303.  
  1304. if (newStatus == STATUS_DISCONNECTED) {
  1305. //char* result;
  1306. //ts3Functions.getServerVariableAsString(serverConnectionHandlerID, VIRTUALSERVER_UNIQUE_IDENTIFIER, &result);
  1307. //std::map<std::string, bool>::iterator it;
  1308. //it = threadlist.find(result);
  1309. //threadlist.erase(it);
  1310. //printf("result removed %s \n", result); //fnguje
  1311.  
  1312.  
  1313.  
  1314. //bool zmena = false;
  1315. //uint64* resulti;
  1316. //unsigned int error;
  1317. //error = ts3Functions.getServerConnectionHandlerList(&resulti);
  1318. //printf("jantar %u", error);
  1319. //if (error != ERROR_ok) return;
  1320.  
  1321. //printf("jantar \n");
  1322. //for (int i = 0; resulti[i] != NULL; i++)
  1323. //{
  1324. // char* resultg;
  1325. // error = ts3Functions.getServerVariableAsString(resulti[i], VIRTUALSERVER_UNIQUE_IDENTIFIER, &resultg);
  1326. // if (error != ERROR_ok) continue;
  1327. // printf("unique sv ids: %llu result: %s \n", resulti[i], resultg);
  1328.  
  1329. // std::map<std::string, uint64>::iterator itg = threadlist.find(resultg);
  1330. // if (itg != threadlist.end() && itg->second != resulti[i])
  1331. // {
  1332. // itg->second = resulti[i];
  1333. // zmena = true;
  1334. // }
  1335.  
  1336. // ts3Functions.freeMemory(resultg);
  1337. //}
  1338.  
  1339. //ts3Functions.freeMemory(resulti);
  1340.  
  1341.  
  1342. }
  1343. }
  1344.  
  1345.  
  1346.  
  1347. int pointsof(const char* targetname, uint64 serverConnectionHandlerID)
  1348. {
  1349.  
  1350. char* s;
  1351. anyID* ids;
  1352. size_t i;
  1353. int result;
  1354.  
  1355. if (ts3Functions.getClientList(serverConnectionHandlerID, &ids) != ERROR_ok) {
  1356. ts3Functions.logMessage("Error getting channel list", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  1357. return 0;
  1358. }
  1359.  
  1360. for (i = 0; ids[i]; i++)
  1361. {
  1362. if (ts3Functions.getClientVariableAsString(serverConnectionHandlerID, ids[i], CLIENT_NICKNAME, &s) != ERROR_ok) {
  1363. ts3Functions.logMessage("Error querying channel name", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  1364. return -2;
  1365. }
  1366. if (strcmp(targetname, s) == 0)
  1367. {
  1368. char* unikveid;
  1369. int error = ts3Functions.getClientVariableAsString(serverConnectionHandlerID, ids[i], CLIENT_UNIQUE_IDENTIFIER, &unikveid);
  1370. if (error != ERROR_ok) continue;
  1371. char *err_msg = 0;
  1372. sqlite3_stmt *res;
  1373. char *sql = "SELECT * FROM Users WHERE ts3id = ?";
  1374. sqlite3_prepare_v2(db, sql, -1, &res, 0);
  1375. sqlite3_bind_text(res, 1, unikveid, -1, 0);
  1376. sqlite3_step(res);
  1377. result = sqlite3_column_int(res, 3);
  1378. //printf("result = %i", result);
  1379. sqlite3_finalize(res);
  1380.  
  1381. ts3Functions.freeMemory(unikveid);
  1382.  
  1383. ts3Functions.freeMemory(s);
  1384. ts3Functions.freeMemory(ids);
  1385. return result;
  1386. }
  1387. ts3Functions.freeMemory(s);
  1388. }
  1389. ts3Functions.freeMemory(ids); /* Release array */
  1390.  
  1391. return -1;
  1392. }
  1393.  
  1394.  
  1395. std::string gibPoints(const char* odhraca, const char* hracovy, const char * lastparametr, uint64 serverConnectionHandlerID)
  1396. {
  1397.  
  1398. char* s;
  1399. char* unikveod = NULL;
  1400. char* unikvekomu = NULL;
  1401. bool fromSet = false;
  1402. bool toSet = false;
  1403. long long pocetPointu = atoll(lastparametr);
  1404. anyID* ids;
  1405. size_t i;
  1406.  
  1407. if (ts3Functions.getClientList(serverConnectionHandlerID, &ids) != ERROR_ok) {
  1408. ts3Functions.logMessage("Error getting channel list", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  1409. return 0;
  1410. }
  1411.  
  1412. for (i = 0; ids[i]; i++)
  1413. {
  1414.  
  1415. if (ts3Functions.getClientVariableAsString(serverConnectionHandlerID, ids[i], CLIENT_NICKNAME, &s) != ERROR_ok) {
  1416. ts3Functions.logMessage("Error querying channel name", LogLevel_ERROR, "Plugin", serverConnectionHandlerID);
  1417. return 0;
  1418. }
  1419. if (pocetPointu > 0)
  1420. {
  1421. int hracovyid;
  1422. if (strcmp(odhraca, s) == 0)
  1423. {
  1424. ts3Functions.getClientVariableAsString(serverConnectionHandlerID, ids[i], CLIENT_UNIQUE_IDENTIFIER, &unikveod);
  1425. fromSet = true;
  1426. }
  1427.  
  1428. if (strcmp(hracovy, s) == 0)
  1429. {
  1430. ts3Functions.getClientVariableAsString(serverConnectionHandlerID, ids[i], CLIENT_UNIQUE_IDENTIFIER, &unikvekomu);
  1431. toSet = true;
  1432. hracovyid = ids[i];
  1433. }
  1434.  
  1435. //printf("========\n%s %s\n", unikveod, unikvekomu);
  1436. if (fromSet && toSet)
  1437. {
  1438. int points = pointsof(hracovy, serverConnectionHandlerID);
  1439. int mojepoints = pointsof(odhraca, serverConnectionHandlerID);
  1440. if (mojepoints >= pocetPointu)
  1441. {
  1442.  
  1443. //sql
  1444. sqlite3_stmt * statement;
  1445. int popointy = mojepoints - (int)pocetPointu;
  1446. sqlite3_prepare_v2(db, "UPDATE Users SET points = ? WHERE ts3id = ?;", -1, &statement, NULL);
  1447. sqlite3_bind_int(statement, 1, popointy);
  1448. sqlite3_bind_text(statement, 2, unikveod, -1, 0);
  1449. sqlite3_step(statement);
  1450. sqlite3_finalize(statement);
  1451.  
  1452. popointy = mojepoints + (int)pocetPointu;
  1453. sqlite3_prepare_v2(db, "UPDATE Users SET points = ? WHERE ts3id = ?;", -1, &statement, NULL);
  1454. sqlite3_bind_int(statement, 1, popointy);
  1455. sqlite3_bind_text(statement, 2, unikvekomu, -1, 0);
  1456. sqlite3_step(statement);
  1457. sqlite3_finalize(statement);
  1458. //sql
  1459.  
  1460.  
  1461. ts3Functions.freeMemory(unikvekomu);
  1462. ts3Functions.freeMemory(unikveod);
  1463. ts3Functions.freeMemory(ids);
  1464. std::string sprava = botTag;
  1465. sprava += "You have given: [b]";
  1466. sprava += std::to_string(pocetPointu);
  1467. sprava += "[/b] points to: [b]";
  1468. sprava += hracovy;
  1469. sprava += "[/b]";
  1470. std::string spravadva = botTag;
  1471. spravadva += "You have received: [b]";
  1472. spravadva += std::to_string(pocetPointu);
  1473. spravadva += "[/b] Points from [b]";
  1474. spravadva += odhraca;
  1475. spravadva += "[/b]";
  1476. ts3Functions.requestSendPrivateTextMsg(serverConnectionHandlerID, spravadva.c_str(), hracovyid, NULL);
  1477. return sprava;
  1478. }
  1479. else
  1480. {
  1481. ts3Functions.freeMemory(unikvekomu);
  1482. ts3Functions.freeMemory(unikveod);
  1483. ts3Functions.freeMemory(ids);
  1484. return "Not enough points";
  1485. }
  1486.  
  1487. }
  1488.  
  1489. }
  1490. ts3Functions.freeMemory(s);
  1491. if (toSet) ts3Functions.freeMemory(unikvekomu);
  1492. if (fromSet) ts3Functions.freeMemory(unikveod);
  1493. }
  1494. ts3Functions.freeMemory(ids); /* Release array */
  1495.  
  1496. return 0;
  1497.  
  1498. }
  1499.  
  1500.  
  1501. int ts3plugin_onTextMessageEvent(uint64 serverConnectionHandlerID, anyID targetMode, anyID toID, anyID fromID, const char* fromName, const char* fromUniqueIdentifier, const char* message, int ffIgnored) {
  1502. printf("PLUGIN: onTextMessageEvent %llu %d %d %s %s %d\n", (long long unsigned int)serverConnectionHandlerID, targetMode, fromID, fromName, message, ffIgnored);
  1503.  
  1504. if (strncmp(message, botTag, strlen(botTag)) == 0)
  1505. {
  1506. return 0;
  1507. }
  1508.  
  1509. if (strncmp(message, "!points", strlen("!points")) == 0)
  1510. {
  1511. if (strlen(message) == strlen("!points") || strlen(message) == strlen("!points "))
  1512. {
  1513. int points = pointsof(fromName, serverConnectionHandlerID);
  1514. std::string msgback = botTag;
  1515. msgback += "You have [b]";
  1516. msgback += std::to_string(points);
  1517. msgback += "[/b] points.";
  1518. ts3Functions.requestSendPrivateTextMsg(serverConnectionHandlerID, msgback.c_str(), fromID, NULL);
  1519. return 0;
  1520. }
  1521. const char * parametr = message + strlen("!points") + 1;
  1522.  
  1523. int points = pointsof(parametr, serverConnectionHandlerID);
  1524. if (points == -1)
  1525. {
  1526. std::string msgback = botTag;
  1527. msgback += "User named [b] ";
  1528. msgback += parametr;
  1529. msgback += "[/b] not found.";
  1530. ts3Functions.requestSendPrivateTextMsg(serverConnectionHandlerID, msgback.c_str(), fromID, NULL);
  1531. return 0;
  1532. }
  1533. else if (points == -2) return 0; // error
  1534. else
  1535. {
  1536. std::string msgback = botTag;
  1537. msgback += "[b]";
  1538. msgback += parametr;
  1539. msgback += "[/b] has [b]";
  1540. msgback += std::to_string(points);
  1541. msgback += "[/b] points.";
  1542. ts3Functions.requestSendPrivateTextMsg(serverConnectionHandlerID, msgback.c_str(), fromID, NULL);
  1543. return 0;
  1544. }
  1545. }
  1546.  
  1547.  
  1548.  
  1549. if (strncmp(message, "!gibpoints", strlen("!gibpoints")) == 0)
  1550. {
  1551. if (strlen(message) <= strlen("!gibpoints") + 1)
  1552. {
  1553. std::stringstream stringStream;
  1554. stringStream << botTag << "Correct syntax: [b]!gibpoints[/b] [i]username[/i] [i]number[/i].";
  1555. ts3Functions.requestSendPrivateTextMsg(serverConnectionHandlerID, stringStream.str().c_str(), fromID, NULL);
  1556. return 0;
  1557. }
  1558.  
  1559. const char * parametr = message + strlen("!gibpoints") + 1;
  1560. std::string msgback = botTag;
  1561.  
  1562. const char * lastparametr = strrchr(parametr, ' ');
  1563.  
  1564. if (lastparametr == NULL)
  1565. {
  1566. std::stringstream stringStream;
  1567. stringStream << botTag << "Correct syntax: [b]!gibpoints[/b] [i]username[/i] [i]number[/i].";
  1568. ts3Functions.requestSendPrivateTextMsg(serverConnectionHandlerID, stringStream.str().c_str(), fromID, NULL);
  1569. return 0;
  1570. }
  1571. lastparametr++; //zbaveni se mezery
  1572.  
  1573. std::string name = parametr;
  1574. name = name.substr(0, name.size() - strlen(lastparametr) - 1);
  1575.  
  1576. int points = pointsof(name.c_str(), serverConnectionHandlerID);
  1577.  
  1578. if (strlen(message) != strlen("!gibpoints") && strlen(message) != strlen("!gibpoints "))
  1579. {
  1580.  
  1581. if (strlen(name.c_str()) == 0 || strlen(lastparametr) == 0)
  1582. {
  1583. std::stringstream stringStream;
  1584. stringStream << botTag << "Correct syntax: [b]!gibpoints[/b] [i]username[/i] [i]number[/i].";
  1585. ts3Functions.requestSendPrivateTextMsg(serverConnectionHandlerID, stringStream.str().c_str(), fromID, NULL);
  1586. return 0;
  1587. }
  1588.  
  1589. if (points == -1)
  1590. {
  1591. msgback += "User named [b] ";
  1592. msgback += name.c_str();
  1593. msgback += "[/b] not found.";
  1594. ts3Functions.requestSendPrivateTextMsg(serverConnectionHandlerID, msgback.c_str(), fromID, NULL);
  1595. return 0;
  1596. }
  1597. else if (points == -2) return 0; // error
  1598. else
  1599. {
  1600. if (atoi(lastparametr) > 0) {
  1601. //kto //komu //kolko //server
  1602. std::string sprava;
  1603. //vo funkci to posle spravu aj cielu btw :D ked tak nezabudnut
  1604. sprava += gibPoints(fromName, name.c_str(), lastparametr, serverConnectionHandlerID);
  1605. ts3Functions.requestSendPrivateTextMsg(serverConnectionHandlerID, sprava.c_str(), fromID, NULL);
  1606. }
  1607. return 0;
  1608.  
  1609. }
  1610. }
  1611.  
  1612. }
  1613.  
  1614. return 0; /* 0 = handle normally, 1 = client will ignore the text message */
  1615. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement