Advertisement
Nyft_

Sistema de Registro/Login DOF2 ~NYFT

Sep 4th, 2020 (edited)
6,371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.20 KB | None | 0 0
  1. #include a_samp
  2. #include dof2
  3.  
  4. // -----------------------------------------------------------------------------
  5.  
  6. #define MAX_PASSWORD                16          // Máximo de caracteres da senha
  7. #define MIN_PASSWORD                4           // Mínimo de caracteres da senha
  8. #define MAX_ATTEMPS_PASSWORD        3           // Tentativas de acertar a senha
  9.  
  10. #define NOVATO_SKIN_MASCULINA       60
  11. #define NOVATO_SKIN_FEMININA        56
  12. #define NOVATO_DINHEIRO_INICIAL     1000
  13.  
  14. #define NOVATO_SPAWN_X              1958.3783
  15. #define NOVATO_SPAWN_Y              1343.1572
  16. #define NOVATO_SPAWN_Z              15.3746
  17. #define NOVATO_SPAWN_A              270.0000
  18.  
  19. // -----------------------------------------------------------------------------
  20.  
  21. enum
  22. {
  23.     DIALOG_CADASTRO,
  24.     DIALOG_CONECTAR,
  25.     DIALOG_SEXUALIDADE
  26. };
  27.  
  28. enum E_PLAYER_DATA
  29. {
  30.     Senha[MAX_PASSWORD],
  31.     UltimoLogin[24],
  32.  
  33.     Sexo,
  34.     Fome,
  35.     Sede,
  36.     Admin,
  37.     Tentativas,
  38.  
  39.     bool:Logado,
  40.     bool:Spawnou,
  41.     bool:Cadastrou,
  42.  
  43.     Float:pX,
  44.     Float:pY,
  45.     Float:pZ,
  46.     Float:pA
  47. };
  48.  
  49. new Player[MAX_PLAYERS][E_PLAYER_DATA];
  50.  
  51. main(){}
  52.  
  53. public OnGameModeExit()
  54. {
  55.     DOF2::Exit();
  56.     return 1;
  57. }
  58.  
  59. public OnPlayerRequestClass(playerid, classid)
  60. {
  61.     if(!Player[playerid][Logado])
  62.     {
  63.         ClearLines(playerid, 30);
  64.         TogglePlayerSpectating(playerid, true);
  65.         InterpolateCameraPos(playerid, 2118.152343, 2142.547363, 43.101249, 2290.450195, 2143.153808, 36.116157, 7500);
  66.         InterpolateCameraLookAt(playerid, 2123.133056, 2142.632324, 42.669498, 2295.448242, 2143.184570, 35.975551, 7500);
  67.  
  68.         // ---------------------------------------------------------------------
  69.  
  70.         if(!DOF2::FileExists(formatFile(playerid)))
  71.             ShowPlayerDialog(playerid, DIALOG_CADASTRO, DIALOG_STYLE_PASSWORD, "Cadastro", "{FFFFFF}Insira uma senha para cadastrar-se:", "Cadastrar", "Sair");
  72.         else
  73.             ShowPlayerDialog(playerid, DIALOG_CONECTAR, DIALOG_STYLE_PASSWORD, "Conectando", "{FFFFFF}Insira sua senha para conectar-se:", "Conectar", "Sair");
  74.     }
  75.     return 1;
  76. }
  77.  
  78. public OnPlayerSpawn(playerid)
  79. {
  80.     if(Player[playerid][Spawnou])
  81.     {
  82.         if(Player[playerid][Cadastrou])
  83.         {
  84.             new string[110];
  85.             ClearLines(playerid, 50);
  86.             Player[playerid][Spawnou] = false;
  87.             Player[playerid][Cadastrou] = false;
  88.  
  89.             format(string, sizeof(string), "{98FB98}* {FFFFFF}Bem-vindo(a) {98FB98}%s{FFFFFF}, pela primeira vez ao nosso servidor.", formatName(playerid));
  90.             SendClientMessage(playerid, -1, string);
  91.             SendClientMessage(playerid, -1, "{98FB98}* {FFFFFF}Caso tenha dúvidas e precisar de ajuda use os comandos {98FB98}/ajuda {FFFFFF}e {98FB98}/comandos{FFFFFF}.");
  92.         }
  93.         else
  94.         {
  95.             new string[135];
  96.             ClearLines(playerid, 50);
  97.             Player[playerid][Spawnou] = false;
  98.  
  99.             format(string, sizeof(string), "{98FB98}* {FFFFFF}Olá {98FB98}%s{FFFFFF}, seu último login no servidor foi: {98FB98}%s{FFFFFF}.", formatName(playerid), Player[playerid][UltimoLogin]);
  100.             SendClientMessage(playerid, -1, string);
  101.             SendClientMessage(playerid, -1, "{98FB98}* {FFFFFF}Caso tenha dúvidas e precisar de ajuda use os comandos {98FB98}/ajuda {FFFFFF}e {98FB98}/comandos{FFFFFF}.");
  102.         }
  103.     }
  104.     return 1;
  105. }
  106.  
  107. public OnPlayerConnect(playerid)
  108. {
  109.     ResetPlayerData(playerid);
  110.     return 1;
  111. }
  112.  
  113. public OnPlayerDisconnect(playerid, reason)
  114. {
  115.     SavePlayerData(playerid);
  116.     return 1;
  117. }
  118.  
  119. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  120. {
  121.     switch(dialogid)
  122.     {
  123.         case DIALOG_CADASTRO:
  124.         {
  125.             if(!response)
  126.                 return Kick(playerid);
  127.  
  128.             if(!(MIN_PASSWORD <= strlen(inputtext) <= MAX_PASSWORD))
  129.             {
  130.                 new dialog[100];
  131.                 format(dialog, sizeof(dialog), "{FFFFFF}Insira uma senha para cadastrar-se:\n\n{FF0000}* Insira uma senha entre %i a %i caracteres.", MIN_PASSWORD, MAX_PASSWORD);
  132.                 ShowPlayerDialog(playerid, DIALOG_CADASTRO, DIALOG_STYLE_PASSWORD, "Cadastro", dialog, "Cadastrar", "Sair");
  133.             }
  134.             else
  135.             {
  136.                 format(Player[playerid][Senha], MAX_PASSWORD, inputtext);
  137.                 format(Player[playerid][UltimoLogin], 24, formatTime());
  138.  
  139.                 // -------------------------------------------------------------
  140.  
  141.                 DOF2::CreateFile(formatFile(playerid));
  142.                 DOF2::SetString(formatFile(playerid), "Senha", Player[playerid][Senha]);
  143.                 DOF2::SetString(formatFile(playerid), "ÚltimoLogin", Player[playerid][UltimoLogin]);
  144.                 DOF2::SetString(formatFile(playerid), "IP", formatIP(playerid));
  145.                 DOF2::SetInt(formatFile(playerid), "Dinheiro", 0);
  146.                 DOF2::SetInt(formatFile(playerid), "Level", 0);
  147.                 DOF2::SetInt(formatFile(playerid), "Skin", 0);
  148.                 DOF2::SetInt(formatFile(playerid), "Interior", 0);
  149.                 DOF2::SetInt(formatFile(playerid), "VirtualWorld", 0);
  150.                 DOF2::SetInt(formatFile(playerid), "Estrelas", 0);
  151.                 DOF2::SetFloat(formatFile(playerid), "Vida", 100.0);
  152.                 DOF2::SetFloat(formatFile(playerid), "Colete", 0.0);
  153.  
  154.                 DOF2::SetInt(formatFile(playerid), "Sexo", Player[playerid][Sexo] = 0);
  155.                 DOF2::SetInt(formatFile(playerid), "Fome", Player[playerid][Fome] = 30);
  156.                 DOF2::SetInt(formatFile(playerid), "Sede", Player[playerid][Sede] = 30);
  157.                 DOF2::SetInt(formatFile(playerid), "Admin", Player[playerid][Admin] = 0);
  158.  
  159.                 DOF2::SetFloat(formatFile(playerid), "X", Player[playerid][pX] = NOVATO_SPAWN_X);
  160.                 DOF2::SetFloat(formatFile(playerid), "Y", Player[playerid][pY] = NOVATO_SPAWN_Y);
  161.                 DOF2::SetFloat(formatFile(playerid), "Z", Player[playerid][pZ] = NOVATO_SPAWN_Z);
  162.                 DOF2::SetFloat(formatFile(playerid), "A", Player[playerid][pA] = NOVATO_SPAWN_A);
  163.                 DOF2::SaveFile();
  164.  
  165.                 // -------------------------------------------------------------
  166.  
  167.                 SendClientMessage(playerid, -1, "{98FB98}* {FFFFFF}Cadastro efetuado com sucesso.");
  168.                 ShowPlayerDialog(playerid, DIALOG_SEXUALIDADE, DIALOG_STYLE_MSGBOX, "Sexualidade", "{FFFFFF}Informe seu sexo abaixo:", "Masculino", "Feminino");
  169.             }
  170.         }
  171.         case DIALOG_SEXUALIDADE:
  172.         {
  173.             Player[playerid][Logado] = true;
  174.             Player[playerid][Spawnou] = true;
  175.             Player[playerid][Cadastrou] = true;
  176.             Player[playerid][Sexo] = (response ? 1 : 2);
  177.  
  178.             TogglePlayerSpectating(playerid, false);
  179.             GivePlayerMoney(playerid, NOVATO_DINHEIRO_INICIAL);
  180.             SendClientMessage(playerid, -1, (response ? "{98FB98}* {FFFFFF}Sexo definido como Masculino." : "{98FB98}* {FFFFFF}Sexo definido como Feminino."));
  181.  
  182.             SetSpawnInfo(playerid, NO_TEAM, (response ? NOVATO_SKIN_MASCULINA : NOVATO_SKIN_FEMININA), Player[playerid][pX], Player[playerid][pY], Player[playerid][pZ], Player[playerid][pA], 0, 0, 0, 0, 0, 0);
  183.             SetCameraBehindPlayer(playerid);
  184.             SpawnPlayer(playerid);
  185.         }
  186.         case DIALOG_CONECTAR:
  187.         {
  188.             if(!response)
  189.                 return Kick(playerid);
  190.  
  191.             if(!strlen(inputtext))
  192.                 return ShowPlayerDialog(playerid, DIALOG_CONECTAR, DIALOG_STYLE_PASSWORD, "Conectando", "{FFFFFF}Insira sua senha para conectar-se:", "Conectar", "Sair");
  193.  
  194.             format(Player[playerid][Senha], MAX_PASSWORD, DOF2::GetString(formatFile(playerid), "Senha"));
  195.             format(Player[playerid][UltimoLogin], 24, DOF2::GetString(formatFile(playerid), "ÚltimoLogin"));
  196.  
  197.             if(!strcmp(Player[playerid][Senha], inputtext))
  198.             {
  199.                 GivePlayerMoney(playerid, DOF2::GetInt(formatFile(playerid), "Dinheiro"));
  200.                 SetPlayerScore(playerid, DOF2::GetInt(formatFile(playerid), "Level"));
  201.                 SetPlayerSkin(playerid, DOF2::GetInt(formatFile(playerid), "Skin"));
  202.                 SetPlayerInterior(playerid, DOF2::GetInt(formatFile(playerid), "Interior"));
  203.                 SetPlayerVirtualWorld(playerid, DOF2::GetInt(formatFile(playerid), "VirtualWorld"));
  204.                 SetPlayerWantedLevel(playerid, DOF2::GetInt(formatFile(playerid), "Estrelas"));
  205.                 SetPlayerHealth(playerid, DOF2::GetFloat(formatFile(playerid), "Vida"));
  206.                 SetPlayerArmour(playerid, DOF2::GetFloat(formatFile(playerid), "Colete"));
  207.  
  208.                 Player[playerid][Sexo] = DOF2::GetInt(formatFile(playerid), "Sexo");
  209.                 Player[playerid][Fome] = DOF2::GetInt(formatFile(playerid), "Fome");
  210.                 Player[playerid][Sede] = DOF2::GetInt(formatFile(playerid), "Sede");
  211.                 Player[playerid][Admin] = DOF2::GetInt(formatFile(playerid), "Admin");
  212.  
  213.                 Player[playerid][pX] = DOF2::GetFloat(formatFile(playerid), "X");
  214.                 Player[playerid][pY] = DOF2::GetFloat(formatFile(playerid), "Y");
  215.                 Player[playerid][pZ] = DOF2::GetFloat(formatFile(playerid), "Z");
  216.                 Player[playerid][pA] = DOF2::GetFloat(formatFile(playerid), "A");
  217.  
  218.                 Player[playerid][Logado] = true;
  219.                 Player[playerid][Spawnou] = true;
  220.                 SendClientMessage(playerid, -1, "{98FB98}* {FFFFFF}Entrada efetuada com sucesso.");
  221.  
  222.                 SetSpawnInfo(playerid, NO_TEAM, GetPlayerSkin(playerid), Player[playerid][pX], Player[playerid][pY], Player[playerid][pZ], Player[playerid][pA], 0, 0, 0, 0, 0, 0);
  223.                 TogglePlayerSpectating(playerid, false);
  224.                 SetCameraBehindPlayer(playerid);
  225.                 SpawnPlayer(playerid);
  226.             }
  227.             else
  228.             {
  229.                 Player[playerid][Tentativas]++;
  230.                 if(Player[playerid][Tentativas] >= MAX_ATTEMPS_PASSWORD) return Kick(playerid);
  231.  
  232.                 new dialog[90];
  233.                 format(dialog, sizeof(dialog), "{FFFFFF}Insira sua senha para conectar-se:\n\n{FF0000}* Senha incorreta (%i/%i).", Player[playerid][Tentativas], MAX_ATTEMPS_PASSWORD);
  234.                 ShowPlayerDialog(playerid, DIALOG_CONECTAR, DIALOG_STYLE_PASSWORD, "Conectando", dialog, "Conectar", "Sair");
  235.             }
  236.         }
  237.     }
  238.     return 1;
  239. }
  240.  
  241. // -----------------------------------------------------------------------------
  242.  
  243. formatFile(playerid)
  244. {
  245.     new file[16 + MAX_PLAYER_NAME];
  246.     format(file, sizeof(file), "Contas/%s.ini", formatName(playerid));
  247.     return file;
  248. }
  249.  
  250. formatName(playerid)
  251. {
  252.     new name[MAX_PLAYER_NAME];
  253.     GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  254.     return name;
  255. }
  256.  
  257. formatIP(playerid)
  258. {
  259.     new ip[16];
  260.     GetPlayerIp(playerid, ip, 16);
  261.     return ip;
  262. }
  263.  
  264. Float:formatHealth(playerid)
  265. {
  266.     new Float:health;
  267.     GetPlayerHealth(playerid, health);
  268.     return health;
  269. }
  270.  
  271. Float:formatArmour(playerid)
  272. {
  273.     new Float:armour;
  274.     GetPlayerArmour(playerid, armour);
  275.     return armour;
  276. }
  277.  
  278. formatTime()
  279. {
  280.     new output[24], date[3], hour[3];
  281.     getdate(date[2], date[1], date[0]);
  282.     gettime(hour[0], hour[1], hour[2]);
  283.     format(output, sizeof(output), "%02d/%02d/%04d - %02d:%02d:%02d", date[0], date[1], date[2], hour[0], hour[1], hour[2]);
  284.     return output;
  285. }
  286.  
  287. ClearLines(playerid, lines)
  288.     for(new i; i != lines; i++)
  289.         SendClientMessage(playerid, -1, #);
  290.  
  291. // -----------------------------------------------------------------------------
  292.  
  293. SavePlayerData(playerid)
  294. {
  295.     if(Player[playerid][Logado])
  296.     {
  297.         if(DOF2::FileExists(formatFile(playerid)))
  298.         {
  299.             format(Player[playerid][UltimoLogin], 24, formatTime());
  300.             GetPlayerPos(playerid, Player[playerid][pX], Player[playerid][pY], Player[playerid][pZ]);
  301.             GetPlayerFacingAngle(playerid, Player[playerid][pA]);
  302.  
  303.             DOF2::SetString(formatFile(playerid), "ÚltimoLogin", Player[playerid][UltimoLogin]);
  304.             DOF2::SetString(formatFile(playerid), "IP", formatIP(playerid));
  305.             DOF2::SetInt(formatFile(playerid), "Dinheiro", GetPlayerMoney(playerid));
  306.             DOF2::SetInt(formatFile(playerid), "Level", GetPlayerScore(playerid));
  307.             DOF2::SetInt(formatFile(playerid), "Skin", GetPlayerSkin(playerid));
  308.             DOF2::SetInt(formatFile(playerid), "Interior", GetPlayerInterior(playerid));
  309.             DOF2::SetInt(formatFile(playerid), "VirtualWorld", GetPlayerVirtualWorld(playerid));
  310.             DOF2::SetInt(formatFile(playerid), "Estrelas", GetPlayerWantedLevel(playerid));
  311.             DOF2::SetFloat(formatFile(playerid), "Vida", formatHealth(playerid));
  312.             DOF2::SetFloat(formatFile(playerid), "Colete", formatArmour(playerid));
  313.  
  314.             DOF2::SetInt(formatFile(playerid), "Sexo", Player[playerid][Sexo]);
  315.             DOF2::SetInt(formatFile(playerid), "Fome", Player[playerid][Fome]);
  316.             DOF2::SetInt(formatFile(playerid), "Sede", Player[playerid][Sede]);
  317.             DOF2::SetInt(formatFile(playerid), "Admin", Player[playerid][Admin]);
  318.  
  319.             DOF2::SetFloat(formatFile(playerid), "X", Player[playerid][pX]);
  320.             DOF2::SetFloat(formatFile(playerid), "Y", Player[playerid][pY]);
  321.             DOF2::SetFloat(formatFile(playerid), "Z", Player[playerid][pZ]);
  322.             DOF2::SetFloat(formatFile(playerid), "A", Player[playerid][pA]);
  323.             DOF2::SaveFile();
  324.         }
  325.     }
  326. }
  327.  
  328. ResetPlayerData(playerid)
  329. {
  330.     ResetPlayerMoney(playerid);
  331.     SetPlayerScore(playerid, 0);
  332.     SetPlayerSkin(playerid, 0);
  333.     SetPlayerInterior(playerid, 0);
  334.     SetPlayerVirtualWorld(playerid, 0);
  335.     SetPlayerWantedLevel(playerid, 0);
  336.     SetPlayerHealth(playerid, 100.0);
  337.     SetPlayerArmour(playerid, 0.0);
  338.  
  339.     Player[playerid][Sexo] = Player[playerid][Admin] = Player[playerid][Fome] = Player[playerid][Sede] = Player[playerid][Tentativas] = 0;
  340.     Player[playerid][pX] = Player[playerid][pY] = Player[playerid][pZ] = Player[playerid][pA] = 0.0;
  341.     Player[playerid][Logado] = Player[playerid][Spawnou] = Player[playerid][Cadastrou] = false;
  342. }
  343.  
  344. /*
  345.  
  346. ADICIONAL:
  347.  
  348. GetPlayerGenderName(playerid)
  349. {
  350.     new name[10];
  351.     name = ((Player[playerid][Sexo] == 1) ? "Masculino" : "Feminino");
  352.     return name;
  353. }
  354.  
  355. USANDO:
  356.  
  357. printf("%s", GetPlayerGenderName(playerid));
  358.  
  359. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement