Raised This Month: $ Target: $400
 0% 

sql_threadquery - cannot set user flags


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
sebxx4
Senior Member
Join Date: Feb 2013
Old 04-23-2022 , 02:21   sql_threadquery - cannot set user flags
Reply With Quote #1

Hello everyone.
I got a problem - I want to connect to sql and check if player has acccess flags. Here's my example code:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>

#define PLUGIN "sqlVIPloader"
#define VERSION "1.0"
#define AUTHOR "Sebxx"

new c_db_hostc_db_userc_db_passc_db_namec_serv_ip
new db_host[33], db_user[33], db_pass[33], db_name[33], serv_ip[23]
new 
Handle:g_SqlTuple

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
c_db_host register_cvar("shop_sql_host""127.0.0.0")
    
c_db_user register_cvar("shop_sql_user""root")
    
c_db_pass register_cvar("shop_sql_pass""")
    
c_db_name register_cvar("shop_sql_db""shop")
    
c_serv_ip register_cvar("this_serv_ip""127.127.127.127:27015")

    new 
cfg_loc[33]
    
get_configsdircfg_loccharsmax(cfg_loc) )
    
server_cmd"exec %s/st_shop_sql.cfg"cfg_loc )
}

public 
client_authorizedid, const authid[] )
{
    if ( !
is_user_bot(id) && !is_user_hltv(id) )
    {
        
get_pcvar_stringc_db_hostdb_host32 )
        
get_pcvar_stringc_db_userdb_user32 )
        
get_pcvar_stringc_db_passdb_pass32 )
        
get_pcvar_stringc_db_namedb_name32 )
        
get_pcvar_stringc_serv_ipserv_ip22 )

        
g_SqlTuple SQL_MakeDbTupledb_hostdb_userdb_passdb_name )

        new 
query[512], user_ip[32], name[32], steamid[35], pw_info[32], pw_hash[34]

        
get_user_ipiduser_ipcharsmax(user_ip), )
        
get_user_nameidnamecharsmax(name) )
        
get_user_authididsteamidcharsmax(steamid) )
        
get_user_infoid"_pw"pw_info31 )
        
hash_stringpw_infoHash_Md5pw_hashcharsmax(pw_hash) )

        
formatex(query511"SELECT sc.access \
                                FROM shop_services AS sc, shop_servers AS sv \
                                WHERE sv.serv_ip = '%s' \
                                AND sc.server_id = sv.serv_id \
                                AND ( ( sc.auth_id = '%s' AND sc.auth = 1 ) OR ( sc.auth_id = '%s' AND sc.password = '%s' AND sc.auth = 2 ) OR ( sc.auth_id = '%s' AND sc.password = '%s' AND sc.auth = 3 ) ) \
                                AND sc.expire > %d"
serv_ipsteamidnamepw_hashuser_ippw_hashget_systime() )

        new 
Data[1]
        
Data[0] = id

        SQL_ThreadQuery
(g_SqlTuple"do_query"queryData1)
    }
}

public 
do_queryFailStateHandle:QueryError[], ErrcodeData[], DataSize )
{
    if ( 
FailState == TQUERY_CONNECT_FAILED )
    {
        
log_amx("Could not connect to SQL database.")

        if ( 
Errcode )
        {
            
log_amx("Error: %s"Error)
        }

        return 
PLUGIN_CONTINUE
    
}
    else if ( 
FailState == TQUERY_QUERY_FAILED )
    {
        
log_amx("Query failed.")

        if ( 
Errcode )
        {
            
log_amx("Error: %s"Error)
        }

        return 
PLUGIN_CONTINUE
    
}

    new 
id Data[0]

    if ( 
SQL_NumResults(Query) )
    {
        new 
flags[32]
        
        while( 
SQL_MoreResultsQuery ) )
        {
            new 
qcolAccess SQL_FieldNameToNumQuery"access" )
            
SQL_ReadResultQueryqcolAccessflags31 )
            
//log_amx( "Flag: %s", flags )
            
set_user_flagsidread_flagsflags ) )
            
SQL_NextRow(Query)
        }
    }

    
SQL_FreeHandle(g_SqlTuple)
    return 
PLUGIN_CONTINUE

The problem is, set_user_flags don't set it. SQL query works well (I see in the console flags get from sql server) but player don't have permissions. What's wrong?

Last edited by sebxx4; 04-23-2022 at 02:25.
sebxx4 is offline
 



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 00:51.


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