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
#define MAX_ADMINS 64
#define PLUGINNAME "AMX Mod X"
new g_aPassword[MAX_ADMINS][32]
new g_aName[MAX_ADMINS][32]
@ -84,6 +85,7 @@ public plugin_init() {
register_cvar("amx_sql_db","amx")
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" ,
random_num('A','Z') , random_num('A','Z') ,random_num('A','Z'),random_num('A','Z') )
@ -111,6 +113,77 @@ public plugin_modules()
}
#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() {
new configFile[64],curMap[32]
get_configsdir(configFile,31)