Lots of bugs with Register/Login...
#1

Hey... I tried to make this register/login system from a tutorial, did exact same things but it won't work.
Here are both commands.

Код:
//====[INCLUDES]====//
#include <a_samp>
#include <sscanf2>
#include <zcmd>
#include <strtok>
#include <sii>

//===[ACCOUNTS]===//
enum PlayerInfo
{
	Logged,
 	Level,
}

//=====[NEW]=====//
new PInfo[MAX_PLAYERS][PlayerInfo];
Код:
public OnPlayerConnect(playerid)
{
	new file[64],
	    PlayerName[25];
	    
	GetPlayerName(playerid,PlayerName,sizeof PlayerName);
	format(file,sizeof file,"Admin/%s.ini",PlayerName);
	if(!fexist(file))
	{
		SendClientMessage(playerid, COLOR_ERROR, "[ERROR] You aren't registered! Use /register <password>!");
	}
	else
	{
		SendClientMessage(playerid, COLOR_ERROR, "[ERROR] You are registered! Use /login <password>!");
	}
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    PInfo[playerid][Logged] = 0;
    return 1;
}
Код:
CMD:register(playerid, params[])
{
	if(PInfo[playerid][Logged] == 1) return SendClientMessage(playerid, COLOR_ERROR, "[ERROR] You are already logged in!");

	new password[23];

	if(sscanf(params,"s[23]",password)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /register <password>");

	new file[64],
		PlayerName[24];

	GetPlayerName(playerid,PlayerName,sizeof PlayerName);
	format(file,sizeof file,"Admin/%s.ini",PlayerName);
	if(fexist(file)) return SendClientMessage(playerid, COLOR_ERROR, "[ERROR] Somehow you're already registered!");

	INI_Open(file);
	INI_WriteString("Password",password);
	INI_WriteInt("Level",PInfo[playerid][Level]);
	INI_Save();
	INI_Close();

	SendClientMessage(playerid, COLOR_ACHIEVEMENT, "[REGISTER] You have successfully registered!");
	PInfo[playerid][Logged] = 1;
	return 1;
}


CMD:login(playerid, params[])
{
	if(PInfo[playerid][Logged] == 1) return SendClientMessage(playerid, COLOR_ERROR, "[ERROR] You are already logged in!");

	new password[23],
		password2[23];

	if(sscanf(params,"s[23]",password)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /login <password>");

	new file[64],
		PlayerName[24];

	GetPlayerName(playerid,PlayerName,sizeof PlayerName);
	format(file,sizeof file,"Admin/%s.ini",PlayerName);

	if(!fexist(file)) return SendClientMessage(playerid, 0xFFFFFFFF, "[ERROR] You aren't registered! Use /register!");
	INI_Open(file);
	INI_ReadString(password2,"Password");

	if(strcmp(password,password2) != 0) return SendClientMessage(playerid, COLOR_ERROR,"[ERROR] Wrong password! Try again!"),
	INI_Close();
	
	PInfo[playerid][Level] = INI_ReadInt("Level");
	INI_Close();

	SendClientMessage(playerid, COLOR_ACHIEVEMENT, "[LOGIN] You have succefully logged in!");
	PInfo[playerid][Logged] = 1;
	return 1;
}
The problem is that I get errors like "USAGE:" when I actually type the correct thing, or when I somehow manage to register it tells me that I am not, or if I try to login it will tell me that I am already logged in.. many other things I guess... I didn't know how to fix these so I would really need some help on them, if you can please help me.
Thank you very much!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)