Querying ConVars from Server Plugins

From Valve Developer Community
Jump to: navigation, search

With the Source Engine update on 11/29/2006 new functions were added to allow plugin authors to query the values of particular convars set on the client. Since this functionality is greatly desired by the mod community and we are not currently ready for an SDK update we have created this page in order to demonstrate how to use this new functionality.

All of the required changes are in src\public\engine\iserverplugin.h.

If you have any questions about these new functions please feel free to contact [email protected].

Step 1 - Add new typedef

Add the following lines after the definition for PLUGIN_RESULT:

  typedef enum
     eQueryCvarValueStatus_ValueIntact=0,	// It got the value fine.
     eQueryCvarValueStatus_NotACvar=2,		// There's a ConCommand, but it's not a ConVar.
     eQueryCvarValueStatus_CvarProtected=3	// The cvar was marked with FCVAR_SERVER_CAN_NOT_QUERY, so the server is not allowed to have its value.
  } EQueryCvarValueStatus;

  typedef int QueryCvarCookie_t;

Step 2 - Add and modify #defines

Add the following lines beneath the typedef's added in Step 1. You will be changing the value of INTERFACEVERSION_ISERVERPLUGINCALLBACKS which was previously defined.

  #define InvalidQueryCvarCookie -1

Step 3 - Add new function declaration to IServerPluginCallbacks()

Add the following four lines to the end of the public: section of IServerPluginCallbacks():

  // This is called when a query from IServerPluginHelpers::StartQueryCvarValue is finished.
  // iCookie is the value returned by IServerPluginHelpers::StartQueryCvarValue.
  // Added with version 2 of the interface.
  virtual void OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue ) = 0;

Step 4 - Add new function declaration to IServerPluginHelpers()

Add the following four lines to the end of the public: section of IServerPluginHelpers():

  // Call this to find out the value of a cvar on the client.
  // It is an asynchronous query, and it will call IServerPluginCallbacks::OnQueryCvarValueFinished when
  // the value comes in from the client.
  // Store the return value if you want to match this specific query to the OnQueryCvarValueFinished call.
  // Returns InvalidQueryCvarCookie if the entity is invalid.
  virtual QueryCvarCookie_t StartQueryCvarValue( edict_t *pEntity, const char *pName ) = 0;