Dialogs dont working together
#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


Messages In This Thread
**DELETE** - by Pettersen - 27.12.2013, 20:51
Re: Dialogs dont working together - by Hansrutger - 27.12.2013, 20:58
**DELETE** - by Pettersen - 27.12.2013, 21:01
Re: Dialogs dont working together - by xVIP3Rx - 27.12.2013, 21:08
**DELETE** - by Pettersen - 27.12.2013, 21:14
Re: Dialogs dont working together - by Hansrutger - 27.12.2013, 21:18
**DELETE** - by Pettersen - 27.12.2013, 21:21
Re: Dialogs dont working together - by xVIP3Rx - 27.12.2013, 21:28
**DELETE** - by Pettersen - 27.12.2013, 21:33
Re: Dialogs dont working together - by xVIP3Rx - 27.12.2013, 21:39

Forum Jump:


Users browsing this thread: 5 Guest(s)