SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 27/12/2013, 09:51 PM   #11
Pettersen
Big Clucker
 
Pettersen's Avatar
 
Join Date: Apr 2013
Location: San Andreas
Posts: 152
Reputation: 9
Default **DELETE**

**DELETE
__________________

Last edited by Pettersen; 28/12/2013 at 11:41 PM.
Pettersen is offline   Reply With Quote
Old 27/12/2013, 09:58 PM   #12
Patrick
Guest
 
Posts: n/a
Default Re: Dialogs dont working together

I do not suggest this tutorial, because it uses udb_hash and it is obsolete if you do not know what obsolete means, it means it's old + it is not updated anymore by DracoBlue, I suggest you use Whirpool instead of udb_hash, also check this tutorial made by newbienoob it uses Whirpool | Click Me(Tutorial)

pawn Code:
//udb_hash use placeholder %d (decimal) or %i (integer)
//Whirpool uses placeholder %s (string)
  Reply With Quote
Old 27/12/2013, 10:03 PM   #13
xVIP3Rx
High-roller
 
xVIP3Rx's Avatar
 
Join Date: Feb 2013
Location: Egypt
Posts: 1,096
Reputation: 96
Default Re: Dialogs dont working together

Here the fixed code by your old method (udb_hash)
pawn Code:
//--Includes--//
#include <a_samp>
#include <YSI\y_ini>

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

//--Dialogs--//
/*
#define   DIALOG_REGISTER   1
#define DIALOG_LOGIN        2
#define DIALOG_CLASS        3
#define MILITARY_CLASS      4
#define CIVIL_CLASS         5
*/

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,
}

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) 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(!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 ShowPlayerDialog(playerid, DIALOG_CLASS, DIALOG_STYLE_LIST, "Class", "MILITARY\nCIVIL", "Choose", "");
        }
        case DIALOG_LOGIN:
        {
            if(!response) return Kick(playerid);

            if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
            {
                GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                ShowPlayerDialog(playerid, DIALOG_CLASS, DIALOG_STYLE_LIST, "Class", "MILITARY\nCIVIL", "Choose", "");
            }
            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;
}

And another one using Whirpool
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) 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(!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 ShowPlayerDialog(playerid, DIALOG_CLASS, DIALOG_STYLE_LIST, "Class", "MILITARY\nCIVIL", "Choose", "");
        }
        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]);
                ShowPlayerDialog(playerid, DIALOG_CLASS, DIALOG_STYLE_LIST, "Class", "MILITARY\nCIVIL", "Choose", "");
            }
            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;
}
You'll have to download Wirlpool plugin and add it to your server.cfg if you choose to use this one
xVIP3Rx is offline   Reply With Quote
Old 27/12/2013, 10:10 PM   #14
zDevon
Huge Clucker
 
Join Date: Jan 2012
Location: Charlotte, NC (USA)
Posts: 298
Reputation: 31
Default Re: Dialogs dont working together

Quote:
Originally Posted by Hansrutger View Post
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.
This is an extremely flawed logic. In a perfect world yes, only you would have access to the files containing the passwords, but that can never be guaranteed - and that's the entire point of security in the first place! Bare bones comparing of strings isn't easier, it's just an excuse to be lazy. There isn't any change in difficulty in adding a hashing process, just a couple more lines of code. Saving plain-text passwords is simply unethical.

Last edited by zDevon; 26/05/2014 at 06:08 PM.
zDevon is offline   Reply With Quote
Old 27/12/2013, 10:14 PM   #15
Pettersen
Big Clucker
 
Pettersen's Avatar
 
Join Date: Apr 2013
Location: San Andreas
Posts: 152
Reputation: 9
Default **DELETE**

**DELETE
__________________

Last edited by Pettersen; 28/12/2013 at 11:42 PM.
Pettersen is offline   Reply With Quote
Old 27/12/2013, 10:17 PM   #16
xVIP3Rx
High-roller
 
xVIP3Rx's Avatar
 
Join Date: Feb 2013
Location: Egypt
Posts: 1,096
Reputation: 96
Default Re: Dialogs dont working together

EDIT: I had a little mistake here.. Fixed..
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[145],
    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], 145);
    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) 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(!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[145]; 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 ShowPlayerDialog(playerid, DIALOG_CLASS, DIALOG_STYLE_LIST, "Class", "MILITARY\nCIVIL", "Choose", "");
        }
        case DIALOG_LOGIN:
        {
            if(!response) return Kick(playerid);
            new Password[145]; WP_Hash(Password, sizeof(Password), inputtext);

            if(!strcmp(PlayerInfo[playerid][pPass], Password, false))
            {
                GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                ShowPlayerDialog(playerid, DIALOG_CLASS, DIALOG_STYLE_LIST, "Class", "MILITARY\nCIVIL", "Choose", "");
            }
            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;
}
xVIP3Rx is offline   Reply With Quote
Old 27/12/2013, 10:18 PM   #17
Pettersen
Big Clucker
 
Pettersen's Avatar
 
Join Date: Apr 2013
Location: San Andreas
Posts: 152
Reputation: 9
Default **DELETE**

**DELETE
__________________

Last edited by Pettersen; 28/12/2013 at 11:42 PM.
Pettersen is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FS Dialogs dont work. Hade. Scripting Help 2 08/01/2013 06:26 PM
A little help please . filterscript dialogs dont respond Jaber_Brown Scripting Help 2 03/09/2012 11:52 AM
Not working dialogs! x96664 Server Support 7 21/06/2012 07:54 PM
Dialogs Dont work.. jtemple042996 Scripting Help 3 18/05/2012 08:05 PM
No errors,no warnings but dialogs dont work IG JackT Help Archive 6 24/07/2011 12:18 PM


All times are GMT. The time now is 03:45 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.