|
楼主 |
发表于 2010-7-27 01:22:46
|
显示全部楼层
来自 中国–广东–惠州
把源码发上来。
cuikejie 发表于 2010-7-26 19:52 chinese_id.sma - new const PLUGINNAME[] = "中文ID"
- new const VERSION[] = "2.1"
- new const AUTHORS[] = "poohoo @ 老友记"
- #include <amxmodx>
- #include <amxmisc>
- #include <fakemeta>
- #include <cstrike>
- #include <dbi>
- new g_RetryOnce[33]
- new g_SetName[33][32]
- new g_SetFlags[33]
- 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_forward(FM_ClientUserInfoChanged, "on_FM_ClientUserInfoChanged")
-
- register_cvar("amx_sql_host", "127.0.0.1")
- register_cvar("amx_sql_user", "root")
- register_cvar("amx_sql_pass", "")
- register_cvar("amx_sql_db", "amx")
- register_cvar("amx_sql_table", "admins")
-
- 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 on_FM_ClientUserInfoChanged(id, buffer)
- {
- if (!is_user_connected(id))
- return FMRES_IGNORED
- 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 FMRES_IGNORED
-
- if (containi(newname, "[NO-sXe-I]")!=-1)
- {
- formatex(newname, 31, "[NO-sXe-I] %s", oldname)
- ig_setname(id, newname)
- }
- else
- ig_setname(id, oldname)
-
- return FMRES_SUPERCEDE
- }
-
- g_SetAllow[id] = 0
- ig_setname(id, g_SetName[id])
- set_task(5, "getusernew", id)
- return FMRES_SUPERCEDE
- }
- public getusernew(id)
- {
- if (!(get_user_flags(id)==g_SetFlags[id])) {
- //这里杯具哈哈不懂C语法所以在也不管他是否规定了
- remove_user_flags(id)
- set_user_flags(id,g_SetFlags[id])
- //log_amx("set user flags")
- }
-
- new sflags[32]
- get_flags(get_user_flags(id),sflags,31)
- //log_amx("getusernew %s",sflags)
- }
- 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
- }
- public set_name(id, const newname[])
- {
- if (strlen(newname)<1)
- return
- g_SetAllow[id] = 1
-
- g_SetFlags[id]=get_user_flags(id)
- new sflags[32]
- get_flags(g_SetFlags[id],sflags,31)
- //log_amx("old %s",sflags)
-
- copy(g_SetName[id], 31, newname)
- one_name(id, g_SetName[id], 31)
- set_user_info(id, "name", "")
- }
- public client_connect(id)
- {
- remove_task(id)
- g_SetAllow[id] = 0
-
- if (!g_RetryOnce[id])
- {
- g_RetryOnce[id] = 1
- g_SetFlags[id] = 0
- client_cmd(id, "retry")
- }
- }
- public client_putinserver(id)
- {
- set_task(1, "get_name_from_file", 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 NAMES '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)
- {
- client_print(id, print_chat, "not cnid")
- }
- else
- {
- new tmpNameCN[32]
- dbi_result(result, "cnid",tmpNameCN,31)
- dbi_free_result(result)
- parse(tmpNameCN,sizeof(tmpNameCN)-1)
- trim(tmpNameCN)
- copy(name, 31, tmpNameCN)
- set = 1
- dbi_close(g_dbc)
- if (set) {
- set_name(id, name)
- }
- }
- }
- }
复制代码 |
|