core/CConVarManager.cpp
changeset 487 3410298035cb
parent 482 539e4ba81895
child 494 9b57583cc80b
     1.1 --- a/core/CConVarManager.cpp	Tue Feb 13 19:20:48 2007 +0000
     1.2 +++ b/core/CConVarManager.cpp	Wed Feb 14 01:25:45 2007 +0000
     1.3 @@ -12,10 +12,12 @@
     1.4  */
     1.5  
     1.6  #include "CConVarManager.h"
     1.7 -#include "CLogger.h"
     1.8  #include "PluginSys.h"
     1.9 +#include "ForwardSys.h"
    1.10 +#include "HandleSys.h"
    1.11  #include "sm_srvcmds.h"
    1.12  #include "sm_stringutil.h"
    1.13 +#include <sh_vector.h>
    1.14  
    1.15  CConVarManager g_ConVarManager;
    1.16  
    1.17 @@ -81,6 +83,17 @@
    1.18  	g_HandleSys.RemoveType(m_ConVarType, g_pCoreIdent);
    1.19  }
    1.20  
    1.21 +void CConVarManager::OnPluginDestroyed(IPlugin *plugin)
    1.22 +{
    1.23 +	CVector<ConVar *> *cvarList;
    1.24 +
    1.25 +	// If plugin has a convar list, free its memory
    1.26 +	if (plugin->GetProperty("ConVar", reinterpret_cast<void **>(&cvarList), true))
    1.27 +	{
    1.28 +		delete cvarList;
    1.29 +	}
    1.30 +}
    1.31 +
    1.32  void CConVarManager::OnHandleDestroy(HandleType_t type, void *object)
    1.33  {
    1.34  	ConVarInfo *info;
    1.35 @@ -116,10 +129,13 @@
    1.36  		// Get plugin object
    1.37  		CPlugin *pl = g_PluginSys.GetPluginByOrder(num);
    1.38  
    1.39 -		// Get number of convars created by plugin
    1.40 -		int convarnum = pl->GetConVarCount();
    1.41 +		CVector<ConVar *> *cvarList = NULL;
    1.42  
    1.43 -		if (convarnum == 0)
    1.44 +		// Get convar list from 'ConVar' property
    1.45 +		pl->GetProperty("ConVar", reinterpret_cast<void **>(&cvarList));
    1.46 +
    1.47 +		// If no cvar list...
    1.48 +		if (cvarList == NULL)
    1.49  		{
    1.50  			g_RootMenu.ConsolePrint("[SM] No convars for \"%s\"", pl->GetPublicInfo()->name);
    1.51  			return;
    1.52 @@ -128,9 +144,9 @@
    1.53  		g_RootMenu.ConsolePrint("[SM] Displaying convars for \"%s\"", pl->GetPublicInfo()->name);
    1.54  
    1.55  		// Iterate convar list and display each one
    1.56 -		for (int i = 0; i < convarnum; i++, id++)
    1.57 +		for (size_t i = 0; i < cvarList->size(); i++, id++)
    1.58  		{
    1.59 -			ConVar *cvar = pl->GetConVarByIndex(i);
    1.60 +			ConVar *cvar = (*cvarList)[i];
    1.61  			g_RootMenu.ConsolePrint("  %02d \"%s\" = \"%s\"", id, cvar->GetName(), cvar->GetString()); 
    1.62  		}
    1.63  
    1.64 @@ -145,6 +161,7 @@
    1.65  {
    1.66  	ConVar *cvar = NULL;
    1.67  	ConVarInfo *info = NULL;
    1.68 +	CVector<ConVar *> *cvarList = NULL;
    1.69  	Handle_t hndl = 0;
    1.70  
    1.71  	// Find out if the convar exists already
    1.72 @@ -190,8 +207,22 @@
    1.73  	// Since we didn't find an existing convar (or concmd with the same name), now we can finally create it!
    1.74  	cvar = new ConVar(name, defaultVal, flags, helpText, hasMin, min, hasMax, max);
    1.75  
    1.76 +	// Find plugin creating convar
    1.77 +	IPlugin *pl = g_PluginSys.FindPluginByContext(pContext->GetContext());
    1.78 +
    1.79 +	// Get convar list from 'ConVar' property of plugin
    1.80 +	pl->GetProperty("ConVar", reinterpret_cast<void **>(&cvarList));
    1.81 +
    1.82 +	// If 'ConVar' property doesn't exist...
    1.83 +	if (cvarList == NULL)
    1.84 +	{
    1.85 +		// Then create it
    1.86 +		cvarList = new CVector<ConVar *>;
    1.87 +		pl->SetProperty("ConVar", cvarList);
    1.88 +	}
    1.89 +
    1.90  	// Add new convar to plugin's list
    1.91 -	g_PluginSys.GetPluginByCtx(pContext->GetContext())->AddConVar(cvar);
    1.92 +	cvarList->push_back(cvar);
    1.93  
    1.94  	// Create a handle from the new convar
    1.95  	hndl = g_HandleSys.CreateHandle(m_ConVarType, cvar, NULL, g_pCoreIdent, NULL);