Querying ConVars from Server Plugins: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
 
m (minor tidy & categorized)
Line 1: Line 1:
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.
With the Source Engine update on 11/29/2006 new functions were added to allow plugin authors to query the values of particular [[ConVar|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''
All of the required changes are in ''src\public\engine\iserverplugin.h''


'''Step 1 - Add New typedef's'''
'''Step 1 - Add new typedef's'''


Add the following lines after the definition for PLUGIN_RESULT
Add the following lines after the definition for PLUGIN_RESULT
Line 17: Line 17:
   typedef int QueryCvarCookie_t;
   typedef int QueryCvarCookie_t;


'''Step 2 - Add and Modify #define's'''
'''Step 2 - Add and modify #define's'''


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.
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.
Line 26: Line 26:




'''Step 3 - Add New Function Declaration to IServerPluginCallbacks'''
'''Step 3 - Add new function declaration to IServerPluginCallbacks'''


Add the following four lines to the end of the public: section of IServerPluginCallbacks
Add the following four lines to the end of the public: section of IServerPluginCallbacks
Line 35: Line 35:
   virtual void OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue ) = 0;
   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'''
'''Step 4 - Add new function declaration to IServerPluginHelpers'''


Add the following four lines to the end of the public: section of IServerPluginHelpers
Add the following four lines to the end of the public: section of IServerPluginHelpers
Line 49: Line 49:


If you have any questions about these new functions issues please feel free to contact mdurand@valvesoftware.com.
If you have any questions about these new functions issues please feel free to contact mdurand@valvesoftware.com.
[[Category:Programming]]
[[Category:Tutorials]]

Revision as of 04:36, 26 February 2008

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

Step 1 - Add new typedef's

Add the following lines after the definition for PLUGIN_RESULT

  typedef enum
  {
     eQueryCvarValueStatus_ValueIntact=0,	// It got the value fine.
     eQueryCvarValueStatus_CvarNotFound=1,
     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 #define's

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
  #define INTERFACEVERSION_ISERVERPLUGINCALLBACKS_VERSION_1	"ISERVERPLUGINCALLBACKS001"
  #define INTERFACEVERSION_ISERVERPLUGINCALLBACKS		"ISERVERPLUGINCALLBACKS002"


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;

If you have any questions about these new functions issues please feel free to contact mdurand@valvesoftware.com.