Guest User

Untitled

a guest
Oct 7th, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 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. Weapon[13][2]
  46. }
  47. new InfoGiocatore[MAX_PLAYERS][Giocatore];
  48.  
  49. PercorsoUtente(playerid)
  50. {
  51. new string[128],playername[MAX_PLAYER_NAME];
  52. GetPlayerName(playerid,playername,sizeof(playername));
  53. format(string,sizeof(string),PATH,playername);
  54. return string;
  55. }
  56.  
  57. udb_hash(buf[])
  58. {
  59. new length=strlen(buf);
  60. new s1 = 1;
  61. new s2 = 0;
  62. new n;
  63. for (n=0; n<length; n++)
  64. {
  65. s1 = (s1 + buf[n]) % 65521;
  66. s2 = (s2 + s1) % 65521;
  67. }
  68. return (s2 << 16) + s1;
  69. }
  70.  
  71.  
  72. public CaricaDati_data(playerid,name[],value[])
  73. {
  74. INI_Int("Password", InfoGiocatore[playerid][Password]);
  75. INI_Int("Soldi", InfoGiocatore[playerid][Soldi]);
  76. INI_Int("Admin", InfoGiocatore[playerid][Admin]);
  77. new widString[32];
  78. for(new wid = 0; wid < 13; wid++) {
  79. format(widString, 32, "Weapon%i", wid);
  80. INI_Int(widString, InfoGiocatore[playerid][Weapon[wid][0]]);
  81. format(widString, 32, "Weapon%iAmmo", wid);
  82. INI_Int(widString, InfoGiocatore[playerid][Weapon[wid][1]]);
  83. }
  84. return 1;
  85. }
  86.  
  87. public OnPlayerDisconnect(playerid, reason)
  88. {
  89. new pname[MAX_PLAYER_NAME], string[22 + MAX_PLAYER_NAME], INI:File = INI_Open(PercorsoUtente(playerid));
  90. GetPlayerName(playerid, pname, sizeof(pname));
  91. format(string, sizeof(string), "%s Si รจ disconnesso.", pname);
  92. SendClientMessageToAll(COLOR_RED, string);
  93. if(InfoGiocatore[playerid][Loggato])
  94. {
  95. INI_SetTag(File,"data");
  96. INI_WriteInt(File,"Soldi",GetPlayerMoney(playerid));
  97. INI_WriteInt(File,"Admin",InfoGiocatore[playerid][Admin]);
  98. new widString[32], weapons[13][2];
  99. for(new wid = 0; wid < 13; wid++) {
  100. GetPlayerWeaponData(playerid, wid, weapons[wid][0], weapons[wid][1]);
  101. format(widString, 32, "Weapon%i", wid);
  102. INI_WriteInt(File,widString,weapons[wid][0]);
  103. format(widString, 32, "Weapon%iAmmo", wid);
  104. INI_WriteInt(File,widString,weapons[wid][1]);
  105. }
  106. INI_Close(File);
  107. }
  108. return 1;
  109. }
  110.  
  111. //Dialog about registration and login
  112. if(dialogid == REGISTRAZIONE)
  113. {
  114. if(!response) return Kick(playerid);
  115. if(response)
  116. {
  117. 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");
  118. new INI:File = INI_Open(PercorsoUtente(playerid));
  119. INI_WriteInt(File, "Password", udb_hash(inputtext));
  120. INI_WriteInt(File, "Soldi",0);
  121. INI_WriteInt(File, "Admin",0);
  122. new widString[32];
  123. for(new wid = 0; wid < 13; wid++) {
  124. format(widString, 32, "Weapon%i", wid);
  125. INI_WriteInt(File,widString,0);
  126. format(widString, 32, "Weapon%iAmmo", wid);
  127. INI_WriteInt(File,widString,0);
  128. }
  129. INI_Close(File);
  130. InfoGiocatore[playerid][Loggato] = true;
  131. }
  132. }
  133. //______________________________________________________________________________---
  134.  
  135. /*------------------------------LOGIN----------------------------------*/
  136. if(dialogid == LOGIN)
  137. {
  138. if(!response) return Kick(playerid);
  139. if(response)
  140. {
  141. if(udb_hash(inputtext) == InfoGiocatore[playerid][Password])
  142. {
  143. INI_ParseFile(PercorsoUtente(playerid), "CaricaDati_%s", .bExtra = true, .extra = playerid);
  144. GivePlayerMoney(playerid, InfoGiocatore[playerid][Soldi]);
  145. InfoGiocatore[playerid][Loggato] = true;
  146. new widString[32];
  147. for(new wid = 0; wid < 13; wid++)
  148. GivePlayerWeapon(playerid, InfoGiocatore[playerid][Weapon[wid][0]], InfoGiocatore[playerid][Weapon[wid][1]]);
  149. }
  150. else ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_INPUT, "Login", "Digita la password:", "Avanti", "Esci");
  151. }
  152. }
  153.  
  154. /*---------------------------------------------------------------*/
Advertisement
Add Comment
Please, Sign In to add comment