From ac0312602289094327f15faf0f81a7548ec4239a Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Fri, 10 Aug 2007 09:16:58 +0000 Subject: [PATCH] Added replicate and notify parameters to ResetConVar() - these were already available for SetConVarX() --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401307 --- core/smn_console.cpp | 48 +++++++++++++++++++++++-------------- plugins/include/console.inc | 23 +++++++++++------- 2 files changed, 44 insertions(+), 27 deletions(-) diff --git a/core/smn_console.cpp b/core/smn_console.cpp index ee33f357..adc12b41 100644 --- a/core/smn_console.cpp +++ b/core/smn_console.cpp @@ -360,6 +360,35 @@ static cell_t sm_SetConVarString(IPluginContext *pContext, const cell_t *params) return 1; } +static cell_t sm_ResetConVar(IPluginContext *pContext, const cell_t *params) +{ + Handle_t hndl = static_cast(params[1]); + HandleError err; + ConVar *pConVar; + + if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar)) + != HandleError_None) + { + return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err); + } + + pConVar->Revert(); + + /* Should we replicate it? */ + if (params[2] && pConVar->IsBitSet(FCVAR_REPLICATED)) + { + ReplicateConVar(pConVar); + } + + /* Should we notify clients? */ + if (params[3] && pConVar->IsBitSet(FCVAR_NOTIFY)) + { + NotifyConVar(pConVar); + } + + return 1; +} + static cell_t sm_GetConVarFlags(IPluginContext *pContext, const cell_t *params) { Handle_t hndl = static_cast(params[1]); @@ -470,23 +499,6 @@ static cell_t sm_GetConVarName(IPluginContext *pContext, const cell_t *params) return 1; } -static cell_t sm_ResetConVar(IPluginContext *pContext, const cell_t *params) -{ - Handle_t hndl = static_cast(params[1]); - HandleError err; - ConVar *pConVar; - - if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar)) - != HandleError_None) - { - return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err); - } - - pConVar->Revert(); - - return 1; -} - static bool s_QueryAlreadyWarned = false; static cell_t sm_QueryClientConVar(IPluginContext *pContext, const cell_t *params) @@ -961,10 +973,10 @@ REGISTER_NATIVES(consoleNatives) {"SetConVarString", sm_SetConVarString}, {"GetConVarFlags", sm_GetConVarFlags}, {"SetConVarFlags", sm_SetConVarFlags}, + {"ResetConVar", sm_ResetConVar}, {"GetConVarName", sm_GetConVarName}, {"GetConVarBounds", sm_GetConVarBounds}, {"SetConVarBounds", sm_SetConVarBounds}, - {"ResetConVar", sm_ResetConVar}, {"QueryClientConVar", sm_QueryClientConVar}, {"RegServerCmd", sm_RegServerCmd}, {"RegConsoleCmd", sm_RegConsoleCmd}, diff --git a/plugins/include/console.inc b/plugins/include/console.inc index a92c2430..e779f3b5 100644 --- a/plugins/include/console.inc +++ b/plugins/include/console.inc @@ -468,6 +468,20 @@ native GetConVarString(Handle:convar, String:value[], maxlength); */ native SetConVarString(Handle:convar, const String:value[], bool:replicate=false, bool:notify=false); +/** + * Resets the console variable to its default value. + * + * @param convar Handle to the convar. + * @param replicate If set to true, the new convar value will be set on all clients. + * This will only work if the convar has the FCVAR_REPLICATED flag + * and actually exists on clients. + * @param notify If set to true, clients will be notified that the convar has changed. + * This will only work if the convar has the FCVAR_NOTIFY flag. + * @noreturn + * @error Invalid or corrupt Handle. + */ +native ResetConVar(Handle:convar, bool:replicate=false, bool:notify=false); + /** * Returns the bitstring of flags on a console variable. * @@ -521,15 +535,6 @@ native SetConVarBounds(Handle:convar, ConVarBounds:type, bool:set, Float:value=0 */ native GetConVarName(Handle:convar, const String:name[], maxlength); -/** - * Resets the console variable to its default value. - * - * @param convar Handle to the convar. - * @noreturn - * @error Invalid or corrupt Handle. - */ -native ResetConVar(Handle:convar); - funcenum ConVarQueryFinished { /**