AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [SNIPPET] How to block the change notification of cvars with NOTIFY flag (https://forums.alliedmods.net/showthread.php?t=144616)

berni 12-05-2010 20:40

[SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
Since the notify=false parameter of the SetConVar Functions doesn't work anymore for orangebox/L4D games, and because it's often necessary to set the NOFITY flag for certain cvars that need to be public, here is how to block the notifcations that normally automatically goes th the clients when such a ConVar gets changed.



PHP Code:

public OnPluginStart() {
     
HookEvent("server_cvar"Event_ServerCvarEventHookMode_Pre);
}

public 
Action:Event_ServerCvar(Handle:event, const String:name[], bool:dontBroadcast) { 

Block all cvar notifications:

PHP Code:

    return Plugin_Handled

or block all cvar notifications of my plugin only starting with "mycvarprefix_":

PHP Code:

    decl String:cvarName[64];
    
GetEventString(event"cvarname"cvarNamesizeof(cvarName));

    if (
StrContains(cvarName"mycvarprefix_") == 0) {
        return 
Plugin_Handled;
    }

    return 
Plugin_Continue

PHP Code:




Master53 01-17-2011 11:29

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
does this block sourcemod cvar change, or just server cvars?

berni 01-17-2011 12:59

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
It does not block cvar changes at all.

Master53 01-17-2011 15:36

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
well not block them, just stop the notification been sent to the players.

berni 01-17-2011 16:14

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
cvars are cvars, there is no difference between sourcemod cvars and server cvars.

asherkin 01-17-2011 19:53

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
Doing this will cause the rules list to get out-of-sync.

EDIT: Treat this as a reply to the post below, I was rather tired and misread the OP originally :P.

DJ Tsunami 01-18-2011 04:39

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
If your plugin is the one changing the convar, it can just remove the FCVAR_NOTIFY flag, change the value, and re-add the flag. HLSW Info does this.

Twelve-60 01-18-2011 09:48

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
Quote:

Originally Posted by DJ Tsunami (Post 1396035)
If your plugin is the one changing the convar, it can just remove the FCVAR_NOTIFY flag, change the value, and re-add the flag. HLSW Info does this.

I use this technique for my WarMod plugin, however I found out that as asherkin said, this does not update the rules list sent out by a server query (A2S_RULES).

To properly update a public CVAR (FCVAR_NOTIFY) without displaying it ingame, you can use the SteamTools extension and use Steam_SetRule() to manually set it, here are my stocks:

PHP Code:

/*********************************************************
 *  Hide setting an int cvar
 * 
 * @noreturn
 *********************************************************/
 
stock SetConVarIntHidden(Handle:cvar, const value) {
    new 
String:cvar_name[64];
    new 
String:value_string[512];
    new 
flags GetConVarFlags(cvar);
    
SetConVarFlags(cvarflags & ~FCVAR_NOTIFY);
    
SetConVarInt(cvarvalue);
    
GetConVarName(cvarcvar_namesizeof(cvar_name));
    
IntToString(valuevalue_stringsizeof(value_string));
    
Steam_SetRule(cvar_namevalue_string);
    
SetConVarFlags(cvarflags);
}


/*********************************************************
 *  Hide setting a string cvar
 * 
 * @noreturn
 *********************************************************/
 
stock SetConVarStringHidden(Handle:cvarString:value[]) {
    new 
String:cvar_name[64];
    new 
flags GetConVarFlags(cvar);
    
SetConVarFlags(cvarflags & ~FCVAR_NOTIFY);
    
SetConVarString(cvarvalue);
    
GetConVarName(cvarcvar_namesizeof(cvar_name));
    
Steam_SetRule(cvar_namevalue);
    
SetConVarFlags(cvarflags);



berni 01-18-2011 11:03

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
Quote:

Originally Posted by asherkin (Post 1395922)
Doing this will cause the rules list to get out-of-sync.

I already wondered what you mean yesterday o.O

I think my method is preferable, because no extension is required, not everyone
has Steamtools installed on their server, my method also doesn't break if new updates come out.

berni 03-16-2011 06:54

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
Update: Added missing code line.

xioSlayer 08-08-2011 06:04

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
I tried both methods and couldn't get the 'cvar changed' notifications to go away...

or does this only work on clients and not admins?

berni 08-08-2011 06:09

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
Your code + how you change convars please.

xioSlayer 08-08-2011 07:42

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
I just ended up editing basecommands.sp to never show cvar changes with sm_cvar.

That should work just fine for now I suppose.

RedSword 05-05-2012 19:29

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
Does anyone got it to work recently ?

Code:

public OnPluginStart()
{
        CreateConVar( "testcvar", "1", "Team Scramble version", FCVAR_PLUGIN );
        HookEvent("server_cvar", Event_ServerCvar, EventHookMode_Pre);
}
public Action:Event_ServerCvar(Handle:event, const String:name[], bool:dontBroadcast)
{
        decl String:cvarName[64];
        GetEventString(event, "cvarname", cvarName, sizeof(cvarName));
        PrintToChatAll(cvarName);

        if (StrEqual(cvarName, "testcvar")) {
                PrintToChatAll("string matched and handled");
                return Plugin_Handled;
        }
       
        return Plugin_Continue;
}

Doesn't work. Also it seems that the whole event isn't even triggered.

Is there another way ?

Bacardi 05-06-2012 02:20

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
Quote:

Originally Posted by RedSword (Post 1702958)
Doesn't work. Also it seems that the whole event isn't even triggered.

Is there another way ?

I assume you need add this flag to your cvar. Like what have few other srcds cvars... (mp_startmoney, mp_flashlight, sv_cheats)
PHP Code:

FCVAR_NOTIFY /**< Notifies players when changed. */ 


TnTSCS 05-06-2012 12:57

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
Saw this from KyleS (I think) a long time ago. This allows you to remove FCVAR_NOTIFY from Cvars

Might need some tweaking, but this is the gist:

PHP Code:


new String:cvars[][] = {"bot_quota""mp_startmoney""mp_flashlight""sv_cheats"};

public 
OnPluginStart()
{
    for(new 
0<sizeof(cvars); i++)
    {
        new 
Handle:CVarHandle FindConVar(cvars[i]);
        if (
CVarHandle != INVALID_HANDLE)
        {
            new 
flags;
            
flags GetConVarFlags(CVarHandle);
            
flags &= ~FCVAR_NOTIFY;
            
SetConVarFlags(CVarHandleflags);
            
CloseHandle(CVarHandle);
            return;
        }
        
ThrowError("Couldn't find %s. What sort of game is this?"cvars[i]);
        return;
    }


Or what about SetEventBroadcast(event, true);

KyleS 05-06-2012 16:29

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
Quote:

Originally Posted by TnTSCS (Post 1703502)
Saw this from KyleS (I think) a long time ago. This allows you to remove FCVAR_NOTIFY from Cvars

Might need some tweaking, but this is the gist:

PHP Code:


new String:cvars[][] = {"bot_quota""mp_startmoney""mp_flashlight""sv_cheats"};

public 
OnPluginStart()
{
    for(new 
0<sizeof(cvars); i++)
    {
        new 
Handle:CVarHandle FindConVar(cvars[i]);
        if (
CVarHandle != INVALID_HANDLE)
        {
            new 
flags;
            
flags GetConVarFlags(CVarHandle);
            
flags &= ~FCVAR_NOTIFY;
            
SetConVarFlags(CVarHandleflags);
            
CloseHandle(CVarHandle);
            return;
        }
        
ThrowError("Couldn't find %s. What sort of game is this?"cvars[i]);
        return;
    }


Or what about SetEventBroadcast(event, true);

If I did write that, my bad >.< That return should be a continue in the for.

minimoney1 05-07-2012 05:18

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
Why not use the same method in the OT and use SetEventBroadcast?


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

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