|
本帖最后由 cuikejie 于 2011-2-12 14:45 编辑
首先声明,此插件是有sakulekingz完全编写。经我们几个连续2天的测试,目前已修复已知BUG。
我在此由衷感谢sakulekingz,让人感觉到这个网络上还是热心人比较多。
使用SQLX异步的中文ID区别与DBI的中文ID能够更好的减轻服务器负担,能够有效解决读取时卡的问题。
需求metamod_version "1.19p32" 和upatch看下面附件- #include <amxmodx>
- #include <amxmisc>
- #include <fakemeta>
- #include <sqlx>
-
- #define PLUGIN "Chinese Name MySQL"
- #define VERSION "1.0"
- #define AUTHOR "k1nader"
- #define LOADING "^n^t%s v%s, Copyright (C) 2011 by %s^n"
-
- new Handle:g_SqlTuple;
- new g_Error[512];
-
- 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 g_retryonce[33];
-
- public plugin_init()
- {
- register_plugin(PLUGIN, VERSION, AUTHOR);
- server_print(LOADING,PLUGIN,VERSION,AUTHOR);
- register_forward(FM_ClientUserInfoChanged, "fwdClientUserInfoChanged");
-
- register_cvar("amx_sql_host", "127.0.0.1");
- register_cvar("amx_sql_user", "");
- register_cvar("amx_sql_pass", "");
- register_cvar("amx_sql_db", "");
- register_cvar("amx_sql_table", "admins");
-
- new configsDir[64];
- get_configsdir(configsDir, 63);
- server_cmd("exec %s/sql.cfg", configsDir);
- server_exec();
- }
-
- 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);
- MySql_Init();
- }
-
- public MySql_Init()
- {
- g_SqlTuple = SQL_MakeDbTuple(g_host,g_user,g_pass,g_dbname);
- new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error));
- if(SqlConnection == Empty_Handle)
- set_fail_state(g_Error);
-
- new Handle:Queries;
- Queries = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS %s (auth varchar(32),cnname varchar(32))", g_tabname);
- if(!SQL_Execute(Queries))
- {
- SQL_QueryError(Queries,g_Error,charsmax(g_Error));
- set_fail_state(g_Error);
- }
- SQL_FreeHandle(Queries);
- SQL_FreeHandle(SqlConnection);
- }
-
- public Load_Mysql_Datex(id)
- {
- if(is_user_connected(id))
- {
- new szTemp[512];
-
- new Data[1];
- Data[0] = id;
- new szUidsetinfo[32];
- get_user_name(id,szUidsetinfo,31);
- format(szTemp,charsmax(szTemp),"SELECT CAST(CONVERT(`cnname` USING utf8) AS BINARY) FROM `%s` WHERE (`%s`.`auth` = '%s')", g_tabname, g_tabname, szUidsetinfo);
- SQL_ThreadQuery(g_SqlTuple,"register_client_datex",szTemp,Data,1);
- return PLUGIN_CONTINUE;
- }
- return PLUGIN_CONTINUE;
- }
-
- public register_client_datex(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
- {
- switch(FailState)
- {
- case TQUERY_CONNECT_FAILED: log_amx("Load - Could not connect to SQL database. [%d] %s", Errcode, Error);
- case TQUERY_QUERY_FAILED: log_amx("Load Query failed. [%d] %s", Errcode, Error);
- }
-
- new id;
- id = Data[0];
-
- if(SQL_NumResults(Query) < 1)
- return PLUGIN_HANDLED;
-
- new info[2];
- info[0] = id;
- info[1] = get_user_flags(id);
- set_task(1.0, "set_access", _, info , 2);
-
- new CsName[32];
-
- SQL_ReadResult(Query, 0, CsName, 31);
-
- set_user_info(id, "name", CsName);
- g_SetAllow[id] = 1;
-
- return PLUGIN_HANDLED;
- }
-
- public set_access(info[2])
- {
- new id = info[0];
- if (is_user_connected(id))
- {
- remove_user_flags(id);
- set_user_flags(id, info[1]);
- }
- }
-
- public client_connect(id)
- {
- g_SetAllow[id] = 0;
- if (!g_retryonce[id])
- {
- g_retryonce[id] = 1;
- client_cmd(id, "retry");
- }
- }
-
- public client_putinserver(id)
- return Load_Mysql_Datex(id);
-
- public fwdClientUserInfoChanged(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);
- set_user_info(id, "name",newname);
- }
- else
- set_user_info(id, "name", oldname);
-
- return FMRES_SUPERCEDE;
- }
- else
- g_SetAllow[id] = 0;
- return FMRES_SUPERCEDE;
- }
-
- public plugin_end()
- SQL_FreeHandle(g_SqlTuple);
复制代码 中文ID使用方法:amxmodx/config/sql.cfg 设置好SQL的链接参数。
注意如果服务端未使用中文破解,需要upatch来进行补丁。(unpatch 见附件)
upatch使用方法:
一、需求
metamod v1.19-p32
二、安装步骤
1、新建目录“{MODDIR}/addons/upatch”。
2、将文件“upatch.dll”(Windows)或“upatch_i386.so”(Linux)复制到目录“{MODDIR}/addons/upatch”。
3、在“{MODDIR}/addons/metamod/plugins.ini”中增加一行(Windows):
win32 addons/upatch/upatch.dll
或(Linux)
linux addons/upatch/upatch_i386.so
4、将 upatch.cfg 复制到服务器根目录或游戏MOD目录(cstrike)。
5、根据需要编辑 upatch.cfg 文件。
6、重启你的CS服务器。
请根据你的数据库类型进行下载
如果大家觉得点通下载扣点通币太多可以去sakulekingz的网站下载
http://www.roshis.org/2011/02/chinese-id-for-mysqlx.html |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注个册吧
×
|