AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Server crashing (https://forums.alliedmods.net/showthread.php?t=146486)

Backstabnoob 12-28-2010 13:55

Server crashing
 
Is there any reason why this probably causes crashes? A little too often, around two times per map (sometimes it doesn't crash the whole map and sometimes it crashes 8x).

PHP Code:


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

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


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.0.1""IdiotStrike")
    
    
RegisterHam(Ham_Spawn"player""client_spawn"1)
    
register_event("DeathMsg""client_death""a")    
    
    
    
set_task(1.0"LoadDatabase")
    
}

public 
LoadDatabase()
{
    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_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)
    }
}

    
    


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
                        }
                        
                        if(
is_valid_ent(iEnt))
                        {
                            
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])
    
                    }
                }
            
            }
        }

    }
    
    return
}

public 
client_disconnect(id)
    for(new 
03x++)
        
ResetVar(idx)
        
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


I checked the code many times and haven't found anything wrong by myself. I hope you can help.

madeitout 12-28-2010 22:38

Re: Server crashing
 
mysql is very touchy, I would use nvault if possible and would probably solve it.
If you need mysql, add timers so that only 1 sql command can be sent at a time
and a few seconds of delay

PHP Code:

new Float:DELAY

public client_authorized(id)
{
    for(new 
03x++)
        
ResetVar(idx)
    
DELAY += 3.0
    set_task
(DELAY"LoadClient"id 100)
}

public 
LoadClient(id)
{
    
id -= 100
    DELAY 
= (DELAY <= 3.0) ? 0.0 DELAY 3.0;
    if (!
is_user_bot(id) && is_user_connected(id) && <= id <= 32)
    {
        new 
authid[36]
        
get_user_authid(idauthid35)

        
formatex(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)
    }




All times are GMT -4. The time now is 02:14.

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