|
发表于 2009-4-26 17:31:45
|
显示全部楼层
|阅读模式
来自 中国–新疆–乌鲁木齐
MYSQL的高手帮我看看那错了我读取SQL失败。我是新手照猫画虎的改的插件。- /* 本插件由 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 g_host[33]
- new g_user[33]
- new g_pass[33]
- new g_dbname[33]
- new g_tabname[33]
- new Sql:g_dbc
- new Result:result
- public plugin_init()
- {
- register_plugin(PLUGINNAME, VERSION, AUTHORS)
-
- register_cvar("amx_sql_host", "127.0.0.1")
- register_cvar("amx_sql_user", "root")
- register_cvar("amx_sql_pass", "123456")
- register_cvar("amx_sql_db", "discuz")
- register_cvar("amx_sql_table", "cdb_memberfields")
-
- 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,32)
- get_cvar_string("amx_sql_user",g_user,32)
- get_cvar_string("amx_sql_pass",g_pass,32)
- get_cvar_string("amx_sql_db",g_dbname,32)
- get_cvar_string("amx_sql_table",g_tabname,32)
-
- return PLUGIN_CONTINUE
- }
- // 名字更改消息
- 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 set = 0
- g_dbc = dbi_connect(g_host,g_user,g_pass,g_dbname)
- if (g_dbc == SQL_FAILED)
- log_amx("SQL Connection Failed")
- else
- {
- result = dbi_query(g_dbc,"set name utf8;")
- result = dbi_query(g_dbc,"select * from `%s` where auth = '%s'", g_tabname, name)
- if (result == RESULT_FAILED)
- {
- log_amx("Sorry,No DataBase or Table")
- }
- else if(result == RESULT_NONE)
- {
- new tmpName[64], tmpNameCN[64]
- dbi_result(result, "auth", tmpName, 31)
- dbi_result(result, "cnname",tmpNameCN,31)
- dbi_free_result(result)
- parse(tmpName,sizeof(tmpName)-1, tmpNameCN,sizeof(tmpNameCN)-1)
- trim(tmpName)
- trim(tmpNameCN)
-
- if (strcmp(name, tmpName)==0)
- {
- copy(name, 31, tmpNameCN)
- set = 1
- }
-
- }
- dbi_close(g_dbc)
-
- // 完成后,设置新的名字
- if (set)
- set_name(id, name)
- }
- }
复制代码 |
|