How can I check if the player is registered?
#1

Hello, like title. I don't know how to check if the player is registered correctly.
This is my code:
PHP код:

CheckAccountConnection
(playerid){
    new 
pName[MAX_PLAYER_NAME], query[512];
    
GetPlayerName(playeridpNamesizeof(pName));
    
mysql_format(MHandlequerysizeof(query), "SELECT * FROM `character` WHERE `Username` = '%e' LIMIT 1"pName);
    
mysql_tquery(MHandlequery"OnCharacterCheck""i"playerid);
    return 
1;
}
forward OnCharacterCheck(playerid);
public 
OnCharacterCheck(playerid){
    new 
rowsszFieldName[MAX_PLAYER_NAME];
    
cache_get_row_count(rows); 
    for(new 
row 0row rowsrow++){
        
cache_get_value(row"Username"szFieldName);
        if(!
strcmp(szFieldNameGetPlayerNameEx(playerid))){
            
cache_get_value(row"Password"Character[playerid][Password]);
            
cache_get_value(row"Username"Character[playerid][Username]);
            
System_Scm(playeridCOLOR_YELLOW"LOGIN""This account was registered.");
            
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD"Login""Fill your password into the box below.""Ok""Cancel");
            break;
        }
        else{
            if(
row == rows-1){
                
System_Scm(playeridCOLOR_YELLOW"REGISTER""You can register.");
                
PlayerRegistrationShow(playerid); // This is my registration textdraw.
                
break;
            }
        }
    }
    return 
1;

Reply
#2

I am using MySQL R41-2, the lastest version.
Reply
#3

You can print.
Reply
#4

I don't really know what do you mean.
Reply
#5

If anyone has another way to check, please tell me.
Reply
#6

Код:
CheckAccountConnection(playerid){ 
    new pName[MAX_PLAYER_NAME], query[512]; 
    GetPlayerName(playerid, pName, sizeof(pName)); 
    mysql_format(MHandle, query, sizeof(query), "SELECT * FROM `character` WHERE `Username` = '%e' LIMIT 1", pName); 
    print(query);
    mysql_tquery(MHandle, query, "OnCharacterCheck", "i", playerid); 
    print(query);
    return 1; 
}
Reply
#7

This is what I get after printing it.
Quote:

[11:56:09] [connection] 127.0.0.1:3087 requests connection cookie.
[11:56:10] [connection] incoming connection: 127.0.0.1:3087 id: 0
[11:56:10] [join] Daniel_DAD has joined the server (0:127.0.0.1)
[11:56:12] - Created Player Textdraw Sucessfully.
[11:56:12] SELECT * FROM `character` WHERE `Username` = 'Daniel_DAD' LIMIT 1
[11:56:23] sscanf warning: Format specifier does not match parameter count.

Reply
#8

You can check the amount of rows. If the cache contains a row the account is registered, if it doesn't the account is not.
Reply
#9

Thanks for the help, guys.
I have done it myself. If anyone has any problems like this, this is the code :
PHP код:
forward OnCharacterCheck(playerid);
public 
OnCharacterCheck(playerid){
    new 
rowsszFieldName[MAX_PLAYER_NAME];
    
cache_get_row_count(rows); // I get all of the rows that is available now.
    
for(new row 0row rowsrow++){ // Let the variable 'row' run from 0 to the maximum rows.
        
cache_get_value_name(row"Username"szFieldName); // I get the Username from each row.
        
if(!strcmp(szFieldNameGetPlayerNameEx(playerid))){ // I check if the Username of the row is the same with the player, then the player is registered.
            
cache_get_value_name(row"Password"Character[playerid][Password]);
            
cache_get_value_name(row"Username"Character[playerid][Username]);
            
System_Scm(playeridCOLOR_YELLOW"LOGIN""This account has been registered.");
            
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD"LOGIN""Fill your password into the box below""Ok""Cancel");
            return 
1// Return 1 to end the program.
        
}
    }
        
// if it can't check any row which is the same with the player username, means the player is not registered.
    
System_Scm(playeridCOLOR_YELLOW"REGISTER""You can register.");
    
PlayerRegistrationShow(playerid);
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)