ds@580: /** ds@653: * vim: set ts=4 : ds@653: * =============================================================== ds@653: * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. ds@653: * =============================================================== ds@653: * ds@653: * This file is not open source and may not be copied without explicit ds@653: * written permission of AlliedModders LLC. This file may not be redistributed ds@653: * in whole or significant part. ds@653: * For information, see LICENSE.txt or http://www.sourcemod.net/license.php ds@653: * ds@653: * Version: $Id$ ds@653: */ ds@580: ds@580: #ifndef _INCLUDE_SOURCEMOD_CONVARMANAGER_H_ ds@580: #define _INCLUDE_SOURCEMOD_CONVARMANAGER_H_ ds@580: ds@580: #include "sm_globals.h" ds@580: #include "sourcemm_api.h" ds@580: #include "sm_trie.h" ds@580: #include ds@580: #include ds@580: #include ds@580: #include ds@580: #include ds@580: ds@580: using namespace SourceHook; ds@580: ds@580: /** ds@580: * Holds SourceMod-specific information about a convar ds@580: */ ds@580: struct ConVarInfo ds@580: { ds@580: Handle_t handle; /**< Handle to convar */ ds@580: bool sourceMod; /**< Determines whether or not convar was created by a SourceMod plugin */ ds@696: IChangeableForward *pChangeForward; /**< Forward associated with convar */ ds@580: FnChangeCallback origCallback; /**< The original callback function */ ds@580: }; ds@580: ds@696: /** ds@696: * Holds information about a client convar query ds@696: */ ds@696: struct ConVarQuery ds@696: { ds@696: QueryCvarCookie_t cookie; /**< Cookie that identifies query */ ds@696: IPluginFunction *pCallback; /**< Function that will be called when query is finished */ ds@696: cell_t value; /**< Optional value passed to query function */ ds@696: }; ds@696: ds@580: class ConVarManager : ds@580: public SMGlobalClass, ds@580: public IHandleTypeDispatch, ds@580: public IPluginsListener, ds@580: public IRootConsoleCommand ds@580: { ds@580: public: ds@580: ConVarManager(); ds@580: ~ConVarManager(); ds@580: public: // SMGlobalClass ds@580: void OnSourceModAllInitialized(); ds@580: void OnSourceModShutdown(); ds@696: void OnSourceModVSPReceived(IServerPluginCallbacks *iface); ds@580: public: // IHandleTypeDispatch ds@580: void OnHandleDestroy(HandleType_t type, void *object); ds@580: public: // IPluginsListener ds@582: void OnPluginUnloaded(IPlugin *plugin); ds@580: public: //IRootConsoleCommand ds@580: void OnRootConsoleCommand(const char *command, unsigned int argcount); ds@580: public: ds@580: /** ds@580: * Get the 'ConVar' handle type ID. ds@580: */ ds@580: inline HandleType_t GetHandleType() ds@580: { ds@580: return m_ConVarType; ds@580: } ds@580: ds@580: /** ds@580: * Get the convar lookup trie. ds@580: */ ds@580: inline Trie *GetConVarCache() ds@580: { ds@580: return m_ConVarCache; ds@580: } ds@580: public: ds@580: /** ds@580: * Create a convar and return a handle to it. ds@580: */ ds@582: Handle_t CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal, ds@582: const char *description, int flags, bool hasMin, float min, bool hasMax, float max); ds@580: ds@580: /** ds@580: * Searches for a convar and returns a handle to it ds@580: */ ds@580: Handle_t FindConVar(const char* name); ds@580: ds@580: /** ds@580: * Add a function to call when the specified convar changes. ds@580: */ ds@582: void HookConVarChange(ConVar *pConVar, IPluginFunction *pFunction); ds@580: ds@580: /** ds@580: * Remove a function from the forward that will be called when the specified convar changes. ds@580: */ ds@582: void UnhookConVarChange(ConVar *pConVar, IPluginFunction *pFunction); ds@696: ds@696: /** ds@696: * Starts a query to find the value of a client convar. ds@696: */ ds@696: QueryCvarCookie_t QueryClientConVar(edict_t *pPlayer, const char *name, IPluginFunction *pCallback, ds@696: Handle_t hndl); ds@580: private: ds@580: /** ds@582: * Adds a convar to a plugin's list. ds@582: */ ds@582: static void AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar); ds@582: ds@582: /** ds@696: * Static callback that Valve's ConVar object executes when the convar's value changes. ds@580: */ ds@580: static void OnConVarChanged(ConVar *pConVar, const char *oldValue); ds@696: ds@696: /** ds@696: * Callback for when StartQueryCvarValue() has finished. ds@696: */ ds@696: void OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result, ds@696: const char *cvarName, const char *cvarValue); ds@580: private: ds@580: HandleType_t m_ConVarType; ds@580: List m_ConVars; ds@696: List m_ConVarQueries; ds@580: Trie *m_ConVarCache; ds@696: IServerPluginCallbacks *m_VSPIface; ds@696: bool m_CanQueryConVars; ds@580: }; ds@580: ds@580: extern ConVarManager g_ConVarManager; ds@580: ds@580: #endif // _INCLUDE_SOURCEMOD_CONVARMANAGER_H_ ds@580: