Raised This Month: $32 Target: $400
 8% 

detecting admin command usage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dustinandband
Senior Member
Join Date: May 2015
Old 11-03-2019 , 16:13   detecting admin command usage
Reply With Quote #1

Been testing some different methods since yesterday and I can't seem to find a way to directly test if a command requires admin flags or not.

It seems like GetCommandOverride() should be able to detect this but it doesn't. Any ideas?

PHP Code:
public Action OnClientCommand(int clientint args)
{
    
// only bother if client's an admin
    
if (!client || !IsClientInGame(client) || IsFakeClient(client) || GetUserAdmin(client) == INVALID_ADMIN_ID)
        return 
Plugin_Continue;
    
    
char sCommand[64];
    
GetCmdArg(0sCommandsizeof(sCommand));
    
    
int flags;
    if (!
GetCommandOverride(sCommandOverride_Commandflags) || flags == 0)
    {
        
// not an admin command, skipping..
        
return Plugin_Continue;
    }
    
    
// admin command...

dustinandband is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 11-04-2019 , 08:47   Re: detecting admin command usage
Reply With Quote #2

Quote:
Originally Posted by dustinandband View Post
Been testing some different methods since yesterday and I can't seem to find a way to directly test if a command requires admin flags or not.

It seems like GetCommandOverride() should be able to detect this but it doesn't. Any ideas?

PHP Code:
public Action OnClientCommand(int clientint args)
{
    
// only bother if client's an admin
    
if (!client || !IsClientInGame(client) || IsFakeClient(client) || GetUserAdmin(client) == INVALID_ADMIN_ID)
        return 
Plugin_Continue;
    
    
char sCommand[64];
    
GetCmdArg(0sCommandsizeof(sCommand));
    
    
int flags;
    if (!
GetCommandOverride(sCommandOverride_Commandflags) || flags == 0)
    {
        
// not an admin command, skipping..
        
return Plugin_Continue;
    }
    
    
// admin command...

Admin commands will almost always have no overrides. An override just means the server changed the command's default flag through a config file.

Try GetCommandFlags
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334

Last edited by eyal282; 11-04-2019 at 08:48.
eyal282 is offline
dustinandband
Senior Member
Join Date: May 2015
Old 11-04-2019 , 23:23   Re: detecting admin command usage
Reply With Quote #3

Quote:
Originally Posted by eyal282 View Post
Admin commands will almost always have no overrides. An override just means the server changed the command's default flag through a config file.

Try GetCommandFlags
I believe GetCommandFlags() is for FCVAR flags. I'm wanting to determine if a command is registered as an admin command (ADMFLAG_).

Also worth noting I don't think checkcommandaccess() would work either. I'm not interested in seeing if a client has access to a command, but rather looking at the command itself (what bitstrings it was registered with).

I guess if i was real desperate i could just log any commands that contain "sm_" in them but I rather not do it that way.
dustinandband is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 11-05-2019 , 00:56   Re: detecting admin command usage
Reply With Quote #4

Use the iterators, either google "sourcemod CommandIterator" or google info on "FindFirstConCmd"
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 11-05-2019 , 04:15   Re: detecting admin command usage
Reply With Quote #5

You can check out the source code of this plugin to see how the author did it: https://forums.alliedmods.net/showthread.php?t=163780
__________________
Psyk0tik is offline
Balimbanana
Member
Join Date: Jan 2017
Old 11-05-2019 , 19:58   Re: detecting admin command usage
Reply With Quote #6

What about GetUserFlagBits(client) ? It gets the total bit sum of what admin flags the client has.
Along with:
Code:
bool CheckCommandAccess(int client, const char[] command, int flags, bool override_only)
Balimbanana is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 11-06-2019 , 03:41   Re: detecting admin command usage
Reply With Quote #7

Quote:
Originally Posted by Balimbanana View Post
What about GetUserFlagBits(client) ? It gets the total bit sum of what admin flags the client has.
Along with:
Code:
bool CheckCommandAccess(int client, const char[] command, int flags, bool override_only)
He wants to check the flags of commands. Checking client flags won't give him the information he needs.

For example, a client can have root access (ADMFLAG_ROOT) but the command may only require ADMFLAG_SLAY.
__________________
Psyk0tik is offline
dustinandband
Senior Member
Join Date: May 2015
Old 11-06-2019 , 11:17   Re: detecting admin command usage
Reply With Quote #8

Thanks guys!

I suppose the cleanest way to do this would be adding a command listener to all admin commands while iterating through them - like this plugin does, instead of iterating over all the commands every time you want to see if an admin used an admin-registered sourcemod command.

Hopefully in future versions of sourcemod there'll be a function for checking a command's admin bitstring directly instead of deploying these hacky work-arounds.
dustinandband is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:35.


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