

/* AMX Mod script.
*
* This file is provided as is (no warranties).
*
*/ 

#include <amxmod>
#define ACCESS_ACTIVE ADMIN_CVAR
#define ACCESS_PASS ADMIN_LEVEL_A

public pass_active(id) { 
    if (!(get_user_flags(id)&ACCESS_ACTIVE)) { 
        client_print(id,print_console,"[AMX] Access Denied") 
        return PLUGIN_HANDLED 
    } 
    if (read_argc() != 2) 
    { 
        client_print(id,print_console,"[AMX] Usage: pass_active <1 | 0>") 
        return PLUGIN_HANDLED 
    } 
    new argstr[12] 
    read_argv(1,argstr,12) 
    new arg = str_to_num(argstr) 
    if ((arg != 1) && (arg != 0)) 
    { 
        client_print(id,print_console,"[AMX] Usage: pass_active <1 | 0>") 
        return PLUGIN_HANDLED 
    } 
    client_print(id,print_console,"[AMX] pass_active est à %i",arg) 
    set_cvar_num("Activepass",arg )
    return PLUGIN_HANDLED 
} 


public check_admin(){ 
	new activepassword = get_cvar_num("Activepass")
	if (activepassword == 1) {
		new players[32], inum
		get_players(players,inum)
		for(new i = 0; i < inum; ++i)	{
			if (get_user_flags(players[i])&ACCESS_PASS){ /* if any flags set */
				affichepass(1)
				return PLUGIN_CONTINUE 
			}
		}
		affichepass(0)
	}
	return PLUGIN_CONTINUE 
}

public active_pass(id){ 
	if ((get_user_flags(id)&ACCESS_PASS)) {
		check_admin()
	}
	return PLUGIN_CONTINUE 
}

public affichepass(active){
	new tmppass[15]
	if(active==1){
		set_hudmessage(0,255,255, -1.0, 0.15, 0, 6.0, 6.0, 0.5, 0.15, 1)
		show_hudmessage(0,"The password is disabled")
		tmppass = "none"
	} else {	
		set_hudmessage(255,0,0, -1.0, 0.15, 0, 6.0, 6.0, 0.5, 0.15, 1)
		show_hudmessage(0,"The password is enabled")
		get_cvar_string("PassValue",tmppass,15)		
	}
	server_cmd("sv_password %s",tmppass)
	server_exec()
	return PLUGIN_CONTINUE
} 

public client_connect(id) {
	if ((get_user_flags(id)&ACCESS_PASS)) {
		check_admin()
	}
	return PLUGIN_CONTINUE
}

public plugin_init() { 
	register_plugin("Admin password","0.7.3","[CCC]Taz-Devil") 
	register_cvar("PassValue", "YourPassword",FCVAR_PROTECTED)  
	register_cvar("Activepass", "1",FCVAR_SERVER)  
	register_clcmd("pass_active","pass_active",ACCESS_ACTIVE,"pass_active <1 | 0>")   
	register_clcmd("active_pass","active_pass",ACCESS_PASS,"Forcing pass")   
	set_task(60.0,"check_admin") /*60 sec. after map start, initialize hud message */
	set_task(300.0,"check_admin",0,"",0,"b") 
	return PLUGIN_CONTINUE 
}  


