Junior Member
|
11-15-2006
, 12:55
Need help whis my plug
|
#1
|
Hi all, i have a script which save info about players into DB...
Code:
#include <amxmod>
new cFile[] = "addons/amxmodx/configs/sql.inf"
new host[32], user[32], pass[32], db[32], table[32], table2[32]
new Handle:query
new Handle:connection
new query_error[256]
new OK
public plugin_init() {
register_logevent("SaveDB",2,"0=World triggered","1=Round_Start")
ReadDB()
}
public ReadDB() {
new text[128], unk
read_file (cFile,0,text,127,unk)
parse(text,host,31,user,31,pass,31,db,31,table,31,table2,31)
new error[1024]
new Handle:server = SQL_MakeDbTuple(host, user, pass, db)
connection = SQL_Connect(server, error[0], error, 1023)
if (connection != Empty_Handle) {
server_print ("[PHP Info] Successfully connected on %s@%s.%s using password: YES",user,host,db)
if (!TalbeExists(table) || !TalbeExists(table2)) { return 1; }
}
else {
server_print ("Could not connect to DB, error:%s",error)
set_task (5.0,"ReadDB")
}
return 0
}
public SaveDB() {
new host[32]; get_cvar_string("hostname",host,31)
new ip[32]; get_user_ip (0,ip,31,0)
new timelimit = get_cvar_num ("mp_timelimit")
new timeleft = get_timeleft()
new nextmap[32]; get_cvar_string ("amx_nextmap",nextmap,31)
new curmap[32]; get_mapname(curmap,31)
new online = get_playersnum()
new maxplayers = get_cvar_num ("sv_visiblemaxplayers")
new pl_t[32], ts; get_players(pl_t,ts,"e","TERRORIST")
new pl_ct[32], cts; get_players(pl_ct,cts,"e","CT")
new spec = online - (ts + cts)
replace_all(host,31,"'","\'")
query = SQL_PrepareQuery(connection, "SELECT * FROM `%s`",table2)
SQL_Execute(query)
if (SQL_AffectedRows(query) < 1) {
query = SQL_PrepareQuery(connection, "INSERT INTO `%s` (host) VALUES ('%s')",table2,host)
OK = SQL_Execute(query)
if (OK) server_print ("[PHP Info] Successfully inserted server name into table: %s",table2)
else {
SQL_QueryError(query, query_error, 255)
server_print ("Could not save info into table: %s",table2)
server_print ("Error: %s",query_error)
}
}
query = SQL_PrepareQuery(connection, "UPDATE `%s` SET host='%s',ip='%s',timelimit='%d',timeleft='%d:%02d',nextmap='%s',curmap='%s',online='%d',maxplayers='%d',ts='%d',cts='%d',spec='%d' WHERE host = '%s'",table2,host,ip,timelimit,timeleft / 60, timeleft % 60,nextmap,curmap,online,maxplayers,ts,cts,spec,host)
OK = SQL_Execute(query)
if (OK) {} //server_print ("[PHP Info] Server info successfully saved into table: %s",table2)
else {
SQL_QueryError(query, query_error, 255)
server_print ("Could not save info into table: %s",table2)
server_print ("Error: %s",query_error)
}
query = SQL_PrepareQuery(connection, "DELETE FROM `%s`",table)
SQL_Execute(query)
new pl[32], num; get_players(pl,num)
for (new i = 0; i < num; i++) {
new name[32]; get_user_name(pl[i],name,31)
new ping, loss; get_user_ping(pl[i], ping, loss)
new frags = get_user_frags(pl[i])
new deaths = get_user_deaths(pl[i])
new team = get_user_team(pl[i])
replace_all(name,31,"'","\'")
query = SQL_PrepareQuery(connection, "INSERT INTO `%s` SET id='%d',name='%s',ping='%d',frags='%d',deaths='%d',team='%d'",table,pl[i],name,ping,frags,deaths,team)
OK = SQL_Execute(query)
if (OK) {} //server_print ("[PHP Info] Player info successfully saved into table: %s",table)
else {
SQL_QueryError(query, query_error, 255)
server_print ("Could not save info into table: %s",table)
server_print ("Error: %s",query_error)
}
}
return 0
}
TalbeExists (table[]) {
query = SQL_PrepareQuery(connection, "SELECT * FROM `%s`",table)
OK = SQL_Execute(query)
if (OK) {
server_print ("[PHP Info] Successfully using table: %s",table)
return 1
}
else {
server_print ("Could not use table: %s",table)
SQL_QueryError(query, query_error, 255)
server_print ("Error: %s",query_error)
}
return 0
}
but it doesn't perfectly work, one round it succs saved info into DB, 2nd, 3rd...2nd map ,3rd...but once i saw that it try to save and server crashed...
server console hung up and it on a circle save info DB...a open my phpmyadmin and found that table size is 68mb...
plz help, why did this script sometimes got this error, where is problem?
Last edited by amxxn00b; 11-15-2006 at 13:05.
|
|