Many things:

1) General code clean-up in convar manager
2) Fixed bug where convar handles were not being cached for pre-existing convars
3) Fixed bug where a convar's old value and new value were switched in the ConVarChanged hooks
4) Made convar and concmd listings more consistent, I think
5) Alphabetized convar listing
6) Minor clean-up in event manager

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40588
This commit is contained in:
Scott Ehlert
2007-03-06 23:59:25 +00:00
parent e6a127ac17
commit 0b25b6d667
9 changed files with 235 additions and 213 deletions
+25 -10
View File
@@ -29,7 +29,7 @@ static cell_t sm_CreateConVar(IPluginContext *pContext, const cell_t *params)
// While the engine seems to accept a blank convar name, it causes a crash upon server quit
if (name == NULL || strcmp(name, "") == 0)
{
return pContext->ThrowNativeError("Null or blank convar name is not allowed");
return pContext->ThrowNativeError("Convar with blank name is not permitted");
}
pContext->LocalToString(params[2], &defaultVal);
@@ -40,7 +40,14 @@ static cell_t sm_CreateConVar(IPluginContext *pContext, const cell_t *params)
float min = sp_ctof(params[6]);
float max = sp_ctof(params[8]);
return g_ConVarManager.CreateConVar(pContext, name, defaultVal, helpText, params[4], hasMin, min, hasMax, max);
Handle_t hndl = g_ConVarManager.CreateConVar(pContext, name, defaultVal, helpText, params[4], hasMin, min, hasMax, max);
if (hndl == BAD_HANDLE)
{
return pContext->ThrowNativeError("Convar \"%s\" was not created. A console command with the same name already exists.", name);
}
return hndl;
}
static cell_t sm_FindConVar(IPluginContext *pContext, const cell_t *params)
@@ -49,12 +56,6 @@ static cell_t sm_FindConVar(IPluginContext *pContext, const cell_t *params)
pContext->LocalToString(params[1], &name);
// While the engine seems to accept a blank convar name, it causes a crash upon server quit
if (name == NULL || strcmp(name, "") == 0)
{
return BAD_HANDLE;
}
return g_ConVarManager.FindConVar(name);
}
@@ -70,7 +71,14 @@ static cell_t sm_HookConVarChange(IPluginContext *pContext, const cell_t *params
return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
}
g_ConVarManager.HookConVarChange(pContext, pConVar, static_cast<funcid_t>(params[2]));
IPluginFunction *pFunction = pContext->GetFunctionById(params[2]);
if (!pFunction)
{
return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
}
g_ConVarManager.HookConVarChange(pConVar, pFunction);
return 1;
}
@@ -87,7 +95,14 @@ static cell_t sm_UnhookConVarChange(IPluginContext *pContext, const cell_t *para
return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
}
g_ConVarManager.UnhookConVarChange(pContext, pConVar, static_cast<funcid_t>(params[2]));
IPluginFunction *pFunction = pContext->GetFunctionById(params[2]);
if (!pFunction)
{
return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
}
g_ConVarManager.UnhookConVarChange(pConVar, pFunction);
return 1;
}