|
发表于 2010-7-25 04:08:56
|
显示全部楼层
来自 中国–广西–南宁
老友记的那个dll- CREATE 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[16];
- new bool:g_CaseSensitiveName[33];
- new bool:Dbid[33];
- new amx_mode;
- new amx_username_field,amx_password_field;
- new g_SetAllow[33],g_SetName[35][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")
- 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[64]
- get_configsdir(configsDir, 63)
-
- server_cmd("exec %s/amxx.cfg", configsDir)
- server_cmd("exec %s/sql.cfg", configsDir)
- }
- public client_connect(id)
- {
- g_CaseSensitiveName[id] = false;
- Dbid[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(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[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[], password[])
- {
- new index = -1
- new result = 0
- new Flags[2];
- new Access[24];
- new Dw_Password[32];
- new Cn_CSId[51];
- 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("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[id] = true;
- if(equal(Flags,"e"))
- {
- result |= 8
- set_user_flags(id, read_flags(Access))
-
- g_SetAllow[id] = 1
- copy(g_SetName[id], 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[id] = 1
- copy(g_SetName[id], 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[id])
- return PLUGIN_CONTINUE
- remove_user_flags(id)
- new password[32], passfield[32], username[32],namefield[32]
-
- if (name[0])
- {
- 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[id])
- 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[35], newname[35]
- 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[id] = 0
- ig_setname(id, g_SetName[id])
- return FMRES_SUPERCEDE
- }
- public set_name(id)
- {
- set_user_info(id, "name", "")
- return PLUGIN_CONTINUE
- }
复制代码 |
|