Advertisement
Zmajk0

Untitled

Jan 18th, 2021
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.69 KB | None | 0 0
  1. //################################################//
  2. #if defined MySQLRegLog
  3. @ Register & Login System
  4. @ Released: 28/07/2019/
  5. @ Author: Itz.Yansi42O / MySQL
  6. #endif
  7. //################################################//
  8. #include "a_samp"
  9. #include "a_mysql"
  10. #include "YSI\y_timers"
  11. //################################################//
  12. #undef MAX_PLAYERS
  13. const MAX_PLAYERS = 200;
  14.  
  15. #define func:%0(%1) forward%0(%1); public%0(%1)
  16. //################################################//
  17. #define MYSQL_HOST "localhost"
  18. #define MYSQL_USER "root"
  19. #define MYSQL_PW ""
  20. #define MYSQL_DB "reglog_db"
  21.  
  22. new MySQL:SQL, yQuery[500], yString[500];
  23. //################################################//
  24. #define srwboja "{E76004}"
  25. #define BELA "{FFFFFF}"
  26.  
  27. #define Info(%0,%1) \
  28. SendClientMessageEx(%0, 0xE76004FF, "[MySQL RegLog]: "BELA""%1)
  29.  
  30. stock SendClientMessageEx(playerid, colour, const fmat[], va_args<>) {
  31. new str[145];
  32. va_format(str, sizeof (str), fmat, va_start<3>);
  33. return SendClientMessage(playerid, colour, str);
  34. }
  35. //################################################//
  36. enum PLAYER_ENUM {
  37. pName[24],
  38. pSQLID,
  39. pLozinka[24],
  40. pDrzava,
  41. pEmail[128],
  42. pGodine,
  43. pSpol,
  44. pNovac,
  45. pSkin,
  46. pLevel
  47. }
  48.  
  49. new PI[MAX_PLAYERS][PLAYER_ENUM];
  50.  
  51. enum {
  52. dialog_REGISTER,
  53. dialog_DRZAVA,
  54. dialog_EMAIL,
  55. dialog_SPOL,
  56. dialog_GODINE,
  57. dialog_LOGIN
  58. }
  59. //################################################//
  60. main() {
  61. print("Mod je uspesno ucitan !");
  62. }
  63.  
  64. func: OnGameModeInit() {
  65. SQL = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PW, MYSQL_DB);
  66.  
  67. if (mysql_errno() != 0) {
  68. print(" * MYSQL ERROR: Nije se moguce konektovati na databazu.");
  69. return 0;
  70. }
  71. else print(" * MYSQL INFO: Konekcija na databazu je uspijesna.");
  72.  
  73. SetGameModeText("@ VP > v1.0 > Yansi");
  74.  
  75. EnableStuntBonusForAll(0);
  76. DisableInteriorEnterExits();
  77.  
  78. mysql_tquery(SQL, "CREATE TABLE IF NOT EXISTS `users` (\
  79. `ID` int(11) NOT NULL,\
  80. `Name` varchar(24) NOT NULL DEFAULT 'none',\
  81. `Lozinka` varchar(24) NOT NULL DEFAULT 'none',\
  82. `Email` varchar(128) NOT NULL DEFAULT 'none',\
  83. `Drzava` int(11) NOT NULL DEFAULT 0,\
  84. `Godine` int(11) NOT NULL DEFAULT 0,\
  85. `Skin` int(11) NOT NULL DEFAULT 19,\
  86. `Level` int(11) NOT NULL DEFAULT 3,\
  87. `Novac` int(11) NOT NULL DEFAULT 150000,\
  88. `Spol` int(11) NOT NULL DEFAULT 0\
  89. )");
  90. return 1;
  91. }
  92. //################################################//
  93. func: OnPlayerConnect(playerid) {
  94. yQuery[0] = (EOS);
  95. mysql_format(SQL, yQuery, sizeof(yQuery), "SELECT * FROM `users` WHERE `Name` = '%e' LIMIT 1", GetName(playerid));
  96. mysql_pquery(SQL, yQuery, "CheckPlayerAccount", "d", "");
  97.  
  98. TogglePlayerSpectating(playerid, false);
  99. return 1;
  100. }
  101. //################################################//
  102. func: CheckPlayerAccount(playerid) {
  103. switch(cache_num_rows()) {
  104. case 0: {
  105. //camera position move to spawn..
  106. InterpolateCameraPos(playerid, 537.2963, -995.1501, 124.7903, 1373.3412, -2283.9702, 65.2952, 10000, 30000);
  107. InterpolateCameraLookAt(playerid, 538.1735, -995.6352, 124.6076, 1374.3429, -2283.9468, 64.7175, 10000, 30000);
  108.  
  109. yString[0] = (EOS);
  110.  
  111. format(yString, sizeof(yString), \
  112. ""srwboja"> "BELA"Dobrodosao '%s' na 'Ime Servera'!\n\
  113. "srwboja"____________________________________\n\
  114. "srwboja"> "BELA"Vas nalog nije pronadjen u bazi!\n\
  115. "srwboja"> "BELA"Da biste nastavili igru potrebno je da se registrujete!\n\
  116. "srwboja"> "BELA"Da bi se registrovali potrebno je da uneste lozinku!\n\
  117. "srwboja"____________________________________\n\
  118. "BELA"> "srwboja"Ime Servera "BELA" - "srwboja"SINCE 2019", GetName(playerid));
  119.  
  120. ShowPlayerDialog(playerid, dialog_REGISTER, DIALOG_STYLE_INPUT,
  121. ""srwboja"VP - "BELA"Registracija", yString,
  122. ""srwboja"UNESI", "KICK");
  123. }
  124. case 1: {
  125. //camera position move to spawn..
  126. InterpolateCameraPos(playerid, 537.2963, -995.1501, 124.7903, 1373.3412, -2283.9702, 65.2952, 10000, 30000);
  127. InterpolateCameraLookAt(playerid, 538.1735, -995.6352, 124.6076, 1374.3429, -2283.9468, 64.7175, 10000, 30000);
  128.  
  129. //login dialog
  130. format(yString, sizeof(yString), ""srwboja"> "BELA"Dobrodosao %s na 'Ime Servera'\n"srwboja"___________________________________________________________________ \
  131. \n> "BELA"Vas account je pronadjen u nasoj bazi podataka..\n"srwboja"> "BELA"Molimo ulogujte se, unesite tacnu sifru ispod\n \
  132. "srwboja"___________________________________________________________________",
  133. GetName(playerid));
  134.  
  135. ShowPlayerDialog(playerid, dialog_LOGIN, DIALOG_STYLE_PASSWORD, ""srwboja"VP - "BELA"Prijavljivanje", yString, ""srwboja"UNESI", "IZLAZ");
  136. }
  137. }
  138. return 1;
  139. }
  140. //################################################//
  141. stock GetName(playerid) {
  142. new name[MAX_PLAYER_NAME];
  143. GetPlayerName(playerid, name, sizeof(name));
  144. return name;
  145. }
  146. //################################################//
  147. func: CheckSQLID(playerid) {
  148. PI[playerid][pSQLID] = cache_insert_id();
  149. printf("(MYSQl REGISTER): Novi account kreiran ! Ime: %s | ID: %d", GetName(playerid), playerid);
  150. return 1;
  151. }
  152. //################################################//
  153. func: OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  154. if(dialogid == dialog_REGISTER) {
  155. if(!response)
  156. return Kick(playerid);
  157.  
  158. yString[0] = (EOS);
  159.  
  160. format(PI[playerid][pName], 24, GetName(playerid));
  161. format(PI[playerid][pLozinka], 128, inputtext);
  162.  
  163. yQuery[0] = (EOS);
  164.  
  165. mysql_format(SQL, yQuery, sizeof(yQuery), "INSERT INTO `users` (Name, Lozinka) VALUES ('%e', '%e')", GetName(playerid), inputtext);
  166. mysql_tquery(SQL, yQuery, "CheckSQLID", "");
  167.  
  168. ShowPlayerDialog(playerid, dialog_DRZAVA, DIALOG_STYLE_LIST,
  169. ""srwboja"VP - "BELA"Drzava",
  170. ""srwboja"[1]. "BELA"Srbija\n"srwboja"[2]. "BELA"Hrvatska\n"srwboja"[3]. "BELA"BiH\n"srwboja"[4]. "BELA"Crna Gora\n"srwboja"[5]. "BELA"Ostalo\n",
  171. ""srwboja"ODABERI", "KICK");
  172. }
  173.  
  174. if(dialogid == dialog_EMAIL) {
  175. if(!response)
  176. return Kick(playerid);
  177.  
  178. if(!IsValidEmail(inputtext))
  179. return Kick(playerid);
  180.  
  181. yString[0] = (EOS);
  182. yQuery[0] = (EOS);
  183.  
  184. format(PI[playerid][pEmail], 128, inputtext);
  185.  
  186. mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Email` = '%s' WHERE `ID` = '%d'", PI[playerid][pEmail], PI[playerid][pSQLID]);
  187. mysql_tquery(SQL, yQuery);
  188.  
  189. Info(playerid, "Vasa e-mail adresa: %s", inputtext);
  190.  
  191. yString[0] = (EOS);
  192. ShowPlayerDialog(playerid, dialog_SPOL, DIALOG_STYLE_MSGBOX, ""srwboja"VP - "BELA"Spol",
  193. ""srwboja"> "BELA"Odaberite kog ste spola, musko lili zensko?",
  194. ""srwboja"MUSKO", "ZENSKO");
  195. }
  196.  
  197. if(dialogid == dialog_SPOL) {
  198. if(!response) {
  199. Info(playerid, "Uredu, vi ste zenskog spola !");
  200. PI[playerid][pSpol] = 2, PI[playerid][pSkin] = 12;
  201.  
  202. yQuery[0] = (EOS);
  203. mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Spol` = 2, `Skin` = 12 WHERE `ID` = %d", PI[playerid][pSQLID]);
  204. mysql_tquery(SQL, yQuery);
  205.  
  206. SetPlayerSkin(playerid, PI[playerid][pSkin]);
  207. GivePlayerMoney(playerid, PI[playerid][pNovac]);
  208. SetSpawnInfo(playerid, 0, PI[playerid][pSkin], 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0); //edit
  209. SpawnPlayer(playerid);
  210. }
  211.  
  212. Info(playerid, "Uredu, vi ste muskog spola !");
  213. PI[playerid][pSpol] = 1, PI[playerid][pSkin] = 19;
  214.  
  215. yQuery[0] = (EOS);
  216. mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Spol` = 1, `Skin` = 29 WHERE `ID` = %d", PI[playerid][pSQLID]);
  217. mysql_tquery(SQL, yQuery);
  218.  
  219. SetPlayerSkin(playerid, PI[playerid][pSkin]);
  220. GivePlayerMoney(playerid, PI[playerid][pNovac]);
  221. SetSpawnInfo(playerid, 0, PI[playerid][pSkin], 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0); //edit
  222. SpawnPlayer(playerid);
  223. return 1;
  224. }
  225.  
  226. if(dialogid == dialog_DRZAVA) {
  227. if(!response)
  228. return Kick(playerid);
  229.  
  230. yQuery[0] = (EOS);
  231. switch(listitem) {
  232. case 0: {
  233. Info(playerid, "Vi ste poreklom iz Srbije !");
  234.  
  235. PI[playerid][pDrzava] = 1;
  236. mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Drzava` = '1' WHERE `ID` = '%d'", PI[playerid][pSQLID]);
  237. mysql_tquery(SQL, yQuery);
  238.  
  239. format(yString, sizeof(yString), ""srwboja"> "BELA"Molimo Vas unesite Vas broj godina ispod!\
  240. \n"srwboja"__________________________________________________\n"srwboja"> "BELA"Minimalan broj godina: 12, maksimalan: 50\n\
  241. "srwboja"__________________________________________________");
  242.  
  243. ShowPlayerDialog(playerid, dialog_GODINE, DIALOG_STYLE_INPUT,
  244. ""srwboja"VP - "BELA"Godine", yString,
  245. ""srwboja"UNESI", "KICK");
  246. }
  247. case 1: {
  248. Info(playerid, "Vi ste poreklom iz Hrvatske !");
  249.  
  250. PI[playerid][pDrzava] = 2;
  251. mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Drzava` = '2' WHERE `ID` = '%d'", PI[playerid][pSQLID]);
  252. mysql_tquery(SQL, yQuery);
  253.  
  254. format(yString, sizeof(yString), ""srwboja"> "BELA"Molimo Vas unesite Vas broj godina ispod!\
  255. \n"srwboja"__________________________________________________\n"srwboja"> "BELA"Minimalan broj godina: 12, maksimalan: 50\n\
  256. "srwboja"__________________________________________________");
  257.  
  258. ShowPlayerDialog(playerid, dialog_GODINE, DIALOG_STYLE_INPUT,
  259. ""srwboja"VP - "BELA"Godine", yString,
  260. ""srwboja"UNESI", "KICK");
  261. }
  262. case 2: {
  263. Info(playerid, "Vi ste poreklom iz Bosne i Hercegovine !");
  264.  
  265. PI[playerid][pDrzava] = 3;
  266. mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Drzava` = '3' WHERE `ID` = '%d'", PI[playerid][pSQLID]);
  267. mysql_tquery(SQL, yQuery);
  268.  
  269. format(yString, sizeof(yString), ""srwboja"> "BELA"Molimo Vas unesite Vas broj godina ispod!\
  270. \n"srwboja"__________________________________________________\n"srwboja"> "BELA"Minimalan broj godina: 12, maksimalan: 50\n\
  271. "srwboja"__________________________________________________");
  272.  
  273. ShowPlayerDialog(playerid, dialog_GODINE, DIALOG_STYLE_INPUT,
  274. ""srwboja"VP - "BELA"Godine", yString,
  275. ""srwboja"UNESI", "KICK");
  276. }
  277. case 3: {
  278. Info(playerid, "Vi ste poreklom iz Crne Gore !");
  279.  
  280. PI[playerid][pDrzava] = 4;
  281. mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Drzava` = '4' WHERE `ID` = '%d'", PI[playerid][pSQLID]);
  282. mysql_tquery(SQL, yQuery);
  283.  
  284. format(yString, sizeof(yString), ""srwboja"> "BELA"Molimo Vas unesite Vas broj godina ispod!\
  285. \n"srwboja"__________________________________________________\n"srwboja"> "BELA"Minimalan broj godina: 12, maksimalan: 50\n\
  286. "srwboja"__________________________________________________");
  287.  
  288. ShowPlayerDialog(playerid, dialog_GODINE, DIALOG_STYLE_INPUT,
  289. ""srwboja"VP - "BELA"Godine", yString,
  290. ""srwboja"UNESI", "KICK");
  291. }
  292. case 4: {
  293. Info(playerid, "Vi ste poreklom iz neke druge drzave !");
  294.  
  295. PI[playerid][pDrzava] = 5;
  296. mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Drzava` = '5' WHERE `ID` = '%d'", PI[playerid][pSQLID]);
  297. mysql_tquery(SQL, yQuery);
  298.  
  299. format(yString, sizeof(yString), ""srwboja"> "BELA"Molimo Vas unesite Vas broj godina ispod!\
  300. \n"srwboja"__________________________________________________\n"srwboja"> "BELA"Minimalan broj godina: 12, maksimalan: 50\n\
  301. "srwboja"__________________________________________________");
  302.  
  303. ShowPlayerDialog(playerid, dialog_GODINE, DIALOG_STYLE_INPUT,
  304. ""srwboja"VP - "BELA"Godine", yString,
  305. ""srwboja"UNESI", "KICK");
  306. }
  307. }
  308. return 1;
  309. }
  310.  
  311. if(dialogid == dialog_GODINE) {
  312. if(!response)
  313. return Kick(playerid);
  314.  
  315. PI[playerid][pGodine] = strval(inputtext);
  316.  
  317. yQuery[0] = (EOS), yString[0] = (EOS);
  318.  
  319. mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Godine` = '%d' WHERE `ID` = '%d'", PI[playerid][pGodine], PI[playerid][pSQLID]);
  320. mysql_tquery(SQL, yQuery);
  321.  
  322. format(yString, sizeof(yString), ""srwboja"> "BELA"Unesite Vasu vazecu e-mail adresu !\n"srwboja"_______________________________________________ \
  323. \n> "BELA"Zbog bezbednosti Vaseg accounta, molimo vas unesite e-mail..\n"srwboja"___________________________________________________________________",
  324. GetName(playerid));
  325.  
  326. ShowPlayerDialog(playerid, dialog_EMAIL, DIALOG_STYLE_INPUT, ""srwboja"VP - "BELA"E-Mail", yString, ""srwboja"UNESI", "KICK");
  327. return 1;
  328. }
  329.  
  330. //login
  331. if(dialogid == dialog_LOGIN) {
  332. if(!response)
  333. return Kick(playerid);
  334.  
  335. yQuery[0] = (EOS);
  336.  
  337. mysql_format(SQL, yQuery, sizeof(yQuery), "SELECT * FROM `users` WHERE `Name` = '%e' AND `Lozinka` = '%e' LIMIT 1", GetName(playerid), inputtext);
  338. mysql_pquery(SQL, yQuery, "OnPlayerLogin", "d", playerid);
  339. }
  340. return 1;
  341. }
  342. //################################################//
  343. IsValidEmail(const email[])
  344. {
  345. new at_pos = strfind(email, "@", true);
  346. if(at_pos >= 1)
  347. {
  348. new offset = (at_pos + 1), dot_pos = strfind(email, ".", true, offset);
  349. if(dot_pos > offset)
  350. {
  351. return 1;
  352. }
  353. }
  354. return 0;
  355. }
  356. //################################################//
  357. func: OnPlayerLogin(playerid) {
  358. yString[0] = (EOS);
  359. switch(cache_num_rows()) {
  360. case 0: {
  361. format(yString, sizeof(yString), ""srwboja"> "BELA"Dobrodosao %s na 'Ime Servera'\n"srwboja"___________________________________________________________________ \
  362. \n> "BELA"Vas account je pronadjen u nasoj bazi podataka..\n"srwboja"> "BELA"Molimo ulogujte se, unesite tacnu sifru ispod\n \
  363. "srwboja"___________________________________________________________________",
  364. GetName(playerid));
  365.  
  366. ShowPlayerDialog(playerid, dialog_LOGIN, DIALOG_STYLE_PASSWORD, ""srwboja"VP - "BELA"Prijavljivanje", yString, ""srwboja"UNESI", "IZLAZ");
  367.  
  368. SendClientMessage(playerid, 0xFF0000FF, "(greska): "BELA"Pogresna lozinka !");
  369. }
  370. case 1: {
  371. cache_get_value_name(0, "Name", PI[playerid][pName]);
  372. cache_get_value_name(0, "Lozinka", PI[playerid][pLozinka]);
  373. cache_get_value_name(0, "Email", PI[playerid][pEmail]);
  374. cache_get_value_name_int(0, "Drzava", PI[playerid][pDrzava]);
  375. cache_get_value_name_int(0, "Godine", PI[playerid][pGodine]);
  376. cache_get_value_name_int(0, "Spol", PI[playerid][pSpol]);
  377. cache_get_value_name_int(0, "Skin", PI[playerid][pSkin]);
  378. cache_get_value_name_int(0, "Novac", PI[playerid][pNovac]);
  379. cache_get_value_name_int(0, "Level", PI[playerid][pLevel]);
  380.  
  381. cache_get_value_name_int(0, "ID", PI[playerid][pSQLID]);
  382.  
  383. for(new i = 0; i < 40; i++) { SendClientMessage(playerid, -1, " "); }
  384. Info(playerid, "%s, uspesno ste se ulogovali na 'Ime Servera' OGC !", GetName(playerid));
  385.  
  386. ResetPlayerMoney(playerid), GivePlayerMoney(playerid, PI[playerid][pNovac]);
  387.  
  388. SetPlayerScore(playerid, PI[playerid][pLevel]);
  389. SetPlayerSkin(playerid, PI[playerid][pSkin]);
  390. TogglePlayerSpectating(playerid, false);
  391.  
  392. SetSpawnInfo(playerid, 0, PI[playerid][pSkin], 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0); //edit
  393. SpawnPlayer(playerid);
  394. }
  395. }
  396. return 1;
  397. }
  398. //################################################//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement