View Single Post
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-30-2020 , 17:22   Re: CheckCommandAccess fails check access
Reply With Quote #4

You maybe want start use admin groups, not need hassle with flags.


Example:
Code:
enum
{
	NONE = 0,
	ADMIN,
	MODER,
	VIP,
	totalgroups
}

int PlayersNum[totalgroups];

public void OnPluginStart()
{
	RegConsoleCmd("sm_test", test);
}

public Action test(int client, int args)
{

	for(int a = 0; a < sizeof(PlayersNum); a++)
	{
		PlayersNum[a] = 0;
	}

	PrintToServer("\n");
	
	for(int i = 1; i <= MaxClients; i++)
	{
		// skip
		if(!IsClientInGame(i) || !IsClientAuthorized(i)) continue;

		// Check order from highest to low, ADMIN -> MODER -> VIP


		if(CheckCommandAccess(i, "access_ADMIN", ADMFLAG_ROOT, true)) // true = will not look admin flags from command called 'access_ADMIN'
		{
			PrintToServer("%N have 'access_ADMIN'", i);
			PlayersNum[ADMIN]++;
			continue;
		}

		if(CheckCommandAccess(i, "access_MODER", ADMFLAG_ROOT, true))
		{
			PrintToServer("%N have 'access_MODER'", i);
			PlayersNum[MODER]++;
			continue;
		}

		if(CheckCommandAccess(i, "access_VIP", ADMFLAG_ROOT, true))
		{
			PrintToServer("%N have 'access_VIP'", i);
			PlayersNum[VIP]++;
			continue;
		}

		PlayersNum[NONE]++;
	}



	PrintToServer("PlayersNum[NONE]	= %i",	PlayersNum[NONE]);
	PrintToServer("PlayersNum[ADMIN]	= %i", PlayersNum[ADMIN]);
	PrintToServer("PlayersNum[MODER]	= %i", PlayersNum[MODER]);
	PrintToServer("PlayersNum[VIP]		= %i", 	PlayersNum[VIP]);


	return Plugin_Handled;
}

admin_groups.cfg
Code:
Groups
{
	/**
	 * Allowed properties for a group:
	 *
	 *   "flags"           - Flag string.
	 *   "immunity"        - Immunity level number, or a group name.
	 *						 If the group name is a number, prepend it with an 
	 *						 '@' symbol similar to admins_simple.ini.  Users 
	 *						 will only inherit the level number if it's higher 
	 *						 than their current value.
	 */
	"Default"
	{
		"immunity"		"1"
	}
	
	"Full Admins"
	{
		/**
		 * You can override commands and command groups here.
		 * Specify a command name or group and either "allow" or "deny"
		 * Examples:
		 * 		":CSDM"			"allow"
		 *		"csdm_enable"	"deny"
		 */
		 Overrides
		 {
		 }
		"flags"			"abcdefghijklmnopqrst"

		/* Largish number for lots of in-between values. */
		"immunity"		"99"
	}

	"Admin"
	{
		"flags" "abcdefghijklmn"
		
		"Overrides"
		{
			"access_ADMIN"	"allow"
		}
	}


	"Moderator"
	{
		"flags" "abc"
		
		"Overrides"
		{
			"access_MODER"	"allow"
		}
	}


	"VIP"
	{
		"flags" "op"
		
		"Overrides"
		{
			"access_VIP"	"allow"
		}
	}

}
admins.cfg
Code:
/**
* USE THIS SECTION TO DECLARE DETAILED ADMIN PROPERTIES.
*
* Each admin should have its own "Admin" section, followed by a name.
* The name does not have to be unique.
*
* Available properties: (Anything else is filtered as custom)
*      "auth"          - REQUIRED - Auth method to use.  Built-in methods are:
*                        "steam"  - Steam based authentication
*                        "name"   - Name based authentication
*                        "ip"    - IP based authentication
*                        Anything else is treated as custom.
*                     Note: Only one auth method is allowed per entry.
*
*      "identity"      - REQUIRED - Identification string, for example, a steamid or name.
*                     Note: Only one identity is allowed per entry.
*
*      "password"      - Optional password to require.
*      "group"         - Adds one group to the user's group table.
*      "flags"         - Adds one or more flags to the user's permissions.
*        "immunity"        - Sets the user's immunity level (0 = no immunity).
*                          Immunity can be any value.  Admins with higher 
*                          values cannot be targetted.  See sm_immunity_mode 
*                          to tweak the rules.  Default value is 0.
*
* Example:
	"BAILOPAN"
	{
		"auth"            "steam"
		"identity"        "STEAM_0:1:16"
		"flags"            "abcdef"
	}
*
*/
Admins
{
	"Bacardi"
	{
		"auth"        "steam"
		"identity"    "STEAM_1:1:14163588"
		"group"			"Admin"
	}

	"QWERTY"
	{
		"auth"        "steam"
		"identity"    "STEAM_1:1:14163586"
		"group"			"Moderator"
	}

	"Asdasd"
	{
		"auth"        "steam"
		"identity"    "STEAM_1:1:14163582"
		"group"			"VIP"
	}  
}

And my tip is:
- If you want avoid admin problems in future, do not give ROOT flag "z" to anyone.
Not even yourself.


ROOT flag have access to all, bypass admin immunity, everything. You not actually want that.
https://sm.alliedmods.net/new-api/admin/AdminFlag

What useful you can do with ROOT flag is, restrict some admin commands or admin check from different admin groups. Use admin_overrides.cfg
Bacardi is offline