core/ConVarManager.h
author David Anderson <dvander@alliedmods.net>
Sun Dec 02 02:10:37 2007 +0000 (2007-12-02)
changeset 1738 cb3be0b31d99
parent 1582 6f18465dd9f9
child 1766 d30c252089be
permissions -rw-r--r--
- added beefy new ReadMapList() native
- admin menu now uses ReadMapList()
- added UTIL_TrimWhitespace() to stringutils
- moved GetFileTime() implementation to ILibrarySys
- cleaned up sorting include a bit
- removed adminmenu_maplist.ini, since it's specified by maplists.cfg
- added maplists.cfg
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #ifndef _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
    33 #define _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
    34 
    35 #include "sm_globals.h"
    36 #include "sourcemm_api.h"
    37 #include <sh_list.h>
    38 #include <IPluginSys.h>
    39 #include <IForwardSys.h>
    40 #include <IHandleSys.h>
    41 #include <IRootConsoleMenu.h>
    42 #include <compat_wrappers.h>
    43 #include "concmd_cleaner.h"
    44 
    45 using namespace SourceHook;
    46 
    47 /**
    48  * Holds SourceMod-specific information about a convar
    49  */
    50 struct ConVarInfo
    51 {
    52 	Handle_t handle;					/**< Handle to self */
    53 	bool sourceMod;						/**< Determines whether or not convar was created by a SourceMod plugin */
    54 	IChangeableForward *pChangeForward;	/**< Forward associated with convar */
    55 	FnChangeCallback_t origCallback;	/**< The original callback function */
    56 	ConVar *pVar;						/**< The actual convar */
    57 };
    58 
    59 /**
    60  * Holds information about a client convar query
    61  */
    62 struct ConVarQuery
    63 {
    64 	QueryCvarCookie_t cookie;			/**< Cookie that identifies query */
    65 	IPluginFunction *pCallback;			/**< Function that will be called when query is finished */
    66 	cell_t value;						/**< Optional value passed to query function */
    67 };
    68 
    69 class ConVarManager :
    70 	public SMGlobalClass,
    71 	public IHandleTypeDispatch,
    72 	public IPluginsListener,
    73 	public IRootConsoleCommand,
    74 	public IConCommandTracker
    75 {
    76 public:
    77 	ConVarManager();
    78 	~ConVarManager();
    79 public: // SMGlobalClass
    80 	void OnSourceModAllInitialized();
    81 	void OnSourceModShutdown();
    82 	void OnSourceModVSPReceived();
    83 public: // IHandleTypeDispatch
    84 	void OnHandleDestroy(HandleType_t type, void *object);
    85 public: // IPluginsListener
    86 	void OnPluginUnloaded(IPlugin *plugin);
    87 public: //IRootConsoleCommand
    88 	void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
    89 public: //IConCommandTracker
    90 	void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe);
    91 public:
    92 	/**
    93 	 * Create a convar and return a handle to it.
    94 	 */
    95 	Handle_t CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal,
    96 	                      const char *description, int flags, bool hasMin, float min, bool hasMax, float max);
    97 
    98 	/**
    99 	 * Searches for a convar and returns a handle to it
   100 	 */
   101 	Handle_t FindConVar(const char* name);
   102 
   103 	/**
   104 	 * Add a function to call when the specified convar changes.
   105 	 */
   106 	void HookConVarChange(ConVar *pConVar, IPluginFunction *pFunction);
   107 
   108 	/**
   109 	 * Remove a function from the forward that will be called when the specified convar changes.
   110 	 */
   111 	void UnhookConVarChange(ConVar *pConVar, IPluginFunction *pFunction);
   112 
   113 	/**
   114 	 * Starts a query to find the value of a client convar.
   115 	 */
   116 	QueryCvarCookie_t QueryClientConVar(edict_t *pPlayer, const char *name, IPluginFunction *pCallback,
   117 	                                    Handle_t hndl);
   118 
   119 	bool IsQueryingSupported();
   120 
   121 	HandleError ReadConVarHandle(Handle_t hndl, ConVar **pVar);
   122 
   123 private:
   124 	/**
   125 	 * Adds a convar to a plugin's list.
   126 	 */
   127 	static void AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar);
   128 
   129 	/**
   130 	 * Static callback that Valve's ConVar object executes when the convar's value changes.
   131 	 */
   132 #if defined ORANGEBOX_BUILD
   133 	static void OnConVarChanged(IConVar *pConVar, const char *oldValue, float flOldValue);
   134 #else
   135 	static void OnConVarChanged(ConVar *pConVar, const char *oldValue);
   136 #endif
   137 
   138 	/**
   139 	 * Callback for when StartQueryCvarValue() has finished.
   140 	 */
   141 	void OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result,
   142 	                              const char *cvarName, const char *cvarValue);
   143 private:
   144 	HandleType_t m_ConVarType;
   145 	List<ConVarInfo *> m_ConVars;
   146 	List<ConVarQuery> m_ConVarQueries;
   147 	bool m_bIsDLLQueryHooked;
   148 	bool m_bIsVSPQueryHooked;
   149 };
   150 
   151 extern ConVarManager g_ConVarManager;
   152 
   153 #endif // _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
   154