Why does this say "You have entered an incorrect password" when it isn't
#1

pawn Код:
case DIALOG_LOGIN: //Dialog login
        {
            if(!response) //If they click the cancel button
            {
                SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You have chosen to quit Domination Roleplay, please visit us again soon!");
                Kick(playerid);
            }
            if(response) //If the player clicked login
            {
                new query[210], pname[24], escapepass[100];//
                GetPlayerName(playerid, pname, 24); //Gets the players name
                mysql_real_escape_string(inputtext, escapepass); //We escape the inputtext to avoid SQL injections.
                format(query, sizeof(query), "SELECT `user` FROM playerdata WHERE user = '%s' AND password = SHA1('%s')", pname, escapepass);
                mysql_function_query(dbHandle, query, true, "LoadPlayerData", "i", playerid);
                new rows, fields;
                cache_get_data(rows, fields, dbHandle);
                if(rows)
                {
                    new savingstring[20];
                    GetPlayerName(playerid, pname, 24);
                    format(query, sizeof(query), "SELECT Level, Money, PlayerPosX, PlayerPosY, PlayerPosZ, InteriorID, SkinID FROM playerdata WHERE user = '%s'", pname);
                    //We only select the variables that we want to use.
                    //We don't need things like the password string or the user string.
                    mysql_function_query(dbHandle, query, true, "LoadPlayerData", "i", playerid);
                    cache_get_field_content(0, "Level",savingstring, dbHandle);SetPlayerScore(playerid, strval(savingstring));
                    cache_get_field_content(0, "Money",savingstring, dbHandle);MoneyGiven[playerid] = strval(savingstring);
                    cache_get_field_content(0, "PlayerPosX",savingstring, dbHandle);PlayerVar[playerid][pPosX] = floatstr(savingstring);
                    cache_get_field_content(0, "PlayerPosY",savingstring, dbHandle);PlayerVar[playerid][pPosY] = floatstr(savingstring);
                    cache_get_field_content(0, "PlayerPosZ",savingstring, dbHandle);PlayerVar[playerid][pPosZ] = floatstr(savingstring);
                    cache_get_field_content(0, "InteriorID",savingstring, dbHandle); PlayerVar[playerid][InteriorID] = strval(savingstring);
                    cache_get_field_content(0, "SkinID",savingstring, dbHandle);PlayerVar[playerid][SkinID] = strval(savingstring);
                    SetPlayerHealth(playerid, 100);
                    TextDrawHideForPlayer(playerid, WIDESCREEN_TOP);
                    TextDrawHideForPlayer(playerid, WIDESCREEN_BOTTOM);
                    TextDrawHideForPlayer(playerid, WelcomeTD);
                    TogglePlayerSpectating(playerid, 0);
                    SetPVarInt(playerid, "prelogin", 0);
                    SetPlayerWeapons(playerid);
                    SetPlayerWeaponsEx(playerid);
                    SendClientMessage(playerid, -1, "You have been logged in!"); //Sends the client a message.
                    Logged[playerid] = 1; //Sets our logged in variable to one
                    SetPlayerInterior(playerid, PlayerVar[playerid][InteriorID]);
                    SetSpawnInfo(playerid, 0, PlayerVar[playerid][SkinID], PlayerVar[playerid][pPosX], PlayerVar[playerid][pPosY], PlayerVar[playerid][pPosZ], 0, 0, 0, 0, 0, 0, 0);
                    SpawnPlayer(playerid);
                    return 1;
                }
                //This means that there is a user in the database with the same
                //password that we typed, we now proceed by using the login function.
                if(!rows)
                {
                    //This means that the password that the player
                    //typed was incorrect and we will resend the dialog.
                    format(string, sizeof(string), "Welcome back, %s. Please enter your password below to log in.", GetName(playerid));
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", string, "Confirm", "Quit");
                    SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You have entered an incorrect password."); //Sends the client a error message
                }
            }
            return 1;
        }
pawn Код:
forward LoadPlayerData(playerid);
public LoadPlayerData(playerid)
{
}
My original code (before using cache) is:

pawn Код:
case DIALOG_LOGIN: //Dialog login
        {
            if(!response) //If they click the cancel button
            {
                SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You have chosen to quit Domination Roleplay, please visit us again soon!");
                Kick(playerid);
            }
            if(response) //If the player clicked login
            {
                new query[210], pname[24], escapepass[100];//
                GetPlayerName(playerid, pname, 24); //Gets the players name
                mysql_real_escape_string(inputtext, escapepass); //We escape the inputtext to avoid SQL injections.
                format(query, sizeof(query), "SELECT `user` FROM playerdata WHERE user = '%s' AND password = SHA1('%s')", pname, escapepass);
                mysql_query(query);
                mysql_store_result();
                new numrows = mysql_num_rows();
                if(numrows == 1)
                {
                    new savingstring[20];
                    GetPlayerName(playerid, pname, 24);
                    format(query, sizeof(query), "SELECT Level, Money, PlayerPosX, PlayerPosY, PlayerPosZ, InteriorID, SkinID FROM playerdata WHERE user = '%s'", pname);
                    //We only select the variables that we want to use.
                    //We don't need things like the password string or the user string.
                    mysql_query(query); //Queries the result
                    mysql_store_result();
                    while(mysql_fetch_row_format(query,"|"))
                    {
                        //We use while so that it does a single query, not multiple
                        //Especially when we have more variables. If there is more
                        //Variables, you should just split the line with sscanf. To
                        //Make it easier.
                        mysql_fetch_field_row(savingstring, "Level"); SetPlayerScore(playerid, strval(savingstring));
                        mysql_fetch_field_row(savingstring, "Money"); MoneyGiven[playerid] = strval(savingstring);
                        mysql_fetch_field_row(savingstring, "PlayerPosX"); PlayerVar[playerid][pPosX] = floatstr(savingstring);
                        mysql_fetch_field_row(savingstring, "PlayerPosY"); PlayerVar[playerid][pPosY] = floatstr(savingstring);
                        mysql_fetch_field_row(savingstring, "PlayerPosZ"); PlayerVar[playerid][pPosZ] = floatstr(savingstring);
                        mysql_fetch_field_row(savingstring, "InteriorID"); PlayerVar[playerid][InteriorID] = strval(savingstring);
                        mysql_fetch_field_row(savingstring, "SkinID"); PlayerVar[playerid][SkinID] = strval(savingstring);
                        //If you are wondering why I'm using savingstring instead
                        //Of a variable like using MoneyGiven right away, it's because
                        //mysql_fetch_field_row requires a string.
                    }
                    mysql_free_result();
                    SetPlayerHealth(playerid, 100);
                    TextDrawHideForPlayer(playerid, WIDESCREEN_TOP);
                    TextDrawHideForPlayer(playerid, WIDESCREEN_BOTTOM);
                    TextDrawHideForPlayer(playerid, WelcomeTD);
                    TogglePlayerSpectating(playerid, 0);
                    SetPVarInt(playerid, "prelogin", 0);
                    SetPlayerWeapons(playerid);
                    SetPlayerWeaponsEx(playerid);
                    SendClientMessage(playerid, -1, "You have been logged in!"); //Sends the client a message.
                    Logged[playerid] = 1; //Sets our logged in variable to one
                    SetPlayerInterior(playerid, PlayerVar[playerid][InteriorID]);
                    SetSpawnInfo(playerid, 0, PlayerVar[playerid][SkinID], PlayerVar[playerid][pPosX], PlayerVar[playerid][pPosY], PlayerVar[playerid][pPosZ], 0, 0, 0, 0, 0, 0, 0);
                    SpawnPlayer(playerid);
                    return 1;
                }
                //This means that there is a user in the database with the same
                //password that we typed, we now proceed by using the login function.
                if(!numrows)
                {
                    //This means that the password that the player
                    //typed was incorrect and we will resend the dialog.
                    format(string, sizeof(string), "Welcome back, %s. Please enter your password below to log in.", GetName(playerid));
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", string, "Confirm", "Quit");
                    SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You have entered an incorrect password."); //Sends the client a error message
                }
                mysql_free_result(); //Remember to always free a result if you stored one!
            }
            return 1;
        }
And that worked fine, but this new cache stuff really doesn't seem to be working.
Reply
#2

I can fix the incorrect password error by doing this:

pawn Код:
case DIALOG_LOGIN: //Dialog login
        {
            if(!response) //If they click the cancel button
            {
                SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You have chosen to quit Domination Roleplay, please visit us again soon!");
                Kick(playerid);
            }
            if(response) //If the player clicked login
            {
                new query[210], pname[24], escapepass[100];//
                GetPlayerName(playerid, pname, 24); //Gets the players name
                mysql_real_escape_string(inputtext, escapepass); //We escape the inputtext to avoid SQL injections.
                format(query, sizeof(query), "SELECT `user` FROM playerdata WHERE user = '%s' AND password = SHA1('%s')", pname, escapepass);
                mysql_function_query(dbHandle, query, true, "LoadPlayerData", "i", playerid);
            }
            return 1;
        }
pawn Код:
forward LoadPlayerData(playerid);
public LoadPlayerData(playerid)
{
    new rows, fields, string[210];
    cache_get_data(rows, fields, dbHandle);

    if(!rows)
    {
        new savingstring[20];

        cache_get_field_content(0, "Level",savingstring, dbHandle);SetPlayerScore(playerid, strval(savingstring));
        cache_get_field_content(0, "Money",savingstring, dbHandle);MoneyGiven[playerid] = strval(savingstring);
        cache_get_field_content(0, "PlayerPosX",savingstring, dbHandle);PlayerVar[playerid][pPosX] = floatstr(savingstring);
        cache_get_field_content(0, "PlayerPosY",savingstring, dbHandle);PlayerVar[playerid][pPosY] = floatstr(savingstring);
        cache_get_field_content(0, "PlayerPosZ",savingstring, dbHandle);PlayerVar[playerid][pPosZ] = floatstr(savingstring);
        cache_get_field_content(0, "InteriorID",savingstring, dbHandle); PlayerVar[playerid][InteriorID] = strval(savingstring);
        cache_get_field_content(0, "SkinID",savingstring, dbHandle);PlayerVar[playerid][SkinID] = strval(savingstring);

        SetPlayerHealth(playerid, 100);
        TextDrawHideForPlayer(playerid, WIDESCREEN_TOP);
        TextDrawHideForPlayer(playerid, WIDESCREEN_BOTTOM);
        TextDrawHideForPlayer(playerid, WelcomeTD);
        TogglePlayerSpectating(playerid, 0);
        SetPVarInt(playerid, "prelogin", 0);
        SetPlayerWeapons(playerid);
        SetPlayerWeaponsEx(playerid);
        SendClientMessage(playerid, -1, "You have been logged in!"); //Sends the client a message.
        Logged[playerid] = 1; //Sets our logged in variable to one
        SetPlayerInterior(playerid, PlayerVar[playerid][InteriorID]);
        SetSpawnInfo(playerid, 0, PlayerVar[playerid][SkinID], PlayerVar[playerid][pPosX], PlayerVar[playerid][pPosY], PlayerVar[playerid][pPosZ], 0, 0, 0, 0, 0, 0, 0);
        SpawnPlayer(playerid);
    }
    else
    {
        //This means that the password that the player
        //typed was incorrect and we will resend the dialog.
        format(string, sizeof(string), "Welcome back, %s. Please enter your password below to log in.", GetName(playerid));
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", string, "Confirm", "Quit");
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You have entered an incorrect password."); //Sends the client a error message
    }
    return 1;
}
But then when I first enter the game it shows the dialog box to login and also asks as if I have already been logged in, then when I enter the correct password in the dialog box it re-logs me in. I will +rep you if you can help I have been stuck on this all day, thanks!
Reply
#3

Nevermind, got told cacheing sucks anyway, using R6 instead, thanks though!
Reply
#4

Quote:
Originally Posted by AphexCCFC
Посмотреть сообщение
Nevermind, got told cacheing sucks anyway, using R6 instead, thanks though!
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
You know where I can download the R6 plugin?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)