Advertisement
Guest User

easyway.pwn

a guest
May 17th, 2017
952
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 27.70 KB | None | 0 0
  1. /* --> News:
  2.     Adicionado limite máximo de tentativas para acertar a rcon
  3.     Callbacks "OnDayChange" e "OnMonthChange" adicionadas
  4.     Salvamento do tempo jogado do jogador
  5.     Função "showPlayerInfo" criada, ela é chamada pelo comando /info e em OnPlayerClickPlayer. Nessa função mostra
  6.     todas as informações do player.
  7. */
  8.  
  9. //-------------------------------------------------------------------//
  10. //**************************** INCLUDES *****************************//
  11. //-------------------------------------------------------------------//
  12.  
  13. #include                               
  14. #include                                
  15. #include                               
  16. #include                               
  17. #include                               
  18. #include                                
  19. #include                                
  20. #include                               
  21. #include                               
  22.  
  23. //-------------------------------------------------------------------//
  24. //************************* DEFINIÇÕES ******************************//
  25. //********************* Você pode alterar ***************************//
  26. //-------------------------------------------------------------------//
  27.  
  28. // --> Configurações
  29. #define SERVER_NAME                     ("EasyWay")
  30. #define SERVER_VERSION                  ("0.1")
  31. #define MAX_LOGIN_ATTEMPTS              (3) // --> Máximo de tentativas para acertar a senha
  32. #define MAX_CONNECTIONS_FROM_IP         (3) // --> Máximo de IPs conectados ao mesmo tempo
  33. #define MINUTES_TO_LOGIN                (5) // --> Em minutos, tempo limite para o jogador se logar / registrar.
  34. #define MAX_RCON_ATTEMPTS               (3) // --> Máximo de tentativas para acertar a rcon
  35.  
  36. // --> Mensagens
  37. #define MSG_CMD_WITHOUT_PERMISSION      "Você não tem permissão para usar este comando."
  38. #define MSG_PLAYER_OFF                  "Jogador não conectado."
  39.  
  40. // --> Cores
  41. #define COLOR_BLUE                      (0x2641FEFF)
  42. #define COLOR_GREY                      (0xAFAFAFFF)
  43. #define COLOR_LIGHTRED                  (0xFF6347FF)
  44. #define COLOR_LIGHTBLUE                 (0x33CCFFAA)
  45. #define COLOR_LIGHTGREEN                (0x66ff66FF)
  46. #define COLOR_CLIENT                    (0xAAC4E5FF)
  47. #define COLOR_TEAL                      (0x00A180FF)
  48. #define COLOR_ORANGE                    (0xFF9409FF)
  49. #define COLOR_PURPLE                    (0xD0AEEBFF)
  50. #define COLOR_OPENSERV                  (0xFFBD9DFF)
  51. #define COLOR_WHITE                     (0xFFFFFFFF)
  52. #define COLOR_PINK                      (0xFF66FFAA)
  53. #define COLOR_RED                       (0xFF0000AA)
  54. #define COLOR_YELLOW                    (0xFFFF00AA)
  55. #define COLOR_GREEN                     (0x33AA33AA)
  56. #define COLOR_LIGHTBLUE2                (0x99ccffAA)
  57. #define COLOR_BROWN                     (0xA8623EAA)
  58. #define COLOR_LIGHTBROWN                (0xf4ac94AA)
  59. #define COLOR_LIGHTBROWN2               (0xc7a6afAA)
  60.  
  61. // --> Cores para dialogs e dentre outras coisas
  62. #define COLOR_TITLE_DIALOG              "{00a180}"
  63. #define COLORT_GREEN                    "{49ad00}"
  64. #define COLORT_YELLOW                   "{fff600}"
  65. #define COLORT_WHITE                    "{ffffff}"
  66. #define COLORT_LIGHTRED                 "{e44235}"
  67. #define COLORT_ORANGE                   "{ff9409}"
  68. #define COLORT_ORANGE2                  "{f2bb73}"
  69. #define COLORT_GREY                     "{a4a4a4}"
  70.  
  71. //-------------------------------------------------------------------//
  72. //************************ !DEFINIÇÕES! *****************************//
  73. //******************** Cuidado ao alterar ***************************//
  74. //-------------------------------------------------------------------//
  75.  
  76. #define DIALOG_REGISTER                 (1) // até 20
  77. #define DIALOG_LOGIN                    (21) // até 24
  78. #define DIALOG_KICK                     (25)
  79. #define DIALOG_MESSAGE                  (26)
  80. #define DIALOG_UNBAN                    (27)
  81.  
  82. #define sendServerMessage(%0,%1)
  83.     sendClientMessageEx(%0, COLOR_TEAL, "[SERVER]:{FFFFFF} "%1)
  84.  
  85. #define sendSyntaxMessage(%0,%1)
  86.     sendClientMessageEx(%0, COLOR_GREY, "[USO CORRETO]:{FFFFFF} "%1)
  87.  
  88. #define sendErrorMessage(%0,%1)
  89.     sendClientMessageEx(%0, COLOR_LIGHTRED, "[ERRO]:{FFFFFF} "%1)
  90.  
  91. #define sendAdminAction(%0,%1)
  92.     sendClientMessageEx(%0, COLOR_CLIENT, "[ADMIN]:{FFFFFF} "%1)
  93.  
  94. #define sendWarningMessage(%0,%1)
  95.     sendClientMessageEx(%0, COLOR_YELLOW, "[AVISO]: "%1)
  96.    
  97. #define MENU_LOGIN_INDEX                (1)
  98. #define MENU_LOGIN_REGISTER             (2)
  99. #define MENU_LOGIN_REGISTER_STAGE_1     (3)
  100. #define MENU_LOGIN_REGISTER_STAGE_2     (4)
  101. #define MENU_LOGIN_REGISTER_STAGE_3     (5)
  102.  
  103. #define PATCH_SERVER                    "server.INI"
  104.  
  105. //-------------------------------------------------------------------//
  106. //*************************** VARIÁVEIS *****************************//
  107. //-------------------------------------------------------------------//
  108.  
  109. new Dialog[2048],
  110.     String[1024],
  111.     Query[1024],
  112.     MySQL:MySQL_Connection = MYSQL_INVALID_HANDLE;
  113.  
  114. enum enum_Player
  115. {
  116.     // Data
  117.     ORM:pORM,
  118.     pAccountID,
  119.     pName[24],
  120.     pPassword[65],
  121.     pEmail[64],
  122.     pRegisterDate,
  123.     pLastLogin,
  124.     pAdmin,
  125.     pPlayed,
  126.  
  127.     // Non-data
  128.     pDialogID,
  129.     bool:pKicked,
  130.     bool:pLogged,
  131.     pAttemptsLogin,
  132.     pAttemptsRcon,
  133.     pTimerPlayer,
  134.     pIP[64],
  135.     pTimeToLogin,
  136.    
  137.     // Registro
  138.     registerPassword[30]
  139. }
  140.  
  141. new Player[MAX_PLAYERS][enum_Player];
  142.  
  143. enum enum_Server
  144. {
  145.     MonthBuilt[32],
  146.     DayBuilt[32]
  147. }
  148.  
  149. new Server[enum_Server];
  150.  
  151. //-------------------------------------------------------------------//
  152. //**************************** FORWARDS *****************************//
  153. //-------------------------------------------------------------------//
  154.  
  155. forward KickTimer(playerid);
  156. forward OnPlayerDataLoaded(playerid);
  157. forward OnPlayerRegister(playerid);
  158. forward OnPlayerUpdateEx(playerid);
  159. forward TimerOneMinute();
  160. forward OnMonthChange();
  161. forward OnDayChange();
  162.  
  163. //-------------------------------------------------------------------//
  164.  
  165. main()
  166. {
  167.     print("n----------------------------------");
  168.     printf("%s [v%s]", SERVER_NAME, SERVER_VERSION);
  169.     print("----------------------------------n");
  170.    
  171.     INI_Load("server.INI");
  172. }
  173.  
  174. public OnGameModeInit()
  175. {
  176.     print("[MySQL] Estabelecendo conexão com o servidor..");
  177.  
  178.     MySQL_Connection = mysql_connect_file("mysql_connection.ini");
  179.     mysql_log(ALL);
  180.    
  181.     if(MySQL_Connection == MYSQL_INVALID_HANDLE)
  182.     {
  183.         print("[MySQL] Não foi possível realizar a conexão, desligando servidor..");
  184.         SendRconCommand("exit");
  185.     }
  186.     else
  187.         print("[MySQL] Conexão estabelecida com sucesso.");
  188.  
  189.     format(String, sizeof(String), "%s [v%s]", SERVER_NAME, SERVER_VERSION);
  190.     SetGameModeText(String);
  191.    
  192.     SetTimer("TimerOneMinute", (1000*60), true);
  193.  
  194.     AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  195.     return 1;
  196. }
  197.  
  198. public OnGameModeExit()
  199. {
  200.     mysql_close(MySQL_Connection);
  201.     return 1;
  202. }
  203.  
  204. public OnPlayerConnect(playerid)
  205. {
  206.     static connecting_ip[64];
  207.     GetPlayerIp(playerid, connecting_ip, 64);
  208.    
  209.     if(getNumberOfPlayersOnThisIP(connecting_ip) > MAX_CONNECTIONS_FROM_IP)
  210.         return Kick(playerid);
  211.  
  212.     if(!IsPlayerNPC(playerid))
  213.     {
  214.         SetSpawnInfo(playerid, 0, 23, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  215.         clearPlayerVars(playerid);
  216.         loadPlayer(playerid);
  217.  
  218.         Player[playerid][pTimerPlayer] = SetTimerEx("OnPlayerUpdateEx", 1000, true, "i", playerid);
  219.     }
  220.     return 1;
  221. }
  222.  
  223. public OnPlayerRequestClass(playerid, classid)
  224. {
  225.     if(!IsPlayerNPC(playerid))
  226.     {
  227.         TogglePlayerSpectating(playerid, true);
  228.         InterpolateCameraPos(playerid, 1350.289306, -1399.634887, 39.952976, 1346.096069, -989.852233, 74.761276, 1000*40);
  229.         InterpolateCameraLookAt(playerid, 1350.505981, -1394.746826, 38.923583, 1348.108398, -985.276794, 74.885650, 1000*40);
  230.  
  231.         orm_setkey(Player[playerid][pORM], "Name");
  232.         orm_select(Player[playerid][pORM], "OnPlayerDataLoaded", "d", playerid);
  233.     }
  234.     return 1;
  235. }
  236.  
  237.  
  238. public OnPlayerDataLoaded(playerid)
  239. {
  240.     orm_setkey(Player[playerid][pORM], "ID");
  241.  
  242.     switch(orm_errno(Player[playerid][pORM]))
  243.     {
  244.         case ERROR_INVALID:
  245.         {
  246.             sendServerMessage(playerid, "Ocorreu algum problema, entre novamente..");
  247.             kickEx(playerid);
  248.         }
  249.         case ERROR_OK: showLoginMenu(playerid, MENU_LOGIN_INDEX);
  250.         case ERROR_NO_DATA: showLoginMenu(playerid, MENU_LOGIN_REGISTER);
  251.     }
  252.    
  253.     mysql_format(MySQL_Connection, Query, sizeof(Query), "SELECT * FROM `banlist` WHERE (`AccountID` = '%d' OR `IP` = '%e') LIMIT 1", Player[playerid][pAccountID], Player[playerid][pIP]);
  254.     inline OnPlayerBanned()
  255.     {
  256.         if(cache_num_rows()) // --> Checar se existe algum resultado
  257.         {
  258.             static IP[64], bannedBy[24], reason[30], date, banTime, banID;
  259.  
  260.             cache_get_value_name_int(0, "Date", date);
  261.             cache_get_value_name_int(0, "BanTime", banTime);
  262.             cache_get_value_name(0, "IP", IP);
  263.             cache_get_value_name(0, "BannedBy", bannedBy);
  264.             cache_get_value_name(0, "Reason", reason);
  265.             cache_get_value_name_int(0, "BanID", banID);
  266.            
  267.             if(banTime > gettime())
  268.             {
  269.                 // --> Ainda está banido
  270.                 Dialog[0] = EOS;
  271.                
  272.                 format(Dialog, sizeof(Dialog),
  273.                 ""#COLORT_YELLOW"Você está banido!nn
  274.                 "#COLORT_WHITE"Nick: "#COLORT_GREY"%sn
  275.                 "#COLORT_WHITE"IP: "#COLORT_GREY"%sn
  276.                 "#COLORT_WHITE"Banido pelo Administrador: "#COLORT_GREY"%sn
  277.                 "#COLORT_WHITE"Motivo: "#COLORT_GREY"%sn
  278.                 "#COLORT_WHITE"Ocorrido em: "#COLORT_GREY"%sn
  279.                 "#COLORT_WHITE"Banido até "#COLORT_GREY"%s",
  280.                 Player[playerid][pName], IP, bannedBy, reason, timestampToDate(date), timestampToDate(banTime));
  281.                
  282.                 showPlayerDialogEx(playerid, DIALOG_KICK, DIALOG_STYLE_MSGBOX, ""#COLOR_TITLE_DIALOG"Banido", Dialog, "Fechar", "");
  283.                 kickEx(playerid);
  284.             }
  285.             else
  286.             {
  287.                 // --> Banimento chegou ao fim
  288.                 format(Query, sizeof(Query), "DELETE FROM `banlist` WHERE `BanID` = '%d'", banID);
  289.                 mysql_tquery(MySQL_Connection, Query);
  290.             }
  291.         }
  292.     }
  293.     mysql_tquery_inline(MySQL_Connection, Query, using inline OnPlayerBanned);
  294. }
  295.  
  296. public OnPlayerRegister(playerid)
  297. {
  298.     sendServerMessage(playerid, "Conta criada com sucesso! Você foi o %dº a criar uma conta.", Player[playerid][pAccountID]);
  299.     Player[playerid][pLogged] = true;
  300.     TogglePlayerSpectating(playerid, false);
  301. }
  302.  
  303.  
  304. public OnPlayerDisconnect(playerid, reason)
  305. {
  306.    if(!IsPlayerNPC(playerid))
  307.     {
  308.         if(Player[playerid][pTimerPlayer] != 0)
  309.             KillTimer(Player[playerid][pTimerPlayer]);
  310.        
  311.         if(Player[playerid][pLogged])
  312.             orm_update(Player[playerid][pORM]);
  313.  
  314.         orm_destroy(Player[playerid][pORM]);
  315.         clearPlayerVars(playerid);
  316.     }
  317.     return 1;
  318. }
  319.  
  320. public OnPlayerRequestSpawn(playerid)
  321. {
  322.    if(!Player[playerid][pLogged])
  323.         return false;
  324.        
  325.     return SpawnPlayer(playerid);
  326. }
  327.  
  328. public OnRconLoginAttempt(ip[], password[], success)
  329. {
  330.    if(!success)
  331.     {
  332.         foreach(new i : Player)
  333.         {
  334.             if(!strcmp(ip, Player[i][pIP]))
  335.             {
  336.                 Player[i][pAttemptsRcon]++;
  337.                 if(Player[i][pAttemptsRcon] > MAX_RCON_ATTEMPTS)
  338.                 {
  339.                     if(Player[i][pLogged])
  340.                         BOT_setPlayerBan(i, 30, "Rcon abuse");
  341.                     else
  342.                         Kick(i);
  343.                     break;
  344.                 }
  345.             }
  346.         }
  347.     }
  348.     return 1;
  349. }
  350.  
  351. public OnPlayerUpdateEx(playerid)
  352. {
  353.     if(!Player[playerid][pLogged])
  354.     {
  355.         Player[playerid][pTimeToLogin]++;
  356.  
  357.         if(Player[playerid][pTimeToLogin] > (MINUTES_TO_LOGIN*60))
  358.         {
  359.             sendWarningMessage(playerid, "Você foi kickado por exceder o limite de tempo sem realizar log-in.");
  360.             kickEx(playerid);
  361.             return true;
  362.         }
  363.     }
  364.     else
  365.     {
  366.         Player[playerid][pPlayed]++;
  367.     }
  368.    
  369.    return true;
  370. }
  371.  
  372. public TimerOneMinute()
  373. {
  374.     foreach(new i : Player)
  375.     {
  376.         if(!Player[i][pLogged])
  377.             continue;
  378.  
  379.         // --> Salvando todos os jogadores conectados
  380.        orm_update(Player[i][pORM]);
  381.     }
  382.    
  383.     static date[3];
  384.     getdate(date[0], date[1], date[2]);
  385.  
  386.     format(String, sizeof(String), "%02d%d", date[1], date[0]);
  387.  
  388.     if(strcmp(String, Server[MonthBuilt], true))
  389.     {
  390.         new INI:iniFile = INI_Open(PATCH_SERVER);
  391.  
  392.         INI_SetTag(iniFile, "data");
  393.         INI_WriteString(iniFile, "MonthBuilt", String);
  394.         INI_Close(iniFile);
  395.  
  396.         CallLocalFunction("OnMonthChange", "");
  397.     }
  398.  
  399.    format(String, sizeof(String), "%02d%02d%d", date[2], date[1], date[0]);
  400.  
  401.     if(strcmp(String, Server[DayBuilt], true))
  402.     {
  403.         new INI:iniFile = INI_Open(PATCH_SERVER);
  404.  
  405.         INI_SetTag(iniFile, "data");
  406.         INI_WriteString(iniFile, "DayBuilt", String);
  407.         INI_Close(iniFile);
  408.  
  409.         CallLocalFunction("OnDayChange", "");
  410.     }
  411.    
  412.     INI_Load("server.INI");
  413. }
  414.  
  415. public OnMonthChange()
  416. {
  417.     // --> Alterou o mês, vamos deletar as contas inativas?
  418.     print("Mudou o mês :DD");
  419. }
  420.  
  421.  
  422. public OnDayChange()
  423. {
  424.     // --> alterou o dia, vamos dar salário a todos os trabalhadores?
  425.    print("Mudou o dia :DD");
  426. }
  427.  
  428. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  429. {
  430.     if(!Player[clickedplayerid][pLogged])
  431.         return false;
  432.  
  433.     return showPlayerInfo(playerid, clickedplayerid);
  434. }
  435.  
  436.  
  437. public OnPlayerCommandReceived(playerid, cmd[], params[], flags)
  438. {
  439.     if(!Player[playerid][pLogged])
  440.         return false;
  441.        
  442.    return true;
  443. }
  444.  
  445. public OnPlayerCommandPerformed(playerid, cmd[], params[], result, flags)
  446. {
  447.    if(result == -1)
  448.    {
  449.        sendErrorMessage(playerid, "Comando "/%s" não existente.", cmd);
  450.        return false;
  451.    }
  452.  
  453.    return true;
  454. }
  455.  
  456. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  457. {
  458.     if(Player[playerid][pDialogID] != dialogid)
  459.     {
  460.         BOT_setPlayerBan(playerid, 30, "Dialog-Hack");
  461.         return true;
  462.     }
  463.    
  464.     switch(dialogid)
  465.     {
  466.         case DIALOG_REGISTER:
  467.         {
  468.             if(!response)
  469.             {
  470.                 sendServerMessage(playerid, "Tudo bem, volte quando quiser criar uma conta!");
  471.                 kickEx(playerid);
  472.                 return true;
  473.             }
  474.  
  475.             showLoginMenu(playerid, MENU_LOGIN_REGISTER_STAGE_1);
  476.             return true;
  477.         }
  478.         case DIALOG_REGISTER+1:
  479.         {
  480.             if(!response)
  481.             {
  482.                 sendServerMessage(playerid, "Tudo bem, volte quando quiser criar uma conta!");
  483.                 kickEx(playerid);
  484.                 return true;
  485.             }
  486.            
  487.             if(isnull(inputtext))
  488.                 return showLoginMenu(playerid, MENU_LOGIN_REGISTER_STAGE_1, ""#COLORT_LIGHTRED"Você precisa digitar uma senha!");
  489.  
  490.             if(!isValidPassword(inputtext))
  491.                 return showLoginMenu(playerid, MENU_LOGIN_REGISTER_STAGE_1, ""#COLORT_LIGHTRED"Senha inválida (somente 6 à 30 dígitos).");
  492.  
  493.             format(Player[playerid][registerPassword], 30, inputtext);
  494.            showLoginMenu(playerid, MENU_LOGIN_REGISTER_STAGE_2);
  495.            return true;
  496.         }
  497.         case DIALOG_REGISTER+2:
  498.         {
  499.             if(!response)
  500.             {
  501.                 Player[playerid][registerPassword][0] = EOS;
  502.                 showLoginMenu(playerid, MENU_LOGIN_REGISTER_STAGE_1);
  503.                 return true;
  504.             }
  505.            
  506.             if(isnull(inputtext))
  507.                 return showLoginMenu(playerid, MENU_LOGIN_REGISTER_STAGE_2, ""#COLORT_LIGHTRED"Você precisa confirmar sua senha!");
  508.  
  509.             if(!strcmp(Player[playerid][registerPassword], inputtext))
  510.                 showLoginMenu(playerid, MENU_LOGIN_REGISTER_STAGE_3);
  511.             else
  512.                 showLoginMenu(playerid, MENU_LOGIN_REGISTER_STAGE_2, ""#COLORT_LIGHTRED"As senhas não combinam!");
  513.            
  514.             return true;
  515.         }
  516.         case DIALOG_REGISTER+3:
  517.         {
  518.             if(!response)
  519.             {
  520.                 Player[playerid][registerPassword][0] = EOS;
  521.                 showLoginMenu(playerid, MENU_LOGIN_REGISTER_STAGE_1);
  522.                 return true;
  523.             }
  524.            
  525.             if(isnull(inputtext))
  526.                 return showLoginMenu(playerid, MENU_LOGIN_REGISTER_STAGE_3, ""#COLORT_LIGHTRED"Você precisa digitar algum e-mail!");
  527.  
  528.             if(!isValidEmail(inputtext))
  529.                 return showLoginMenu(playerid, MENU_LOGIN_REGISTER_STAGE_3, ""#COLORT_LIGHTRED"Digite um e-mail válido!");
  530.                
  531.             if(SQL_verifyEmail(inputtext))
  532.                 return showLoginMenu(playerid, MENU_LOGIN_REGISTER_STAGE_3, ""#COLORT_LIGHTRED"Este e-mail já está em uso.");
  533.  
  534.             // --> Registro concluido
  535.            
  536.            SHA256_PassHash(Player[playerid][registerPassword], "EveryBodyHatesCris", Player[playerid][pPassword], 65);
  537.            format(Player[playerid][pEmail], 64, inputtext);
  538.            
  539.            Player[playerid][pRegisterDate] = gettime();
  540.            Player[playerid][pLastLogin] = gettime();
  541.            
  542.             orm_insert(Player[playerid][pORM], "OnPlayerRegister", "d", playerid);
  543.         }
  544.         case DIALOG_LOGIN:
  545.         {
  546.             if(!response)
  547.             {
  548.                 sendServerMessage(playerid, "Volte sempre.");
  549.                 kickEx(playerid);
  550.                 return true;
  551.             }
  552.            
  553.             if(isnull(inputtext))
  554.                 return showLoginMenu(playerid, MENU_LOGIN_INDEX, ""#COLORT_LIGHTRED"Digite sua senha!");
  555.                
  556.            static hash[65];
  557.             SHA256_PassHash(inputtext, "EveryBodyHatesCris", hash, 65);
  558.  
  559.             if(!strcmp(hash, Player[playerid][pPassword]))
  560.             {
  561.                 Player[playerid][pLogged] = true;
  562.  
  563.                 sendServerMessage(playerid, "Logado com suceso!");
  564.                 sendServerMessage(playerid, "Seu último login foi em %s.", timestampToDate(Player[playerid][pLastLogin]));
  565.                
  566.                 Player[playerid][pLastLogin] = gettime();
  567.                
  568.                 TogglePlayerSpectating(playerid, false);
  569.             }
  570.             else
  571.             {
  572.                 Player[playerid][pAttemptsLogin]++;
  573.                
  574.                 if(Player[playerid][pAttemptsLogin] == MAX_LOGIN_ATTEMPTS)
  575.                 {
  576.                     sendWarningMessage(playerid, "Você foi kickado por excessos de tentativas.");
  577.                     kickEx(playerid);
  578.                 }
  579.                 else showLoginMenu(playerid, MENU_LOGIN_INDEX, ""#COLORT_LIGHTRED"Senha inválida.");
  580.             }
  581.            
  582.             return true;
  583.         }
  584.         case DIALOG_UNBAN:
  585.         {
  586.             if(!response)
  587.             {
  588.                 DeletePVar(playerid, "BanID");
  589.                 DeletePVar(playerid, "params");
  590.                 return true;
  591.             }
  592.  
  593.             static banID, params[64];
  594.             banID = GetPVarInt(playerid, "BanID");
  595.             GetPVarString(playerid, "params", params, sizeof(params));
  596.            
  597.             switch(listitem)
  598.             {
  599.                 case 0: // Unban Account
  600.                 {
  601.                     format(Query, sizeof(Query), "UPDATE `banlist` SET `AccountID` = '-1' WHERE `BanID` = '%d'", banID);
  602.                     mysql_tquery(MySQL_Connection, Query);
  603.                    
  604.                     sendAdminAction(playerid, "Você desbaniu a conta "%s".", params);
  605.                 }
  606.                 case 1: // Unban IP
  607.                 {
  608.                     format(Query, sizeof(Query), "UPDATE `banlist` SET `IP` = 'N/A' WHERE `BanID` = '%d'", banID);
  609.                     mysql_tquery(MySQL_Connection, Query);
  610.                    
  611.                     sendAdminAction(playerid, "Você desbaniu o IP "%s".", params);
  612.                 }
  613.                 case 2: // Unban all
  614.                 {
  615.                     format(Query, sizeof(Query),"DELETE FROM `banlist` WHERE `BanID` = '%d'", banID);
  616.                     mysql_tquery(MySQL_Connection, Query);
  617.                    
  618.                     sendAdminAction(playerid, "Você desbaniu tudo de "%s".", params);
  619.                 }
  620.             }
  621.  
  622.             return true;
  623.         }
  624.     }
  625.  
  626.     return false;
  627. }
  628.  
  629. public KickTimer(playerid)
  630. {
  631.     if(Player[playerid][pKicked])
  632.         return Kick(playerid);
  633.  
  634.     return false;
  635. }
  636.  
  637. //-------------------------------------------------------------------//
  638. //*************************** COMANDOS ******************************//
  639. //-------------------------------------------------------------------//
  640.  
  641. CMD:info(playerid)
  642.     return showPlayerInfo(playerid, playerid);
  643.  
  644. CMD:setadmin(playerid, params[])
  645. {
  646.    if(!IsPlayerAdmin(playerid))
  647.         return sendErrorMessage(playerid, MSG_CMD_WITHOUT_PERMISSION);
  648.  
  649.     static id, level;
  650.  
  651.    if(sscanf(params, "ui", id, level))
  652.         return sendSyntaxMessage(playerid, "/setadmin  ");
  653.  
  654.    if(id == INVALID_PLAYER_ID)
  655.         return sendErrorMessage(playerid, MSG_PLAYER_OFF);
  656.  
  657.    if(!(level >= 0 && level  Player
  658.  
  659. stock loadPlayer(playerid)
  660. {
  661.     GetPlayerName(playerid, Player[playerid][pName], 24);
  662.     GetPlayerIp(playerid, Player[playerid][pIP], 64);
  663.    
  664.     new ORM:ormid = Player[playerid][pORM] = orm_create("players");
  665.     orm_addvar_int(ormid, Player[playerid][pAccountID], "ID");
  666.     orm_addvar_string(ormid, Player[playerid][pName], 24, "Name");
  667.     orm_addvar_string(ormid, Player[playerid][pPassword], 65, "Password");
  668.     orm_addvar_string(ormid, Player[playerid][pEmail], 64, "Email");
  669.     orm_addvar_int(ormid, Player[playerid][pLastLogin], "LastLogin");
  670.     orm_addvar_int(ormid, Player[playerid][pRegisterDate], "RegisterDate");
  671.     orm_addvar_int(ormid, Player[playerid][pAdmin], "Admin");
  672.     orm_addvar_int(ormid, Player[playerid][pPlayed], "Played");
  673. }
  674.  
  675. stock showLoginMenu(playerid, menuid, message[] = "")
  676. {
  677.     switch(menuid)
  678.     {
  679.         case MENU_LOGIN_INDEX:
  680.         {
  681.             format(String, sizeof(String), "%snn", message);
  682.             format(Dialog, sizeof(Dialog), ""#COLORT_WHITE"Bem-vindo novamente "#COLORT_YELLOW"%s!nn%s"#COLORT_WHITE"Digite sua senha para logar:", Player[playerid][pName], (isnull(message) ? "" : String));
  683.             showPlayerDialogEx(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, ""#COLOR_TITLE_DIALOG"Login", Dialog, "Entrar", "Sair");
  684.         }
  685.         case MENU_LOGIN_REGISTER:
  686.         {
  687.             format(Dialog, sizeof(Dialog), ""#COLORT_WHITE"Bem-vindo "#COLORT_YELLOW"%s!nn"#COLORT_WHITE"Vejo que você não tem uma conta, vamos criar uma?", Player[playerid][pName]);
  688.             showPlayerDialogEx(playerid, DIALOG_REGISTER, DIALOG_STYLE_MSGBOX, ""#COLOR_TITLE_DIALOG"Registro", Dialog, "Sim", "Não");
  689.         }
  690.         case MENU_LOGIN_REGISTER_STAGE_1:
  691.         {
  692.             format(String, sizeof(String), "%snn", message);
  693.             format(Dialog, sizeof(Dialog), "%s"COLORT_WHITE"Para começar, digite uma senha de 6 à 30 dígitos:", (isnull(message) ? "" : String));
  694.            showPlayerDialogEx(playerid, DIALOG_REGISTER+1, DIALOG_STYLE_PASSWORD, ""#COLOR_TITLE_DIALOG"Registro [1/3]", Dialog, "Prosseguir", "Sair");
  695.         }
  696.         case MENU_LOGIN_REGISTER_STAGE_2:
  697.         {
  698.             format(String, sizeof(String), "%snn", message);
  699.             format(Dialog, sizeof(Dialog), "%s"COLORT_WHITE"Agora para confirmar, digite novamente a senha escolhida:", (isnull(message) ? "" : String));
  700.            showPlayerDialogEx(playerid, DIALOG_REGISTER+2, DIALOG_STYLE_PASSWORD, ""#COLOR_TITLE_DIALOG"Registro [2/3]", Dialog, "Prosseguir", "Voltar");
  701.         }
  702.         case MENU_LOGIN_REGISTER_STAGE_3:
  703.         {
  704.             format(String, sizeof(String), "%snn", message);
  705.             format(Dialog, sizeof(Dialog), "%s"COLORT_WHITE"Para terminar, digite um e-mail válido:", (isnull(message) ? "" : String));
  706.            showPlayerDialogEx(playerid, DIALOG_REGISTER+3, DIALOG_STYLE_INPUT, ""#COLOR_TITLE_DIALOG"Registro [3/3]", Dialog, "Concluir", "Voltar");
  707.         }
  708.     }
  709.     return true;
  710. }
  711.  
  712. stock clearPlayerVars(playerid)
  713. {
  714.     // Data
  715.     Player[playerid][pName][0] = EOS;
  716.     Player[playerid][pAccountID] = 0;
  717.     Player[playerid][pPassword][0] = EOS;
  718.     Player[playerid][pEmail][0] = EOS;
  719.     Player[playerid][pRegisterDate] = 0;
  720.     Player[playerid][pLastLogin] = 0;
  721.    Player[playerid][pAdmin] = 0;
  722.    Player[playerid][pPlayed] = 0;
  723.    
  724.     // Non-data
  725.     Player[playerid][pKicked] = false;
  726.     Player[playerid][pDialogID] = 0;
  727.     Player[playerid][pLogged] = false;
  728.     Player[playerid][pIP][0] = EOS;
  729.     Player[playerid][pTimerPlayer] = 0;
  730.     Player[playerid][pTimeToLogin] = 0;
  731.     Player[playerid][pAttemptsLogin] = 0;
  732.     Player[playerid][pAttemptsRcon] = 0;
  733.    
  734.     // Registro
  735.     Player[playerid][registerPassword][0] = EOS;
  736. }
  737.  
  738. stock setPlayerBan(adminid, id, days, reason[])
  739. {
  740.     static accountid;
  741.     accountid = Player[id][pAccountID];
  742.    
  743.     if(accountid == 0)
  744.         accountid = -1;
  745.    
  746.     days = gettime()+((60*60*24)*days);
  747.    
  748.    mysql_format(MySQL_Connection, Query, sizeof(Query), "INSERT INTO `banlist`(`AccountID`, `IP`, `Reason`, `Date`, `BannedBy`, `BanTime`) VALUES('%d', '%e', '%e', '%d', '%e', '%d')", accountid, Player[id][pIP], reason, gettime(), Player[adminid][pName], days);
  749.     mysql_tquery(MySQL_Connection, Query);
  750.     return kickEx(id);
  751. }
  752.  
  753. stock BOT_setPlayerBan(id, days, reason[])
  754. {
  755.     static accountid;
  756.     accountid = Player[id][pAccountID];
  757.  
  758.     if(accountid == 0)
  759.         accountid = -1;
  760.  
  761.     days = gettime()+((60*60*24)*days);
  762.  
  763.    mysql_format(MySQL_Connection, Query, sizeof(Query), "INSERT INTO `banlist`(`AccountID`, `IP`, `Reason`, `Date`, `BannedBy`, `BanTime`) VALUES('%d', '%e', '%e', '%d', 'BOT', '%d')", accountid, Player[id][pIP], reason, gettime(), days);
  764.     mysql_tquery(MySQL_Connection, Query);
  765.     return Kick(id);
  766. }
  767.  
  768. stock showPlayerInfo(playerid, target)
  769. {
  770.     Dialog[0] = EOS;
  771.    
  772.     format(String, sizeof(String), ""#COLORT_WHITE"Nick: "#COLORT_GREY"%s (ID de Conta: %d)n", Player[target][pName], Player[target][pAccountID]);
  773.     strcat(Dialog, String);
  774.     format(String, sizeof(String), ""#COLORT_WHITE"Registrado em: "#COLORT_GREY"%sn", timestampToDate(Player[target][pRegisterDate]));
  775.     strcat(Dialog, String);
  776.     format(String, sizeof(String), ""#COLORT_WHITE"E-mail: "#COLORT_GREY"%sn", Player[target][pEmail]);
  777.     strcat(Dialog, String);
  778.     format(String, sizeof(String), ""#COLORT_WHITE"Tempo de Jogo: "#COLORT_GREY"%s", convertToTime(Player[target][pPlayed]));
  779.     strcat(Dialog, String);
  780.  
  781.     return showPlayerDialogEx(playerid, DIALOG_MESSAGE, DIALOG_STYLE_MSGBOX, ""#COLOR_TITLE_DIALOG"Informações da Conta", Dialog, "Fechar", "");
  782. }
  783.  
  784. // --> Utilidades
  785.  
  786. stock sendClientMessageToAllEx(color, const str[], va_args)
  787. {
  788.     va_format(String, 144, str, va_start);
  789.     return SendClientMessageToAll(color, String);
  790. }
  791.  
  792. stock sendClientMessageEx(playerid, color, const str[], va_args)
  793. {
  794.     va_format(String, 144, str, va_start);
  795.     return SendClientMessage(playerid, color, String);
  796. }
  797.  
  798. stock showPlayerDialogEx(playerid, dialogid, style, caption[], info[], button1[], button2[])
  799. {
  800.    Player[playerid][pDialogID] = dialogid;
  801.    ShowPlayerDialog(playerid, dialogid, style, caption, info, button1, button2);
  802.    return dialogid;
  803. }
  804.  
  805. stock kickEx(playerid)
  806. {
  807.     if(Player[playerid][pKicked])
  808.         return false;
  809.  
  810.     Player[playerid][pKicked] = true;
  811.     SetTimerEx("KickTimer", 200, false, "d", playerid);
  812.     return true;
  813. }
  814.  
  815. stock isValidPassword(password[])
  816. {
  817.    if(30 < strlen(password) || strlen(password) < 6)
  818.        return false;
  819.  
  820.     return true;
  821. }
  822.  
  823. stock SQL_verifyEmail(email[]) // Checar se o email já é usado, true = sim, false = não
  824. {
  825.    static Cache:result, exists;
  826.  
  827.     mysql_format(MySQL_Connection, Query, sizeof(Query), "SELECT * FROM `players` WHERE `Email` = '%e' LIMIT 1", email);
  828.     result = mysql_query(MySQL_Connection, Query, true);
  829.    exists = !!cache_num_rows();
  830.  
  831.     cache_delete(result);
  832.    return exists;
  833. }
  834.  
  835. stock isValidEmail(email[])
  836. {
  837.     static const ValidEmails[17][16] = {
  838.     {"@gmail.com"},
  839.     {"@hotmail.com.br"},
  840.     {"@hotmail.com"},
  841.     {"@globo.com"},
  842.     {"@globomail.com"},
  843.     {"@uol.com"},
  844.     {"@outlook.com"},
  845.     {"@live.com"},
  846.     {"@msn.com"},
  847.     {"@yahoo.com.br"},
  848.     {"@ymail.com"},
  849.     {"@rocketmail.com"},
  850.     {"@ig.com.br"},
  851.     {"@pop.com.br"},
  852.     {"@bol.com.br"},
  853.     {"@oi.com.br"},
  854.     {"@r7.com"}
  855.     };
  856.  
  857.     for(new i; i < sizeof ValidEmails; i++)
  858.         if(strfind(email, ValidEmails[i], false) != -1)
  859.             return true;
  860.  
  861.     return false;
  862. }
  863.  
  864. stock timestampToDate(datetime, style = 0)
  865. {
  866.    static tm;
  867.     localtime(Time:datetime, timestamp);
  868.  
  869.     switch(style)
  870.     {
  871.         case 0: strftime(String, 64, "%d/%m/%Y às %X", timestamp);
  872.         case 1: strftime(String, 64, "%d/%m/%Y", timestamp);
  873.     }
  874.     return String;
  875. }
  876.  
  877. stock hideDialog(playerid)
  878.     return showPlayerDialogEx(playerid, -1, DIALOG_STYLE_MSGBOX, " ", " ", " ", " ");
  879.  
  880. stock getNumberOfPlayersOnThisIP(test_ip[]) // --> by maxips.pwn, atualizei para uma versão mais compacta
  881. {
  882.     static against_ip[64], count;
  883.     count = 0;
  884.    
  885.     foreach(new i : Player)
  886.     {
  887.         GetPlayerIp(i, against_ip, 64);
  888.         if(!strcmp(against_ip, test_ip))
  889.             count++;
  890.     }
  891.    
  892.     return count;
  893. }
  894.  
  895. INI:server[data](name[], value[])
  896. {
  897.     INI_String("MonthBuilt",    Server[MonthBuilt]);
  898.     INI_String("DayBuilt",      Server[DayBuilt]);
  899.    return true;
  900. }
  901.  
  902. stock convertToTime(n) // --> by DanDRT
  903. {
  904.     static t[5];
  905.  
  906.     t[4] = n;
  907.  
  908.     t[0] = t[4] / 3600; // Hour
  909.     t[1] = ((t[4] / 60) - (t[0] * 60)); // Minutes
  910.     t[2] = (t[4] - ((t[0] * 3600) + (t[1] * 60))); // Seconds
  911.     t[3] = (t[0] / 24); // Days
  912.  
  913.     if(t[3] > 0)
  914.         t[0] = t[0] % 24,
  915.         format(String, sizeof(String), "%dd, %02dh, %02dm e %02ds", t[3], t[0], t[1], t[2]);
  916.     else if(t[0] > 0)
  917.         format(String, sizeof(String), "%02dh %02dm e %02ds", t[0], t[1], t[2]);
  918.     else if(t[1] > 0)
  919.         format(String, sizeof(String), "%02dm e %02ds", t[1], t[2]);
  920.     else
  921.         format(String, sizeof(String), "%02ds", t[2]);
  922.  
  923.     return String;
  924. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement