AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   register_concomd with multiple access levels (https://forums.alliedmods.net/showthread.php?t=178146)

DPT 02-11-2012 23:37

register_concomd with multiple access levels
 
Hello again..

I have a question.. Can cmd_access check a command against multiple access levels? If yes, whats the sytanx exactly?

I've tried the following but it didnt work
register_concmd("amx_test","cmdTest",ADMIN_BA N & ADMIN_LEVEL_H & ADMIN_LEVEL_G)

In some other post, I saw that I should try doing the following

register_concmd("amx_test","cmdTest",ADMIN_BA N|ADMIN_LEVEL_H|ADMIN_LEVEL_G)

but again it didnt work..

Any help would be appreciated..

naXe 02-11-2012 23:44

Re: register_concomd with multiple access levels
 
&& ?

fysiks 02-12-2012 02:46

Re: register_concomd with multiple access levels
 
Quote:

Originally Posted by DPT (Post 1648774)
PHP Code:

register_concmd("amx_test","cmdTest",ADMIN_BAN ADMIN_LEVEL_H ADMIN_LEVEL_G


This won't let anyone access anything.

Quote:

Originally Posted by DPT (Post 1648774)
PHP Code:

register_concmd("amx_test","cmdTest",ADMIN_BAN|ADMIN_LEVEL_H|ADMIN_LEVEL_G


This will allow anyone with ADMIN_BAN or ADMIN_LEVEL_H or ADMIN_LEVEL_G access the command.

If you want to require all of the flags to access the command you can use this version of cmd_access() with the second version of register_concmd() that you posted.

PHP Code:

stock cmd_access_require_all(idlevelcidnumbool:accesssilent false
{
    new 
has_access 0;
    if ( 
id==(is_dedicated_server()?0:1) ) 
    {
        
has_access 1;
    }
    else if ( 
level==ADMIN_ADMIN )
    {
        if ( 
is_user_admin(id) )
        {
            
has_access 1;
        }
    }
    else if ( 
get_user_flags(id) & level == level )
    {
        
has_access 1;
    }
    else if (
level == ADMIN_ALL
    {
        
has_access 1;
    }

    if ( 
has_access==
    {
        if (!
accesssilent)
        {
#if defined AMXMOD_BCOMPAT
            
console_print(idSIMPLE_T("You have no access to that command."));
#else
            
console_print(id,"%L",id,"NO_ACC_COM");
#endif
        
}
        return 
0;
    }
    if (
read_argc() < num
    {
        new 
hcmd[32], hinfo[128], hflag;
        
get_concmd(cid,hcmd,31,hflag,hinfo,127,level);
#if defined AMXMOD_BCOMPAT
        
console_print(idSIMPLE_T("Usage:  %s %s"), hcmdSIMPLE_T(hinfo));
#else
        
console_print(id,"%L:  %s %s",id,"USAGE",hcmd,hinfo);
#endif
        
return 0;
    }
    
    return 
1;



DPT 02-12-2012 20:09

Re: register_concomd with multiple access levels
 
fysiks, I have tried:

PHP Code:

register_concmd("amx_test","cmdTest",ADMIN_BAN|ADMIN_LEVEL_H|ADMIN_LEVEL_G

Users with the ADMIN_BAN flag and ADMIN_LEVEL_H were able to access the command. However, users with ADMIN_LEVEL_G were not able to access it. Thats strange.. I tried swapping ADMIN_LEVEL_H with ADMIN_LEVEL_G and still the same results.. users with the ADMIN_LEVEL_G flag were not able to access the command.

To test even further, I tried this:

PHP Code:

register_concmd("amx_test","cmdknifes_only",ADMIN_BAN|ADMIN_LEVEL_G

and guess what, users with ADMIN_LEVEL_H were able to access the command although i removed ADMIN_LEVEL_H this time.. I think there's something wrong with the | between the access levels?

Any other alternative? How can i use get_user_flags to properly check if a user has either ADMIN_BAN OR ADMIN_LEVEL_H OR ADMIN_LEVEL_G flag using an if statement?

Can you please help?

fysiks 02-12-2012 20:50

Re: register_concomd with multiple access levels
 
Some of your experiences sound like you didn't update the .amxx file and restarting before trying again.

Any of the ADMIN_ constants can be put together with the | and it will work if the person has at least one of them.

What were the flags listed in users.ini of those who tried and it didn't work?

DPT 02-12-2012 20:58

Re: register_concomd with multiple access levels
 
Fysiks, I did.. Every time I update my plugin, I restart the server to make sure its updated.. for the users who have the ADMIN_LEVEL_G flag, the flags "fs" are in users.ini ... and for ADMIN_LEVEL_H, the flags in users.ini are "acfit"

Emp` 02-12-2012 21:32

Re: register_concomd with multiple access levels
 
Make sure your cmdaccess.ini (configs folder) is updated accordingly.

IIRC, once you register a command (and it is placed in the cmdaccess.ini) and then change the access flags, the cmdaccess.ini is not updated with the new flags; it still contains the old flags from the original register.

DPT 02-12-2012 21:44

Re: register_concomd with multiple access levels
 
Emp, to be honest, I did not understand you clearly.. Is there any easier method of checking if the user has either ADMIN_BAN or ADMIN_LEVEL_H or ADMIN_LEVEL_G.. Can't we do it using the get_user_flags function? How would the if statement look like?

This if statement didn't really work:

PHP Code:

new uflags get_user_flags(id)
if (
uflags != ADMIN_BAN uflags != ADMIN_LEVEL_G uflags != ADMIN_LEVEL_H)
return 
PLUGIN_HANDLED 


fysiks 02-12-2012 23:29

Re: register_concomd with multiple access levels
 
Quote:

Originally Posted by DPT (Post 1649408)
Emp, to be honest, I did not understand you clearly..

He said you need to look in /addons/amxmodx/configs/cmdaccess.ini. Find your command and change the flags to what you want in that file. In your case it would be "dst".


Quote:

Originally Posted by DPT (Post 1649408)
Is there any easier method of checking if the user has either ADMIN_BAN or ADMIN_LEVEL_H or ADMIN_LEVEL_G.. Can't we do it using the get_user_flags function? How would the if statement look like?

cmd_access() should work fine once you solve your issue. There is nothing wrong with cmd_access().

Quote:

Originally Posted by DPT (Post 1649408)
This if statement didn't really work:

PHP Code:

new uflags get_user_flags(id)
if (
uflags != ADMIN_BAN uflags != ADMIN_LEVEL_G uflags != ADMIN_LEVEL_H)
return 
PLUGIN_HANDLED 


FYI, nothing in that if statement conditional is correct. I recommend that you learn about logical and bitwise operators and how they differ. You will never want to use logical operators with ADMIN_ constants.

DPT 02-12-2012 23:42

Re: register_concomd with multiple access levels
 
Alright I did it.. I added the flags to cmdaccess.ini.. the line looks like that now

"test_plugin" "dgh" ; test.amxx

I saved it, restarted the server, and tried to access the command. However, I still get a "you have no access to that command"

Is there anything else im missing?


All times are GMT -4. The time now is 09:51.

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