Added in-game cmd "amx_addadmin <playername> <flags> [password] - automatically add specified player as an admin to users.ini"
This commit is contained in:
parent
01cc4a1bad
commit
87fd5e2b4e
@ -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]
|
||||
@ -83,9 +84,10 @@ public plugin_init() {
|
||||
register_cvar("amx_sql_pass","")
|
||||
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') )
|
||||
|
||||
register_clcmd( g_cmdLoopback, "ackSignal" )
|
||||
@ -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)
|
||||
@ -131,15 +204,15 @@ loadSettings(szFilename[]) {
|
||||
new szText[256], szFlags[32], szAccess[32]
|
||||
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 ( parse(szText, g_aName[ g_aNum ] ,31, g_aPassword[ g_aNum ], 31, szAccess,31,szFlags,31 ) < 2 )
|
||||
continue
|
||||
|
||||
g_aAccess[ g_aNum ] = read_flags(szAccess)
|
||||
g_aFlags[ g_aNum ] = read_flags( szFlags )
|
||||
g_aFlags[ g_aNum ] = read_flags( szFlags )
|
||||
++g_aNum
|
||||
}
|
||||
if (g_aNum == 1)
|
||||
@ -158,22 +231,22 @@ public adminSql() {
|
||||
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("[AMXX] %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
|
||||
|
||||
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)
|
||||
|
||||
@ -332,14 +405,14 @@ getAccess(id,name[],authid[],ip[], password[]) {
|
||||
|
||||
accessUser( id, name[] = "" ) {
|
||||
remove_user_flags(id)
|
||||
new userip[32],userauthid[32],password[32],passfield[32],username[32]
|
||||
get_user_ip(id,userip,31,1)
|
||||
new userip[32],userauthid[32],password[32],passfield[32],username[32]
|
||||
get_user_ip(id,userip,31,1)
|
||||
get_user_authid(id,userauthid,31)
|
||||
if ( name[0] ) copy( username , 31, name)
|
||||
else get_user_name(id,username,31 )
|
||||
get_cvar_string("amx_password_field",passfield,31)
|
||||
get_user_info(id,passfield,password,31)
|
||||
new result = getAccess(id,username,userauthid,userip,password)
|
||||
get_cvar_string("amx_password_field",passfield,31)
|
||||
get_user_info(id,passfield,password,31)
|
||||
new result = getAccess(id,username,userauthid,userip,password)
|
||||
if (result & 1) client_cmd(id,"echo ^"* %L^"",id,"INV_PAS")
|
||||
if (result & 2) {
|
||||
client_cmd(id,g_cmdLoopback)
|
||||
@ -351,12 +424,12 @@ accessUser( id, name[] = "" ) {
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
new newname[32], oldname[32]
|
||||
get_user_name(id,oldname,31)
|
||||
get_user_info(id,"name",newname,31)
|
||||
get_user_name(id,oldname,31)
|
||||
get_user_info(id,"name",newname,31)
|
||||
|
||||
if ( !equal(newname,oldname) )
|
||||
accessUser( id, newname )
|
||||
|
Loading…
Reference in New Issue
Block a user