Raised This Month: $ Target: $400
 0% 

Quick SQL help


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
turshija
Member
Join Date: Jan 2009
Old 06-13-2010 , 11:06   Re: Quick SQL help
Reply With Quote #6

Okay, I've managed to make exactly what I need (simple ban that uses SQL) , but I'm getting an error messages I don't know how to fix

Code:
L 06/13/2010 - 15:19:45: [MySQL] Invalid info tuple handle: 0
L 06/13/2010 - 15:19:45: [AMXX] Displaying debug trace (plugin "amx_cheater.amxx")
L 06/13/2010 - 15:19:45: [AMXX] Run time error 10: native error (native "SQL_ThreadQuery")
L 06/13/2010 - 15:19:45: [AMXX]    [0] amx_cheater.sma::client_connect (line 70)
Error logs spammed with this, and server crashes too much ... :S
line 70 is this:

PHP Code:
 SQL_ThreadQueryg_sql_tuple"QueryCheckAuth"cachedata1); 
And this is entire 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 pc_site
new pc_unique

new Handle:g_sql_tuple


new const link[] = "http://www.site.com/ban/addban.php";


public 
plugin_init() {
    
register_plugin("SQL Ban""1.0""Turshija");
    
    
    
register_concmd("amx_banz""banuj"ADMIN_BAN"Name Time ^"Reason^"!");

    
pc_sql_host register_cvar("db_host""xxx.xxx.xxx.xxx");
    
pc_sql_user register_cvar("db_user""db user");
    
pc_sql_pass register_cvar("db_pass""db pass"FCVAR_PROTECTED);
    
pc_sql_db register_cvar("db_name""db name");
    
    
pc_site register_cvar("sql_ban_site","");        // forum link
    
pc_unique register_cvar("sql_ban_unique","");        // unique server ID
    
    
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];
    new 
unique[32];
    
    
get_user_name(idname31);
    
get_user_authid(idauth31);
    
get_pcvar_string(pc_unique,unique,31);
    
    new 
tajm get_systime();
    
    
formatex(cache,500"SELECT * FROM bans WHERE banned='1' AND steamid='%s' AND uniqueid='%s' AND expire>'%i';",auth,unique,tajm);


    
// here..
    
new data[1];
    
data[0] = id;

   
// and here.. the last parameters

    
SQL_ThreadQueryg_sql_tuple"QueryCheckAuth"cachedata1);
    
    return 
PLUGIN_CONTINUE;
    
}


public 
QueryCheckAuthiFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:fQueueTime ) {
    if( 
iFailState == TQUERY_CONNECT_FAILED || iFailState == TQUERY_QUERY_FAILED ) {
        
log_amx"SQL Error!" );
    } else if( 
SQL_NumResultshQuery ) ) {
        
         
//taking the ID previously sent through 'data'.
    
new id iData[0];

    new 
banid[32],admin[32],reason[500],datum[32],istek[32],temp;
    new 
website[64];
    
    
get_pcvar_string(pc_site,website,63);
    
    
    
SQL_MoreResultshQuery );
    
    
SQL_ReadResult(hQuery0banid,31);
    
SQL_ReadResult(hQuery3,admin31);
    
SQL_ReadResult(hQuery5,reason499);
    
SQL_ReadResult(hQuery6,datum31);
    
SQL_ReadResult(hQuery10,istek31);
    
    
temp = ((str_to_num(istek)-get_systime())/60)+1;
    
    
    
    
// prints ban stuff in console
    
    
client_cmd(id,"clear");
    
client_cmd(id,"echo;echo;echo;echo;echo;echo;echo;");
    
client_cmd(id,"echo =====================================");
    
client_cmd(id,"echo Banned by: ^"%s^"",admin);
    
    
// also echoes ban time, expiration time, etc, etc
    
    
client_cmd(id,"echo =====================================");
    
client_cmd(id,"echo;echo;echo;echo;echo;");

    
set_task(1.0,"kikuj",id,"",0,"a",5)
    
    
    
    }
}  



public 
kikuj(id) {
    
server_cmd("kick #%d ^"You are banned on this servercheck console for more info!^"",get_user_userid(id));
}

public 
banuj(idlevelcid) {
    if(!
cmd_access(idlevelcid2))
        return 
1;
        
    new 
target[32], reason[51];
    new 
TaskData[4];
    new 
temp[8],duzina;
    
    
read_argv(1target31);    
    new 
iTarget cmd_target(idtarget8);
    
    if (!
iTarget)
        return 
PLUGIN_HANDLED;
    
    new 
argc read_argc();
    if (
argc == 1) {
        
temp="0";
        
reason="No reason";
    } else if (
argc == 2) {
        
read_argv(2temp,7);
        
reason="No reason";
    } else {
        
read_argv(2temp,7);        // ban length
        
read_argv(3reason50);
    }
    
    
    
duzina str_to_num(temp);    // ban length
    
TaskData[0]=id;
    
TaskData[1]=iTarget;
    
TaskData[2]=duzina;
    
    

    
//client_print(id,print_chat,"LOL HAI XD");
    
motd(TaskData,reason);
    
    return 
PLUGIN_HANDLED;
        
}
public  
motd(TaskData[],reason[])
{    
    new 
id TaskData[0];
    new 
target TaskData[1];
    new 
duzina TaskData[2];
    new 
temp=duzina;
    if (
temp==0temp=1000000;
    
    new 
BanTime = ((temp 60) + get_systime());
    
    new 
cache[1000]="",cache2[1000]="";
    new 
adminname[32]; new cheatername[32]; new cheaterauth[32]; new cheaterip[32]; new datum[32]; new hostname[64];
    new 
website[64],unique[32];
    
    
get_pcvar_string(pc_site,website,63);
    
get_pcvar_string(pc_unique,unique,31);
    
    
get_user_name(idadminname31);
    
get_user_name(targetcheatername31);
    
get_user_authid(targetcheaterauth31);
    
get_user_ip(targetcheaterip31);
    
    
strcat(cache,link,100);
    
formatex(cache21000"?name=%s&steamid=%s&adminname=%s&ip=%s&reason=%s&unique=%s&expire=%i",cheatername,cheaterauthadminnamecheateripreasonuniqueBanTime)    
    
    
    
strcat(cache,cache2,1000);
    
show_motd(id,cache)
    
    
    
get_cvar_string("hostname",hostname,63);
    
get_time("%H:%M - %m/%d/%Y"datum,31);
    
    
    
// prints info in chat for screenshot
    
    
client_print(targetprint_chat,"* Banovao te %s na serveru: %s",adminname,hostname);
    
client_print(targetprint_chat"* Trenutni nick:  ^"%s^" SteamID: %s ",cheatername,cheaterauth);
    
client_print(targetprint_chat"* Datum : %s",datum);
    
client_print(targetprint_chat"* Poseti %s za unban.",website);
    
    
console_print(target"* Banovao te %s na serveru: %s",adminname,hostname);
    
console_print(target"* Trenutni nick:  ^"%s^" SteamID: %s ",cheatername,cheaterauth);
    
console_print(target"* Datum : %s",datum);
    
console_print(target"* Poseti %s za unban.",website);
    
    
    
client_cmd(target,"wait;wait;wait;wait;wait;wait;wait;wait;wait;wait;wait;wait;wait;wait;wait;");
    
client_cmd(target,"snapshot;wait;wait;wait;screenshot;wait;snapshot;wait;wait;wait;retry;");
    
        
    return 
PLUGIN_HANDLED

this ban works basically by opening a MOTD window on admin that links to a PHP file that inserts ban info in SQL, and then execing retry on player so he gets ban info in console printed, and it works excellent ...
Main reason I'm doing that is because I made SQL user that has only SELECT privilege so people can't sniff SQL pass and fuk up DB

When I made it without Threaded query using this:

PHP Code:
  Query SQL_PrepareQuery(g_SqlConnection"SELECT * FROM bans WHERE banned='1' AND steamid='%s' AND uniqueid='%s';"auth,unique)
SQL_Execute(Query); 
it worked fine, but I thought threaded query would be better ...
Also when testing this plugin on empty server, everything is fine, but after putting it on public server that has 30 players online, it crashes server sometimes on map change ...
Do I need SQL disconnect somewhere or something?

Any suggestions ?


Edit: I've copied everything from grab_cvars function into public client_connect, and so far it works great, but still if you think anything should be improved, feel free to tell me
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