Grief.QQ的asp+mysql论坛排行榜修改求助
想保存玩家数据时写入玩家IP,尝试多次无法成功。数据库已经添加了IP字段,求帮助,附上RegSqlRank.sma源码#include <amxmisc>
#include <amxmodx>
#include <csstats>
#include <dbi>
#include <string>
#define MAX_PLAYERS 32 + 1
#define MAX_NAME_LENGTH 31
#define MAX_TEXT_LENGTH 255
#define BUFFER_SIZE 500
#define S_KILLS 0 //csstats,csx
#define S_DEATHS 1 //csstats,csx
#define S_HS 2 //csstats,csx
#define S_TK 3 //csstats,csx
#define S_SHOTS 4 //csstats,csx
#define S_HITS 5 //csstats,csx
#define S_TIME 6 //custom
#define S_SCORE 7 //custom
#define S_EFF 8 //custom
#define S_ACC 9 //custom
#define S_ACCHS 10 //custom
#define S_SIZE 11 //array size
//stats vars
new g_iPStats
new g_sPStatsNames
new g_iMutationcount
new g_host
new g_user
new g_pass
new g_dbname
new g_error
new Sql:g_dbc
new Result:result
new g_sqlstats_table
new g_iStats
new g_iBodyHits
new top_url
new rank_url
new amx_password_field
public plugin_init()
{
register_plugin("RegSqlRank","0.7","")
register_cvar("amx_ranktable", "csrank",0)
amx_password_field=register_cvar("amx_password_field", "_pw")
register_cvar("amx_top_url","")
register_cvar("amx_rank_url","")
g_iMutationcount = 0
new configsDir
get_configsdir(configsDir, 63)
server_cmd("exec %s/sql.cfg", configsDir)
server_exec()
return PLUGIN_CONTINUE
}
public plugin_cfg()
{
get_cvar_string("amx_sql_host",g_host,MAX_NAME_LENGTH)
get_cvar_string("amx_sql_user",g_user,MAX_NAME_LENGTH)
get_cvar_string("amx_sql_pass",g_pass,MAX_NAME_LENGTH)
get_cvar_string("amx_sql_db",g_dbname,MAX_NAME_LENGTH)
get_cvar_string("amx_ranktable", g_sqlstats_table, MAX_NAME_LENGTH)
return PLUGIN_CONTINUE
}
public plugin_modules()
{
require_module("csx")
require_module("sql")
}
public plugin_end()
{
for (new id = 1; id < MAX_PLAYERS; id++)
gets_user_stats(id)
save_user_stats()
return PLUGIN_CONTINUE
}
public client_putinserver(id)
{
new idx
idx = id
set_task(15.0,"check",12345, idx, 1)
return PLUGIN_CONTINUE
}
public check(idx[])
{
new id = idx
new username
new userpwd
new passfield
get_pcvar_string(amx_password_field, passfield, 31)
get_user_info(id,"name",username,31)
get_user_info(id,passfield,userpwd,31)
replace_all(username,31,"[","[")
replace_all(username,31,"]","]")
replace_all(username,31,"<","<")
replace_all(username,31,">",">")
new g_sqlpwd
new g_Signature
new g_realname
g_dbc = dbi_connect(g_host,g_user,g_pass,g_dbname,g_error,MAX_NAME_LENGTH)
if (g_dbc == SQL_FAILED)
log_amx(" SQL Connection Failed")
else
{
result = dbi_query(g_dbc,"set names utf8;")
result = dbi_query(g_dbc,"select * from `%s` where Username = '%s'", g_sqlstats_table, username)
if (result == RESULT_FAILED)
{
log_amx(" Sorry,No DataBase or Table")
}
else if(result == RESULT_NONE)
{
client_print(id,print_chat,"您可以在论坛注册此当前ID,然后登陆CS以保留成绩!")
}
else
{
dbi_result(result, "Password", g_sqlpwd, 31)
dbi_result(result, "Real_name",g_realname,31)
dbi_result(result, "Signature",g_Signature,63)
dbi_free_result(result)
dbi_close(g_dbc)
if (equal(g_sqlpwd,userpwd) && strlen(userpwd)>0)
{
replace_all(username,31,"[","[")
replace_all(username,31,"]","]")
replace_all(username,31,"<","<")
replace_all(username,31,">",">")
replace_all(g_Signature,31,"[","[")
replace_all(g_Signature,31,"]","]")
replace_all(g_Signature,31,"<","<")
replace_all(g_Signature,31,">",">")
client_print(0,print_chat,"欢迎【VIP】%s -->>【昵称:】%s,",username,g_realname)
client_print(0,print_chat,"【个性签名:】%s",g_Signature)
}
else
{
new userid = get_user_userid( id)
server_cmd( "kick #%d ^"对不起,该帐号需密码,输入密码或改名后重新进入!^"", userid)
}
}
}
return PLUGIN_CONTINUE
}
public client_infochanged(id)
{
new newname
new oldname
get_user_name(id,oldname,31)
get_user_info(id,"name",newname,31)
if ( is_user_connected(id) && !equal(newname,oldname))
{
new idx
idx = id
set_task(10.0,"check",123456, idx,1)
}
return PLUGIN_CONTINUE
}
public client_disconnect(id)
{
gets_user_stats(id)
return PLUGIN_CONTINUE
}
save_user_stats()
{
log_amx(" Saving %i Players", g_iMutationcount)
g_dbc = dbi_connect(g_host,g_user,g_pass,g_dbname,g_error,MAX_NAME_LENGTH)
if (g_dbc == SQL_FAILED)
log_amx(" SQL Connection Failed")
else{
for (new i = 0; i < g_iMutationcount; i++)
{
replace_all(g_sPStatsNames,MAX_NAME_LENGTH+1,"'","\'")
dbi_query(g_dbc,"UPDATE `%s` SET date=NOW(),score=%i,kills=%i,teamkills=%i,deaths=%i,hits=%i,shots=%i,headshots=%i,efficiency=%i,accuracy=%i, accuracyHS=%i WHERE Username='%s'", g_sqlstats_table, g_iPStats, g_iPStats, g_iPStats, g_iPStats, g_iPStats, g_iPStats, g_iPStats, g_iPStats, g_iPStats, g_iPStats, g_sPStatsNames)
}
dbi_close(g_dbc)
}
g_iMutationcount = 0
}
gets_user_stats(iPlayer)
{
new bad_id = "hltv"
new bad_id2 = "VALVE_ID_LOOPBACK"
new iName
new g_sqlpwd
new userpwd
new passfield
get_user_name(iPlayer,iName,MAX_NAME_LENGTH)
replace_all(iName,31,"[","[")
replace_all(iName,31,"]","]")
replace_all(iName,31,"<","<")
replace_all(iName,31,">",">")
g_dbc = dbi_connect(g_host,g_user,g_pass,g_dbname,g_error,MAX_NAME_LENGTH)
if (g_dbc == SQL_FAILED)
log_amx(" SQL Connection Failed")
else
{
result = dbi_query(g_dbc,"select * from `%s` where Username = '%s'", g_sqlstats_table, iName)
if (result == RESULT_FAILED)
{
return PLUGIN_CONTINUE
}
else if(result == RESULT_NONE)
{
return PLUGIN_CONTINUE
}
else
{
dbi_result(result, "Password", g_sqlpwd, 31)
dbi_free_result(result)
dbi_close(g_dbc)
get_pcvar_string(amx_password_field, passfield, 31)
get_user_info(iPlayer,passfield,userpwd,31)
}
}
if ( is_user_connected(iPlayer) && contain( iName,bad_id) == -1 && contain( iName,bad_id2) == -1 && equal(g_sqlpwd,userpwd) && strlen(userpwd)>0)
{
get_user_name(iPlayer, g_sPStatsNames, MAX_NAME_LENGTH)
get_user_stats( iPlayer, g_iStats, g_iBodyHits )
g_iPStats = g_iStats
g_iPStats = g_iStats
g_iPStats = g_iStats
g_iPStats = g_iStats
g_iPStats = g_iStats
g_iPStats = g_iStats
g_iPStats = g_iStats - g_iStats - g_iStats
g_iPStats = (g_iStats+g_iStats)==0 ? -1 : g_iStats*100 / (g_iStats+g_iStats)
g_iPStats = g_iStats==0 ? -1 : g_iStats*100 / g_iStats
g_iPStats = g_iStats==0 ? -1 : g_iStats*100 / g_iStats
if (g_iMutationcount < BUFFER_SIZE )
g_iMutationcount++
else
log_amx(" g_iMutationcount overflow, increase BUFFER_SIZE")
}
return PLUGIN_CONTINUE
}
public client_command( id )
{
new cmd
read_argv(0,cmd,20)
if(equal(cmd,"say")||equal(cmd,"say_team")){
read_argv(1,cmd,20)
trim(cmd)
if(contain(cmd," ")>-1)return PLUGIN_CONTINUE
}
if( equal(cmd,"/",1) || equal(cmd,"\",1) || equal(cmd,".",1) || equal(cmd,"!",1) )
copy(cmd,20,cmd)
if( equali(cmd,"top15") || equali(cmd,"top") )
highscores(id)
if( equali(cmd,"rank") || equali(cmd,"rankstats") )
rankscores(id)
else return PLUGIN_CONTINUE
return PLUGIN_HANDLED
}
public highscores(id)
{
new html
get_cvar_string("amx_top_url",top_url,255)
format(html, 255, "%s",top_url)
show_motd(id, html, "英雄【TOP15】排行")
}
public rankscores(id)
{
new html
new name
new ip
new u_id
get_user_name(id,name,31)
get_user_ip(id,ip,15,1)
get_cvar_string("amx_rank_url",rank_url,255)
replace_all(name,31,"[","[")
replace_all(name,31,"]","]")
replace_all(name,31,"<","<")
replace_all(name,31,">",">")
g_dbc = dbi_connect(g_host,g_user,g_pass,g_dbname,g_error,MAX_NAME_LENGTH)
if (g_dbc == SQL_FAILED)
log_amx(" SQL Connection Failed")
else
{
result = dbi_query(g_dbc,"select * from `%s` where Username = '%s'", g_sqlstats_table, name)
if (result == RESULT_FAILED)
{
return PLUGIN_CONTINUE
}
else if(result == RESULT_NONE)
{
return PLUGIN_CONTINUE
}
else
{
dbi_result(result, "Author_ID", u_id, 11)
dbi_free_result(result)
dbi_close(g_dbc)
}
}
format(html, 255, "%s?Author_ID=%s&ip=%s",rank_url,u_id,ip)
show_motd(id, html, "您目前的成绩&排行")
return PLUGIN_CONTINUE
}
页:
[1]