- 听众
- 收听
- 积分
- 373
- 主题
- 回帖
- 0
- 精华
注册时间2009-1-6
最后登录1970-1-1
该用户从未签到
|
Dll模块自己去找老友记同志的帖子下吧- -!
咱水平臭又烂大牛勿笑!~- #include <amxmodx>
- #include <amxmisc>
- #include <fakemeta>
- #include <cstrike>
- #include <dbi>
- #define _MAX 32
- new g_cmdLoopback[16];
- new bool:g_CaseSensitiveName[33];
- new amx_mode;
- new amx_password_field;
- new g_SetAllow[33],g_SetName[33][32];
- new g_host[_MAX], g_user[_MAX], g_pass[_MAX], g_dbname[_MAX], g_error[_MAX],g_tabname[_MAX],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")
- //------------------------------------------------------
- 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")
- //-----------------------------------------------------
- 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[64]
- get_configsdir(configsDir, 63)
-
- server_cmd("exec %s/amxx.cfg", configsDir)
- server_cmd("exec %s/sql.cfg", configsDir)
- server_cmd("amx_sqladmins")
- }
- public client_connect(id)
- {
- g_CaseSensitiveName[id] = false;
-
- remove_task(id)
- g_SetAllow[id] = 0
- }
- public plugin_cfg()
- {
- new configsDir[64]
- 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(6.1, "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("数据库连接失败")
- } else {
- dbi_query(g_dbc, "CREATE TABLE IF NOT EXISTS `%s` ( `uid` int(11) 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, PRIMARY KEY (`uid`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='AMX Mod X Admins' AUTO_INCREMENT=29 ;", g_tabname)
- dbi_close(g_dbc)
- }
- return PLUGIN_CONTINUE
- }
- public delayed_load()
- {
- new configFile[128], curMap[64], configDir[128]
- get_configsdir(configDir, sizeof(configDir)-1)
- get_mapname(curMap, sizeof(curMap)-1)
- new i=0;
-
- while (curMap[i] != '_' & curMap[i++] != '^0') {/*do nothing*/}
-
- if (curMap[i]=='_')
- {
- curMap[i]='^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[], ip[], password[])
- {
- new index = -1
- new result = 0
- new Flags[2];
- new Access[24];
- new Dw_Password[32];
- new Cn_CSId[32]
- g_CaseSensitiveName[id] = false;
- g_dbc = dbi_connect(g_host,g_user,g_pass,g_dbname,g_error,_MAX)
- if (g_dbc == SQL_FAILED)
- log_amx("%s %s %s %s 数据库连接失败 错误信息:%s ",g_host,g_user,g_pass,g_dbname,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,31)
- index = id
- }
- dbi_free_result(g_result)
- dbi_close(g_dbc)
- }
- if (index != -1)
- {
- if(equal(Flags,"e"))
- {
- result |= 8
- set_user_flags(id, read_flags(Access))
-
- g_SetAllow[id] = 1
- copy(g_SetName[id], 31, Cn_CSId)
- //set_task(3.0, "set_name", id)
-
- log_amx("管理员:%s (账户^"%s^") (权限 ^"%s^") (地址 ^"%s^")", Cn_CSId, name, Access, ip)
- }
- else
- {
- if (equal(password, Dw_Password))
- {
- result |= 12
- set_user_flags(id, read_flags(Access))
-
- g_SetAllow[id] = 1
- copy(g_SetName[id], 31, Cn_CSId)
- //set_task(3.0, "set_name", id)
-
- log_amx("管理员:%s (账户^"%s^") (权限 ^"%s^") (地址 ^"%s^")", Cn_CSId, name, Access, ip)
- }
- else
- {
- result |= 1
-
- if(equal(Flags,"a"))
- {
- result |= 2
- log_amx("由于密码错误 Kick (账户 ^"%s^") (地址 ^"%s^")", name,ip)
- }
- }
- }
- }
- 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[id])
- return PLUGIN_CONTINUE
- remove_user_flags(id)
- new userip[32], password[32], passfield[32], username[32]
-
- get_user_ip(id, userip, 31, 1)
-
- if (name[0])
- {
- copy(username, 31, name)
- }
- else
- {
- get_user_name(id, username, 31)
- }
-
- get_pcvar_string(amx_password_field, passfield, 31)
- get_user_info(id, passfield, password, 31)
-
- new result = getAccess(id, username, userip, 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")
- set_name(id)
- g_CaseSensitiveName[id]=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[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
-
- ig_setname(id, oldname)
-
- return FMRES_SUPERCEDE
- }
-
- g_SetAllow[id] = 0
- ig_setname(id, g_SetName[id])
- return FMRES_SUPERCEDE
- }
- public set_name(id)
- {
- set_user_info(id, "name", "")
- return PLUGIN_CONTINUE
- }
复制代码 点击进入下载-admin_sql.zip |
|