Slow response time when log-in -
polygxn - 08.02.2019
Hi! So I just started learning PAWN like one week ago so if you notice any stupid things in my code just please go ahead and tell me how can I improve it, whats the better way to do that certain thing.
So, my problem is when I click "Login" it takes at least 3-4 seconds to spawn me. Okay, this is a long time but I feel like I just screwed up something in my code what causes this 3-4 second delay on each and every log-in.
So here is the textdraw where I click when I want to log-in:
PHP код:
if(playertextid == Login_Textdraw22[playerid])
{
new query[128];
mysql_format(g_sql, query, sizeof query, "SELECT * FROM characters WHERE Name = '%e' LIMIT 1", PlayerName(playerid));
mysql_tquery(g_sql, query, "SetPlayerLogin", "i", playerid);
}
Here is the SetPlayerLogin:
PHP код:
forward SetPlayerLogin(playerid);
public SetPlayerLogin(playerid)
{
new query[128], password[129], string[128];
if(!cache_num_rows())
{
format(string, sizeof(string), "Account unregistered! Type a in a password and click register!");
ErrorTag(playerid, string);
}
else
{
WP_Hash(password, 129, DialogPassword);
cache_get_value_name(0, "Password", pInfo[playerid][pPassword], 129);
cache_get_value_name_int(0, "DBID", pInfo[playerid][pID]);
if(!strcmp(password, pInfo[playerid][pPassword]))
{
mysql_format(g_sql, query, sizeof(query), "SELECT * FROM `characters` WHERE `Name` = '%e' LIMIT 1", PlayerName(playerid));
mysql_tquery(g_sql, query, "OnPlayerLoad", "i", playerid);
}
else
{
format(string, sizeof(string), "Wrong password!");
ErrorTag(playerid, string);
}
}
}
Here is the OnPlayerLoad:
PHP код:
forward OnPlayerLoad(playerid);
public OnPlayerLoad(playerid)
{
cache_get_value_name_int(0, "Skin", pInfo[playerid][pSkin]);
cache_get_value_name_int(0, "Admin", pInfo[playerid][pAdmin]);
SetSpawnInfo(playerid, 0, pInfo[playerid][pSkin], 1554.9028, -1621.7440, 13.5469, 277.4472, 0, 0, 0, 0, 0, 0);
TogglePlayerSpectating(playerid, false);
SpawnPlayer(playerid);
pInfo[playerid][pLoggedIn] = true;
DLoginTextdraw(playerid);
CancelSelectTextDraw(playerid);
ClearChat();
return 1;
}
Honestly I can take a 3-4 second delay but I want to learn, and correct my faults to not do them over and over. If anyone need any more code, or information about the login system to investigate this, just comment. Thank you!
Re: Slow response time when log-in -
Calisthenics - 08.02.2019
First and foremost, why do you select everything just to retrieve only `Password` and `DBID`? Select only these two columns.
An account name is unique, therefore set `Name` as UNIQUE KEY.
`DialogPassword` can be overwritten because of threaded queries. You need a player-array.
When the two passwords match, select the rest (`Skin`, `Admin`) and not everything again. But more importantly, you now know the `DBID` so replace
WHERE `Name` with
WHERE `DBID`
Re: Slow response time when log-in -
polygxn - 13.02.2019
Well thank you for the information! I completely re-wrote the login-register system with all of the information I got since I created the post and its fine now. The problem was that I selected everything from the table most of the times, even outside this code. Thank you again!
Re: Slow response time when log-in -
polygxn - 13.02.2019
Thank you aswell ******. I just implemented bcrypt rather than whirpool. I dont feel any improvement in speed tho but its probably much more safe and etc, I just need to learn more about it!