strcmp question
#1

What's wrong with this?

pawn Code:
case    DIALOG_LOGIN: {
                    if( response )
                    {
                        if( !strlen( inputtext ) ) //They hit enter without entering a password.
                            return ShowPlayerDialog( playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Welcome to SA:MP - Zone DM!", "\n\nYou have entered an invalid password, in order to assist you, a plain text password field has been enabled.\n\nPlease enter a password in order to register an account with us.", "Submit", "Quit" );
                           
                        if( !strcmp( accInfo [ playerid ] [ Password ], inputtext, false ) )
                            return ShowPlayerDialog( playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Welcome to SA:MP - Zone DM!", "\n\nYou have entered an invalid password, in order to assist you, a plain text password field has been enabled.\n\nPlease enter a password in order to register an account with us.", "Submit", "Quit" );

                        INI_ParseFile( GetAccountPath( playerid ), "LoadUser_%s", .bExtra = true, .extra = playerid );
                       
                        GivePlayerMoney( playerid, 1000 );
                    }
                }
Reply
#2

You sure you got that enum accInfo ?
Or you maybe wrote it in bad caps
Reply
#3

pawn Code:
#define     USERPATH            "ZoneDM/Users/%s.ini"

enum accVars
{
    Password[ 64 ],
    Model,
    Access,
    ClassID
};
new accInfo [ MAX_PLAYERS ] [ accVars ], bool:player_Logged[ MAX_PLAYERS ] = false;
pawn Code:
public OnPlayerConnect(playerid)
{
    if( fexist( GetAccountPath( playerid ) ) ) //They exist!
    {
        INI_ParseFile( GetAccountPath( playerid ), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowPlayerDialog( playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Welcome to SA:MP - Zone DM!", "\n\nPlease enter your password below to be logged in.", "Submit", "Quit" );
    }
    else //New user
    {
        ShowPlayerDialog( playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Welcome to SA:MP - Zone DM!", "\n\nPlease enter a password in order to register an account with us.", "Submit", "Quit" );
    }
    player_Spawned [ playerid ] = false, player_Logged [ playerid ] = false;
    return 1;
}
pawn Code:
switch( dialogid )
    {
        case    DIALOG_BLANK: { if( response ) { } }
        case    DIALOG_REGISTER: {
                    if( response )
                    {
                        if( !strlen( inputtext ) ) //They hit enter without entering a password.
                            return ShowPlayerDialog( playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Welcome to SA:MP - Zone DM!", "\n\nYou have entered an invalid password, in order to assist you, a plain text password field has been enabled.\n\nPlease enter a password in order to register an account with us.", "Submit", "Quit" );
                       
                        new
                            INI: myAcc = INI_Open( GetAccountPath( playerid ) );
                           
                        INI_SetTag(         myAcc,          "data" );
                       
                        INI_WriteString(    myAcc,          "Password",         inputtext );
                       
                        INI_WriteInt(       myAcc,          "Model",            -1 );
                        INI_WriteInt(       myAcc,          "Access",           1 );
                        INI_WriteInt(       myAcc,          "ClassID",          -1 );
                           
                        INI_Close( myAcc );
                    }
                    else if( !response )
                    {
                        SendClientMessage( playerid, 0xFFFFFFFF, "You have chosen to quit the server. We hope you visit again soon!" );
                        Kick( playerid );
                    }
                }
        case    DIALOG_LOGIN: {
                    if( response )
                    {
                        if( !strlen( inputtext ) ) //They hit enter without entering a password.
                            return ShowPlayerDialog( playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Welcome to SA:MP - Zone DM!", "\n\nYou have entered an invalid password, in order to assist you, a plain text password field has been enabled.\n\nPlease enter a password in order to register an account with us.", "Submit", "Quit" );
                           
                        if( strcmp( accInfo[ playerid ] [ Password ], inputtext, false ) == 0 )
                            return ShowPlayerDialog( playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Welcome to SA:MP - Zone DM!", "\n\nYou have entered an invalid password, in order to assist you, a plain text password field has been enabled.\n\nPlease enter a password in order to register an account with us.", "Submit", "Quit" );

                        INI_ParseFile( GetAccountPath( playerid ), "LoadUser_%s", .bExtra = true, .extra = playerid );
                       
                        player_Logged [ playerid ] = true;
                       
                        GivePlayerMoney( playerid, 1000 );
                    }
                }
    }
Yeah, I'm sure.
Reply
#4

Strcmp returns 0 when the password match ( if(!strcmp) ) and when they match you're showing they have put an invalid password.
Reply
#5

The lines
pawn Code:
if( !strcmp( accInfo [ playerid ] [ Password ], inputtext, false ) )
                            return ShowPlayerDialog( playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, etc....
This basically says that if the player types the password correctly, then it'll return that dialog no matter what. I won't treat you like an idiot, because you aren't lol, but strcmp subtracts the two strings' ASCII values and if the strings are the same, then it'll return 0. That is why some lines look like this.
pawn Code:
if(strcmp(string,string2,true) == 0)
So what you would do is this.
pawn Code:
if( strcmp( accInfo [ playerid ] [ Password ], inputtext, false ) != 0 )
                            return ShowPlayerDialog( playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, etc....
So if strcmp subtracts the password's ASCII values with the inputtext's values, if that does not equal 0 then the two strings aren't correct, thus returning the Invalid Password dialog. Hope I helped.

EDIT:

This post explains how strcmp works.
That's how I learned lol
http://forum.sa-mp.com/showpost.php?...28&postcount=1
Reply
#6

You both did, thank you. I'll +rep you momentarily. I have another question... I just got the following printed in my server console, I've never seen it before..

Quote:

[11:34:30] Warning: PlayerDialogResponse PlayerId: 0 dialog ID doesn't match last sent dialog ID

The code:

pawn Code:
case    DIALOG_LOGIN: {
                    if( response )
                    {
                        if( !strlen( inputtext ) ) //They hit enter without entering a password.
                            return ShowPlayerDialog( playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Welcome to SA:MP - Zone DM!", "\n\nYou have entered an invalid password, in order to assist you, a plain text password field has been enabled.\n\nPlease enter your password below to be logged in.", "Submit", "Quit" );
                           
                        if( strcmp( accInfo[ playerid ] [ Password ], inputtext, false ) )
                            return ShowPlayerDialog( playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Welcome to SA:MP - Zone DM!", "\n\nYou have entered an invalid password, in order to assist you, a plain text password field has been enabled.\n\nPlease enter your password below to be logged in.", "Submit", "Quit" );

                        INI_ParseFile( GetAccountPath( playerid ), "LoadUser_%s", .bExtra = true, .extra = playerid );
                       
                        player_Logged [ playerid ] = true;
                       
                        SpawnPlayer( playerid );
                       
                        GivePlayerMoney( playerid, 9999999 );
                    }
                    else if( !response )
                    {
                        SendClientMessage( playerid, 0xFFFFFFFF, "You have chosen to quit the server. We hope you visit again soon!" );
                        Kick( playerid );
                    }
                }
? O.o
Reply
#7

Whoa, never seen that before.

But
pawn Code:
if( strcmp( accInfo[ playerid ] [ Password ], inputtext, false ) )
                            return ShowPlayerDialog( playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT
You're not seeing if it won't return 0.
Code:
!= 0
Reply
#8

Quote:
Originally Posted by VincentDunn
View Post
Whoa, never seen that before.
Me neither.


Quote:
Originally Posted by VincentDunn
View Post
But
pawn Code:
if( strcmp( accInfo[ playerid ] [ Password ], inputtext, false ) )
                            return ShowPlayerDialog( playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT
You're not seeing if it won't return 0.
Code:
!= 0
I've fixed it in the actual script, thank you.

pawn Code:
if( strcmp( accInfo[ playerid ] [ Password ], inputtext, false ) )
                            return ShowPlayerDialog( playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT
Reply
#9

I'm lost then.
It works fine in game, but just prints that message?
These sorta things I just fiddle around with something until the message goes away.
Couldn't find anything on it on ****** or the search button.
Reply
#10

Quote:
Originally Posted by VincentDunn
View Post
I'm lost then.
It works fine in game, but just prints that message?
These sorta things I just fiddle around with something until the message goes away.
Couldn't find anything on it on ****** or the search button.
It's odd, it only happens randomly. I guess everything still works, and I couldn't duplicate the message in about ten minutes, so I don't know. Thanks anyways.
Reply
#11

Quote:
Originally Posted by 2KY
View Post
You both did, thank you. I'll +rep you momentarily. I have another question... I just got the following printed in my server console, I've never seen it before..



The code:

pawn Code:
case    DIALOG_LOGIN: {
                    if( response )
                    {
                        if( !strlen( inputtext ) ) //They hit enter without entering a password.
                            return ShowPlayerDialog( playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Welcome to SA:MP - Zone DM!", "\n\nYou have entered an invalid password, in order to assist you, a plain text password field has been enabled.\n\nPlease enter your password below to be logged in.", "Submit", "Quit" );
                           
                        if( strcmp( accInfo[ playerid ] [ Password ], inputtext, false ) )
                            return ShowPlayerDialog( playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Welcome to SA:MP - Zone DM!", "\n\nYou have entered an invalid password, in order to assist you, a plain text password field has been enabled.\n\nPlease enter your password below to be logged in.", "Submit", "Quit" );

                        INI_ParseFile( GetAccountPath( playerid ), "LoadUser_%s", .bExtra = true, .extra = playerid );
                       
                        player_Logged [ playerid ] = true;
                       
                        SpawnPlayer( playerid );
                       
                        GivePlayerMoney( playerid, 9999999 );
                    }
                    else if( !response )
                    {
                        SendClientMessage( playerid, 0xFFFFFFFF, "You have chosen to quit the server. We hope you visit again soon!" );
                        Kick( playerid );
                    }
                }
? O.o
I have received the error "dialog ID doesn't match last sent dialog ID" error as well. It seems to happen when the server restarts while a dialog is open. The client reconnects and has the same dialog plus the client is hung until you close the dialog. Then the script continues as normal. This look like some ind of bug. When the server restarts, the client should forget about all dialogs that were open at the time.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)