Weird MySQL issue
#1

Hi, so I have decided to make a system where players can have their main accounts and register up to 3 characters in it. Everything is working fine except the characters won't show to the player when he successfully logins to his main account.. Here's the code:

pawn Code:
forward OnPasswordChecked(playerid);
public OnPasswordChecked(playerid)
{
    new bool:match = bcrypt_is_equal();
    if(match)
    {
        new userid = PlayerInfo[playerid][UserID];
        new query[500];
        mysql_format(Database, query, sizeof(query), "SELECT * FROM `characters` WHERE `AccountID` = '%i'", userid);
        mysql_pquery(Database, query, "SelectCharForPlayer", "dd", playerid, userid);
    }
    else
    {
        new string[300];
        format(string, sizeof(string), "Wrong Password!\nPlease type your correct password below.");
        Dialog_Show(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", string, "Login", "Exit");
    }
    return 1;
}
pawn Code:
forward SelectCharForPlayer(playerid, userid);
public SelectCharForPlayer(playerid, userid)
{
    new charactername[24], characterage, charactergender[50], string[500], charinfo[500];
   
    if(cache_num_rows())
    {
        for(new i = 0; i < cache_num_rows(); i++)
        {
            cache_get_value_name(i, "CharacterName", charactername, 24);
            cache_get_value_name(i, "CharacterGender", charactergender, 50);
            cache_get_value_name_int(i, "CharacterAge", characterage);
       
            format(charinfo, sizeof(charinfo), "{FFFFFF}Name: %s - Gender: %s - Age: %d\n", charactername, charactergender, characterage);
            strcat(string, charinfo);
           
            Dialog_Show(playerid, DIALOG_SELECTCHARACTER, DIALOG_STYLE_LIST, "{FFFFFF}Character Selection", string, "Continue", "Exit");
        }
    }
    else
    {
        SendClientMessage(playerid, COLOR_WHITE, "You don't have any character registered on your account ID.");
    }
    return 1;
}
It says I don't have any character registered on my account ID (which is UserID) but I do have 2 registered on that ID, so it's really weird..
Reply
#2

Check this:
Quote:

new userid = PlayerInfo[playerid][UserID];

Also, change
Quote:

SendClientMessage(playerid, COLOR_WHITE, "You don't have any character registered on your account ID.");

Make it output the userid itself, so you can make sure the id is actually correct.

When you have no mysql errors, the problem will usualy be in one of the variables, so u gotta debug it fist.
Reply
#3

Quote:
Originally Posted by ch1ps
View Post
Check this:

Also, change

Make it output the userid itself, so you can make sure the id is actually correct.

When you have no mysql errors, the problem will usualy be in one of the variables, so u gotta debug it fist.
Right, the id is not correct. It gets executed as 0 no matter what the ID is, it should be 16 instead..
Reply
#4

Quote:
Originally Posted by Y_Less
View Post
How are you calling BCrypt? It probably isn't passing the playerid to the callback.
pawn Code:
Dialog:DIALOG_LOGIN(playerid, response, listitem, inputtext[])
{
    if(response)
    {
        new query[500], Password[BCRYPT_HASH_LENGTH];
        mysql_format(Database, query, sizeof(query), "SELECT `Password` FROM `players` WHERE `Username` = '%e'", GetName(playerid));
        mysql_query(Database, query);
        cache_get_value_name(0, "Password", Password, BCRYPT_HASH_LENGTH);
        bcrypt_check(inputtext, Password, "OnPasswordChecked", "i", playerid);
    }
    else
        return Kick(playerid);
    return 1;
}
Here.
Reply
#5

You never retrieved userid so there are no rows. Select userid and password only once, when they connect to determinate if they are registered or not. There is no point to select the password every time the player responds to login dialog.

You also forgot to delete the cache. If you do it correctly, all this can be done with threaded queries.
Reply
#6

The problem is the line i mentioned in my first quote, the user info was never fetched thats why it shows 0.
Make a function that fetches the userid by the user's name. Use that instead
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)