Advertisement
iCasTiel

cBan v0.2.1 - STRCMP + STRTOK

Jan 20th, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 28.34 KB | None | 0 0
  1. #include a_samp
  2. #include sscanf2
  3.  
  4. #if defined MAX_PLAYERS
  5.     #undef MAX_PLAYERS
  6.     #define MAX_PLAYERS 20
  7. #else
  8.     #define MAX_PLAYERS 20
  9. #endif
  10.  
  11. #define Kick(%0) SetTimerEx("Kicka", 100, false, "i", %0)
  12. #define Ban(%0) SetTimerEx("Bana", 100, false, "i", %0)
  13.  
  14. #define BLACK_LIST_TIPO 8500
  15. #define DIALOG_BLACK_LIST_INSERIR_DATA_USUARIOS 8501
  16. #define DIALOG_BLACK_LIST_INSERIR_DATA_IPS 8502
  17.  
  18. #define SPLITTER /
  19.  
  20. new MonthTimes[12][4] =
  21. {
  22.         { 31, 31, 2678400, 2678400 },
  23.         { 28, 29, 2419200, 2505600 },
  24.         { 31, 31, 2678400, 2678400 },
  25.         { 30, 30, 2592000, 2592000 },
  26.         { 31, 31, 2678400, 2678400 },
  27.         { 30, 30, 2592000, 2592000 },
  28.         { 31, 31, 2678400, 2678400 },
  29.         { 31, 31, 2678400, 2678400 },
  30.         { 30, 30, 2592000, 2592000 },
  31.         { 31, 31, 2678400, 2678400 },
  32.         { 30, 30, 2592000, 2592000 },
  33.         { 31, 31, 2678400, 2678400 }
  34. };
  35.  
  36. new DB:cBan;
  37.  
  38. new Query[1024];
  39.  
  40. public OnFilterScriptInit() {
  41.  
  42.     print("\n--------------------------------------");
  43.     print("      cBan carregado com sucesso!");
  44.     print("--------------------------------------\n");
  45.  
  46.     cBan = db_open("cBan.db");
  47.  
  48.     db_free_result(db_query(cBan, "CREATE TABLE IF NOT EXISTS usuarios_banidos (id INTEGER PRIMARY KEY, nome TEXT, admin TEXT, motivo TEXT, tempo NUMERIC, data_ocorrido NUMERIC)"));
  49.     db_free_result(db_query(cBan, "CREATE TABLE IF NOT EXISTS ips_banidos (id INTEGER PRIMARY KEY, ip TEXT, admin TEXT, motivo TEXT, tempo NUMERIC, data_ocorrido NUMERIC)"));
  50.  
  51.     return 1;
  52. }
  53.  
  54. public OnFilterScriptExit() {
  55.  
  56.     db_close(cBan);
  57.     return 1;
  58. }
  59.  
  60. public OnPlayerConnect(playerid) {
  61.  
  62.     new meuNome[MAX_PLAYER_NAME], DBResult:Consulta, meuIP[16];
  63.  
  64.     GetPlayerName(playerid, meuNome, MAX_PLAYER_NAME);
  65.     GetPlayerIp(playerid, meuIP, 16);
  66.  
  67.     format (Query, 1024, "SELECT * FROM usuarios_banidos WHERE nome = '%s'", meuNome);
  68.     Consulta = db_query(cBan, Query);
  69.  
  70.     if ( db_num_rows(Consulta) > 0 ) {
  71.  
  72.         new Admin[MAX_PLAYER_NAME], Motivo[64], Tempo;
  73.  
  74.         db_get_field_assoc(Consulta, "admin", Admin, MAX_PLAYER_NAME);
  75.         db_get_field_assoc(Consulta, "motivo", Motivo, 64);
  76.         db_get_field_assoc(Consulta, "tempo", Query, 1024);
  77.         Tempo = strval(Query);
  78.  
  79.         if ( Tempo != -1 ) {
  80.  
  81.             if ( gettime() >= Tempo ) {
  82.  
  83.                 format (Query, 1024, "DELETE FROM usuarios_banidos WHERE nome = '%s'", meuNome);
  84.                 db_free_result(db_query(cBan, Query));
  85.                 SendClientMessage(playerid, 0xD40000FF, "Sua conta foi desbanida! Não cometa os mesmos erros!");
  86.             }
  87.             else {
  88.  
  89.                 format (Query, 1024, "{FFFFFF}Sua conta esta banida!\n{FF0000}Informações de banimento:\n{FFFFFF}Nome da conta: {FF0000}%s\n{FFFFFF}Administrador responsável: {FF0000}%s\n{FFFFFF}Motivo do banimento:{FF0000}%s\n{FFFFFF}Data de desbanimento: {FF0000}%s", meuNome, Admin, Motivo, timestampToDate(Tempo) );
  90.                 ShowPlayerDialog(playerid, 9999, DIALOG_STYLE_MSGBOX, "{FF0000}Você esta banido!", Query, "Fechar", #);
  91.                 Kick(playerid);
  92.             }
  93.         }
  94.         else {
  95.  
  96.             format (Query, 1024, "{FFFFFF}Sua conta esta banida!\n{FF0000}Informações de banimento:\n{FFFFFF}Nome da conta: {FF0000}%s\n{FFFFFF}Administrador responsável: {FF0000}%s\n{FFFFFF}Motivo do banimento:{FF0000}%s\n{FFFFFF}Data de desbanimento: {FF0000}Nunca", meuNome, Admin, Motivo );
  97.             ShowPlayerDialog(playerid, 9999, DIALOG_STYLE_MSGBOX, "{FF0000}Você esta banido!", Query, "Fechar", #);
  98.             Kick(playerid);
  99.  
  100.         }
  101.     }
  102.     db_free_result(Consulta);
  103.  
  104.     format (Query, 1024, "SELECT * FROM ips_banidos WHERE ip = '%s'", meuIP);
  105.     Consulta = db_query(cBan, Query);
  106.  
  107.     if ( db_num_rows(Consulta) > 0 ) {
  108.  
  109.         new Admin[MAX_PLAYER_NAME], Motivo[64], Tempo;
  110.  
  111.         db_get_field_assoc(Consulta, "admin", Admin, MAX_PLAYER_NAME);
  112.         db_get_field_assoc(Consulta, "motivo", Motivo, 64);
  113.         db_get_field_assoc(Consulta, "tempo", Query, 1024);
  114.         Tempo = strval(Query);
  115.  
  116.         if ( Tempo != -1 ) {
  117.  
  118.             if ( gettime() >= Tempo ) {
  119.  
  120.                 format (Query, 1024, "DELETE FROM ips_banidos WHERE ip = '%s'", meuIP);
  121.                 db_free_result(db_query(cBan, Query));
  122.                 SendClientMessage(playerid, 0xD40000FF, "Seu IP foi desbanido! Não cometa os mesmos erros!");
  123.             }
  124.             else {
  125.  
  126.                 format (Query, 1024, "{FFFFFF}Seu IP esta banido!\n{FF0000}Informações de banimento:\n{FFFFFF}IP: {FF0000}%s\n{FFFFFF}Administrador responsável: {FF0000}%s\n{FFFFFF}Motivo do banimento:{FF0000}%s\n{FFFFFF}Data de desbanimento: {FF0000}%s", meuIP, Admin, Motivo, timestampToDate(Tempo) );
  127.                 ShowPlayerDialog(playerid, 9999, DIALOG_STYLE_MSGBOX, "{FF0000}Você esta banido!", Query, "Fechar", #);
  128.                 Kick(playerid);
  129.             }
  130.         }
  131.         else {
  132.  
  133.             format (Query, 1024, "{FFFFFF}Seu IP esta banido!\n{FF0000}Informações de banimento:\n{FFFFFF}IP: {FF0000}%s\n{FFFFFF}Administrador responsável: {FF0000}%s\n{FFFFFF}Motivo do banimento:{FF0000}%s\n{FFFFFF}Data de desbanimento: {FF0000}Nunca", meuIP, Admin, Motivo );
  134.             ShowPlayerDialog(playerid, 9999, DIALOG_STYLE_MSGBOX, "{FF0000}Você esta banido!", Query, "Fechar", #);
  135.             Kick(playerid);
  136.  
  137.         }
  138.     }
  139.     db_free_result(Consulta);
  140.     return 1;
  141. }
  142.  
  143. public OnPlayerSpawn(playerid) {
  144.  
  145.     SendClientMessage(playerid, 0x00B655FF, "Este servidor utiliza o sistema cBan, desenvolvido por CasTiel!");
  146.     SendClientMessage(playerid, 0x00B655FF, "Você pode ver todos os comandos disponíveis do sistema utilizando /ajudaban!");
  147.     SendClientMessage(playerid, 0x00B655FF, "Consulte a lista de banidos usando /blacklist!");
  148.     return 1;
  149. }
  150.  
  151. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  152.  
  153.     switch (dialogid) {
  154.  
  155.         case BLACK_LIST_TIPO: {
  156.  
  157.             if ( response ) {
  158.  
  159.                 SendClientMessage(playerid, 0xFF0000FF, "Você optou por ver a lista de usuários banidos!");
  160.                 ShowPlayerDialog(playerid, DIALOG_BLACK_LIST_INSERIR_DATA_USUARIOS, DIALOG_STYLE_INPUT, "{FFFFFF}Black list", "{FFFFFF}Digite no campo abaixo a {FF0000}data referente aos bloqueios de usuários efetuados!\n{FF0000}OBS:{FFFFFF}Siga o padrão {FF0000}dd-mm-aaaa{FFFFFF}, exemplo (18/01/2013)!", "Ver lista", "Fechar");
  161.             }
  162.             else {
  163.  
  164.                 SendClientMessage(playerid, 0xFF0000FF, "Você optou por ver a lista de IPs banidos!");
  165.                 ShowPlayerDialog(playerid, DIALOG_BLACK_LIST_INSERIR_DATA_IPS, DIALOG_STYLE_INPUT, "{FFFFFF}Black list", "{FFFFFF}Digite no campo abaixo a {FF0000}data referente aos bloqueios de IPs efetuados!\n{FF0000}OBS:{FFFFFF}Siga o padrão {FF0000}dd-mm-aaaa{FFFFFF}, exemplo (18/01/2013)!", "Ver lista", "Fechar");
  166.             }
  167.         }
  168.         case DIALOG_BLACK_LIST_INSERIR_DATA_USUARIOS: {
  169.  
  170.             if ( response ) {
  171.  
  172.                 new timestamp;
  173.                 timestamp = DateToTimestamp(inputtext);
  174.  
  175.                 if ( strlen(inputtext) != 10 || strfind(inputtext, "/") == -1 || timestamp == -1 ) {
  176.  
  177.                     SendClientMessage(playerid, 0xFF0000FF, "Data informada não segue os padrões estabelecidos!!");
  178.                     ShowPlayerDialog(playerid, DIALOG_BLACK_LIST_INSERIR_DATA_USUARIOS, DIALOG_STYLE_INPUT, "{FFFFFF}Black list", "{FFFFFF}Digite no campo abaixo a {FF0000}data referente aos bloqueios de usuários efetuados!\n{FF0000}OBS:{FFFFFF}Siga o padrão {FF0000}dd-mm-aaaa{FFFFFF}, exemplo (18/01/2013)!", "Ver lista", "Fechar");
  179.                     return 1;
  180.                  }
  181.  
  182.                 new DBResult:Consulta;
  183.  
  184.                 format (Query, 1024, "SELECT nome, admin, motivo FROM usuarios_banidos WHERE data_ocorrido BETWEEN %d AND %d", timestamp, (timestamp + 86399) );
  185.                 Consulta = db_query(cBan, Query);
  186.  
  187.                 if (db_num_rows(Consulta) == 0 ) {
  188.  
  189.                     format (Query, 1024, "{FFFFFF}Nenhum usuário foi banido em %s", inputtext);
  190.                     ShowPlayerDialog(playerid, 9999, DIALOG_STYLE_MSGBOX, "{FFFFFF}Black list", Query, "Fechar", "");
  191.  
  192.                 }
  193.                 else {
  194.  
  195.                     new Nome[MAX_PLAYER_NAME], Admin[MAX_PLAYER_NAME], Motivo[64], str[128];
  196.  
  197.                     Query[0] = EOS;
  198.  
  199.                     do {
  200.  
  201.                         db_get_field_assoc(Consulta, "nome", Nome, MAX_PLAYER_NAME);
  202.                         db_get_field_assoc(Consulta, "admin", Admin, MAX_PLAYER_NAME);
  203.                         db_get_field_assoc(Consulta, "motivo", Motivo, 64);
  204.                         format (str, 128, "{FF0000}Nome: {FFFFFF}%s - {FF0000}Admin responsável:{FFFFFF}%s - {FF0000}Motivo: {FFFFFF}%s\n", Nome, Admin, Motivo);
  205.                         strcat(Query, str);
  206.                     }
  207.                     while( db_next_row(Consulta) );
  208.  
  209.                     format (str, 128, "{FFFFFF}Lista de usuários banidos em {FF0000}%s", inputtext);
  210.                     ShowPlayerDialog(playerid, 9999, DIALOG_STYLE_MSGBOX, str, Query, "Fechar", #);
  211.  
  212.                 }
  213.                 db_free_result(Consulta);
  214.             }
  215.         }
  216.         case DIALOG_BLACK_LIST_INSERIR_DATA_IPS: {
  217.  
  218.             if ( response ) {
  219.  
  220.                 new timestamp;
  221.                 timestamp = DateToTimestamp(inputtext);
  222.  
  223.                 if ( strlen(inputtext) != 10 || strfind(inputtext, "/") == -1 || timestamp == -1 ) {
  224.  
  225.                     SendClientMessage(playerid, 0xFF0000FF, "Data informada não segue os padrões estabelecidos!!");
  226.                     ShowPlayerDialog(playerid, DIALOG_BLACK_LIST_INSERIR_DATA_USUARIOS, DIALOG_STYLE_INPUT, "{FFFFFF}Black list", "{FFFFFF}Digite no campo abaixo a {FF0000}data referente aos bloqueios de usuários efetuados!\n{FF0000}OBS:{FFFFFF}Siga o padrão {FF0000}dd-mm-aaaa{FFFFFF}, exemplo (18/01/2013)!", "Ver lista", "Fechar");
  227.                     return 1;
  228.                  }
  229.  
  230.                 new DBResult:Consulta;
  231.  
  232.                 format (Query, 1024, "SELECT ip, admin, motivo FROM ips_banidos WHERE data_ocorrido BETWEEN %d AND %d", timestamp, (timestamp + 86399) );
  233.                 Consulta = db_query(cBan, Query);
  234.  
  235.                 if (db_num_rows(Consulta) == 0 ) {
  236.  
  237.                     format (Query, 1024, "{FFFFFF}Nenhum IP foi banido em %s", inputtext);
  238.                     ShowPlayerDialog(playerid, 9999, DIALOG_STYLE_MSGBOX, "{FFFFFF}Black list", Query, "Fechar", "");
  239.  
  240.                 }
  241.                 else {
  242.  
  243.                     new IP[16], Admin[MAX_PLAYER_NAME], Motivo[64], str[128];
  244.  
  245.                     Query[0] = EOS;
  246.  
  247.                     do {
  248.  
  249.                         db_get_field_assoc(Consulta, "ip", IP, 16);
  250.                         db_get_field_assoc(Consulta, "admin", Admin, MAX_PLAYER_NAME);
  251.                         db_get_field_assoc(Consulta, "motivo", Motivo, 64);
  252.                         format (str, 128, "{FF0000}IP: {FFFFFF}%s - {FF0000}Admin responsável:{FFFFFF}%s - {FF0000}Motivo: {FFFFFF}%s\n", IP, Admin, Motivo);
  253.                         strcat(Query, str);
  254.                     }
  255.                     while( db_next_row(Consulta) );
  256.  
  257.                     format (str, 128, "{FFFFFF}Lista de IPs banidos em {FF0000}%s", inputtext);
  258.                     ShowPlayerDialog(playerid, 9999, DIALOG_STYLE_MSGBOX, str, Query, "Fechar", #);
  259.  
  260.                 }
  261.                 db_free_result(Consulta);
  262.             }
  263.         }
  264.     }
  265.     return 1;
  266. }
  267.  
  268.  
  269. /* Funções */
  270.  
  271. strtok(const string[], &index)
  272. {
  273.     new length = strlen(string);
  274.     while ((index < length) && (string[index] <= ' '))
  275.     {
  276.         index++;
  277.     }
  278.  
  279.     new offset = index;
  280.     new result[20];
  281.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  282.     {
  283.         result[index - offset] = string[index];
  284.         index++;
  285.     }
  286.     result[index - offset] = EOS;
  287.     return result;
  288. }
  289.  
  290. IsNumeric(const string[])
  291. {
  292.     for (new i = 0, j = strlen(string); i < j; i++)
  293.     {
  294.         if (string[i] > '9' || string[i] < '0') return 0;
  295.     }
  296.     return 1;
  297. }
  298.  
  299. ReturnUser(text[], playerid = INVALID_PLAYER_ID)
  300. {
  301.     new pos = 0;
  302.     while (text[pos] < 0x21) // Strip out leading spaces
  303.     {
  304.         if (text[pos] == 0) return INVALID_PLAYER_ID; // No passed text
  305.         pos++;
  306.     }
  307.     new userid = INVALID_PLAYER_ID;
  308.     if (IsNumeric(text[pos])) // Check whole passed string
  309.     {
  310.         // If they have a numeric name you have a problem (although names are checked on id failure)
  311.         userid = strval(text[pos]);
  312.         if (userid >=0 && userid < MAX_PLAYERS)
  313.         {
  314.             if(!IsPlayerConnected(userid))
  315.             {
  316.                 /*if (playerid != INVALID_PLAYER_ID)
  317.                 {
  318.                     SendClientMessage(playerid, 0xFF0000AA, "User not connected");
  319.                 }*/
  320.                 userid = INVALID_PLAYER_ID;
  321.             }
  322.             else
  323.             {
  324.                 return userid; // A player was found
  325.             }
  326.         }
  327.         /*else
  328.         {
  329.             if (playerid != INVALID_PLAYER_ID)
  330.             {
  331.                 SendClientMessage(playerid, 0xFF0000AA, "Invalid user ID");
  332.             }
  333.             userid = INVALID_PLAYER_ID;
  334.         }
  335.         return userid;*/
  336.         // Removed for fallthrough code
  337.     }
  338.     // They entered [part of] a name or the id search failed (check names just incase)
  339.     new len = strlen(text[pos]);
  340.     new count = 0;
  341.     new name[MAX_PLAYER_NAME];
  342.     for (new i = 0; i < MAX_PLAYERS; i++)
  343.     {
  344.         if (IsPlayerConnected(i))
  345.         {
  346.             GetPlayerName(i, name, sizeof (name));
  347.             if (strcmp(name, text[pos], true, len) == 0) // Check segment of name
  348.             {
  349.                 if (len == strlen(name)) // Exact match
  350.                 {
  351.                     return i; // Return the exact player on an exact match
  352.                     // Otherwise if there are two players:
  353.                     // Me and MeYou any time you entered Me it would find both
  354.                     // And never be able to return just Me's id
  355.                 }
  356.                 else // Partial match
  357.                 {
  358.                     count++;
  359.                     userid = i;
  360.                 }
  361.             }
  362.         }
  363.     }
  364.     if (count != 1)
  365.     {
  366.         if (playerid != INVALID_PLAYER_ID)
  367.         {
  368.             if (count)
  369.             {
  370.                 SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow earch");
  371.             }
  372.             else
  373.             {
  374.                 SendClientMessage(playerid, 0xFF0000AA, "No matching user found");
  375.             }
  376.         }
  377.         userid = INVALID_PLAYER_ID;
  378.     }
  379.     return userid; // INVALID_USER_ID for bad return
  380. }
  381.  
  382. stock IsLeapYear(year)
  383. {
  384.         if(year % 4 == 0) return 1;
  385.         else return 0;
  386. }
  387.  
  388. stock DateToTimestamp(str[]) {
  389.  
  390.         new date[3]; // date[0] = day           date[1] = month                 date[2] = year
  391.         if(!sscanf(str,"p<"#SPLITTER">ddd",date[0],date[1],date[2]))
  392.         {
  393.                 new total = 0, tmp = 0;
  394.                 total += date[0] * 86400;
  395.                 if(date[1] == 2 && date[0] < 29) tmp = ((date[2] - 1968) / 4 - 2);
  396.                 else tmp = ((date[2] - 1968) / 4 - 1);
  397.                 total += tmp * 31622400;
  398.                 total += (date[2] - 1970 - tmp) * 31536000;
  399.                 for(new i = 1; i < date[1]; i ++) total += MonthTimes[i][0 + IsLeapYear(date[2])] * 86400;
  400.                 return total;
  401.         }
  402.         else return -1;
  403. }
  404.  
  405. stock banirConta(nome[], admin[], motivo[], tempo = -1 ) {
  406.  
  407.     format (Query, 1024, "INSERT INTO usuarios_banidos (nome, admin, motivo, tempo, data_ocorrido) VALUES ('%s', '%s', '%s', '%d', '%d')", nome, admin, motivo, tempo, gettime());
  408.     db_free_result(db_query(cBan, Query));
  409.  
  410.     return 1;
  411. }
  412.  
  413. stock banirIP(ip[], admin[], motivo[], tempo = -1) {
  414.  
  415.     format (Query, 1024, "INSERT INTO ips_banidos (ip, admin, motivo, tempo, data_ocorrido) VALUES ('%s', '%s', '%s', '%d', '%d')", ip, admin, motivo, tempo, gettime());
  416.     db_free_result(db_query(cBan, Query));
  417.  
  418.     return 1;
  419. }
  420.  
  421. stock desbanirConta(conta[]) {
  422.  
  423.     format (Query, 1024, "DELETE FROM usuarios_banidos WHERE nome = '%s'", conta);
  424.     db_free_result(db_query(cBan, Query));
  425.     return 1;
  426. }
  427.  
  428. stock desbanirIP(ip[]) {
  429.  
  430.     format (Query, 1024, "DELETE FROM ips_banidos WHERE ip = '%s'", ip);
  431.     db_free_result(db_query(cBan, Query));
  432.     return 1;
  433. }
  434.  
  435. stock timestampToDate(time) {
  436.  
  437.     new date[20], DBResult:Data, str[55];
  438.  
  439.     format (str, 55, "SELECT datetime(%d, 'unixepoch', 'localtime')" ,time);
  440.     Data = db_query(cBan, str);
  441.     db_get_field(Data, 0, date, 20);
  442.     db_free_result(Data);
  443.     return date;
  444. }
  445.  
  446. /* Fim funções */
  447.  
  448. /* Comandos */
  449. public OnPlayerCommandText(playerid, cmdtext[]) {
  450.  
  451.     new cmd[128], idx;
  452.     cmd = strtok(cmdtext, idx);
  453.  
  454.     if (!strcmp("/ban", cmd)) {
  455.  
  456.         if (!IsPlayerAdmin(playerid))
  457.             return SendClientMessage(playerid, 0xFF0000FF, "Comando restrito a administradores RCON!");
  458.  
  459.         new name_[MAX_PLAYER_NAME], motivo_[64];
  460.         name_ = strtok(cmdtext, idx);
  461.  
  462.         new length = strlen(cmdtext);
  463.         while ((idx < length) && (cmdtext[idx] <= ' '))
  464.         {
  465.             idx++;
  466.         }
  467.         new offset = idx;
  468.         while ((idx < length) && ((idx - offset) < (sizeof(motivo_) - 1)))
  469.         {
  470.             motivo_[idx - offset] = cmdtext[idx];
  471.             idx++;
  472.         }
  473.         motivo_[idx - offset] = EOS;
  474.  
  475.         if (!strlen(name_) || !strlen(motivo_))
  476.             return SendClientMessage(playerid, 0xFF0000FF, "Uso correto: /ban [ID/NOME] [MOTIVO]");
  477.  
  478.         new id_ = ReturnUser(name_);
  479.  
  480.         if (!IsPlayerConnected(id_))
  481.             return SendClientMessage(playerid, 0xFF0000FF, "Jogador offline!");
  482.  
  483.         new nome_[MAX_PLAYER_NAME], meuNome[MAX_PLAYER_NAME];
  484.         GetPlayerName(id_, nome_, MAX_PLAYER_NAME);
  485.         GetPlayerName(playerid, meuNome, MAX_PLAYER_NAME);
  486.  
  487.         new DBResult:verificarConta;
  488.  
  489.         format (Query, 1024, "SELECT * FROM usuarios_banidos WHERE nome = '%s'", nome_);
  490.         verificarConta = db_query(cBan, Query);
  491.  
  492.         if ( db_num_rows(verificarConta) > 0 )
  493.             return SendClientMessage(playerid, 0xFF0000FF, "Esta conta ja se encontra BANIDA!");
  494.  
  495.         db_free_result(verificarConta);
  496.  
  497.         banirConta(nome_, meuNome, motivo_);
  498.  
  499.         format (Query, 1024, "AdmCmd: %s[ID: %d] foi banido por %s[ID: %d] motivo: %s", nome_, id_, meuNome, playerid, motivo_);
  500.         SendClientMessageToAll(0xFF6347AA, Query);
  501.         Kick(id_);
  502.  
  503.         return 1;
  504.     }
  505.  
  506.     if (!strcmp("/bantemp", cmd)) {
  507.  
  508.         if (!IsPlayerAdmin(playerid))
  509.             return SendClientMessage(playerid, 0xFF0000FF, "Comando restrito a administradores RCON!");
  510.  
  511.         new name_[MAX_PLAYER_NAME], motivo_[64], dias[24];
  512.  
  513.         name_ = strtok(cmdtext, idx), dias = strtok(cmdtext, idx);
  514.  
  515.         new length = strlen(cmdtext);
  516.         while ((idx < length) && (cmdtext[idx] <= ' '))
  517.         {
  518.             idx++;
  519.         }
  520.         new offset = idx;
  521.         while ((idx < length) && ((idx - offset) < (sizeof(motivo_) - 1)))
  522.         {
  523.             motivo_[idx - offset] = cmdtext[idx];
  524.             idx++;
  525.         }
  526.         motivo_[idx - offset] = EOS;
  527.  
  528.         if (!strlen(name_) || !strlen(dias) || !strlen(motivo_))
  529.             return SendClientMessage(playerid, 0xFF0000FF, "Uso correto: /bantemp [ID/NOME] [DIAS] [MOTIVO]");
  530.  
  531.         new id_ = ReturnUser(name_);
  532.         new dias_ = strval(dias);
  533.  
  534.         if (dias_ <= 0)
  535.             return SendClientMessage(playerid, 0xFF0000FF, "Número de dias inválido!");
  536.  
  537.         if (!IsPlayerConnected(id_))
  538.             return SendClientMessage(playerid, 0xFF0000FF, "Jogador offline!");
  539.  
  540.         new nome_[MAX_PLAYER_NAME], meuNome[MAX_PLAYER_NAME];
  541.         GetPlayerName(id_, nome_, MAX_PLAYER_NAME);
  542.         GetPlayerName(playerid, meuNome, MAX_PLAYER_NAME);
  543.  
  544.         new DBResult:verificarConta;
  545.  
  546.         format (Query, 1024, "SELECT * FROM usuarios_banidos WHERE nome = '%s'", nome_);
  547.         verificarConta = db_query(cBan, Query);
  548.  
  549.         if ( db_num_rows(verificarConta) > 0 )
  550.             return SendClientMessage(playerid, 0xFF0000FF, "Esta conta ja se encontra BANIDA!");
  551.  
  552.         db_free_result(verificarConta);
  553.  
  554.         banirConta(nome_, meuNome, motivo_, (gettime() + (dias_ * 86400)));
  555.  
  556.         format (Query, 1024, "AdmCmd: %s[ID: %d] foi banido temporariamente (%d dia(s)) por %s[ID: %d] motivo: %s", nome_, id_, dias_, meuNome, playerid, motivo_);
  557.         SendClientMessageToAll(0xFF6347AA, Query);
  558.         Kick(id_);
  559.  
  560.         return 1;
  561.     }
  562.  
  563.     if (!strcmp(cmd, "/banconta")) {
  564.  
  565.         if (!IsPlayerAdmin(playerid))
  566.             return SendClientMessage(playerid, 0xFF0000FF, "Comando restrito a administradores RCON!");
  567.  
  568.         new conta_[MAX_PLAYER_NAME], motivo_[64];
  569.  
  570.         conta_ = strtok(cmdtext, idx);
  571.  
  572.         new length = strlen(cmdtext);
  573.         while ((idx < length) && (cmdtext[idx] <= ' '))
  574.         {
  575.             idx++;
  576.         }
  577.         new offset = idx;
  578.         while ((idx < length) && ((idx - offset) < (sizeof(motivo_) - 1)))
  579.         {
  580.             motivo_[idx - offset] = cmdtext[idx];
  581.             idx++;
  582.         }
  583.         motivo_[idx - offset] = EOS;
  584.  
  585.         if ( strlen(conta_) < 3 || !strlen(motivo_))
  586.             return SendClientMessage(playerid, 0xFF0000FF, "Uso correto: /banconta [NOME DA CONTA] [MOTIVO]");
  587.  
  588.         new DBResult:verificarConta;
  589.  
  590.         format (Query, 1024, "SELECT * FROM usuarios_banidos WHERE nome = '%s'", conta_);
  591.         verificarConta = db_query(cBan, Query);
  592.  
  593.         if ( db_num_rows(verificarConta) > 0 )
  594.             return SendClientMessage(playerid, 0xFF0000FF, "Esta conta ja se encontra BANIDA!");
  595.  
  596.         db_free_result(verificarConta);
  597.  
  598.         new meuNome[MAX_PLAYER_NAME];
  599.         GetPlayerName(playerid, meuNome, MAX_PLAYER_NAME);
  600.  
  601.         banirConta(conta_, meuNome, motivo_);
  602.  
  603.         format (Query, 1024, "AdmCmd: %s foi banido por %s[ID: %d] motivo: %s", conta_, meuNome, playerid, motivo_);
  604.         SendClientMessageToAll(0xFF6347AA, Query);
  605.  
  606.         new i, NOME2_[MAX_PLAYER_NAME];
  607.  
  608.         for ( i = 0; i < MAX_PLAYERS; ++i) {
  609.  
  610.             if (IsPlayerConnected(i)) {
  611.  
  612.                 GetPlayerName(i, NOME2_, MAX_PLAYER_NAME);
  613.                 if (!strcmp(conta_, NOME2_)) {
  614.  
  615.                     Kick(i);
  616.                     break;
  617.                 }
  618.             }
  619.         }
  620.  
  621.         return 1;
  622.     }
  623.  
  624.     if (!strcmp(cmd, "/bantempconta")) {
  625.  
  626.         if (!IsPlayerAdmin(playerid))
  627.             return SendClientMessage(playerid, 0xFF0000FF, "Comando restrito a administradores RCON!");
  628.  
  629.         new conta_[MAX_PLAYER_NAME], motivo_[64], dias[24];
  630.  
  631.         conta_ = strtok(cmdtext, idx), dias = strtok(cmdtext, idx);
  632.  
  633.         new length = strlen(cmdtext);
  634.         while ((idx < length) && (cmdtext[idx] <= ' '))
  635.         {
  636.             idx++;
  637.         }
  638.         new offset = idx;
  639.         while ((idx < length) && ((idx - offset) < (sizeof(motivo_) - 1)))
  640.         {
  641.             motivo_[idx - offset] = cmdtext[idx];
  642.             idx++;
  643.         }
  644.         motivo_[idx - offset] = EOS;
  645.  
  646.         if (strlen(conta_) < 3 || !strlen(motivo_) || !strlen(dias))
  647.             return SendClientMessage(playerid, 0xFF0000FF, "Uso correto: /bantempconta [NOME DA CONTA] [DIAS] [MOTIVO]");
  648.  
  649.         new dias_ = strval(dias);
  650.  
  651.         if (dias_ <= 0)
  652.             return SendClientMessage(playerid, 0xFF0000FF, "Número de dias inválido!");
  653.  
  654.         new DBResult:verificarConta;
  655.  
  656.         format (Query, 1024, "SELECT * FROM usuarios_banidos WHERE nome = '%s'", conta_);
  657.         verificarConta = db_query(cBan, Query);
  658.  
  659.         if ( db_num_rows(verificarConta) > 0 )
  660.             return SendClientMessage(playerid, 0xFF0000FF, "Esta conta ja se encontra BANIDA!");
  661.  
  662.         db_free_result(verificarConta);
  663.  
  664.         new meuNome[MAX_PLAYER_NAME];
  665.         GetPlayerName(playerid, meuNome, MAX_PLAYER_NAME);
  666.  
  667.         banirConta(conta_, meuNome, motivo_, (gettime() + (dias_ * 86400)));
  668.  
  669.         format (Query, 1024, "AdmCmd: %s foi banido temporariamente (%d dia(s)) por %s[ID: %d] motivo: %s", conta_, dias_, meuNome, playerid, motivo_);
  670.         SendClientMessageToAll(0xFF6347AA, Query);
  671.  
  672.         new i, NOME2_[MAX_PLAYER_NAME];
  673.  
  674.         for ( i = 0; i < MAX_PLAYERS; ++i) {
  675.  
  676.             if (IsPlayerConnected(i)) {
  677.  
  678.                 GetPlayerName(i, NOME2_, MAX_PLAYER_NAME);
  679.                 if (!strcmp(conta_, NOME2_)) {
  680.  
  681.                     Kick(i);
  682.                     break;
  683.                 }
  684.             }
  685.         }
  686.  
  687.         return 1;
  688.     }
  689.  
  690.     if (!strcmp(cmd, "/banip")) {
  691.  
  692.         if (!IsPlayerAdmin(playerid))
  693.             return SendClientMessage(playerid, 0xFF0000FF, "Comando restrito a administradores RCON!");
  694.  
  695.         new ip_[24], motivo_[64];
  696.  
  697.         ip_ = strtok(cmdtext, idx);
  698.  
  699.         new length = strlen(cmdtext);
  700.         while ((idx < length) && (cmdtext[idx] <= ' '))
  701.         {
  702.             idx++;
  703.         }
  704.         new offset = idx;
  705.         while ((idx < length) && ((idx - offset) < (sizeof(motivo_) - 1)))
  706.         {
  707.             motivo_[idx - offset] = cmdtext[idx];
  708.             idx++;
  709.         }
  710.         motivo_[idx - offset] = EOS;
  711.  
  712.         if (strlen(ip_) < 8 || !strlen(motivo_))
  713.             return SendClientMessage(playerid, 0xFF0000FF, "Uso correto: /banip [IP] [MOTIVO]");
  714.  
  715.         new DBResult:verificarIP;
  716.  
  717.         format (Query, 1024, "SELECT * FROM ips_banidos WHERE ip = '%s'", ip_);
  718.         verificarIP = db_query(cBan, Query);
  719.  
  720.         if ( db_num_rows(verificarIP) > 0 )
  721.             return SendClientMessage(playerid, 0xFF0000FF, "Este IP ja se encontra BANIDO!");
  722.  
  723.         db_free_result(verificarIP);
  724.  
  725.         new meuNome[MAX_PLAYER_NAME];
  726.         GetPlayerName(playerid, meuNome, MAX_PLAYER_NAME);
  727.  
  728.         banirIP(ip_, meuNome, motivo_);
  729.  
  730.         format (Query, 1024, "AdmCmd: O IP %s foi banido por %s[ID: %d] motivo: %s", ip_, meuNome, playerid, motivo_);
  731.         SendClientMessageToAll(0xFF6347AA, Query);
  732.  
  733.         new i, IP2_[16];
  734.  
  735.         for ( i = 0; i < MAX_PLAYERS; ++i) {
  736.  
  737.             if (IsPlayerConnected(i)) {
  738.  
  739.                 GetPlayerIp(i, IP2_, 16);
  740.                 if (!strcmp(ip_, IP2_))
  741.                     Kick(i);
  742.             }
  743.         }
  744.  
  745.         return 1;
  746.     }
  747.  
  748.     if (!strcmp("/baniptemp", cmd)) {
  749.  
  750.         if (!IsPlayerAdmin(playerid))
  751.             return SendClientMessage(playerid, 0xFF0000FF, "Comando restrito a administradores RCON!");
  752.  
  753.         new ip_[24], motivo_[64], dias[24];
  754.  
  755.         ip_ = strtok(cmdtext, idx), dias = strtok(cmdtext, idx);
  756.  
  757.         new length = strlen(cmdtext);
  758.         while ((idx < length) && (cmdtext[idx] <= ' '))
  759.         {
  760.             idx++;
  761.         }
  762.         new offset = idx;
  763.         while ((idx < length) && ((idx - offset) < (sizeof(motivo_) - 1)))
  764.         {
  765.             motivo_[idx - offset] = cmdtext[idx];
  766.             idx++;
  767.         }
  768.         motivo_[idx - offset] = EOS;
  769.  
  770.         if (strlen(ip_) < 8 || !strlen(motivo_) || !strlen(dias))
  771.             return SendClientMessage(playerid, 0xFF0000FF, "Uso correto: /baniptemp [IP] [DIAS] [MOTIVO]");
  772.  
  773.         new dias_ = strval(dias);
  774.  
  775.         if (dias_ <= 0)
  776.             return SendClientMessage(playerid, 0xFF0000FF, "Número de dias inválido!");
  777.  
  778.         new DBResult:verificarIP;
  779.  
  780.         format (Query, 1024, "SELECT * FROM ips_banidos WHERE ip = '%s'", ip_);
  781.         verificarIP = db_query(cBan, Query);
  782.  
  783.         if ( db_num_rows(verificarIP) > 0 )
  784.             return SendClientMessage(playerid, 0xFF0000FF, "Este IP ja se encontra BANIDO!");
  785.  
  786.         db_free_result(verificarIP);
  787.  
  788.         new meuNome[MAX_PLAYER_NAME];
  789.         GetPlayerName(playerid, meuNome, MAX_PLAYER_NAME);
  790.  
  791.         banirIP(ip_, meuNome, motivo_, (gettime() + (dias_ * 86400)));
  792.  
  793.         format (Query, 1024, "AdmCmd: O IP %s foi banido temporariamente( %d dia(s) ) por %s[ID: %d] motivo: %s", ip_, dias_, meuNome, playerid, motivo_);
  794.         SendClientMessageToAll(0xFF6347AA, Query);
  795.  
  796.         new i, IP2_[16];
  797.  
  798.         for ( i = 0; i < MAX_PLAYERS; ++i) {
  799.  
  800.             if (IsPlayerConnected(i)) {
  801.  
  802.                 GetPlayerIp(i, IP2_, 16);
  803.                 if (!strcmp(ip_, IP2_))
  804.                     Kick(i);
  805.             }
  806.         }
  807.  
  808.         return 1;
  809.     }
  810.  
  811.     if (!strcmp("/desbanconta", cmd)) {
  812.  
  813.         if (!IsPlayerAdmin(playerid))
  814.             return SendClientMessage(playerid, 0xFF0000FF, "Comando restrito a administradores RCON!");
  815.  
  816.         new conta_[MAX_PLAYER_NAME];
  817.  
  818.         conta_ = strtok(cmdtext, idx);
  819.  
  820.         if ( strlen(conta_) < 3 )
  821.             return SendClientMessage(playerid, 0xFF0000FF, "Uso correto: /desbanconta [CONTA]");
  822.  
  823.         new DBResult:verificarConta;
  824.  
  825.         format (Query, 1024, "SELECT * FROM usuarios_banidos WHERE nome = '%s'", conta_);
  826.         verificarConta = db_query(cBan, Query);
  827.  
  828.         if ( db_num_rows(verificarConta) > 0 ) {
  829.  
  830.             desbanirConta(conta_);
  831.             format (Query, 1024, "AdmCmd: A conta %s foi desbanida com sucesso!", conta_);
  832.             SendClientMessage(playerid, 0xFF6347AA, Query);
  833.         }
  834.         else
  835.             SendClientMessage(playerid, 0xFF0000FF, "Nenhum usuário com este nome esta banido!");
  836.  
  837.         db_free_result(verificarConta);
  838.  
  839.         return 1;
  840.     }
  841.  
  842.     if (!strcmp("/desbanip", cmd)) {
  843.  
  844.         if (!IsPlayerAdmin(playerid))
  845.             return SendClientMessage(playerid, 0xFF0000FF, "Comando restrito a administradores RCON!");
  846.  
  847.         new ip_[24];
  848.         ip_ = strtok(cmdtext, idx);
  849.  
  850.         if (strlen(ip_) < 8 )
  851.             return SendClientMessage(playerid, 0xFF0000FF, "Uso correto: /desbanip [IP]");
  852.  
  853.         new DBResult:verificarIP;
  854.  
  855.         format (Query, 1024, "SELECT * FROM ips_banidos WHERE ip = '%s'", ip_);
  856.         verificarIP = db_query(cBan, Query);
  857.  
  858.         if ( db_num_rows(verificarIP) > 0 ) {
  859.  
  860.             desbanirIP(ip_);
  861.             format (Query, 1024, "AdmCmd: O IP %s foi desbanido com sucesso!", ip_);
  862.             SendClientMessage(playerid, 0xFF6347AA, Query);
  863.         }
  864.         else
  865.             SendClientMessage(playerid, 0xFF0000FF, "IP informado não esta banido!");
  866.  
  867.         db_free_result(verificarIP);
  868.  
  869.         return 1;
  870.     }
  871.  
  872.     if (!strcmp(cmd, "/ajudaban")) {
  873.  
  874.         if (!IsPlayerAdmin(playerid))
  875.             return SendClientMessage(playerid, 0xFF0000FF, "Comando restrito a administradores RCON!");
  876.  
  877.         ShowPlayerDialog(playerid, 9999, DIALOG_STYLE_MSGBOX, "Menu de ajuda do cBan!", "\t{FF0000}Comandos disponíveis!\n{FFFFFF}/ban\n{FFFFFF}/bantemp\n{FFFFFF}/banconta\n{FFFFFF}/bantempconta\n{FFFFFF}/banip\n{FFFFFF}/baniptemp\n{FFFFFF}/desbanconta\n{FFFFFF}/desbanip\n{FFFFFF}/blacklist", "Fechar", #);
  878.  
  879.         return 1;
  880.     }
  881.    
  882.     if (!strcmp(cmd, "/blacklist")) {
  883.  
  884.         ShowPlayerDialog(playerid, BLACK_LIST_TIPO, DIALOG_STYLE_MSGBOX, "{FFFFFF}Black list", "{FFFFFF}Clique em {FF0000}Usuários {FFFFFF}se você deseja {FF0000}ver a lista de usuários banidos {FFFFFF}ou em {FF0000}IPs {FFFFFF}caso queira {FF0000}ver a lista de IPs bloqueados!", "Usuários", "IPs");
  885.         return 1;
  886.     }
  887.  
  888.     return 0;
  889. }
  890.  
  891. forward Kicka(p); public Kicka(p) {
  892.     #undef Kick
  893.     Kick(p);
  894.     #define Kick(%0) SetTimerEx("Kicka", 100, false, "i", %0)
  895.     return 1;
  896. }
  897.  
  898. forward Bana(p); public Bana(p) {
  899.     #undef Ban
  900.     Ban(p);
  901.     #define Ban(%0) SetTimerEx("Bana", 100, false, "i", %0)
  902.     return 1;
  903. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement