Advertisement
iSmirnoff

banMySQL v0.01

Nov 26th, 2013
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 28.18 KB | None | 0 0
  1. /*
  2.                             - Todos os Créditos -
  3.  
  4.                     [ iCmd 7.1 ]:               [iPs]Bruno
  5.                     [ iBits ]:                  [iPs]Willian
  6.                     [ MySQL ]:                  BlueG
  7.                     [ SSCANF2 ]:                Y_Less
  8.                     [ DOF2 ]:                   Double-O-Seven
  9.                     [ ZCMD ]:                   Zeex
  10.  
  11. */
  12. // ============================== //
  13. //            # INCLUDES #        //
  14. // ============================== //
  15. #include  <      A_SAMP      >  
  16. #include  <       iBits      >
  17.  
  18. #define CmD     2 // 1 == ZCMD + SSCANF    - 2 == iPs Commands
  19. #define SAVE    2 // 1 == DOF2             - 2 == MySQL
  20.  
  21. #if CmD == 1
  22.     #include <  ZCMD   >
  23.     #include < SSCANF2 >
  24. #else
  25.     #include < iCmd71 >
  26. #endif
  27.  
  28. #if SAVE == 1
  29.     #include < DOF2 >
  30. #else
  31.     #include < A_MySQL >
  32.  
  33.     #define HostName    "localhost" // Url do Host
  34.     #define UserName    "root"      // Login
  35.     #define DataName    "ForumSAMP" // Data Base
  36.     #define PassName    ""          // Senha
  37.  
  38.     new salvarSenha [ 30 ] ;
  39.     new MySQLConnect ;
  40.  
  41.     forward checkIpBan ( idCheck, ipBanned[] ) ;
  42.     forward checkNickBan ( idCheck, nickBanned[] ) ;
  43.     forward carregarBanido ( playerid ) ;
  44.     forward playerLogin ( playerid ) ;
  45.     forward verificacaoLogin ( playerid ) ;
  46.  
  47. #endif
  48.  
  49. #define Kick(%0) SetTimerEx("Kicka", 100, false, "i", %0)
  50.  
  51. #define dialogCheckBan   (0)
  52. #define dialogBan        (1)
  53. #define dialogRegistro   (2)
  54. #define dialogLogin      (3)
  55.  
  56. new Segundo, Minuto, Hora, Dia, Mes, Ano ;
  57. new adminBan [ 21 ], motivoBan [ 50 ], dataBan [ 10 ], horaBan [ 15 ], nickBan [ 21 ], ipBan [ 16 ] ;
  58. new bit1:varLogado<MAX_PLAYERS>;
  59. new bit2:varBanido<MAX_PLAYERS>;
  60.  
  61. new varSenha  [ 30 ] ;
  62. new varNick   [ 21 ] ;
  63.  
  64.  
  65. forward carregarBanidos ( playerid ) ;
  66. forward salvarContas ( playerid ) ;
  67. forward carregarContas ( playerid ) ;
  68. forward Kicka ( p ) ;
  69. forward carregandoAll ( playerid ) ;
  70.  
  71.  
  72.  
  73. public OnFilterScriptInit () {
  74.  
  75.     #if SAVE == 2
  76.         MySQLConnect = mysql_connect ( HostName, UserName, DataName, PassName ) ;
  77.  
  78.         mysql_function_query ( MySQLConnect,  "CREATE TABLE IF NOT EXISTS `usuarios` ( `ID` int ( 11 ) NOT NULL AUTO_INCREMENT, `Nick` varchar ( 21 ), `Senha` VARCHAR ( 50 ), `Banido` INT ( 11 ), PRIMARY KEY (`ID`) )", false, #, # ) ;
  79.  
  80.         mysql_function_query ( MySQLConnect,  "CREATE TABLE IF NOT EXISTS `banidos` ( `ID` int ( 11 ) NOT NULL AUTO_INCREMENT, `Nick` varchar ( 21 ), `IP` VARCHAR ( 16 ), `Motivo` VARCHAR ( 50 ), `Admin` VARCHAR ( 21 ), `Hora` VARCHAR ( 15 ), PRIMARY KEY (`ID`) )", false, #, # ) ;  
  81.         if ( mysql_ping () >= 1 ) {
  82.  
  83.             print("# ------------------------------------ #") ;
  84.             print("# [ MYSQL ]: Banco de Dados carregado  #") ;
  85.         }
  86.         else {
  87.  
  88.             print("# ------------------------------------ #") ;
  89.             print("# [ MYSQL ]: Erro no Banco de Dados    #") ;
  90.         }
  91.     #endif
  92.     return true ;
  93. }
  94. public OnFilterScriptExit () {
  95.  
  96.     #if SAVE == 1
  97.         DOF2::Exit () ;
  98.     #else
  99.         mysql_close ( MySQLConnect ) ;
  100.     #endif
  101.     return true ;
  102. }
  103.  
  104. public Kicka ( p ) {
  105.  
  106.     #undef Kick
  107.         Kick ( p ) ;
  108.     #define Kick(%0) SetTimerEx("Kicka", 100, false, "i", %0)
  109.     return true ;
  110. }
  111.  
  112. public carregandoAll ( playerid ) {
  113.  
  114.     if ( getBit2 ( varBanido, playerid ) == 1 ) {
  115.  
  116.         new celulasBan [ 128 ], celulas [ 128 ] ;
  117.  
  118.         strcat ( celulasBan, "Banido do Servidor\n\n" ) ;
  119.  
  120.         format ( celulas, 70, "%s, Você está banido do Servidor\n\n", Nome ( playerid ) ) ;
  121.         strcat ( celulasBan, celulas ) ;
  122.  
  123.         format ( celulas, 35, "Motivo: %s\n\n", motivoBan [ playerid ] ) ;
  124.         strcat ( celulasBan, celulas ) ;
  125.  
  126.         format ( celulas, 30, "Admin: %s\n\n", adminBan [ playerid ] ) ;
  127.         strcat ( celulasBan, celulas ) ;
  128.  
  129.         format ( celulas, 20, "Data: %s\n\n", dataBan [ playerid ] ) ;
  130.         strcat ( celulasBan, celulas ) ;
  131.  
  132.         format ( celulas, 20, "Hora: %s", horaBan [ playerid ] ) ;
  133.         strcat ( celulasBan, celulas ) ;
  134.  
  135.         ShowPlayerDialog ( playerid, dialogBan, DIALOG_STYLE_MSGBOX, "Você está banido", celulasBan, "Cancelar", # ) ;
  136.         Kick ( playerid ) ;
  137.     }
  138.     else {
  139.  
  140.         #if SAVE == 1
  141.  
  142.             new Arquivo [ 64 ], Celulas [ 250 ] ;
  143.             format ( Arquivo, 64, "Contas/%s.ini", Nome ( playerid ) ) ;
  144.  
  145.             if ( DOF2::FileExists ( Arquivo ) ) {
  146.  
  147.                 format ( Celulas, 220, "{00F200}Registrado\n\n{FFFFFF}Olá {07C3F7}%s, {FFFFFF}Você está registrado em nosso servidor digite sua senha para logar\n\n{FFFFFF}Caso não queira logar clique em 'Sair' para sair do Servidor", Nome ( playerid ) ) ;
  148.                 ShowPlayerDialog ( playerid, dialogLogin, DIALOG_STYLE_INPUT, "Login Necessário", Celulas, "Logar", "Sair" ) ;
  149.             }
  150.             else {
  151.  
  152.                 format ( Celulas, 250, "{FC0000}Não Registrado\n\n{FFFFFF}Olá {07C3F7}%s, {FFFFFF}Você não está registrado em nosso servidor, você pode se registrar agora\n\n{FFFFFF}Ou você pode entrar em nosso site e se registrar\n\n{FFFFFF}Agradecemos a prefencia.", Nome ( playerid ) ) ;
  153.                 ShowPlayerDialog ( playerid, dialogRegistro, DIALOG_STYLE_INPUT, "Não Registrado", Celulas, "Registrar", "Sair" ) ;
  154.             }
  155.         #else
  156.             new Row, Field, Celulas [ 80 ] ;
  157.             cache_get_data ( Row, Field, MySQLConnect ) ;
  158.             format( Celulas , 80, "SELECT * FROM `usuarios` WHERE `Nick` = '%s' LIMIT 1" , Nome ( playerid ) ) ;
  159.             mysql_function_query ( MySQLConnect, Celulas, true, "playerLogin", "i", playerid ) ;
  160.         #endif
  161.     }
  162.     return true ;
  163. }
  164. public OnPlayerConnect ( playerid ) {
  165.  
  166.     #if SAVE == 1
  167.         carregarContas ( playerid ) ;
  168.     #else
  169.         new Celulas [ 100 ] ;
  170.         format ( Celulas, 100, "SELECT * FROM `usuarios` WHERE `Nick`='%s' LIMIT 1", Nome ( playerid )  ) ;
  171.         mysql_function_query ( MySQLConnect, Celulas, true, "carregarContas", "i", playerid ) ;
  172.     #endif
  173.  
  174.     carregarBanidos ( playerid ) ;
  175.     SendClientMessage ( playerid, -1, "Carregando sua Conta... Aguarde 5 Segundos" ) ;
  176.     SetTimerEx("carregandoAll", 5000, 0, "i", playerid ) ;
  177.     return true ;
  178. }
  179.  
  180. public OnPlayerDisconnect ( playerid, reason ) {
  181.  
  182.     if ( getBit1 ( varLogado, playerid ) == 1 ) {
  183.  
  184.         salvarContas ( playerid ) ;
  185.     }
  186.     return true ;
  187. }
  188.  
  189. public OnDialogResponse ( playerid, dialogid, response, listitem, inputtext [ ] ) {
  190.  
  191.     switch ( dialogid ) {
  192.  
  193.         case dialogRegistro: {
  194.  
  195.             if ( !response )
  196.                 return Kick ( playerid ) ;
  197.  
  198.             if ( !strlen ( inputtext ) ) {
  199.  
  200.                 new Celulas [ 220 ] ;
  201.                 format ( Celulas, 220, "{00F200}Registrado\n\n{FFFFFF}Olá {07C3F7}%s, {FFFFFF}Você está registrado em nosso servidor digite sua senha para logar\n\n{FFFFFF}Caso não queira logar clique em Sair para sair do Servidor", Nome ( playerid ) ) ;
  202.                 ShowPlayerDialog ( playerid, dialogLogin, DIALOG_STYLE_INPUT, "Login Necessário", Celulas, "Logar", "Sair" ) ;
  203.             }
  204.             #if SAVE == 1
  205.                 new Arquivo [ 64 ] ;
  206.                 format ( Arquivo, 64, "Contas/%s.ini", Nome ( playerid ) ) ;
  207.                 DOF2::CreateFile ( Arquivo ) ;
  208.                 DOF2::SetString ( Arquivo, "Nick", Nome ( playerid ) ) ;
  209.                 DOF2::SetString ( Arquivo, "Senha", inputtext ) ;
  210.                 DOF2::SetInt ( Arquivo, "Banido", getBit2 ( varBanido, playerid ) ) ;
  211.                 DOF2::SaveFile () ;
  212.                 SetSpawnInfo( playerid, 1, 29, 1958.33, 1343.12, 15.36, 269.15, 26, 36, 28, 150, 0, 0 ) ;
  213.                 SpawnPlayer ( playerid ) ;
  214.                 SendClientMessage ( playerid, -1, "REGISTRADO COM SUCESSO" ) ;
  215.                 setBit1 ( varLogado, playerid, 1 ) ;
  216.             #else
  217.                 new Celulas [ 90 ] ;
  218.                 format ( Celulas, 90, "INSERT INTO `usuarios` (`Nick`, `Senha`, `Banido`) VALUES ('%s', '%s', '0')", Nome ( playerid ), inputtext  ) ;
  219.                 mysql_function_query ( MySQLConnect, Celulas, false, #, # ) ;
  220.                 strmid ( varSenha [ playerid ], inputtext, 0, strlen ( inputtext ), 50 ) ;
  221.                 SetSpawnInfo( playerid, 1, 29, 1958.33, 1343.12, 15.36, 269.15, 26, 36, 28, 150, 0, 0 ) ;
  222.                 SpawnPlayer ( playerid ) ;
  223.                 SendClientMessage ( playerid, -1, "REGISTRADO COM SUCESSO" ) ;
  224.                 setBit1 ( varLogado, playerid, 1 ) ;
  225.             #endif
  226.         }
  227.         case dialogLogin: {
  228.  
  229.             if ( !response )
  230.                 return Kick ( playerid ) ;
  231.  
  232.             if ( !strlen ( inputtext ) ) {
  233.  
  234.                 new Celulas [ 220 ] ;
  235.                 format ( Celulas, 220, "{00F200}Registrado\n\n{FFFFFF}Olá {07C3F7}%s, {FFFFFF}Você está registrado em nosso servidor digite sua senha para logar\n\n{FFFFFF}Caso não queira logar clique em 'Sair' para sair do Servidor", Nome ( playerid ) ) ;
  236.                 ShowPlayerDialog ( playerid, dialogLogin, DIALOG_STYLE_INPUT, "Login Necessário", Celulas, "Logar", "Sair" ) ;
  237.             }
  238.             #if SAVE == 1
  239.                 new Arquivo [ 64 ] ;
  240.                 format ( Arquivo, 64, "Contas/%s.ini", Nome ( playerid ) ) ;
  241.                 if ( !strcmp ( inputtext, DOF2::GetString ( Arquivo, "Senha" ), false ) ) {
  242.  
  243.                     SetSpawnInfo( playerid, 1, 29, 1958.33, 1343.12, 15.36, 269.15, 26, 36, 28, 150, 0, 0 ) ;
  244.                     SpawnPlayer ( playerid ) ;
  245.                     SendClientMessage ( playerid, -1, "LOGADO COM SUCESSO" ) ;
  246.                     setBit1 ( varLogado, playerid, 1 ) ;
  247.                 }
  248.                 else {
  249.  
  250.                     new Celulas [ 220 ] ;
  251.                     format ( Celulas, 220, "{00F200}Registrado\n\n{FFFFFF}Olá {07C3F7}%s, {FFFFFF}Você está registrado em nosso servidor digite sua senha para logar\n\n{FFFFFF}Caso não queira logar clique em Sair para sair do Servidor", Nome ( playerid ) ) ;
  252.                     ShowPlayerDialog ( playerid, dialogLogin, DIALOG_STYLE_INPUT, "Login Necessário", Celulas, "Logar", "Sair" ) ;
  253.                     SendClientMessage ( playerid, -1, "VOCÊ ERROU SUA SENHA, TENTE NOVAMENTE !" ) ;
  254.                 }
  255.             #else
  256.                 new Celulas [ 90 ] ;
  257.                 strmid ( salvarSenha [ playerid ], inputtext, 0, strlen ( inputtext ), 50 ) ;
  258.                 format ( Celulas, 90, "SELECT * FROM `usuarios` WHERE `Nick`='%s' AND `Senha`='%s'", Nome ( playerid ), inputtext ) ;
  259.                 mysql_function_query ( MySQLConnect, Celulas, true, "verificacaoLogin", "i", playerid ) ;
  260.             #endif
  261.          }
  262.     }
  263.     return true ;
  264. }
  265. #if SAVE == 2
  266.     public playerLogin ( playerid ) {
  267.  
  268.         new Row, Field, Celulas [ 250 ] ;
  269.         cache_get_data ( Row, Field, MySQLConnect ) ;
  270.  
  271.         if ( Row ) {
  272.  
  273.             format ( Celulas, 220, "{00F200}Registrado\n\n{FFFFFF}Olá {07C3F7}%s, {FFFFFF}Você está registrado em nosso servidor digite sua senha para logar\n\n{FFFFFF}Caso não queira logar clique em Sair para sair do Servidor", Nome ( playerid ) ) ;
  274.             ShowPlayerDialog ( playerid, dialogLogin, DIALOG_STYLE_INPUT, "Login Necessário", Celulas, "Logar", "Sair" ) ;
  275.         }
  276.         else {
  277.  
  278.             format ( Celulas, 250, "{FC0000}Não Registrado\n\n{FFFFFF}Olá {07C3F7}%s, {FFFFFF}Você não está registrado em nosso servidor, você pode se registrar agora\n\n{FFFFFF}Ou você pode ir até o nosso site e se registrar\n\n{FFFFFF}Agradecemos a prefencia.", Nome ( playerid ) ) ;
  279.             ShowPlayerDialog ( playerid, dialogRegistro, DIALOG_STYLE_INPUT, "Não Registrado", Celulas, "Registrar", "Sair" ) ;
  280.         }
  281.         return true ;
  282.     }
  283.     public verificacaoLogin ( playerid ) {
  284.  
  285.         new Row, Field, Celulas [ 332 ] ;
  286.         cache_get_data ( Row, Field, MySQLConnect ) ;
  287.  
  288.         if ( Row ) {
  289.  
  290.             strmid ( varSenha [ playerid ], salvarSenha [ playerid ], 0, strlen ( salvarSenha [ playerid ] ), 50 ) ;
  291.             SetSpawnInfo( playerid, 0, 230, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0 );
  292.             SpawnPlayer ( playerid ) ;
  293.             setBit1 ( varLogado, playerid, 1 ) ;
  294.         }
  295.         else {
  296.  
  297.             format ( Celulas, 220, "{00F200}Registrado\n\n{FFFFFF}Olá {07C3F7}%s, {FFFFFF}Você está registrado em nosso servidor digite sua senha para logar\n\n{FFFFFF}Caso não queira logar clique em Sair para sair do Servidor", Nome ( playerid ) ) ;
  298.             ShowPlayerDialog ( playerid, dialogLogin, DIALOG_STYLE_INPUT, "Login Necessário", Celulas, "Logar", "Sair");
  299.             SendClientMessage ( playerid, -1, "VOCÊ ERROU SUA SENHA, TENTE NOVAMENTE !" ) ;
  300.         }
  301.         return true ;
  302.     }
  303. #endif
  304. public salvarContas ( playerid ) {
  305.  
  306.     #if SAVE == 1
  307.         new Arquivo [ 64 ] ;
  308.         format ( Arquivo, 64, "Contas/%s.ini", Nome ( playerid ) ) ;
  309.  
  310.         if ( !DOF2::FileExists ( Arquivo ) ) DOF2::CreateFile ( Arquivo ) ; {
  311.  
  312.             DOF2::SetString ( Arquivo, "Nick", varNick [ playerid ] ) ;
  313.             DOF2::SetString ( Arquivo, "Senha", varSenha [ playerid ] ) ;
  314.             DOF2::SetInt ( Arquivo, "Banido", getBit2 ( varBanido, playerid ) ) ;
  315.             DOF2::SaveFile() ;
  316.         }
  317.     #else
  318.         new myQuery [ 135 ] ;
  319.         format ( myQuery, 135, "UPDATE `usuarios` SET `Nick`='%s', `Senha`='%s', `Banido`='%i' WHERE `Nick`= '%s'", Nome ( playerid ), varSenha [ playerid ], getBit2 ( varBanido, playerid ), Nome ( playerid ) ) ;
  320.         mysql_function_query ( MySQLConnect, myQuery, true, #, # ) ;
  321.     #endif
  322.     return true ;
  323. }
  324.  
  325. public carregarContas ( playerid ) {
  326.  
  327.     #if SAVE == 1
  328.         new Arquivo [ 64 ] ;
  329.         format ( Arquivo, 64, "Contas/%s.ini", Nome ( playerid ) ) ;
  330.  
  331.         if ( DOF2::FileExists ( Arquivo ) ) {
  332.  
  333.             strmid ( varNick [ playerid ], DOF2::GetString ( Arquivo, "Nick" ), 0, strlen ( DOF2::GetString ( Arquivo, "Nick" ) ), 21 ) ;
  334.             strmid ( varSenha [ playerid ], DOF2::GetString ( Arquivo, "Senha" ), 0, strlen ( DOF2::GetString ( Arquivo, "Senha" ) ), 50 ) ;
  335.             setBit2 ( varBanido, playerid, DOF2::GetInt ( Arquivo, "Banido" ) ) ;
  336.         }
  337.     #else
  338.         new rows, fields, vaLor [ 10 ] ;
  339.         cache_get_data ( rows, fields, MySQLConnect ) ;
  340.         cache_get_field_content ( 0, "Nick", varNick [ playerid ], MySQLConnect ) ;
  341.         cache_get_field_content ( 0, "Senha", varSenha [ playerid ], MySQLConnect ) ;
  342.         cache_get_field_content ( 0, "Banido", vaLor, MySQLConnect ) ;
  343.         setBit2 ( varBanido, playerid, strval ( vaLor ) ) ;
  344.     #endif
  345.     return true ;
  346. }
  347.  
  348. public carregarBanidos ( playerid ) {
  349.  
  350.     #if SAVE == 1
  351.         new Arquivo [ 64 ] ;
  352.         format ( Arquivo, 64, "Banidos/%s.ini", Nome ( playerid ) ) ;
  353.  
  354.         if ( DOF2::FileExists ( Arquivo ) ) {
  355.  
  356.             strmid ( varNick [ playerid ], DOF2::GetString ( Arquivo, "Nick" ), 0, strlen ( DOF2::GetString ( Arquivo, "Nick" ) ), 21 ) ;
  357.             strmid ( motivoBan [ playerid ], DOF2::GetString ( Arquivo, "Motivo" ), 0, strlen ( DOF2::GetString ( Arquivo, "Motivo" ) ), 50 ) ;
  358.             strmid ( adminBan [ playerid ], DOF2::GetString ( Arquivo, "Admin" ), 0, strlen ( DOF2::GetString ( Arquivo, "Admin" ) ), 50 ) ;
  359.             strmid ( dataBan [ playerid ], DOF2::GetString ( Arquivo, "Data" ), 0, strlen ( DOF2::GetString ( Arquivo, "Data" ) ), 50 ) ;
  360.             strmid ( horaBan [ playerid ], DOF2::GetString ( Arquivo, "Hora" ), 0, strlen ( DOF2::GetString ( Arquivo, "Hora" ) ), 50 ) ;
  361.             strmid ( ipBan [ playerid ], DOF2::GetString ( Arquivo, "IP" ), 0, strlen ( DOF2::GetString ( Arquivo, "IP" ) ), 50 ) ;
  362.         }
  363.         new ipBanido [ 16 ] ;
  364.         GetPlayerIp ( playerid, ipBanido, 16 ) ;
  365.  
  366.         format ( Arquivo, 64, "iPsBanidos/%s.ini", ipBanido ) ;
  367.  
  368.         if ( DOF2::FileExists ( Arquivo ) ) {
  369.  
  370.             strmid ( varNick [ playerid ], DOF2::GetString ( Arquivo, "Nick" ), 0, strlen ( DOF2::GetString ( Arquivo, "Nick" ) ), 21 ) ;
  371.             strmid ( motivoBan [ playerid ], DOF2::GetString ( Arquivo, "Motivo" ), 0, strlen ( DOF2::GetString ( Arquivo, "Motivo" ) ), 50 ) ;
  372.             strmid ( adminBan [ playerid ], DOF2::GetString ( Arquivo, "Admin" ), 0, strlen ( DOF2::GetString ( Arquivo, "Admin" ) ), 50 ) ;
  373.             strmid ( dataBan [ playerid ], DOF2::GetString ( Arquivo, "Data" ), 0, strlen ( DOF2::GetString ( Arquivo, "Data" ) ), 50 ) ;
  374.             strmid ( horaBan [ playerid ], DOF2::GetString ( Arquivo, "Hora" ), 0, strlen ( DOF2::GetString ( Arquivo, "Hora" ) ), 50 ) ;
  375.         }
  376.     #else
  377.         new myQuery [ 128 ] ;
  378.         format ( myQuery, 128, "SELECT * FROM `banidos` WHERE `Nick` = '%s' LIMIT 1", Nome ( playerid ) ) ;
  379.         mysql_function_query ( MySQLConnect, myQuery, true, "carregarBanido", "i", playerid ) ;
  380.        
  381.        
  382.     #endif
  383.     return true ;
  384. }
  385. #if SAVE == 2
  386.     public carregarBanido ( playerid ) {
  387.  
  388.         new rows, fields ;
  389.         cache_get_data ( rows, fields, MySQLConnect ) ;
  390.         cache_get_field_content ( 0, "Nick", nickBan [ playerid ], MySQLConnect ) ;
  391.         cache_get_field_content ( 0, "Motivo", motivoBan [ playerid ], MySQLConnect ) ;
  392.         cache_get_field_content ( 0, "Admin", adminBan [ playerid ], MySQLConnect ) ;
  393.         cache_get_field_content ( 0, "Data", dataBan [ playerid ], MySQLConnect ) ;
  394.         cache_get_field_content ( 0, "Hora", horaBan [ playerid ], MySQLConnect ) ;
  395.         return true ;
  396.     }
  397. #endif
  398. #if CmD == 2
  399.     public OnPlayerCommandText ( playerid, commandid, params[] ) {
  400.  
  401.             switch ( commandid ) {
  402.  
  403.                 case iscmd ( "b,a,n,i,r" ) : {
  404.  
  405.                     if (!param ( "us[50]" ) )
  406.                         return SendClientMessage ( playerid, -1, "[ USE ]: /banir [ID] [Motivo]" ) ;
  407.  
  408.                     funcaoBanP ( getp($0), playerid, gets($1) ) ;
  409.                     return true ;
  410.                 }
  411.                 case iscmd ( "c,h,e,c,a,r,i,p" ): {
  412.  
  413.                     if (!param ( "s[16]") )
  414.                         return SendClientMessage ( playerid, -1, "[ USE ]: /checarip [IP]" ) ;
  415.  
  416.                     funcaoChecarIPBan ( gets($0), playerid ) ;
  417.                     return true ;
  418.                 }
  419.                 case iscmd ( "c,h,e,c,a,r,n,i,c,k" ): {
  420.  
  421.                     if (!param ( "s[21]") )
  422.                         return SendClientMessage ( playerid, -1, "[ USE ]: /checarnick [Nick]" ) ;
  423.  
  424.                     funcaoChecarNickBan ( gets($0), playerid ) ;
  425.                     return true ;
  426.                 }
  427.                 case iscmd ( "d,e,s,b,a,n,i,p" ): {
  428.  
  429.                     if (!param ( "s[16]" ) )
  430.                         return SendClientMessage ( playerid, -1, "[ USE ]: /desbanip [IP]" ) ;
  431.  
  432.                     funcaoDesbanIP ( gets($0), playerid ) ;
  433.                     return true ;
  434.                 }
  435.             }
  436.             return false ;
  437.     }
  438. #endif
  439. stock Nome ( playerid ) {
  440.  
  441.     new nOme [ 21 ] ;
  442.     GetPlayerName ( playerid, nOme, 21 ) ;
  443.     return nOme ;
  444. }
  445. stock funcaoBanP ( idBanido, idBaniu, motivBan[] ) {
  446.  
  447.     new Celulas [ 200 ] ;
  448.  
  449.     varBanido [ idBaniu ] = 1 ;
  450.     salvarContas ( idBaniu ) ;
  451.  
  452.     format ( Celulas, 128, "[ AVISO ]: %s - Foi banido permanentemente do servidor pelo Admin: %s. Motivo: %s", Nome ( idBanido ), Nome ( idBaniu ), motivBan ) ;
  453.     SendClientMessageToAll ( -1, Celulas ) ;
  454.  
  455.     #if SAVE == 1
  456.         new celulasData [ 50 ], iP [ 16 ], celulasHora [ 50 ], celulasPasta [ 64 ], celulasIP [ 64 ] ;
  457.  
  458.         getdate ( Ano, Mes, Dia ) ;
  459.         gettime ( Hora, Minuto, Segundo ) ;
  460.         GetPlayerIp ( idBanido, iP, 16 ) ;
  461.         format ( celulasData, 50, "%d/%d/%d", Dia, Mes, Ano ) ;
  462.         format ( celulasHora, 50, "%d:%d:%d", Hora, Minuto, Segundo ) ;
  463.         format ( celulasPasta, 64, "Banidos/%s.ini", Nome ( idBanido ) ) ;
  464.         format ( celulasIP, 64, "iPsBanidos/%s.ini", iP ) ;
  465.  
  466.         if ( DOF2::CreateFile ( celulasPasta ) ) {
  467.  
  468.             DOF2::SetString ( celulasPasta, "Admin", Nome ( idBaniu ) ) ;
  469.             DOF2::SetString ( celulasPasta, "Motivo", motivBan ) ;
  470.             DOF2::SetString ( celulasPasta, "Data", celulasData ) ;
  471.             DOF2::SetString ( celulasPasta, "Hora", celulasHora ) ;
  472.             DOF2::SetString ( celulasPasta, "IP", iP ) ;
  473.             DOF2::SaveFile () ;
  474.         }
  475.         if ( DOF2::CreateFile ( celulasIP ) ) {
  476.  
  477.             DOF2::SetString ( celulasIP, "Admin", Nome ( idBaniu ) ) ;
  478.             DOF2::SetString ( celulasIP, "Motivo", motivBan ) ;
  479.             DOF2::SetString ( celulasIP, "Data", celulasData ) ;
  480.             DOF2::SetString ( celulasIP, "Hora", celulasHora ) ;
  481.             DOF2::SetString ( celulasIP, "Nick", Nome ( idBanido ) ) ;
  482.             DOF2::SaveFile () ;
  483.         }
  484.     #else
  485.         new celulasData [ 50 ], celulasHora [ 50 ], iP [ 16 ] ;
  486.  
  487.         getdate ( Ano, Mes, Dia ) ;
  488.         gettime ( Hora, Minuto, Segundo ) ;
  489.         format ( celulasData, 50, "%d/%d/%d", Dia, Mes, Ano ) ;
  490.         format ( celulasHora, 50, "%d:%d:%d", Hora, Minuto, Segundo ) ;
  491.  
  492.         format ( Celulas, 200, "INSERT INTO `banidos`( `Nick`, `IP`, `Motivo`, `Admin`, `Data`, `Hora`) VALUES ('%s', '%s', '%s', '%s', '%s', '%s')", Nome ( idBanido ), iP, motivBan, Nome ( idBaniu ), celulasData, celulasHora ) ;
  493.         mysql_function_query ( MySQLConnect, Celulas, false, #, # ) ;
  494.  
  495.     #endif
  496.     return true ;
  497. }
  498. stock funcaoDesbanIP ( iP[], idDesban ) {
  499.  
  500.     #if SAVE == 1
  501.         new Arquivo [ 64 ] ;
  502.         format ( Arquivo, 64, "iPsBanidos/%s.ini", iP ) ;
  503.         DOF2::RemoveFile ( Arquivo ) ;
  504.  
  505.         SendClientMessage ( idDesban, -1, "[ AVISO ]: IP desbanido com sucesso" ) ;
  506.     #else
  507.         new Celulas [ 50 ] ;
  508.         format ( Celulas , 50, "DELETE FROM `banidos` WHERE `IP` = '%s'" , iP );
  509.         mysql_function_query ( MySQLConnect, Celulas, false, #, # ) ;
  510.         SendClientMessage ( idDesban, -1, "[ AVISO ]: IP desbanido com sucesso" ) ;
  511.     #endif
  512.     return true ;
  513. }
  514.  
  515. stock funcaoChecarNickBan ( nickBanned[], idCheck ) {
  516.  
  517.     #if SAVE == 1
  518.  
  519.         new Celulas [ 300 ], celulasCheck [ 65 ], strCat [ 300 ] ;
  520.  
  521.         format ( celulasCheck, 65, "Banidos/%s.ini", nickBanned ) ;
  522.         if ( fexist ( celulasCheck ) ) {
  523.  
  524.             strmid ( adminBan, DOF2::GetString ( celulasCheck, "Admin" ), 0, strlen ( DOF2::GetString ( celulasCheck, "Admin" ) ), 50 ) ;
  525.             strmid ( motivoBan, DOF2::GetString ( celulasCheck, "Motivo" ), 0, strlen ( DOF2::GetString ( celulasCheck, "Motivo" ) ), 50 ) ;
  526.             strmid ( dataBan, DOF2::GetString ( celulasCheck, "Data" ), 0, strlen ( DOF2::GetString ( celulasCheck, "Data" ) ), 50 ) ;
  527.             strmid ( horaBan, DOF2::GetString ( celulasCheck, "Hora" ), 0, strlen ( DOF2::GetString ( celulasCheck, "Hora" ) ), 50 ) ;
  528.             strmid ( ipBan, DOF2::GetString ( celulasCheck, "IP" ), 0, strlen ( DOF2::GetString ( celulasCheck, "IP" ) ), 50 ) ;
  529.  
  530.             format ( Celulas, 100, "{FF0000}Jogador {0077FF}%s {FF0000}está Banido\n\n\n", nickBanned ) ;
  531.             strcat ( strCat, Celulas ) ;
  532.             format ( Celulas, 100, "{929FAD}Admin: {FFFFFF}%s\n\n", adminBan ) ;
  533.             strcat ( strCat, Celulas ) ;
  534.             format ( Celulas, 100, "{929FAD}IP: {FFFFFF}%s\n\n", ipBan ) ;
  535.             strcat ( strCat, Celulas ) ;
  536.             format ( Celulas, 100, "{929FAD}Motivo: {FFFFFF}%s\n\n", motivoBan ) ;
  537.             strcat ( strCat, Celulas ) ;
  538.             format ( Celulas, 100, "{929FAD}Data: {FFFFFF}%s\n\n", dataBan ) ;
  539.             strcat ( strCat, Celulas ) ;
  540.             format ( Celulas, 100, "{929FAD}Hora: {FFFFFF}%s\n\n", horaBan ) ;
  541.             strcat ( strCat, Celulas ) ;
  542.             ShowPlayerDialog ( idCheck, dialogCheckBan, DIALOG_STYLE_MSGBOX, "Sistema de Bans", strCat, "Fechar", "" ) ;
  543.         }
  544.         else {
  545.  
  546.             format ( Celulas, 70, "[ ERRO ]: Nick: %s não está banido", nickBanned ) ;
  547.             SendClientMessage ( idCheck, -1, Celulas ) ;
  548.         }
  549.     #else
  550.         new  celulasCheck [ 70 ] ;
  551.         format ( celulasCheck, 70, "SELECT * FROM `banidos` WHERE `Nick`='%s'", nickBanned ) ;
  552.         mysql_function_query ( MySQLConnect, celulasCheck, true, "checkNickBan", "i", idCheck ) ;
  553.     #endif
  554. }
  555. stock funcaoChecarIPBan ( ipBanned[], idCheck ) {
  556.  
  557.     #if SAVE == 1
  558.  
  559.         new Celulas [ 300 ], celulasCheck [ 65 ], strCat [ 300 ] ;
  560.  
  561.         format ( celulasCheck, 65, "iPsBanidos/%s.ini", ipBanned ) ;
  562.         if ( fexist ( celulasCheck ) ) {
  563.  
  564.             strmid ( adminBan, DOF2::GetString ( celulasCheck, "Admin" ), 0, strlen ( DOF2::GetString ( celulasCheck, "Admin" ) ), 50 ) ;
  565.             strmid ( motivoBan, DOF2::GetString ( celulasCheck, "Motivo" ), 0, strlen ( DOF2::GetString ( celulasCheck, "Motivo" ) ), 50 ) ;
  566.             strmid ( dataBan, DOF2::GetString ( celulasCheck, "Data" ), 0, strlen ( DOF2::GetString ( celulasCheck, "Data" ) ), 50 ) ;
  567.             strmid ( horaBan, DOF2::GetString ( celulasCheck, "Hora" ), 0, strlen ( DOF2::GetString ( celulasCheck, "Hora" ) ), 50 ) ;
  568.             strmid ( nickBan, DOF2::GetString ( celulasCheck, "Nick" ), 0, strlen ( DOF2::GetString ( celulasCheck, "Nick" ) ), 50 ) ;
  569.  
  570.             format ( Celulas, 300, "{FF0000}Jogador {0077FF}%s {FF0000}está Banido\n\n", nickBan ) ;
  571.             strcat ( strCat, Celulas ) ;
  572.             format ( Celulas, 300, "{929FAD}Admin: {FFFFFF}%s\n\n", adminBan ) ;
  573.             strcat ( strCat, Celulas ) ;
  574.             format ( Celulas, 300, "{929FAD}IP: {FFFFFF}%s\n\n", ipBan ) ;
  575.             strcat ( strCat, Celulas ) ;
  576.             format ( Celulas, 300, "{929FAD}Motivo: {FFFFFF}%s\n\n", motivoBan ) ;
  577.             strcat ( strCat, Celulas ) ;
  578.             format ( Celulas, 300, "{929FAD}Data: {FFFFFF}%s\n\n", dataBan ) ;
  579.             strcat ( strCat, Celulas ) ;
  580.             format ( Celulas, 300, "{929FAD}Hora: {FFFFFF}%s\n\n", horaBan ) ;
  581.             strcat ( strCat, Celulas ) ;
  582.             ShowPlayerDialog ( idCheck, dialogCheckBan, DIALOG_STYLE_MSGBOX, "Sistema de Bans", strCat, "Fechar", "" ) ;
  583.         }
  584.         else {
  585.  
  586.             format ( Celulas, 70, "[ ERRO ]: IP: %s não está banido", ipBanned ) ;
  587.             SendClientMessage ( idCheck, -1, Celulas ) ;
  588.         }
  589.     #else
  590.         new  celulasCheck [ 70 ] ;
  591.         format ( celulasCheck, 70, "SELECT * FROM `banidos` WHERE `IP`='%s'", ipBanned ) ;
  592.         mysql_function_query ( MySQLConnect, celulasCheck, true, "checkIpBan", "i", idCheck ) ;
  593.     #endif
  594. }
  595. #if SAVE == 2
  596.  
  597.     public OnQueryError ( errorid, error[], callback[], query[], connectionHandle ) {
  598.  
  599.         printf("%i %s %s %s %i", errorid, error, callback, query, connectionHandle ) ;
  600.         return true ;
  601.     }
  602.     public checkNickBan ( idCheck ) {
  603.  
  604.         new Row, Fields, strCat [ 300 ], Celulas [ 300 ] ;
  605.  
  606.         cache_get_data ( Row, Fields, MySQLConnect ) ;
  607.  
  608.         if ( Row ) {
  609.  
  610.             cache_get_field_content ( 0, "Admin", adminBan, MySQLConnect ) ;
  611.             cache_get_field_content ( 0, "Nick", nickBan, MySQLConnect ) ;
  612.             cache_get_field_content ( 0, "IP", ipBan, MySQLConnect ) ;
  613.             cache_get_field_content ( 0, "Motivo", motivoBan, MySQLConnect ) ;
  614.             cache_get_field_content ( 0, "Data", dataBan, MySQLConnect ) ;
  615.             cache_get_field_content ( 0, "Hora", horaBan, MySQLConnect ) ;
  616.  
  617.             format ( Celulas, 300, "{FF0000}Jogador {0077FF}%s {FF0000}está Banido\n\n\n", nickBan ) ;
  618.             strcat ( strCat, Celulas ) ;
  619.             format ( Celulas, 300, "{929FAD}Admin: {FFFFFF}%s\n\n", adminBan ) ;
  620.             strcat ( strCat, Celulas ) ;
  621.             format ( Celulas, 300, "{929FAD}IP: {FFFFFF}%s\n\n", ipBan ) ;
  622.             strcat ( strCat, Celulas ) ;
  623.             format ( Celulas, 300, "{929FAD}Motivo: {FFFFFF}%s\n\n", motivoBan ) ;
  624.             strcat ( strCat, Celulas ) ;
  625.             format ( Celulas, 300, "{929FAD}Data: {FFFFFF}%s\n\n", dataBan ) ;
  626.             strcat ( strCat, Celulas ) ;
  627.             format ( Celulas, 300, "{929FAD}Hora: {FFFFFF}%s\n\n", horaBan ) ;
  628.             strcat ( strCat, Celulas ) ;
  629.             ShowPlayerDialog ( idCheck, dialogCheckBan, DIALOG_STYLE_MSGBOX, "Sistema de Bans", strCat, "Fechar", "" ) ;
  630.         }
  631.         else {
  632.  
  633.             SendClientMessage ( idCheck, -1, "[ ERRO ]: Este nick não está banido" ) ;
  634.         }
  635.         return true ;
  636.     }
  637.     public checkIpBan ( idCheck ) {
  638.  
  639.         new Row, Fields, strCat [ 128 ], Celulas [ 128 ] ;
  640.  
  641.         cache_get_data ( Row, Fields, MySQLConnect ) ;
  642.  
  643.         if ( Row ) {
  644.  
  645.             cache_get_field_content ( 0, "Admin", adminBan, MySQLConnect ) ;
  646.             cache_get_field_content ( 0, "Nick", nickBan, MySQLConnect ) ;
  647.             cache_get_field_content ( 0, "IP", ipBan, MySQLConnect ) ;
  648.             cache_get_field_content ( 0, "Motivo", motivoBan, MySQLConnect ) ;
  649.             cache_get_field_content ( 0, "Data", dataBan, MySQLConnect ) ;
  650.             cache_get_field_content ( 0, "Hora", horaBan, MySQLConnect ) ;
  651.  
  652.             format ( Celulas, 300, "{FF0000}Jogador {0077FF}%s {FF0000}está Banido\n\n\n", nickBan ) ;
  653.             strcat ( strCat, Celulas ) ;
  654.             format ( Celulas, 300, "{929FAD}Admin: {FFFFFF}%s\n\n", adminBan ) ;
  655.             strcat ( strCat, Celulas ) ;
  656.             format ( Celulas, 300, "{929FAD}IP: {FFFFFF}%s\n\n", ipBan ) ;
  657.             strcat ( strCat, Celulas ) ;
  658.             format ( Celulas, 300, "{929FAD}Motivo: {FFFFFF}%s\n\n", motivoBan ) ;
  659.             strcat ( strCat, Celulas ) ;
  660.             format ( Celulas, 300, "{929FAD}Data: {FFFFFF}%s\n\n", dataBan ) ;
  661.             strcat ( strCat, Celulas ) ;
  662.             format ( Celulas, 300, "{929FAD}Hora: {FFFFFF}%s\n\n", horaBan ) ;
  663.             strcat ( strCat, Celulas ) ;
  664.             ShowPlayerDialog ( idCheck, dialogCheckBan, DIALOG_STYLE_MSGBOX, "Sistema de Bans", strCat, "Fechar", "" ) ;
  665.         }
  666.         else
  667.             SendClientMessage ( idCheck, -1, "[ ERRO ]: Este IP não está banido" ) ;
  668.        
  669.         return true ;
  670.     }
  671. #endif
  672.  
  673. #if CmD == 1
  674.     COMMAND:banir ( playerid, params[] ) {
  675.  
  676.         new idBan, banMotivo [ 50 ] ;
  677.  
  678.         if ( sscanf ( params, "us[50]", idBan, banMotivo ) )
  679.             return SendClientMessage ( playerid, -1, "[ USE ]: /banir [ID] [Motivo]" ) ;
  680.  
  681.         funcaoBanP ( idBan, playerid, banMotivo ) ;
  682.         return true ;
  683.     }
  684.     COMMAND:checarip ( playerid, params[] ) {
  685.  
  686.         new iPx [ 16 ] ;
  687.  
  688.         if ( sscanf ( params, "s[16]", iPx ) )
  689.             return SendClientMessage ( playerid, -1, "[ USE ]: /checarip [IP]" ) ;
  690.  
  691.         funcaoChecarIPBan ( iPx, playerid ) ;
  692.         return true ;
  693.     }
  694.     COMMAND:checarnick ( playerid, params[] ) {
  695.  
  696.         new NOME [ 21 ] ;
  697.         if ( sscanf ( params, "s[21]", NOME ) )
  698.             return SendClientMessage ( playerid, -1, "[ USE ]: /checarnick [Nick]" ) ;
  699.  
  700.         funcaoChecarNickBan ( NOME, playerid ) ;
  701.         return true ;
  702.     }
  703.     COMMAND:desbanip ( playerid, params[] ) {
  704.  
  705.         new IP [ 16 ] ;
  706.         if ( sscanf ( params, "u[16]", IP ) )
  707.             return SendClientMessage ( playerid, -1, "[ USE ]: /desbanip [IP]" ) ;
  708.  
  709.         funcaoDesbanIP ( IP, playerid ) ;
  710.         return true ;
  711.     }
  712. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement