Raised This Month: $ Target: $400
 0% 

Lag on connect caused by SQL - need help.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
EvolDay
Senior Member
Join Date: Apr 2008
Location: Canada
Old 07-04-2009 , 00:16   Lag on connect caused by SQL - need help.
Reply With Quote #1

Hey guys I'm having a problem, Whenever a new map loads on the server I get SQL lag while the server checks all the clients if they have rated or not. Is there anyway i could add a delay so that it does not check all the clients simotaniously.. Thanks for any help. I posted the code below that i am using.


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

#define PLUGIN "ratemap"
#define VERSION "0.9.6"
#define AUTHOR "sTmN"

new mapname[30],tag[30]

new 
Handle:g_SqlTuple
new g_Error[512]
new 
ErrorCode,Handle:SqlConnection

new Host[64] = "DB Host"
new User[64] = "DB User"
new Pass[64] = "DB Pass"
new Db[64] = "DB Name"
new Table[32] = "DB Table"

new g_maxplayers

new bool:g_selected false
new bool:do_vote[33] = false

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_dictionary("ratemap.txt");
    
    
register_cvar("rm_tag","[RateMap]")
    
get_cvar_string("rm_tag",tag,30
    
    
get_mapname(mapname,30)    

    
set_task(15.0"RateMap"272456""0"b")
    
g_maxplayers get_maxplayers()
    
    
table_init();
}

public 
sql_connect()
{
    
SqlConnection SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
    if(
SqlConnection == Empty_Handle)
        
set_fail_state(g_Error)
    
}

public 
table_init()
{
    
g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db)
    
    
sql_connect();

    new 
Handle:Query SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS %s (steamid TEXT(32),mapname TEXT(32),rate INT(11))",Table)
    if(!
SQL_Execute(Query))
    {
        
SQL_QueryError(Query,g_Error,511)
        
set_fail_state(g_Error)
    }

    
server_print("# Connected to database succesfully."
    
SQL_FreeHandle(SqlConnection)
}

public 
ratemenu(id)
{
    new 
Temp[64]
    
    
format(Temp64"%L"LANG_PLAYER"MENU_TITLE");
    new 
menu menu_create(Temp,"func_ratemenu")
    
    
format(Temp64"%L"LANG_PLAYER"OPTION_1");
    
menu_additem(menuTemp,"1",0)
    
    
format(Temp64"%L"LANG_PLAYER"OPTION_2");
    
menu_additem(menuTemp,"2",0)
    
    
format(Temp64"%L"LANG_PLAYER"OPTION_3");
    
menu_additem(menuTemp,"3",0)
    
    
format(Temp64"%L"LANG_PLAYER"OPTION_4");
    
menu_additem(menuTemp,"4",0)
    
    
format(Temp64"%L"LANG_PLAYER"OPTION_5");
    
menu_additem(menuTemp,"5",0)
    
    
menu_setprop(menu,MPROP_EXIT,MEXIT_ALL)
    
    
menu_display(id,menu,0)
}


public 
func_ratemenu(id,menu,item)
{
    
    if(
item==MENU_EXIT)
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED
    
}
    
    new 
data[6], iName[64]
    new 
accesscallback
    
    menu_item_getinfo
(menuitemaccessdata,5iName63callback);
    
    new 
key str_to_num(data);
    
    switch(
key)
    {
        case 
ratesql(id,key);
        case 
ratesql(id,key);
        case 
ratesql(id,key);
        case 
ratesql(id,key);
        case 
ratesql(id,key);
        case 
ratesql(id,key);
    }
    return 
PLUGIN_HANDLED


public 
ratesql(id,key)
{
    new 
steamid[32]
    
get_user_authid(id,steamid,32)
    
    new 
rate[15]
    
    
num_to_str(key,rate,12)
    
    
sql_connect();
    
    new 
Handle:Queries SQL_PrepareQuery(SqlConnection,"INSERT INTO %s VALUES('%s','%s','%s')",Table,steamid,mapname,rate)
    
    if(
key==1)
        
format(rate15"%L"LANG_PLAYER"OPTION_1");
    
    else if(
key==2)
        
format(rate15"%L"LANG_PLAYER"OPTION_2");
    
    else if(
key==3)
        
format(rate15"%L"LANG_PLAYER"OPTION_3");
    
    else if(
key==4)
        
format(rate15"%L"LANG_PLAYER"OPTION_4");
    
    else if(
key==5)
        
format(rate15"%L"LANG_PLAYER"OPTION_5");
     
    
do_vote[id] = false
    
    ColorChat
(0RED,"%L",LANG_PLAYER,"RATEINFO",tag,steamid,rate)
    
    if(!
SQL_Execute(Queries))
    {
        
SQL_QueryError(Queries,g_Error,511)
        
set_fail_state(g_Error)
    }
    
    
SQL_FreeHandle(SqlConnection)
}

public 
client_authorized(id)
{
    new 
steamid[32]
    
get_user_authid(id,steamid,31)

    
sql_connect();
    new 
Handle:Query SQL_PrepareQuery(SqlConnection,"SELECT steamid FROM %s WHERE steamid='%s' AND mapname='%s'",Table,steamid,mapname)
    
    if(!
SQL_Execute(Query))
    {
        
SQL_QueryError(Query,g_Error,511)
        
set_fail_state(g_Error)
    }
        
    if(!
SQL_MoreResults(Query))
    {
        
do_vote[id] = true
    

    else 
    {      
        
do_vote[id] = false
    
}
    
SQL_FreeHandle(SqlConnection)
}

public 
client_disconnect(id)
{
    
do_vote[id] = false
}

public 
RateMap()
{
    new 
timeleft get_timeleft()
        
    if (
timeleft 60 || timeleft 308)
    {
        
g_selected false
        
return
    }

    if (
g_selected)
        return
    
    
g_selected true
    votecheck
()
}

public 
votecheck()
{    
    for(new 
1<= g_maxplayers; ++i)
    {
        if (
do_vote[i] && !is_user_connected(i) && !is_user_connecting(i))
        {
            
ratemenu(i)
        }
    }

__________________
EvolDay is offline
 


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 15:34.


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