daily pastebin goal
45%
SHARE
TWEET

Untitled

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