Console command flags

From Valve Developer Community
Jump to navigation Jump to search

ConVars and ConCommands use various bitflags to determine their behavior. These are usually set in the constructor, but flags may be added via ConCommandBase::AddFlags() and, in Alien Swarm and later, removed via ConCommandBase::RemoveFlags() (easily ported to other branches). Dynamically modifying flags is not usually done very often, however. Users do not have the ability to modify these flags without the use of plugins or other custom code.

The macros for these flags are defined in src/public/tier1/iconvar.h and are prefixed with FCVAR_. All flags affect ConVars, but not all of them affect ConCommands; this is noted in the table below. "Bit #" represents how many times 0x1 is shifted left to produce the value.

When running help <command> or cvarlist, the list of flags on each command will be printed, but these use various abbreviations and do not include all flags. This information is also noted in the table.

List of flags

Bit # Internal name help name cvarlist name Affects ConCommands Description
0 FCVAR_UNREGISTERED N/A Yes Skips adding this command to the global linked list of console commands. Anything which attempts to access it by name will fail, including running or querying it through the console, and even ConVarRef objects and FindVar()! This is probably only useful in very unusual cases, such as creating temporary ConVar objects within a function or the like.
1 FCVAR_DEVELOPMENTONLY (in all games since Source 2007) N/A Yes Hides this command from auto complete, cvarlist, etc. and prevents it from being run; the engine will effectively act like it doesn't exist. This flag is removed automatically if tier1 was compiled in debug mode (possible in SDK 2013, but not Alien Swarm) or can be removed manually using ConCommandBase::RemoveFlags() in game code.
Warning.pngWarning:Despite code comments implying as such, commands with this flag are not compiled out in release builds! Server plugins (and VScript in Team Fortress 2 Team Fortress 2) can change the values of dev-only console variables and/or remove the flag completely. If you have a command that you want to be absolutely sure is never run outside debug builds, you must wrap it in an #ifdef _DEBUG.
2 FCVAR_GAMEDLL game sv Yes Automatically added to commands/variables defined in server.dll. Shouldn't be set manually.
3 FCVAR_CLIENTDLL client cl Yes Automatically added to commands/variables defined in client.dll. Shouldn't be set manually.
4 FCVAR_HIDDEN (in all games since Source 2007) N/A Yes Hides this command from auto complete, cvarlist, etc. like FCVAR_DEVELOPMENTONLY, but still allows it to be run through config files or if manually typed by the user. Used for things which the user should have access to, but generally shouldn't be changing manually.
5 FCVAR_PROTECTED prot No Hides the value of this ConVar from several places where it would normally be visible. The value will never be networked to clients, and if it is also flagged with FCVAR_NOTIFY, the notification message will have the value replaced by the string ***PROTECTED***. This should be used for data such as passwords which clients shouldn't know about.
6 FCVAR_SPONLY singleplayer sp Yes Prevents the command from being used in multiplayer.
Warning.pngWarning:Although unable to be changed while connected, the values of ConVars with this flag are not reset when joining a multiplayer server.
7 FCVAR_ARCHIVE archive a No When set, the variable's value is saved in the file config.cfg when the game shuts down or the user manually runs host_writeconfig. This file is executed when the game is reopened, restoring the previously set values. This should be used for any settings that are exposed to the user through UI or otherwise expected to persist across game restarts (like name or network_rate).
Tip.pngTip:Avoid combining this with flags that restrict the command's usage or change its value, such as FCVAR_CHEAT or FCVAR_REPLICATED. This can create a bad user experience by causing settings exposed in the UI to get unexpectedly reset or changed.
8 FCVAR_NOTIFY notify nf No Prints a notification message to all clients' chat whenever the variable is changed. This should be used for variables that change game play rules, which are important for players to know about (mp_friendlyfire etc).
9 FCVAR_USERINFO user (in all games since Left 4 Dead) user No When used on a client-side console variable, its value is transmitted to the server and updated every time the user changes it. This should be used for client information the server needs to know about, like the player's name or their network settings. When the player changes one of these variables the engine notifies the server code via ClientSettingsChanged(). The game server can also query the engine for specific client settings with GetClientConVarValue().
10 FCVAR_PRINTABLEONLY print No Restricts a console variable's value to only contain only printable characters (no control chars etc). This should be used for variables that are logged or broadcasted (gamerules etc), to prevent arbitrary code execution and other problems.
11 FCVAR_UNLOGGED log [Todo]
Todo: "If this is a FCVAR_SERVER, don't log changes to the log file / console if we are creating a log." Does this actually do anything?
12 FCVAR_NEVER_AS_STRING numeric No Tells the engine never to print this variable as a string since it contains control sequences.
13 FCVAR_REPLICATED replicated rep No Forces all connected clients to match the server-side value. This should be used for shared code where it's important that both sides run the exact same path using the same data (e.g. predicted movement/weapons, game rules).
14 FCVAR_CHEAT cheat Yes In multiplayer, prevents this command/variable from being used unless the server has sv_cheats turned on. If a client connects to a server where cheats are disabled (which is the default), all client side console variables labeled as FCVAR_CHEAT are reverted to their default values and can't be changed as long as the client stays connected. Console commands marked as FCVAR_CHEAT can't be executed either.

As a general rule of thumb, any client-side command that isn't specifically meant to be configured by users should be marked with this flag, as even the most harmless looking commands can sometimes be misused to cheat. For server-side only commands you can be more lenient, since these would have no effect when changed by connected clients anyway.

Note.pngNote:Has no effect in singleplayer. If you want a command to be locked behind sv_cheats in singleplayer (e.g. so using it voids achievements), you must add code to the command which explicitly checks if cheats are enabled when attempting to use/change it.
15 FCVAR_SS (in all games since Left 4 Dead) ss No Automatically generates copies of this console variable corresponding to each splitscreen player. The additional copies are numbered from 2 to MAX_SPLITSCREEN_PLAYERS, with the original un-numbered copy being used for player 1. Thus, if MAX_SPLITSCREEN_PLAYERS is set to 1 then this will have no effect; you do not need to go out of your way to remove the flag in mods which don't have splitscreen.
FCVAR_INTERNAL_USE (only in Team Fortress 2 branch) No Allows this ConVar to be changed in Team Fortress 2 Team Fortress 2 competitive mode. Seemingly functions identically to FCVAR_ALLOWED_IN_COMPETITIVE.
16 FCVAR_DEMO demo No When starting to record a demo file, explicitly adds the value of this console variable to the recording to ensure a correct playback.
17 FCVAR_DONTRECORD norecord Yes Prevents this command from being recorded in demo files; effectively the opposite of FCVAR_DEMO.
Warning.pngWarning:Doesn't prevent the command from being run if a demo file is modified to include it anyway. Make sure to add an explicit engine->IsPlayingDemo() check to the command's code if this could potentially be used maliciously.
18 FCVAR_SS_ADDED (in all games since Left 4 Dead) ss_added No Automatically added to console variables created by FCVAR_SS. Shouldn't be set manually.
FCVAR_ALLOWED_IN_COMPETITIVE (only in Team Fortress 2 branch) No Allows this ConVar to be changed in Team Fortress 2 Team Fortress 2 competitive mode. Seemingly functions identically to FCVAR_INTERNAL_USE.
19 FCVAR_RELEASE (in all games since Left 4 Dead) No In the Left 4 Dead seriesLeft 4 Dead series Left 4 Dead series, all ConVars that don't have this flag are marked as FCVAR_DEVELOPMENTONLY automatically. Enabling this behavior requires recompiling the engine, making this flag useless to modders unless one were to reimplement the functionality in game code.
20 FCVAR_RELOAD_MATERIALS (in all games since Alien Swarm) (also in Source 2013) No If set and this variable changes, it forces a material reload.
21 FCVAR_RELOAD_TEXTURES (in all games since Alien Swarm) (also in Source 2013) No If set and this variable changes, it forces a texture reload.
22 FCVAR_NOT_CONNECTED notconnected No Prevents this variable from being changed while the client is currently in a server, due to the possibility of exploitation of the command (e.g. fps_max).
Confirm:Does this have any effect in singleplayer? It might vary between engine branches
23 FCVAR_MATERIAL_SYSTEM_THREAD (in all games since Alien Swarm) (also in Source 2013) No Indicates that this cvar is read from the material system thread. Changes how setting the value is handled internally to avoid threading related errors.
24 FCVAR_ARCHIVE_XBOX No Like FCVAR_ARCHIVE, but for Xbox 360. Needless to say, this is not particularly useful to most modders.
25 FCVAR_ACCESSIBLE_FROM_THREADS (in all games since Alien Swarm) (also in Source 2013) [Todo] Used as a debugging tool to check material system thread ConVars. No effect unless tier1 is compiled with CONVAR_TEST_MATERIAL_THREAD_CONVARS defined.
28 FCVAR_SERVER_CAN_EXECUTE (in all games since Source 2007) server_can_execute Yes Allows a client-side command to be run by the server via IVEngineServer::ClientCommand(). If the server attempts to run a command without this flag, the client's console will print an error message and it will be ignored. In singleplayer, this is disabled and all commands can be executed by the server.
Note.pngNote:In mods, this restriction is disabled by default; you must call IVEngineClient::SetRestrictServerCommands() to enable it.
29 FCVAR_SERVER_CANNOT_QUERY (in all games since Source 2007) No Prevents the server from being able to query the value of a client-side console variable. Effectively the inverse of FCVAR_PROTECTED, and should be used in similar cases.
30 FCVAR_CLIENTCMD_CAN_EXECUTE (in all games since Source 2007) clientcmd_can_execute Yes Allows this command to be executed by IVEngineClient::ClientCmd(). There is also IVEngineClient::ClientCmd_Unrestricted(), which ignores this flag and will execute any command.
Todo: What actually is the purpose of this, why would clients need to restrict commands that didn't come from the server? Which Valve games have this restriction enabled?
Note.pngNote:In mods, this restriction is disabled by default; you must call IVEngineClient::SetRestrictClientCommands() to enable it.
31 FCVAR_EXEC_DESPITE_DEFAULT (only in Team Fortress 2 branch) No Allows this cvar to be changed even when the launch parameter -default is set, which normally forces all cvars to use their default values.

Prior to Source 2007 Source 2007, additional flags were set automatically for commands defined in certain modules. All of these were removed except for FCVAR_GAMEDLL and FCVAR_CLIENTDLL (which are used internally for FCVAR_REPLICATED linkage).

Bit # Internal name help name cvarlist name Description
1 FCVAR_LAUNCHER launcher Defined by launcher.
4 FCVAR_MATERIAL_SYSTEM matsys Defined by the material system.
15 FCVAR_STUDIORENDER studio Defined by the studiorender system.
18 FCVAR_PLUGIN Defined by a third party plugin.
19 FCVAR_DATACACHE Defined by the datacache system.
20 FCVAR_TOOLSYSTEM Defined by an IToolSystem library.
21 FCVAR_FILESYSTEM Defined by the file system.
23 FCVAR_SOUNDSYSTEM Defined by the soundsystem library.
25 FCVAR_INPUTSYSTEM Defined by the inputsystem DLL.
26 FCVAR_NETWORKSYSTEM Defined by the network system.
27 FCVAR_VPHYSICS Defined by VPhysics.

Some preset combinations of flags are also defined in code, for convenience or testing against:

  • FCVAR_NONE is defined as 0, equivalent to having no flags set
  • FCVAR_MATERIAL_THREAD_MASK is defined as ( FCVAR_RELOAD_MATERIALS | FCVAR_RELOAD_TEXTURES | FCVAR_MATERIAL_SYSTEM_THREAD ). (in all games since Alien Swarm) (also in Source 2013)
  • FCVAR_NON_ENGINE is defined as (FCVAR_LAUNCHER|FCVAR_GAMEDLL|FCVAR_CLIENTDLL|FCVAR_MATERIAL_SYSTEM|FCVAR_DATACACHE|FCVAR_STUDIORENDER|FCVAR_FILESYSTEM|FCVAR_PLUGIN|FCVAR_TOOLSYSTEM|FCVAR_SOUNDSYSTEM|FCVAR_INPUTSYSTEM|FCVAR_NETWORKSYSTEM|FCVAR_VPHYSICS) (removed since Source 2007)

Custom flags

It is possible to define custom flags, and query them with ConCommandBase::IsFlagSet(). Because the flags are stored in a 32-bit integer though, there isn't much room for additional ones. Which flags are available for use depends on the engine branch:

Beyond this, if the flag you want to add is only relevant to ConCommands, then one of the various ConVar-only flags (such as FCVAR_ARCHIVE) could be reused, as this would have no effects otherwise. However, you would need to be careful that these flags are never applied to ConVars by accident, as this would produce unexpected side effects.

Porting RemoveFlags() to other engine branches

It is possible to port ConCommandBase::RemoveFlags() to branches that don't have it, such as Source 2013 Source 2013. To do so, simply add the following lines to the end of the definition of ConCommandBase in public\tier1\convar.h:

	public:
		void RemoveFlags( int flags ) { m_nFlags &= ~flags; }

Make sure this function is not virtual, as this would cause the layout of the class in memory to change and break compatibility with the engine.