Raised This Month: $7 Target: $400
 1% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 12-05-2010 , 20:40   [SNIPPET] How to block the change notification of cvars with NOTIFY flag
Reply With Quote #1

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:

__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0

Last edited by berni; 03-16-2011 at 06:54.
berni is offline
Master53
Veteran Member
Join Date: Dec 2009
Old 01-17-2011 , 11:29   Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
Reply With Quote #2

does this block sourcemod cvar change, or just server cvars?
__________________
Master(d)



Master53 is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-17-2011 , 12:59   Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
Reply With Quote #3

It does not block cvar changes at all.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Master53
Veteran Member
Join Date: Dec 2009
Old 01-17-2011 , 15:36   Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
Reply With Quote #4

well not block them, just stop the notification been sent to the players.
__________________
Master(d)



Master53 is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-17-2011 , 16:14   Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
Reply With Quote #5

cvars are cvars, there is no difference between sourcemod cvars and server cvars.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 01-17-2011 , 19:53   Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
Reply With Quote #6

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 .
__________________

Last edited by asherkin; 01-18-2011 at 09:55.
asherkin is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 01-18-2011 , 04:39   Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
Reply With Quote #7

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.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
Twelve-60
Senior Member
Join Date: Aug 2007
Old 01-18-2011 , 09:48   Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
Reply With Quote #8

Quote:
Originally Posted by DJ Tsunami View Post
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);

__________________
Twelve-60 is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-18-2011 , 11:03   Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
Reply With Quote #9

Quote:
Originally Posted by asherkin View Post
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.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 03-16-2011 , 06:54   Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
Reply With Quote #10

Update: Added missing code line.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni 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 05:39.


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