Added two new optional paramaters to SetConVar* natives for purpose of replicating convar value to client and/or notifying of convar change
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40942
This commit is contained in:
parent
4b613ac5d5
commit
28ae0b0d65
@ -22,6 +22,10 @@
|
||||
#include "sm_stringutil.h"
|
||||
#include "PlayerManager.h"
|
||||
#include "ChatTriggers.h"
|
||||
#include <inetchannel.h>
|
||||
#include <bitbuf.h>
|
||||
|
||||
#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<INetChannel *>(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;
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user