读取mysql的cs中文名字问题?
本帖最后由 cslover 于 2010-7-25 05:13 编辑数据库: `amx`
表的结构 `admins`
CREATE TABLE IF NOT EXISTS `admins` (
`auth` varchar(32) NOT NULL,
`cnname` varchar(32) NOT NULL,
`password` varchar(32) NOT NULL,
`access` varchar(32) NOT NULL,
`flags` varchar(32) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=gbk COMMENT='AMX Mod X Admins';
INSERT INTO `admins` (`auth`, `cnname`, `password`, `access`, `flags`) VALUES
('123', '一二三', '123', 'abcdefghijklmnopqrstu', 'a');用admin_sql.amxx和chinese_id.amxx使用一个表。读取玩家权限没有问题,但是中文名字读取不了(就是不改为中文名字)?
提示L 07/25/2010 - 01:39:15: Sorry,No DataBase or Table
L 07/25/2010 - 01:39:09: Login: "123<2><STEAM_ID_LAN><>" became an
admin (account "123") (access "abcdefghijklmnopqrstu") (address "127.0.0.1")这个不太可能吧?权限都没问题,怎么可能没有数据库或者表呢?
不知道问题出在哪儿?
使用的是下面这个mysql中文名字插件。
http://www.dt-club.net/forum/viewthread.php?tid=44412&highlight=mysql郁闷了好久。。。 老友记的那个dllCREATE TABLE `admins` ( `uid` int(8) NOT NULL auto_increment,`auth` varchar(32) NOT NULL,`password` varchar(32) NOT NULL,`access` varchar(32) NOT NULL,`flags` varchar(32) NOT NULL,`cnid` varchar(33) NOT NULL,`regtime` datetime NOT NULL,PRIMARY KEY(`uid`)) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 COMMENT='AMX Mod X Admins' AUTO_INCREMENT=13 ;#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <cstrike>
#include <dbi>
#define _MAX 32
new g_cmdLoopback;
new bool:g_CaseSensitiveName;
new bool:Dbid;
new amx_mode;
new amx_username_field,amx_password_field;
new g_SetAllow,g_SetName;
new g_host, g_user, g_pass, g_dbname, g_error,g_tabname,Sql:g_dbc,Result:g_result
public plugin_init()
{
register_plugin("Admin Base (SQL)", AMXX_VERSION_STR, "AMXX Dev Team && LoveHuai")
register_forward(FM_ClientUserInfoChanged, "on_FM_ClientUserInfoChanged")
register_dictionary("admin.txt")
register_dictionary("common.txt")
amx_mode=register_cvar("amx_mode", "1")
amx_password_field=register_cvar("amx_password_field", "_pw")
amx_username_field=register_cvar("amx_username_field", "_id")
//------------------------------------------------------
register_cvar("amx_vote_ratio", "0.02")
register_cvar("amx_vote_time", "10")
register_cvar("amx_vote_answers", "1")
register_cvar("amx_vote_delay", "60")
register_cvar("amx_last_voting", "0")
register_cvar("amx_show_activity", "2")
register_cvar("amx_votekick_ratio", "0.40")
register_cvar("amx_voteban_ratio", "0.40")
register_cvar("amx_votemap_ratio", "0.40")
register_cvar("amx_sql_host", "127.0.0.1")
register_cvar("amx_sql_user", "root")
register_cvar("amx_sql_pass", "love")
register_cvar("amx_sql_db", "amx")
register_cvar("amx_sql_table", "admins")
//-----------------------------------------------------
set_cvar_float("amx_last_voting", 0.0)
format(g_cmdLoopback, 15, "amxauth%c%c%c%c", random_num('A', 'Z'), random_num('A', 'Z'), random_num('A', 'Z'), random_num('A', 'Z'))
register_clcmd(g_cmdLoopback, "ackSignal")
remove_user_flags(0, read_flags("z"))
new configsDir
get_configsdir(configsDir, 63)
server_cmd("exec %s/amxx.cfg", configsDir)
server_cmd("exec %s/sql.cfg", configsDir)
}
public client_connect(id)
{
g_CaseSensitiveName = false;
Dbid = false;
remove_task(id)
g_SetAllow = 0
}
public plugin_cfg()
{
new configsDir
get_configsdir(configsDir, 63)
server_cmd("exec %s/sql.cfg", configsDir)
get_cvar_string("amx_sql_host",g_host,_MAX)
get_cvar_string("amx_sql_user",g_user,_MAX)
get_cvar_string("amx_sql_pass",g_pass,_MAX)
get_cvar_string("amx_sql_db",g_dbname,_MAX)
get_cvar_string("amx_sql_table",g_tabname,_MAX)
sql_init()
set_task(2.0, "delayed_load")
return PLUGIN_CONTINUE
}
public sql_init()
{
g_dbc = dbi_connect(g_host,g_user,g_pass,g_dbname,g_error,_MAX)
if (g_dbc == SQL_FAILED){
log_amx("Connect Error")
} else {
dbi_query(g_dbc, "CREATE TABLE `admins` ( `udi` int(8) NOT NULL auto_increment,`auth` varchar(32) NOT NULL,`password` varchar(32) NOT NULL,`access` varchar(32) NOT NULL,`flags` varchar(32) NOT NULL,`cnid` varchar(33) NOT NULL,`regtime` datetime NOT NULL,PRIMARY KEY(`udi`)) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 COMMENT='AMX Mod X Admins' AUTO_INCREMENT=13 ;", g_tabname)
dbi_close(g_dbc)
}
return PLUGIN_CONTINUE
}
public delayed_load()
{
new configFile, curMap, configDir
get_configsdir(configDir, sizeof(configDir)-1)
get_mapname(curMap, sizeof(curMap)-1)
new i=0;
while (curMap != '_' && curMap != '^0') {/*do nothing*/}
if (curMap=='_')
{
curMap='^0';
formatex(configFile, sizeof(configFile)-1, "%s/maps/prefix_%s.cfg", configDir, curMap);
if (file_exists(configFile))
{
server_cmd("exec %s", configFile);
}
}
get_mapname(curMap, sizeof(curMap)-1)
formatex(configFile, sizeof(configFile)-1, "%s/maps/%s.cfg", configDir, curMap)
if (file_exists(configFile))
{
server_cmd("exec %s", configFile)
}
}
getAccess(id, name[], password[])
{
new index = -1
new result = 0
new Flags;
new Access;
new Dw_Password;
new Cn_CSId;
g_CaseSensitiveName = false;
g_dbc = dbi_connect(g_host,g_user,g_pass,g_dbname,g_error,_MAX)
if (g_dbc == SQL_FAILED)
log_amx("Error Info:%s ",g_error)
else
{
dbi_query(g_dbc,"set names 'utf8'")
g_result = dbi_query(g_dbc,"SELECT * FROM `%s` WHERE auth= '%s'",g_tabname,name)
while (dbi_nextrow(g_result) > 0 )
{
dbi_result(g_result, "access",Access,23)
dbi_result(g_result, "flags",Flags,1)
dbi_result(g_result, "password",Dw_Password,31)
dbi_result(g_result, "cnid",Cn_CSId,34)
index = id
}
dbi_free_result(g_result)
dbi_close(g_dbc)
}
if (index != -1)
{
Dbid = true;
if(equal(Flags,"e"))
{
result |= 8
set_user_flags(id, read_flags(Access))
g_SetAllow = 1
copy(g_SetName, 31, Cn_CSId)
log_amx("用户:%s (账户^"%s^") (权限 ^"%s^") ", Cn_CSId, name, Access);
}
else
{
if (equal(password, Dw_Password))
{
result |= 12
set_user_flags(id, read_flags(Access))
g_SetAllow = 1
copy(g_SetName, 31, Cn_CSId)
log_amx("用户:%s (账户^"%s^") (权限 ^"%s^")", Cn_CSId, name, Access)
}
else
{
result |= 1
if(equal(Flags,"a"))
{
result |= 2
log_amx("由于密码错误 Kick (账户 ^"%s^")", name)
}
}
}
}
else if (get_pcvar_float(amx_mode) == 2.0)
{
result |= 2
}
else
{
result |= 8
set_user_flags(id, read_flags("z"))
}
return result
}
accessUser(id, name[] = "")
{
if(g_CaseSensitiveName)
return PLUGIN_CONTINUE
remove_user_flags(id)
new password, passfield, username,namefield
if (name)
{
copy(username, 31, name)
}
else
{
get_pcvar_string(amx_username_field, namefield, 31)
get_user_info(id, namefield, username, 31)
}
get_pcvar_string(amx_password_field, passfield, 31)
get_user_info(id, passfield, password, 31)
new result = getAccess(id, username, password)
if (result & 1)
{
client_cmd(id, "echo ^"* %L^"", id, "INV_PAS")
}
if (result & 2)
{
client_cmd(id, "%s", g_cmdLoopback)
return PLUGIN_HANDLED
}
if (result & 4)
{
client_cmd(id, "echo ^"* %L^"", id, "PAS_ACC")
}
if (result & 8 || result & 12)
{
client_cmd(id, "echo ^"* %L^"", id, "PRIV_SET")
if(Dbid)
set_name(id)
g_CaseSensitiveName=true;
}
return PLUGIN_CONTINUE
}
public ackSignal(id)
{
server_cmd("kick #%d ^"%L^"", get_user_userid(id), id, "NO_ENTRY")
return PLUGIN_HANDLED
}
public client_authorized(id)
return get_pcvar_num(amx_mode) ? accessUser(id) : PLUGIN_CONTINUE
public client_putinserver(id)
{
if (!is_dedicated_server() && id == 1)
return get_pcvar_num(amx_mode) ? accessUser(id) : PLUGIN_CONTINUE
return PLUGIN_CONTINUE
}
public on_FM_ClientUserInfoChanged(id, buffer)
{
if (!is_user_connected(id))
return FMRES_IGNORED
if (!g_SetAllow)
{
new oldname, newname
get_user_name(id, oldname, 34)
get_user_info(id, "name", newname, 34)
if (strcmp(newname, oldname)==0)
return FMRES_IGNORED
ig_setname(id, oldname)
return FMRES_SUPERCEDE
}
g_SetAllow = 0
ig_setname(id, g_SetName)
return FMRES_SUPERCEDE
}
public set_name(id)
{
set_user_info(id, "name", "")
return PLUGIN_CONTINUE
} 本帖最后由 cslover 于 2010-7-25 05:05 编辑
-- phpMyAdmin SQL Dump
-- version 3.3.1
-- http://www.phpmyadmin.net
--
-- 主机: localhost
-- 生成日期: 2010 年 07 月 24 日 21:03
-- 服务器版本: 5.1.45
-- PHP 版本: 5.3.2
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- 数据库: `amx`
--
-- --------------------------------------------------------
--
-- 表的结构 `admins`
--
CREATE TABLE IF NOT EXISTS `admins` (
`uid` int(8) NOT NULL AUTO_INCREMENT,
`auth` varchar(32) NOT NULL,
`password` varchar(32) NOT NULL,
`access` varchar(32) NOT NULL,
`flags` varchar(32) NOT NULL,
`cnid` varchar(33) NOT NULL,
`regtime` datetime NOT NULL,
PRIMARY KEY (`uid`)
) ENGINE=MyISAMDEFAULT CHARSET=utf8 COMMENT='AMX Mod X Admins' AUTO_INCREMENT=13 ;
--
-- 转存表中的数据 `admins`
--
INSERT INTO `admins` (`uid`, `auth`, `password`, `access`, `flags`, `cnid`, `regtime`) VALUES
(1, '123', '123', 'abcdefghijklmnopqrstu', 'a', '阿达洒洒打算的', '2010-07-25 04:58:38');
感谢回复。但是你这个是整合插件吧?我的问题是,我使用不了。不知道哪里出错了。那个dll有加载。
刚测试你的插件,好像连权限都没读取,不要密码都进了。依然没有中文名字。 首先,开启admin_sql.amxx
然后把字段Csid改为auth,使插件从auth字段读取英文名。
然后新建一个名为cnname,类型为varchar,字符集设置为utf8
这样就可以读取中文名了! 首先,开启admin_sql.amxx
然后把字段Csid改为auth,使插件从auth字段读取英文名。
然后新建一个名为cnname,类型为varchar,字符集设置为utf8
这样就可以读取中文名了! ...
cuikejie 发表于 2010-7-25 09:20 http://www.dt-club.net/forum/images/common/back.gif谢谢啊!但是插件中的csid也改成auth了,cnname字段也加了,类型确定是varchar,字符集不管是gbk还是utf8都一样,中文名字还是读取不了,我mysql默认gbk字符集。。。真不懂问题出在哪里? 你对照下,一样不?
要用到老友记的文件及中文sql版的id插件。。。你加载了没? 其实这个问题我也很郁闷,都成功了,就是中文名字只能6个字。。。暂时观望中。 8# cuikejie
name 最大长度32
中文字符UTF-8占3
32/3=10
我的服里
AcFun.Gaming|芙兰朵露
好像就这样了再长没事过如果太长就会出现密码错误 7# cuikejie 加载了。。。我就拿2个插件测试。。。都成功运作了。。。权限可以,但是没改中文名。