Advertisement
Guest User

Untitled

a guest
May 1st, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.32 KB | None | 0 0
  1. // This is a comment
  2. // uncomment the line below if you want to write a filterscript
  3. //#define FILTERSCRIPT
  4.  
  5. #include <a_samp>
  6. #include <a_mysql>
  7. #include <zcmd>
  8.  
  9.  
  10. //MySQL Configuration
  11. #define SQL_HOST "localhost"
  12. #define SQL_DB "dbdbdb"
  13. #define SQL_USER "root"
  14. #define SQL_PASS ""
  15.  
  16. #define TABLENAME "users"
  17.  
  18. #define CONNECT_THREAD_ID 1
  19. #define REG_THREAD_ID 2
  20. #define LOGIN_THREAD_ID 3
  21.  
  22. #define GREY 0xAFAFAFAA
  23. #define RED 0xFF0000AA
  24. #define YELLOW 0xFFFF00AA
  25. #define LIGHTBLUE 0x33CCFFAA
  26.  
  27. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  28.  
  29. new
  30. bool:LoggedIn[MAX_PLAYERS] = { false, ... },
  31. bool:AccRegistered[MAX_PLAYERS] = { false, ... },
  32. Wrongattempt[MAX_PLAYERS],
  33. TimerSet[MAX_PLAYERS],
  34. pLogtimer[MAX_PLAYERS],
  35. PlayerMoney[MAX_PLAYERS],
  36. PlayerScore[MAX_PLAYERS],
  37. CONNECT_PLAYER_ID = INVALID_PLAYER_ID,
  38. LOGIN_PLAYER_ID = INVALID_PLAYER_ID,
  39. REG_PLAYER_ID = INVALID_PLAYER_ID;
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. public OnFilterScriptInit()
  47. {
  48. print("\n--------------------------------------");
  49. print(" Blank Filterscript by your name here");
  50. print("--------------------------------------\n");
  51. return 1;
  52. }
  53.  
  54. public OnFilterScriptExit()
  55. {
  56. return 1;
  57. }
  58.  
  59.  
  60. main()
  61. {
  62. print("\n----------------------------------");
  63. print(" Blank Gamemode by your name here");
  64. print("----------------------------------\n");
  65. }
  66.  
  67.  
  68. public OnGameModeInit()
  69. {
  70. // Don't use these lines if it's a filterscript
  71. SetGameModeText("Blank Script");
  72. AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  73. mysql_debug(1);
  74. new Connection = mysql_connect(SQL_HOST, SQL_USER,SQL_DB, SQL_PASS);
  75. if(Connection)
  76. {
  77. new dest[200];
  78. mysql_stat(dest);
  79. printf(dest);
  80. printf(">> MySQL Register Script successfully initialized");
  81. SetupTable();
  82. }
  83. return 1;
  84. }
  85.  
  86. SetupTable()
  87. {
  88. return mysql_query("CREATE TABLE IF NOT EXISTS `"TABLENAME"`(`id` int(11) NOT NULL auto_increment PRIMARY KEY,`Username` varchar(30) NOT NULL,`Password` varchar(50) NOT NULL,`Money` int(10) NOT NULL default '0',`Score` int(10) NOT NULL default '0')");
  89. }
  90.  
  91.  
  92. public OnQueryFinish(query[],resultid)
  93. {
  94. new string[128],pName[MAX_PLAYER_NAME+1];
  95. switch(resultid)
  96. {
  97. case CONNECT_THREAD_ID:
  98. {
  99. if(IsPlayerConnected(CONNECT_PLAYER_ID))
  100. {
  101. GetPlayerName(CONNECT_PLAYER_ID,pName,sizeof pName);
  102. mysql_store_result();
  103. if(mysql_num_rows() > 0)
  104. {
  105. format(string,sizeof(string),">> This account (%s) is registered.Please login by using /login [pass]",pName);
  106. SendClientMessage(CONNECT_PLAYER_ID,GREY,string);
  107. AccRegistered[CONNECT_PLAYER_ID] = true;
  108. pLogtimer[CONNECT_PLAYER_ID] = SetTimerEx("LoginKick",30000,0,"d",CONNECT_PLAYER_ID);
  109. }
  110. else
  111. {
  112. format(string,sizeof(string),">> Welcome %s, you can register by using /register [pass]",pName);
  113. SendClientMessage(CONNECT_PLAYER_ID,GREY,string);
  114. AccRegistered[CONNECT_PLAYER_ID] = false;
  115. }
  116. mysql_free_result();
  117. }
  118. CONNECT_PLAYER_ID = INVALID_PLAYER_ID;
  119. return 0;
  120. }
  121. case REG_THREAD_ID:
  122. {
  123. if(IsPlayerConnected(REG_PLAYER_ID))
  124. {
  125. GetPlayerName(REG_PLAYER_ID,pName,sizeof pName);
  126. format(string,sizeof(string),">> Account %s successfully registered - Remember your password for later use.",pName);
  127. SendClientMessage(REG_PLAYER_ID,GREY,string);
  128. SendClientMessage(REG_PLAYER_ID,GREY,"You have been automatically logged in");
  129. LoggedIn[REG_PLAYER_ID] = true;
  130. AccRegistered[REG_PLAYER_ID] = true;
  131. }
  132. REG_PLAYER_ID = INVALID_PLAYER_ID;
  133. return 0;
  134. }
  135. case LOGIN_THREAD_ID:
  136. {
  137. if(IsPlayerConnected(LOGIN_PLAYER_ID))
  138. {
  139. mysql_store_result();
  140. if(mysql_num_rows() == 1)
  141. {
  142. PlayerMoney[LOGIN_PLAYER_ID] = mysql_fetch_int();
  143. GivePlayerMoney(LOGIN_PLAYER_ID,PlayerMoney[LOGIN_PLAYER_ID]);
  144. ////
  145. PlayerScore[LOGIN_PLAYER_ID] = mysql_fetch_int();
  146. SetPlayerScore(LOGIN_PLAYER_ID,PlayerScore[LOGIN_PLAYER_ID]);
  147. ///
  148. LoggedIn[LOGIN_PLAYER_ID] = true;
  149. format(string,sizeof(string),">> You have been successfully logged in. (Money: %d) (Score: %d)",PlayerMoney[LOGIN_PLAYER_ID], PlayerScore[LOGIN_PLAYER_ID]);
  150. SendClientMessage(LOGIN_PLAYER_ID,GREY,string);
  151. mysql_free_result();
  152. }
  153. else
  154. {
  155. Wrongattempt[LOGIN_PLAYER_ID] += 1;
  156. printf("Bad log in attempt by %s (Total attempts: %d)",pName,Wrongattempt[LOGIN_PLAYER_ID]);
  157. if(Wrongattempt[LOGIN_PLAYER_ID] >= 3)
  158. {
  159. SendClientMessage(LOGIN_PLAYER_ID,RED,">> You have been kicked.( 3 times wrong pass )");
  160. mysql_free_result();
  161. return Kick(LOGIN_PLAYER_ID);
  162. }
  163. mysql_free_result();
  164. SendClientMessage(LOGIN_PLAYER_ID,RED,">> Wrong Password");
  165. }
  166. }
  167. LOGIN_PLAYER_ID = INVALID_PLAYER_ID;
  168. return 0;
  169. }
  170. }
  171. return 1;
  172. }
  173.  
  174.  
  175. public OnGameModeExit()
  176. {
  177. print("MySQL Register / Login Script has been unloaded");
  178. if(mysql_ping()) mysql_close();
  179. return 1;
  180. }
  181.  
  182. MySQLCheck()
  183. {
  184. if(mysql_ping() == -1)
  185. {
  186. mysql_connect(SQL_HOST, SQL_USER,SQL_DB, SQL_PASS);
  187. }
  188. return 1;
  189. }
  190.  
  191. RegisterAccount(playerid,pass[])
  192. {
  193. MySQLCheck();
  194. new
  195. pName[MAX_PLAYER_NAME],
  196. query[256];
  197.  
  198. GetPlayerName(playerid,pName,sizeof(pName));
  199. mysql_real_escape_string(pName,pName);
  200. mysql_real_escape_string(pass,pass);
  201. format(query,sizeof(query),"INSERT INTO `"TABLENAME"` (Username,Password) VALUES ('%s',md5('%s'))",pName,pass);
  202. mysql_query(query,REG_THREAD_ID);
  203. REG_PLAYER_ID = playerid;
  204. return 1;
  205. }
  206.  
  207. LoginPlayer(playerid,pass[])
  208. {
  209. new
  210. pName[MAX_PLAYER_NAME],
  211. query[256];
  212.  
  213. GetPlayerName(playerid,pName,sizeof(pName));
  214. MySQLCheck();
  215.  
  216. mysql_real_escape_string(pName,pName);
  217. mysql_real_escape_string(pass,pass);
  218. format(query,sizeof(query),"SELECT Money, Score FROM `"TABLENAME"` WHERE Username = '%s' AND Password = md5('%s') LIMIT 1",pName,pass);
  219. mysql_query(query,LOGIN_THREAD_ID);
  220. LOGIN_PLAYER_ID = playerid;
  221. return 1;
  222. }
  223.  
  224. public OnPlayerRequestClass(playerid, classid)
  225. {
  226. SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  227. SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  228. SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  229. return 1;
  230. }
  231.  
  232. public OnPlayerConnect(playerid)
  233. {
  234.  
  235. new
  236. query[256],
  237. pname[MAX_PLAYER_NAME];
  238. Wrongattempt[playerid] = 0;
  239. LoggedIn[playerid] = false;
  240. TimerSet[playerid] = 0;
  241.  
  242. GetPlayerName(playerid,pname,sizeof(pname));
  243. MySQLCheck();
  244. format(query,sizeof(query),"SELECT * FROM `"TABLENAME"` WHERE Username = '%s'",pname);
  245. mysql_query(query,CONNECT_THREAD_ID);
  246. CONNECT_PLAYER_ID = playerid;
  247. SetupTable();
  248. return 1;
  249. }
  250.  
  251. public OnPlayerDisconnect(playerid, reason)
  252. {
  253. if(pLogtimer[playerid] != 0) KillTimer(pLogtimer[playerid]);
  254. new
  255. query[300],
  256. pName[MAX_PLAYER_NAME];
  257.  
  258. GetPlayerName(playerid,pName,sizeof(pName));
  259.  
  260. if(LoggedIn[playerid])
  261. {
  262. new Float:arm;
  263. GetPlayerArmour(playerid,arm);
  264. format(query,sizeof(query),"UPDATE `"TABLENAME"` SET `Money`='%d', `Score`='%d' WHERE (`Username` = '%s')",GetPlayerMoney(playerid), GetPlayerScore(playerid),pName);
  265. mysql_query(query);
  266. }
  267. return 1;
  268. }
  269.  
  270.  
  271. forward LoginKick(playerid);
  272. public LoginKick(playerid)
  273. {
  274. if(!LoggedIn[playerid]) KickEx(playerid,"Not logged in");
  275. else
  276. {
  277. KillTimer(pLogtimer[playerid]);
  278. pLogtimer[playerid] = 0;
  279. }
  280. return 1;
  281. }
  282.  
  283.  
  284. public OnPlayerSpawn(playerid)
  285. {
  286. return 1;
  287. }
  288.  
  289. public OnPlayerDeath(playerid, killerid, reason)
  290. {
  291. return 1;
  292. }
  293.  
  294. public OnVehicleSpawn(vehicleid)
  295. {
  296. return 1;
  297. }
  298.  
  299. public OnVehicleDeath(vehicleid, killerid)
  300. {
  301. return 1;
  302. }
  303.  
  304. public OnPlayerText(playerid, text[])
  305. {
  306. return 1;
  307. }
  308.  
  309. public OnPlayerCommandText(playerid, cmdtext[])
  310. {
  311. if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  312. {
  313. // Do something here
  314. return 1;
  315. }
  316. return 0;
  317. }
  318.  
  319. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  320. {
  321. return 1;
  322. }
  323.  
  324. public OnPlayerExitVehicle(playerid, vehicleid)
  325. {
  326. return 1;
  327. }
  328.  
  329. public OnPlayerStateChange(playerid, newstate, oldstate)
  330. {
  331. return 1;
  332. }
  333.  
  334. public OnPlayerEnterCheckpoint(playerid)
  335. {
  336. return 1;
  337. }
  338.  
  339. public OnPlayerLeaveCheckpoint(playerid)
  340. {
  341. return 1;
  342. }
  343.  
  344. public OnPlayerEnterRaceCheckpoint(playerid)
  345. {
  346. return 1;
  347. }
  348.  
  349. public OnPlayerLeaveRaceCheckpoint(playerid)
  350. {
  351. return 1;
  352. }
  353.  
  354. public OnRconCommand(cmd[])
  355. {
  356. return 1;
  357. }
  358.  
  359. public OnPlayerRequestSpawn(playerid)
  360. {
  361. return 1;
  362. }
  363.  
  364. public OnObjectMoved(objectid)
  365. {
  366. return 1;
  367. }
  368.  
  369. public OnPlayerObjectMoved(playerid, objectid)
  370. {
  371. return 1;
  372. }
  373.  
  374. public OnPlayerPickUpPickup(playerid, pickupid)
  375. {
  376. return 1;
  377. }
  378.  
  379. public OnVehicleMod(playerid, vehicleid, componentid)
  380. {
  381. return 1;
  382. }
  383.  
  384. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  385. {
  386. return 1;
  387. }
  388.  
  389. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  390. {
  391. return 1;
  392. }
  393.  
  394. public OnPlayerSelectedMenuRow(playerid, row)
  395. {
  396. return 1;
  397. }
  398.  
  399. public OnPlayerExitedMenu(playerid)
  400. {
  401. return 1;
  402. }
  403.  
  404. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  405. {
  406. return 1;
  407. }
  408.  
  409. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  410. {
  411. return 1;
  412. }
  413.  
  414. public OnRconLoginAttempt(ip[], password[], success)
  415. {
  416. return 1;
  417. }
  418.  
  419. public OnPlayerUpdate(playerid)
  420. {
  421. return 1;
  422. }
  423.  
  424. public OnPlayerStreamIn(playerid, forplayerid)
  425. {
  426. return 1;
  427. }
  428.  
  429. public OnPlayerStreamOut(playerid, forplayerid)
  430. {
  431. return 1;
  432. }
  433.  
  434. public OnVehicleStreamIn(vehicleid, forplayerid)
  435. {
  436. return 1;
  437. }
  438.  
  439. public OnVehicleStreamOut(vehicleid, forplayerid)
  440. {
  441. return 1;
  442. }
  443.  
  444. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  445. {
  446. return 1;
  447. }
  448.  
  449. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  450. {
  451. return 1;
  452. }
  453.  
  454. COMMAND:login(playerid, params[])
  455. {
  456. if(LoggedIn[playerid])
  457. {
  458. return SendClientMessage(playerid,RED,">> You are already logged in");
  459. }
  460. if(!AccRegistered[playerid])
  461. {
  462. return SendClientMessage(playerid,RED,">> This Account is not registered. ( Use /register [pass] )");
  463. }
  464. if(!strlen(params))
  465. {
  466. return SendClientMessage(playerid,RED,"SYNTAX: /login [password]");
  467. }
  468. LoginPlayer(playerid,params);
  469. return true;
  470. }
  471.  
  472. COMMAND:registration(playerid, params[])
  473. {
  474. new pName[MAX_PLAYER_NAME];
  475. GetPlayerName(playerid,pName,sizeof(pName));
  476. if(AccRegistered[playerid])
  477. {
  478. return SendClientMessage(playerid,RED,">> This account is already registered. ( /login [pass] )");
  479. }
  480. if(LoggedIn[playerid])
  481. {
  482. return SendClientMessage(playerid,RED,">> You are already logged in");
  483. }
  484. if(!strlen(params))
  485. {
  486. return SendClientMessage(playerid,RED,"SYNTAX: /register [password]");
  487. }
  488. if(strlen(params) < 6)
  489. {
  490. return SendClientMessage(playerid,RED,">> The password should contain 6 characters at least.");
  491. }
  492. RegisterAccount(playerid,params);
  493. return 1;
  494. }
  495.  
  496.  
  497. stock KickEx(playerid,reason[])
  498. {
  499. new
  500. string[1000],
  501. MsgAll[128],
  502. pName[MAX_PLAYER_NAME];
  503. GetPlayerName(playerid,pName,sizeof(pName));
  504. format(string,sizeof(string),"You have been kicked: ");
  505. strcat(string,reason,sizeof(string));
  506. SendClientMessage(playerid,RED,string);
  507. Kick(playerid);
  508. format(MsgAll,sizeof(MsgAll),">> %s has been kicked.(Reason: %s)",pName,reason);
  509. SendClientMessageToAll(GREY,MsgAll);
  510. return 1;
  511. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement