3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is not open source and may not be copied without explicit
8 * written permission of AlliedModders LLC. This file may not be redistributed
9 * in whole or significant part.
10 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
15 #ifndef _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
16 #define _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
18 #include "sm_globals.h"
19 #include "sourcemm_api.h"
22 #include <IPluginSys.h>
23 #include <IForwardSys.h>
24 #include <IHandleSys.h>
25 #include <IRootConsoleMenu.h>
27 using namespace SourceHook;
30 * Holds SourceMod-specific information about a convar
34 Handle_t handle; /**< Handle to convar */
35 bool sourceMod; /**< Determines whether or not convar was created by a SourceMod plugin */
36 IChangeableForward *pChangeForward; /**< Forward associated with convar */
37 FnChangeCallback origCallback; /**< The original callback function */
41 * Holds information about a client convar query
45 QueryCvarCookie_t cookie; /**< Cookie that identifies query */
46 IPluginFunction *pCallback; /**< Function that will be called when query is finished */
47 cell_t value; /**< Optional value passed to query function */
52 public IHandleTypeDispatch,
53 public IPluginsListener,
54 public IRootConsoleCommand
59 public: // SMGlobalClass
60 void OnSourceModAllInitialized();
61 void OnSourceModShutdown();
62 void OnSourceModVSPReceived(IServerPluginCallbacks *iface);
63 public: // IHandleTypeDispatch
64 void OnHandleDestroy(HandleType_t type, void *object);
65 public: // IPluginsListener
66 void OnPluginUnloaded(IPlugin *plugin);
67 public: //IRootConsoleCommand
68 void OnRootConsoleCommand(const char *command, unsigned int argcount);
71 * Get the 'ConVar' handle type ID.
73 inline HandleType_t GetHandleType()
79 * Get the convar lookup trie.
81 inline Trie *GetConVarCache()
87 * Create a convar and return a handle to it.
89 Handle_t CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal,
90 const char *description, int flags, bool hasMin, float min, bool hasMax, float max);
93 * Searches for a convar and returns a handle to it
95 Handle_t FindConVar(const char* name);
98 * Add a function to call when the specified convar changes.
100 void HookConVarChange(ConVar *pConVar, IPluginFunction *pFunction);
103 * Remove a function from the forward that will be called when the specified convar changes.
105 void UnhookConVarChange(ConVar *pConVar, IPluginFunction *pFunction);
108 * Starts a query to find the value of a client convar.
110 QueryCvarCookie_t QueryClientConVar(edict_t *pPlayer, const char *name, IPluginFunction *pCallback,
114 * Adds a convar to a plugin's list.
116 static void AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar);
119 * Static callback that Valve's ConVar object executes when the convar's value changes.
121 static void OnConVarChanged(ConVar *pConVar, const char *oldValue);
124 * Callback for when StartQueryCvarValue() has finished.
126 void OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result,
127 const char *cvarName, const char *cvarValue);
129 HandleType_t m_ConVarType;
130 List<ConVarInfo *> m_ConVars;
131 List<ConVarQuery> m_ConVarQueries;
133 IServerPluginCallbacks *m_VSPIface;
134 bool m_CanQueryConVars;
137 extern ConVarManager g_ConVarManager;
139 #endif // _INCLUDE_SOURCEMOD_CONVARMANAGER_H_