Advertisement
Guest User

Untitled

a guest
Mar 19th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.78 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_mysql>
  3.  
  4. native WP_Hash(buffer[], len, const str[]); //Hashing the passwords
  5.  
  6. //============= DATABASE =============== //
  7. #define MYSQL_HOST "x" //hiding for security reasons
  8. #define MYSQL_USER "x"
  9. #define MYSQL_PASSWORD "x"
  10. #define MYSQL_DATABASE "x"
  11.  
  12. //============= NEWLY REGISTERED PLAYERS ============== //
  13. #define SPAWN_X 10.0
  14. #define SPAWN_Y 10.0
  15. #define SPAWN_Z 14.0
  16. #define SPAWN_A 0.0
  17.  
  18. //============= DIALOG REGISTER / LOGIN =============== //
  19.  
  20. enum
  21. {
  22. LoginDialog,
  23. RegisterDialog
  24. };
  25.  
  26. new
  27. mysql;
  28.  
  29.  
  30. //============ PLAYER DATA =============== //
  31. enum PlayerData
  32. {
  33. ID,
  34. Name[MAX_PLAYER_NAME],
  35. Password[129],
  36. IP[16],
  37. Admin,
  38. VIP,
  39. Money,
  40. Float:posX,
  41. Float:posY,
  42. Float:posZ,
  43. Float:posR,
  44. Gun1,
  45. Ammo1,
  46. Gun2,
  47. Ammo2,
  48. Gun3,
  49. Ammo3,
  50. Skin
  51. };
  52.  
  53. new PlayerInfo[MAX_PLAYERS][PlayerData];
  54.  
  55.  
  56. //============ FORWARDS ================= //
  57. forward OnAccountCheck(playerid);
  58.  
  59. main()
  60. {
  61. print("\n----------------------------------");
  62. print(" Blank Gamemode by your name here");
  63. print("----------------------------------\n");
  64. }
  65.  
  66.  
  67. public OnGameModeInit()
  68. {
  69. // Don't use these lines if it's a filterscript
  70. SetGameModeText("GTA RPG"); //Tha name
  71. UsePlayerPedAnims(); //Walking like CJ
  72. mysql_log(LOG_ALL);
  73. mysql = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
  74. if(mysql_errno() != 0)
  75. {
  76. printf("[MySQL] Could not connect to MYSQL Database :(");
  77. }
  78. else
  79. {
  80. printf("[MySQL] Successfully connected to MYSQL Database!");
  81. }
  82. return 1;
  83. }
  84.  
  85. public OnGameModeExit()
  86. {
  87. return 1;
  88. }
  89.  
  90. public OnPlayerRequestClass(playerid, classid)
  91. {
  92. SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  93. SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  94. SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  95. return 1;
  96. }
  97.  
  98. public OnPlayerConnect(playerid)
  99. {
  100. TogglePlayerSpectating(playerid, true);
  101. new
  102. query[128],
  103. playername[MAX_PLAYER_NAME];
  104.  
  105. GetPlayerName(playerid, playername, sizeof(playername));
  106. mysql_format(mysql, query, sizeof(query), "SELECT `Password`, `ID` FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
  107. mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
  108. return 1;
  109. }
  110.  
  111. public OnPlayerDisconnect(playerid, reason)
  112. {
  113. return 1;
  114. }
  115.  
  116. public OnPlayerSpawn(playerid)
  117. {
  118. return 1;
  119. }
  120.  
  121. public OnPlayerDeath(playerid, killerid, reason)
  122. {
  123. return 1;
  124. }
  125.  
  126. public OnVehicleSpawn(vehicleid)
  127. {
  128. return 1;
  129. }
  130.  
  131. public OnVehicleDeath(vehicleid, killerid)
  132. {
  133. return 1;
  134. }
  135.  
  136. public OnPlayerText(playerid, text[])
  137. {
  138. return 1;
  139. }
  140.  
  141. public OnPlayerCommandText(playerid, cmdtext[])
  142. {
  143. if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  144. {
  145. // Do something here
  146. return 1;
  147. }
  148. return 0;
  149. }
  150.  
  151. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  152. {
  153. return 1;
  154. }
  155.  
  156. public OnPlayerExitVehicle(playerid, vehicleid)
  157. {
  158. return 1;
  159. }
  160.  
  161. public OnPlayerStateChange(playerid, newstate, oldstate)
  162. {
  163. return 1;
  164. }
  165.  
  166. public OnPlayerEnterCheckpoint(playerid)
  167. {
  168. return 1;
  169. }
  170.  
  171. public OnPlayerLeaveCheckpoint(playerid)
  172. {
  173. return 1;
  174. }
  175.  
  176. public OnPlayerEnterRaceCheckpoint(playerid)
  177. {
  178. return 1;
  179. }
  180.  
  181. public OnPlayerLeaveRaceCheckpoint(playerid)
  182. {
  183. return 1;
  184. }
  185.  
  186. public OnRconCommand(cmd[])
  187. {
  188. return 1;
  189. }
  190.  
  191. public OnPlayerRequestSpawn(playerid)
  192. {
  193. return 1;
  194. }
  195.  
  196. public OnObjectMoved(objectid)
  197. {
  198. return 1;
  199. }
  200.  
  201. public OnPlayerObjectMoved(playerid, objectid)
  202. {
  203. return 1;
  204. }
  205.  
  206. public OnPlayerPickUpPickup(playerid, pickupid)
  207. {
  208. return 1;
  209. }
  210.  
  211. public OnVehicleMod(playerid, vehicleid, componentid)
  212. {
  213. return 1;
  214. }
  215.  
  216. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  217. {
  218. return 1;
  219. }
  220.  
  221. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  222. {
  223. return 1;
  224. }
  225.  
  226. public OnPlayerSelectedMenuRow(playerid, row)
  227. {
  228. return 1;
  229. }
  230.  
  231. public OnPlayerExitedMenu(playerid)
  232. {
  233. return 1;
  234. }
  235.  
  236. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  237. {
  238. return 1;
  239. }
  240.  
  241. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  242. {
  243. return 1;
  244. }
  245.  
  246. public OnRconLoginAttempt(ip[], password[], success)
  247. {
  248. return 1;
  249. }
  250.  
  251. public OnPlayerUpdate(playerid)
  252. {
  253. return 1;
  254. }
  255.  
  256. public OnPlayerStreamIn(playerid, forplayerid)
  257. {
  258. return 1;
  259. }
  260.  
  261. public OnPlayerStreamOut(playerid, forplayerid)
  262. {
  263. return 1;
  264. }
  265.  
  266. public OnVehicleStreamIn(vehicleid, forplayerid)
  267. {
  268. return 1;
  269. }
  270.  
  271. public OnVehicleStreamOut(vehicleid, forplayerid)
  272. {
  273. return 1;
  274. }
  275.  
  276. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  277. {
  278. switch(dialogid)
  279. {
  280. case LoginDialog:
  281. {
  282. if(!response) Kick(playerid);
  283.  
  284. new
  285. hashpass[129],
  286. query[100],
  287. playername[MAX_PLAYER_NAME];
  288.  
  289. GetPlayerName(playerid, playername, sizeof(playername));
  290. WP_Hash(hashpass, sizeof(hashpass), inputtext);
  291. if(!strcmp(hashpass, PlayerInfo[playerid][Password]))
  292. {
  293. mysql_format(mysql, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
  294. mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
  295. }
  296. else
  297. {
  298. SendClientMessage(playerid, -1, "You have specified an incorrect password!");
  299. ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT, "Login", "Welcome player!\nYour account has been found in our database. Please fill in your password:", "Login", "Quit");
  300. }
  301. }
  302. case RegisterDialog:
  303. {
  304. if(!response) return Kick(playerid);
  305. if(strlen(inputtext) < 5)
  306. {
  307. SendClientMessage(playerid, -1, "Your password must at least contain more than 4 characters.");
  308. return ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_INPUT, "Register", "Welcome player!\nYour account has not been registered yet. Please fill in your desired password:", "Register", "Quit");
  309. }
  310. new
  311. query[512],
  312. playername[MAX_PLAYER_NAME],
  313. playerip[16];
  314.  
  315.  
  316. GetPlayerName(playerid, playername, sizeof(playername));
  317. GetPlayerIp(playerid, playerip, sizeof(playerip));
  318. WP_Hash(PlayerInfo[playerid][Password], 129, inputtext);
  319. mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX`, `PosY`, `PosZ`, `PosR`, `Gun1`, `Ammo1`, `Gun2`, `Ammo2`, `Gun3`, `Ammo3`, `Skin`) VALUES ('%e', '%e', '%e', 0, 0, 0, %f, %f, %f, %f, 0, 0, 0, 0, 0, 0, 0)", playername, PlayerInfo[playerid][Password], playerip, SPAWN_X, SPAWN_Y, SPAWN_Z, SPAWN_A);
  320. mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
  321. }
  322. }
  323. return 1;
  324. }
  325.  
  326. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  327. {
  328. return 1;
  329. }
  330.  
  331. //========================== ACCOUNT CHECK =====================================
  332.  
  333. public OnAccountCheck(playerid)
  334. {
  335. new
  336. rows,
  337. fields;
  338. cache_get_data(rows, fields, mysql);
  339.  
  340. if(rows)
  341. {
  342. cache_get_value_index(0, 3, PlayerInfo[playerid][Password], mysql, 129);
  343. PlayerInfo[playerid][ID] = cache_get_value_index_int(0, "ID");
  344. ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT, "Login", "Welcome player!\nYour account has been found in our database. Please fill in your password:", "Login", "Quit");
  345. }
  346. else
  347. {
  348. ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_INPUT, "Register", "Welcome player!\nYour account has not been registered yet. Please fill in your desired password:", "Register", "Quit");
  349. }
  350. return true;
  351. }
  352.  
  353. forward OnAccountLoad(playerid);
  354. public OnAccountLoad(playerid)
  355. {
  356. cache_get_value_index_int(0, 5, PlayerInfo[playerid][Admin]);
  357. cache_get_value_index_int(0, 6, PlayerInfo[playerid][VIP]);
  358. cache_get_value_index_int(0, 7, PlayerInfo[playerid][Money]);
  359. cache_get_value_index_float(0, 8, PlayerInfo[playerid][posX]);
  360. cache_get_value_index_float(0, 9, PlayerInfo[playerid][posY]);
  361. cache_get_value_index_float(0, 10, PlayerInfo[playerid][posZ]);
  362. cache_get_value_index_float(0, 11, PlayerInfo[playerid][posR]);
  363. cache_get_value_index_int(0, 12, PlayerInfo[playerid][Gun1]);
  364. cache_get_value_index_int(0, 13, PlayerInfo[playerid][Ammo1]);
  365. cache_get_value_index_int(0, 14, PlayerInfo[playerid][Gun2]);
  366. cache_get_value_index_int(0, 15, PlayerInfo[playerid][Ammo2]);
  367. cache_get_value_index_int(0, 16, PlayerInfo[playerid][Gun3]);
  368. cache_get_value_index_int(0, 17, PlayerInfo[playerid][Ammo3]);
  369. cache_get_value_index_int(0, 18, PlayerInfo[playerid][Skin]);
  370.  
  371. TogglePlayerSpectating(playerid, false);
  372.  
  373. GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);
  374.  
  375. SetSpawnInfo(playerid, 0, PlayerInfo[playerid][Skin], PlayerInfo[playerid][posX], PlayerInfo[playerid][posY], PlayerInfo[playerid][posZ], PlayerInfo[playerid][posR], PlayerInfo[playerid][Gun1],PlayerInfo[playerid][Ammo1],PlayerInfo[playerid][Gun2],PlayerInfo[playerid][Ammo2],PlayerInfo[playerid][Gun3],PlayerInfo[playerid][Ammo3]);
  376. SpawnPlayer(playerid);
  377.  
  378. SendClientMessage(playerid, -1, "You have successfully logged in.");
  379. return true;
  380. }
  381.  
  382. forward OnAccountRegister(playerid);
  383. public OnAccountRegister(playerid)
  384. {
  385. PlayerInfo[playerid][ID] = cache_insert_id();
  386. printf("[Registration] New account registered. Database ID: [%d]", PlayerInfo[playerid][ID]);
  387.  
  388. TogglePlayerSpectating(playerid, false);
  389.  
  390. SetSpawnInfo(playerid, 0, 23, SPAWN_X, SPAWN_Y, SPAWN_Z, SPAWN_A, 0, 0, 0, 0, 0, 0);
  391. SpawnPlayer(playerid);
  392. return true;
  393. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement