|
发表于 2005-2-25 07:36:58
|
显示全部楼层
来自 中国–江苏–常州–钟楼区
admin.sma
#if defined USING_SQL
public adminSql() {
new host[64],user[32],pass[32],db[32],table[32],error[128]
get_cvar_string("amx_sql_host",host,63)
get_cvar_string("amx_sql_user",user,31)
get_cvar_string("amx_sql_pass",pass,31)
get_cvar_string("amx_sql_db",db,31)
get_cvar_string("amx_sql_table",table,31)
new Sql:sql = dbi_connect(host,user,pass,db,error,127)
if (sql <= SQL_FAILED) {
server_print("%L",LANG_SERVER,"SQL_CANT_CON",error)
//backup to users.ini
new configsDir[64]
get_configsdir(configsDir, 63)
format(configsDir, 63, "%s/users.ini", configsDir)
loadSettings(configsDir) // Load admins accounts
return PLUGIN_HANDLED
}
dbi_query(sql,"CREATE TABLE IF NOT EXISTS `%s` ( `auth` VARCHAR( 32 ) NOT NULL, `password` VARCHAR( 32 ) NOT NULL, `access` VARCHAR( 32 ) NOT NULL, `flags` VARCHAR( 32 ) NOT NULL ) COMMENT = 'AMX Mod X Admins'",table)
new Result:Res = dbi_query(sql,"SELECT `auth`,`password`,`access`,`flags` FROM `%s`",table)
if (Res == RESULT_FAILED) {
dbi_error(sql,error,127)
server_print("%L",LANG_SERVER,"SQL_CANT_LOAD_ADMINS",error)
dbi_free_result(Res)
dbi_close(sql)
return PLUGIN_HANDLED
}
else if (Res == RESULT_NONE) {
server_print("%L",LANG_SERVER,"NO_ADMINS")
dbi_free_result(Res)
dbi_close(sql)
return PLUGIN_HANDLED
}
new szFlags[32],szAccess[32]
g_aNum = 0
while( dbi_nextrow(Res) > 0 ) {
dbi_result(Res, "auth", g_aName[g_aNum], 31)
dbi_result(Res, "password", g_aPassword[g_aNum], 31)
dbi_result(Res, "access", szAccess, 31)
dbi_result(Res, "flags", szFlags, 31)
g_aAccess[ g_aNum ] = read_flags( szAccess )
g_aFlags[ g_aNum ] = read_flags( szFlags )
++g_aNum
}
if (g_aNum == 1)
server_print("%L", LANG_SERVER, "SQL_LOADED_ADMIN" )
else
server_print("%L", LANG_SERVER, "SQL_LOADED_ADMINS", g_aNum )
dbi_free_result(Res)
dbi_close(sql)
return PLUGIN_HANDLED
}
#endif
public cmdReload(id,level,cid) {
if (!cmd_access(id,level,cid,1))
return PLUGIN_HANDLED
//strip original flags (patch submitted by mrhunt)
remove_user_flags(0,read_flags("z"))
#if !defined USING_SQL
new filename[128]
get_configsdir(filename,127)
format(filename,63,"%s/users.ini", filename)
g_aNum = 0
loadSettings(filename) // Re-Load admins accounts
if (id != 0) {
if (g_aNum == 1)
console_print(id,"%L", LANG_SERVER, "LOADED_ADMIN" )
else
console_print(id,"%L", LANG_SERVER, "LOADED_ADMINS", g_aNum )
}
#else
adminSql()
if (id != 0) {
if (g_aNum == 1)
console_print(id,"%L", LANG_SERVER, "SQL_LOADED_ADMIN" )
else
console_print(id,"%L", LANG_SERVER, "SQL_LOADED_ADMINS", g_aNum )
}
#endif
return PLUGIN_HANDLED
} |
|