Loading data with Y_INI
#10

Quote:
Originally Posted by dakata994
Посмотреть сообщение
Did you try mine ? If you tried and it won't work try this:
Код:
// ------- Accounts ------//

#define PATH "/Users/%s.ini"
#define DIALOG_REGISTER 1
enum pInfo
{

    pPassword

}


public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPassword]);
    return 1;
}

stock UserPath(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}


stock udb_hash(buf[]) {
    new length=strlen(buf);
    new s1 = 1;
    new s2 = 0;
    new n;
    for (n=0; n<length; n++)
    {
       s1 = (s1 + buf[n]) % 65521;
       s2 = (s2 + s1)     % 65521;
    }
    return (s2 << 16) + s1;
}



public OnPlayerConnect(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"Authentication","{FFFFFF}Wellcome back to {FF0000} CHANGE IT \n{FFFFFF}Type your password to Login.","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,"Authentication","{FFFFFF}Wellcome to {FF0000}CHANGE IT \n{FFFFFF}Type your password to Register.","Register","Quit");
    }
    return 1;
}



public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_Close(File);
			}
        }
        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    SpawnPlayer(playerid);
                }
                else
                {
                    Kick(playerid);
                }
                return 1;
            }
        }
    }
    return 1;
}
I am not using udb_hash, I am using Whirlpool. It works differently, which means that the password hash is a string, and that is why I have to use INI_String in stead of INI_Int, unfortunately
Reply


Messages In This Thread
Loading data with Y_INI - by sim_sima - 15.12.2013, 21:01
Re: Loading data with Y_INI - by dakata994 - 15.12.2013, 21:07
Re: Loading data with Y_INI - by sim_sima - 15.12.2013, 21:12
Re: Loading data with Y_INI - by dakata994 - 15.12.2013, 21:16
Re: Loading data with Y_INI - by Patrick - 15.12.2013, 21:20
Re: Loading data with Y_INI - by sim_sima - 15.12.2013, 21:26
Re: Loading data with Y_INI - by Sgt.TheDarkness - 15.12.2013, 21:28
Re: Loading data with Y_INI - by dakata994 - 15.12.2013, 21:33
Re: Loading data with Y_INI - by sim_sima - 15.12.2013, 21:34
Re: Loading data with Y_INI - by sim_sima - 15.12.2013, 21:39

Forum Jump:


Users browsing this thread: 2 Guest(s)