added handle reading to GameConfigManager

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40955
This commit is contained in:
David Anderson 2007-06-16 08:35:26 +00:00
parent 15a7be0e3e
commit c133002c14
3 changed files with 49 additions and 10 deletions

View File

@ -24,6 +24,7 @@
#include "ShareSys.h" #include "ShareSys.h"
#include "MemoryUtils.h" #include "MemoryUtils.h"
#include "LibrarySys.h" #include "LibrarySys.h"
#include "HandleSys.h"
#if defined PLATFORM_LINUX #if defined PLATFORM_LINUX
#include <dlfcn.h> #include <dlfcn.h>
@ -560,3 +561,19 @@ void GameConfigManager::CloseGameConfigFile(IGameConfig *cfg)
delete pConfig; delete pConfig;
} }
} }
extern HandleType_t g_GameConfigsType;
IGameConfig *GameConfigManager::ReadHandle(Handle_t hndl, IdentityToken_t *ident, HandleError *err)
{
HandleSecurity sec(ident, g_pCoreIdent);
IGameConfig *conf = NULL;
HandleError _err = g_HandleSys.ReadHandle(hndl, g_GameConfigsType, &sec, (void **)&conf);
if (err)
{
*err = _err;
}
return conf;
}

View File

@ -76,6 +76,9 @@ public:
public: //IGameConfigManager public: //IGameConfigManager
bool LoadGameConfigFile(const char *file, IGameConfig **pConfig, char *error, size_t maxlength); bool LoadGameConfigFile(const char *file, IGameConfig **pConfig, char *error, size_t maxlength);
void CloseGameConfigFile(IGameConfig *cfg); void CloseGameConfigFile(IGameConfig *cfg);
IGameConfig *ReadHandle(Handle_t hndl,
IdentityToken_t *ident,
HandleError *err);
public: //SMGlobalClass public: //SMGlobalClass
void OnSourceModStartup(bool late); void OnSourceModStartup(bool late);
void OnSourceModAllInitialized(); void OnSourceModAllInitialized();

View File

@ -20,6 +20,7 @@
#define _INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_ #define _INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_
#include <IShareSys.h> #include <IShareSys.h>
#include <IHandleSys.h>
/** /**
* @file IGameConfigs.h * @file IGameConfigs.h
@ -27,7 +28,7 @@
*/ */
#define SMINTERFACE_GAMECONFIG_NAME "IGameConfigManager" #define SMINTERFACE_GAMECONFIG_NAME "IGameConfigManager"
#define SMINTERFACE_GAMECONFIG_VERSION 2 #define SMINTERFACE_GAMECONFIG_VERSION 3
class SendProp; class SendProp;
@ -69,8 +70,9 @@ namespace SourceMod
* *
* @param key Name of the signature. * @param key Name of the signature.
* @param addr Pointer to store the memory address in. * @param addr Pointer to store the memory address in.
* @return A MemorySignature pointer on success, or NULL * @return True if the key was found, false otherwise.
* if the key was not found. * Note that true is a valid return even if the
* address is NULL.
*/ */
virtual bool GetMemSig(const char *key, void **addr) =0; virtual bool GetMemSig(const char *key, void **addr) =0;
}; };
@ -93,23 +95,40 @@ namespace SourceMod
/** /**
* @brief Loads or finds an already loaded game config file. * @brief Loads or finds an already loaded game config file.
* *
* @param file File to load. The path must be relative to the 'gamedata' * @param file File to load. The path must be relative to the
* folder under the config folder, and the extension should be omitted. * 'gamedata' folder and the extension should be
* @param pConfig Pointer to store the game config pointer. Pointer will be valid even on failure. * omitted.
* @param pConfig Pointer to store the game config pointer. Pointer
* will be valid even on failure.
* @param error Optional error message buffer. * @param error Optional error message buffer.
* @param maxlength Maximum length of the error buffer. * @param maxlength Maximum length of the error buffer.
* @return True on success, false if the file failed. * @return True on success, false if the file failed.
*/ */
virtual bool LoadGameConfigFile(const char *file, IGameConfig **pConfig, char *error, size_t maxlength) =0; virtual bool LoadGameConfigFile(const char *file,
IGameConfig **pConfig,
char *error,
size_t maxlength) =0;
/** /**
* @brief Closes an IGameConfig pointer. Since a file can be loaded more than once, * @brief Closes an IGameConfig pointer. Since a file can be loaded
* the file will not actually be removed from memory until it is closed once for each * more than once, the file will not actually be removed from memory
* call to LoadGameConfigfile(). * until it is closed once for each call to LoadGameConfigfile().
* *
* @param cfg Pointer to the IGameConfig to close. * @param cfg Pointer to the IGameConfig to close.
*/ */
virtual void CloseGameConfigFile(IGameConfig *cfg) =0; virtual void CloseGameConfigFile(IGameConfig *cfg) =0;
/**
* @brief Reads an GameConfig Handle.
*
* @param hndl Handle to read.
* @param ident Identity of the owner (can be NULL).
* @param err Optional error buffer.
* @return IGameConfig pointer on success, NULL otherwise.
*/
virtual IGameConfig *ReadHandle(Handle_t hndl,
IdentityToken_t *ident,
HandleError *err) =0;
}; };
} }