|
想保存玩家数据时写入玩家IP,尝试多次无法成功。数据库已经添加了IP字段,求帮助,附上RegSqlRank.sma源码
[PHP]
#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[BUFFER_SIZE][S_SIZE]
new g_sPStatsNames[BUFFER_SIZE][MAX_NAME_LENGTH+1]
new g_iMutationcount
new g_host[MAX_NAME_LENGTH+1]
new g_user[MAX_NAME_LENGTH+1]
new g_pass[MAX_NAME_LENGTH+1]
new g_dbname[MAX_NAME_LENGTH+1]
new g_error[MAX_NAME_LENGTH+1]
new Sql:g_dbc
new Result:result
new g_sqlstats_table[MAX_NAME_LENGTH+1]
new g_iStats[8]
new g_iBodyHits[8]
new top_url[256]
new rank_url[256]
new amx_password_field
public plugin_init()
{
register_plugin("RegSqlRank","0.7","[Grief.QQ]")
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[64]
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[1]
idx[0] = id
set_task(15.0,"check",12345, idx, 1)
return PLUGIN_CONTINUE
}
public check(idx[])
{
new id = idx[0]
new username[32]
new userpwd[32]
new passfield[32]
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[12]
new g_Signature[64]
new g_realname[32]
g_dbc = dbi_connect(g_host,g_user,g_pass,g_dbname,g_error,MAX_NAME_LENGTH)
if (g_dbc == SQL_FAILED)
log_amx("[RegSqlRank] 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("[RegSqlRank] 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[32]
new oldname[32]
get_user_name(id,oldname,31)
get_user_info(id,"name",newname,31)
if ( is_user_connected(id) && !equal(newname,oldname))
{
new idx[1]
idx[0] = 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("[RegSqlRank] 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("[sqlStats] 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[S_SCORE], g_iPStats[S_KILLS], g_iPStats[S_TK], g_iPStats[S_DEATHS], g_iPStats[S_HITS], g_iPStats[S_SHOTS], g_iPStats[S_HS], g_iPStats[S_EFF], g_iPStats[S_ACC], g_iPStats[S_ACCHS], g_sPStatsNames)
}
dbi_close(g_dbc)
}
g_iMutationcount = 0
}
gets_user_stats(iPlayer)
{
new bad_id[5] = "hltv"
new bad_id2[18] = "VALVE_ID_LOOPBACK"
new iName[MAX_NAME_LENGTH+1]
new g_sqlpwd[12]
new userpwd[32]
new passfield[32]
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("[RegSqlRank] 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[g_iMutationcount], MAX_NAME_LENGTH)
get_user_stats( iPlayer, g_iStats, g_iBodyHits )
g_iPStats[g_iMutationcount][S_KILLS] = g_iStats[S_KILLS]
g_iPStats[g_iMutationcount][S_DEATHS] = g_iStats[S_DEATHS]
g_iPStats[g_iMutationcount][S_HS] = g_iStats[S_HS]
g_iPStats[g_iMutationcount][S_TK] = g_iStats[S_TK]
g_iPStats[g_iMutationcount][S_SHOTS] = g_iStats[S_SHOTS]
g_iPStats[g_iMutationcount][S_HITS] = g_iStats[S_HITS]
g_iPStats[g_iMutationcount][S_SCORE] = g_iStats[S_KILLS] - g_iStats[S_DEATHS] - g_iStats[S_TK]
g_iPStats[g_iMutationcount][S_EFF] = (g_iStats[S_KILLS]+g_iStats[S_DEATHS])==0 ? -1 : g_iStats[S_KILLS]*100 / (g_iStats[S_KILLS]+g_iStats[S_DEATHS])
g_iPStats[g_iMutationcount][S_ACC] = g_iStats[S_SHOTS]==0 ? -1 : g_iStats[S_HITS]*100 / g_iStats[S_SHOTS]
g_iPStats[g_iMutationcount][S_ACCHS] = g_iStats[S_SHOTS]==0 ? -1 : g_iStats[S_HS]*100 / g_iStats[S_SHOTS]
if (g_iMutationcount < BUFFER_SIZE )
g_iMutationcount++
else
log_amx("[RegSqlRank] g_iMutationcount overflow, increase BUFFER_SIZE")
}
return PLUGIN_CONTINUE
}
public client_command( id )
{
new cmd[21]
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[1])
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[256]
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[256]
new name[32]
new ip[16]
new u_id[12]
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("[RegSqlRank] 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
}
[/PHP] |
|