|
发表于 2009-4-15 01:13:34
|
显示全部楼层
|阅读模式
来自 中国–新疆–乌鲁木齐
本帖最后由 hulianglove 于 2009-4-18 17:06 编辑
/* 本插件由 AMXX-Studio 中文版自动生成 */
/* UTF-8 func by www.DT-Club.net */
new const PLUGINNAME[] = "中文ID"
new const VERSION[] = "2.1"
new const AUTHORS[] = "poohoo @ 老友记"
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <dbi>
new g_RetryOnce[33]
new g_SetName[33][32]
new g_SetAllow[33]
new FILE[256]
new host[33]
new user[33]
new pass[33]
new tabname[33]
public plugin_init()
{
register_plugin(PLUGINNAME, VERSION, AUTHORS)
register_cvar("dbi_host", "127.0.0.1")
register_cvar("dbi_user", "root")
register_cvar("dbi_pass", "123456")
register_cvar("dbi_tabname", "Discuz")
get_cvar_string("dbi_host",host,32)
get_cvar_string("dbi_user",user,32)
get_cvar_string("dbi_pass",pass,32)
get_cvar_string("dbi_tabname",tabname,32)
}
// 名字更改消息
public client_infochanged(id)
{
if (!is_user_connected(id))
return PLUGIN_CONTINUE
// 更换限制标记
if (!g_SetAllow[id])
{
new oldname[32], newname[32]
get_user_name(id, oldname, 31)
get_user_info(id, "name", newname, 31)
if (strcmp(newname, oldname)==0)
return PLUGIN_CONTINUE
// 兼容 sXe 改名
if (equal(newname, "[NO-sXe-I]", 10))
{
replace(oldname, 31, "[NO-sXe-I] ", "")
formatex(newname, 31, "[NO-sXe-I] %s", oldname)
ig_setname(id, newname)
}
else
ig_setname(id, oldname)
return PLUGIN_CONTINUE
}
g_SetAllow[id] = 0
ig_setname(id, g_SetName[id])
return PLUGIN_CONTINUE
}
// 重名检查
one_name(id, name[], len)
{
new sample[32], s
copy(sample, 31, name)
for (new i=0; i<33; i++)
{
if (s>0)
formatex(sample, 31, "(%d)%s", s, name)
if (!is_name_inuse(id, sample))
break
s++
}
copy(name, len, sample)
}
is_name_inuse(id, const sample[])
{
new name[32]
for (new i=1; i<=get_maxplayers(); i++)
{
if (!is_user_connected(i)) continue
if (id==i) continue
get_user_name(i, name, 31)
if (strcmp(name, sample)==0)
return 1
}
return 0
}
// 设置 id 需要的名字
public set_name(id, const newname[])
{
if (strlen(newname)<1)
return
g_SetAllow[id] = 1
copy(g_SetName[id], 31, newname)
one_name(id, g_SetName[id], 31)
set_user_info(id, "name", g_SetName[id])
}
public client_connect(id)
{
remove_task(id)
g_SetAllow[id] = 0
// 强制重新连接一次,以解决因为换中文ID后,换图会出现权限认证问题
if (!g_RetryOnce[id])
{
g_RetryOnce[id] = 1
client_cmd(id, "retry")
}
}
public client_putinserver(id)
{
// 延时足够的时间,等待 admin 权限认证插件完成权限设置后,再执行更换名字
set_task(random_float(3.0,10.0), "get_name_from_file", id)
}
// 从文件里检查是否有对应的中文ID
public get_name_from_file(id)
{
if (!is_user_connected(id))
return
new name[32]
get_user_name(id, name, 31)
new Sql:dbc
new Result:result
new auth[33]
new cnname[33]
dbc = dbi_connect(host,user,pass,tabname)
result = dbi_query(dbc, "SELECT * FROM cdb_memberfields")
while(dbi_nextrow(result > 0))
(
dbi_result(result,"auth",auth,32)
dbi_result(result,"cnname",cnname,32)
)
{
tmpName = ("%s",auth)
tmpNameCN = ("%s",cnname)
parse(tmpName,sizeof(tmpName)-1, tmpNameCN,sizeof(tmpNameCN)-1)
trim(tmpName)
trim(tmpNameCN)
if (strcmp(name, tmpName)==0)
{
copy(name, 31, tmpNameCN)
set = 1
break
}
}
// 完成后,设置新的名字
if (set)
set_name(id, name)
dbi_close(dbc)
} |
|