Mysql Won't Create Account (R41-2)
#1

When i created my account. It don't call "OnAccountLoad" Or "OnAccountRegister".
It calls 'OnAccountCheck". When i join the server i register put in my password. then again i joined the server it still saids i need to register. what the problem can be?



Код:
enum pInfo
{
    pAdmin,
    pWork,
    StartingPoint,
    EndingPoint,
    pVIP,
    pConvoy,
    MissionID,
    ID,
    Password[129],
    VIP,
    Score,
    Money,
}
new PlayerInfo[MAX_PLAYERS][pInfo];
my server log saids:
Passed to connect to database! (so it is connected to mysql).
On Top Gamemode:
Код:
static Name[MAX_PLAYERS][24];
OnPlayerConnect:

Код:
    new query[128];
    mysql_format(mysql, query, sizeof(query), "SELECT `Password`, `ID` FROM `accounts` WHERE `Name` = '%e' LIMIT 1",  Name[playerid]);
    mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
OnPlayerDisconnect:
Код:
    new query[128], pname[MAX_PLAYER_NAME], string[39 + MAX_PLAYER_NAME];
    
    mysql_format(mysql, query, sizeof(query), "UPDATE `accounts` SET `Score`= %i WHERE `ID` = '%d'", GetPlayerScore(playerid), PlayerInfo[playerid][ID]);
    mysql_tquery(mysql, query, "", "");
Код:
public OnAccountCheck(playerid)
{
    new rows; //a variable that will be used to retrieve rows and fields in the database.
    cache_get_row_count(rows);//let's get the rows and fields from the database.
    if(rows) //if there is row
    {//then
        cache_get_value_name(0, "Password", PlayerInfo[playerid][Password],  129);
        //we will load player's password into pInfo[playerid][Password] to be used in logging in
        cache_get_value_name_int(0, "ID", PlayerInfo[playerid][ID]); //now let's load player's ID into pInfo[playerid][ID] so we can use it later
        printf("%s", PlayerInfo[playerid][Password]); //OPTIONAL: Just for debugging. If it didn't show your password, then there must be something wrong while getting player's password
        ShowPlayerDialog(playerid, dlogin, DIALOG_STYLE_INPUT, "Login", "In order to play, you need to login", "Login", "Quit"); //And since we found a result from the database, which means, there is an account; we will show a login dialog
    }
    else //if we didn't find any rows from the database, that means, no accounts were found
    {
        ShowPlayerDialog(playerid, dregister, DIALOG_STYLE_INPUT, "TruckingWorld: {FFFF00}Register", "In order to play, you need to register.", "Register", "Quit");
        //So we show them a dialog register
    }
    return 1;
}
forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
    cache_get_value_name_int(0, "Admin", PlayerInfo[playerid][pAdmin]);
    cache_get_value_name_int(0, "VIP", PlayerInfo[playerid][pVIP]);
    cache_get_value_name_int(0, "Score", PlayerInfo[playerid][Score]);
    cache_get_value_name_int(0, "Money", PlayerInfo[playerid][Money]);


    GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);

    SendClientMessage(playerid, -1, "You have successfully logged in.");
    return true;
}
forward OnAccountRegister(playerid);
public OnAccountRegister(playerid)
{
    PlayerInfo[playerid][ID] = cache_insert_id(); //loads the ID of the player in the variable once they registered.
    printf("TW Account ID: %d", PlayerInfo[playerid][ID]); //just for debugging.
    return 1;
}
Database Screenshot:
Reply
#2

Can you show us queries that execute "OnAccountLoad" and "OnAccountRegister" callbacks?
Reply
#3

OnDialogResponse:
Код:
switch(dialogid)
    {
        case LoginDialog:
        {
            if(!response) Kick(playerid);

            new hashpass[129], query[100];

            WP_Hash(hashpass, sizeof(hashpass), inputtext);
            if(!strcmp(hashpass, PlayerInfo[playerid][Password]))
            {
                mysql_format(mysql, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1", Name[playerid]);
                mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
            }
            else
            {
                SendClientMessage(playerid, -1, "You have specified an incorrect password!");
                ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT, "Login", "Welcome player!\nYour account has been found in our database. Please fill in your password:", "Login", "Quit");
            }
        }
        case RegisterDialog:
        {
            if(!response) return Kick(playerid);
            if(strlen(inputtext) < 5)
            {
                SendClientMessage(playerid, -1, "Your password must at least contain more than 4 characters.");
                return ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_INPUT, "Register", "Welcome player!\nYour account has not been registered yet. Please fill in your desired password:", "Register", "Quit");
            }
            new query[512], playerip[16];

            GetPlayerIp(playerid, playerip, sizeof(playerip));
            WP_Hash(PlayerInfo[playerid][Password], 129, inputtext);
            mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`) VALUES ('%e', '%e', '%e', 0, 0, 0)", Name[playerid], PlayerInfo[playerid][Password], playerip);
            mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
        }
    }
Funtion:

Код:
forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
    cache_get_value_name_int(0, "Admin", PlayerInfo[playerid][pAdmin]);
    cache_get_value_name_int(0, "VIP", PlayerInfo[playerid][pVIP]);
    cache_get_value_name_int(0, "Score", PlayerInfo[playerid][Score]);
    cache_get_value_name_int(0, "Money", PlayerInfo[playerid][Money]);


    GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);

    SendClientMessage(playerid, -1, "You have successfully logged in.");
    return true;
}
forward OnAccountRegister(playerid);
public OnAccountRegister(playerid)
{
    PlayerInfo[playerid][ID] = cache_insert_id(); //loads the ID of the player in the variable once they registered.
    printf("TW Account ID: %d", PlayerInfo[playerid][ID]); //just for debugging.
    return 1;
}
Reply
#4

This looks like an older version of MySQL to me.

Updated to R40+ Syntax:
Код:
forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
    cache_get_value_name_int(0, "Admin", PlayerInfo[playerid][pAdmin]);
    cache_get_value_name_int(0, "VIP", PlayerInfo[playerid][pVIP]);
    cache_get_value_name_int(0, "Score", PlayerInfo[playerid][Score]);
    cache_get_value_name_int(0, "Money", PlayerInfo[playerid][Money]);
    printf("%d | %d | %d | %d", PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pVIP], PlayerInfo[playerid][Score], PlayerInfo[playerid][Money]);
    GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);
    SetPlayerScore(playerid, PlayerInfo[playerid][Score]);

    SendClientMessage(playerid, -1, "You have successfully logged in.");
    return true;
}
Reply
#5

Quote:
Originally Posted by Logic_
Посмотреть сообщение
This looks like an older version of MySQL to me.

Код:
forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
    cache_get_value_name(0, "Admin", PlayerInfo[playerid][pAdmin]);
    cache_get_value_name(0, "VIP", PlayerInfo[playerid][pVIP]);
    cache_get_value_name(0, "Score", PlayerInfo[playerid][Score]);
    cache_get_value_name(0, "Money", PlayerInfo[playerid][Money]);

    GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);

    SendClientMessage(playerid, -1, "You have successfully logged in.");
    return true;
}
Hmm not sure. How does it go?
edit notice you had edited it
Reply
#6

Quote:
Originally Posted by DerickClark
Посмотреть сообщение
Hmm not sure.
Try changing your login function as I gave you above and leave us the results. Also, are you getting any errors or anything when you compile?

EDIT: I bet you learned anything from the tutorial or from wherever you found this code, you just copied and pasted it.
Reply
#7

Do you save player name into Name[playerid] variable under OnPlayerConnect?
Also change '%e' to '%s' on these queries:
Код:
SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1
INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`) VALUES ('%e', '%e', '%e', 0, 0, 0)
Quote:
Originally Posted by Logic_
Посмотреть сообщение
This looks like an older version of MySQL to me.

Updated to R40+ Syntax:
Код:
forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
    cache_get_value_name(0, "Admin", PlayerInfo[playerid][pAdmin]);
    cache_get_value_name(0, "VIP", PlayerInfo[playerid][pVIP]);
    cache_get_value_name(0, "Score", PlayerInfo[playerid][Score]);
    cache_get_value_name(0, "Money", PlayerInfo[playerid][Money]);

    GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);

    SendClientMessage(playerid, -1, "You have successfully logged in.");
    return true;
}
DerickClark's code is correct, he uses cache_get_value_name_int because those columns are integers.
Reply
#8

@X337
On Top Gamemode:

Код:
static Name[MAX_PLAYERS][24];
Код:
public OnPlayerConnect(playerid)
{
    new query[128];
    mysql_format(mysql, query, sizeof(query), "SELECT `Password`, `ID` FROM `Accounts` WHERE `Name` = '%e' LIMIT 1",  Name[playerid]);
    mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
}
Reply
#9

Quote:
Originally Posted by X337
Посмотреть сообщение
DerickClark's code is correct, he uses cache_get_value_name_int because those columns are integers.
Thank you for correcting me.

EDIT: No need to escape hashed password, they can be used be directly with %s identifier. Thing that player has control over must be escaped, for example a security question that you want to save in your database.
Reply
#10

Код:
public OnPlayerConnect(playerid)
{
    new query[128];
    GetPlayerName(playerid, Name[playerid], MAX_PLAYER_NAME);
    mysql_format(mysql, query, sizeof(query), "SELECT `Password`, `ID` FROM `Accounts` WHERE `Name` = '%s' LIMIT 1",  Name[playerid]);
    mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)