SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 27/12/2013, 08:51 PM   #1
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, 08:58 PM   #2
Hansrutger
Gangsta
 
Hansrutger's Avatar
 
Join Date: May 2011
Location: Sweden
Posts: 760
Reputation: 161
Default Re: Dialogs dont working together

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.
__________________


Hansrutger is offline   Reply With Quote
Old 27/12/2013, 09:01 PM   #3
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:08 PM   #4
xVIP3Rx
High-roller
 
xVIP3Rx's Avatar
 
Join Date: Feb 2013
Location: Egypt
Posts: 1,096
Reputation: 96
Default Re: Dialogs dont working together

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
xVIP3Rx is offline   Reply With Quote
Old 27/12/2013, 09:14 PM   #5
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:18 PM   #6
Hansrutger
Gangsta
 
Hansrutger's Avatar
 
Join Date: May 2011
Location: Sweden
Posts: 760
Reputation: 161
Default Re: Dialogs dont working together

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.
__________________


Hansrutger is offline   Reply With Quote
Old 27/12/2013, 09:21 PM   #7
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:28 PM   #8
xVIP3Rx
High-roller
 
xVIP3Rx's Avatar
 
Join Date: Feb 2013
Location: Egypt
Posts: 1,096
Reputation: 96
Default Re: Dialogs dont working together

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;
}
xVIP3Rx is offline   Reply With Quote
Old 27/12/2013, 09:33 PM   #9
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:39 PM   #10
xVIP3Rx
High-roller
 
xVIP3Rx's Avatar
 
Join Date: Feb 2013
Location: Egypt
Posts: 1,096
Reputation: 96
Default Re: Dialogs dont working together

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.
xVIP3Rx 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 11:28 PM.


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