05.02.2013, 13:00
I've been looking for a Register/Login system and I found one. Everything is in my gamemode and went testing.
But the problem is: It creates the User file, but it doesn't write anything in it.
This is the Login/Register system:
Thank you for trying to help me.
But the problem is: It creates the User file, but it doesn't write anything in it.
This is the Login/Register system:
pawn Код:
#include <YSI\y_ini>
pawn Код:
#define DIALOG_REGISTER 261
#define DIALOG_LOGIN 272
#define USERS "Users/%s.ini"
native WP_Hash(buffer[],len,const str[]);
enum PlayerInfo
{
Pass[129],
Money,
Scores,
Kills,
Deaths
}
new pInfo[MAX_PLAYERS][PlayerInfo];
forward LoadUser_data(playerid, name[], value[]);
pawn Код:
public OnPlayerConnect(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
if(fexist(UserPath(playerid)))
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","{FFFFFF}Welcome back. This account is {00FF00}registered. \n{FFFFFF}Insert your password to login to your account","Login","Quit");
}
else
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Register","{FFFFFF}Welcome! This account is {FF0000}not registered.\n{FFFFFF}Enter your own password to create a new account.","Register","Quit");
}
// There is some codes underneath here.
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
if(fexist(UserPath(playerid)))
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Money",GetPlayerMoney(playerid));
INI_WriteInt(File,"Scores",GetPlayerScore(playerid));
INI_WriteInt(File,"Kills",pInfo[playerid][Kills]);
INI_WriteInt(File,"Deaths",pInfo[playerid][Deaths]);
INI_Close(File);
}
return 1;
}
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_REGISTER)
{
if(!response) return Kick(playerid);
if(response)
{
if(!strlen(inputtext))
{
ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Register","You have entered an {FF0000}invalid password.\n{FFFFFF}Enter your own password to create a new account!","Register","Quit");
return 1;
}
new hashpass[129];
WP_Hash(hashpass,sizeof(hashpass),inputtext);
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteString(File,"Password",hashpass);
INI_WriteInt(File,"Money",0);
INI_WriteInt(File,"Scores",0);
INI_WriteInt(File,"Kills",0);
INI_WriteInt(File,"Deaths",0);
INI_Close(File);
SendClientMessage(playerid,COLOR_WHITE,"You have been {00FF00}successfully {FFFFFF}registered");
return 1;
}
}
if(dialogid == DIALOG_LOGIN)
{
if(!response) return Kick(playerid);
if(response)
{
new hashpass[129];
WP_Hash(hashpass,sizeof(hashpass),inputtext);
if(!strcmp(hashpass,pInfo[playerid][Pass]))
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
SetPlayerScore(playerid,pInfo[playerid][Scores]);
GivePlayerMoney(playerid,pInfo[playerid][Money]);
SendClientMessage(playerid,COLOR_WHITE,"Welcome back! You have {00FF00}successfully {FFFFFF}logged in");
}
else
{
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \n{FF0000}Insert 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;
}
}
}
return 1;
}
pawn Код:
public LoadUser_data(playerid,name[],value[])
{
INI_String("Password",pInfo[playerid][Pass],129);
INI_Int("Money",pInfo[playerid][Money]);
INI_Int("Scores",pInfo[playerid][Scores]);
INI_Int("Kills",pInfo[playerid][Kills]);
INI_Int("Deaths",pInfo[playerid][Deaths]);
return 1;
}
pawn Код:
stock UserPath(playerid)
{
new str[128],name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(str,sizeof(str),USERS,name);
return str;
}