Raised This Month: $51 Target: $400
 12% 

View Poll Results: Have you noticed the problem with this native?
Yes 1 8.33%
No 11 91.67%
Voters: 12. You may not vote on this poll

Solved GetUserFlagBits seems to be broken


Post New Thread Reply   
 
Thread Tools Display Modes
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 06-29-2016 , 14:34   Re: GetUserFlagBits seems to be broken
Reply With Quote #11

Quote:
Originally Posted by arne1288 View Post
As in, ... CheckCommandAccess ?
Then why isnt an official sourcemod plugin using it?
__________________
luki1412 is offline
Wilczek
AlliedModders Donor
Join Date: Oct 2012
Location: Poland
Old 06-29-2016 , 15:00   Re: GetUserFlagBits seems to be broken
Reply With Quote #12

Quote:
Originally Posted by luki1412 View Post
Check out the attached plugin below, not made by me, but using this native and not working 100% of the time.
Code:
new String:CharAdminFlag[32];

public OnPluginStart()
{
    bri_charadminflag = CreateConVar("bri_charadminflag", "a", "Admin flag to use for immunity (only one).  Must be a in char format.");
}

public OnConfigsExecuted()
{
    GetConVarString(bri_charadminflag, CharAdminFlag, sizeof(CharAdminFlag));
}

public OnClientPostAdminCheck(client)
{
    if (IsValidAdmin(client, CharAdminFlag))
        IsPlayerAdmin[client] = true;
    else
        IsPlayerAdmin[client] = false;
}

stock bool:IsValidAdmin(client, const String:flags[])
{
    if (!IsClientConnected(client))
        return false;
    new ibFlags = ReadFlagString(flags);
    if ((GetUserFlagBits(client) & ibFlags) == ibFlags) {
        return true;
    }
    if (GetUserFlagBits(client) & ADMFLAG_ROOT) {
        return true;
    }
    return false;
}
Doesn't it return true only if a client has the only flag you are looking for ('a' in this case) or if he's a root?

---
Quote:
Originally Posted by ddhoward View Post
There are better ways to check a player's permissions, with the most convenient for server owners being CheckCommandAccess.
Checking for a specific command isn't a case for reserved slots, and then a fall off to flags seems a little... going around?
__________________

Last edited by Wilczek; 06-29-2016 at 15:03.
Wilczek is offline
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 06-29-2016 , 15:11   Re: GetUserFlagBits seems to be broken
Reply With Quote #13

Quote:
Originally Posted by Wilczek View Post
Code:
new String:CharAdminFlag[32];

public OnPluginStart()
{
    bri_charadminflag = CreateConVar("bri_charadminflag", "a", "Admin flag to use for immunity (only one).  Must be a in char format.");
}

public OnConfigsExecuted()
{
    GetConVarString(bri_charadminflag, CharAdminFlag, sizeof(CharAdminFlag));
}

public OnClientPostAdminCheck(client)
{
    if (IsValidAdmin(client, CharAdminFlag))
        IsPlayerAdmin[client] = true;
    else
        IsPlayerAdmin[client] = false;
}

stock bool:IsValidAdmin(client, const String:flags[])
{
    if (!IsClientConnected(client))
        return false;
    new ibFlags = ReadFlagString(flags);
    if ((GetUserFlagBits(client) & ibFlags) == ibFlags) {
        return true;
    }
    if (GetUserFlagBits(client) & ADMFLAG_ROOT) {
        return true;
    }
    return false;
}
Doesn't it return true only if a client has the only flag you are looking for ('a' in this case) or if he's a root?

---


Checking for a specific command isn't a case for reserved slots, and then a fall off to flags seems a little... going around?
Yes its supposed to return true, save it and then at the end of the round make the client immune to damage if the client has the flag, but it somehow fails to return true even if you have the flag.
__________________
luki1412 is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 06-29-2016 , 15:17   Re: GetUserFlagBits seems to be broken
Reply With Quote #14

Wilczek asked if the posted code would have IsValidAdmin return true if the client has ONLY the indicated flag. If the flag is "a" and a player has flags "abc", he is concerned that the function would return false. I don't think that that is the issue here, though.
__________________

Last edited by ddhoward; 06-29-2016 at 15:17.
ddhoward is offline
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 06-29-2016 , 15:26   Re: GetUserFlagBits seems to be broken
Reply With Quote #15

Quote:
Originally Posted by ddhoward View Post
Wilczek asked if the posted code would have IsValidAdmin return true if the client has ONLY the indicated flag. If the flag is "a" and a player has flags "abc", he is concerned that the function would return false. I don't think that that is the issue here, though.
Oh, I misunderstood him then. Yeah I dont think thats the issue here, because it fails even if Im root.
__________________
luki1412 is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 06-29-2016 , 15:53   Re: GetUserFlagBits seems to be broken
Reply With Quote #16

Are you sure that this particular native is the point of failure? Perhaps pop some debug messages in there.

PHP Code:
stock bool:IsValidAdmin(client, const String:flags[])
{
    if (!
IsClientConnected(client)) {
        
PrintToChatAll("client not connected!");
        return 
false;
    }
    new 
ibFlags ReadFlagString(flags);
    
PrintToChatAll("checking for flags \"%s\", user has flag bits equaling %i"flagsGetUserFlagBits(client));
    if ((
GetUserFlagBits(client) & ibFlags) == ibFlags) {
        
PrintToChatAll("user has the right bits!");
        return 
true;
    }
    if (
GetUserFlagBits(client) & ADMFLAG_ROOT) {
        
PrintToChatAll("user is root!");
        return 
true;
    }
    
PrintToChatAll("returning false");
    return 
false;

__________________
ddhoward is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-30-2016 , 19:16   Re: GetUserFlagBits seems to be broken
Reply With Quote #17

Quote:
Originally Posted by luki1412 View Post
Then why isnt an official sourcemod plugin using it?
Admin Help, Antiflood, Base Bans, Base Chat, and ReservedSlots all use it.

Plugins that just register admin commands won't because it's quicker to use RegAdminCmd which acts like RegConsoleCmd with a CheckCommandAccess block in it.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 07-05-2016 , 16:32   Re: GetUserFlagBits seems to be broken
Reply With Quote #18

Quote:
Originally Posted by ddhoward View Post
Are you sure that this particular native is the point of failure? Perhaps pop some debug messages in there.

PHP Code:
stock bool:IsValidAdmin(client, const String:flags[])
{
    if (!
IsClientConnected(client)) {
        
PrintToChatAll("client not connected!");
        return 
false;
    }
    new 
ibFlags ReadFlagString(flags);
    
PrintToChatAll("checking for flags \"%s\", user has flag bits equaling %i"flagsGetUserFlagBits(client));
    if ((
GetUserFlagBits(client) & ibFlags) == ibFlags) {
        
PrintToChatAll("user has the right bits!");
        return 
true;
    }
    if (
GetUserFlagBits(client) & ADMFLAG_ROOT) {
        
PrintToChatAll("user is root!");
        return 
true;
    }
    
PrintToChatAll("returning false");
    return 
false;

This code is fine, but that doesn't really matter anymore. I have no idea what is causing it but since Im the only one that has this problem Im gonna try to find the solution myself.
__________________
luki1412 is offline
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 07-05-2016 , 16:39   Re: GetUserFlagBits seems to be broken
Reply With Quote #19

Quote:
Originally Posted by Powerlord View Post
Admin Help, Antiflood, Base Bans, Base Chat, and ReservedSlots all use it.

Plugins that just register admin commands won't because it's quicker to use RegAdminCmd which acts like RegConsoleCmd with a CheckCommandAccess block in it.
I wasnt talking about registering commands. Also, ReservedSlots uses GetUserFlagBits.
__________________
luki1412 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-05-2016 , 18:52   Re: GetUserFlagBits seems to be broken
Reply With Quote #20

Quote:
Originally Posted by luki1412 View Post
Also, ReservedSlots uses GetUserFlagBits.
Reserved Slots is also a core plugin that literally has its own dedicated admin flag ("a"). Likewise, the adminmenu plugin has its own dedicated admin flag ("b").

Any plugins that aren't part of the core won't have their own dedicated admin flags.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Reply



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 17:07.


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