iDarkRain

DialogRCON

Dec 27th, 2011
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.32 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define DialogRCON 1920
  4. #define DialogRCON2 1921
  5.  
  6. // Descomenta la siguiente linea si deseas activar la opción de ver los jugadores (CONSUME MUCHA MEMORIA)
  7. //#define VerJugadores
  8.  
  9. // IMPORTANTE: coloca aquí la cantidad de slots de tu servidor (sólo será necesario si activaste la opción de ver los jugadores)
  10. #undef MAX_PLAYERS
  11. #define MAX_PLAYERS 500
  12.  
  13. public OnFilterScriptInit()
  14. {
  15.     print("*** DialogRCON by iDarkRain - Cargado ***");
  16.     return 1;
  17. }
  18.  
  19. public OnFilterScriptExit()
  20. {
  21.     print("*** DialogRCON by iDarkRain - Descargado ***");
  22.     return 1;
  23. }
  24.  
  25. public OnPlayerDisconnect(playerid, reason)
  26. {
  27.     DeletePVar(playerid, "DialogRCON");
  28.     return 1;
  29. }
  30.  
  31. public OnPlayerCommandText(playerid, cmdtext[])
  32. {
  33.     if (strcmp("/drcon", cmdtext, true, 6) == 0 && IsPlayerAdmin(playerid))
  34.     {
  35.         new dialog[590] = "Cerrar el servidor";
  36.         strcat(dialog, "\nEnviar mensaje a la consola");
  37.         strcat(dialog, "\nCambiar nombre del servidor");
  38.         strcat(dialog, "\nCambiar modo de juego");
  39.         strcat(dialog, "\nCambiar nombre de mapa");
  40.         strcat(dialog, "\nEjecutar un archivo de configuración externo");
  41.         strcat(dialog, "\nKickear un jugador");
  42.         strcat(dialog, "\nBanear un jugador");
  43.         strcat(dialog, "\nCambiar de gamemode");
  44.         strcat(dialog, "\nRecargar samp.ban");
  45.         strcat(dialog, "\nRecargar server_log.txt");
  46.         strcat(dialog, "\nEnviar mensaje a los jugadores");
  47.         strcat(dialog, "\nMostrar los jugadores conectados");
  48.         strcat(dialog, "\nBanear una IP específica");
  49.         strcat(dialog, "\nDesbanear una IP específica");
  50.         strcat(dialog, "\nCambiar la gravedad");
  51.         strcat(dialog, "\nCambiar el clima");
  52.         strcat(dialog, "\nCargar un filterscript específico");
  53.         strcat(dialog, "\nCambiar la página web del servidor");
  54.         strcat(dialog, "\nDescargar un filterscript específico");
  55.         strcat(dialog, "\nRecargar un filterscript específico");
  56.         strcat(dialog, "\nCambiar la contraseña de RCON");
  57.         ShowPlayerDialog(playerid, DialogRCON, DIALOG_STYLE_LIST, "DialogRCON by iDarkRain", dialog, "Entrar", "Salir");
  58.         return 1;
  59.     }
  60.     return 0;
  61. }
  62.  
  63. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  64. {
  65.     switch(dialogid)
  66.     {
  67.         case DialogRCON:
  68.         {
  69.             if(!response) return 1;
  70.             if(!IsPlayerAdmin(playerid)) return 1;
  71.             if(listitem == 0) { SendRconCommand("exit"); return 1; }
  72.             if(listitem == 1)
  73.             {
  74.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_INPUT, inputtext, "Escribe el mensaje que deseas enviar a la consola del servidor.", "Enviar", "Cancelar");
  75.                 SetPVarInt(playerid, "DialogRCON", listitem);
  76.                 return 1;
  77.             }
  78.             if(listitem == 2)
  79.             {
  80.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_INPUT, inputtext, "Escribe el nuevo nombre para el nombre del servidor que desea poner.", "Cambiar", "Cancelar");
  81.                 SetPVarInt(playerid, "DialogRCON", listitem);
  82.                 return 1;
  83.             }
  84.             if(listitem == 3)
  85.             {
  86.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_INPUT, inputtext, "Escribe el nuevo nombre para el modo de juego que desea poner.", "Cambiar", "Cancelar");
  87.                 SetPVarInt(playerid, "DialogRCON", listitem);
  88.                 return 1;
  89.             }
  90.             if(listitem == 4)
  91.             {
  92.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_INPUT, inputtext, "Escribe el nuevo nombre para el nombre del mapa que desea poner.", "Cambiar", "Cancelar");
  93.                 SetPVarInt(playerid, "DialogRCON", listitem);
  94.                 return 1;
  95.             }
  96.             if(listitem == 5)
  97.             {
  98.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_INPUT, inputtext, "Escribe el nombre del archivo de configuración externo\nEjemplo: blah.cfg", "Ejecutar", "Cancelar");
  99.                 SetPVarInt(playerid, "DialogRCON", listitem);
  100.                 return 1;
  101.             }
  102.             if(listitem == 6)
  103.             {
  104.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_INPUT, inputtext, "Escribe el ID o parte del nombre del jugador que desea kickear", "Kickear", "Cancelar");
  105.                 SetPVarInt(playerid, "DialogRCON", listitem);
  106.                 return 1;
  107.             }
  108.             if(listitem == 7)
  109.             {
  110.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_INPUT, inputtext, "Escribe el ID o parte del nombre del jugador que desea banear", "Banear", "Cancelar");
  111.                 SetPVarInt(playerid, "DialogRCON", listitem);
  112.                 return 1;
  113.             }
  114.             if(listitem == 8)
  115.             {
  116.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_INPUT, inputtext, "Escribe el nombre del gamemode que desea usar\nNo es necesario colocar el '.amx' al final", "Cambiar", "Cancelar");
  117.                 SetPVarInt(playerid, "DialogRCON", listitem);
  118.                 return 1;
  119.             }
  120.             if(listitem == 9)
  121.             {
  122.                 SendRconCommand("reloadbans");
  123.                 SendClientMessage(playerid, -1, "Archivo de baneos");
  124.                 SendClientMessage(playerid, -1, "--------");
  125.                 SendClientMessage(playerid, -1, " Cargado: samp.ban");
  126.                 return 1;
  127.             }
  128.             if(listitem == 10)
  129.             {
  130.                 SendRconCommand("reloadlog");
  131.                 SendClientMessage(playerid, -1, "---------");
  132.                 SendClientMessage(playerid, -1, "Archivo de log recargado: 'server_log.txt'.");
  133.                 SendClientMessage(playerid, -1, "---------");
  134.                 return 1;
  135.             }
  136.             if(listitem == 11)
  137.             {
  138.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_INPUT, inputtext, "Escribe el mensaje que desea enviar a los jugadores.", "Enviar", "Cancelar");
  139.                 SetPVarInt(playerid, "DialogRCON", listitem);
  140.                 return 1;
  141.             }
  142.             if(listitem == 12)
  143.             {
  144. #if defined VerJugadores
  145.                 new dialog[76*MAX_PLAYERS], string[76], ip[16], nombre[MAX_PLAYER_NAME];
  146.                 for(new i = 0; i < MAX_PLAYERS; i++)
  147.                 {
  148.                     if(IsPlayerConnected(i))
  149.                     {
  150.                         GetPlayerName(i, nombre, sizeof(nombre));
  151.                         GetPlayerIp(i, ip, sizeof(ip));
  152.                         if(IsPlayerNPC(playerid)) format(string, sizeof(string), "[BOT] [ID: %d] %s - IP: %s - Ping: %d\n", i, nombre, ip, GetPlayerPing(i));
  153.                         else format(string, sizeof(string), "[ID: %d] %s - IP: %s - Ping: %d\n", i, nombre, ip, GetPlayerPing(i));
  154.                         strcat(dialog, string);
  155.                     }
  156.                 }
  157.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_MSGBOX, inputtext, dialog, "Ok", "");
  158. #else
  159.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_MSGBOX, inputtext, "Esta opción debe activarse en el script", "Ok", "");
  160. #endif
  161.                 SetPVarInt(playerid, "DialogRCON", listitem);
  162.                 return 1;
  163.             }
  164.             if(listitem == 13)
  165.             {
  166.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_INPUT, inputtext, "Escribe la dirección de IP que deseas banear.", "Banear", "Cancelar");
  167.                 SetPVarInt(playerid, "DialogRCON", listitem);
  168.                 return 1;
  169.             }
  170.             if(listitem == 14)
  171.             {
  172.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_INPUT, inputtext, "Escribe la dirección de IP que deseas desbanear.", "Desbanear", "Cancelar");
  173.                 SetPVarInt(playerid, "DialogRCON", listitem);
  174.                 return 1;
  175.             }
  176.             if(listitem == 15)
  177.             {
  178.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_INPUT, inputtext, "Escribe la cantidad de gravedad que desea colocar.", "Colocar", "Cancelar");
  179.                 SetPVarInt(playerid, "DialogRCON", listitem);
  180.                 return 1;
  181.             }
  182.             if(listitem == 16)
  183.             {
  184.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_INPUT, inputtext, "Escribe la ID del clima que desea colocar.", "Colocar", "Cancelar");
  185.                 SetPVarInt(playerid, "DialogRCON", listitem);
  186.                 return 1;
  187.             }
  188.             if(listitem == 17)
  189.             {
  190.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_INPUT, inputtext, "Escribe el nombre del filterscript que desea cargar\nNo es necesario colocar el '.amx' al final", "Cargar", "Cancelar");
  191.                 SetPVarInt(playerid, "DialogRCON", listitem);
  192.                 return 1;
  193.             }
  194.             if(listitem == 18)
  195.             {
  196.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_INPUT, inputtext, "Escribe la URL de la página web que deseas colocar.", "Colocar", "Cancelar");
  197.                 SetPVarInt(playerid, "DialogRCON", listitem);
  198.                 return 1;
  199.             }
  200.             if(listitem == 19)
  201.             {
  202.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_INPUT, inputtext, "Escribe el nombre del filterscript que desea descargar\nNo es necesario colocar el '.amx' al final", "Descargar", "Cancelar");
  203.                 SetPVarInt(playerid, "DialogRCON", listitem);
  204.                 return 1;
  205.             }
  206.             if(listitem == 20)
  207.             {
  208.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_INPUT, inputtext, "Escribe el nombre del filterscript que desea recargar\nNo es necesario colocar el '.amx' al final", "Recargar", "Cancelar");
  209.                 SetPVarInt(playerid, "DialogRCON", listitem);
  210.                 return 1;
  211.             }
  212.             if(listitem == 21)
  213.             {
  214.                 ShowPlayerDialog(playerid, DialogRCON2, DIALOG_STYLE_PASSWORD, inputtext, "Escribe la nueva contraseña del RCON que deseas colocar.", "Cambiar", "Cancelar");
  215.                 SetPVarInt(playerid, "DialogRCON", listitem);
  216.                 return 1;
  217.             }
  218.             return 1;
  219.         }
  220.         case DialogRCON2:
  221.         {
  222.             new string[256];
  223.             if(!response) return 1;
  224.             if(!IsPlayerAdmin(playerid)) return 1;
  225.             if(GetPVarInt(playerid, "DialogRCON") == 1)
  226.             {
  227.                 format(string, sizeof(string), "echo %s", inputtext);
  228.                 SendRconCommand(string);
  229.             }
  230.             if(GetPVarInt(playerid, "DialogRCON") == 2)
  231.             {
  232.                 format(string, sizeof(string), "hostname %s", inputtext);
  233.                 SendRconCommand(string);
  234.             }
  235.             if(GetPVarInt(playerid, "DialogRCON") == 3)
  236.             {
  237.                 format(string, sizeof(string), "gamemodetext %s", inputtext);
  238.                 SendRconCommand(string);
  239.             }
  240.             if(GetPVarInt(playerid, "DialogRCON") == 4)
  241.             {
  242.                 format(string, sizeof(string), "mapname %s", inputtext);
  243.                 SendRconCommand(string);
  244.             }
  245.             if(GetPVarInt(playerid, "DialogRCON") == 5)
  246.             {
  247.                 format(string, sizeof(string), "exec %s", inputtext);
  248.                 SendRconCommand(string);
  249.             }
  250.             if(GetPVarInt(playerid, "DialogRCON") == 6)
  251.             {
  252.                 new usuario = ReturnUser(inputtext);
  253.                 if(IsPlayerConnected(usuario)) Kick(usuario);
  254.             }
  255.             if(GetPVarInt(playerid, "DialogRCON") == 7)
  256.             {
  257.                 new usuario = ReturnUser(inputtext);
  258.                 if(IsPlayerConnected(usuario)) Ban(usuario);
  259.             }
  260.             if(GetPVarInt(playerid, "DialogRCON") == 8)
  261.             {
  262.                 format(string, sizeof(string), "changemode %s", inputtext);
  263.                 SendRconCommand(string);
  264.             }
  265.             if(GetPVarInt(playerid, "DialogRCON") == 11)
  266.             {
  267.                 format(string, sizeof(string), "say %s", inputtext);
  268.                 SendRconCommand(string);
  269.             }
  270.             if(GetPVarInt(playerid, "DialogRCON") == 13)
  271.             {
  272.                 format(string, sizeof(string), "banip %s", inputtext);
  273.                 SendRconCommand(string);
  274.                 SendRconCommand("reloadbans");
  275.             }
  276.             if(GetPVarInt(playerid, "DialogRCON") == 14)
  277.             {
  278.                 format(string, sizeof(string), "unbanip %s", inputtext);
  279.                 SendRconCommand(string);
  280.                 SendRconCommand("reloadbans");
  281.             }
  282.             if(GetPVarInt(playerid, "DialogRCON") == 15)
  283.             {
  284.                 SetGravity(floatstr(inputtext));
  285.             }
  286.             if(GetPVarInt(playerid, "DialogRCON") == 16)
  287.             {
  288.                 SetWeather(strval(inputtext));
  289.             }
  290.             if(GetPVarInt(playerid, "DialogRCON") == 17)
  291.             {
  292.                 format(string, sizeof(string), "loadfs %s", inputtext);
  293.                 SendRconCommand(string);
  294.             }
  295.             if(GetPVarInt(playerid, "DialogRCON") == 18)
  296.             {
  297.                 format(string, sizeof(string), "weburl %s", inputtext);
  298.                 SendRconCommand(string);
  299.             }
  300.             if(GetPVarInt(playerid, "DialogRCON") == 19)
  301.             {
  302.                 format(string, sizeof(string), "unloadfs %s", inputtext);
  303.                 SendRconCommand(string);
  304.             }
  305.             if(GetPVarInt(playerid, "DialogRCON") == 20)
  306.             {
  307.                 format(string, sizeof(string), "reloadfs %s", inputtext);
  308.                 SendRconCommand(string);
  309.             }
  310.             if(GetPVarInt(playerid, "DialogRCON") == 21)
  311.             {
  312.                 format(string, sizeof(string), "rcon_password %s", inputtext);
  313.                 SendRconCommand(string);
  314.             }
  315.             return 1;
  316.         }
  317.     }
  318.     return 0;
  319. }
  320.  
  321. stock IsNumeric(const string[])
  322. {
  323.     for (new i = 0, j = strlen(string); i < j; i++)
  324.     {
  325.         if (string[i] > '9' || string[i] < '0') return 0;
  326.     }
  327.     return 1;
  328. }
  329.  
  330. stock ReturnUser(text[], playerid = INVALID_PLAYER_ID)
  331. {
  332.     new pos = 0;
  333.     while (text[pos] < 0x21) // Strip out leading spaces
  334.     {
  335.         if (text[pos] == 0) return INVALID_PLAYER_ID; // No passed text
  336.         pos++;
  337.     }
  338.     new userid = INVALID_PLAYER_ID;
  339.     if (IsNumeric(text[pos])) // Check whole passed string
  340.     {
  341.         // If they have a numeric name you have a problem (although names are checked on id failure)
  342.         userid = strval(text[pos]);
  343.         if (userid >=0 && userid < MAX_PLAYERS)
  344.         {
  345.             if(!IsPlayerConnected(userid))
  346.             {
  347.                 /*if (playerid != INVALID_PLAYER_ID)
  348.                 {
  349.                     SendClientMessage(playerid, 0xFF0000AA, "User not connected");
  350.                 }*/
  351.                 userid = INVALID_PLAYER_ID;
  352.             }
  353.             else
  354.             {
  355.                 return userid; // A player was found
  356.             }
  357.         }
  358.         /*else
  359.         {
  360.             if (playerid != INVALID_PLAYER_ID)
  361.             {
  362.                 SendClientMessage(playerid, 0xFF0000AA, "Invalid user ID");
  363.             }
  364.             userid = INVALID_PLAYER_ID;
  365.         }
  366.         return userid;*/
  367.         // Removed for fallthrough code
  368.     }
  369.     // They entered [part of] a name or the id search failed (check names just incase)
  370.     new len = strlen(text[pos]);
  371.     new count = 0;
  372.     new name[MAX_PLAYER_NAME];
  373.     for (new i = 0; i < MAX_PLAYERS; i++)
  374.     {
  375.         if (IsPlayerConnected(i))
  376.         {
  377.             GetPlayerName(i, name, sizeof (name));
  378.             if (strcmp(name, text[pos], true, len) == 0) // Check segment of name
  379.             {
  380.                 if (len == strlen(name)) // Exact match
  381.                 {
  382.                     return i; // Return the exact player on an exact match
  383.                     // Otherwise if there are two players:
  384.                     // Me and MeYou any time you entered Me it would find both
  385.                     // And never be able to return just Me's id
  386.                 }
  387.                 else // Partial match
  388.                 {
  389.                     count++;
  390.                     userid = i;
  391.                 }
  392.             }
  393.         }
  394.     }
  395.     if (count != 1)
  396.     {
  397.         if (playerid != INVALID_PLAYER_ID)
  398.         {
  399.             if (count)
  400.             {
  401.                 SendClientMessage(playerid, 0xFF0000AA, "Se encontraron múltiples usuarios, intente hacer la búsqueda más específica");
  402.             }
  403.             else
  404.             {
  405.                 SendClientMessage(playerid, 0xFF0000AA, "No se encontró ningún usuario");
  406.             }
  407.         }
  408.         userid = INVALID_PLAYER_ID;
  409.     }
  410.     if(IsPlayerNPC(userid)) userid = INVALID_PLAYER_ID;
  411.     return userid; // INVALID_USER_ID for bad return
  412. }
Advertisement
Add Comment
Please, Sign In to add comment