Dialogs dont working together
#1

**DELETE
Reply
#2

Well I'd rather made the password things not being hashed because I don't understand/like that kind of system as I have seen lots of people having trouble with it. I don't know why you would want to hash a file that only you would have access to. Having a basic string comperance (strcmp) between what is written inside the file and what the player puts inside inputtext is so much easier in my opinion.

Sorry if this wasn't an actual answer, it was just how I would have done it personally, but it's up to the scripter itself.
Reply
#3

**DELETE
Reply
#4

Here you go.. Fixed/Improved code
pawn Code:
//--Includes--//
#include <a_samp>
#include <YSI\y_ini>

#define PATH "/Users/%s.ini"

//--Dialogs--//
enum //Enums are better so you don't track every Dialog id.. But you can use defines if you would like too
{
    DIALOG_REGISTER,
    DIALOG_LOGIN,
    DIALOG_CLASS,
    MILITARY_CLASS,
    CIVIL_CLASS,
}
/*#define   DIALOG_REGISTER     1
#define DIALOG_LOGIN        2
#define DIALOG_CLASS        3
#define MILITARY_CLASS      4
#define CIVIL_CLASS         5*/

enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pKills,
    pDeaths
}
new PlayerInfo[MAX_PLAYERS][pInfo];

main(){}
public OnGameModeInit()
{
    SetGameModeText("Blank Script");
    return 1;
}

public OnPlayerConnect(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login", "Type your password below to login.", "Login", "Quit");
    }
    else ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registering", "Type your password below to register a new account.", "Register", "Quit");
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Close(File);
    return 1;
}

public OnPlayerRequestSpawn(playerid) return 0;
public OnPlayerRequestClass(playerid, classid)
{
    ShowPlayerDialog(playerid, DIALOG_CLASS, DIALOG_STYLE_LIST, "Class", "MILITARY\nCIVIL", "Choose", "");
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    if(IsPlayerConnected(killerid) && killerid != INVALID_PLAYER_ID) PlayerInfo[killerid][pKills]++;
    PlayerInfo[playerid][pDeaths]++;
    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, "Registering", "You have entered an invalid password.\nType 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_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_Close(File);
                return 1;
            }
        }
        case DIALOG_LOGIN:
        {
            if(!response) return Kick(playerid);
            if(response)
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                }
                else ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "You have entered an incorrect password.\nType your password below to login.", "Login", "Quit");
            }
            return 1;
        }
        case DIALOG_CLASS:
        {
            if(!response) return 1;
            switch(listitem)
            {
                case 0:
                {
                    SetPlayerTeam(playerid, MILITARY_CLASS);
                    SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 26, 36, 28, 150, 0, 0);
                    SpawnPlayer(playerid);
                }
                case 1:
                {
                    SetPlayerTeam(playerid, CIVIL_CLASS);
                    SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 26, 36, 28, 150, 0, 0);
                    SpawnPlayer(playerid);
                }
            }
        }
    }
    return 0;
}


forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    return 1;
}

stock UserPath(playerid)
{
    new string[40], playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}
/*Credits to Dracoblue*/
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;
}
You was using
pawn Code:
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
So you wasn't even loading it, You should use "LoadUser_data" Instead
Reply
#5

**DELETE
Reply
#6

Quote:
Originally Posted by Pettersen
View Post
I wil have it hashed, Because in security, Player's can feel safe with hashed password, If a idiot hacks the server they have all passwords.. If its hashed he "cant" get them
I don't think anyone can get the passwords because you save them inside your own files and not actual public files available to anyone. Besides a hacker cannot just "change" ID to another playerid ingame either so that wouldn't make him able to control the other player either to look at what he types in. But I don't know.
Reply
#7

**DELETE
Reply
#8

Quote:
Originally Posted by Hansrutger
View Post
I don't think anyone can get the passwords because you save them inside your own files and not actual public files available to anyone. Besides a hacker cannot just "change" ID to another playerid ingame either so that wouldn't make him able to control the other player either to look at what he types in. But I don't know.
Hashing is pretty easy.. also give me a single reason to know the players's passwords.. Some players (Like me sometimes) put their phone numbers as a password..So no reason to know that..

OT: I used another way to hash the password.. Try it
pawn Code:
//--Includes--//
#include <a_samp>
#include <YSI\y_ini>

#define PATH "/Users/%s.ini"

native WP_Hash(buffer[], len, const str[]);

//--Dialogs--//
enum //Enums are better so you don't track every Dialog id.. But you can use defines if you would like too
{
    DIALOG_REGISTER,
    DIALOG_LOGIN,
    DIALOG_CLASS,
    MILITARY_CLASS,
    CIVIL_CLASS,
}
/*#define   DIALOG_REGISTER     1
#define DIALOG_LOGIN        2
#define DIALOG_CLASS        3
#define MILITARY_CLASS      4
#define CIVIL_CLASS         5*/

enum pInfo
{
    pPass[128],
    pCash,
    pAdmin,
    pKills,
    pDeaths
}

new PlayerInfo[MAX_PLAYERS][pInfo];

main(){}
public OnGameModeInit()
{
    SetGameModeText("Blank Script");
    return 1;
}

public OnPlayerConnect(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login", "Type your password below to login.", "Login", "Quit");
    }
    else ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registering", "Type your password below to register a new account.", "Register", "Quit");
    return 1;
}

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_String("Password", PlayerInfo[playerid][pPass], 128);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Close(File);
    return 1;
}

public OnPlayerRequestSpawn(playerid) return 0;
public OnPlayerRequestClass(playerid, classid)
{
    ShowPlayerDialog(playerid, DIALOG_CLASS, DIALOG_STYLE_LIST, "Class", "MILITARY\nCIVIL", "Choose", "");
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    if(IsPlayerConnected(killerid) && killerid != INVALID_PLAYER_ID) PlayerInfo[killerid][pKills]++;
    PlayerInfo[playerid][pDeaths]++;
    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, "Registering", "You have entered an invalid password.\nType your password below to register a new account.", "Register", "Quit");

                new Password[128]; WP_Hash(Password, sizeof(Password), inputtext);
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File, "data");
                INI_WriteString(File, "Password", Password);
                INI_WriteInt(File, "Cash",0);
                INI_WriteInt(File, "Admin",0);
                INI_WriteInt(File, "Kills",0);
                INI_WriteInt(File, "Deaths",0);
                INI_Close(File);
                return 1;
            }
        }
        case DIALOG_LOGIN:
        {
            if(!response) return Kick(playerid);
            new Password[128]; WP_Hash(Password, sizeof(Password), inputtext);

            if(!strcmp(PlayerInfo[playerid][pPass], Password, false))
            {
                GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
            }
            else ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "You have entered an incorrect password.\nType your password below to login.", "Login", "Quit");
            return 1;
        }
        case DIALOG_CLASS:
        {
            if(!response) return 1;
            switch(listitem)
            {
                case 0:
                {
                    SetPlayerTeam(playerid, MILITARY_CLASS);
                    SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 26, 36, 28, 150, 0, 0);
                    SpawnPlayer(playerid);
                }
                case 1:
                {
                    SetPlayerTeam(playerid, CIVIL_CLASS);
                    SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 26, 36, 28, 150, 0, 0);
                    SpawnPlayer(playerid);
                }
            }
        }
    }
    return 0;
}

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

**DELETE
Reply
#10

Quote:
Originally Posted by Pettersen
View Post
Same bug s
Or can some just make a login system (download) and add class selection in dialog like this?
http://i.imgur.com/6GjNnhV.png
Give me few minutes, I'll test/fix it and edit that post.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)