Advertisement
Kronus13

kRegister & Login System

Oct 17th, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.91 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.  
  30.  
  31. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  32. /*            Definições           */
  33. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  34.  
  35. #undef MAX_PLAYERS
  36. #define MAX_PLAYERS             ( 50 )              // ~ Defina aqui o número máximo de players/slots do seu host/server.
  37.  
  38. #define PASTA_USERS             "Contas/%s.ini"     // ~ Defina aqui o local de salvamento das contas dos players.
  39.  
  40. #define SKIN_INICIAL            ( 23 )              // ~ Defina aqui a skin inicial do player após o registro.
  41.  
  42.  
  43.  
  44. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  45. /*             Dialogs             */
  46. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  47. #define DIALOG_LANGUAGE         ( 00 ) // ~ Defina aqui o id da dialog de linguagem , caso haja outra dialog com o mesmo id.
  48. #define DIALOG_REGISTER         ( 01 ) // ~ Defina aqui o id da dialog de registro , caso haja outra dialog com o mesmo id.
  49. #define DIALOG_LOGIN            ( 02 ) // ~ Defina aqui o id da dialog de login , caso haja outra dialog com o mesmo id.
  50.  
  51.  
  52.  
  53. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  54. /*    Enums, Varáveis e Arrays.    */
  55. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  56. enum pInfo
  57. {
  58.     Idioma ,
  59.     Morreu ,
  60.     Matou
  61. }
  62. new pDados[ MAX_PLAYERS ][ pInfo ];
  63. new bool: pLogado[ MAX_PLAYERS ];
  64. new kstring[128];
  65.  
  66.  
  67.  
  68. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  69. /*            Callbacks            */
  70. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  71. public OnFilterScriptExit()
  72. {
  73.     for(new i = 0; i < GetMaxPlayers(); ++i)
  74.     {
  75.         if(pLogado[i])
  76.             SalvarDados(i);
  77.     }
  78.     DOF2_Exit();
  79.     return 1;
  80. }
  81.  
  82. public OnPlayerRequestClass(playerid, classid)
  83. {
  84.     for(new i = 0; i < 100; ++i)
  85.         SendClientMessage(playerid, -1, " ");
  86.    
  87.     SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  88.     ShowPlayerDialog(playerid, DIALOG_LANGUAGE, DIALOG_STYLE_MSGBOX, "{FFFFFF}NomeDoSeuServer", "{FFFFFF} ~ Qual seu idioma ? \n\n ~ What your language ?", "PT-BR", "English" );
  89.     return 1;
  90. }
  91.  
  92. public OnPlayerDisconnect(playerid, reason)
  93. {
  94.     if(pLogado[playerid])
  95.         SalvarDados(playerid);
  96.     return 1;
  97. }
  98.  
  99. public OnPlayerDeath(playerid, killerid, reason)
  100. {
  101.     pDados[playerid][Morreu]++;
  102.     pDados[killerid][Matou]++;
  103.     return 1;
  104. }
  105.  
  106. public OnPlayerCommandText(playerid, commandid, params[])
  107. {
  108.     switch(commandid)
  109.     {
  110.         case iscmd("m,u,d,a,r,n,o,m,e") , iscmd("c,h,a,n,g,e,n,a,m,e"):
  111.         {
  112.             new nome_antigo[25];
  113.             if(pDados[playerid][Idioma] == 1)
  114.             {
  115.                 if(!params[0])return SendClientMessage(playerid, 0xFF0000FF, "( ERRO ): Uso incorreto , o correto seria: /mudarnome [ Nome Novo ]");
  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.                 SendClientMessage(playerid, 0x00FF00FF, kstring);
  123.                 SalvarDados(playerid);
  124.             }
  125.             else if(pDados[playerid][Idioma] == 2)
  126.             {
  127.                 if(!params[0])return SendClientMessage(playerid, 0xFF0000FF, "( ERROR ): Incorrect usage, the correct would be: /changename [ New Name ]");
  128.  
  129.                 nome_antigo = Nome(playerid);
  130.                 DOF2_RemoveFile(Contas(playerid));
  131.                
  132.                 SetPlayerName(playerid, params);
  133.                 format(kstring, sizeof kstring, "You changed your name from {FFFFFF}%s{00FF00} to {FFFFFF}%s{00FF00}.", nome_antigo, Nome(playerid));
  134.                 SendClientMessage(playerid, 0x00FF00FF, kstring);
  135.                 SalvarDados(playerid);
  136.             }
  137.         }
  138.        
  139.         case iscmd("m,u,d,a,r,s,e,n,h,a") , iscmd("c,h,a,n,g,e,p,a,s,s"):
  140.         {
  141.             if(pDados[playerid][Idioma] == 1)
  142.             {
  143.                 if(!params[0])return SendClientMessage(playerid, 0xFF0000FF, "( ERRO ): Uso incorreto , o correto seria: /mudarsenha [ Senha Nova ]");
  144.                
  145.                 DOF2_SetString(Contas(playerid), "Senha", params);
  146.                 format(kstring, sizeof kstring, "Você alterou sua senha para {FFFFFF}%s{00FF00}.", params);
  147.                 SendClientMessage(playerid, 0x00FF00FF, kstring);
  148.             }
  149.             else if(pDados[playerid][Idioma] == 2)
  150.             {
  151.                 if(!params[0])return SendClientMessage(playerid, 0xFF0000FF, "( ERROR ): Incorrect usage, the correct would be: /changepass [ New Password ]");
  152.  
  153.                 DOF2_SetString(Contas(playerid), "Senha", params);
  154.                 format(kstring, sizeof kstring, "You changed your password to {FFFFFF}%s{00FF00}.", params);
  155.                 SendClientMessage(playerid, 0x00FF00FF, kstring);
  156.             }
  157.         }
  158.     }
  159.     return 1;
  160. }
  161.  
  162. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  163. {
  164.     if(dialogid == DIALOG_LANGUAGE)
  165.     {
  166.         if(response)
  167.         {
  168.             pDados[playerid][Idioma] = 1;
  169.             if(DOF2_FileExists(Contas(playerid)))
  170.                 ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Logando...", "{FFFFFF} ~ Bem-vindo de volta ! \n\n ~ Digite sua senha abaixo:", "Logar", "Cancelar");
  171.             else
  172.                 ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registrando...", "{FFFFFF} ~ Bem-vindo ! \n\n ~ Digite uma senha abaixo:", "Registrar", "Cancelar");
  173.  
  174.         }
  175.         else
  176.         {
  177.             pDados[playerid][Idioma] = 2;
  178.             if(DOF2_FileExists(Contas(playerid)))
  179.                 ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Logging...", "{FFFFFF} ~ Welcome back ! \n\n ~ Enter your password below:", "Log in", "Cancel");
  180.             else
  181.                 ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registering...", "{FFFFFF} ~ Welcome ! \n\n ~ Enter a password below:", "Register", "Cancel");
  182.  
  183.         }
  184.     }
  185.    
  186.     if(dialogid == DIALOG_LOGIN)
  187.     {
  188.         if(response)
  189.         {
  190.             if(pDados[playerid][Idioma] == 1)
  191.             {
  192.                 if(!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");
  193.  
  194.                 if(!strcmp(DOF2_GetString(Contas(playerid),"Senha"), inputtext))
  195.                 {
  196.                     SpawnPlayer(playerid);
  197.                     pDados[playerid][Morreu] = DOF2_GetInt(Contas(playerid), "Morreu");
  198.                     pDados[playerid][Matou] = DOF2_GetInt(Contas(playerid), "Matou");
  199.                     GivePlayerMoney(playerid, DOF2_GetInt(Contas(playerid), "Grana"));
  200.                     SetPlayerScore(playerid, DOF2_GetInt(Contas(playerid), "Level"));
  201.                     SetPlayerSkin(playerid, DOF2_GetInt(Contas(playerid), "Pele"));
  202.                     pLogado[playerid] = true;
  203.                    
  204.                     SendClientMessage(playerid, 0x00FF00FF, "Logado com sucesso , dados carregados !");
  205.                 }
  206.                 else
  207.                 {
  208.                     SendClientMessage(playerid, 0xFF0000FF, "( ERRO ): Senha incorreta , tente novamente !");
  209.                     ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Logando...", "{FFFFFF} ~ Bem-vindo de volta ! \n\n ~ Digite sua senha abaixo:", "Logar", "Cancelar");
  210.                 }
  211.             }
  212.             else if(pDados[playerid][Idioma] == 2)
  213.             {
  214.                 if(!strlen(inputtext))return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Logging...", "{FFFFFF} ~ Welcome back ! \n\n ~ Enter your password below:", "Log in", "Cancel");
  215.  
  216.                 if(!strcmp(DOF2_GetString(Contas(playerid),"Senha"), inputtext))
  217.                 {
  218.                     SpawnPlayer(playerid);
  219.                     pDados[playerid][Morreu] = DOF2_GetInt(Contas(playerid), "Morreu");
  220.                     pDados[playerid][Matou] = DOF2_GetInt(Contas(playerid), "Matou");
  221.                     GivePlayerMoney(playerid, DOF2_GetInt(Contas(playerid), "Grana"));
  222.                     SetPlayerScore(playerid, DOF2_GetInt(Contas(playerid), "Level"));
  223.                     SetPlayerSkin(playerid, DOF2_GetInt(Contas(playerid), "Pele"));
  224.                     pLogado[playerid] = true;
  225.                    
  226.                     SendClientMessage(playerid, 0x00FF00FF, "Logged successfully loaded dice!.");
  227.                 }
  228.                 else
  229.                 {
  230.                     SendClientMessage(playerid, 0xFF0000FF, "( ERRO ): Incorrect password try again !");
  231.                     ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Logging...", "{FFFFFF} ~ Welcome back ! \n\n ~ Enter your password below:", "Log in", "Cancel");
  232.                 }
  233.             }
  234.         }
  235.         else Kick(playerid);
  236.     }
  237.  
  238.     if(dialogid == DIALOG_REGISTER)
  239.     {
  240.         if(response)
  241.         {
  242.             if(pDados[playerid][Idioma] == 1)
  243.             {
  244.                 if(!strlen(inputtext))return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registrando...", "{FFFFFF} ~ Bem-vindo ! \n\n ~ Digite uma senha abaixo:", "Registrar", "Cancelar");
  245.  
  246.                 DOF2_CreateFile(Contas(playerid));
  247.                 DOF2_SetString(Contas(playerid), "Senha", inputtext);
  248.                 DOF2_SetInt(Contas(playerid), "Morreu", 0);
  249.                 DOF2_SetInt(Contas(playerid), "Matou", 0);
  250.                 DOF2_SetInt(Contas(playerid), "Grana", 1000);
  251.                 DOF2_SetInt(Contas(playerid), "Level", 1);
  252.                 DOF2_SetInt(Contas(playerid), "Pele", SKIN_INICIAL);
  253.                 DOF2_SaveFile();
  254.                
  255.                 SpawnPlayer(playerid);
  256.                 GivePlayerMoney(playerid, 1000);
  257.                 SetPlayerScore(playerid, 1);
  258.                 SetPlayerSkin(playerid, SKIN_INICIAL);
  259.                 pLogado[playerid] = true;
  260.                
  261.                 SendClientMessage(playerid, 0x00FF00FF, "Registrado com sucesso , você recebeu R$1000 e 1 Level.");
  262.  
  263.             }
  264.             else if(pDados[playerid][Idioma] == 2)
  265.             {
  266.                 if(!strlen(inputtext))return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registering...", "{FFFFFF} ~ Welcome ! \n\n ~ Enter a password below:", "Register", "Cancel");
  267.  
  268.                 DOF2_CreateFile(Contas(playerid));
  269.                 DOF2_SetString(Contas(playerid), "Senha", inputtext);
  270.                 DOF2_SetInt(Contas(playerid), "Morreu", 0);
  271.                 DOF2_SetInt(Contas(playerid), "Matou", 0);
  272.                 DOF2_SetInt(Contas(playerid), "Grana", 1000);
  273.                 DOF2_SetInt(Contas(playerid), "Level", 1);
  274.                 DOF2_SetInt(Contas(playerid), "Pele", SKIN_INICIAL);
  275.                 DOF2_SaveFile();
  276.  
  277.                 SpawnPlayer(playerid);
  278.                 GivePlayerMoney(playerid, 1000);
  279.                 SetPlayerScore(playerid, 1);
  280.                 SetPlayerSkin(playerid, SKIN_INICIAL);
  281.                 pLogado[playerid] = true;
  282.  
  283.                 SendClientMessage(playerid, 0x00FF00FF, "Successfully registered, you will receive R$1000 and Level 1.");
  284.             }
  285.         }
  286.         else Kick(playerid);
  287.     }
  288.     return 1;
  289. }
  290.  
  291.  
  292.  
  293. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  294. /*             Funções             */
  295. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  296. Nome(playerid)
  297. {
  298.     new nome[MAX_PLAYER_NAME];
  299.     GetPlayerName(playerid, nome, sizeof nome);
  300.     return nome;
  301. }
  302.  
  303. Contas(playerid)
  304. {
  305.     new pasta[64], nome[MAX_PLAYER_NAME];
  306.     GetPlayerName(playerid, nome, sizeof nome);
  307.     format(pasta, sizeof pasta, PASTA_USERS, nome);
  308.     return pasta;
  309. }
  310.  
  311. SalvarDados(playerid)
  312. {
  313.     DOF2_SetInt(Contas(playerid), "Morreu", pDados[playerid][Morreu]);
  314.     DOF2_SetInt(Contas(playerid), "Matou", pDados[playerid][Matou]);
  315.     DOF2_SetInt(Contas(playerid), "Grana", GetPlayerMoney(playerid));
  316.     DOF2_SetInt(Contas(playerid), "Level", GetPlayerScore(playerid));
  317.     DOF2_SetInt(Contas(playerid), "Pele", GetPlayerSkin(playerid));
  318.     DOF2_SaveFile();
  319.    
  320.     pLogado[playerid] = false;
  321. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement