Advertisement
Guest User

Login/Register system

a guest
Dec 13th, 2022
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.91 KB | None | 0 0
  1. #include <a_samp>
  2. #include <easyDialog>
  3. #include <ysilib\YSI_Storage\y_ini>
  4. #include <ysilib\YSI_Coding\y_hooks>
  5. #include <ysilib\YSI_Coding\y_malloc>
  6. #include <ysilib\YSI_Coding\y_timers>
  7. #include <ysilib\YSI_Coding\y_va>
  8. #include <ysilib\YSI_Core\y_master>
  9. #include <ysilib\YSI_Core\y_utils>
  10. #include <ysilib\YSI_Data\y_foreach>
  11. #include <sscanf2>
  12. #include <streamer>
  13.  
  14. #define KORISNIK_PATH "/Korisnici/%s.ini"
  15.  
  16. enum korisnikInfo {
  17. pLozinka,
  18. pNovac,
  19. pBankaNovac,
  20. pLevel,
  21. pRespekti,
  22. pPotrebnoRespekta,
  23. pSkin,
  24. pAdmin,
  25. pUbistva,
  26. pSmrti
  27. };
  28.  
  29. new KorisnikInfo[MAX_PLAYERS][korisnikInfo];
  30.  
  31. forward UcitajKorisnike_data(const playerid, name[], value[]);
  32. public UcitajKorisnike_data(const playerid, name[], value[]) {
  33. INI_Int("Lozinka", KorisnikInfo[playerid][pLozinka]);
  34. INI_Int("Novac", KorisnikInfo[playerid][pNovac]);
  35. INI_Int("BankaNovac", KorisnikInfo[playerid][pBankaNovac]);
  36. INI_Int("Level", KorisnikInfo[playerid][pLevel]);
  37. INI_Int("Respekti", KorisnikInfo[playerid][pRespekti]);
  38. INI_Int("PotrebnoRespekta", KorisnikInfo[playerid][pPotrebnoRespekta]);
  39. INI_Int("Skin", KorisnikInfo[playerid][pSkin]);
  40. INI_Int("Admin", KorisnikInfo[playerid][pAdmin]);
  41. INI_Int("Ubistva", KorisnikInfo[playerid][pUbistva]);
  42. INI_Int("Smrti", KorisnikInfo[playerid][pSmrti]);
  43. return 1;
  44. }
  45.  
  46. forward KickujIgraca(const playerid);
  47. public KickujIgraca(const playerid) {
  48. SendClientMessage(playerid, -1, ""c_srv"BO > "c_white"Kickovani ste sa servera!");
  49. Kick(playerid);
  50. return 1;
  51. }
  52.  
  53. stock KorisnikPath(const playerid) {
  54. new string[128],playername[MAX_PLAYER_NAME];
  55. GetPlayerName(playerid,playername,sizeof(playername));
  56. format(string,sizeof(string),KORISNIK_PATH,playername);
  57. return string;
  58. }
  59.  
  60. stock udb_hash(const buf[]) {
  61. new length=strlen(buf);
  62. new s1 = 1;
  63. new s2 = 0;
  64. new n;
  65. for (n=0; n<length; n++)
  66. {
  67. s1 = (s1 + buf[n]) % 65521;
  68. s2 = (s2 + s1) % 65521;
  69. }
  70. return (s2 << 16) + s1;
  71. }
  72.  
  73. stock ocistichat(const playerid, lines) {
  74. for(new i = 0; i < lines; i++) {
  75. SendClientMessage(playerid, -1, " ");
  76. }
  77. return 1;
  78. }
  79.  
  80. stock ImeIgraca(const playerid) {
  81. new name[MAX_PLAYER_NAME];
  82. GetPlayerName(playerid, name, sizeof(name));
  83. return name;
  84. }
  85.  
  86. stock SacuvajIgraca(const playerid) {
  87. new INI:File = INI_Open(KorisnikPath(playerid));
  88. INI_SetTag(File, "[Informacije]");
  89. INI_WriteInt(File, "Novac", GetPlayerMoney(playerid));
  90. INI_WriteInt(File, "BankaNovac", KorisnikInfo[playerid][pBankaNovac]);
  91. INI_WriteInt(File, "Level", GetPlayerScore(playerid));
  92. INI_WriteInt(File, "Respekti", KorisnikInfo[playerid][pRespekti]);
  93. INI_WriteInt(File, "PotrebnoRespekta", KorisnikInfo[playerid][pPotrebnoRespekta]);
  94. INI_WriteInt(File, "Skin", KorisnikInfo[playerid][pSkin]);
  95. INI_WriteInt(File, "Admin", KorisnikInfo[playerid][pAdmin]);
  96. INI_WriteInt(File, "Ubistva", KorisnikInfo[playerid][pUbistva]);
  97. INI_WriteInt(File, "Smrti", KorisnikInfo[playerid][pSmrti]);
  98. INI_Close(File);
  99. return 1;
  100. }
  101.  
  102. hook OnGameModeInit() {
  103. print("|------------------------------|");
  104. print(" reglog is loading... ");
  105. print(" reglog is founded ");
  106. print(" reglog is loaded ");
  107. print("|------------------------------|\n\n");
  108. return 1;
  109. }
  110.  
  111. hook OnPlayerConnect(playerid) {
  112. if(fexist(KorisnikPath(playerid))) {
  113. INI_ParseFile(KorisnikPath(playerid), "UcitajKorisnike_%s", .bExtra = true, .extra = playerid);
  114. Dialog_Show(playerid, "d_login", DIALOG_STYLE_PASSWORD, ""c_srv"BO "c_white"- Prijava", ""c_white"Unesite svoju lozinku za prijavu\n"c_white"Ako ste zaboravili vasu lozinku javite se na forum:"c_srv"www.bo-samp.info", ""c_white"Prijava", ""c_white"Izlaz");
  115. }
  116. else {
  117. Dialog_Show(playerid, "d_register", DIALOG_STYLE_PASSWORD, ""c_srv"BO "c_white"- Register", ""c_white"Da bi ste se registrovali na server unesite vasu zeljenu lozinku", ""c_white"Registracija", ""c_white"Izlaz");
  118. }
  119. return 1;
  120. }
  121.  
  122. hook OnPlayerDisconnect(playerid, reason) {
  123. SacuvajIgraca(playerid);
  124. return 1;
  125. }
  126.  
  127. hook OnPlayerSpawn(playerid) {
  128. SetPlayerSkin(playerid, KorisnikInfo[playerid][pSkin]);
  129. return 1;
  130. }
  131.  
  132. hook OnPlayerDeath(playerid, killerid, reason) {
  133. KorisnikInfo[killerid][pUbistva]++;
  134. KorisnikInfo[playerid][pSmrti]++;
  135. return 1;
  136. }
  137.  
  138. Dialog:d_register(const playerid, response, listitem, string: inputtext[]) {
  139. if(!response) return KickujIgraca(playerid);
  140. if(response) {
  141. if(!strlen(inputtext)) return Dialog_Show(playerid, "d_register", DIALOG_STYLE_PASSWORD, ""c_srv"BO "c_white"- Register", ""c_white"Da bi ste se registrovali na server unesite vasu zeljenu lozinku", ""c_white"Registracija", ""c_white"Izlaz");
  142. new INI:File = INI_Open(KorisnikPath(playerid));
  143. INI_SetTag(File, "[Informacije]");
  144. INI_WriteInt(File, "Lozinka", udb_hash(inputtext));
  145. INI_WriteInt(File, "Novac", 15000);
  146. INI_WriteInt(File, "BankaNovac", 0);
  147. INI_WriteInt(File, "Level", 3);
  148. INI_WriteInt(File, "Respekti", 0);
  149. INI_WriteInt(File, "PotrebnoRespekta", 10);
  150. INI_WriteInt(File, "Skin", 7);
  151. INI_WriteInt(File, "Admin", 0);
  152. INI_WriteInt(File, "Ubistva", 0);
  153. INI_WriteInt(File, "Smrti", 0);
  154. INI_Close(File);
  155. SetSpawnInfo(playerid, 0, KorisnikInfo[playerid][pSkin], 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
  156. SpawnPlayer(playerid);
  157. SetPlayerScore(playerid, 3);
  158. KorisnikInfo[playerid][pSkin] = 7;
  159. SetPlayerSkin(playerid, KorisnikInfo[playerid][pSkin]);
  160. KorisnikInfo[playerid][pNovac] = 15000;
  161. GivePlayerMoney(playerid, KorisnikInfo[playerid][pNovac]);
  162. KorisnikInfo[playerid][pPotrebnoRespekta] = 10;
  163. ocistichat(playerid, 20);
  164. }
  165. return 1;
  166. }
  167.  
  168. Dialog:d_login(const playerid, response, listitem, string: inputtext[]) {
  169. if(!response) return KickujIgraca(playerid);
  170. if(response) {
  171. if(udb_hash(inputtext) == KorisnikInfo[playerid][pLozinka]) {
  172. INI_ParseFile(KorisnikPath(playerid), "UcitajKorisnike_%s", .bExtra = true, .extra = playerid);
  173. SetSpawnInfo(playerid, 0, KorisnikInfo[playerid][pSkin], 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
  174. SpawnPlayer(playerid);
  175. GivePlayerMoney(playerid, KorisnikInfo[playerid][pNovac]);
  176. SetPlayerSkin(playerid, KorisnikInfo[playerid][pSkin]);
  177. SetPlayerScore(playerid, KorisnikInfo[playerid][pLevel]);
  178. ocistichat(playerid, 20);
  179. }
  180. else {
  181. Dialog_Show(playerid, "d_login", DIALOG_STYLE_PASSWORD, ""c_srv"BO "c_white"- Prijava", ""c_white"Unesite svoju lozinku za prijavu\n"c_white"Ako ste zaboravili vasu lozinku javite se na forum:"c_srv"www.bo-samp.info", ""c_white"Prijava", ""c_white"Izlaz");
  182. }
  183. return 1;
  184. }
  185. return 1;
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement