core/ConVarManager.h
author David Anderson <dvander@alliedmods.net>
Fri Jun 01 02:30:29 2007 +0000 (2007-06-01)
changeset 868 bdbf922e246f
parent 696 d5cc8d0fa899
child 1145 f12e19245c7a
permissions -rw-r--r--
-initial import of database natives + config
-initial import of completed database layer
-CreateIdentity now requires a non-optional second pointer. This breaks backwards compatibility for CreateIdentity(), however, this is not a function extension authors are supposed to be calling
ds@580
     1
/**
ds@653
     2
 * vim: set ts=4 :
ds@653
     3
 * ===============================================================
ds@653
     4
 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
ds@653
     5
 * ===============================================================
ds@653
     6
 *
ds@653
     7
 * This file is not open source and may not be copied without explicit
ds@653
     8
 * written permission of AlliedModders LLC.  This file may not be redistributed 
ds@653
     9
 * in whole or significant part.
ds@653
    10
 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
ds@653
    11
 *
ds@653
    12
 * Version: $Id$
ds@653
    13
 */
ds@580
    14
ds@580
    15
#ifndef _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
ds@580
    16
#define _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
ds@580
    17
ds@580
    18
#include "sm_globals.h"
ds@580
    19
#include "sourcemm_api.h"
ds@580
    20
#include "sm_trie.h"
ds@580
    21
#include <sh_list.h>
ds@580
    22
#include <IPluginSys.h>
ds@580
    23
#include <IForwardSys.h>
ds@580
    24
#include <IHandleSys.h>
ds@580
    25
#include <IRootConsoleMenu.h>
ds@580
    26
ds@580
    27
using namespace SourceHook;
ds@580
    28
ds@580
    29
/**
ds@580
    30
 * Holds SourceMod-specific information about a convar
ds@580
    31
 */
ds@580
    32
struct ConVarInfo
ds@580
    33
{
ds@580
    34
	Handle_t handle;					/**< Handle to convar */
ds@580
    35
	bool sourceMod;						/**< Determines whether or not convar was created by a SourceMod plugin */
ds@696
    36
	IChangeableForward *pChangeForward;	/**< Forward associated with convar */
ds@580
    37
	FnChangeCallback origCallback;		/**< The original callback function */
ds@580
    38
};
ds@580
    39
ds@696
    40
/**
ds@696
    41
 * Holds information about a client convar query
ds@696
    42
 */
ds@696
    43
struct ConVarQuery
ds@696
    44
{
ds@696
    45
	QueryCvarCookie_t cookie;			/**< Cookie that identifies query */
ds@696
    46
	IPluginFunction *pCallback;			/**< Function that will be called when query is finished */
ds@696
    47
	cell_t value;						/**< Optional value passed to query function */
ds@696
    48
};
ds@696
    49
ds@580
    50
class ConVarManager :
ds@580
    51
	public SMGlobalClass,
ds@580
    52
	public IHandleTypeDispatch,
ds@580
    53
	public IPluginsListener,
ds@580
    54
	public IRootConsoleCommand
ds@580
    55
{
ds@580
    56
public:
ds@580
    57
	ConVarManager();
ds@580
    58
	~ConVarManager();
ds@580
    59
public: // SMGlobalClass
ds@580
    60
	void OnSourceModAllInitialized();
ds@580
    61
	void OnSourceModShutdown();
ds@696
    62
	void OnSourceModVSPReceived(IServerPluginCallbacks *iface);
ds@580
    63
public: // IHandleTypeDispatch
ds@580
    64
	void OnHandleDestroy(HandleType_t type, void *object);
ds@580
    65
public: // IPluginsListener
ds@582
    66
	void OnPluginUnloaded(IPlugin *plugin);
ds@580
    67
public: //IRootConsoleCommand
ds@580
    68
	void OnRootConsoleCommand(const char *command, unsigned int argcount);
ds@580
    69
public:
ds@580
    70
	/**
ds@580
    71
	 * Get the 'ConVar' handle type ID.
ds@580
    72
	 */
ds@580
    73
	inline HandleType_t GetHandleType()
ds@580
    74
	{
ds@580
    75
		return m_ConVarType;
ds@580
    76
	}
ds@580
    77
ds@580
    78
	/**
ds@580
    79
	 * Get the convar lookup trie.
ds@580
    80
	 */
ds@580
    81
	inline Trie *GetConVarCache()
ds@580
    82
	{
ds@580
    83
		return m_ConVarCache;
ds@580
    84
	}
ds@580
    85
public:
ds@580
    86
	/**
ds@580
    87
	 * Create a convar and return a handle to it.
ds@580
    88
	 */
ds@582
    89
	Handle_t CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal,
ds@582
    90
	                      const char *description, int flags, bool hasMin, float min, bool hasMax, float max);
ds@580
    91
ds@580
    92
	/**
ds@580
    93
	 * Searches for a convar and returns a handle to it
ds@580
    94
	 */
ds@580
    95
	Handle_t FindConVar(const char* name);
ds@580
    96
ds@580
    97
	/**
ds@580
    98
	 * Add a function to call when the specified convar changes.
ds@580
    99
	 */
ds@582
   100
	void HookConVarChange(ConVar *pConVar, IPluginFunction *pFunction);
ds@580
   101
ds@580
   102
	/**
ds@580
   103
	 * Remove a function from the forward that will be called when the specified convar changes.
ds@580
   104
	 */
ds@582
   105
	void UnhookConVarChange(ConVar *pConVar, IPluginFunction *pFunction);
ds@696
   106
ds@696
   107
	/**
ds@696
   108
	 * Starts a query to find the value of a client convar.
ds@696
   109
	 */
ds@696
   110
	QueryCvarCookie_t QueryClientConVar(edict_t *pPlayer, const char *name, IPluginFunction *pCallback,
ds@696
   111
	                                    Handle_t hndl);
ds@580
   112
private:
ds@580
   113
	/**
ds@582
   114
	 * Adds a convar to a plugin's list.
ds@582
   115
	 */
ds@582
   116
	static void AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar);
ds@582
   117
ds@582
   118
	/**
ds@696
   119
	 * Static callback that Valve's ConVar object executes when the convar's value changes.
ds@580
   120
	 */
ds@580
   121
	static void OnConVarChanged(ConVar *pConVar, const char *oldValue);
ds@696
   122
ds@696
   123
	/**
ds@696
   124
	 * Callback for when StartQueryCvarValue() has finished.
ds@696
   125
	 */
ds@696
   126
	void OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result,
ds@696
   127
	                              const char *cvarName, const char *cvarValue);
ds@580
   128
private:
ds@580
   129
	HandleType_t m_ConVarType;
ds@580
   130
	List<ConVarInfo *> m_ConVars;
ds@696
   131
	List<ConVarQuery> m_ConVarQueries;
ds@580
   132
	Trie *m_ConVarCache;
ds@696
   133
	IServerPluginCallbacks *m_VSPIface;
ds@696
   134
	bool m_CanQueryConVars;
ds@580
   135
};
ds@580
   136
ds@580
   137
extern ConVarManager g_ConVarManager;
ds@580
   138
ds@580
   139
#endif // _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
ds@580
   140