Advertisement
Guest User

Simple Login / Register / Joinning Msg by Oldphynix

a guest
Sep 13th, 2013
775
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.01 KB | None | 0 0
  1. #include <a_samp>
  2. #include <YSI\y_ini>
  3.  
  4.  
  5. #define COLOR_GOLD 0xB8860BAA
  6. #define dregister 2011
  7. #define dlogin 2012
  8. #define UserPath "OPUsers/%s.ini"
  9. #if defined FILTERSCRIPT
  10.  
  11. public OnFilterScriptInit()
  12. {
  13. print("\n--------------------------------------");
  14. print(" Simple Welcome + Register and Login Message by Oldphynix");
  15. print("--------------------------------------\n");
  16. return 1;
  17. }
  18.  
  19. public OnFilterScriptExit()
  20. {
  21. return 1;
  22. }
  23.  
  24. #else
  25.  
  26. main()
  27. {
  28. print("\n----------------------------------");
  29. print(" Simple Welcome + Register and Login Message by Oldphynix");
  30. print("----------------------------------\n");
  31. }
  32. //Enums
  33. enum PlayerInfo
  34. {
  35. Pass[129],
  36. Adminlevel,
  37. VIPlevel,
  38. Money,
  39. Scores,
  40. Kills,
  41. Deaths
  42. }
  43. //News
  44. new pInfo[MAX_PLAYERS][PlayerInfo];
  45. //Natives
  46. native WP_Hash(buffer[],len,const str[]);
  47. //Stocks
  48. stock Path(playerid)
  49. {
  50. new str[128],name[MAX_PLAYER_NAME];
  51. GetPlayerName(playerid,name,sizeof(name));
  52. format(str,sizeof(str),UserPath,name);
  53. return str;
  54. }
  55. //Functions
  56. forward loadaccount_user(playerid, name[], value[]);
  57.  
  58. #endif
  59. //Accounts Public
  60. public loadaccount_user(playerid, name[], value[])
  61. {
  62. INI_String("Password", pInfo[playerid][Pass],129);
  63. INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);
  64. INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);
  65. INI_Int("Money",pInfo[playerid][Money]);
  66. INI_Int("Scores",pInfo[playerid][Scores]);
  67. INI_Int("Kills",pInfo[playerid][Kills]);
  68. INI_Int("Deaths",pInfo[playerid][Deaths]);
  69. return 1;
  70. }
  71.  
  72. //Others Public
  73. public OnGameModeInit()
  74. {
  75. return 1;
  76. }
  77.  
  78. public OnGameModeExit()
  79. {
  80. return 1;
  81. }
  82.  
  83. public OnPlayerRequestClass(playerid, classid)
  84. {
  85. return 1;
  86. }
  87.  
  88. public OnPlayerConnect(playerid)
  89. {
  90. new pname[MAX_PLAYER_NAME], string[23 + MAX_PLAYER_NAME+1];
  91. GetPlayerName(playerid, pname, sizeof(pname));
  92. format(string, sizeof(string), "Player %s Has Joined the Server!", pname);
  93. SendClientMessageToAll(COLOR_GOLD, string);
  94. if(fexist(Path(playerid)))
  95. {
  96. INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
  97. ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. This Username is registered.\nPlease Enter Your Passwords to Login","Login","Quit");/*A dialog with input style will appear so you can insert your password to login.*/
  98. }
  99. else
  100. {
  101. ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome,This Username aren't Registered\nPlease Enter your passwords to register and keep it secret","Register","Quit");
  102. return 1;
  103. }
  104. return 1;
  105. }
  106.  
  107. public OnPlayerDisconnect(playerid, reason)
  108. {
  109. new
  110. szString[64],
  111. name[MAX_PLAYER_NAME];
  112. GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  113. switch(reason)
  114. {
  115. case 0: format(szString, sizeof szString, "Player %s Has Leaved The Server, Reason : Timed Out/Crashed", name);
  116. case 1: format(szString, sizeof szString, "Player %s Has Leaved The Server, Reason : Leaved", name);
  117. case 2: format(szString, sizeof szString, "Player %s Has Leaved The Server, Reason : Kicked/Banned", name);
  118. }
  119. SendClientMessageToAll(COLOR_GOLD, szString);
  120. new INI:file = INI_Open(Path(playerid));
  121. INI_SetTag(file,"Player's Data");
  122. INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]);
  123. INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);
  124. INI_WriteInt(file,"Money",GetPlayerMoney(playerid));
  125. INI_WriteInt(file,"Scores",GetPlayerScore(playerid));
  126. INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);
  127. INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);
  128. INI_Close(file);
  129. return 1;
  130. }
  131.  
  132. public OnPlayerSpawn(playerid)
  133. {
  134. return 1;
  135. }
  136.  
  137. public OnPlayerDeath(playerid, killerid, reason)
  138. {
  139. pInfo[killerid][Kills]++;
  140. pInfo[playerid][Deaths]++;
  141. return 1;
  142. }
  143.  
  144. public OnVehicleSpawn(vehicleid)
  145. {
  146. return 1;
  147. }
  148.  
  149. public OnVehicleDeath(vehicleid, killerid)
  150. {
  151. return 1;
  152. }
  153.  
  154. public OnPlayerText(playerid, text[])
  155. {
  156. return 1;
  157. }
  158.  
  159. public OnPlayerCommandText(playerid, cmdtext[])
  160. {
  161. return 1;
  162. }
  163.  
  164. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  165. {
  166. return 1;
  167. }
  168.  
  169. public OnPlayerExitVehicle(playerid, vehicleid)
  170. {
  171. return 1;
  172. }
  173.  
  174. public OnPlayerStateChange(playerid, newstate, oldstate)
  175. {
  176. return 1;
  177. }
  178.  
  179. public OnPlayerEnterCheckpoint(playerid)
  180. {
  181. return 1;
  182. }
  183.  
  184. public OnPlayerLeaveCheckpoint(playerid)
  185. {
  186. return 1;
  187. }
  188.  
  189. public OnPlayerEnterRaceCheckpoint(playerid)
  190. {
  191. return 1;
  192. }
  193.  
  194. public OnPlayerLeaveRaceCheckpoint(playerid)
  195. {
  196. return 1;
  197. }
  198.  
  199. public OnRconCommand(cmd[])
  200. {
  201. return 1;
  202. }
  203.  
  204. public OnPlayerRequestSpawn(playerid)
  205. {
  206. return 1;
  207. }
  208.  
  209. public OnObjectMoved(objectid)
  210. {
  211. return 1;
  212. }
  213.  
  214. public OnPlayerObjectMoved(playerid, objectid)
  215. {
  216. return 1;
  217. }
  218.  
  219. public OnPlayerPickUpPickup(playerid, pickupid)
  220. {
  221. return 1;
  222. }
  223.  
  224. public OnVehicleMod(playerid, vehicleid, componentid)
  225. {
  226. return 1;
  227. }
  228.  
  229. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  230. {
  231. return 1;
  232. }
  233.  
  234. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  235. {
  236. return 1;
  237. }
  238.  
  239. public OnPlayerSelectedMenuRow(playerid, row)
  240. {
  241. return 1;
  242. }
  243.  
  244. public OnPlayerExitedMenu(playerid)
  245. {
  246. return 1;
  247. }
  248.  
  249. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  250. {
  251. return 1;
  252. }
  253.  
  254. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  255. {
  256. return 1;
  257. }
  258.  
  259. public OnRconLoginAttempt(ip[], password[], success)
  260. {
  261. return 1;
  262. }
  263.  
  264. public OnPlayerUpdate(playerid)
  265. {
  266. return 1;
  267. }
  268.  
  269. public OnPlayerStreamIn(playerid, forplayerid)
  270. {
  271. return 1;
  272. }
  273.  
  274. public OnPlayerStreamOut(playerid, forplayerid)
  275. {
  276. return 1;
  277. }
  278.  
  279. public OnVehicleStreamIn(vehicleid, forplayerid)
  280. {
  281. return 1;
  282. }
  283.  
  284. public OnVehicleStreamOut(vehicleid, forplayerid)
  285. {
  286. return 1;
  287. }
  288.  
  289. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  290. {
  291. if(dialogid == dregister)
  292. {
  293. if(!response) return Kick(playerid);
  294. if(response)
  295. {
  296. if(!strlen(inputtext))
  297. {
  298. ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome,This Username aren't Registered\nPlease Enter your passwords to register and keep it secret\nPlease enter the password!","Register","Quit");
  299. return 1;
  300. }
  301. new hashpass[129];
  302. WP_Hash(hashpass,sizeof(hashpass),inputtext);
  303. new INI:file = INI_Open(Path(playerid));
  304. INI_SetTag(file,"Player's Data");
  305. INI_WriteString(file,"Password",hashpass);
  306. INI_WriteInt(file,"AdminLevel",0);
  307. INI_WriteInt(file,"VIPLevel",0);
  308. INI_WriteInt(file,"Money",25000);
  309. INI_WriteInt(file,"Scores",2);
  310. INI_WriteInt(file,"Kills",0);
  311. INI_WriteInt(file,"Deaths",0);
  312. INI_Close(file);
  313. SendClientMessage(playerid,-1,"You Have been Registered , Welcome ! You get 2 Scores and 25000 Money from register");
  314. return 1;
  315. }
  316. }
  317. if(dialogid == dlogin)
  318. {
  319. if(!response) return Kick(playerid);
  320. if(response)
  321. {
  322. new hashpass[129];
  323. WP_Hash(hashpass,sizeof(hashpass),inputtext);
  324. if(!strcmp(hashpass, pInfo[playerid][Pass], false))
  325. {
  326. INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);
  327. SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");
  328. }
  329. else
  330. {
  331. ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. This Username is registered.\nPlease Enter Your Passwords to Login\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
  332. return 1;
  333. }
  334. }
  335. }
  336. return 1;
  337. }
  338. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  339. {
  340. return 1;
  341. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement