Raised This Month: $ Target: $400
 0% 

Server crashing cuz of this LARGE code


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 04-09-2011 , 15:04   Server crashing cuz of this LARGE code
Reply With Quote #1

PHP Code:


/* Vytvoril IdiotStrike pro www.traxxzone.cz. Posledni update: 9.2. 2011. 

Changelog:
0.1.0 - Prvni release
0.1.1 - Opraveno nekolik bugu
0.2.0 - Darky, Zmeneni steamId
0.2.1 - Opraven bug vraceni TP
0.3.0 - Kupony
1.0.0 - Opraveno mnoho bugu, prakticky rewrite kodu
1.0.1 - Opraveno nekolik bugu
1.0.2 - Tituly
1.0.3 - Trial verze
1.1.0 - Opraven chat color, vice titulu (menu)

*/



#include <amxmodx>
#include <cstrike>
#include <sqlx>
#include <hamsandwich>
#include <engine>
#include <colorchat>
#include <amxmisc>

new Handleg_SqlTupleg_Cache[512]


new 
g_PlayerSkins[3][33] = {0,0,0}
new 
g_PlayerUntil[3][33] = {0,0,0}
new 
g_PlayerModel[3][33][128]
new 
g_PlayerHat[33][128]
new 
g_PlayerOmezeni[3][33] = {0,0,0}
new 
g_itemname[3][33][128]

new 
g_iEnt[33]

new 
cvar_port

new g_PlayerTitle[33][60][128]
new 
g_PlayerTitleUmisteni[33][60]
new 
g_PlayerTitleActive[33]
new 
g_PlayerTitleUntil[33][60]
new 
g_PlayerTitleId[33][60]

new const 
g_team_names[CsTeams][] = 

"SPEC"
"T"
"CT"
"SPEC" 
}; 


new 
cvar_say_all
new 
cvar_sayteam_all

new 
g_msgid_SayText
new 
g_max_clients;


public 
client_infochanged(id)
{
    for(new 
03x++)
        if(
g_PlayerModel[x][id][0])
            return 
PLUGIN_HANDLED
    
    
return PLUGIN_CONTINUE
}

public 
plugin_init()
{
    
cvar_port register_cvar("store_port""27000")
    
    
    
register_plugin("Skins Store""1.1.0""IdiotStrike")
    
    
RegisterHam(Ham_Spawn"player""client_spawn"1)
    
//    register_event("DeathMsg", "client_death", "a")    
    
    
    
cvar_say_all register_cvar("cc_say_all""0"); 
    
cvar_sayteam_all register_cvar("cc_sayteam_all""0"); 
    
g_msgid_SayText get_user_msgid("SayText"); 
    
    
register_clcmd("say""CmdSay"); 
    
register_clcmd("say_team""CmdTeamSay"); 
    
    
g_max_clients get_maxplayers(); 
    
}

public 
StoreReload(id)
{
    if(!
is_user_alive(id))
    {
        
client_print(idprint_chat"[TraxX Store] Musis byt nazivu k pouziti tohoto prikazu.")
        return 
PLUGIN_HANDLED
    
}
    
    
client_print(idprint_chat"[TraxX Store] Nacitam znovu skiny, klobouky a titul...")
    
    for(new 
x3x++)
        
ResetVar(idx)
    
    
LoadClient(id)
    
    
set_task(2.0"LoadSkinIn_Game"id)
    
    return 
PLUGIN_HANDLED
}



public 
StoreTitles(client)
{
    if(
HasTitle(client))
    {
        new 
menu menu_create("\rTraxXStore: Tituly""StoreTitles_Handle")
        
menu_additem(menu"\rZadny titul""0"0)
        
menu_addblank(menu0)
        
        for(new 
x=160x++)
        {
            if(!
equali(g_PlayerTitle[client][x][0], ""))
            {
                new 
str[2]
                
num_to_str(xstr1)
                
                new 
string[128]
        
                if(
g_PlayerTitleUmisteni[client][x] == 1)
                    
format(string127"<nick> %s"g_PlayerTitle[client][x])
                else
                    
format(string127"%s <nick>"g_PlayerTitle[client][x])
                
                
menu_additem(menustringstr0
            }
        }
        
menu_setprop(menuMPROP_EXITMEXIT_ALL);
        
        
menu_display(clientmenu0);
        
    }
    else
        
client_print(clientprint_chat"[TraxX Store] Nemas zadne tituly. Kup si je na www.traxxzone.cz!")
}

public 
StoreTitles_Handle(idmenuitem)
{
    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);
    
    new 
authid[36]
    
get_user_authid(idauthid35)
    
    
format(g_Cache511"UPDATE skiny_title_data SET aktivni=0 WHERE authid='%s' AND server=%d AND titleid=%d"authidget_pcvar_num(cvar_port), g_PlayerTitleId[id][g_PlayerTitleActive[id]])
    
    
SQL_ThreadQuery(g_SqlTuple"IgnoreHandle"g_Cache)
    
    if(
key != 0)
    {
        
format(g_Cache511"UPDATE skiny_title_data SET aktivni=1 WHERE authid='%s' AND server=%d AND titleid=%d"authidget_pcvar_num(cvar_port), g_PlayerTitleId[id][key])
        
SQL_ThreadQuery(g_SqlTuple"IgnoreHandle"g_Cache)
        
        
g_PlayerTitleActive[id] = key
        
        
new string[128]
        
        if(
g_PlayerTitleUmisteni[id][key] == 1)
            
format(string127"<nick> %s"g_PlayerTitle[id][key])
        else
            
format(string127"%s <nick>"g_PlayerTitle[id][key])
            
        
client_print(idprint_chat"[TraxX Store] Vas titul je nyni %s."string)
        
    }
    else
    {
        
client_print(idprint_chat"[TraxX Store] Vypli jste svuj titul. Pro vybrani titulu napiste /titul.")
        
g_PlayerTitleActive[id] = 0
    
}
    return 
PLUGIN_HANDLED
    
}
    
public 
CmdSay(client

    new 
said[192]; 
    
read_args(saidsizeof(said) - 1); 
    
remove_quotes(said);
    
    if(
equali(said"/reload"))
        
StoreReload(client)
    
    if(
equali(said"/titul"))
        
StoreTitles(client)
    
    if( !
IsValidMessage(said) ) return PLUGIN_HANDLED
    
    new 
name[32]; 
    
get_user_name(clientnamesizeof(name) - 1); 
    
    new 
alive is_user_alive(client); 
    
    new 
tag[9]; 
    if( 
cs_get_user_team(client) == CS_TEAM_SPECTATOR 
    { 
        
copy(tagsizeof(tag) - 1"*SPEC* "); 
    } 
    else if( !
alive 
    { 
        
copy(tagsizeof(tag) - 1"*DEAD* "); 
    } 
    
    new 
say_all get_pcvar_num(cvar_say_all); 
    
    new 
message[192]; 
    
    if(
HasActiveTitle(client))
        switch(
g_PlayerTitleUmisteni[client][g_PlayerTitleActive[client]])
    {
        case 
0formatex(messagesizeof(message) - 1"^x01%s ^x04%s^x03 %s^x01: %s"tagg_PlayerTitle[client][g_PlayerTitleActive[client]], namesaid)
            case 
1formatex(messagesizeof(message) - 1"^x01%s^x03 %s^x04 %s^x01: %s"tagnameg_PlayerTitle[client][g_PlayerTitleActive[client]], said)
        }
    else
        
formatex(messagesizeof(message) - 1"^x01%s^x03 %s^x01: %s"tagnamesaid)
    
    
    for( new 
1<= g_max_clientsi++ ) 
    { 
        if(
        !
is_user_connected(i
        || 
say_all 
        
|| is_user_alive(i) != alive
        
&& !is_user_admin(i)) continue; 
        
        
message_begin(MSG_ONE_UNRELIABLEg_msgid_SayText_i); 
        
write_byte(client); 
        
write_string(message); 
        
message_end(); 
    } 
    
    return 
PLUGIN_HANDLED


public 
CmdTeamSay(client

    new 
said[192]; 
    
read_args(saidsizeof(said) - 1); 
    
remove_quotes(said); 
    
    if( !
IsValidMessage(said) ) return PLUGIN_HANDLED
    
    new 
name[32]; 
    
get_user_name(clientnamesizeof(name) - 1); 
    
    new 
alive is_user_alive(client); 
    
    new 
CsTeams:team cs_get_user_team(client); 
    
    
    new 
tag[9]; 
    if( 
cs_get_user_team(client) == CS_TEAM_SPECTATOR 
    { 
        
copy(tagsizeof(tag) - 1"*SPEC* "); 
    } 
    else if( !
alive 
    { 
        
copy(tagsizeof(tag) - 1"*DEAD* "); 
    } 
    
    new 
sayteam_all get_pcvar_num(cvar_sayteam_all); 
    
    new 
message[192]; 
    
    if(
HasActiveTitle(client))
        switch(
g_PlayerTitleUmisteni[client][g_PlayerTitleActive[client]])
    {
        case 
0formatex(messagesizeof(message) - 1"^x01%s (%s) ^x04%s^x03 %s^x01: %s"tagg_team_names[team], g_PlayerTitle[client][g_PlayerTitleActive[client]], namesaid)
            case 
1formatex(messagesizeof(message) - 1"^x01%s (%s) ^x03%s^x04 %s^x01: %s"tagg_team_names[team], nameg_PlayerTitle[client][g_PlayerTitleActive[client]], said)
        }
    
    else
        
formatex(messagesizeof(message) - 1"^x01%s (%s) ^x03%s^x01: %s"tagg_team_names[team], namesaid)
    
    for( new 
1<= g_max_clientsi++ ) 
    { 
        if(
        !
is_user_connected(i
        || 
cs_get_user_team(i) != team 
        
|| sayteam_all 
        
|| is_user_alive(i) != alive
        
&& !is_user_admin(i)) continue; 
        
        
message_begin(MSG_ONE_UNRELIABLEg_msgid_SayText_i); 
        
write_byte(client); 
        
write_string(message); 
        
message_end(); 
    } 
    
    return 
PLUGIN_HANDLED


public 
plugin_cfg()
{
    new 
Host[64],User[64],Pass[64],Db[64]
    
    
get_cvar_string("amx_sql_host",Host,63)
    
get_cvar_string("amx_sql_user",User,63)
    
get_cvar_string("amx_sql_pass",Pass,63)
    
get_cvar_string("amx_sql_db",Db,63)
    
    
g_SqlTuple SQL_MakeDbTuple(HostUserPassDb)
}

/*
public client_PostThink(id)
{
    if (is_user_alive(id) && is_valid_ent(g_iEnt[id]))
    {
        new rendermode, red, green, blue, renderfx, renderamt
        get_rendering(id, rendermode, red, green, blue, renderfx, renderamt)
        set_rendering(g_iEnt[id], rendermode, red, green, blue, renderfx, renderamt)
    }
}


public client_death()
{
    new id = read_data(2)
    
    if (is_user_connected(id) && is_valid_ent(g_iEnt[id]))
        remove_entity(g_iEnt[id])
}
*/

public client_authorized(id)
{
    for(new 
03x++)
        
ResetVar(idx)
    
set_task(1.0"LoadClient"id)
}

public 
LoadClient(id)
{
    
    if(!
is_user_bot(id) && <= id <= 32)
    {
        new 
authid[36]
        
get_user_authid(idauthid35)
        
        
format(g_Cache511"SELECT * FROM skiny_data WHERE authid='%s' AND server=%d"authidget_pcvar_num(cvar_port))
        
        new 
Data[1]
        
Data[0] = id
        
        SQL_ThreadQuery
(g_SqlTuple"LoadSkin"g_CacheData1)
        
        
format(g_Cache511"SELECT * FROM skiny_title_data WHERE authid='%s' AND server=%d AND until > %d"authidget_pcvar_num(cvar_port), get_systime())
        
SQL_ThreadQuery(g_SqlTuple"LoadTitle"g_CacheData1)
    }
}


public 
LoadTitle(FailStateHandle:QueryError[], ErrcodeData[], DataSize)
{
    
    if (
FailState == TQUERY_CONNECT_FAILED)
        
set_fail_state("CONNECT_FAILED")
    
    else if (
FailState == TQUERY_QUERY_FAILED)
        
set_fail_state("QUERY_FAILED")
    
    if (
Errcode)
        
set_fail_state(Error)
    
    new 
id Data[0]
    
    new 
1
    
while(SQL_MoreResults(Query))
    {
        new 
cache SQL_ReadResult(Query2)
        
//g_PlayerTitleUntil[id][x] = SQL_ReadResult(Query, 3)
        
        
if(SQL_ReadResult(Query4))
            
g_PlayerTitleActive[id] = x
        
        g_PlayerTitleId
[id][x] = cache
        
        format
(g_Cache511"SELECT * FROM skiny_title_list WHERE id=%d"cache)
        
        new 
TheData[2]
        
TheData[0] = id
        TheData
[1] = x
        
        SQL_ThreadQuery
(g_SqlTuple"LoadTitle_Info"g_CacheTheData2)
        
        
SQL_NextRow(Query)
        
x++
        
    }
    
    
    
//log_amx("Hrac %d ma nejaky zaznam titlu.", id)
    
    
}

public 
LoadTitle_Info(FailStateHandle:QueryError[], ErrcodeData[], DataSize)
{
    
    if (
FailState == TQUERY_CONNECT_FAILED)
        
set_fail_state("CONNECT_FAILED")
    
    else if (
FailState == TQUERY_QUERY_FAILED)
        
set_fail_state("QUERY_FAILED")
    
    if (
Errcode)
        
set_fail_state(Error)
    
    new 
id Data[0]
    
    new 
Data[1]
    
    
SQL_ReadResult(Query1g_PlayerTitle[id][x], 127)
    
g_PlayerTitleUmisteni[id][x] = SQL_ReadResult(Query5)
    
    
    
log_amx("Titul hrace %d by mel byt nacten (%s)"idg_PlayerTitle[id])
    
}



public 
LoadSkin(FailStateHandle:QueryError[], ErrcodeData[], DataSize)
{
    
    if (
FailState == TQUERY_CONNECT_FAILED)
        
set_fail_state("CONNECT_FAILED")
    
    else if (
FailState == TQUERY_QUERY_FAILED)
        
set_fail_state("QUERY_FAILED")
    
    if (
Errcode)
        
set_fail_state(Error)
    
    new 
id Data[0]
    
    if(
SQL_NumResults(Query) > 0)
    {
        new 
0
        
        
while(SQL_MoreResults(Query))
        {
            
            
g_PlayerSkins[x][id] = SQL_ReadResult(Query2)
            
g_PlayerUntil[x][id] = SQL_ReadResult(Query3)
            
            
format(g_Cache511"SELECT * FROM skiny_list WHERE id=%d"g_PlayerSkins[x][id])
            
            new 
TheData[2]
            
TheData[0] = id
            TheData
[1] = x
            SQL_ThreadQuery
(g_SqlTuple"LoadSkin_Info"g_CacheTheData2)
            
            
x++
            
SQL_NextRow(Query)
        }
    }
    
    
}

public 
LoadSkin_Info(FailStateHandle:QueryError[], ErrcodeData[], DataSize)
{
    
    if (
FailState == TQUERY_CONNECT_FAILED)
        
set_fail_state("CONNECT_FAILED")
    
    else if (
FailState == TQUERY_QUERY_FAILED)
        
set_fail_state("QUERY_FAILED")
    
    if (
Errcode)
        
set_fail_state(Error)
    
    new 
id Data[0]
    new 
num Data[1]
    
    if(
SQL_NumResults(Query) > 0)
    {
        new 
type SQL_ReadResult(Query1)
        
        new 
path[128]
        
SQL_ReadResult(Query2path127)
        
        
SQL_ReadResult(Query7g_itemname[num][id], 127)
        
        if(
type == 2)
        {
            
            
format(g_PlayerModel[num][id], 127path)
        }
        else
            
format(g_PlayerHat[id], 127path)
        
        
g_PlayerOmezeni[num][id] = SQL_ReadResult(Query8)
    }
    
}

public 
IgnoreHandle(FailStateHandle:QueryError[], ErrcodeData[], DataSize)
{
    if (
FailState == TQUERY_CONNECT_FAILED)
        
set_fail_state("CONNECT_FAILED")
    
    else if (
FailState == TQUERY_QUERY_FAILED)
        
set_fail_state("QUERY_FAILED")
    
    if (
Errcode)
        
set_fail_state(Error)
}


public 
client_spawn(id)    
{
    
set_task(0.1"LoadSkinIn_Game"id)
}

public 
LoadSkinIn_Game(id)
{
    if(
is_user_connected(id) && is_user_alive(id) && !is_user_bot(id))
    {
        
cs_reset_user_model(id)
        
        new 
authid[36]
        
get_user_authid(idauthid35)
        
        for(new 
num 0num 3num++)
        {
            if(
g_PlayerSkins[num][id])
            {
                if(
g_PlayerUntil[num][id] < get_systime())
                    
ResetVar(idnum)
                
                if(
g_PlayerUntil[num][id] > get_systime() && g_PlayerSkins[num][id])
                {
                    if(
Is_Model(idnum))
                    {
                        if(
g_PlayerOmezeni[num][id] == && cs_get_user_team(id) == CS_TEAM_CT)
                        {
                            
cs_set_user_model(idg_PlayerModel[num][id])
                            
ColorChat(idGREEN"[TraxX Store] ^x01'^x03%s^x01' skin byl nacten."g_itemname[num][id])
                        }
                        else if(
g_PlayerOmezeni[num][id] == && cs_get_user_team(id) == CS_TEAM_T)
                        {
                            
cs_set_user_model(idg_PlayerModel[num][id])
                            
ColorChat(idGREEN"[TraxX Store] ^x01'^x03%s^x01' skin byl nacten."g_itemname[num][id])
                        }
                        else if(
g_PlayerOmezeni[num][id] == 3)
                        {
                            
cs_set_user_model(idg_PlayerModel[num][id])
                            
ColorChat(idGREEN"[TraxX Store] ^x01'^x03%s^x01' skin byl nacten."g_itemname[num][id])
                        }
                    }
                    else if(!
is_valid_ent(g_iEnt[id]) || g_iEnt[id] == 0)
                    {
                        new 
iEnt
                        
                        
if (!(iEnt create_entity("info_target")))
                        {
                            
client_print(idprint_chat"Tvoje cepice je roztrhana nebo neco. Kontaktuj developera!")
                            
                            return
                        }
                        
                        
entity_set_model(iEntg_PlayerHat[id])
                        
entity_set_int(iEntEV_INT_movetypeMOVETYPE_FOLLOW)
                        
entity_set_edict(iEntEV_ENT_aimentid)
                        
                        
                        
g_iEnt[id] = iEnt
                        
                        ColorChat
(idGREEN"[TraxX Store] ^x01'^x03%s^x01' klobouk byl nacten."g_itemname[num][id])
                        
                    }
                    else
                        
ColorChat(idGREEN"[TraxX Store] ^x01'^x03%s^x01' klobouk byl nacten (ReLoad)."g_itemname[num][id])
                    
                }
                
            }
        }
        
    }
    
    return
}

public 
client_disconnect(id)
{
    for(new 
03x++)
        
ResetVar(idx)
    
    for(new 
x60x++)
    {
        
g_PlayerTitle[id][x] = ""
        
g_PlayerTitleUntil[id][x] = 0
        g_PlayerTitleUmisteni
[id][x] = 0
    
}
    
    
g_PlayerTitleActive[id] = 0
}

public 
ResetVar(idnum)
{
    
g_PlayerOmezeni[num][id] = 0
    g_PlayerUntil
[num][id] = 0
    g_PlayerSkins
[num][id] = 0
    
    
    
if(Is_Model(idnum))
        
g_PlayerModel[num][id] = ""
    
else
    {
        
g_PlayerHat[id] = ""
        
        
if (is_valid_ent(g_iEnt[id]))
            
remove_entity(g_iEnt[id])
    }
    
    
g_itemname[num][id] = ""
    
}


public 
plugin_end()
    
SQL_FreeHandle(g_SqlTuple)

/*
stock get_rendering(index, &rendermode, &red, &green, &blue, &renderfx, &renderamt)
{
    rendermode = entity_get_int(index, EV_INT_rendermode)
    
    new Float:color[3]
    entity_get_vector(index, EV_VEC_rendercolor, color)
    red = floatround(color[0])
    green = floatround(color[1])
    blue = floatround(color[2])
    
    renderfx = entity_get_int(index, EV_INT_renderfx)
    renderamt = floatround(entity_get_float(index, EV_FL_renderamt))
}
*/

stock Is_Model(idnum)
{
    if(
g_PlayerModel[num][id][0])
        return 
1
    
    
return 0
}

stock HasTitle(id)
{
    
//if(!equali(g_PlayerTitle[id][1], ""))
    
if(g_PlayerTitle[id][1][0])
    
//    if(g_PlayerUntil[id][1] > get_systime())
            
return true
    
    
return false
}

stock HasActiveTitle(id)
{
    if(
g_PlayerTitleActive[id])
    
//    if(g_PlayerUntil[id][g_PlayerTitleActive[id]] > get_systime())
            
return true
    
    
return false
}
    


bool:IsValidMessage(const said[]) 

    for( new 
0said[i]; i++ ) 
    { 
        if( 
said[i] != ' ' 
        { 
            return 
true
        } 
    } 

    return 
false

Hello. Can anybody tell me why this code crashes the server? It's really random, no visible cause. But I'm pretty sure it happens cuz of this.

If there are any code optimizations please let me know.

Thanks in advance!
Backstabnoob is offline
Reply



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 19:46.


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