Guest User

Untitled

a guest
Oct 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.72 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3. #include <sscanf>
  4. #include <YSI\y_ini>
  5. #include <foreach>
  6.  
  7. /* We now have this at the top of our gamemode, an #include is basically a DIRECTIVE which inserts code from a specified file and puts it into whatever you have put the #include line in, so:
  8.  
  9. #include <zcmd> is including the code from the zcmd.inc file located in your Pawno/include file
  10.  
  11. Includes are important so remember them
  12.  
  13.  
  14. Okay, so now we need to use some defines so that we can get our script running
  15. */
  16.  
  17. #define COLOR_BLUE 0x0000FFAA
  18. #define COLOR_GREY 0xAFAFAFAA
  19. #define COLOR_GREEN 0x33AA33AA
  20. #define COLOR_YELLOW 0xFFFF00AA
  21. #define COLOR_WHITE 0xFFFFFFAA
  22. #define PATH "/Users/%s.ini" // Very important line
  23.  
  24. /* These are our colours, so when you send a client message or a string or whatever, you can simply type: SendClientMessage(playerid, COLOR_BLUE, "Hello."); and it will send it the colour blue, and vice versa for whatever colour you want to send. */
  25.  
  26. #define DIALOG_REGISTER 1
  27. #define DIALOG_LOGIN 2
  28. #define DIALOG_SUCCESS_1 3
  29. #define DIALOG_SUCCESS_2 4
  30.  
  31. // These defines are what we are going to be using for allowing our players to register and login to our server so that we can save all of the information.
  32.  
  33. enum pInfo // <---------- Here
  34. { // Opening the brackets to show that we are including our array tags
  35.     pPass,
  36.     pAdmin,
  37.     pSkin,
  38.     pLevel,
  39.     pMoney,
  40.     pEXP
  41. }
  42. new
  43.     PlayerInfo[MAX_PLAYERS][pInfo]; // pInfo is the name for all of our arrays which is HERE
  44.  
  45. //////// STOCKS ////////
  46. /* Okay, we don't need that stock, but we do need this very important stock: */
  47.  
  48. stock UserPath(playerid)
  49. {
  50.     new
  51.         string[128],
  52.         playername[MAX_PLAYER_NAME];
  53.  
  54.     GetPlayerName(playerid, playername, sizeof(playername));
  55.     format(string, sizeof(string), PATH, playername);
  56.     return string;
  57. }
  58.  
  59. /* Okay, now we need yet another stock which will allow for passwords to be hidden and make them safe and secure from hackers. If you ever want to reset a password, you go to Users/Playername and then just change the password line, simpleeessssss. Okay, so copy and paste this - this is very complicated */
  60.  
  61. stock udb_hash(buf[])
  62. {
  63.     new length=strlen(buf);
  64.     new s1 = 1;
  65.     new s2 = 0;
  66.     new n;
  67.     for (n=0; n<length; n++)
  68.     {
  69.         s1 = (s1 + buf[n]) % 65521;
  70.         s2 = (s2 + s1)     % 65521;
  71.     }
  72.     return (s2 << 16) + s1;
  73. }
  74.  
  75. //////// FUNCTIONS ////////
  76.  
  77. forward LoadUser_data(playerid,name[],value[]);
  78. public LoadUser_data(playerid,name[],value[])
  79. {
  80.  
  81.     INI_Int("Password",PlayerInfo[playerid][pPass]);
  82.     INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
  83.     INI_Int("Level",PlayerInfo[playerid][pLevel]);
  84.     INI_Int("Skin",PlayerInfo[playerid][pSkin]);
  85.     INI_Int("Money",PlayerInfo[playerid][pMoney]);
  86.     INI_Int("Experience",PlayerInfo[playerid][pEXP]);
  87.     return 1;
  88. }
  89.  
  90. // Okay, so now we are LOADING all of this information from our Arrays. We have also given each of our arrays nice little names, good eh? So, inside the document we will have all of that but you will only see what is in the speechmarks, and whatever the data is.
  91.  
  92. main() {}
  93.  
  94. public OnGameModeInit()
  95. {
  96.     return 1;
  97. }
  98.  
  99. public OnGameModeExit()
  100. {
  101.     return 1;
  102. }
  103.  
  104. public OnPlayerRequestClass(playerid, classid)
  105. {
  106.     SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  107.     SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  108.     SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  109.     return 1;
  110. }
  111.  
  112. public OnPlayerConnect(playerid)
  113. {
  114.     // We want it so when a player hasn't connected to the server, we want there name to be a colour
  115.     SetPlayerColor(playerid, COLOR_GREY);
  116.     // You might not have COLOR_GREY at the top, if not, add this: #define COLOR_GREY 0xAFAFAFAA
  117.  
  118.     // Now we want to check if a player actually fucking exists, so lets use file exist (fexist)
  119.     if(fexist(UserPath(playerid)))
  120.     {
  121.         INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  122.         // This line is a little more complicated, only reason I am not going into detail is because
  123.         // You will most likely not use INI again if you get a mySQL database, I will help you later with
  124.         ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Type your password below", "Login", "Quit"); // Put this all on line in your pawn file
  125.     }
  126.     else
  127.     {
  128.         ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registering...", "Type your password below to register a new account", "Register", "Quit");
  129.     }
  130.     return 1;
  131. }
  132.  
  133. public OnPlayerDisconnect(playerid, reason)
  134. {
  135.     new
  136.         playername[MAX_PLAYER_NAME]; // This is where we will store the players name
  137.  
  138.     GetPlayerName(playerid, playername, sizeof(playername)); // This is us obtaining the players name
  139.  
  140.     new
  141.         date1, // Year
  142.         date2, // Month
  143.         date3; // Day
  144.  
  145.     getdate(date3, date2, date1); // Putting the date together backwards so it's day/month/year
  146.  
  147.     new
  148.         INI:File = INI_Open(UserPath(playerid)); // Opening the file of the player who has quit.
  149.  
  150.     INI_SetTag(File, "Player Information"); // This will be at the top of each players info
  151.     // So let's copy and paste what we had originally to speed this shit up
  152.     INI_WriteInt(File, "Admin",PlayerInfo[playerid][pAdmin]);
  153.     INI_WriteInt(File, "Level",PlayerInfo[playerid][pLevel]);
  154.     INI_WriteInt(File, "Skin",PlayerInfo[playerid][pSkin]);
  155.     INI_WriteInt(File, "Money",PlayerInfo[playerid][pMoney]);
  156.     INI_WriteInt(File, "Experience",PlayerInfo[playerid][pEXP]);
  157.     // Now, what we're doing here is updating all of the information and writing it into the file
  158.     // So now that the player has left the server, we have updated his skin and shit like that
  159.     INI_Close(File); // Closing the file because we are done with it
  160.  
  161.     printf("[ %s ] has disconnected from the server on [ %d / %d / %d]", playername, date1, date2, date3);
  162.     // This is us just making a log to show when a player leaves, just for safety purposes
  163.     return 1;
  164. }
  165.  
  166. public OnPlayerSpawn(playerid)
  167. {
  168.     new playername[MAX_PLAYER_NAME];
  169.     GetPlayerName(playerid, playername, sizeof(playername));
  170.     printf("[ %s ] has spawned", playername);
  171.     return 1;
  172. }
  173.  
  174. public OnPlayerDeath(playerid, killerid, reason)
  175. {
  176.     return 1;
  177. }
  178.  
  179. public OnVehicleSpawn(vehicleid)
  180. {
  181.     return 1;
  182. }
  183.  
  184. public OnVehicleDeath(vehicleid, killerid)
  185. {
  186.     return 1;
  187. }
  188.  
  189. public OnPlayerText(playerid, text[])
  190. {
  191.     return 1;
  192. }
  193.  
  194. public OnPlayerCommandText(playerid, cmdtext[])
  195. {
  196.     return 1;
  197. }
  198.  
  199. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  200. {
  201.     return 1;
  202. }
  203.  
  204. public OnPlayerExitVehicle(playerid, vehicleid)
  205. {
  206.     return 1;
  207. }
  208.  
  209. public OnPlayerStateChange(playerid, newstate, oldstate)
  210. {
  211.     return 1;
  212. }
  213.  
  214. public OnPlayerEnterCheckpoint(playerid)
  215. {
  216.     return 1;
  217. }
  218.  
  219. public OnPlayerLeaveCheckpoint(playerid)
  220. {
  221.     return 1;
  222. }
  223.  
  224. public OnPlayerEnterRaceCheckpoint(playerid)
  225. {
  226.     return 1;
  227. }
  228.  
  229. public OnPlayerLeaveRaceCheckpoint(playerid)
  230. {
  231.     return 1;
  232. }
  233.  
  234. public OnRconCommand(cmd[])
  235. {
  236.     return 1;
  237. }
  238.  
  239. public OnPlayerRequestSpawn(playerid)
  240. {
  241.     return 1;
  242. }
  243.  
  244. public OnObjectMoved(objectid)
  245. {
  246.     return 1;
  247. }
  248.  
  249. public OnPlayerObjectMoved(playerid, objectid)
  250. {
  251.     return 1;
  252. }
  253.  
  254. public OnPlayerPickUpPickup(playerid, pickupid)
  255. {
  256.     return 1;
  257. }
  258.  
  259. public OnVehicleMod(playerid, vehicleid, componentid)
  260. {
  261.     return 1;
  262. }
  263.  
  264. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  265. {
  266.     return 1;
  267. }
  268.  
  269. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  270. {
  271.     return 1;
  272. }
  273.  
  274. public OnPlayerSelectedMenuRow(playerid, row)
  275. {
  276.     return 1;
  277. }
  278.  
  279. public OnPlayerExitedMenu(playerid)
  280. {
  281.     return 1;
  282. }
  283.  
  284. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  285. {
  286.     return 1;
  287. }
  288.  
  289. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  290. {
  291.     return 1;
  292. }
  293.  
  294. public OnRconLoginAttempt(ip[], password[], success)
  295. {
  296.     return 1;
  297. }
  298.  
  299. public OnPlayerUpdate(playerid)
  300. {
  301.     return 1;
  302. }
  303.  
  304. public OnPlayerStreamIn(playerid, forplayerid)
  305. {
  306.     return 1;
  307. }
  308.  
  309. public OnPlayerStreamOut(playerid, forplayerid)
  310. {
  311.     return 1;
  312. }
  313.  
  314. public OnVehicleStreamIn(vehicleid, forplayerid)
  315. {
  316.     return 1;
  317. }
  318.  
  319. public OnVehicleStreamOut(vehicleid, forplayerid)
  320. {
  321.     return 1;
  322. }
  323.  
  324.  
  325. // Okay, because in the public we can have multiple dialogs, we want to switch dialogid
  326.  
  327. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  328. {
  329.     switch( dialogid ) // The spaces aren't needed, but it looks neater
  330.     {
  331.         case DIALOG_REGISTER: // Now we're sayin, if the dialogid is dialog_register, do this:
  332.         {
  333.             if(!response) return Kick(playerid);
  334.             // ! basically means the opposite, so if there is no response, we kick the player for taking too long
  335.             if(response) // If they do respond by moving the mouse or typing something
  336.             {
  337.                 if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Registering...","Type your password below to register a new account.","Register","Quit");
  338.                 // Basically, if the length of the password is too short, we send them the dialog again
  339.                 new
  340.                     INI:File = INI_Open(UserPath(playerid));
  341.                     // We are opening a new file for the player who registers, so they are registered
  342.  
  343.                 INI_SetTag(File, "Information"); // Title inside the file, rename this to whatever
  344.                 INI_WriteInt(File,"Password",udb_hash(inputtext)); // Adding the HASHED password
  345.                 INI_WriteInt(File,"Admin",0); // Setting their admin to 0
  346.                 INI_WriteInt(File,"Level",0); // Setting their level 0
  347.                 INI_WriteInt(File,"Skin",0); // Setting their skin to 0
  348.                 INI_WriteInt(File,"Money",0); // Setting their money to 0
  349.                 INI_WriteInt(File,"Experience",0); // Setting their EXP to 0
  350.  
  351.                 //Okay, so now we want to spawn the player ignore this will explain later
  352.                 SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 296.15, 0, 0, 0, 0, 0, 0);
  353.                 SpawnPlayer(playerid);
  354.  
  355.                 // Okay, now the player is registered and he is on the server all fine
  356.              }
  357.          }
  358.  
  359.  
  360.          case DIALOG_LOGIN:
  361.          {
  362.              // SAme process
  363.              if(!response) return Kick(playerid); // Get rid of the idle player
  364.              if(response)
  365.              {
  366.                  if(udb_hash(inputtext) == PlayerInfo[playerid][pPass]) // If the password enters matches pass
  367.                  {
  368.                      INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  369.                      // Opening and loading the data for the player
  370.                      GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
  371.                      // Giving him his cash which is in his file
  372.                      SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
  373.                      // Giving him the skin
  374.                      ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX, "Success!", "You have logged in!", "Ok", "");
  375.                      // Telling him he is successful and giving him ONE button
  376.                  }
  377.                  else //If the password does not match in the file, tell him to login again
  378.                  {
  379.                      ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "You have entered a bad password", "Login", "Quit");
  380.                  }
  381.                  return 1;
  382.             }
  383.         }
  384.     }
  385.     return 1;
  386. }
  387.  
  388.  
  389. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  390. {
  391.     return 1;
  392. }
Add Comment
Please, Sign In to add comment