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

Own custom admin flags


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 01-10-2020 , 18:51   Own custom admin flags
Reply With Quote #1

Hello there.
So, in my server I have like more than 30 console admin commands.
My question is instead of using the delay admin flags which are like "abcdef...", How can I use flags like - @#$ ??
I means I want to use "@" as a flag. How to do it ?
Abhinash is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-10-2020 , 20:47   Re: Own custom admin flags
Reply With Quote #2

Flags are stored in a bitsum in a 4-byte cell (32 bits) so you are limited to 32 flags. The way they are read using read_flags() is flags |= ( 1 << [char] - 'a') . So it's basically subtracting the ascii code for 'a' from each character you give to it, so you can go beyond character 'z' until you reach 'a' + 31.

I am not certain whether or not AMX-X uses these bits for anything, can anyone involved with AMX-X development weigh in?

Below are the characters and ASCII codes that can possibly be used as flags:
{ = 123
| = 124
} = 125
~ = 126
Char 127 (character does not display in editors or forum so I would avoid using it)
€ = 128

Can be added to your plugin:
Code:
#define ADMIN_CUSTOM1	    (1<<26) /* flag "{" */
#define ADMIN_CUSTOM2	    (1<<27) /* flag "|" */
#define ADMIN_CUSTOM3	    (1<<28) /* flag "}" */
#define ADMIN_CUSTOM4	    (1<<29) /* flag "~" */
#define ADMIN_CUSTOM5	    (1<<30) /* flag NA */
#define ADMIN_CUSTOM6	    (1<<31) /* flag "€" */
Edit: I found that the get_flags() native limits flags to between 'a' and 'z' so avoid using that with these flags. I'm not sure what else may be impacted, so I'd probably avoid using these custom flags and figuring out another way.

Code:
void UTIL_GetFlags(char* f, int a)
{
	for (int i = 'a'; i <= 'z'; ++i)
	{
		if (a & 1) *f++ = i;
		a >>= 1;
	}

	*f = 0;
}
__________________

Last edited by Bugsy; 01-10-2020 at 21:15.
Bugsy is offline
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 01-11-2020 , 06:51   Re: Own custom admin flags
Reply With Quote #3

Then update me up in this thread when you find a better way
Abhinash is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-11-2020 , 07:45   Re: Own custom admin flags
Reply With Quote #4

You'll probably need some other method for this rather than flags, because you have limited flags, but unlimited commands.

I'm currently working on a very flexible permission-based plugin/admin system that allows you to use permissions for each command instead of admin flags (e.g. for amx_slap you would need amxcmd.slap permission or amxcmd.* for all commands). Maybe you can use that when I release it.
__________________

Last edited by OciXCrom; 01-11-2020 at 07:46.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-11-2020 , 12:14   Re: Own custom admin flags
Reply With Quote #5

Can do something like this, or wait for OciXCrom's plugin.

set_permission <name> <- or +> <permission #>

Code:
set_permission bugsy + 2
set_permission bugsy + 5
set_permission bugsy - 2
You will need nVault Array
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <nvault_array>

new const Version[] = "0.1";

enum Permissions
{
    
Custom1 1,
    
Custom2,
    
Custom3,
    
Custom4,
    
Custom5
}

new 
g_szAuthIDMAX_PLAYERS ][ 34 ];
new 
bool:g_bUserPermissionsMAX_PLAYERS ][ Permissions ];
new 
g_Vault;

public 
plugin_init() 
{
    
register_plugin"Permissions" Version "bugsy" );
    
    
register_concmd"set_permission" "SetPermission" );
    
    
g_Vault nvault_open"permissions_vault" );
}

public 
plugin_end()
{
    
nvault_closeg_Vault );
}

public 
client_authorizedid )
{
    new 
iTS;
    
get_user_authidid g_szAuthIDid ] , charsmaxg_szAuthID[] ) );
    
nvault_get_arrayg_Vault g_szAuthIDid ] , g_bUserPermissionsid ][ Permissions:] , sizeofg_bUserPermissions[] ) , iTS );
}

#if AMXX_VERSION_NUM == 190
public client_disconnectedid )
#else
public client_disconnectid )
#endif
{
    
nvault_set_arrayg_Vault g_szAuthIDid ] , g_bUserPermissionsid ][ Permissions:] , sizeofg_bUserPermissions[] ) );
}

public 
SetPermissionid )
{
    new 
szArgName32 ] , szArgCommand] , szPermission] , iPlayer Permissions:pPermission;
    
    if ( !( 
get_user_flagsid ) & ADMIN_RCON ) )
    {
        
console_printid "* You do not have permission to use this command." );
        return 
PLUGIN_HANDLED;
    }

    if ( ( 
read_argvszArgName charsmaxszArgName ) ) ) && ( read_argvszArgCommand charsmaxszArgCommand ) ) ) && ( read_argvszPermission charsmaxszPermission ) ) ) )
    {
        if ( !( 
Custom1 <= ( pPermission Permissions:str_to_numszPermission ) ) < Permissions ) )
        {
            
console_printid "* Invalid permission entered, must be between %d and %d" Custom1 _:Permissions );
            return 
PLUGIN_HANDLED;
        }
        
        if ( !( 
szArgCommand] == '+' || szArgCommand] == '-' ) )
        {
            
console_printid "* Invalid command, must be - or +" );
            return 
PLUGIN_HANDLED;
        }
        
        if ( ( 
iPlayer cmd_targetid szArgName ) ) ) 
        {
            
get_user_nameiPlayer szArgName charsmaxszArgName ) );
            
            if ( 
szArgCommand] == '+' && g_bUserPermissionsiPlayer ][ pPermission ] )
            {
                
console_printid "* %s already has permission %d" szArgName pPermission );
                return 
PLUGIN_HANDLED;
            }
            
            if ( 
szArgCommand] == '-' && !g_bUserPermissionsiPlayer ][ pPermission ] )
            {
                
console_printid "* %s does not currently have permission %d" szArgName pPermission );
                return 
PLUGIN_HANDLED;
            }
            
            
g_bUserPermissionsiPlayer ][ pPermission ] = bool:( szArgCommand] == '+' );
            
            
console_printid "* Permission %d %s for %s" pPermission g_bUserPermissionsiPlayer ][ pPermission ] ? "added" "removed" szArgName );
        }
    }
    else
    {
        
console_printid "* Incorrect arguments: give_permission <player> <+ or -> <permission # %d to %d>" Custom1 _:Permissions );
    }
    
    return 
PLUGIN_HANDLED;

__________________

Last edited by Bugsy; 01-11-2020 at 14:30.
Bugsy is offline
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 01-14-2020 , 09:25   Re: Own custom admin flags
Reply With Quote #6

Any better way of permission system ?
Abhinash is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-14-2020 , 09:44   Re: Own custom admin flags
Reply With Quote #7

What's wrong with our suggestions?...
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 01-14-2020 , 09:50   Re: Own custom admin flags
Reply With Quote #8

Quote:
Originally Posted by Abhinash View Post
Any better way of permission system ?
i Suggest you to describe better what you want for custom permission system.
Not only flags itself, since change a ~ z for symbols do not make any sense.
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-14-2020 , 10:01   Re: Own custom admin flags
Reply With Quote #9

Quote:
Originally Posted by Bugsy View Post
I am not certain whether or not AMX-X uses these bits for anything, can anyone involved with AMX-X development weigh in?

[/code]
Me myself it was very helpful as no access flag in the amxx new menu system.

Heres an example
PHP Code:
    const NO_ACCESS = (1<<26);
    
    
pratio formatex(sTextcharsmax(sText), "\rPrisoner's \w( Terrorist )"):formatex(sTextcharsmax(sText), "Prisoner's ( Terrorist )")
    
menu_additem(iMenusText"1"pratio 0:NO_ACCESS
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-14-2020 at 10:02.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 01-19-2020 , 15:27   Re: Own custom admin flags
Reply With Quote #10

Quote:
Originally Posted by OciXCrom View Post
You'll probably need some other method for this rather than flags, because you have limited flags, but unlimited commands.

I'm currently working on a very flexible permission-based plugin/admin system that allows you to use permissions for each command instead of admin flags (e.g. for amx_slap you would need amxcmd.slap permission or amxcmd.* for all commands). Maybe you can use that when I release it.
When are you going to release it ?
Abhinash 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 11:26.


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