22.01.2014, 23:33
Hello so i made a register system but i noticed when i go to my user file it shows everything in zero even the password when i set myself admin through ini file it dosent save it
here is my code:
here is my code:
pawn Код:
enum PlayerInfo
{
pPass[129],
pCash,
pScore,
pAdmin,
pKills,
pDeaths,
Last,
NoPM
}
new pInfo[MAX_PLAYERS][PlayerInfo];
pawn Код:
native WP_Hash(buffer[],len,const str[]);
forward loadaccount_user(playerid, name[], value[]);
public loadaccount_user(playerid, name[], value[])
{
INI_String("Password", pInfo[playerid][pPass],129);
INI_Int("Cash",pInfo[playerid][pCash]);
INI_Int("Score",pInfo[playerid][pScore]);
INI_Int("Admin",pInfo[playerid][pAdmin]);
INI_Int("Kills",pInfo[playerid][pKills]);
INI_Int("Deaths",pInfo[playerid][pDeaths]);
return 1;
}
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
new pname[MAX_PLAYER_NAME], string[39 + MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
switch(reason)
{
case 0: format(string, sizeof(string), "{FEFEFE}%s has left the server. (Lost Connection)", pname);
case 1: format(string, sizeof(string), "{FEFEFE}%s has left the server. (Leaving)", pname);
case 2: format(string, sizeof(string), "{FEFEFE}%s has left the server. (Kicked)", pname);
}
SendClientMessageToAll(0xAAAAAAAA, string);
new INI:file = INI_Open(Path(playerid));
INI_SetTag(file,"data");
INI_WriteInt(file,"Password",pInfo[playerid][pPass]);
INI_WriteInt(file,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(file,"Score",GetPlayerScore(playerid));
INI_WriteInt(file,"Admin",pInfo[playerid][pAdmin]);
INI_WriteInt(file,"Kills",pInfo[playerid][pKills]);
INI_WriteInt(file,"Deaths",pInfo[playerid][pDeaths]);
INI_Close(file);
pInfo[playerid][Last] = -1;
pInfo[playerid][NoPM] = 0;
return 1;
}
pawn Код:
if(dialogid == dregister) //If dialog id is a register dialog
{//then
if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
if(response) //if they clicked the first button "Register"
{//then
if(!strlen(inputtext)) //If they didn't enter any password
{// then we will tell to them to enter the password to register
ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
return 1;
}
//If they have entered a correct password for his/her account...
new hashpass[129]; //Now we will create a new variable to hash his/her password
WP_Hash(hashpass,sizeof(hashpass),inputtext);//We will use whirlpool to hash their inputted text
new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
INI_SetTag(file,"data");//We will set a tag inside of user's account called "Player's Data"
INI_WriteString(file,"Password",hashpass);//This will write a hashed password into user's account
INI_WriteInt(file,"Cash",0);
INI_WriteInt(file,"Score",0);
INI_WriteInt(file,"Admin",0);
INI_WriteInt(file,"Kills",0);
INI_WriteInt(file,"Deaths",0);
INI_Close(file);//Now after we've done saving their data, we now need to close the file
SendClientMessage(playerid,-1,"You have been successfully registered");//Tell to them that they have successfully registered a new account
return 1;
}
}
if(dialogid == dlogin) //If dialog id is a login dialog
{//then
if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
if(response) //if they clicked the first button "Register"
{//then
new hashpass[129]; //Will create a new variable to hash his/her password
WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
if(!strcmp(hashpass, pInfo[playerid][pPass], false)) //If they have insert their correct password
{//then
INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
SetPlayerScore(playerid,pInfo[playerid][pScore]);//We will get their score inside of his user's account and we will set it here
GivePlayerMoney(playerid,pInfo[playerid][pCash]);//As explained above
SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
}
else //If they've entered an incorrect password
{//then
ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. To Project Gaming Freeroam. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
return 1;
}
}
}