| Backstabnoob |
04-09-2011 15:04 |
Server crashing cuz of this LARGE code
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 Handle: g_SqlTuple, g_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 x = 0; x < 3; x++)
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(id, print_chat, "[TraxX Store] Musis byt nazivu k pouziti tohoto prikazu.")
return PLUGIN_HANDLED
}
client_print(id, print_chat, "[TraxX Store] Nacitam znovu skiny, klobouky a titul...")
for(new x; x < 3; x++)
ResetVar(id, x)
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(menu, 0)
for(new x=1; x < 60; x++)
{
if(!equali(g_PlayerTitle[client][x][0], ""))
{
new str[2]
num_to_str(x, str, 1)
new string[128]
if(g_PlayerTitleUmisteni[client][x] == 1)
format(string, 127, "<nick> %s", g_PlayerTitle[client][x])
else
format(string, 127, "%s <nick>", g_PlayerTitle[client][x])
menu_additem(menu, string, str, 0)
}
}
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_display(client, menu, 0);
}
else
client_print(client, print_chat, "[TraxX Store] Nemas zadne tituly. Kup si je na www.traxxzone.cz!")
}
public StoreTitles_Handle(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[6], iName[64];
new access, callback;
menu_item_getinfo(menu, item, access, data,5, iName, 63, callback);
new key = str_to_num(data);
new authid[36]
get_user_authid(id, authid, 35)
format(g_Cache, 511, "UPDATE skiny_title_data SET aktivni=0 WHERE authid='%s' AND server=%d AND titleid=%d", authid, get_pcvar_num(cvar_port), g_PlayerTitleId[id][g_PlayerTitleActive[id]])
SQL_ThreadQuery(g_SqlTuple, "IgnoreHandle", g_Cache)
if(key != 0)
{
format(g_Cache, 511, "UPDATE skiny_title_data SET aktivni=1 WHERE authid='%s' AND server=%d AND titleid=%d", authid, get_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(string, 127, "<nick> %s", g_PlayerTitle[id][key])
else
format(string, 127, "%s <nick>", g_PlayerTitle[id][key])
client_print(id, print_chat, "[TraxX Store] Vas titul je nyni %s.", string)
}
else
{
client_print(id, print_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(said, sizeof(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(client, name, sizeof(name) - 1);
new alive = is_user_alive(client);
new tag[9];
if( cs_get_user_team(client) == CS_TEAM_SPECTATOR )
{
copy(tag, sizeof(tag) - 1, "*SPEC* ");
}
else if( !alive )
{
copy(tag, sizeof(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 0: formatex(message, sizeof(message) - 1, "^x01%s ^x04%s^x03 %s^x01: %s", tag, g_PlayerTitle[client][g_PlayerTitleActive[client]], name, said)
case 1: formatex(message, sizeof(message) - 1, "^x01%s^x03 %s^x04 %s^x01: %s", tag, name, g_PlayerTitle[client][g_PlayerTitleActive[client]], said)
}
else
formatex(message, sizeof(message) - 1, "^x01%s^x03 %s^x01: %s", tag, name, said)
for( new i = 1; i <= g_max_clients; i++ )
{
if(
!is_user_connected(i)
|| say_all
|| is_user_alive(i) != alive
&& !is_user_admin(i)) continue;
message_begin(MSG_ONE_UNRELIABLE, g_msgid_SayText, _, i);
write_byte(client);
write_string(message);
message_end();
}
return PLUGIN_HANDLED;
}
public CmdTeamSay(client)
{
new said[192];
read_args(said, sizeof(said) - 1);
remove_quotes(said);
if( !IsValidMessage(said) ) return PLUGIN_HANDLED;
new name[32];
get_user_name(client, name, sizeof(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(tag, sizeof(tag) - 1, "*SPEC* ");
}
else if( !alive )
{
copy(tag, sizeof(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 0: formatex(message, sizeof(message) - 1, "^x01%s (%s) ^x04%s^x03 %s^x01: %s", tag, g_team_names[team], g_PlayerTitle[client][g_PlayerTitleActive[client]], name, said)
case 1: formatex(message, sizeof(message) - 1, "^x01%s (%s) ^x03%s^x04 %s^x01: %s", tag, g_team_names[team], name, g_PlayerTitle[client][g_PlayerTitleActive[client]], said)
}
else
formatex(message, sizeof(message) - 1, "^x01%s (%s) ^x03%s^x01: %s", tag, g_team_names[team], name, said)
for( new i = 1; i <= g_max_clients; i++ )
{
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_UNRELIABLE, g_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(Host, User, Pass, Db)
}
/*
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 x = 0; x < 3; x++)
ResetVar(id, x)
set_task(1.0, "LoadClient", id)
}
public LoadClient(id)
{
if(!is_user_bot(id) && 1 <= id <= 32)
{
new authid[36]
get_user_authid(id, authid, 35)
format(g_Cache, 511, "SELECT * FROM skiny_data WHERE authid='%s' AND server=%d", authid, get_pcvar_num(cvar_port))
new Data[1]
Data[0] = id
SQL_ThreadQuery(g_SqlTuple, "LoadSkin", g_Cache, Data, 1)
format(g_Cache, 511, "SELECT * FROM skiny_title_data WHERE authid='%s' AND server=%d AND until > %d", authid, get_pcvar_num(cvar_port), get_systime())
SQL_ThreadQuery(g_SqlTuple, "LoadTitle", g_Cache, Data, 1)
}
}
public LoadTitle(FailState, Handle:Query, Error[], Errcode, Data[], 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 x = 1
while(SQL_MoreResults(Query))
{
new cache = SQL_ReadResult(Query, 2)
//g_PlayerTitleUntil[id][x] = SQL_ReadResult(Query, 3)
if(SQL_ReadResult(Query, 4))
g_PlayerTitleActive[id] = x
g_PlayerTitleId[id][x] = cache
format(g_Cache, 511, "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_Cache, TheData, 2)
SQL_NextRow(Query)
x++
}
//log_amx("Hrac %d ma nejaky zaznam titlu.", id)
}
public LoadTitle_Info(FailState, Handle:Query, Error[], Errcode, Data[], 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 x = Data[1]
SQL_ReadResult(Query, 1, g_PlayerTitle[id][x], 127)
g_PlayerTitleUmisteni[id][x] = SQL_ReadResult(Query, 5)
log_amx("Titul hrace %d by mel byt nacten (%s)", id, g_PlayerTitle[id])
}
public LoadSkin(FailState, Handle:Query, Error[], Errcode, Data[], 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 x = 0
while(SQL_MoreResults(Query))
{
g_PlayerSkins[x][id] = SQL_ReadResult(Query, 2)
g_PlayerUntil[x][id] = SQL_ReadResult(Query, 3)
format(g_Cache, 511, "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_Cache, TheData, 2)
x++
SQL_NextRow(Query)
}
}
}
public LoadSkin_Info(FailState, Handle:Query, Error[], Errcode, Data[], 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(Query, 1)
new path[128]
SQL_ReadResult(Query, 2, path, 127)
SQL_ReadResult(Query, 7, g_itemname[num][id], 127)
if(type == 2)
{
format(g_PlayerModel[num][id], 127, path)
}
else
format(g_PlayerHat[id], 127, path)
g_PlayerOmezeni[num][id] = SQL_ReadResult(Query, 8)
}
}
public IgnoreHandle(FailState, Handle:Query, Error[], Errcode, Data[], 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(id, authid, 35)
for(new num = 0; num < 3; num++)
{
if(g_PlayerSkins[num][id])
{
if(g_PlayerUntil[num][id] < get_systime())
ResetVar(id, num)
if(g_PlayerUntil[num][id] > get_systime() && g_PlayerSkins[num][id])
{
if(Is_Model(id, num))
{
if(g_PlayerOmezeni[num][id] == 1 && cs_get_user_team(id) == CS_TEAM_CT)
{
cs_set_user_model(id, g_PlayerModel[num][id])
ColorChat(id, GREEN, "[TraxX Store] ^x01'^x03%s^x01' skin byl nacten.", g_itemname[num][id])
}
else if(g_PlayerOmezeni[num][id] == 2 && cs_get_user_team(id) == CS_TEAM_T)
{
cs_set_user_model(id, g_PlayerModel[num][id])
ColorChat(id, GREEN, "[TraxX Store] ^x01'^x03%s^x01' skin byl nacten.", g_itemname[num][id])
}
else if(g_PlayerOmezeni[num][id] == 3)
{
cs_set_user_model(id, g_PlayerModel[num][id])
ColorChat(id, GREEN, "[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(id, print_chat, "Tvoje cepice je roztrhana nebo neco. Kontaktuj developera!")
return
}
entity_set_model(iEnt, g_PlayerHat[id])
entity_set_int(iEnt, EV_INT_movetype, MOVETYPE_FOLLOW)
entity_set_edict(iEnt, EV_ENT_aiment, id)
g_iEnt[id] = iEnt
ColorChat(id, GREEN, "[TraxX Store] ^x01'^x03%s^x01' klobouk byl nacten.", g_itemname[num][id])
}
else
ColorChat(id, GREEN, "[TraxX Store] ^x01'^x03%s^x01' klobouk byl nacten (ReLoad).", g_itemname[num][id])
}
}
}
}
return
}
public client_disconnect(id)
{
for(new x = 0; x < 3; x++)
ResetVar(id, x)
for(new x; x < 60; x++)
{
g_PlayerTitle[id][x] = ""
g_PlayerTitleUntil[id][x] = 0
g_PlayerTitleUmisteni[id][x] = 0
}
g_PlayerTitleActive[id] = 0
}
public ResetVar(id, num)
{
g_PlayerOmezeni[num][id] = 0
g_PlayerUntil[num][id] = 0
g_PlayerSkins[num][id] = 0
if(Is_Model(id, num))
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(id, num)
{
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 i = 0; said[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!
|