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

[CS:GO] Dynamic permissions with convar


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JoaoRodrigoGamer
Junior Member
Join Date: Jul 2019
Location: Portugal
Old 08-24-2019 , 06:17   [CS:GO] Dynamic permissions with convar
Reply With Quote #1

So, I was trying to make a "modular" plugin on which you could go to the config file on /cfg/sourcemod/MoreVIPFeatures.cfg and change the flag needed to execute certain commands. I came up with this code:

PHP Code:
ConVar c_VIPflag;
char s_VIPflag[30];

public 
void OnPluginStart()
{
    
c_VIPflag CreateConVar("MorevipFeatures_flag""o""The VIP flag needed to get the VIP Features");
    
AutoExecConfig(true"MoreVIPFeatures");

    
GetConVarString(c_VIPflags_VIPflagsizeof(s_VIPflag));

    if(
StrEqual(s_VIPflag"a"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_RESERVATION);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_RESERVATION);
    }
    else if (
StrEqual(s_VIPflag"b"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_GENERIC);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_GENERIC);
    }
    else if (
StrEqual(s_VIPflag"c"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_KICK);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_KICK);
    }
    else if (
StrEqual(s_VIPflag"d"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_BAN);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_BAN);
    }
    else if (
StrEqual(s_VIPflag"e"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_UNBAN);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_UNBAN);
    }
    else if (
StrEqual(s_VIPflag"f"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_SLAY);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_SLAY);
    }
    else if (
StrEqual(s_VIPflag"g"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_CHANGEMAP);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_CHANGEMAP);
    }
    else if (
StrEqual(s_VIPflag"h"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_CONVARS);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_CONVARS);
    }
    else if (
StrEqual(s_VIPflag"i"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_CONFIG);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_CONFIG);
    }
    else if (
StrEqual(s_VIPflag"j"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_CHAT);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_CHAT);
    }
    else if (
StrEqual(s_VIPflag"k"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_VOTE);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_VOTE);
    }
    else if (
StrEqual(s_VIPflag"l"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_PASSWORD);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_PASSWORD);
    }
    else if (
StrEqual(s_VIPflag"m"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_RCON);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_RCON);
    }
    else if (
StrEqual(s_VIPflag"n"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_CHEATS);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_CHEATS);
    }
    else if (
StrEqual(s_VIPflag"z"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_ROOT);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_ROOT);
    }
    else if (
StrEqual(s_VIPflag"o"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_CUSTOM1);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_CUSTOM1);
    }
    else if (
StrEqual(s_VIPflag"p"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_CUSTOM2);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_CUSTOM2);
    }
    else if (
StrEqual(s_VIPflag"q"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_CUSTOM3);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_CUSTOM3);
    }
    else if (
StrEqual(s_VIPflag"r"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_CUSTOM4);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_CUSTOM4);
    }
    else if (
StrEqual(s_VIPflag"s"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_CUSTOM5);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_CUSTOM5);
    }
    else if (
StrEqual(s_VIPflag"t"true))
    {
        
RegAdminCmd("sm_vipmenu"VipMenuADMFLAG_CUSTOM6);
        
RegAdminCmd("sm_vipspawn"vipSpawnADMFLAG_CUSTOM6);
    }
    else
    {
        
SetFailState("[MoreVIPFeatures] %t""Could not get flag");
    }

I thought it was all working but when I got to test the code and change the flag needed on the config file to "b", it would still use the default flag "o".
Can anyone help me understand and try to fix this issue?
JoaoRodrigoGamer is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 08-24-2019 , 06:35   Re: [CS:GO] Dynamic permissions with convar
Reply With Quote #2

Register the commands as regular console commands (RegConsoleCmd) and check within them those flags.
__________________
Ilusion9 is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 08-24-2019 , 06:44   Re: [CS:GO] Dynamic permissions with convar
Reply With Quote #3

You should be using the Command Override system already provided by sourcemod without having to do stuff like this.

Quote:
Originally Posted by Ilusion9 View Post
Register the commands as regular console commands (RegConsoleCmd) and check within them those flags.
This is another possibility and use CheckCommandAccess function.
__________________

Last edited by Silvers; 08-24-2019 at 06:48.
Silvers is offline
JoaoRodrigoGamer
Junior Member
Join Date: Jul 2019
Location: Portugal
Old 08-25-2019 , 14:11   Re: [CS:GO] Dynamic permissions with convar
Reply With Quote #4

Quote:
Originally Posted by Ilusion9 View Post
Register the commands as regular console commands (RegConsoleCmd) and check within them those flags.
I did that lazy thing of writing to console in every if statement to check where it was registering the commands and it is still registered with the "o" flag even though the ConVar output (when I write the ConVar in the console to return the stored value) is "t".
JoaoRodrigoGamer is offline
JoaoRodrigoGamer
Junior Member
Join Date: Jul 2019
Location: Portugal
Old 08-25-2019 , 14:16   Re: [CS:GO] Dynamic permissions with convar
Reply With Quote #5

Quote:
Originally Posted by Silvers View Post
You should be using the Command Override system already provided by sourcemod without having to do stuff like this.
That is a good solution but I would really like to make that the flag config for this plugin didn't require to change stuff on the sourcemod config files. I realize that it is the best solution and I'll probably adopt it if we don't find another way to set the needed flag through the plugin config file in csgo/cfg/sourcemod/...
JoaoRodrigoGamer 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 13:50.


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