Advertisement
Guest User

Register System

a guest
Nov 27th, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.06 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 <YSI\y_ini> //If you have installed YSI, then you shouldn't have any problem
  7.  
  8.  
  9. #if defined FILTERSCRIPT
  10.  
  11. #define dregister 2011 //Defining register dialog so it won't mixed up with the other dialogs
  12. #define dlogin 2012 //Defining login dialog so it won't mixed up with the other dialogs
  13. #define UserPath "Users/%s.ini"
  14.  
  15. native WP_Hash(buffer[],len,const str[]); // Whirlpool native, add it at the top of your script under includes
  16.  
  17.  
  18.  
  19. //We will create an enum to store player's data.
  20. enum PlayerInfo
  21. {
  22. Pass[129], //User's password
  23. Adminlevel, //User's admin level
  24. VIPlevel, //User's vip level
  25. Money, //User's money
  26. Scores, //User's scores
  27. Kills, //User's kills
  28. Deaths //User's deaths
  29. }
  30. new pInfo[MAX_PLAYERS][PlayerInfo]; /*This will create a new variable so we can later use it to saving/loading user's info.*/
  31.  
  32. stock Path(playerid) //Will create a new stock so we can easily use it later to load/save user's data in user's path
  33. {
  34. new str[128],name[MAX_PLAYER_NAME];
  35. GetPlayerName(playerid,name,sizeof(name));
  36. format(str,sizeof(str),UserPath,name);
  37. return str;
  38. }
  39.  
  40. forward loadaccount_user(playerid, name[], value[]); //forwarding a new function to load user's data
  41.  
  42. //Now we will use our own function that we have created above
  43. public loadaccount_user(playerid, name[], value[])
  44. {
  45. INI_String("Password", pInfo[playerid][Pass],129); /*we will use INI_String to load user's password.
  46. ("Password",.. will load user's password inside of user's path. 'pInfo[playerid][Pass]',...We have defined our user's variable above called, pInfo. Now it's time to use it here to load user's password. '129',... 129 is a length of a hashed user's password. Whirlpool will hash 128 characters + NULL*/
  47. INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);/*We will use INI_Int to load user's admin level. INI_Int stands for INI_Integer. This load an admin level. */
  48. INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
  49. INI_Int("Money",pInfo[playerid][Money]); //As explained above
  50. INI_Int("Scores",pInfo[playerid][Scores]);//As explained above
  51. INI_Int("Kills",pInfo[playerid][Kills]);//As explained above
  52. INI_Int("Deaths",pInfo[playerid][Deaths]);//As explained above
  53. return 1;
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. public OnFilterScriptInit()
  72. {
  73. print("\n--------------------------------------");
  74. print(" Blank Filterscript by your name here");
  75. print("--------------------------------------\n");
  76. return 1;
  77. }
  78.  
  79. public OnFilterScriptExit()
  80. {
  81. return 1;
  82. }
  83.  
  84. #else
  85.  
  86. main()
  87. {
  88. print("\n----------------------------------");
  89. print(" Blank Gamemode by your name here");
  90. print("----------------------------------\n");
  91. }
  92.  
  93. #endif
  94.  
  95. public OnGameModeInit()
  96. {
  97. // Don't use these lines if it's a filterscript
  98. SetGameModeText("Blank Script");
  99. AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  100. return 1;
  101. }
  102.  
  103. public OnGameModeExit()
  104. {
  105. return 1;
  106. }
  107.  
  108. public OnPlayerRequestClass(playerid, classid)
  109. {
  110. SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  111. SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  112. SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  113. return 1;
  114. }
  115.  
  116. /*OnPlayerConnect will be called when players is connected to your server. So now we will need to show a register or login dialog*/
  117. public OnPlayerConnect(playerid)
  118. {
  119. new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
  120. GetPlayerName(playerid,name,sizeof(name)); //Get player's name
  121. if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
  122. {// then
  123. INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
  124. ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account","Login","Quit");/*A dialog with input style will appear so you can insert your password to login.*/
  125. }
  126. else //If the connected user is not registered,
  127. {//then we will 'force' him to register :)
  128. ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
  129. return 1;
  130. }
  131. return 1;
  132. }
  133.  
  134. public OnPlayerDisconnect(playerid, reason)
  135. {
  136. //Same as OnDialogResponse, we will save their stats inside of their user's account
  137. if(fexist(Path(playerid)))//Will check if the file is exit or not inside of User's folder that we have created.
  138. {
  139. new INI:file = INI_Open(Path(playerid)); //will open their file
  140. INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
  141. INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
  142. INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
  143. INI_WriteInt(file,"Money",GetPlayerMoney(playerid));//We will save his money inside of his account
  144. INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//We will save his score inside of his account
  145. INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);//As explained above
  146. INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);//As explained above
  147. INI_Close(file);//Now after we've done saving their data, we now need to close the file
  148. return 1;
  149. }
  150. return 1;
  151. }
  152.  
  153. public OnPlayerSpawn(playerid)
  154. {
  155. return 1;
  156. }
  157.  
  158. public OnPlayerDeath(playerid, killerid, reason)
  159. {
  160. pInfo[killerid][Kills]++;//Will give 1 kill to killer and it will be saved inside of his/her account
  161. pInfo[playerid][Deaths]++;//Will give 1 death each time they die and it will be saved inside of his/her account
  162. return 1;
  163. }
  164.  
  165. public OnVehicleSpawn(vehicleid)
  166. {
  167. return 1;
  168. }
  169.  
  170. public OnVehicleDeath(vehicleid, killerid)
  171. {
  172. return 1;
  173. }
  174.  
  175. public OnPlayerText(playerid, text[])
  176. {
  177. return 1;
  178. }
  179.  
  180. public OnPlayerCommandText(playerid, cmdtext[])
  181. {
  182. if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  183. {
  184. // Do something here
  185. return 1;
  186. }
  187. return 0;
  188. }
  189.  
  190. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  191. {
  192. return 1;
  193. }
  194.  
  195. public OnPlayerExitVehicle(playerid, vehicleid)
  196. {
  197. return 1;
  198. }
  199.  
  200. public OnPlayerStateChange(playerid, newstate, oldstate)
  201. {
  202. return 1;
  203. }
  204.  
  205. public OnPlayerEnterCheckpoint(playerid)
  206. {
  207. return 1;
  208. }
  209.  
  210. public OnPlayerLeaveCheckpoint(playerid)
  211. {
  212. return 1;
  213. }
  214.  
  215. public OnPlayerEnterRaceCheckpoint(playerid)
  216. {
  217. return 1;
  218. }
  219.  
  220. public OnPlayerLeaveRaceCheckpoint(playerid)
  221. {
  222. return 1;
  223. }
  224.  
  225. public OnRconCommand(cmd[])
  226. {
  227. return 1;
  228. }
  229.  
  230. public OnPlayerRequestSpawn(playerid)
  231. {
  232. return 1;
  233. }
  234.  
  235. public OnObjectMoved(objectid)
  236. {
  237. return 1;
  238. }
  239.  
  240. public OnPlayerObjectMoved(playerid, objectid)
  241. {
  242. return 1;
  243. }
  244.  
  245. public OnPlayerPickUpPickup(playerid, pickupid)
  246. {
  247. return 1;
  248. }
  249.  
  250. public OnVehicleMod(playerid, vehicleid, componentid)
  251. {
  252. return 1;
  253. }
  254.  
  255. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  256. {
  257. return 1;
  258. }
  259.  
  260. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  261. {
  262. return 1;
  263. }
  264.  
  265. public OnPlayerSelectedMenuRow(playerid, row)
  266. {
  267. return 1;
  268. }
  269.  
  270. public OnPlayerExitedMenu(playerid)
  271. {
  272. return 1;
  273. }
  274.  
  275. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  276. {
  277. return 1;
  278. }
  279.  
  280. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  281. {
  282. return 1;
  283. }
  284.  
  285. public OnRconLoginAttempt(ip[], password[], success)
  286. {
  287. return 1;
  288. }
  289.  
  290. public OnPlayerUpdate(playerid)
  291. {
  292. return 1;
  293. }
  294.  
  295. public OnPlayerStreamIn(playerid, forplayerid)
  296. {
  297. return 1;
  298. }
  299.  
  300. public OnPlayerStreamOut(playerid, forplayerid)
  301. {
  302. return 1;
  303. }
  304.  
  305. public OnVehicleStreamIn(vehicleid, forplayerid)
  306. {
  307. return 1;
  308. }
  309.  
  310. public OnVehicleStreamOut(vehicleid, forplayerid)
  311. {
  312. return 1;
  313. }
  314.  
  315. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  316. {
  317. if(dialogid == dregister) //If dialog id is a register dialog
  318. {//then
  319. if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
  320. if(response) //if they clicked the first button "Register"
  321. {//then
  322. if(!strlen(inputtext)) //If they didn't enter any password
  323. {// then we will tell to them to enter the password to register
  324. ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
  325. return 1;
  326. }
  327. //If they have entered a correct password for his/her account...
  328. new hashpass[129]; //Now we will create a new variable to hash his/her password
  329. WP_Hash(hashpass,sizeof(hashpass),inputtext);//We will use whirlpool to hash their inputted text
  330. new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
  331. INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
  332. INI_WriteString(file,"Password",hashpass);//This will write a hashed password into user's account
  333. INI_WriteInt(file,"AdminLevel",0); //Write an integer inside of user's account called "AdminLevel". We will set his level to 0 after he registered.
  334. INI_WriteInt(file,"VIPLevel",0);//As explained above
  335. INI_WriteInt(file,"Money",0);//Write an integer inside of user's account called "Money". We will set their money to 0 after he registered
  336. INI_WriteInt(file,"Scores",0);//Write an integer inside of user's account called "Scores". We will set their score to 0 after he registered
  337. INI_WriteInt(file,"Kills",0);//As explained above
  338. INI_WriteInt(file,"Deaths",0);//As explained above
  339. INI_Close(file);//Now after we've done saving their data, we now need to close the file
  340. SendClientMessage(playerid,-1,"You have been successfully registered");//Tell to them that they have successfully registered a new account
  341. return 1;
  342. }
  343. }
  344. if(dialogid == dlogin) //If dialog id is a login dialog
  345. {//then
  346. if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
  347. if(response) //if they clicked the first button "Register"
  348. {//then
  349. new hashpass[129]; //Will create a new variable to hash his/her password
  350. WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
  351. if(!strcmp(hashpass,pInfo[playerid][Pass])) //If they have insert their correct password
  352. {//then
  353. INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
  354. SetPlayerScore(playerid,pInfo[playerid][Scores]);//We will get their score inside of his user's account and we will set it here
  355. GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
  356. SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
  357. }
  358. else //If they've entered an incorrect password
  359. {//then
  360. ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
  361. return 1;
  362. }
  363. }
  364. }
  365. return 1;
  366. }
  367.  
  368. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  369. {
  370. return 1;
  371. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement