CS中文ID – MYSQL 解决卡服问题
本帖最后由 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;
new g_SetAllow;
new g_host;
new g_user;
new g_pass;
new g_dbname;
new g_tabname;
new g_retryonce;
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;
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;
new Data;
Data = id;
new szUidsetinfo;
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;
if(SQL_NumResults(Query) < 1)
return PLUGIN_HANDLED;
new info;
info = id;
info = get_user_flags(id);
set_task(1.0, "set_access", _, info , 2);
new CsName;
SQL_ReadResult(Query, 0, CsName, 31);
set_user_info(id, "name", CsName);
g_SetAllow = 1;
return PLUGIN_HANDLED;
}
public set_access(info)
{
new id = info;
if (is_user_connected(id))
{
remove_user_flags(id);
set_user_flags(id, info);
}
}
public client_connect(id)
{
g_SetAllow = 0;
if (!g_retryonce)
{
g_retryonce = 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)
{
new oldname, newname;
get_user_name(id, oldname, 31);
get_user_info(id, "name", newname, 31);
if (strcmp(newname, oldname) == 0)
return FMRES_IGNORED;
if (containi(newname, "")!=-1)
{
formatex(newname, 31, " %s", oldname);
set_user_info(id, "name",newname);
}
else
set_user_info(id, "name", oldname);
return FMRES_SUPERCEDE;
}
else
g_SetAllow = 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 纯支持了.HL里面的中文ID看着还是比较别扭,语音出来的时候只能是乱码,毕竟已经是夕阳游戏啦. 谢谢楼主啦 换成中文名与奖励插件冲突,造成服务器死机,有中文名的奖励插件吗,怎么解决啊 非常棒
。。。。 这个看下。希望能用到! 这东西确实不错!留着肯定有用! 很不错的 不晓得管不管用!
页:
[1]
2