Difference between revisions of "Querying ConVars from Server Plugins"

From Valve Developer Community
Jump to: navigation, search
m (minor tidy & categorized)
m (cleanup)
 
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 [[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.
 
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 <code>src\public\engine\iserverplugin.h</code>.
  
'''Step 1 - Add new typedef's'''
+
If you have any questions about these new functions please feel free to contact [mailto:mdurand@valvesoftware.com mdurand@valvesoftware.com].
  
Add the following lines after the definition for PLUGIN_RESULT
+
==Step 1 - Add new typedef==
 +
 
 +
Add the following lines after the definition for [[PLUGIN_RESULT]]:
  
 
   typedef enum
 
   typedef enum
Line 14: Line 16:
 
       eQueryCvarValueStatus_CvarProtected=3 // The cvar was marked with FCVAR_SERVER_CAN_NOT_QUERY, so the server is not allowed to have its value.
 
       eQueryCvarValueStatus_CvarProtected=3 // The cvar was marked with FCVAR_SERVER_CAN_NOT_QUERY, so the server is not allowed to have its value.
 
   } EQueryCvarValueStatus;
 
   } EQueryCvarValueStatus;
 
+
 
   typedef int QueryCvarCookie_t;
 
   typedef int QueryCvarCookie_t;
  
'''Step 2 - Add and modify #define's'''
+
==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.
 
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 25: Line 27:
 
   #define INTERFACEVERSION_ISERVERPLUGINCALLBACKS "ISERVERPLUGINCALLBACKS002"
 
   #define INTERFACEVERSION_ISERVERPLUGINCALLBACKS "ISERVERPLUGINCALLBACKS002"
  
 +
==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 <code>public:</code> section of [[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.
 
   // This is called when a query from IServerPluginHelpers::StartQueryCvarValue is finished.
Line 35: Line 36:
 
   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 <code>public:</code> section of [[IServerPluginHelpers()]]:
  
 
   // Call this to find out the value of a cvar on the client.
 
   // Call this to find out the value of a cvar on the client.
Line 48: Line 49:
 
   virtual QueryCvarCookie_t StartQueryCvarValue( edict_t *pEntity, const char *pName ) = 0;
 
   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.
+
[[Category:Networking]]
 
 
[[Category:Programming]]
 
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]
 +
__NOTOC__

Latest revision as of 12:53, 28 March 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.

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

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_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 #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
  #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;