Register bug
#1

Can someone fuckin' tell me why the fuck the server ask me always to register even if i have already an account?

This is OnPlayerConnect which handles the system:

Код:
new query[300], pname[24];
    GetPlayerName(playerid, pname, 24);
    format(query, sizeof(query), "SELECT IP FROM `players` WHERE Username = '%s' LIMIT 1", pname);
    mysql_function_query(mConnectionHandle, query, false, "", "");
    mysql_store_result();

	new rows = mysql_num_rows();
    if(!rows)
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""White"Please register",""White"Welcome to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to register!\n\n"White"Please insert a password below:", "Register", "Cancel");
    }
    if(rows == 1)
    {
        mysql_fetch_field_row(IP[0],"IP");
        GetPlayerIp(playerid, IP[1], 15);
        if(strlen(IP[0]) != 0 && !strcmp(IP[0], IP[1], true))
        {
            MySQL_Login(playerid);
        }
        else if(!strlen(IP[0]) || strcmp(IP[0], IP[1], true))
        {
            ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""White"Please log-in", ""White"Welcome back to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to log-in!\n\n"White"Please insert "Red"your"White" password below:", "Login", "Cancel");
            IsRegistered[playerid] = 1;
        }
    }
    mysql_free_result();
	printf("%s", query);
Stats are saved perfectly without problems on quit, the only problem is i have to register AGAIN and AGAIN EVEN if the account ALREADY exists in database! (And it does, check screen)

http://s10.postimg.org/feg31yu5z/Immagine.jpg

Server log:

Quote:

[17:02:23] [join] okkkkk has joined the server (0:93.148.160.140)
[17:02:23] IsPlayerBanned called.
[17:02:23] SELECT IP FROM `players` WHERE Username = 'okkkkk' LIMIT 1

Mysql log:

Quote:

[17:02:23] [DEBUG] mysql_tquery - connection: 1, query: "SELECT * FROM `Bans` WHERE (`Username` = 'okkkkk' OR `IP` = '93.", callback: "(null)", format: "(null)"
[17:02:23] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[17:02:23] [DEBUG] mysql_tquery - scheduling query "SELECT * FROM `Bans` WHERE (`Username` = 'okkkkk' OR `IP` = 'HIDDEN IP') AND `Banned` = 1 LIMIT 1"..
[17:02:23] [DEBUG] cache_get_row_count - connection: 1
[17:02:23] [WARNING] cache_get_row_count - no active cache
[17:02:23] [DEBUG] mysql_tquery - connection: 1, query: "SELECT IP FROM `players` WHERE Username = 'okkkkk' LIMIT 1", callback: "(null)", format: "(null)"
[17:02:23] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[17:02:23] [DEBUG] mysql_tquery - scheduling query "SELECT IP FROM `players` WHERE Username = 'okkkkk' LIMIT 1"..
[17:02:23] [DEBUG] cache_get_row_count - connection: 1
[17:02:23] [WARNING] cache_get_row_count - no active cache
[17:02:23] [DEBUG] mysql_tquery - connection: 0, query: "UPDATE ServerStats SET TotalJoins = TotalJoins + 1", callback: "(null)", format: "(null)"
[17:02:23] [ERROR] "mysql_tquery" - invalid connection handle (ID = 0)
[17:02:23] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[17:02:23] [DEBUG] CMySQLQuery::Execute[()] - query was successful
[17:02:23] [DEBUG] CMySQLQuery::Execute[()] - no callback specified, skipping result saving
[17:02:23] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[17:02:23] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[17:02:23] [DEBUG] CMySQLQuery::Execute[()] - query was successful
[17:02:23] [DEBUG] CMySQLQuery::Execute[()] - no callback specified, skipping result saving
[17:02:23] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[17:02:23] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[17:02:23] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called

Reply
#2

Okay, you don't know how to properly use the MySQL.

Код:
mysql_function_query(MainPipeline, szQuery, true, "CheckIfPlayerExist", "i", playerid);
PHP код:
forward CheckIfPlayerExist(playerid);
public 
CheckIfPlayerExist(playerid)
{
    new 
szRowsszFieldsstring[256];
    
cache_get_data(szRowsszFields);
    if(
szRows)
    {
       
// Account Found
    
}
    else
    {
        
// NO account
    
}
    return 
1;

The reason why your code is not working is because MySQL has to be run in functions if they are threaded.
Reply
#3

I don't wanna check with IP because if client IP changes server will not find the account. I wanna check for username.

And i did already

Код:
 format(query, sizeof(query), "SELECT `players` WHERE Username = '%s' LIMIT 1", pname);
But nothing..
Reply
#4

Then we need to know if your password are hashed or something like that, we can't just make that for you.
Reply
#5

Yes they are, with Whirlpool.
Reply
#6

In your previous thread I've edited some stuff that wasn't needed. Some as restoring stats, register checks.

http://forum.sa-mp.com/showpost.php?...96&postcount=5
Reply
#7

Your problem is you need to put IP in ' ' for server to understand, thats why mysql never selects any rows, therefore everytime you login it sends you to register part. so the right way to do it would be

PHP код:
format(querysizeof(query), "SELECT 'IP' FROM `players` WHERE Username = '%s' LIMIT 1"pname); 
I got a couple suggestions for you tho,
A) user mysql_format and escape your strings using %e, there probably won't be a guy injecting your server with his username, but better be safe than sorry
PHP код:
    mysql_format(querysizeof(query), "SELECT 'id' FROM `players` WHERE Username = '%e' LIMIT 1"pname); 

B) It's recommended to user mysql_tquery to query your results (cuz if you don't and you make kinda heavy queries your server would go onto deathmode for a couple secs until its done - at least thats what I heard) so instead of mysql_function query use:

PHP код:
mysql_tquery(mConnectionHandlequery"OnAccountLoad""i"playerid); 
PHP код:
public OnAccountLoad(playerid)
{
    new 
rows mysql_num_rows();
    if(!
rows)
    {
        
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_INPUT""White"Please register",""White"Welcome to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to register!\n\n"White"Please insert a password below:""Register""Cancel");
    }
    if(
rows == 1)
    {
        
mysql_fetch_field_row(IP[0],"IP");
        
GetPlayerIp(playeridIP[1], 15);
        if(
strlen(IP[0]) != && !strcmp(IP[0], IP[1], true))
        {
            
MySQL_Login(playerid);
        }
        else if(!
strlen(IP[0]) || strcmp(IP[0], IP[1], true))
        {
            
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT""White"Please log-in"""White"Welcome back to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to log-in!\n\n"White"Please insert "Red"your"White" password below:""Login""Cancel");
            
IsRegistered[playerid] = 1;
        }
    }

C) Anyway if you don't wanna check IP, delete everything under "if(rows==1)" and just put
PHP код:
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT""White"Please log-in"""White"Welcome back to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to log-in!\n\n"White"Please insert "Red"your"White" password below:""Login""Cancel"); 
or check w/e you like




Hope I helped you, good luck and have fun scripting.
Reply
#8

Pro.Gamer thanks for help but same problem. Stats are loaded but it asks me to register again..

Server log:

Quote:

[17:42:51] SELECT 'IP' FROM `players` WHERE Username = 'e' LIMIT 1
[17:42:56] [connection] 93.******** requests connection cookie.
[17:42:57] [connection] incoming connection: 93.******* id: 1
[17:42:58] [join] Face9000 has joined the server (1:93.1********)
[17:42:58] IsPlayerBanned called.
[17:42:58] SELECT 'IP' FROM `players` WHERE Username = 'e' LIMIT 1
[17:43:07] [part] Face9000 has left the server (1:1)

Mysql log:

Quote:

[17:43:32] [DEBUG] mysql_tquery - connection: 1, query: "SELECT 'IP' FROM `players` WHERE Username = 'e' LIMIT 1", callback: "OnAccountLoad", format: "i"
[17:43:32] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[17:43:32] [DEBUG] mysql_tquery - scheduling query "SELECT 'IP' FROM `players` WHERE Username = 'e' LIMIT 1"..
[17:43:32] [DEBUG] mysql_tquery - connection: 0, query: "UPDATE ServerStats SET TotalJoins = TotalJoins + 1", callback: "(null)", format: "(null)"
[17:43:32] [ERROR] "mysql_tquery" - invalid connection handle (ID = 0)
[17:43:32] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[17:43:32] [DEBUG] CMySQLQuery::Execute[()] - query was successful
[17:43:32] [DEBUG] CMySQLQuery::Execute[()] - no callback specified, skipping result saving
[17:43:32] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[17:43:32] [DEBUG] CMySQLQuery::Execute[OnAccountLoad(i)] - starting query execution
[17:43:32] [DEBUG] CMySQLQuery::Execute[OnAccountLoad(i)] - query was successful
[17:43:32] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[17:43:32] [DEBUG] CMySQLQuery::Execute[OnAccountLoad(i)] - data being passed to ProcessCallbacks()
[17:43:32] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[17:43:32] [DEBUG] Calling callback "OnAccountLoad"..
[17:43:32] [DEBUG] cache_get_row_count - connection: 1
[17:43:32] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[17:43:32] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called

Reply
#9

SELECT Password, IP FROM `players` WHERE Username = '%e' LIMIT 1
Reply
#10

Same problem.

This register system is trolling me.

Mysql log:

Quote:

17:54:07] [DEBUG] mysql_tquery - connection: 1, query: "SELECT 'Password' FROM `players` WHERE Username = 'e' LIMIT 1", callback: "OnAccountLoad", format: "i"
[17:54:07] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[17:54:07] [DEBUG] mysql_tquery - scheduling query "SELECT 'Password' FROM `players` WHERE Username = 'e' LIMIT 1"..
[17:54:07] [DEBUG] mysql_tquery - connection: 0, query: "UPDATE ServerStats SET TotalJoins = TotalJoins + 1", callback: "(null)", format: "(null)"
[17:54:07] [ERROR] "mysql_tquery" - invalid connection handle (ID = 0)
[17:54:07] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[17:54:07] [DEBUG] CMySQLQuery::Execute[()] - query was successful
[17:54:07] [DEBUG] CMySQLQuery::Execute[()] - no callback specified, skipping result saving
[17:54:07] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[17:54:07] [DEBUG] CMySQLQuery::Execute[OnAccountLoad(i)] - starting query execution
[17:54:07] [DEBUG] CMySQLQuery::Execute[OnAccountLoad(i)] - query was successful
[17:54:07] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[17:54:07] [DEBUG] CMySQLQuery::Execute[OnAccountLoad(i)] - data being passed to ProcessCallbacks()
[17:54:07] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[17:54:07] [DEBUG] Calling callback "OnAccountLoad"..
[17:54:07] [DEBUG] cache_get_row_count - connection: 1
[17:54:07] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[17:54:07] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)