Guest User

Untitled

a guest
Aug 3rd, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.25 KB | None | 0 0
  1.  
  2. #include <a_samp>
  3. #include <a_mysql>
  4. #include <zcmd>
  5. #include <sscanf2>
  6.  
  7. /* MySQL Connection */
  8.  
  9. #define MySQL_Hostname "localhost" //This will be your mysql host. Default for xampp is localhost
  10. #define MySQL_Username "root" //This will be your mysql username. Default for xampp is root
  11. #define MySQL_Database "genx" //This is your database name. Remember we have created a database called server before.
  12. #define MySQL_Password "" //This is your mysql password. In xampp, the password didn't set. So leave it empty.
  13.  
  14. /* Dialog Definition */
  15.  
  16. #define DIALOG_REGISTER 1
  17. #define DIALOG_LOGIN 2
  18.  
  19. /* Colour Definition */
  20.  
  21. #define COLOR_WHITE 0xFFFFFFAA
  22. #define WHITE "{FFFFFF}"
  23. #define COLOR_GREY 0xAFAFAFAA
  24. #define GREY "{AFAFAA}"
  25. #define COLOR_LIGHTBLUE 0x33CCFFAA
  26. #define LIGHTBLUE "{CCFFAA}"
  27. #define COLOR_RED 0xAA3333AA
  28. #define RED "{FF0000}"
  29.  
  30. /* Starter Accounts */
  31.  
  32. #define starterCash 400
  33.  
  34. /* Server Definitions */
  35.  
  36. #define ServerName "Generation X Roleplay"
  37. #define GameMode "GenX:RP"
  38. #define GameVersion "v1.0"
  39.  
  40. /* End of Definitions */
  41.  
  42. static dbHandle;
  43. new firstPlayers = 10;
  44.  
  45. native WP_Hash(buffer[], len, const str[]); //Whirlpool
  46.  
  47. enum PlayerData
  48. {
  49. ID,
  50. Name[MAX_PLAYER_NAME],
  51. Password[129],
  52. Cash
  53. }
  54. new PlayerInfo[MAX_PLAYERS][PlayerData];
  55.  
  56. main()
  57. {
  58. }
  59.  
  60. public OnGameModeInit()
  61. {
  62. // Don't use these lines if it's a filterscript
  63. new string[126];
  64. format(string, sizeof(string), "%s %s", GameMode, GameVersion);
  65. SetGameModeText(string);
  66. format(string, sizeof(string), "hostname %s", ServerName);
  67. SendRconCommand(string);
  68. AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  69.  
  70. mysql_log(LOG_ERROR | LOG_WARNING | LOG_DEBUG);
  71. dbHandle = mysql_connect(MySQL_Hostname, MySQL_Username, MySQL_Database, MySQL_Password);
  72. if(mysql_errno(dbHandle) != 0)
  73. {
  74. printf("[-- Could not establish a MySQL connection! --]");
  75. }
  76. else
  77. {
  78. printf("[-- Established a successful MySQL connection! --]");
  79. }
  80. return 1;
  81. }
  82.  
  83. public OnGameModeExit()
  84. {
  85. mysql_close(dbHandle);
  86. return 1;
  87. }
  88.  
  89. public OnPlayerRequestClass(playerid, classid)
  90. {
  91. SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  92. SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  93. SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  94. return 1;
  95. }
  96.  
  97. public OnPlayerConnect(playerid)
  98. {
  99. if(dbHandle)
  100. {
  101. new query[128];
  102. GetPlayerName(playerid, PlayerInfo[playerid][Name], MAX_PLAYER_NAME);
  103. mysql_format(dbHandle, query, sizeof(query), "SELECT `ID`, `Name` FROM `players` WHERE `Name` = '%s' LIMIT 1", PlayerInfo[playerid][Name]);
  104. mysql_tquery(dbHandle, query, "CheckAccount", "i", playerid);
  105. }
  106. else
  107. {
  108. SendClientMessage(playerid, COLOR_RED, "Error"WHITE": Could not establish a connection to our server.");
  109. Kick(playerid);
  110. }
  111. return 1;
  112. }
  113.  
  114. public OnPlayerDisconnect(playerid, reason)
  115. {
  116. SaveAccount(playerid);
  117. return 1;
  118. }
  119.  
  120. public OnPlayerSpawn(playerid)
  121. {
  122. return 1;
  123. }
  124.  
  125. public OnPlayerDeath(playerid, killerid, reason)
  126. {
  127. return 1;
  128. }
  129.  
  130. public OnVehicleSpawn(vehicleid)
  131. {
  132. return 1;
  133. }
  134.  
  135. public OnVehicleDeath(vehicleid, killerid)
  136. {
  137. return 1;
  138. }
  139.  
  140. public OnPlayerText(playerid, text[])
  141. {
  142. return 1;
  143. }
  144.  
  145. public OnPlayerCommandText(playerid, cmdtext[])
  146. {
  147. if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  148. {
  149. // Do something here
  150. return 1;
  151. }
  152. return 0;
  153. }
  154.  
  155. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  156. {
  157. return 1;
  158. }
  159.  
  160. public OnPlayerExitVehicle(playerid, vehicleid)
  161. {
  162. return 1;
  163. }
  164.  
  165. public OnPlayerStateChange(playerid, newstate, oldstate)
  166. {
  167. return 1;
  168. }
  169.  
  170. public OnPlayerEnterCheckpoint(playerid)
  171. {
  172. return 1;
  173. }
  174.  
  175. public OnPlayerLeaveCheckpoint(playerid)
  176. {
  177. return 1;
  178. }
  179.  
  180. public OnPlayerEnterRaceCheckpoint(playerid)
  181. {
  182. return 1;
  183. }
  184.  
  185. public OnPlayerLeaveRaceCheckpoint(playerid)
  186. {
  187. return 1;
  188. }
  189.  
  190. public OnRconCommand(cmd[])
  191. {
  192. return 1;
  193. }
  194.  
  195. public OnPlayerRequestSpawn(playerid)
  196. {
  197. return 1;
  198. }
  199.  
  200. public OnObjectMoved(objectid)
  201. {
  202. return 1;
  203. }
  204.  
  205. public OnPlayerObjectMoved(playerid, objectid)
  206. {
  207. return 1;
  208. }
  209.  
  210. public OnPlayerPickUpPickup(playerid, pickupid)
  211. {
  212. return 1;
  213. }
  214.  
  215. public OnVehicleMod(playerid, vehicleid, componentid)
  216. {
  217. return 1;
  218. }
  219.  
  220. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  221. {
  222. return 1;
  223. }
  224.  
  225. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  226. {
  227. return 1;
  228. }
  229.  
  230. public OnPlayerSelectedMenuRow(playerid, row)
  231. {
  232. return 1;
  233. }
  234.  
  235. public OnPlayerExitedMenu(playerid)
  236. {
  237. return 1;
  238. }
  239.  
  240. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  241. {
  242. return 1;
  243. }
  244.  
  245. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  246. {
  247. return 1;
  248. }
  249.  
  250. public OnRconLoginAttempt(ip[], password[], success)
  251. {
  252. return 1;
  253. }
  254.  
  255. public OnPlayerUpdate(playerid)
  256. {
  257. return 1;
  258. }
  259.  
  260. public OnPlayerStreamIn(playerid, forplayerid)
  261. {
  262. return 1;
  263. }
  264.  
  265. public OnPlayerStreamOut(playerid, forplayerid)
  266. {
  267. return 1;
  268. }
  269.  
  270. public OnVehicleStreamIn(vehicleid, forplayerid)
  271. {
  272. return 1;
  273. }
  274.  
  275. public OnVehicleStreamOut(vehicleid, forplayerid)
  276. {
  277. return 1;
  278. }
  279.  
  280. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  281. {
  282. if (dialogid == 0)
  283. {
  284. if (response)
  285. {
  286. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, ""LIGHTBLUE"GX:RP - Citizen Login", ""WHITE"Welcome back!\nYour account has been detected as registered.\nPlease fill in your password:", "Login", "Quit");
  287. }
  288. }
  289. else if (dialogid == DIALOG_REGISTER)
  290. {
  291. if (response)
  292. {
  293. if(strlen(inputtext) < 11 || strlen(inputtext) > 29 )
  294. {
  295. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, ""LIGHTBLUE"GX:RP - Immigration Office", ""RED"Your password must be between 11 and 29 characters long."WHITE"\nYour account has not been registered.\nPlease choose and enter a password:", "Register", "Quit");
  296. }
  297. else
  298. {
  299. new query[300];
  300. WP_Hash(PlayerInfo[playerid][Password], 129, inputtext);
  301.  
  302. mysql_format(dbHandle, query, sizeof(query), "INSERT INTO `players` (`Name`, `Password`, `Cash`) VALUES ('%s', '%s', %d)", PlayerInfo[playerid][Name], PlayerInfo[playerid][Password], starterCash);
  303. mysql_tquery(dbHandle, query, "RegisterAccount", "i", playerid);
  304. }
  305. }
  306. else
  307. {
  308. Kick(playerid);
  309. }
  310. }
  311. else if (dialogid == DIALOG_LOGIN)
  312. {
  313. new hashpass[129], query[50];
  314. new pname[MAX_PLAYER_NAME];
  315. if (response)
  316. {
  317. GetPlayerName(playerid, pname, sizeof(pname));
  318. WP_Hash(hashpass, sizeof(hashpass), inputtext);
  319. if(!strcmp(hashpass, PlayerInfo[playerid][Password]))
  320. {
  321. mysql_format(dbHandle, query, sizeof(query), "SELECT * FROM `players` WHERE `Name` = '%e' LIMIT 1", pname);
  322. mysql_tquery(dbHandle, query, "LoadAccount", "i", playerid);
  323. }
  324. else
  325. {
  326. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, ""LIGHTBLUE"GX:RP - Citizen Login", ""RED"You have entered an invalid password!\n"WHITE"Your account has been detected as registered.\nPlease fill in your password:", "Login", "Quit");
  327. }
  328. }
  329. else
  330. {
  331. Kick(playerid);
  332. }
  333. }
  334. return 1;
  335. }
  336.  
  337. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  338. {
  339. return 1;
  340. }
  341.  
  342. forward CheckAccount(playerid);
  343. public CheckAccount(playerid)
  344. {
  345. new rows, fields;
  346. cache_get_data(rows, fields, dbHandle);
  347.  
  348. if(rows)
  349. {
  350. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, ""LIGHTBLUE"GX:RP - Citizen Login", ""WHITE"Welcome back!\nYour account has been detected as registered.\nPlease fill in your password:", "Login", "Quit");
  351. }
  352. else
  353. {
  354. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, ""LIGHTBLUE"GX:RP - Immigration Office", ""WHITE"Welcome!\nYour account has not been registered.\nPlease choose and enter a password:", "Register", "Quit");
  355. }
  356. return 1;
  357. }
  358.  
  359. forward RegisterAccount(playerid);
  360. public RegisterAccount(playerid)
  361. {
  362. PlayerInfo[playerid][ID] = cache_insert_id();
  363. ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, ""LIGHTBLUE"GX:RP - Registration Successful", ""WHITE"The registration progress is complete.\nYou will now be taken to the citizen login.", "Continue", "");
  364. return 1;
  365. }
  366.  
  367. forward LoadAccount(playerid);
  368. public LoadAccount(playerid)
  369. {
  370. PlayerInfo[playerid][ID] = cache_insert_id();
  371. cache_get_field_content(1, "Name", PlayerInfo[playerid][Name]);
  372. cache_get_field_content(2, "Password", PlayerInfo[playerid][Password]);
  373. PlayerInfo[playerid][Cash] = cache_get_field_content_int(3, "Cash");
  374.  
  375. SetSpawnInfo( playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0 );
  376. SpawnPlayer(playerid);
  377. return 1;
  378. }
  379.  
  380. stock playerName(name[MAX_PLAYER_NAME])
  381. {
  382. for(new i; i < MAX_PLAYER_NAME; i++)
  383. {
  384. if(name[i] == '_') name[i] = ' ';
  385. }
  386. return name;
  387. }
  388.  
  389. forward SaveAccount(playerid);
  390. public SaveAccount(playerid)
  391. {
  392. new query[126];
  393. mysql_format(dbHandle, query, sizeof(query), "UPDATE `players` SET `Name`='%s', `Password`='%s', `Cash`=%d", PlayerInfo[playerid][Name], PlayerInfo[playerid][Password], GetPlayerMoney(playerid));
  394. mysql_tquery(dbHandle, query, "RegisterAccount", "i", playerid);
  395. return 1;
  396. }
Advertisement
Add Comment
Please, Sign In to add comment