SA-MP Forums Archive
Only Two? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Only Two? (/showthread.php?tid=66344)



Only Two? - Paladin - 21.02.2009

Hey, I created a login and register script using pStats etc... now I went to test today with my team and I realised that only two people can login/register, I have no idea why, if ID 0 and 1 are taken, and ID 2 joins and types /register <pass> it doesnt say anything, if he tries /login <pass> it says 'please login'

(Note this code was not stolen it was created by the Lethotas scripting team and remains property of the Lethotas Scripting team)

Register
Код:
	if (strcmp(cmd, "/register", true) == 0)
 	{
 		if(IsPlayerConnected(playerid))
 		{
			if(pInfo[playerid][pLoggedin] == 1) {
				SendClientMessage(playerid,COLOR_LIGHTGREEN,"SERVER: You are already logged in.");
				return 1;
			}
			
			new File: hFile = fopen(pFilename[playerid], io_read);
			if(hFile)
			{
				SendClientMessage(playerid,COLOR_LIGHTGREEN,"SERVER: That name is already registered, try another one");
				Kick(playerid);
				return 1;
			}
			
			tmp = strtok(cmdtext, idx);
      if(!strlen(tmp)){
		 		SendClientMessage(playerid, COLOR_LIGHTGREEN, "USAGE: /REGISTER [PASSWORD]");
				return 1;
			}

			new File: account = fopen(pFilename[playerid], io_write);
			if (account) {
			strmid(pInfo[playerid][pPassword], tmp, 0, strlen(tmp), 255);
			new file[128];
			{
					format(file, sizeof file, "Password: %s\n\r", pInfo[playerid][pPassword]);
					{	fwrite(account, file); }
					format(file, sizeof file, "AdminLevel: %d\n\r",pInfo[playerid][pAdmin]);
					{	fwrite(account, file); }
					format(file, sizeof file, "Needs Greeter Help: %d\n\r",pInfo[playerid][pHelp]);
					{	fwrite(account, file); }
 					format(file, sizeof file, "Greeter Duty: %d\n\r",pInfo[playerid][pGduty]);
					{	fwrite(account, file); }
					format(file, sizeof file, "Greeter: %d\n\r",pInfo[playerid][pGreeter]);
					{	fwrite(account, file); }
					format(file, sizeof file, "Cash: %d\n\r", pInfo[playerid][pCash]);
					{	fwrite(account, file); }
					format(file, sizeof file, "Cop Rank: %d\n\r", pInfo[playerid][pCop]);
					{	fwrite(account, file); }
					format(file, sizeof file, "Medic rank: %d\n\r", pInfo[playerid][pMedic]);
					{	fwrite(account, file); }
					format(file, sizeof file, "Agent Rank: %d\n\r", pInfo[playerid][pAgent]);
					{	fwrite(account, file); }
					format(file, sizeof file, "Presidential Security: %d\n\r", pInfo[playerid][pPS]);
					{	fwrite(account, file); }
					format(file, sizeof file, "On Duty: %d\n\r", pInfo[playerid][pDuty]);
					{	fwrite(account, file); }
 					format(file, sizeof file, "Jailed: %d\n\r", pInfo[playerid][pJail]);
					{	fwrite(account, file); }
     			format(file, sizeof file, "Drivers License: %d\n\r", pInfo[playerid][pLicense]);
					{	fwrite(account, file); }
       		format(file, sizeof file, "Passport: %d\n\r", pInfo[playerid][pPassport]);
					{	fwrite(account, file); }
      		format(file, sizeof file, "Muted: %d\n\r", pInfo[playerid][pMute]);
					{	fwrite(account, file); }
      		format(file, sizeof file, "Skin: %d\n\r", pInfo[playerid][pSkin]);
					{	fwrite(account, file); }
      		format(file, sizeof file, "Duty Skin: %d\n\r", pInfo[playerid][pDutySkin]);
					{	fwrite(account, file); }
      		format(file, sizeof file, "Wanted: %d\n\r", pInfo[playerid][pWanted]);
					{	fwrite(account, file); }
      		format(file, sizeof file, "Car: %d\n\r", pInfo[playerid][pCar]);
					{	fwrite(account, file); }
      		format(file, sizeof file, "Car Locked/Unlocked: %d\n\r", pInfo[playerid][pCarLocked]);
					{	fwrite(account, file); }
			}
			fclose(account);
			SendClientMessage(playerid,COLOR_LIGHTGREEN,"SERVER: Your account has been successfully registered");
			SendClientMessage(playerid,COLOR_LIGHTGREEN,"SERVER: You have been auto logged in");
			pInfo[playerid][pLoggedin] = 1;
			SpawnPlayer(playerid);
			SetPlayerSkin(playerid, 259);
			TogglePlayerControllable(playerid, true);
			}
			
			return 1;
 		}
	}
Login:
Код:
	if (strcmp(cmd, "/login",true) == 0)
	{
	  if(pInfo[playerid][pLoggedin] == 1) // If player is already logged in.
	  {
	  SendClientMessage(playerid,COLOR_LIGHTGREEN,"SERVER: You are already logged in!");
	  return 1;
	  }
		tmp = strtok(cmdtext, idx); // Retrieves the second argument of /LOGIN and stores it in tmp
		if(!strlen(tmp)) // If only /LOGIN is typed without a password
		{
		SendClientMessage(playerid, COLOR_LIGHTGREEN, "USAGE: /LOGIN [PASSWORD]");
		return 1;
		}
		if(!fexist(pFilename[playerid])) // If the account is not yet registered.
		{
		SendClientMessage(playerid, COLOR_LIGHTGREEN, "SERVER: That account is not yet registered, please use /REGISTER [PASSWORD]");
		return 1;
		}
		new File:account = fopen(pFilename, io_read);
		
		if (account)
		{
	  	new pass[256];
	  	new passres[128], value[128];
	  	fread(account, pass, sizeof pass);
	  	passres = GetFileString(pass);
	  	if (!strcmp("Password", passres))
			{
				value = GetFileValue(pass);
				strmid(pInfo[playerid][pPassword], value, 0, strlen(value)-1, 128);
			}
			
			if (!strcmp(pInfo[playerid][pPassword], tmp, true))
			{
		  	while (fread(account, pass, 256))
				{
					passres = GetFileString(pass);
					if (strfind(passres, "AdminLevel") != -1) // Retrieves the admin level
					{
						value = GetFileValue(pass);
						pInfo[playerid][pAdmin] = strval(value);
					}
					if (strfind(passres, "Cash") != -1) // Retrieves the stored cash amount
					{
						value = GetFileValue(pass);
						pInfo[playerid][pCash] = strval(value);
					}
				}
				fclose(account);
 				pInfo[playerid][pLoggedin] = 1;
			} else {
				SendClientMessage(playerid, COLOR_LIGHTGREEN, "SERVER: Incorrect Password.");
	    	fclose(account);
	    	return 1;
			}
			GivePlayerMoney(playerid, pInfo[playerid][pCash]);
			format(str, sizeof str, "SERVER: You are now logged in!");
			SendClientMessage(playerid, COLOR_LIGHTGREEN, str);
			TogglePlayerControllable(playerid, true);
			SpawnPlayer(playerid);
			SetPlayerSkin(playerid, pInfo[playerid][pSkin]);
 			if (pInfo[playerid][pAdmin] > 0)
			{
    		format(str, sizeof str, "SERVER: You logged in as a level %d admin!", pInfo[playerid][pAdmin]);
				SendClientMessage(playerid, COLOR_YELLOW, str);
			}
			new string[128];
			new tmpname[128];
			if(pInfo[playerid][pJail] == 1)
			{
		 	SetPlayerPos(playerid, 1950.3784,-4959.1797,1.3590);
		 	TogglePlayerControllable(playerid, false);
		 	SendClientMessage(playerid, COLOR_LIGHTRED, "You logged in and were jailed!");
			format(string, sizeof(string), "[A] %s(%d) has logged in and was jailed", tmpname, playerid);
			SendClientMessageToAdmins(COLOR_YELLOW, string, 1);
		}
 		} else {
			SendClientMessage(playerid, COLOR_LIGHTGREEN, "SERVER: That account is not yet registered, please use /REGISTER [PASSWORD]");
			return 1;
		}
	}
Pastebin link: http://pastebin.com/dfe2771d

- Paladin


Re: Only Two? - Joe Staff - 21.02.2009

Close files when you're done with them...
pawn Код:
fclose(File:handle);



Re: Only Two? - Paladin - 21.02.2009

Quote:
Originally Posted by SilentHuntR
Close files when you're done with them...
pawn Код:
fclose(File:handle);
I didn't make a 'handle' ... and where must I put that anyway, I'm sure that I closed all of it off!


Re: Only Two? - Daren_Jacobson - 21.02.2009

go into a_samp.inc and look for #define MAX_PLAYERS and make sure it is at 200 (or however many slots your server has)


Re: Only Two? - Paladin - 21.02.2009

Quote:
Originally Posted by Daren_Jacobson
go into a_samp.inc and look for #define MAX_PLAYERS and make sure it is at 200 (or however many slots your server has)
It's definitely not that, since only two commands stop working in my entire script...


Re: Only Two? - Paladin - 22.02.2009

I bumped this topic because I haven't gotten any help and I really need it...