SA-MP Forums Archive
MySQL Logging player's Master Account in - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL Logging player's Master Account in (/showthread.php?tid=520120)



MySQL Logging player's Master Account in - AMouldyLemon - 17.06.2014

EDIT:
pawn Код:
forward MasterAccountLogin(playerid, password[]); // Login to an existing master account.
public MasterAccountLogin(playerid, password[])
{
    if(IsPlayerConnected(playerid))
    {
        if(AccountExists(playerid))
        {
            if(strlen(password) >= 1 && strlen(password) <= 20)
            {
                if(MasterAccount[playerid][mLoggedIn])
                {
                    /*new value[128], DBResult:qresult;
                    format(query, sizeof(query), "SELECT * FROM `MainAccount` WHERE ( `username` = '%s' AND `password` = '%s' )", sqlite_escape_string(PlayerName(playerid)), sqlite_escape_string(password));
                    qresult = mysql_query(database, query);
                    if(db_num_rows(qresult) >= 1)*/

                   
                    new rows, fields;
                    new value[128];
                    new query[128];
                    new qresult[128];
                    format(query, sizeof(query), "SELECT * FROM `MasterAccount` WHERE `username` = '%s' AND `mPassword` = '%s'", MasterAccount[playerid][mOriginalUsername] , MasterAccount[playerid][mPassword]);
                    cache_get_data(rows, fields);
                    if(rows >=1)
                    {
                        SetPlayerColor(playerid, COLOR_DARKGREY);// Logged in to master account, yellow = character not spawned.
                        MasterAccount[playerid][mLoggedIn] = true;
                        cache_get_row(qresult, "password", value, 20)format(MasterAccount[playerid][mPassword], 20, value); // 413
                        cache_get_row(qresult, "email_address", value, 30); format(MasterAccount[playerid][mEmailAddress], 30, value); // 414
                        cache_get_row(qresult, "ip_address", value, 20);    format(MasterAccount[playerid][mOld_IP], 20, value); // 415
                        cache_get_row(qresult, "super_admin", value, 5);    MasterAccount[playerid][mSuperAdmin] = strval(value); // 416
                        cache_get_row(qresult, "id", value, 15);    MasterAccount[playerid][mID] = strval(value); // 417
                        mysql_free_result(qresult);
                        ShowMenuDialog(playerid);
                        printf("Password: %s, Email Address: %s, Last IP Used: %s, Super Admin: %d, ID: %d.", MasterAccount[playerid][mPassword],  MasterAccount[playerid][mEmailAddress],  MasterAccount[playerid][mOld_IP], MasterAccount[playerid][mSuperAdmin], MasterAccount[playerid][mID]);
                        return true;
                    }
                    else
                    {
                        SetPVarInt(playerid, "LOGIN_ATTEMPTS", GetPVarInt(playerid, "LOGIN_ATTEMPTS") + 1);
                        switch(GetPVarInt(playerid, "LOGIN_ATTEMPTS"))
                        {
                            case 1: ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Master Account - Login","You entered an invalid password, you have three more attempts before you are auto-kicked.","Login","Cancel");
                            case 2: ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Master Account - Login","You entered an invalid password, you have two more attempts before you are auto-kicked.","Login","Cancel");
                            case 3: ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Master Account - Login","You entered an invalid password, you have one more attempt before you are auto-kicked.","Login","Cancel");
                            case 4: Kick(playerid);
                        }
                    }
                }
            }
            else
            {
                ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Master Account - Login","Account already registered, please enter your password to continue.","Login","Cancel");
            }
        }
    }
    return false;
}
pawn Код:
423) : error 035: argument type mismatch (argument 1)
(424) : error 035: argument type mismatch (argument 1)
(425) : error 035: argument type mismatch (argument 1)
(426) : error 035: argument type mismatch (argument 1)
(427) : error 035: argument type mismatch (argument 1)
(428) : error 017: undefined symbol "mysql_free_result"
Anyone?


Re: MySQL Logging player's Master Account in - Konstantinos - 17.06.2014

The first argument should be integer (rowid) and cache_get_row has the field index not the name. Assuming there'll only be 1 row for each player:
pawn Код:
cache_get_field_content(0, "password", MasterAccount[playerid][mPassword], 20);
cache_get_field_content(0, "email_address", MasterAccount[playerid][mEmailAddress], 30);
cache_get_field_content(0, "ip_address", MasterAccount[playerid][mOld_IP], 20);
cache_get_field_content(0, "super_admin", value, 5); MasterAccount[playerid][mSuperAdmin] = strval(value);
cache_get_field_content(0, "id", value, 15); MasterAccount[playerid][mID] = strval(value);
It'd be recommended to use the latest version of the mysql plugin (R39) and you can use cache_get_field_content_int to retrieve an integer value instead of using strval (plus it's much faster).


Re: MySQL Logging player's Master Account in - AMouldyLemon - 17.06.2014

Thanks, but I still get thus error:
pawn Код:
(428) : error 017: undefined symbol "mysql_free_result"



Re: MySQL Logging player's Master Account in - Konstantinos - 17.06.2014

That function wouldn't work for threaded queries anyways so it had been removed. By the way, you format the query and you use directly cache_get_data function without executing the query first. And because of the way threaded queries work, it will need to be in another callback.


Re: MySQL Logging player's Master Account in - AMouldyLemon - 17.06.2014

What..?
So I don't need mysql_free_result?


Re: MySQL Logging player's Master Account in - Konstantinos - 17.06.2014

No, you don't.

- A tutorial about threaded queries: https://sampforum.blast.hk/showthread.php?tid=337810
- An example script (for register/login) using threaded queries (R34+): https://github.com/pBlueG/SA-MP-MySQ...stem-cache.pwn


Re: MySQL Logging player's Master Account in - AMouldyLemon - 17.06.2014

I love you.


Re: MySQL Logging player's Master Account in - iZN - 17.06.2014

That's the magic of threaded queries. You don't have to worry about free'ing the result, it's automatically free'd (clears up the cache you've used inside that callback from the plugin data) once you return 1 the callback you've used for query.