SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 12/12/2013, 09:07 PM   #1
KickInTheMick
Banned
 
Join Date: Mar 2013
Posts: 36
Reputation: 4
Default MYsql login/register won't login

pawn Code:
#include <a_samp>
#include <a_mysql>
#include <zcmd>
#include <sscanf2>
#include <foreach>
#include <streamer>
native WP_Hash(buffer[], len, const str[]);

//MySQL connection handle
new gHandle;

//player data
enum E_PLAYERS
{
    ID,
    Name[MAX_PLAYER_NAME],
    Password[129],
    Money,
    Score,

    bool:IsLoggedIn,
    bool:IsRegistered,
    LoginAttempts,
    LoginTimer
};
new Player[MAX_PLAYERS][E_PLAYERS];

//dialog data
enum {
    DIALOG_UNUSED,

    DIALOG_LOGIN,
    DIALOG_REGISTER,
};

public OnGameModeInit()
{
    mySQL_init();
    return 1;
}

public OnGameModeExit()
{
    mysql_close(gHandle);
    return 1;
}

stock mySQL_init()
{
    mysql_debug(1);
    gHandle = mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);

    /* Table Structure - kind of messy, I know. */
    mysql_function_query(gHandle, "CREATE TABLE IF NOT EXISTS `players` ( \
            `id` int(11) NOT NULL AUTO_INCREMENT, \
            `username` varchar(24) NOT NULL, \
            `password` varchar(129) NOT NULL, \
            `money` int(11) NOT NULL, \
            `skin` int(11) NOT NULL, \
            PRIMARY KEY (`id`) \
    )"
, false, "SendQuery", "");
    return 1;
}

forward SendQuery();
public SendQuery()
{
    return 1;
}

public OnPlayerConnect(playerid)
{
    SetTimerEx("SafeOnPlayerConnect", 250, 0, "d", playerid);
    return 1;
}

forward SafeOnPlayerConnect(playerid);
public SafeOnPlayerConnect(playerid)
{
        Player[playerid][IsLoggedIn] = true;
        CheckAccount(playerid);
        return 1;
}

public OnPlayerDisconnect(playerid,reason)
{
    SaveAccount(playerid);
    return 1;
}

stock CheckAccount(playerid)
{
        new query[82];

        format(query, sizeof(query), "SELECT id, password FROM `players` WHERE `username` = '%s' LIMIT 1", GetName(playerid));
        mysql_function_query(gHandle, query, true, "OnAccountCheck", "d", playerid);
        return 1;
}

forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
    if(playerid != INVALID_PLAYER_ID)
    {
        new rows, fields, string[128];
        cache_get_data(rows, fields, gHandle);

        if(rows)
        {
            Player[playerid][ID] = cache_get_row_int(0, 0, gHandle);
            cache_get_row(0, 2, Player[playerid][Password], gHandle, 129);
            format(string, sizeof(string), CHAT_WHITE "This account (" CHAT_YELLOW "%s" CHAT_WHITE ") is registered. Please login by entering your password in the field below:", GetName(playerid));
            ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", string, "Login", "Abort");
            Player[playerid][IsRegistered] = true;
        }

        else
        {
            format(string, sizeof(string), CHAT_WHITE "Welcome " CHAT_YELLOW "%s" CHAT_WHITE ", you can register by entering your password in the field below:", GetName(playerid));
            ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registration", string, "Register", "Abort");
            Player[playerid][IsRegistered] = false;
        }
    }
    return 1;
}


public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_LOGIN:
        {
            if(!response)
                return Kick(playerid);

            new hashed_pass[129];
            WP_Hash(hashed_pass, sizeof(hashed_pass), inputtext);

            if(strcmp(hashed_pass, Player[playerid][Password]) == 0)
            {
                Player[playerid][IsLoggedIn] = true;
                LoadAccount(playerid);
            }
            else
            {
                Player[playerid][LoginAttempts]++;
                if(Player[playerid][LoginAttempts] >= 3)
                {
                    ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Login", "You have mistyped your password too often (3 times).", "Okay", "");
                    DelayedKick(playerid);
                }
                else
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Wrong password!\nPlease enter your password in the field below:", "Login", "Abort");
            }
        }

        case DIALOG_REGISTER:
        {
            if(!response) return Kick(playerid);
            if(strlen(inputtext) <= 3)
                return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registration",
            "Your password must be longer than 3 characters!\nPlease enter your password in the field below:",
            "Register", "Abort");

            new Hashpass[129];
            WP_Hash(Hashpass, sizeof(Hashpass), inputtext);
            CreateAccount(playerid, Hashpass);
        }
        default: return 0;
    }
    return 1;
}

stock LoadAccount(playerid)
{
    new query[128];

    format(query, sizeof(query), "SELECT * FROM `players` WHERE `id` = %d", Player[playerid][ID]);
    mysql_function_query(gHandle, query, true, "OnAccountLoad", "d", playerid);
}

forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
    new temp[40];
    format(temp, sizeof(temp), "SERVER: Welcome %s", GetName(playerid));
    SendClientMessage(playerid, -1, temp);

    Player[playerid][Money]   = cache_get_row_int(0, 3, gHandle),
    Player[playerid][Score]   = cache_get_row_int(0, 4, gHandle);
    return 1;
}

stock CreateAccount(playerid, pass[129])
{
        new query[240];
        format(query, sizeof(query), "INSERT INTO `players` (username, password) VALUES (\'%s\', \'%s\')",
                GetName(playerid),
                pass
        );

        mysql_function_query(gHandle, query, false, "OnAccountCreate", "d", playerid);
}

forward OnAccountCreate(playerid);
public OnAccountCreate(playerid)
{
        Player[playerid][ID] = mysql_insert_id();
        return 1;
}

stock SaveAccount(playerid)
{
        new query[300];
        new money, score;
        money = GetPlayerMoney(playerid);
        score = GetPlayerScore(playerid);

        format(query, sizeof(query), "UPDATE `players` SET money = %d, score = %d WHERE `id` = %d",
                money,
                score,
                Player[playerid][ID]
        );

        mysql_function_query(gHandle, query, false, "SendQuery", "");
        return 1;
}

I will rep you if you help me, Thanks;
KickInTheMick is offline   Reply With Quote
Old 13/12/2013, 06:25 AM   #2
RenSoprano
Huge Clucker
 
Join Date: Oct 2011
Location: Bansko, Bulgaria
Posts: 437
Reputation: 44
Default Re: MYsql login/register won't login

Post your mysql log
__________________

Last edited by RenSoprano; 13/12/2013 at 08:23 AM.
RenSoprano is offline   Reply With Quote
Old 13/12/2013, 07:06 AM   #3
BizzyD
Gangsta
 
BizzyD's Avatar
 
Join Date: Jan 2011
Location: Home
Posts: 879
Reputation: 66
Default Re: MYsql login/register won't login

Post your mysql.log
__________________
We never fail, we only shine with brilliance. One king one faith one religion. And if you hear me come and join the revolution
BizzyD is offline   Reply With Quote
Old 13/12/2013, 08:24 AM   #4
KickInTheMick
Banned
 
Join Date: Mar 2013
Posts: 36
Reputation: 4
Default Re: MYsql login/register won't login

Code:
[00:01:19] [DEBUG] CMySQLHandle::Create - creating new connection..
[00:01:19] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called
[00:01:19] [DEBUG] CMySQLHandle::Create - connection created with ID = 1
[00:01:19] [DEBUG] CMySQLConnection::Connect - connection was successful
[00:01:19] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[00:01:20] [DEBUG] CMySQLConnection::Connect - connection was successful
[00:01:20] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[00:01:20] [DEBUG] mysql_tquery - connection: 1, query: "CREATE TABLE IF NOT EXISTS `players` ( `id` int(11) NOT NULL AUT", callback: "SendQuery", format: "(null)"
[00:01:20] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[00:01:20] [DEBUG] mysql_tquery - scheduling query "CREATE TABLE IF NOT EXISTS `players` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(24) NOT NULL, `password` varchar(129) NOT NULL, `money` int(11) NOT NULL, `skin` int(11) NOT NULL, PRIMARY KEY (`id`) )"..
[00:01:20] [DEBUG] CMySQLQuery::Execute[SendQuery()] - starting query execution
[00:01:20] [DEBUG] CMySQLQuery::Execute[SendQuery()] - query was successful
[00:01:20] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[00:01:20] [DEBUG] CMySQLQuery::Execute[SendQuery()] - data being passed to ProcessCallbacks()
[00:01:20] [DEBUG] Calling callback "SendQuery"..
[00:01:20] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[00:01:20] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[00:01:44] [DEBUG] mysql_tquery - connection: 1, query: "SELECT id, password FROM `players` WHERE `username` = 'Arthur_Mi", callback: "OnAccountCheck", format: "d"
[00:01:44] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[00:01:44] [DEBUG] mysql_tquery - scheduling query "SELECT id, password FROM `players` WHERE `username` = 'Arthur_Millere' LIMIT 1"..
[00:01:44] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(d)] - starting query execution
[00:01:44] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(d)] - query was successful
[00:01:44] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[00:01:44] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(d)] - data being passed to ProcessCallbacks()
[00:01:44] [DEBUG] Calling callback "OnAccountCheck"..
[00:01:44] [DEBUG] cache_get_data - connection: 1
[00:01:44] [DEBUG] cache_get_row_int - row: 0, field_idx: 0, connection: 1
[00:01:44] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '0', data: "346"
[00:01:44] [DEBUG] cache_get_row - row: 0, field_idx: 2, connection: 1, max_len: 129
[00:01:44] [WARNING] CMySQLResult::GetRowData - invalid row ('0') or field index ('2')
[00:01:44] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[00:01:44] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[00:02:01] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `players` SET money = 0, score = 0 WHERE `id` = 346", callback: "SendQuery", format: "(null)"
[00:02:01] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[00:02:01] [DEBUG] mysql_tquery - scheduling query "UPDATE `players` SET money = 0, score = 0 WHERE `id` = 346"..
[00:02:01] [DEBUG] CMySQLQuery::Execute[SendQuery()] - starting query execution
[00:02:02] [DEBUG] CMySQLQuery::Execute[SendQuery()] - query was successful
[00:02:02] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[00:02:02] [DEBUG] CMySQLQuery::Execute[SendQuery()] - data being passed to ProcessCallbacks()
[00:02:02] [DEBUG] Calling callback "SendQuery"..
[00:02:02] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[00:02:02] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[00:02:29] [DEBUG] mysql_tquery - connection: 1, query: "SELECT id, password FROM `players` WHERE `username` = 'Arthur_Mi", callback: "OnAccountCheck", format: "d"
[00:02:29] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[00:02:29] [DEBUG] mysql_tquery - scheduling query "SELECT id, password FROM `players` WHERE `username` = 'Arthur_Mille' LIMIT 1"..
[00:02:29] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(d)] - starting query execution
[00:02:30] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(d)] - query was successful
[00:02:30] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[00:02:30] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(d)] - data being passed to ProcessCallbacks()
[00:02:30] [DEBUG] Calling callback "OnAccountCheck"..
[00:02:30] [DEBUG] cache_get_data - connection: 1
[00:02:30] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[00:02:30] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[00:02:37] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO `players` (username, password) VALUES ('Arthur_Mille", callback: "OnAccountCreate", format: "d"
[00:02:37] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[00:02:37] [DEBUG] mysql_tquery - scheduling query "INSERT INTO `players` (username, password) VALUES ('Arthur_Mille', 'FD9D94340DBD72C11B37EBB0D2A19B4D05E00FD78E4E2CE8923B9EA3A54E900DF181CFB112A8A73228D1F3551680E2AD9701A4FCFB248FA7FA77B95180628BB2')"..
[00:02:37] [DEBUG] CMySQLQuery::Execute[OnAccountCreate(d)] - starting query execution
[00:02:37] [DEBUG] CMySQLQuery::Execute[OnAccountCreate(d)] - query was successful
[00:02:37] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[00:02:37] [DEBUG] CMySQLQuery::Execute[OnAccountCreate(d)] - data being passed to ProcessCallbacks()
[00:02:37] [DEBUG] Calling callback "OnAccountCreate"..
[00:02:37] [DEBUG] cache_insert_id - connection: 1
[00:02:37] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[00:02:37] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[00:02:47] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `players` SET money = 1000, score = 1000 WHERE `id` = 586", callback: "SendQuery", format: "(null)"
[00:02:47] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[00:02:47] [DEBUG] mysql_tquery - scheduling query "UPDATE `players` SET money = 1000, score = 1000 WHERE `id` = 586"..
[00:02:47] [DEBUG] CMySQLQuery::Execute[SendQuery()] - starting query execution
[00:02:47] [DEBUG] CMySQLQuery::Execute[SendQuery()] - query was successful
[00:02:47] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[00:02:47] [DEBUG] CMySQLQuery::Execute[SendQuery()] - data being passed to ProcessCallbacks()
[00:02:47] [DEBUG] Calling callback "SendQuery"..
[00:02:47] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[00:02:47] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[00:03:10] [DEBUG] mysql_tquery - connection: 1, query: "SELECT id, password FROM `players` WHERE `username` = 'Arthur_Mi", callback: "OnAccountCheck", format: "d"
[00:03:10] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[00:03:10] [DEBUG] mysql_tquery - scheduling query "SELECT id, password FROM `players` WHERE `username` = 'Arthur_Mille' LIMIT 1"..
[00:03:10] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(d)] - starting query execution
[00:03:10] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(d)] - query was successful
[00:03:10] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[00:03:10] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(d)] - data being passed to ProcessCallbacks()
[00:03:10] [DEBUG] Calling callback "OnAccountCheck"..
[00:03:10] [DEBUG] cache_get_data - connection: 1
[00:03:10] [DEBUG] cache_get_row_int - row: 0, field_idx: 0, connection: 1
[00:03:10] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '0', data: "586"
[00:03:10] [DEBUG] cache_get_row - row: 0, field_idx: 2, connection: 1, max_len: 129
[00:03:10] [WARNING] CMySQLResult::GetRowData - invalid row ('0') or field index ('2')
[00:03:10] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[00:03:10] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[00:03:15] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `players` SET money = 0, score = 0 WHERE `id` = 586", callback: "SendQuery", format: "(null)"
[00:03:15] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[00:03:15] [DEBUG] mysql_tquery - scheduling query "UPDATE `players` SET money = 0, score = 0 WHERE `id` = 586"..
[00:03:15] [DEBUG] CMySQLQuery::Execute[SendQuery()] - starting query execution
[00:03:16] [DEBUG] CMySQLQuery::Execute[SendQuery()] - query was successful
[00:03:16] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[00:03:16] [DEBUG] CMySQLQuery::Execute[SendQuery()] - data being passed to ProcessCallbacks()
[00:03:16] [DEBUG] Calling callback "SendQuery"..
[00:03:16] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[00:03:16] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
KickInTheMick is offline   Reply With Quote
Old 13/12/2013, 08:41 AM   #5
BizzyD
Gangsta
 
BizzyD's Avatar
 
Join Date: Jan 2011
Location: Home
Posts: 879
Reputation: 66
Default Re: MYsql login/register won't login

What happends when you login?
You dont spawn or what?
__________________
We never fail, we only shine with brilliance. One king one faith one religion. And if you hear me come and join the revolution
BizzyD is offline   Reply With Quote
Old 13/12/2013, 06:07 PM   #6
RenSoprano
Huge Clucker
 
Join Date: Oct 2011
Location: Bansko, Bulgaria
Posts: 437
Reputation: 44
Default Re: MYsql login/register won't login

Hmm, it will be show us your databas pic
__________________
RenSoprano 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
[FilterScript] Register & Login system (verification code + return password + auto login [by ip]) benel1 Filterscripts 20 26/11/2014 09:05 PM
Textdraw during login and register problem|shows only for login or register FireWarrior101 Scripting Help 6 05/10/2013 05:16 PM
help i have register and login no work pls help he login but player must make /register alking282 Scripting Help 11 16/04/2012 07:04 AM
Mysql Register Login BaranHyrn Scripting Help 0 21/12/2011 06:33 PM
MySQL Login And Register quite_scream Help Archive 2 16/02/2010 02:13 PM


All times are GMT. The time now is 09:32 PM.


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