Raised This Month: $ Target: $400
 0% 

Quick SQL help


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
turshija
Member
Join Date: Jan 2009
Old 06-11-2010 , 20:39   Quick SQL help
Reply With Quote #1

Okay, I started playing with SQL in AMXX, and I've stumbled upon a problem ...
I have used SQL in few different programming languages (PHP, C/C++) but something here bugs me too much ...
I made a simple code that does SQL check query in client_connect if the player steamid is in table or not (for example ban plugin), and then kick him if he is ...
So, I've managed to do everything except the kick part
I don't know how to do that from "QueryCheckAuth" ?

Main question is this:
How do I get player id in that function so I can do for example server_cmd("kick #%d",get_user_userid(id)) if mysql_num_rows>0 ?
See the last function in the code

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>

new pc_sql_host
new pc_sql_user
new pc_sql_pass
new pc_sql_db

new Handle:g_sql_tuple


public plugin_init() {
    
register_plugin("SQL test""0.1""Turshija");
    
    
    
pc_sql_host register_cvar("db_host""XXX.XXX.XXX.XXX");
    
pc_sql_user register_cvar("db_user""username here");
    
pc_sql_pass register_cvar("db_pass""password here"FCVAR_PROTECTED);
    
pc_sql_db register_cvar("db_name""db name here");

    
set_task(0.1"grab_cvars")
    
    
}

public 
grab_cvars(){
    new 
sql_host[32], sql_user[32], sql_pass[32], sql_db[32]
    
get_pcvar_string(pc_sql_hostsql_host31)
    
get_pcvar_string(pc_sql_usersql_user31)
    
get_pcvar_string(pc_sql_passsql_pass31)
    
get_pcvar_string(pc_sql_dbsql_db31)
    
    
g_sql_tuple SQL_MakeDbTuple(sql_hostsql_usersql_passsql_db)
}


public 
client_connect (id){
    new 
name[32],auth[32];
    new 
cache[500];
    
    
get_user_name(idname31);
    
get_user_authid(idauth31);
    
    
formatex(cache,500"SELECT * FROM table WHERE auth='%s'",auth);
    
    
SQL_ThreadQueryg_sql_tuple"QueryCheckAuth"cache );
    
    return 
PLUGIN_CONTINUE;
}


public 
QueryCheckAuthiFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:fQueueTime ) {
    if( 
iFailState == TQUERY_CONNECT_FAILED || iFailState == TQUERY_QUERY_FAILED ) {
        
log_amx"Error!" );
    } else if( 
SQL_NumResultshQuery ) ) {
        
        
///////////////////////
        // NOW WHAT ?! -_-
        ///////////////////////
    
    
}


Last edited by turshija; 06-11-2010 at 20:47.
turshija 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 14:52.


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