MrmirvC

Untitled

Oct 7th, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.59 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3. #include <YSI\y_ini>
  4. #include <sscanf2>
  5.  
  6.  
  7.  
  8. #define COLOR_BLACK 0x2C2727AA
  9. #define COLOR_GREEN 0x33AA33AA
  10. #define COLOR_PINK 0xFF66FFAA
  11. #define COLOR_BLUE 0x0000BBAA
  12. #define COLOR_WHITE 0xFFFFFFAA
  13. #define COLOR_LIGHTYELLOW 0x99FF9900
  14. #define COLOR_GREY 0xAFAFAFAA
  15. #define COLOR_GREEN 0x33AA33AA
  16. #define COLOR_RED 0xAA3333AA
  17. #define COLOR_YELLOW 0xFFFF00AA
  18. #define COLOR_PINK 0xFF66FFAA
  19. #define COLOR_BLUE 0x0000BBAA
  20. #define COLOR_ORANGE 0xFF9900AA
  21. #define COLOR_PURPLE 0x990099AA
  22. #define COLOR_BROWN 0x663300AA
  23. #define COLOR_LIGHTBLUE 0x33CCFFAA
  24. #define COLOR_DARKRED 0x660000AA
  25. #define COLOR_DARKBLUE 0x000066AA
  26.  
  27.  
  28.  
  29. #define DIALOG_RULES 1
  30. #define DIALOG_TELETRASPORTI 2
  31. #define REGISTRAZIONE 3
  32. #define LOGIN 4
  33.  
  34. #define PATH "/Giocatori/%s.ini"
  35.  
  36. forward CaricaDati_data(playerid,name[],value[]);
  37.  
  38. enum Giocatore
  39. {
  40.     Password,
  41.     Soldi,
  42.     Admin,
  43.     bool:Loggato[MAX_PLAYERS]
  44. }
  45. new InfoGiocatore[MAX_PLAYERS][Giocatore];
  46.  
  47. PercorsoUtente(playerid)
  48. {
  49.     new string[128],playername[MAX_PLAYER_NAME];
  50.     GetPlayerName(playerid,playername,sizeof(playername));
  51.     format(string,sizeof(string),PATH,playername);
  52.     return string;
  53. }
  54.  
  55. udb_hash(buf[])
  56. {
  57.     new length=strlen(buf);
  58.     new s1 = 1;
  59.     new s2 = 0;
  60.     new n;
  61.     for (n=0; n<length; n++)
  62.     {
  63.        s1 = (s1 + buf[n]) % 65521;
  64.        s2 = (s2 + s1)     % 65521;
  65.     }
  66.     return (s2 << 16) + s1;
  67. }
  68.  
  69.  
  70. public CaricaDati_data(playerid,name[],value[])
  71. {
  72.     INI_Int("Password", InfoGiocatore[playerid][Password]);
  73.     INI_Int("Soldi", InfoGiocatore[playerid][Soldi]);
  74.     INI_Int("Admin", InfoGiocatore[playerid][Admin]);
  75.     return 1;
  76. }
  77.  
  78. public OnPlayerDisconnect(playerid, reason)
  79. {
  80.     new pname[MAX_PLAYER_NAME], string[22 + MAX_PLAYER_NAME], INI:File = INI_Open(PercorsoUtente(playerid));
  81.     GetPlayerName(playerid, pname, sizeof(pname));
  82.     format(string, sizeof(string), "%s Si รจ disconnesso.", pname);
  83.     SendClientMessageToAll(COLOR_RED, string);
  84.     if(InfoGiocatore[playerid][Loggato])
  85.     {
  86.         INI_SetTag(File,"data");
  87.         INI_WriteInt(File,"Soldi",GetPlayerMoney(playerid));
  88.         INI_WriteInt(File,"Admin",InfoGiocatore[playerid][Admin]);
  89.         INI_Close(File);
  90.     }
  91.     return 1;
  92. }
  93.  
  94. //Dialog about registration and login
  95.     if(dialogid == REGISTRAZIONE)
  96.     {
  97.         if(!response) return Kick(playerid);
  98.         if(response)
  99.         {
  100.             if(!strlen(inputtext) || strlen(inputtext) < 4 || strlen(inputtext) > 16) return ShowPlayerDialog(playerid, REGISTRAZIONE, DIALOG_STYLE_INPUT, "Registrazione", "ERRORE: La password deve essere compresa fra i 4 e 16 caratteri.\nDigita la password:", "Avanti", "Esci");
  101.             new INI:File = INI_Open(PercorsoUtente(playerid));
  102.             INI_WriteInt(File, "Password", udb_hash(inputtext));
  103.             INI_WriteInt(File, "Soldi",0);
  104.             INI_WriteInt(File, "Admin",0);
  105.             INI_Close(File);
  106.             InfoGiocatore[playerid][Loggato] = true;
  107.         }
  108.     }
  109. //______________________________________________________________________________---
  110.  
  111. /*------------------------------LOGIN----------------------------------*/
  112.     if(dialogid == LOGIN)
  113.     {
  114.         if(!response) return Kick(playerid);
  115.         if(response)
  116.         {
  117.             if(udb_hash(inputtext) == InfoGiocatore[playerid][Password])
  118.             {
  119.                 INI_ParseFile(PercorsoUtente(playerid), "CaricaDati_%s", .bExtra = true, .extra = playerid);
  120.                 GivePlayerMoney(playerid, InfoGiocatore[playerid][Soldi]);
  121.                 InfoGiocatore[playerid][Loggato] = true;
  122.             }
  123.             else ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_INPUT, "Login", "Digita la password:", "Avanti", "Esci");
  124.         }
  125.     }
  126.    
  127. /*---------------------------------------------------------------*/
Advertisement
Add Comment
Please, Sign In to add comment