diff --git a/core/smn_console.cpp b/core/smn_console.cpp index e89ae1c2..a3fca79b 100644 --- a/core/smn_console.cpp +++ b/core/smn_console.cpp @@ -22,6 +22,10 @@ #include "sm_stringutil.h" #include "PlayerManager.h" #include "ChatTriggers.h" +#include +#include + +#define NET_SETCONVAR 5 enum ConVarBounds { @@ -29,6 +33,44 @@ enum ConVarBounds ConVarBound_Lower }; +static void ReplicateConVar(ConVar *pConVar) +{ + int maxClients = g_Players.GetMaxClients(); + + char data[256]; + bf_write buffer(data, sizeof(data)); + + buffer.WriteUBitLong(NET_SETCONVAR, 5); + buffer.WriteByte(1); + buffer.WriteString(pConVar->GetName()); + buffer.WriteString(pConVar->GetString()); + + for (int i = 1; i <= maxClients; i++) + { + CPlayer *pPlayer = g_Players.GetPlayerByIndex(i); + + if (pPlayer && pPlayer->IsInGame() && !pPlayer->IsFakeClient()) + { + INetChannel *netchan = static_cast(engine->GetPlayerNetInfo(i)); + netchan->SendData(buffer); + } + } +} + +static void NotifyConVar(ConVar *pConVar) +{ + IGameEvent *pEvent = gameevents->CreateEvent("server_cvar"); + pEvent->SetString("cvarname", pConVar->GetName()); + if (pConVar->IsBitSet(FCVAR_PROTECTED)) + { + pEvent->SetString("cvarvalue", "***PROTECTED***"); + } else { + pEvent->SetString("cvarvalue", pConVar->GetString()); + } + + gameevents->FireEvent(pEvent); +} + static cell_t sm_CreateConVar(IPluginContext *pContext, const cell_t *params) { char *name, *defaultVal, *helpText; @@ -161,6 +203,18 @@ static cell_t sm_SetConVarNum(IPluginContext *pContext, const cell_t *params) pConVar->SetValue(params[2]); + /* Should we replicate it? */ + if (params[3] && pConVar->IsBitSet(FCVAR_REPLICATED)) + { + ReplicateConVar(pConVar); + } + + /* Should we notify clients? */ + if (params[4] && pConVar->IsBitSet(FCVAR_NOTIFY)) + { + NotifyConVar(pConVar); + } + return 1; } @@ -196,6 +250,18 @@ static cell_t sm_SetConVarFloat(IPluginContext *pContext, const cell_t *params) float value = sp_ctof(params[2]); pConVar->SetValue(value); + /* Should we replicate it? */ + if (params[3] && pConVar->IsBitSet(FCVAR_REPLICATED)) + { + ReplicateConVar(pConVar); + } + + /* Should we notify clients? */ + if (params[4] && pConVar->IsBitSet(FCVAR_NOTIFY)) + { + NotifyConVar(pConVar); + } + return 1; } @@ -233,6 +299,18 @@ static cell_t sm_SetConVarString(IPluginContext *pContext, const cell_t *params) pConVar->SetValue(value); + /* Should we replicate it? */ + if (params[3] && pConVar->IsBitSet(FCVAR_REPLICATED)) + { + ReplicateConVar(pConVar); + } + + /* Should we notify clients? */ + if (params[4] && pConVar->IsBitSet(FCVAR_NOTIFY)) + { + NotifyConVar(pConVar); + } + return 1; } diff --git a/plugins/include/console.inc b/plugins/include/console.inc index d409d01c..141ef80f 100644 --- a/plugins/include/console.inc +++ b/plugins/include/console.inc @@ -360,10 +360,15 @@ native bool:GetConVarBool(Handle:convar); * * @param convar Handle to the convar. * @param value New boolean value. + * @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 SetConVarBool(Handle:convar, bool:value); +native SetConVarBool(Handle:convar, bool:value, bool:replicate=false, bool:notify=false); /** * Returns the integer value of a console variable. @@ -379,10 +384,15 @@ native GetConVarInt(Handle:convar); * * @param convar Handle to the convar. * @param value New integer value. + * @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 SetConVarInt(Handle:convar, value); +native SetConVarInt(Handle:convar, value, bool:replicate=false, bool:notify=false); /** * Returns the floating point value of a console variable. @@ -398,10 +408,15 @@ native Float:GetConVarFloat(Handle:convar); * * @param convar Handle to the convar. * @param value New floating point value. + * @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 SetConVarFloat(Handle:convar, Float:value); +native SetConVarFloat(Handle:convar, Float:value, bool:replicate=false, bool:notify=false); /** * Retrieves the string value of a console variable. @@ -419,10 +434,15 @@ native GetConVarString(Handle:convar, String:value[], maxlength); * * @param convar Handle to the convar. * @param value New string value. + * @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 SetConVarString(Handle:convar, const String:value[]); +native SetConVarString(Handle:convar, const String:value[], bool:replicate=false, bool:notify=false); /** * Returns the bitstring of flags on a console variable.