Advertisement
Guest User

(GUITAR) Making a registration system - Using "Y_INI + Whirl

a guest
Sep 10th, 2012
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.45 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>
  7.  
  8. native WP_Hash(buffer[], len, const str[]);
  9.  
  10. //DIALOG DEFINITIONS
  11. #define DIALOG_REGISTER 1
  12. #define DIALOG_LOGIN 2
  13. #define DIALOG_SUCCESS_1 3
  14. #define DIALOG_SUCCESS_2 4
  15.  
  16. //Saving path definition
  17. #define PATH "/Players/%s.ini"
  18.  
  19. //Colors
  20. #define COL_WHITE "{FFFFFF}"
  21. #define COL_RED "{F81414}"
  22. #define COL_GREEN "{00FF22}"
  23. #define COL_LIGHTBLUE "{00CED1}"
  24.  
  25. main()
  26. {
  27.     print("\n----------------------------------");
  28.     print(" Registration System is loaded 100% :P");
  29.     print("----------------------------------\n");
  30. }
  31.  
  32. enum pInfo
  33. {
  34.     pPass[129],
  35.     pCash,
  36.     pAdmin,
  37.     pKills,
  38.     pDeaths
  39. }
  40. new PlayerInfo[MAX_PLAYERS][pInfo];
  41.  
  42. forward LoadUser_data(playerid,name[],value[]);
  43. public LoadUser_data(playerid,name[],value[])
  44. {
  45.     INI_String("Password",PlayerInfo[playerid][pPass], 129);
  46.     INI_Int("Cash",PlayerInfo[playerid][pCash]);
  47.     INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
  48.     INI_Int("Kills",PlayerInfo[playerid][pKills]);
  49.     INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
  50.     return 1;
  51. }
  52.  
  53. stock UserPath(playerid)
  54. {
  55.     new string[128],playername[MAX_PLAYER_NAME];
  56.     GetPlayerName(playerid,playername,sizeof(playername));
  57.     format(string,sizeof(string),PATH,playername);
  58.     return string;
  59. }
  60.  
  61. public OnGameModeInit()
  62. {
  63.     // Don't use these lines if it's a filterscript
  64.     SetGameModeText("Blank Script");
  65.     AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  66.     return 1;
  67. }
  68.  
  69. public OnGameModeExit()
  70. {
  71.     return 1;
  72. }
  73.  
  74. public OnPlayerRequestClass(playerid, classid)
  75. {
  76.     SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  77.     SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  78.     SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  79.     return 1;
  80. }
  81.  
  82. public OnPlayerConnect(playerid)
  83. {
  84.     if(fexist(UserPath(playerid)))
  85.     {
  86.         INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
  87.         ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
  88.     }
  89.     else
  90.     {
  91.         ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
  92.     }
  93.     return 1;
  94. }
  95.  
  96. public OnPlayerDisconnect(playerid, reason)
  97. {
  98.     new INI:File = INI_Open(UserPath(playerid));
  99.     INI_SetTag(File,"PlayerData");
  100.     INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
  101.     INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
  102.     INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
  103.     INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
  104.     INI_Close(File);
  105.     return 1;
  106. }
  107.  
  108. public OnPlayerSpawn(playerid)
  109. {
  110.     return 1;
  111. }
  112.  
  113. public OnPlayerDeath(playerid, killerid, reason)
  114. {
  115.     PlayerInfo[killerid][pKills]++;
  116.     PlayerInfo[playerid][pDeaths]++;
  117.     return 1;
  118. }
  119.  
  120. public OnVehicleSpawn(vehicleid)
  121. {
  122.     return 1;
  123. }
  124.  
  125. public OnVehicleDeath(vehicleid, killerid)
  126. {
  127.     return 1;
  128. }
  129.  
  130. public OnPlayerText(playerid, text[])
  131. {
  132.     return 1;
  133. }
  134.  
  135. public OnPlayerCommandText(playerid, cmdtext[])
  136. {
  137.     if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  138.     {
  139.         // Do something here
  140.         return 1;
  141.     }
  142.     return 0;
  143. }
  144.  
  145. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  146. {
  147.     return 1;
  148. }
  149.  
  150. public OnPlayerExitVehicle(playerid, vehicleid)
  151. {
  152.     return 1;
  153. }
  154.  
  155. public OnPlayerStateChange(playerid, newstate, oldstate)
  156. {
  157.     return 1;
  158. }
  159.  
  160. public OnPlayerEnterCheckpoint(playerid)
  161. {
  162.     return 1;
  163. }
  164.  
  165. public OnPlayerLeaveCheckpoint(playerid)
  166. {
  167.     return 1;
  168. }
  169.  
  170. public OnPlayerEnterRaceCheckpoint(playerid)
  171. {
  172.     return 1;
  173. }
  174.  
  175. public OnPlayerLeaveRaceCheckpoint(playerid)
  176. {
  177.     return 1;
  178. }
  179.  
  180. public OnRconCommand(cmd[])
  181. {
  182.     return 1;
  183. }
  184.  
  185. public OnPlayerRequestSpawn(playerid)
  186. {
  187.     return 1;
  188. }
  189.  
  190. public OnObjectMoved(objectid)
  191. {
  192.     return 1;
  193. }
  194.  
  195. public OnPlayerObjectMoved(playerid, objectid)
  196. {
  197.     return 1;
  198. }
  199.  
  200. public OnPlayerPickUpPickup(playerid, pickupid)
  201. {
  202.     return 1;
  203. }
  204.  
  205. public OnVehicleMod(playerid, vehicleid, componentid)
  206. {
  207.     return 1;
  208. }
  209.  
  210. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  211. {
  212.     return 1;
  213. }
  214.  
  215. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  216. {
  217.     return 1;
  218. }
  219.  
  220. public OnPlayerSelectedMenuRow(playerid, row)
  221. {
  222.     return 1;
  223. }
  224.  
  225. public OnPlayerExitedMenu(playerid)
  226. {
  227.     return 1;
  228. }
  229.  
  230. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  231. {
  232.     return 1;
  233. }
  234.  
  235. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  236. {
  237.     return 1;
  238. }
  239.  
  240. public OnRconLoginAttempt(ip[], password[], success)
  241. {
  242.     return 1;
  243. }
  244.  
  245. public OnPlayerUpdate(playerid)
  246. {
  247.     return 1;
  248. }
  249.  
  250. public OnPlayerStreamIn(playerid, forplayerid)
  251. {
  252.     return 1;
  253. }
  254.  
  255. public OnPlayerStreamOut(playerid, forplayerid)
  256. {
  257.     return 1;
  258. }
  259.  
  260. public OnVehicleStreamIn(vehicleid, forplayerid)
  261. {
  262.     return 1;
  263. }
  264.  
  265. public OnVehicleStreamOut(vehicleid, forplayerid)
  266. {
  267.     return 1;
  268. }
  269.  
  270. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  271. {
  272.     switch( dialogid )
  273.     {
  274.         case DIALOG_REGISTER:
  275.         {
  276.             if (!response) return Kick(playerid);
  277.             if(response)
  278.             {
  279.                 if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, ""COL_WHITE"Making your account ..",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
  280.                 new INI:File = INI_Open(UserPath(playerid));
  281.                 INI_SetTag(File,"PlayerData");
  282.                 new HashPass[129];
  283.                 WP_Hash(HashPass, sizeof(HashPass), inputtext);
  284.                 INI_WriteString(File, "Password", HashPass);
  285.                 INI_WriteInt(File,"Cash",0);
  286.                 INI_WriteInt(File,"Admin",-1);
  287.                 INI_WriteInt(File,"Kills",0);
  288.                 INI_WriteInt(File,"Deaths",0);
  289.                 INI_Close(File);
  290.                
  291.                 SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
  292.                 ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Account created!",""COL_GREEN"You've created an account successfuly. Relogging is recommended.","Ok","");
  293.             }
  294.         }
  295.  
  296.         case DIALOG_LOGIN:
  297.         {
  298.             if ( !response ) return Kick ( playerid );
  299.             if( response )
  300.             {
  301.                 new HashPass[129];
  302.                 WP_Hash(HashPass, sizeof(HashPass), inputtext);
  303.                 if(strcmp(HashPass, PlayerInfo[playerid][pPass]) == 0)
  304.                 {
  305.                     INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
  306.                     GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
  307.                     ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
  308.                 }
  309.                 else
  310.                 {
  311.                     ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
  312.                 }
  313.                 return 1;
  314.             }
  315.         }
  316.     }
  317.     return 1;
  318. }
  319.  
  320. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  321. {
  322.     return 1;
  323. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement