AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Get command admin flags (https://forums.alliedmods.net/showthread.php?t=309085)

Phil25 07-13-2018 07:36

Get command admin flags
 
I'm looking for a way to get admin flags of a SourceMod command, such as sm_kick.

GetCommandFlags provides only FCVAR_* flags (similar to GetConVarFlags), 0 for any SM commands.
GetCommandOverride seems to provide the flags only when the command is overridden.

The only way I've found so far is by using ReadCommandIterator, however, I would have to iterate every command each time I want to check. Or perhaps there is a way to get the handle of a specific command?

Thank you in advance.

eyal282 07-13-2018 08:15

Re: Get command admin flags
 
Quote:

Originally Posted by Phil25 (Post 2603281)
I'm looking for a way to get admin flags of a SourceMod command, such as sm_kick.

GetCommandFlags provides only FCVAR_* flags (similar to GetConVarFlags), 0 for any SM commands.
GetCommandOverride seems to provide the flags only when the command is overridden.

The only way I've found so far is by using ReadCommandIterator, however, I would have to iterate every command each time I want to check. Or perhaps there is a way to get the handle of a specific command?

Thank you in advance.

Iterator is best, use it.

Phil25 07-13-2018 08:38

Re: Get command admin flags
 
The whole point of this is that by having the flags only, I need to check if they are sufficient to access a command.

Here's a method of creating a temporary anonymous admin, setting their flags and then using it for CheckAccess.

PHP Code:

stock bool CheckCommandAccessFlags(const char[] sCmd, const char[] sFlags){
    
AdminId hAdmin CreateAdmin("");

    
int i = -1;
    
AdminFlag eFlag;
    while(
sFlags[++i] != '\0')
        if(
FindFlagByChar(sFlags[i], eFlag))
            
hAdmin.SetFlag(eFlagtrue);

    
bool bResult CheckAccess(hAdminsCmd0false);
    
RemoveAdmin(hAdmin);
    return 
bResult;


I've found that it works properly, and has the additional benefit of respecting the overrides.

Quote:

Originally Posted by eyal282 (Post 2603288)
Iterator is best, use it.

I have over 400 sm commands, would iterating all of them be faster than creating a temp admin every time?

Fyren 07-14-2018 01:14

Re: Get command admin flags
 
I don't think there's a function to directly do what you want, though one could be added.

That said, flags aren't really useful if you're building a more featureful admin system. There's only so many flags available but there will be many commands (as you say, you have 400+). Groups and overrides may be the way to go, depending on what you're really trying to do.


All times are GMT -4. The time now is 16:12.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.