Raised This Month: $ Target: $400
 0% 

[ANY] ConVar Suppression


Post New Thread Reply   
 
Thread Tools Display Modes
Author
KyleS
SourceMod Plugin Approver
Join Date: Jul 2009
Location: Segmentation Fault.
Plugin ID:
3114
Plugin Version:
1.0
Plugin Category:
Server Management
Plugin Game:
Any
Plugin Dependencies:
    Servers with this Plugin:
    55 
    Plugin Description:
    Suppresses ConVars from printing to clients when they change.
    Old 07-23-2012 , 22:49   [ANY] ConVar Suppression
    Reply With Quote #1

    Huge thanks to Berni's Snippet.

    What does this do?
    Depends on what you do with it. However, the only function I'm immediately aware of is suppressing selected ConVar changes from being printed to chat.

    Oh? Is that all?
    Yes. Thanks!

    ... Are there any commands?
    Indeed there are. As a matter of fact, there is only one.

    sm_suppressconvar <convar> <enabled|disabled> - Whether to display changes of this ConVar to Chat or not.

    Can you give an example?
    Sure! sm_suppressconvar sm_nextmap enabled

    THIS ALREADY EXISTS
    Oh. Ok. Sorry! At this present time I'm unaware of any that are not hard coded.
    Attached Files
    File Type: sp Get Plugin or Get Source (ConVarSuppression.sp - 2624 views - 2.5 KB)

    Last edited by KyleS; 07-24-2012 at 01:15. Reason: Evidently I cannot spell Suppression.
    KyleS is offline
    Sreaper
    髪を用心
    Join Date: Nov 2009
    Old 07-24-2012 , 00:35   Re: [ANY] ConVar Suppression
    Reply With Quote #2

    Thanks Kyle! I've wanted something like this for awhile!
    Sreaper is offline
    Powerlord
    AlliedModders Donor
    Join Date: Jun 2008
    Location: Seduce Me!
    Old 07-24-2012 , 12:52   Re: [ANY] ConVar Suppression
    Reply With Quote #3

    It amuses me that your code only checks the first letter. So, if I were to write
    Code:
    sm_suppressconvar mp_restartgame do
    it would disable mp_restartgame's reporting.

    Having said that, I wasn't aware that there was a server_cvar event.

    It seems like a lot more work to hook server_cvar and do it there rather than just stripping FCVAR_NOTIFY from the cvar, though...

    Edit: Also, I'm disappointed to see a plugin approver reusing the same string buffer for three different arguments in the same function. While you could argue it's efficient, it's very hard to maintain later.
    __________________
    Not currently working on SourceMod plugin development.

    Last edited by Powerlord; 07-24-2012 at 12:54.
    Powerlord is offline
    thetwistedpanda
    Good Little Panda
    Join Date: Sep 2008
    Old 07-24-2012 , 12:58   Re: [ANY] ConVar Suppression
    Reply With Quote #4

    *sigh*, refraining from the many negative comments the above poster really deserves, nice work Kyle. Didn't realize the server_cvar event existed either!
    __________________
    thetwistedpanda is offline
    Powerlord
    AlliedModders Donor
    Join Date: Jun 2008
    Location: Seduce Me!
    Old 07-24-2012 , 13:25   Re: [ANY] ConVar Suppression
    Reply With Quote #5

    Quote:
    Originally Posted by thetwistedpanda View Post
    *sigh*, refraining from the many negative comments the above poster really deserves, nice work Kyle. Didn't realize the server_cvar event existed either!
    Feel free to leave me any negative comments that you want. It doesn't change the fact that the method this plugin author references in this post is likely more efficient than the way this plugin works.
    __________________
    Not currently working on SourceMod plugin development.

    Last edited by Powerlord; 07-24-2012 at 13:25.
    Powerlord is offline
    alongub
    Veteran Member
    Join Date: Aug 2009
    Location: Israel
    Old 07-24-2012 , 13:29   Re: [ANY] ConVar Suppression
    Reply With Quote #6

    Quote:
    Originally Posted by Powerlord View Post
    Also, I'm disappointed to see a plugin approver reusing the same string buffer for three different arguments in the same function. While you could argue it's efficient, it's very hard to maintain later.
    Since this is a rather small plugin, I think that the "hard to maintain" argument is not relevant here.
    alongub is offline
    asherkin
    SourceMod Developer
    Join Date: Aug 2009
    Location: OnGameFrame()
    Old 07-24-2012 , 13:29   Re: [ANY] ConVar Suppression
    Reply With Quote #7

    Quote:
    Originally Posted by Powerlord View Post
    It amuses me that your code only checks the first letter. So, if I were to write
    Code:
    sm_suppressconvar mp_restartgame do
    it would disable mp_restartgame's reporting.
    Awesome optimization there.

    Quote:
    Originally Posted by Powerlord View Post
    It seems like a lot more work to hook server_cvar and do it there rather than just stripping FCVAR_NOTIFY from the cvar, though...
    Stripping FCVAR_NOTIFY would remove them from the A2S_RULES response.
    __________________
    asherkin is offline
    KyleS
    SourceMod Plugin Approver
    Join Date: Jul 2009
    Location: Segmentation Fault.
    Old 07-24-2012 , 14:03   Re: [ANY] ConVar Suppression
    Reply With Quote #8

    Quote:
    Originally Posted by Powerlord View Post
    It amuses me that your code only checks the first letter. So, if I were to write
    Code:
    sm_suppressconvar mp_restartgame do
    it would disable mp_restartgame's reporting.
    Actually, you're incorrect, doing so would remove mp_restartgame from the trie. However, if you were to use the shorthand sm_suppressconvar mp_restartgame e , this would do what you're wanting. If it makes you happy I can totally check with StrEqual for disable and enable, as I do in some other plugins.

    Quote:
    Originally Posted by Powerlord View Post
    It seems like a lot more work to hook server_cvar and do it there rather than just stripping FCVAR_NOTIFY from the cvar, though...
    As Asherkin pointed out in the 6th post, this causes A2S_Rules to become out of sync. I recently rewrote every single plugin I use (Came to about 30~, I'm still writing), which is why I posted this instead of going the incorrect route and stripping FVCAR_NOTIFY. Sure it's easier, but no one wants to be the cause of breakage on a server.

    Quote:
    Originally Posted by Powerlord View Post
    Edit: Also, I'm disappointed to see a plugin approver reusing the same string buffer for three different arguments in the same function. While you could argue it's efficient, it's very hard to maintain later.
    I don't see this growing. I also didn't see a point in wasting arrays. If functionality has been lost as a result of this, please let me know. Upon request I can also totally add a verbose syntax checker.

    If you have any further questions or concerns in regards to this plugin please let me know.

    EDIT: Oops!

    Quote:
    Originally Posted by Powerlord View Post
    Feel free to leave me any negative comments that you want. It doesn't change the fact that the method this plugin author references in this post is likely more efficient than the way this plugin works.
    I didn't say that! What I had said was I had made a mistake with said Snippet. Even looking at it now, CloseHandle shouldn't be there either. However, it has no effect on ConVars (As far as I'm aware), so it isn't unsafe or anything.

    If I were to rewrite the above hard coded snippet, it would look something like this.
    PHP Code:
    #pragma semicolon 1
    #include <sourcemod>

    public OnPluginStart()
    {
        new 
    Handle:hCVarHandle INVALID_HANDLE;
        new 
    iFlags;
        
        new 
    String:sCVars[][] = {"bot_quota""mp_startmoney""mp_flashlight""sv_cheats"};
        for(new 
    0sizeof(sCVars); i++)
        {
            
    hCVarHandle FindConVar(sCVars[i]);
            if (
    hCVarHandle == INVALID_HANDLE)
            {
                
    LogError("Couldn't find %s. What sort of game is this?"sCVars[i]);
                continue;
            }
            
            
    iFlags GetConVarFlags(hCVarHandle);
            if (!(
    iFlags FCVAR_NOTIFY))
            {
                continue;
            }
            
            
    iFlags &= ~FCVAR_NOTIFY;
            
    SetConVarFlags(hCVarHandleiFlags);
        }

    There's nothing stopping another plugin from re-adding FCVAR_NOTIFY back to those convars, which is another reason why this is a bad method.

    Last edited by KyleS; 07-24-2012 at 14:23.
    KyleS is offline
    Powerlord
    AlliedModders Donor
    Join Date: Jun 2008
    Location: Seduce Me!
    Old 07-24-2012 , 14:26   Re: [ANY] ConVar Suppression
    Reply With Quote #9

    Quote:
    Originally Posted by KyleS View Post
    I don't see this growing. I also didn't see a point in wasting arrays. If functionality has been lost as a result of this, please let me know. Upon request I can also totally add a verbose syntax checker.

    If you have any further questions or concerns in regards to this plugin please let me know.
    It's a matter of readability, not functionality. sCommand means 3 different things at different points:

    1. The command name at the first ReplyToCommand.
    2. The second argument at the StringToInt.
    3. The first argument at the second, third, and fourth ReplyToCommands.

    This is one of those things that makes maintenance programmers (want to) kill previous programmers.

    Speaking of functionality, it might be a good idea to check if the ConVar exists (checking FindConVar against INVALID_HANDLE) before adding it to the trie, returning common.phrases's "Unable to find cvar" phrase if not found:
    PHP Code:
    // In OnPluginStart
        
    LoadTranslations("common.phrases");

    // in OnSupressConVar's case 0:
                
    new Handle:convar FindConVar(sCommand);
                
                if (
    convar == INVALID_HANDLE)
                {
                    
    ReplyToCommand(client"%s%t"PLUGIN_PREFIX"Unable to find cvar"sCommand);
                    return 
    Plugin_Handled;
                }
                else
                {
                    
    CloseHandle(convar);
                } 
    __________________
    Not currently working on SourceMod plugin development.

    Last edited by Powerlord; 07-24-2012 at 14:33.
    Powerlord is offline
    KyleS
    SourceMod Plugin Approver
    Join Date: Jul 2009
    Location: Segmentation Fault.
    Old 07-24-2012 , 20:28   Re: [ANY] ConVar Suppression
    Reply With Quote #10

    Quote:
    Originally Posted by Powerlord View Post
    It's a matter of readability, not functionality. sCommand means 3 different things at different points:
    I agree that separate variables would be awesome. However we don't have pointers in Pawn, so while it's an excuse for this, it's mine. If we could point to arrays with a single cell, that would make my day.
    Quote:
    Originally Posted by Powerlord View Post
    1. The command name at the first ReplyToCommand.
    Said buffer is only used when argc is < 2 (If memory serves me right). This is there so we're not hard coding command names. At the bottom of the if (argc < 2), there should be a return Plugin_Handled, otherwise you've found a major issue! If so, thanks! It's there so if someone adds the alias sm_powerlordcvarsuppressionsuperawesomecomman d and points it to the function, no changes will be required and the same will happen.

    Quote:
    Originally Posted by Powerlord View Post
    2. The second argument at the StringToInt.
    Totally! As you can see, the result of the operation on the buffer is stored to a cell with a value of 0 or 1. -1 if it's unknown or invalid.

    Quote:
    Originally Posted by Powerlord View Post
    3. The first argument at the second, third, and fourth ReplyToCommands.
    Second argument to the second, third, and fourth ReplyToCommand. In this case it's changed to the cvar that it is suppressing.

    Quote:
    Originally Posted by Powerlord View Post
    This is one of those things that makes maintenance programmers (want to) kill previous programmers.
    A better fitting name for the Array would be Junk or something I suppose? sCommand made sense as it's the command name for the first, then turns into the 2nd arg, and then the first. If this was C, I'd have 3 char pointers to show this, but it isn't. If I add comments would it help you? I normally do, but this was more of a "Oh, this doesn't exist. I'll share it." thing.

    Quote:
    Originally Posted by Powerlord View Post
    Speaking of functionality, it might be a good idea to check if the ConVar exists (checking FindConVar against INVALID_HANDLE) before adding it to the trie, returning common.phrases's "Unable to find cvar" phrase if not found:
    PHP Code:
    // In OnPluginStart
        
    LoadTranslations("common.phrases");

    // in OnSupressConVar's case 0:
                
    new Handle:convar FindConVar(sCommand);
                
                if (
    convar == INVALID_HANDLE)
                {
                    
    ReplyToCommand(client"%s%t"PLUGIN_PREFIX"Unable to find cvar"sCommand);
                    return 
    Plugin_Handled;
                }
                else
                {
                    
    CloseHandle(convar);
                } 
    Good idea! The only bad thing I can see coming from this is late loading a plugin then expecting the ConVar to be suppressed when this actually errored out.
    KyleS 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 12:33.


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