pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

pastebin private pastebin - collaborative debugging tool What's a private pastebin?

Posted by hummy on Fri 4th Dec 20:36
download | new post

  1. /*
  2.  
  3. Description:
  4.  
  5. Adds a !ts or a !vent command that allows players to join the teamspeak/ventrilo server or admins to force players into the teamspeak server
  6.  
  7. Requirements:
  8.  
  9.     * Game that supports opening URLs in the game browser.
  10.  
  11. Commands:
  12.  
  13. sm_teamspeak [<target>] -
  14.  
  15.     * When a player executes it, it just opens the players teamspeak, connects him to the server and joins the specified channel in the config.
  16.  
  17.     * When an admin executes it he can also specify a target which player to join the teamspeak.
  18.  
  19. example: !ts @all would force all players to connect to the teamspeak server
  20.  
  21. sm_ts - Alias of above
  22.  
  23. sm_ventrilo [<target>] -
  24.  
  25.     * When a player executes it, it just opens the players ventrilo, connects him to the server and joins the specified channel in the config.
  26.  
  27.     * When an admin executes it he can also specify a target which player to join the ventrilo.
  28.  
  29. example: !ts @all would force all players to connect to the teamspeak server
  30.  
  31. sm_vent - Alias of above
  32.  
  33. ConVars:
  34.  
  35. ts_printjoins - Enable/disable teamspeak join messages <1/0>
  36. Default: 1
  37.  
  38. Config
  39.  
  40. configs/teamspeak.cfg
  41. configs/ventrilo.cfg
  42.  
  43. Todo
  44.  
  45.     * Add support for any voice server
  46.  
  47.  
  48. Changelog
  49.  
  50. Date: 26.08.2008
  51. Version: 1.2
  52.  
  53.     * Added ventrilo support (Thanks to the_reverend)
  54.  
  55. Date: 26.08.2008
  56. Version: 1.1
  57.  
  58.     * Removed debug message on join
  59.     * Added display ts joins in green text in the serverchat
  60.     * Added Convar for setting join messages on/off
  61.  
  62. Date: 24.08.2008
  63. Version: 1.0.2
  64.  
  65.     * Fixed not working disallowed-characters replacement
  66.  
  67. Date: 24.08.2008
  68. Version: 1.0.1
  69.  
  70.     * Fixed hardcoded server address
  71.  
  72. Date: 23.08.2008
  73. Version: 1.0
  74.  
  75.     * Initial release
  76.  
  77. */
  78.  
  79.  
  80.  
  81.  
  82.  
  83. // enforce semicolons after each code statement
  84. #pragma semicolon 1
  85.  
  86. #include <sourcemod>
  87.  
  88. #define PLUGIN_VERSION "1.2"
  89.  
  90.  
  91. /*****************************************************************
  92.  
  93.  
  94.                         P L U G I N   I N F O
  95.  
  96.  
  97. *****************************************************************/
  98.  
  99. public Plugin:myinfo = {
  100.         name = "Teamspeak join command",
  101.         author = "Berni",
  102.         description = "Allows players to join the teamspeak server",
  103.         version = PLUGIN_VERSION,
  104.         url = "http://forums.alliedmods.net/showthread.php?p=674090"
  105. }
  106.  
  107.  
  108.  
  109. /*****************************************************************
  110.  
  111.  
  112.                         G L O B A L   V A R S
  113.  
  114.  
  115. *****************************************************************/
  116.  
  117. // ConVar Handles
  118. new Handle:ts_version;
  119. new Handle:ts_printjoins;
  120.  
  121. // Teamspeak
  122. new String:teamspeak_address[256];
  123. new String:teamspeak_password[64];
  124. new String:teamspeak_channel[128];
  125. new String:teamspeak_disallowed[128];
  126.  
  127. // Ventrilo
  128. new String:ventrilo_address[256];
  129. new String:ventrilo_servername[128];
  130. new String:ventrilo_password[64];
  131. new String:ventrilo_channel[128];
  132.  
  133. // Mumble
  134. new String:mumble_address[256];
  135. new String:mumble_password[64];
  136. new String:mumble_channel[128];
  137.  
  138.  
  139. /*****************************************************************
  140.  
  141.  
  142.                         F O R W A R D   P U B L I C S
  143.  
  144.  
  145. *****************************************************************/
  146.  
  147. public OnPluginStart() {
  148.        
  149.         // ConVars
  150.         ts_version = CreateConVar("ts_version", PLUGIN_VERSION, "Teamspeak & ventrilo join plugin version", FCVAR_DONTRECORD|FCVAR_REPLICATED|FCVAR_NOTIFY);
  151.         // Set it to the correct version, in case the plugin gets updated...
  152.         SetConVarString(ts_version, PLUGIN_VERSION);
  153.        
  154.         ts_printjoins = CreateConVar("ts_printjoins", "1", "Enable/disable teamspeak join messages <1/0>", FCVAR_REPLICATED|FCVAR_NOTIFY);
  155.  
  156.         RegConsoleCmd("sm_ts", Command_Teamspeak, "Allows users to join the teamspeak server");
  157.         RegConsoleCmd("sm_teamspeak", Command_Teamspeak, "Allows users to join the teamspeak server");
  158.         RegConsoleCmd("sm_vent", Command_Ventrilo, "Allows users to join the ventrilo server");
  159.         RegConsoleCmd("sm_ventrilo", Command_Ventrilo, "Allows users to join the ventrilo server");
  160.         RegConsoleCmd("sm_mumb", Command_Mumble, "Allows users to join the mumble server");
  161.         RegConsoleCmd("sm_mumble", Command_Mumble, "Allows users to join the mumble server");
  162. }
  163.  
  164. public OnConfigsExecuted() {
  165.         ReadConfig_Teamspeak();
  166.         ReadConfig_Ventrilo();
  167.         ReadConfig_Mumble();
  168. }
  169.  
  170.  
  171.  
  172. /****************************************************************
  173.  
  174.  
  175.                         C A L L B A C K   F U N C T I O N S
  176.  
  177.  
  178. ****************************************************************/
  179.  
  180. public Action:Command_Teamspeak(client, args) {
  181.         decl target_list[MAXPLAYERS];
  182.         new target_count;
  183.  
  184.         if (args == 0) {
  185.                 target_count = 1;
  186.                 target_list[0] = client;
  187.         }
  188.         else {
  189.        
  190.                 new AdminId:aid = GetUserAdmin(client);
  191.                
  192.                 if (aid != INVALID_ADMIN_ID && GetAdminFlag(aid, Admin_Custom4)) {
  193.                         decl String:target[MAX_TARGET_LENGTH];
  194.                         GetCmdArg(1, target, sizeof(target));
  195.  
  196.                         decl String:target_name[MAX_TARGET_LENGTH];
  197.                         decl bool:tn_is_ml;
  198.  
  199.                         target_count = ProcessTargetString(
  200.                                         target,
  201.                                         client,
  202.                                         target_list,
  203.                                         sizeof(target_list),
  204.                                         COMMAND_FILTER_ALIVE,
  205.                                         target_name,
  206.                                         sizeof(target_name),
  207.                                         tn_is_ml
  208.                         );
  209.                        
  210.                         ReplyToCommand(client, "\x04[SM] Command executed on target %s...", target);
  211.                 }
  212.                 else {
  213.                         ReplyToCommand(client, "\x04[SM] Access denied");
  214.                         return Plugin_Handled;
  215.                 }
  216.         }
  217.        
  218.         if (target_count <= 0) {
  219.                 ReplyToCommand(client, "\x04[SM] Error: no valid targets found");
  220.                 return Plugin_Handled;
  221.         }
  222.        
  223.         decl String:URL[256];
  224.         decl String:nickName[64];
  225.  
  226.         for (new i=0; i<target_count; ++i) {
  227.                 GenerateValidTeamspeakNickName(target_list[i], nickName, sizeof(nickName));
  228.                
  229.                 Format(URL, sizeof(URL), "teamspeak://%s/nickname=%s?password=%s?channel=%s", teamspeak_address, nickName, teamspeak_password, teamspeak_channel);
  230.                
  231.                 ReplyToCommand(target_list[i], "\x04[SM] Trying to join Teamspeak server...");
  232.                 ShowMOTDPanel(target_list[i], "", URL, MOTDPANEL_TYPE_URL);
  233.                 ShowVGUIPanel(target_list[i], "info", INVALID_HANDLE, false);
  234.                
  235.                 if (GetConVarBool(ts_printjoins)) {
  236.                         PrintToChatAll("\x04[SM] Player %N is joining the teamspeak server !", target_list[i]);
  237.                 }
  238.         }
  239.        
  240.         return Plugin_Handled;
  241. }
  242.  
  243. public Action:Command_Ventrilo(client, args) {
  244.         decl target_list[MAXPLAYERS];
  245.         new target_count;
  246.  
  247.         if (args == 0) {
  248.                 target_count = 1;
  249.                 target_list[0] = client;
  250.         }
  251.         else {
  252.        
  253.                 new AdminId:aid = GetUserAdmin(client);
  254.                
  255.                 if (aid != INVALID_ADMIN_ID && GetAdminFlag(aid, Admin_Custom4)) {
  256.                         decl String:target[MAX_TARGET_LENGTH];
  257.                         GetCmdArg(1, target, sizeof(target));
  258.  
  259.                         decl String:target_name[MAX_TARGET_LENGTH];
  260.                         decl bool:tn_is_ml;
  261.  
  262.                         target_count = ProcessTargetString(
  263.                                         target,
  264.                                         client,
  265.                                         target_list,
  266.                                         sizeof(target_list),
  267.                                         COMMAND_FILTER_ALIVE,
  268.                                         target_name,
  269.                                         sizeof(target_name),
  270.                                         tn_is_ml
  271.                         );
  272.                        
  273.                         ReplyToCommand(client, "\x04[SM] Command executed on target %s...", target);
  274.                 }
  275.                 else {
  276.                         ReplyToCommand(client, "\x04[SM] Access denied");
  277.                         return Plugin_Handled;
  278.                 }
  279.         }
  280.        
  281.         if (target_count <= 0) {
  282.                 ReplyToCommand(client, "\x04[SM] Error: no valid targets found");
  283.                 return Plugin_Handled;
  284.         }
  285.        
  286.         decl String:URL[256];
  287.         decl String:nickName[64];
  288.  
  289.         for (new i=0; i<target_count; ++i) {
  290.                 GenerateValidTeamspeakNickName(target_list[i], nickName, sizeof(nickName));
  291.                
  292.                 Format(URL, sizeof(URL), "ventrilo://%s/servername=%s&serverpassword=%s&channelname=%s", ventrilo_address, ventrilo_servername, ventrilo_password, ventrilo_channel);
  293.                
  294.                 ReplyToCommand(target_list[i], "\x04[SM] Trying to join Ventrilo server...");
  295.                 ShowMOTDPanel(target_list[i], "", URL, MOTDPANEL_TYPE_URL);
  296.                 ShowVGUIPanel(target_list[i], "info", INVALID_HANDLE, false);
  297.                
  298.                 if (GetConVarBool(ts_printjoins)) {
  299.                         PrintToChatAll("\x04[SM] Player %N is joining the ventrilo server !", target_list[i]);
  300.                 }
  301.         }
  302.        
  303.         return Plugin_Handled;
  304. }
  305.  
  306. public Action:Command_Mumble(client, args) {
  307.         decl target_list[MAXPLAYERS];
  308.         new target_count;
  309.  
  310.         if (args == 0) {
  311.                 target_count = 1;
  312.                 target_list[0] = client;
  313.         }
  314.         else {
  315.        
  316.                 new AdminId:aid = GetUserAdmin(client);
  317.                
  318.                 if (aid != INVALID_ADMIN_ID && GetAdminFlag(aid, Admin_Custom4)) {
  319.                         decl String:target[MAX_TARGET_LENGTH];
  320.                         GetCmdArg(1, target, sizeof(target));
  321.  
  322.                         decl String:target_name[MAX_TARGET_LENGTH];
  323.                         decl bool:tn_is_ml;
  324.  
  325.                         target_count = ProcessTargetString(
  326.                                         target,
  327.                                         client,
  328.                                         target_list,
  329.                                         sizeof(target_list),
  330.                                         COMMAND_FILTER_ALIVE,
  331.                                         target_name,
  332.                                         sizeof(target_name),
  333.                                         tn_is_ml
  334.                         );
  335.                        
  336.                         ReplyToCommand(client, "\x04[SM] Command executed on target %s...", target);
  337.                 }
  338.                 else {
  339.                         ReplyToCommand(client, "\x04[SM] Access denied");
  340.                         return Plugin_Handled;
  341.                 }
  342.         }
  343.        
  344.         if (target_count <= 0) {
  345.                 ReplyToCommand(client, "\x04[SM] Error: no valid targets found");
  346.                 return Plugin_Handled;
  347.         }
  348.        
  349.         decl String:URL[256];
  350.         decl String:nickName[64];
  351.  
  352.         for (new i=0; i<target_count; ++i) {
  353.                 GenerateValidTeamspeakNickName(target_list[i], nickName, sizeof(nickName));
  354.                
  355.                 Format(URL, sizeof(URL), "mumble://%s@%s/%s?version=1.2.0", nickName, mumble_address, mumble_channel);
  356.                
  357.                 ReplyToCommand(target_list[i], "\x04[SM] Trying to join Mumble server...");
  358.                 ShowMOTDPanel(target_list[i], "", URL, MOTDPANEL_TYPE_URL);
  359.                 ShowVGUIPanel(target_list[i], "info", INVALID_HANDLE, false);
  360.                
  361.                 if (GetConVarBool(ts_printjoins)) {
  362.                         PrintToChatAll("\x04[SM] Player %N is joining the Mumble server !", target_list[i]);
  363.                 }
  364.         }
  365.        
  366.         return Plugin_Handled;
  367. }
  368.  
  369. /*****************************************************************
  370.  
  371.  
  372.                         P L U G I N   F U N C T I O N S
  373.  
  374.  
  375. *****************************************************************/
  376.  
  377. GenerateValidTeamspeakNickName(client, String:buffer[], size) {
  378.         if (size == 0) {
  379.                 return;
  380.         }
  381.  
  382.         decl String:clientName[64];
  383.         GetClientName(client, clientName, sizeof(clientName));
  384.        
  385.        
  386.        
  387.         new n=0;
  388.         new buf_pos = 0;
  389.         if
  390.         while (clientName[n] != '\0') {
  391.                 new x = 0;
  392.                 new invalid = false;
  393.                 while (teamspeak_disallowed[x] != '\0') {
  394.                         if (clientName[n] == teamspeak_disallowed[x]) {
  395.                                 invalid = true;
  396.                                 break;
  397.                         }
  398.                        
  399.                         ++x;
  400.                 }
  401.                
  402.                 if (!invalid) {
  403.                         buffer[buf_pos] = clientName[n];
  404.                         buf_pos++;
  405.                        
  406.                         if (buf_pos == size) {
  407.                                 break;
  408.                         }
  409.                 }
  410.                
  411.                 ++n;
  412.         }
  413.        
  414.         buffer[buf_pos] = '\0';
  415. }
  416.  
  417. ReadConfig_Teamspeak() {
  418.         decl String:path[PLATFORM_MAX_PATH];
  419.  
  420.         new Handle:kv = CreateKeyValues("Teamspeakserver");
  421.        
  422.         BuildPath(Path_SM, path, sizeof(path), "configs/voiceserver/teamspeak.cfg");
  423.         FileToKeyValues(kv, path);
  424.  
  425.         KvGetString(kv, "address", teamspeak_address, sizeof(teamspeak_address));
  426.         KvGetString(kv, "password", teamspeak_password, sizeof(teamspeak_password));
  427.         KvGetString(kv, "channel", teamspeak_channel, sizeof(teamspeak_channel));
  428.         KvGetString(kv, "DisAllowedClientNameChars", teamspeak_disallowed, sizeof(teamspeak_disallowed));
  429.        
  430.         CloseHandle(kv);
  431.  
  432.         return true;
  433.  
  434. }
  435.  
  436. ReadConfig_Ventrilo() {
  437.         decl String:path[PLATFORM_MAX_PATH];
  438.  
  439.         new Handle:kv = CreateKeyValues("Ventriloserver");
  440.        
  441.         BuildPath(Path_SM, path, sizeof(path), "configs/voiceserver/ventrilo.cfg");
  442.         FileToKeyValues(kv, path);
  443.  
  444.         KvGetString(kv, "address", ventrilo_address, sizeof(ventrilo_address));
  445.         KvGetString(kv, "password", ventrilo_password, sizeof(ventrilo_password));
  446.         KvGetString(kv, "servername", ventrilo_servername, sizeof(ventrilo_servername));
  447.         KvGetString(kv, "channel", ventrilo_channel, sizeof(ventrilo_channel));
  448.        
  449.         CloseHandle(kv);
  450.  
  451.         return true;
  452.  
  453. }
  454.  
  455. ReadConfig_Mumble() {
  456.         decl String:path[PLATFORM_MAX_PATH];
  457.  
  458.         new Handle:kv = CreateKeyValues("Mumbleserver");
  459.        
  460.         BuildPath(Path_SM, path, sizeof(path), "configs/voiceserver/mumble.cfg");
  461.         FileToKeyValues(kv, path);
  462.  
  463.         KvGetString(kv, "address", mumble_address, sizeof(mumble_address));
  464.         KvGetString(kv, "password", mumble_password, sizeof(mumble_password));
  465.         KvGetString(kv, "channel", mumble_channel, sizeof(mumble_channel));
  466.         KvGetString(kv, "DisAllowedClientNameChars", teamspeak_disallowed, sizeof(teamspeak_disallowed));
  467.        
  468.         CloseHandle(kv);
  469.  
  470.         return true;
  471.  
  472. }
  473.  
  474.  
  475.  
  476.  
  477. these are the errors.
  478.  
  479. /home/groups/sourcemod/upload_tmp/phpSCwljl.sp(390) : error 029: invalid expression, assumed zero
  480. /home/groups/sourcemod/upload_tmp/phpSCwljl.sp(390) : error 029: invalid expression, assumed zero
  481. /home/groups/sourcemod/upload_tmp/phpSCwljl.sp(407) : error 024: "break" or "continue" is out of context
  482.  
  483. 3 Errors.

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Use syntax highlighting

To highlight particular lines, prefix each line with @@


Remember my settings