OnPlayerLogin
#1

pawn Код:
public OnPlayerLogin(playerid,password[])
{
new string2[64];
new playername2[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername2, sizeof(playername2));
format(string2, sizeof(string2), "users/%s.ini", playername2);
new File: file = fopen(string2, io_read);
if (file)
{
new PassData[256];
new keytmp[256], valtmp[256];
fread( file , PassData , sizeof( PassData ) );
keytmp = ini_GetKey( PassData );
if( strcmp( keytmp , "pPassword" , true ) == 0 )
{
valtmp = ini_GetValue( PassData );
strmid(PlayerInfo[playerid][pPassword], valtmp, 0, strlen(valtmp)-1, 255);
}
if(strcmp(PlayerInfo[playerid][pPassword],password, true ) == 0 )
{
new key[ 256 ] , val[ 256 ];
new Data[ 256 ];
while ( fread( file , Data , sizeof( Data ) ) )
{
key = ini_GetKey( Data );
if( strcmp( key , "Level" , true ) == 0 ){val = ini_GetValue( Data ); PlayerInfo[playerid][pLevel] = strval( val );}
if( strcmp( key , "Sex" , true ) == 0 ){val = ini_GetValue( Data ); PlayerInfo[playerid][pSex] = strval( val );}
if( strcmp( key , "Age" , true ) == 0 ){val = ini_GetValue( Data ); PlayerInfo[playerid][pAge] = strval( val );}
if( strcmp( key , "Admin" , true ) == 0 ){val = ini_GetValue( Data ); PlayerInfo[playerid][pAdmin] = strval( val );}
if( strcmp( key , "Supporter" , true ) == 0 ){val = ini_GetValue( Data ); PlayerInfo[playerid][pSupporter] = strval( val );}
if( strcmp( key , "Cash" , true ) == 0 ){val = ini_GetValue( Data ); PlayerInfo[playerid][pCash] = strval( val );
}
fclose(file);
gPlayerLogged[playerid] = 1;
format(string2, sizeof(string2), "SERVER: Welcome %s.",playername2);
SendClientMessage(playerid, COLOR_WHITE,string2);
return 1;
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "{0084FF}Login:", "{FF0000}WRONG PASSWORD!\n{FFFFFF} Please enter your password below", "Login", "Cancel");
fclose(file);
}
}
return 1;
}

Okay. I created an account system, however I' cannot get OnPlayerLogin to work.

I can type ANYTHING in, and it'll log me in, it shouldn't happen, help me please?
Reply
#2

I know I'm not suppose to bump but I'm needing this ASAP.
Reply
#3

Try this:

pawn Код:
"\users\%s.ini"
The folder "users" needs to be in your "scriptfiles" folder.

Also keep in mind that strcmp is true (0 in this case) if one of the strings is empty, you might wanna check that first

//EDIT: Work with this code, but please say something to the added comments:

pawn Код:
public OnPlayerLogin(playerid,password[])
{
    new string2[64];
    new playername2[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername2, sizeof(playername2));
    format(string2, sizeof(string2), "\users\%s.ini", playername2);
    if(fexist(string2))
    {
        new File:file = fopen(string2, io_read);
        new PassData[256];
        new keytmp[256], valtmp[256];
        fread( file , PassData , sizeof( PassData ) );
        keytmp = ini_GetKey( PassData );
        if( strcmp( keytmp , "pPassword" , true ) == 0 ) //What is this? Even if the if-statement were wrong, the code would continue
        {
            valtmp = ini_GetValue( PassData );
            strmid(PlayerInfo[playerid][pPassword], valtmp, 0, strlen(valtmp)-1, 255);
        }
        if(strcmp(PlayerInfo[playerid][pPassword],password, true ) == 0 ) //Make sure neither of the strings is empty
        {
            new key[ 256 ] , val[ 256 ];
            new Data[ 256 ];
            while ( fread( file , Data , sizeof( Data ) ) )
            {
                key = ini_GetKey( Data );
                if( strcmp( key , "Level" , true ) == 0 ){val = ini_GetValue( Data ); PlayerInfo[playerid][pLevel] = strval( val );}
                if( strcmp( key , "Sex" , true ) == 0 ){val = ini_GetValue( Data ); PlayerInfo[playerid][pSex] = strval( val );}
                if( strcmp( key , "Age" , true ) == 0 ){val = ini_GetValue( Data ); PlayerInfo[playerid][pAge] = strval( val );}
                if( strcmp( key , "Admin" , true ) == 0 ){val = ini_GetValue( Data ); PlayerInfo[playerid][pAdmin] = strval( val );}
                if( strcmp( key , "Supporter" , true ) == 0 ){val = ini_GetValue( Data ); PlayerInfo[playerid][pSupporter] = strval( val );}
                if( strcmp( key , "Cash" , true ) == 0 ){val = ini_GetValue( Data ); PlayerInfo[playerid][pCash] = strval( val );
            }
            gPlayerLogged[playerid] = 1;
            format(string2, sizeof(string2), "SERVER: Welcome %s.",playername2);
            SendClientMessage(playerid, COLOR_WHITE,string2);
        }
        else ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "{0084FF}Login:", "{FF0000}WRONG PASSWORD!\n{FFFFFF} Please enter your password below", "Login", "Cancel");
        fclose(file);
    }
    else {} //Account not created yet
    return 1;
}
Reply
#4

xD.....
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)