Advertisement
Guest User

Login & Register system by Navroopsingh

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