MySQL not saving account + setting random stats
#1

I have just followed NewbieNoob's tutorial and set everything. No warnings/errors but when player has registered, it gives them random stats and after relogging the account isn't saving. I am new to MySQL stuffs so can someone help me out?

pawn Код:
//OnPlayerConnect
new query[128];
mysql_format(mysql, query, sizeof(query),"SELECT `Password` FROM `players` WHERE `Name` = '%e' LIMIT 1", pInfo[playerid][PlayerName]);
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);

// Login and Register dialogs
Dialog_Register(playerid, response, inputtext[])
{
    new str[128], Name[24];
    GetPlayerName(playerid, Name, sizeof(Name));
    if (!response)
    {
        format(str, 129, "%s has been kicked from the server! [Quitting the Register Dialog]", Name);
        SendClientMessageToAll(RED, str);
        SendClientMessage(playerid, DARK_RED, "You must Register your Account before entering the server!");
        Timer_Disconnect[playerid] = SetTimerEx("DisconnectPlayer", 100, false, "d", playerid);
    }
    if(response)
    {
        new query[300];
        if(strlen(inputtext) > 6)
        {
            WP_Hash(pInfo[playerid][Password], 129, inputtext);
            mysql_format(mysql, query, sizeof(query), "INSERT INTO `players` (`Name`, `Password`, `Level`, `Money`, `Score`, `VIP`, `MoneyBoost` ,`BoostTime`, `Jailed`, `Wanted`, `Banned`, `TBanned`, `TBanTime`, `License`, `PoliceStats`, `MetersDriven`, `TruckerJobs`, `Assisted`, `Convoys`, `Flights`, `Fines`, `JailedPlayers`) VALUES ('%e', '%s', '%s', 0,0,0,0,0,0,0,0,0,0,0,0.0,0,0,0,0,0,0)",
            Name,
            pInfo[playerid][Password],
            pInfo[playerid][AdminLevel],
            pInfo[playerid][Money],
            pInfo[playerid][Score],
            pInfo[playerid][VIP],
            pInfo[playerid][MoneyBoost],
            pInfo[playerid][BoostTime],
            pInfo[playerid][Jailed],
            pInfo[playerid][WantedLevel],
            pInfo[playerid][Banned],
            pInfo[playerid][TempBanned],
            pInfo[playerid][BanTime],
            pInfo[playerid][TruckerLicense],
            pInfo[playerid][PoliceStats],
            pInfo[playerid][StatsMetersDriven],
            pInfo[playerid][StatsTruckerJobs],
            pInfo[playerid][StatsMechanic],
            pInfo[playerid][StatsConvoyJobs],
            pInfo[playerid][StatsPilotJobs],
            pInfo[playerid][StatsPoliceFined],
            pInfo[playerid][StatsPoliceJailed]);
            mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
            pInfo[playerid][LoggedIn] = true;
        }
        else
        {
            SendClientMessage(playerid, RED, "Your Password must contain at least 6 characters!");
            ShowPlayerDialog(playerid, DialogRegister, DIALOG_STYLE_PASSWORD, "{FFFFFF}REGISTER", "{FF8000}This account is not registered!\n\n{FFFFFF}Enter your Password bellow to register:", "Register", "");
        }
    }
    return 1;
}

Dialog_Login(playerid, response, inputtext[])
{
    new msg[128], Name[24];
    GetPlayerName(playerid, Name, sizeof(Name));
    if(!response)
    {
        format(msg, 128, "%s has been kicked from the server! [Quitting the Login Dialog]", Name);
        SendClientMessageToAll(RED, msg);
        SendClientMessage(playerid, DARK_RED, "You must Login to your Account before entering the server!");
        Timer_Disconnect[playerid] = SetTimerEx("DisconnectPlayer", 100, false, "d", playerid);
    }
    if(response)
    {
        new hpass[129]; new query[100];
        WP_Hash(hpass, 129, inputtext);
        if(!strcmp(hpass, pInfo[playerid][Password]))
        {
            mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `Name` = '%e' LIMIT 1", Name);
            mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
            BankFile_Load(playerid);
            pInfo[playerid][LoggedIn] = true;
        }
        else
        {
            ShowPlayerDialog(playerid, DialogRegister, DIALOG_STYLE_PASSWORD, "{FFFFFF}REGISTER", "{FF8000}This account is not registered!\n\n{FFFFFF}Enter your Password bellow to register:", "Register", "");
        }
    }
    return 1;
}

// Stock to save player's file
stock PlayerFile_Save(playerid)
{
    new query[128];
    mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET `Level`=%d, `Money`=%d, `Score`=%d, `VIP`=%d, `MoneyBoost`=%d, `BoostTime`=%d, `Jailed`=%d, `Wanted`=%d, `Banned`=%d, `TBanned`=%d, `TBanTime`=%d, `License`=%d, `PoliceStats`=%d, `MetersDriven`=%d, `TruckerJobs`=%d, `Assisted`=%d, `Convoys`=%d, `Flights`=%d, `Fines`=%d, `JailedPlayers`=%d WHERE `Name`= '%s'",
    pInfo[playerid][AdminLevel],
    pInfo[playerid][Money],
    pInfo[playerid][Score],
    pInfo[playerid][VIP],
    pInfo[playerid][MoneyBoost],
    pInfo[playerid][BoostTime],
    pInfo[playerid][Jailed],
    pInfo[playerid][WantedLevel],
    pInfo[playerid][Banned],
    pInfo[playerid][TempBanned],
    pInfo[playerid][BanTime],
    pInfo[playerid][TruckerLicense],
    pInfo[playerid][RulesRead],
    pInfo[playerid][PoliceStats],
    pInfo[playerid][StatsMetersDriven],
    pInfo[playerid][StatsTruckerJobs],
    pInfo[playerid][StatsMechanic],
    pInfo[playerid][StatsConvoyJobs],
    pInfo[playerid][StatsPilotJobs],
    pInfo[playerid][StatsPoliceFined],
    pInfo[playerid][StatsPoliceJailed]);
    mysql_tquery(mysql, query, "", "");
    return 1;
}

//Functions to load accounts
forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
    pInfo[playerid][AdminLevel] = cache_get_field_content_int(0, "Level");
    pInfo[playerid][Money] = cache_get_field_content_int(0, "Money");
    pInfo[playerid][Score] = cache_get_field_content_int(0, "Score");
    pInfo[playerid][VIP] = cache_get_field_content_int(0, "VIP");
    pInfo[playerid][MoneyBoost] = cache_get_field_content_int(0, "MoneyBoost");
    pInfo[playerid][BoostTime] = cache_get_field_content_int(0, "BoostTime");
    pInfo[playerid][Jailed] = cache_get_field_content_int(0, "Jailed");
    pInfo[playerid][WantedLevel] = cache_get_field_content_int(0, "Wanted");
    pInfo[playerid][Banned] = cache_get_field_content_int(0, "Banned");
    pInfo[playerid][TempBanned] = cache_get_field_content_int(0, "Tbanned");
    pInfo[playerid][BanTime] = cache_get_field_content_int(0, "TBanTime");
    pInfo[playerid][TruckerLicense] = cache_get_field_content_int(0, "License");
    pInfo[playerid][PoliceStats] = cache_get_field_content_int(0, "PoliceStats");
    pInfo[playerid][StatsMetersDriven] = cache_get_field_content_int(0, "MetersDriven");
    pInfo[playerid][StatsTruckerJobs] = cache_get_field_content_int(0, "TruckerJobs");
    pInfo[playerid][StatsMechanic] = cache_get_field_content_int(0, "Assisted");
    pInfo[playerid][StatsConvoyJobs] = cache_get_field_content_int(0, "Convoys");
    pInfo[playerid][StatsPilotJobs] = cache_get_field_content_int(0, "Flights");
    pInfo[playerid][StatsPoliceFined] = cache_get_field_content_int(0, "Fines");
    pInfo[playerid][StatsPoliceJailed] = cache_get_field_content_int(0, "JailedPlayers");
    return 1;
}

forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields, mysql);
    if(rows)
    {
        cache_get_field_content(0, "PASS", pInfo[playerid][Password], mysql, 129);
        ShowPlayerDialog(playerid, DialogLogin, DIALOG_STYLE_PASSWORD, "{FFFFFF}LOGIN", "{00FF00}Welcome back!\n\n{FFFFFF}Please enter your Password bellow to login:", "Login", "");
    }
    else
    {
        ShowPlayerDialog(playerid, DialogRegister, DIALOG_STYLE_PASSWORD, "{FFFFFF}REGISTER", "{FF8000}This account is not registered!\n\n{FFFFFF}Enter your Password bellow to register:", "Register", "");
    }
    return 1;
}
These are the scripts that i have added to my server. I can't find the mistakes as i don't know where they are. So need help!
Reply
#2

You have missed the ''.

pawn Код:
//For example

`Money` = '%d'
Reply
#3

Increase the size of the query in PlayerFile_Save because 128 is not enough.
Also in the query with the INSERT clause the placeholders do not match the arguments. If you're going to use default values directly, remove the unneeded arguments or else add more placeholders.
Reply
#4

That still didn't work. Its the same as before. I have increased the querry's size to 1000 (is that ok?)
Also checked the placeholders and set them properly but not working.
Reply
#5

Check the mysql logs and debug it: print the queries.
Reply
#6

Edit: Oh i misunderstood your message. But it didn't work still. I don't know whats wrong on it.

It says the connection was successful and all. Its connected to db already. I guess something is wrong on the script?
Reply
#7

By printing the queries, you'll be able to see if the whole text is stored. Also in case there is any error in the MySQL syntax, it'll be easier to find it. That's what you need to check in the mysql logs, any errors/warnings are given.

Without those info, it's kind of impossible not only for me but for everyone else to find the problem.

An example script can be found here: https://github.com/pBlueG/SA-MP-MySQ...stem-cache.pwn
in case you're interested.
Reply
#8

So i figured it out, the hashed password length was causing it. I removed the password hashing system and it worked perfectly.

But i also want to keep the hashing system. How can i make it working properly with hash password? I tried increasing the query size to 1000 and 1000 length for hashed password and other data wasn't enough. And if i increase the length more than 1000, it gives me large code size warning. I am using Whirlpool for hashing the password and it makes the password's length like 200+ characters (i guess)
Reply
#9

Whirlpool hashes the passwords to 128 characters + NULL.

Queries can be more than 1000 characters, however it is recommended to try reduing it as much as you can. For example, you can use default values while creating the table so you won't need to insert the default values in the query. Removing some spaces and the grave accent marks around table/fields' name will reduce the characters too.
Reply
#10

Hm, i have no idea why but whenever i hash the password using whirlpool, everything gets messed up and if i remove hashing function, it gets back to normal 0_o

I have hashed the password and increased the query size a bit but nothing happened. The bug is only appearing when i hash the password. Else everything is fine.

Any idea about that? I still need to fix this issue :/

This is the log that i have printed. Incase if its helpful to find out the problem
Код:
[16:48:55] [join] Oxide has joined the server (0:192.168.1.2)
[16:48:59] INSERT INTO `players` (Username, Password, Admin, VIP, Money, Score, Banned ,WantedLevel, License, PoliceStats, TruckerJobs, Convoys, Fines, JailedPlayers, MoneyBoost) VALUES ('Oxide', 'F3C0137053558D7B2B2EABBD1CE634BE2A83B9E926F1715EE270B47259933FD52030A3166C586D160E04ADB605C14ED710C9AE8FE7A9FB1D2BADA96A52142FF2', 65, 69, 56, 70, 70, 55, 50, 52, 0, 0 , 0, 0, 49)
The values are set with some random numbers after hashing the password. It gets back to normal when i remove the hash.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)