AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Own custom admin flags (https://forums.alliedmods.net/showthread.php?t=320815)

Abhinash 01-10-2020 18:51

Own custom admin flags
 
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 ?

Bugsy 01-10-2020 20:47

Re: Own custom admin flags
 
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;
}


Abhinash 01-11-2020 06:51

Re: Own custom admin flags
 
Then update me up in this thread when you find a better way

OciXCrom 01-11-2020 07:45

Re: Own custom admin flags
 
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.

Bugsy 01-11-2020 12:14

Re: Own custom admin flags
 
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;



Abhinash 01-14-2020 09:25

Re: Own custom admin flags
 
Any better way of permission system ?

OciXCrom 01-14-2020 09:44

Re: Own custom admin flags
 
What's wrong with our suggestions?...

^SmileY 01-14-2020 09:50

Re: Own custom admin flags
 
Quote:

Originally Posted by Abhinash (Post 2680211)
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.

Natsheh 01-14-2020 10:01

Re: Own custom admin flags
 
Quote:

Originally Posted by Bugsy (Post 2679710)
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


Abhinash 01-19-2020 15:27

Re: Own custom admin flags
 
Quote:

Originally Posted by OciXCrom (Post 2679739)
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 ?


All times are GMT -4. The time now is 03:00.

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