core/CConVarManager.h
author David Anderson <dvander@alliedmods.net>
Sat Feb 17 19:03:18 2007 +0000 (2007-02-17)
changeset 520 7676d61cde2d
parent 487 3410298035cb
child 576 50696154c0b8
permissions -rw-r--r--
added helper a core translation helper to the translator
regadmincmd is now officially done and tested, as are overrides
printtoplayers now prints to the server on id==0 as a convenience
fixed a crash bug in the admin system
fixed up console.inc a bit
ds@457
     1
/**
ds@457
     2
* ===============================================================
ds@457
     3
* SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
ds@457
     4
* ===============================================================
ds@457
     5
*
ds@457
     6
* This file is not open source and may not be copied without explicit
ds@457
     7
* written permission of AlliedModders LLC.  This file may not be redistributed 
ds@457
     8
* in whole or significant part.
ds@457
     9
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php
ds@457
    10
*
ds@457
    11
* Version: $Id$
ds@457
    12
*/
ds@457
    13
ds@457
    14
#ifndef _INCLUDE_SOURCEMOD_CCONVARMANAGER_H_
ds@457
    15
#define _INCLUDE_SOURCEMOD_CCONVARMANAGER_H_
ds@457
    16
ds@457
    17
#include "sm_globals.h"
ds@457
    18
#include "sourcemm_api.h"
ds@457
    19
#include "sm_trie.h"
ds@465
    20
#include <sh_list.h>
ds@487
    21
#include <IPluginSys.h>
ds@487
    22
#include <IForwardSys.h>
ds@487
    23
#include <IHandleSys.h>
ds@457
    24
#include <IRootConsoleMenu.h>
ds@457
    25
ds@465
    26
using namespace SourceHook;
ds@465
    27
ds@465
    28
/**
ds@465
    29
 * Holds SourceMod-specific information about a convar
ds@465
    30
 */
ds@465
    31
struct ConVarInfo
ds@465
    32
{
ds@465
    33
	Handle_t handle;					/**< Handle to convar */
ds@465
    34
	bool sourceMod;						/**< Determines whether or not convar was created by a SourceMod plugin */
ds@465
    35
	IChangeableForward *changeForward;	/**< Forward associated with convar */
ds@465
    36
	FnChangeCallback origCallback;		/**< The original callback function */
ds@465
    37
};
ds@465
    38
ds@457
    39
class CConVarManager :
ds@457
    40
	public SMGlobalClass,
ds@457
    41
	public IHandleTypeDispatch,
ds@487
    42
	public IPluginsListener,
ds@457
    43
	public IRootConsoleCommand
ds@457
    44
{
ds@457
    45
public:
ds@457
    46
	CConVarManager();
ds@457
    47
	~CConVarManager();
ds@457
    48
public: // SMGlobalClass
ds@457
    49
	void OnSourceModAllInitialized();
ds@457
    50
	void OnSourceModShutdown();
ds@457
    51
public: // IHandleTypeDispatch
ds@457
    52
	void OnHandleDestroy(HandleType_t type, void *object);
ds@487
    53
public: // IPluginsListener
ds@487
    54
	void OnPluginDestroyed(IPlugin *plugin);
ds@457
    55
public: //IRootConsoleCommand
ds@457
    56
	void OnRootConsoleCommand(const char *command, unsigned int argcount);
ds@457
    57
public:
ds@465
    58
	/**
ds@465
    59
	 * Get the 'ConVar' handle type ID.
ds@465
    60
	 */
ds@457
    61
	inline HandleType_t GetHandleType()
ds@457
    62
	{
ds@457
    63
		return m_ConVarType;
ds@457
    64
	}
ds@465
    65
ds@465
    66
	/**
ds@465
    67
	 * Get the convar lookup trie.
ds@465
    68
	 */
ds@465
    69
	inline Trie *GetConVarCache()
ds@465
    70
	{
ds@465
    71
		return m_ConVarCache;
ds@465
    72
	}
ds@457
    73
public:
ds@465
    74
	/**
ds@465
    75
	 * Create a convar and return a handle to it.
ds@465
    76
	 */
ds@457
    77
	Handle_t CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal, const char *helpText,
ds@457
    78
	                      int flags, bool hasMin, float min, bool hasMax, float max);
ds@465
    79
ds@465
    80
	/**
ds@465
    81
	 * Searches for a convar and returns a handle to it
ds@465
    82
	 */
ds@457
    83
	Handle_t FindConVar(const char* name);
ds@465
    84
ds@465
    85
	/**
ds@465
    86
	 * Add a function to call when the specified convar changes.
ds@465
    87
	 */
ds@465
    88
	void HookConVarChange(IPluginContext *pContext, ConVar *cvar, funcid_t funcid);
ds@465
    89
ds@465
    90
	/**
ds@465
    91
	 * Remove a function from the forward that will be called when the specified convar changes.
ds@465
    92
	 */
ds@465
    93
	void UnhookConVarChange(IPluginContext *pContext, ConVar *cvar, funcid_t funcid);
ds@465
    94
private:
ds@465
    95
	/**
ds@465
    96
	* Static callback that Valve's ConVar class executes when the convar's value changes.
ds@465
    97
	*/
ds@465
    98
	static void OnConVarChanged(ConVar *cvar, const char *oldValue);
ds@457
    99
private:
ds@457
   100
	HandleType_t m_ConVarType;
ds@465
   101
	List<ConVarInfo *> m_ConVars;
ds@465
   102
	Trie *m_ConVarCache;
ds@457
   103
};
ds@457
   104
ds@457
   105
extern CConVarManager g_ConVarManager;
ds@457
   106
dvander@464
   107
#endif // _INCLUDE_SOURCEMOD_CCONVARMANAGER_H_
dvander@464
   108