Added in-game cmd "amx_addadmin <playername> <flags> [password] - automatically add specified player as an admin to users.ini"

This commit is contained in:
Johnny Bergström 2005-03-24 10:59:46 +00:00
parent 01cc4a1bad
commit 87fd5e2b4e

View File

@ -42,6 +42,7 @@
#endif #endif
#define MAX_ADMINS 64 #define MAX_ADMINS 64
#define PLUGINNAME "AMX Mod X"
new g_aPassword[MAX_ADMINS][32] new g_aPassword[MAX_ADMINS][32]
new g_aName[MAX_ADMINS][32] new g_aName[MAX_ADMINS][32]
@ -83,9 +84,10 @@ public plugin_init() {
register_cvar("amx_sql_pass","") register_cvar("amx_sql_pass","")
register_cvar("amx_sql_db","amx") register_cvar("amx_sql_db","amx")
register_concmd("amx_reloadadmins","cmdReload",ADMIN_CFG) register_concmd("amx_reloadadmins", "cmdReload", ADMIN_CFG)
register_concmd("amx_addadmin", "addadminfn", ADMIN_CFG, "<playername> <flags> [password] - automatically add specified player as an admin to users.ini")
format( g_cmdLoopback, 15, "amxauth%c%c%c%c" , 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') ) random_num('A','Z') , random_num('A','Z') ,random_num('A','Z'),random_num('A','Z') )
register_clcmd( g_cmdLoopback, "ackSignal" ) register_clcmd( g_cmdLoopback, "ackSignal" )
@ -111,6 +113,77 @@ public plugin_modules()
} }
#endif #endif
public addadminfn(id, level, cid) {
if (!cmd_access(id, level, cid, 3))
return PLUGIN_HANDLED
new arg[33]
read_argv(1, arg, 32)
new player = cmd_target(id, arg, 2) // 2 = allow yourself (remove later?) 8 = no bots
if (!player)
return PLUGIN_HANDLED
new flags[64]
read_argv(2, flags, 63)
new password[64]
if (read_argc() == 4)
read_argv(3, password, 63)
new steamid[64]
get_user_authid(player, steamid, 63)
AddAdmin(id, steamid, flags, password)
cmdReload(id, ADMIN_CFG, 0)
return PLUGIN_HANDLED
}
AddAdmin(id, steamid[], accessflags[], password[]) {
// Make sure that the users.ini file exists.
new configsDir[64]
get_configsdir(configsDir, 63)
format(configsDir, 63, "%s/users.ini", configsDir)
if (!file_exists(configsDir)) {
console_print(id, "[%s] File ^"%s^" doesn't exist.", PLUGINNAME, configsDir)
return
}
// Make sure steamid isn't already in file.
new line = 0, textline[256], len
const SIZE = 63
new line_steamid[SIZE + 1], line_password[SIZE + 1], line_accessflags[SIZE + 1], line_flags[SIZE + 1], parsedParams
// <name|ip|steamid> <password> <access flags> <account flags>
while ((line = read_file(configsDir, line, textline, 255, len))) {
if (len == 0 || equal(textline, ";", 1))
continue // comment line
parsedParams = parse(textline, line_steamid, SIZE, line_password, SIZE, line_accessflags, SIZE, line_flags, SIZE)
if (parsedParams != 4)
continue // Send warning/error?
if (containi(line_flags, "c") != -1 && equal(line_steamid, steamid)) {
console_print(id, "[%s] %s already exists!", PLUGINNAME, steamid)
return
}
//console_print(id, "Found: %s, %s, %s, %s", line_steamid, line_password, line_accessflags, line_flags)
}
// If we came here, steamid doesn't exist in users.ini. Add it.
// Find out what flags we need.
new flags[64] = "c" // Always use steamid
new flagslen = strlen(flags)
if (strlen(password) == 0)
flagslen += format(flags[flagslen], 63 - flagslen, "e") // add flag to not check password if password wasn't supplied
new linetoadd[512]
format(linetoadd, 511, "^"%s^" ^"%s^" ^"%s^" ^"%s^"", steamid, password, accessflags, flags)
console_print(id, "Adding:^n%s", linetoadd)
if (!write_file(configsDir, linetoadd))
console_print(id, "[%s] Failed writing to %s!", PLUGINNAME, configsDir)
}
public plugin_cfg() { public plugin_cfg() {
new configFile[64],curMap[32] new configFile[64],curMap[32]
get_configsdir(configFile,31) get_configsdir(configFile,31)
@ -131,15 +204,15 @@ loadSettings(szFilename[]) {
new szText[256], szFlags[32], szAccess[32] new szText[256], szFlags[32], szAccess[32]
new a, pos = 0 new a, pos = 0
while ( g_aNum < MAX_ADMINS && read_file(szFilename,pos++,szText,255,a) ) while ( g_aNum < MAX_ADMINS && read_file(szFilename,pos++,szText,255,a) )
{ {
if ( szText[0] == ';' ) continue if ( szText[0] == ';' ) continue
if ( parse(szText, g_aName[ g_aNum ] ,31, g_aPassword[ g_aNum ], 31, szAccess,31,szFlags,31 ) < 2 ) if ( parse(szText, g_aName[ g_aNum ] ,31, g_aPassword[ g_aNum ], 31, szAccess,31,szFlags,31 ) < 2 )
continue continue
g_aAccess[ g_aNum ] = read_flags(szAccess) g_aAccess[ g_aNum ] = read_flags(szAccess)
g_aFlags[ g_aNum ] = read_flags( szFlags ) g_aFlags[ g_aNum ] = read_flags( szFlags )
++g_aNum ++g_aNum
} }
if (g_aNum == 1) if (g_aNum == 1)
@ -158,22 +231,22 @@ public adminSql() {
get_cvar_string("amx_sql_pass",pass,31) get_cvar_string("amx_sql_pass",pass,31)
get_cvar_string("amx_sql_db",db,31) get_cvar_string("amx_sql_db",db,31)
get_cvar_string("amx_sql_table",table,31) get_cvar_string("amx_sql_table",table,31)
new Sql:sql = dbi_connect(host,user,pass,db,error,127) new Sql:sql = dbi_connect(host,user,pass,db,error,127)
if (sql <= SQL_FAILED) { if (sql <= SQL_FAILED) {
server_print("[AMXX] %L",LANG_SERVER,"SQL_CANT_CON",error) server_print("[AMXX] %L",LANG_SERVER,"SQL_CANT_CON",error)
//backup to users.ini //backup to users.ini
new configsDir[64] new configsDir[64]
get_configsdir(configsDir, 63) get_configsdir(configsDir, 63)
format(configsDir, 63, "%s/users.ini", configsDir) format(configsDir, 63, "%s/users.ini", configsDir)
loadSettings(configsDir) // Load admins accounts loadSettings(configsDir) // Load admins accounts
return PLUGIN_HANDLED 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) 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) new Result:Res = dbi_query(sql,"SELECT `auth`,`password`,`access`,`flags` FROM `%s`",table)
@ -332,14 +405,14 @@ getAccess(id,name[],authid[],ip[], password[]) {
accessUser( id, name[] = "" ) { accessUser( id, name[] = "" ) {
remove_user_flags(id) remove_user_flags(id)
new userip[32],userauthid[32],password[32],passfield[32],username[32] new userip[32],userauthid[32],password[32],passfield[32],username[32]
get_user_ip(id,userip,31,1) get_user_ip(id,userip,31,1)
get_user_authid(id,userauthid,31) get_user_authid(id,userauthid,31)
if ( name[0] ) copy( username , 31, name) if ( name[0] ) copy( username , 31, name)
else get_user_name(id,username,31 ) else get_user_name(id,username,31 )
get_cvar_string("amx_password_field",passfield,31) get_cvar_string("amx_password_field",passfield,31)
get_user_info(id,passfield,password,31) get_user_info(id,passfield,password,31)
new result = getAccess(id,username,userauthid,userip,password) new result = getAccess(id,username,userauthid,userip,password)
if (result & 1) client_cmd(id,"echo ^"* %L^"",id,"INV_PAS") if (result & 1) client_cmd(id,"echo ^"* %L^"",id,"INV_PAS")
if (result & 2) { if (result & 2) {
client_cmd(id,g_cmdLoopback) client_cmd(id,g_cmdLoopback)
@ -351,12 +424,12 @@ accessUser( id, name[] = "" ) {
} }
public client_infochanged(id) { public client_infochanged(id) {
if ( !is_user_connected(id) || !get_cvar_num("amx_mode") ) if ( !is_user_connected(id) || !get_cvar_num("amx_mode") )
return PLUGIN_CONTINUE return PLUGIN_CONTINUE
new newname[32], oldname[32] new newname[32], oldname[32]
get_user_name(id,oldname,31) get_user_name(id,oldname,31)
get_user_info(id,"name",newname,31) get_user_info(id,"name",newname,31)
if ( !equal(newname,oldname) ) if ( !equal(newname,oldname) )
accessUser( id, newname ) accessUser( id, newname )