Raised This Month: $7 Target: $400
 1% 

problem with sql


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CamerDisco
AlliedModders Donor
Join Date: Aug 2015
Location: Poland
Old 09-01-2016 , 10:04   problem with sql
Reply With Quote #1

Someone can tell me why it's not adding me to database?
PHP Code:
public OnPluginStart() {
    
HookEvent("player_death"Event_PlayerDeath);
    
RegConsoleCmd("sm_myhs"counths);
    
    
char error[256];
    
g_hDB SQL_Connect("hs"falseerrorsizeof(error));
    if(
g_hDB == null || strlen(error) > 0)
    {
        
PrintToServer("Error (%s)"error);
        
LogError("Error (%s)"error);
        return;
    }
    else
        
PrintToServer("Successfully connected to database!");
    
}

public 
OnClientConnected(int client)
{
        
count[client] = 0;
        
        
decl String:query[512];
        
decl String:auth[64];
        
decl String:eauth[128];
        
GetClientAuthString(clientauthsizeof(auth));
        
SQL_EscapeString(g_hDBautheauthsizeof(eauth));
    
        
Format(querysizeof(query), "SELECT * FROM 'hs' WHERE steamid='%s'"eauth);
    
        
SQL_TQuery(g_hDBSQLT_LoadHSqueryGetClientUserId(client), DBPrio_High);
}



public 
SQLT_LoadHS(Handle:ownerHandle:hndl, const String:error[], any:data)
{
            new 
client GetClientOfUserId(data);
        
            if(
SQL_GetRowCount(hndl)==0)
            {
                
decl String:query[256];
                
decl String:auth[64];
                
decl String:eauth[128];
        
                
GetClientAuthString(clientauthsizeof(auth));
                
SQL_EscapeString(g_hDBautheauthsizeof(eauth));
        
        
                
Format(querysizeof(query), "INSERT INTO 'hs' ('id', 'steamid', 'count') VALUES (NULL, '%s', 0)",  eauth);
        
                
SQL_TQuery(g_hDBSQLT_Errorquery_DBPrio_High);
            }
            else
            {
                
SQL_FetchRow(hndl);
                new 
field;
                
SQL_FieldNameToNum(hndl"count"field)
                
count[client] = SQL_FetchInt(hndlfield);
            }
}

public 
SQLT_Error(Handle:ownerHandle:hndl, const String:error[], any:data){
    if(
g_hDB==INVALID_HANDLE){
        
LogError("SQL Error: %s"error);
    }


Last edited by CamerDisco; 09-01-2016 at 12:05.
CamerDisco is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 09-01-2016 , 22:04   Re: problem with sql
Reply With Quote #2

Because you're ignoring GetClientAuthString's return value. It's not valid to get the steamid before the player is validated. Switch to OnClientAuthorized.
__________________
Peace-Maker is offline
CamerDisco
AlliedModders Donor
Join Date: Aug 2015
Location: Poland
Old 09-02-2016 , 08:55   Re: problem with sql
Reply With Quote #3

Ok, thanks, but I've next problem, SteamID isn't ok, on steamid I've: "BOT"
And it's adding bots to the table.
PHP Code:
public OnClientAuthorized(client, const String:auth[])
{
            
char query[255];
            new 
String:authid[64];
            
GetClientAuthId(clientAuthId_Steam2authidsizeof(authid));
    
            
Format(querysizeof(query), "SELECT * FROM hs WHERE steamid='%s'"authid);
    
            
SQL_TQuery(g_hDBSQLT_Errorqueryclient);
}




public 
SQLT_Error(Handle:ownerHandle:hndl, const String:error[], any:data){
    if(
hndl==INVALID_HANDLE){
        
LogError("SQL Error: %s"error);
        return;
    }
            new 
client GetClientOfUserId(data);
            if(
client<=0) return;
            if(
SQL_GetRowCount(hndl)==0)
            {
                
decl String:query2[256];
                new 
String:authid[64];
                
GetClientAuthId(clientAuthId_Steam2authidsizeof(authid));
                
        
                
Format(query2sizeof(query2), "INSERT INTO hs (id, steamid, count) VALUES (NULL, '%s', 0)"authid);
        
                
SQL_TQuery(g_hDBSQLT_Error2query2_DBPrio_High);
            }
            else
            {
                
SQL_FetchRow(hndl);
                new 
field;
                
SQL_FieldNameToNum(hndl"count"field);
                
count[client] = SQL_FetchInt(hndlfield);
            }
}

public 
SQLT_Error2(Handle:ownerHandle:hndl, const String:error[], any:data){
    if(
hndl==INVALID_HANDLE){
        
LogError("SQL Error: %s"error);
        return;
    }
}

public 
bool:IsValidClient(client)
{
    if(
client >= && client <= MaxClients && IsClientInGame(client) && IsClientConnected(client))
        return 
true;

    return 
false;


Last edited by CamerDisco; 09-02-2016 at 09:02.
CamerDisco is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 09-02-2016 , 09:06   Re: problem with sql
Reply With Quote #4

Quote:
Originally Posted by CamerDisco View Post
Ok, thanks, but I've next problem, SteamID isn't ok, on steamid I've: "BOT"
And it's adding bots to the table.
PHP Code:
public OnClientAuthorized(client, const String:auth[])
{
            
char query[255];
            new 
String:authid[64];
            
GetClientAuthId(clientAuthId_Steam2authidsizeof(authid));
    
            
Format(querysizeof(query), "SELECT * FROM hs WHERE steamid='%s'"authid);
    
            
SQL_TQuery(g_hDBSQLT_Errorqueryclient);

Here:

Look reason for editing lol.


Quote:
Note:
Consider begin coding in 1.7 SourcePawn Transitional Syntax.
__________________

Last edited by xines; 09-02-2016 at 09:42. Reason: Use other code example
xines is offline
CamerDisco
AlliedModders Donor
Join Date: Aug 2015
Location: Poland
Old 09-02-2016 , 09:28   Re: problem with sql
Reply With Quote #5

I tried it, but the same, my SteamID is "BOT", beacause I validated client so it's not bot. Why?

Last edited by CamerDisco; 09-02-2016 at 09:30.
CamerDisco is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 09-02-2016 , 09:37   Re: problem with sql
Reply With Quote #6

Quote:
Originally Posted by CamerDisco View Post
I tried it, but the same, my SteamID is "BOT", beacause I validated client so it's not bot. Why?
Try this:

PHP Code:
public void OnClientAuthorized(int client, const char[] auth)
{
    if (
IsFakeClient(client)) return; //if bot do nothing
    
char query[255];    
    
Format(querysizeof(query), "SELECT * FROM hs WHERE steamid='%s'"auth);
    
SQL_TQuery(g_hDBSQLT_Errorqueryclient);

__________________
xines is offline
CamerDisco
AlliedModders Donor
Join Date: Aug 2015
Location: Poland
Old 09-02-2016 , 09:46   Re: problem with sql
Reply With Quote #7

It's not working too, but I found reason.
PHP Code:
SQL_TQuery(g_hDBSQLT_ErrorqueryGetClientUserId(client)); 
instead
PHP Code:
SQL_TQuery(g_hDBSQLT_Errorqueryclient); 
Thanks for help!
CamerDisco is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 09-02-2016 , 09:52   Re: problem with sql
Reply With Quote #8

Quote:
Originally Posted by CamerDisco View Post
It's not working too, but I found reason.
PHP Code:
SQL_TQuery(g_hDBSQLT_ErrorqueryGetClientUserId(client)); 
instead
PHP Code:
SQL_TQuery(g_hDBSQLT_Errorqueryclient); 
Thanks for help!
?? remove this:
PHP Code:
new client GetClientOfUserId(data); 
Change:
PHP Code:
public SQLT_Error(Handle:ownerHandle:hndl, const String:error[], any:data
to:

PHP Code:
public SQLT_Error(Handle:ownerHandle:hndl, const String:error[], any:client
And the code i posted should should work.
__________________
xines is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-03-2016 , 07:02   Re: problem with sql
Reply With Quote #9

Dont send client indices through a threaded callback!!!!!

Use GetClientUserId and GetClientOfUserId.
__________________
Neuro Toxin is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 09-03-2016 , 08:51   Re: problem with sql
Reply With Quote #10

Quote:
Originally Posted by Neuro Toxin View Post
Dont send client indices through a threaded callback!!!!!

Use GetClientUserId and GetClientOfUserId.
Threaded queries as well as anything else asynchronous (e.g. timer callbacks).
Potato Uno is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:00.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode