Slow response time when log-in
#1

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_sqlquerysizeof query"SELECT * FROM characters WHERE Name = '%e' LIMIT 1"PlayerName(playerid));
           
mysql_tquery(g_sqlquery"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(stringsizeof(string), "Account unregistered! Type a in a password and click register!");
        
ErrorTag(playeridstring);
    }
    else
    {
        
WP_Hash(password129DialogPassword);
        
cache_get_value_name(0"Password"pInfo[playerid][pPassword], 129);
        
cache_get_value_name_int(0"DBID"pInfo[playerid][pID]);
        if(!
strcmp(passwordpInfo[playerid][pPassword]))
        {
            
mysql_format(g_sqlquerysizeof(query), "SELECT * FROM `characters` WHERE `Name` = '%e' LIMIT 1"PlayerName(playerid));
            
mysql_tquery(g_sqlquery"OnPlayerLoad""i"playerid);
        }
        else
        {
            
format(stringsizeof(string), "Wrong password!");
            
ErrorTag(playeridstring);
        }
    }

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(playerid0pInfo[playerid][pSkin], 1554.9028, -1621.744013.5469277.4472000000);
    
TogglePlayerSpectating(playeridfalse);
    
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!
Reply
#2

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`
Reply
#3

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!
Reply
#4

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)