Advertisement
Kronus13

kRegister & Login System (C/Lang)

Oct 18th, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.14 KB | None | 0 0
  1. /*
  2.                 ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~
  3.                     Register & Login System
  4.                 ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~
  5.            
  6.         Olá galera , sou Kronus13 sou novo em Pawn
  7.      e programei este simples sistema de registro/login ,
  8.     utilizando a include iCmd para criar simples comandos.
  9.    
  10.         Faz 15 dias que conheci o fórum e me registrei ,
  11.       porém , precisei aguardar pela ativação da minha conta
  12.     enquanto isso... estudei bastante e assisti todos os videos
  13.      do paulor , que me abriram muito a mente para programar.
  14.    
  15.         Por isso programei esse sistema de registro/login ,
  16.     para ver e mostrar a vocês meus resultados e tambem saber
  17.       se vocês acham que eu possa a vir ser um bom scripter.
  18. */
  19.  
  20.  
  21.  
  22. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  23. /*            Includes             */
  24. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  25.  
  26. #include <      a_samp      >
  27. #include <       icmd       >
  28. #include <       dof2       >
  29. #include <       lang       >
  30.  
  31.  
  32. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  33. /*            Definições           */
  34. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  35.  
  36. #undef MAX_PLAYERS
  37. #define MAX_PLAYERS             ( 50 )              // ~ Defina aqui o número máximo de players/slots do seu host/server.
  38.  
  39. #define PASTA_USERS             "Contas/%s.ini"     // ~ Defina aqui o local de salvamento das contas dos players.
  40.  
  41. #define SKIN_INICIAL            ( 23 )              // ~ Defina aqui a skin inicial do player após o registro.
  42.  
  43.  
  44.  
  45. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  46. /*             Dialogs             */
  47. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  48. #define DIALOG_LANGUAGE         ( 00 ) // ~ Defina aqui o id da dialog de linguagem , caso haja outra dialog com o mesmo id.
  49. #define DIALOG_REGISTER         ( 01 ) // ~ Defina aqui o id da dialog de registro , caso haja outra dialog com o mesmo id.
  50. #define DIALOG_LOGIN            ( 02 ) // ~ Defina aqui o id da dialog de login , caso haja outra dialog com o mesmo id.
  51.  
  52.  
  53.  
  54. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  55. /*    Enums, Varáveis e Arrays.    */
  56. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  57. enum pInfo
  58. {
  59.     Idioma ,
  60.     Morreu ,
  61.     Matou
  62. }
  63. new pDados[ MAX_PLAYERS ][ pInfo ];
  64. new bool: pLogado[ MAX_PLAYERS ];
  65. new kstring[128];
  66. new mstring[128];
  67.  
  68.  
  69.  
  70. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  71. /*            Callbacks            */
  72. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  73. public OnFilterScriptExit()
  74. {
  75.     for(new i = 0; i < GetMaxPlayers(); ++i)
  76.     {
  77.         if(pLogado[i])
  78.             SalvarDados(i);
  79.     }
  80.     DOF2_Exit();
  81.     return 1;
  82. }
  83.  
  84. public OnPlayerRequestClass(playerid, classid)
  85. {
  86.     for(new i = 0; i < 100; ++i)
  87.         SendClientMessage(playerid, -1, " ");
  88.    
  89.     SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  90.     ShowPlayerDialog(playerid, DIALOG_LANGUAGE, DIALOG_STYLE_MSGBOX, "{FFFFFF}NomeDoSeuServer", "{FFFFFF} ~ Qual seu idioma ? \n\n ~ What your language ?", "PT-BR", "English" );
  91.     return 1;
  92. }
  93.  
  94. public OnPlayerDisconnect(playerid, reason)
  95. {
  96.     if(pLogado[playerid])
  97.         SalvarDados(playerid);
  98.     return 1;
  99. }
  100.  
  101. public OnPlayerDeath(playerid, killerid, reason)
  102. {
  103.     pDados[playerid][Morreu]++;
  104.     pDados[killerid][Matou]++;
  105.     return 1;
  106. }
  107.  
  108. public OnPlayerCommandText(playerid, commandid, params[])
  109. {
  110.     switch(commandid)
  111.     {
  112.         case iscmd("m,u,d,a,r,n,o,m,e"), iscmd("c,h,a,n,g,e,n,a,m,e"):
  113.         {
  114.             new nome_antigo[25];
  115.             if(!params[0])return SendClientMessageLang(playerid, 0xFF0000FF, "( ERRO ): Uso incorreto , o correto seria: /mudarnome [ Nome Novo ]", "( ERROR ): Incorrect usage, the correct would be: /changename [ New Name ]", "");
  116.  
  117.             nome_antigo = Nome(playerid);
  118.             DOF2_RemoveFile(Contas(playerid));
  119.                
  120.             SetPlayerName(playerid, params);
  121.             format(kstring, sizeof kstring, "Você alterou seu nome de {FFFFFF}%s{00FF00}, para {FFFFFF}%s{00FF00}.", nome_antigo, Nome(playerid));
  122.             format(mstring, sizeof mstring, "You changed your name from {FFFFFF}%s{00FF00} to {FFFFFF}%s{00FF00}.", nome_antigo, Nome(playerid));
  123.             SendClientMessageLang(playerid, 0x00FF00FF, kstring, mstring, "");
  124.             SalvarDados(playerid);
  125.         }
  126.        
  127.         case iscmd("m,u,d,a,r,s,e,n,h,a") , iscmd("c,h,a,n,g,e,p,a,s,s"):
  128.         {
  129.             if(!params[0])return SendClientMessageLang(playerid, 0xFF0000FF, "( ERRO ): Uso incorreto , o correto seria: /mudarsenha [ Senha Nova ]", "( ERROR ): Incorrect usage, the correct would be: /changepass [ New Password ]", "");
  130.                
  131.             DOF2_SetString(Contas(playerid), "Senha", params);
  132.             format(kstring, sizeof kstring, "Você alterou sua senha para {FFFFFF}%s{00FF00}.", params);
  133.             format(mstring, sizeof mstring, "You changed your password to {FFFFFF}%s{00FF00}.", params);
  134.             SendClientMessageLang(playerid, 0x00FF00FF, kstring, mstring, "");
  135.         }
  136.     }
  137.     return 1;
  138. }
  139.  
  140. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  141. {
  142.     if(dialogid == DIALOG_LANGUAGE)
  143.     {
  144.         if(response)
  145.         {
  146.             SetPlayerLang(playerid, 0);
  147.             if(DOF2_FileExists(Contas(playerid)))
  148.                 ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Logando...", "{FFFFFF} ~ Bem-vindo de volta ! \n\n ~ Digite sua senha abaixo:", "Logar", "Cancelar");
  149.             else
  150.                 ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registrando...", "{FFFFFF} ~ Bem-vindo ! \n\n ~ Digite uma senha abaixo:", "Registrar", "Cancelar");
  151.  
  152.         }
  153.         else
  154.         {
  155.             SetPlayerLang(playerid, 1);
  156.             if(DOF2_FileExists(Contas(playerid)))
  157.                 ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Logging...", "{FFFFFF} ~ Welcome back ! \n\n ~ Enter your password below:", "Log in", "Cancel");
  158.             else
  159.                 ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registering...", "{FFFFFF} ~ Welcome ! \n\n ~ Enter a password below:", "Register", "Cancel");
  160.  
  161.         }
  162.     }
  163.    
  164.     if(dialogid == DIALOG_LOGIN)
  165.     {
  166.         if(response)
  167.         {
  168.             if(GetPlayerLang(playerid) == 0 && !strlen(inputtext))return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Logando...", "{FFFFFF} ~ Bem-vindo de volta ! \n\n ~ Digite sua senha abaixo:", "Logar", "Cancelar");
  169.             if(GetPlayerLang(playerid) == 1 && !strlen(inputtext))return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Logging...", "{FFFFFF} ~ Welcome back ! \n\n ~ Enter your password below:", "Log in", "Cancel");
  170.                
  171.             if(!strcmp(DOF2_GetString(Contas(playerid),"Senha"), inputtext))
  172.             {
  173.                 SpawnPlayer(playerid);
  174.                 CarregarDados(playerid);
  175.                    
  176.                 SendClientMessageLang(playerid, 0x00FF00FF, "Logado com sucesso , dados carregados !", "Logged successfully loaded dice!", "");
  177.             }
  178.             else
  179.             {
  180.                 if(GetPlayerLang(playerid) == 0)
  181.                 {
  182.                     SendClientMessage(playerid, 0xFF0000FF, "( ERRO ): Senha incorreta , tente novamente !");
  183.                     ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Logando...", "{FFFFFF} ~ Bem-vindo de volta ! \n\n ~ Digite sua senha abaixo:", "Logar", "Cancelar");
  184.                 }
  185.                 else if(GetPlayerLang(playerid) == 1)
  186.                 {
  187.                     SendClientMessage(playerid, 0xFF0000FF, "( ERROR ): Incorrect password, please try again !");
  188.                     ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Logging...", "{FFFFFF} ~ Welcome back ! \n\n ~ Enter your password below:", "Log in", "Cancel");
  189.                 }
  190.             }
  191.         }
  192.         else Kick(playerid);
  193.     }
  194.  
  195.     if(dialogid == DIALOG_REGISTER)
  196.     {
  197.         if(response)
  198.         {
  199.             if(GetPlayerLang(playerid) == 1 && !strlen(inputtext))return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registrando...", "{FFFFFF} ~ Bem-vindo ! \n\n ~ Digite uma senha abaixo:", "Registrar", "Cancelar");
  200.             if(GetPlayerLang(playerid) == 2 && !strlen(inputtext))return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registering...", "{FFFFFF} ~ Welcome ! \n\n ~ Enter a password below:", "Register", "Cancel");
  201.            
  202.             DOF2_CreateFile(Contas(playerid));
  203.             DOF2_SetString(Contas(playerid), "Senha", inputtext);
  204.             DOF2_SetInt(Contas(playerid), "Morreu", 0);
  205.             DOF2_SetInt(Contas(playerid), "Matou", 0);
  206.             DOF2_SetInt(Contas(playerid), "Grana", 1000);
  207.             DOF2_SetInt(Contas(playerid), "Level", 1);
  208.             DOF2_SetInt(Contas(playerid), "Pele", SKIN_INICIAL);
  209.             DOF2_SaveFile();
  210.  
  211.             SpawnPlayer(playerid);
  212.             GivePlayerMoney(playerid, 1000);
  213.             SetPlayerScore(playerid, 1);
  214.             SetPlayerSkin(playerid, SKIN_INICIAL);
  215.             pLogado[playerid] = true;
  216.  
  217.             SendClientMessageLang(playerid, 0x00FF00FF, "Registrado com sucesso , você recebeu R$1000 e 1 Level.", "Successfully registered, you will receive R$1000 and Level 1.", "");
  218.         }
  219.         else Kick(playerid);
  220.     }
  221.     return 1;
  222. }
  223.  
  224.  
  225.  
  226. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  227. /*             Funções             */
  228. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  229. Nome(playerid)
  230. {
  231.     new nome[MAX_PLAYER_NAME];
  232.     GetPlayerName(playerid, nome, sizeof nome);
  233.     return nome;
  234. }
  235.  
  236. Contas(playerid)
  237. {
  238.     new pasta[64], nome[MAX_PLAYER_NAME];
  239.     GetPlayerName(playerid, nome, sizeof nome);
  240.     format(pasta, sizeof pasta, PASTA_USERS, nome);
  241.     return pasta;
  242. }
  243.  
  244. SalvarDados(playerid)
  245. {
  246.     DOF2_SetInt(Contas(playerid), "Morreu", pDados[playerid][Morreu]);
  247.     DOF2_SetInt(Contas(playerid), "Matou", pDados[playerid][Matou]);
  248.     DOF2_SetInt(Contas(playerid), "Grana", GetPlayerMoney(playerid));
  249.     DOF2_SetInt(Contas(playerid), "Level", GetPlayerScore(playerid));
  250.     DOF2_SetInt(Contas(playerid), "Pele", GetPlayerSkin(playerid));
  251.     DOF2_SaveFile();
  252.    
  253.     pLogado[playerid] = false;
  254. }
  255.  
  256. CarregarDados(playerid)
  257. {
  258.     pDados[playerid][Morreu] = DOF2_GetInt(Contas(playerid), "Morreu");
  259.     pDados[playerid][Matou] = DOF2_GetInt(Contas(playerid), "Matou");
  260.     GivePlayerMoney(playerid, DOF2_GetInt(Contas(playerid), "Grana"));
  261.     SetPlayerScore(playerid, DOF2_GetInt(Contas(playerid), "Level"));
  262.     SetPlayerSkin(playerid, DOF2_GetInt(Contas(playerid), "Pele"));
  263.  
  264.     pLogado[playerid] = true;
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement