Advertisement
whiplk

[FS] - Sistema login/registro(simples)

Nov 13th, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.41 KB | None | 0 0
  1. //sistema simples, requer modificações de programador para programador, as modificações estão marcadas com //comentários
  2. //Includes
  3. #include <a_samp>
  4. #include <SII>
  5.  
  6. //Defines
  7. #define STREAM_REGIS_IDX 1 // ID inicial do dialog, pode ser modificado para evitar conflitos com outros scripts.
  8. #define STREAM_LOGIN_IDX 2 // ||
  9. #define login<%0,%1> ShowPlayerDialog(%0, %1, DIALOG_STYLE_PASSWORD, "capt", "msg", "but1", "but2"); // redirecionamento ao login(requer inserir capt, mensagem, but1, but2)
  10. #define register<%0,%1> ShowPlayerDialog(%0, %1, DIALOG_STYLE_PASSWORD, "capt", "msg", "but1", "but2"); // redirecionamento ao registro(requer inserir capt, mensagem, but1, but2)
  11.  
  12. main(){}
  13.  
  14. //Nativas:
  15. public OnPlayerConnect(playerid)
  16. {
  17.     //Verifica se existe o .ini (player)
  18.     if (_ExistsAcc(playerid)) return login<playerid, STREAM_LOGIN_IDX> //redireciona ao login caso exista.
  19.     else return register<playerid, STREAM_REGIS_IDX> //redireciona ao cadastro caso contrário.
  20. }
  21. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  22. {
  23.     //verifica se o dialogid aberto é de login ou registro
  24.     if (dialogid == STREAM_REGIS_IDX)
  25.     {
  26.         //verifica se a string é nula, se o tamanho dela é maior que 4 e menor que 15
  27.         if (inputtext[0] != '\0' && strlen(inputtext) > 4 && strlen(inputtext) < 15)
  28.         {
  29.             register(playerid, inputtext); //registro completo
  30.         }
  31.     }
  32.     if (dialogid == STREAM_LOGIN_IDX)
  33.     {
  34.         if (inputtext[0] != '\0' && strlen(inputtext) > 4 && strlen(inputtext) < 15)
  35.         {
  36.             if (login(playerid, inputtext))
  37.             {
  38.                 return 1; //Iniciar login
  39.             }
  40.         }
  41.     }
  42.     return 1;
  43. }
  44.  
  45. //Stocks de auxilio:
  46. stock register(playerid, senha[])
  47. {
  48.     new LWS_l_str[30];
  49.     format(LWS_l_str, 30, "%s.ini", _AccName(playerid));
  50.     INI_Open(LWS_l_str);
  51.     INI_WriteString("Senha", senha);
  52.     INI_Save();
  53.     INI_Close();
  54.     return 1;
  55. }
  56. stock login(playerid, senha[])
  57. {
  58.     new LWS_l_str[30], LWS_l_temp[15];
  59.     format(LWS_l_str, 30, "%s.ini", _AccName(playerid));
  60.     INI_Open(LWS_l_str);
  61.     INI_ReadString(LWS_l_temp, "Senha", 15);
  62.     INI_Save();
  63.     INI_Close();
  64.     return strcmp(senha, LWS_l_temp)==0?1:0;
  65. }
  66. stock _ExistsAcc(playerid)
  67. {
  68.     new LWS_l_acc[MAX_PLAYER_NAME + 5];
  69.     format(LWS_l_acc, sizeof(LWS_l_acc), "%s.ini", _AccName(playerid));
  70.     return fexist(LWS_l_acc);
  71. }
  72. stock _AccName(playerid)
  73. {
  74.     new LWS_l_nome[MAX_PLAYER_NAME];
  75.     GetPlayerName(playerid, LWS_l_nome, MAX_PLAYER_NAME);
  76.     return LWS_l_nome;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement