From e30f612a2194df22dd6cae482607b19d8b306597 Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Mon, 21 Jan 2008 02:01:22 +0000 Subject: [PATCH] Added new native SendConVarValue for networking fake convar values to individual clients --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401858 --- core/smn_console.cpp | 47 +++++++++++++++++++++++++++++++++++++ plugins/include/console.inc | 11 +++++++++ 2 files changed, 58 insertions(+) diff --git a/core/smn_console.cpp b/core/smn_console.cpp index fe4ace2b..e2be7a50 100644 --- a/core/smn_console.cpp +++ b/core/smn_console.cpp @@ -1196,6 +1196,52 @@ static cell_t FindNextConCommand(IPluginContext *pContext, const cell_t *params) return 1; } +static cell_t SendConVarValue(IPluginContext *pContext, const cell_t *params) +{ + Handle_t hndl = static_cast(params[2]); + HandleError err; + ConVar *pConVar; + + char *value; + pContext->LocalToString(params[3], &value); + + if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar)) + != HandleError_None) + { + return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err); + } + + char data[256]; + bf_write buffer(data, sizeof(data)); + + buffer.WriteUBitLong(NET_SETCONVAR, 5); + buffer.WriteByte(1); + buffer.WriteString(pConVar->GetName()); + buffer.WriteString(value); + + CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]); + + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", params[1]); + } + + if (!pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client %d is not connected", params[1]); + } + + if (pPlayer->IsFakeClient()) + { + return pContext->ThrowNativeError("Client %d is fake and cannot be targeted", params[1]); + } + + INetChannel *netchan = static_cast(engine->GetPlayerNetInfo(params[1])); + netchan->SendData(buffer); + + return 1; +} + REGISTER_NATIVES(consoleNatives) { {"CreateConVar", sm_CreateConVar}, @@ -1242,5 +1288,6 @@ REGISTER_NATIVES(consoleNatives) {"GetCommandFlags", GetCommandFlags}, {"FindFirstConCommand", FindFirstConCommand}, {"FindNextConCommand", FindNextConCommand}, + {"SendConVarValue", SendConVarValue}, {NULL, NULL} }; diff --git a/plugins/include/console.inc b/plugins/include/console.inc index 6869bdbd..d866d5bd 100644 --- a/plugins/include/console.inc +++ b/plugins/include/console.inc @@ -754,3 +754,14 @@ native Handle:FindFirstConCommand(String:buffer[], max_size, &bool:isCommand, &f * contents of outputs is undefined. */ native bool:FindNextConCommand(Handle:search, String:buffer[], max_size, &bool:isCommand, &flags=0); + +/** + * Replicates a convar value to a specific client. This does not change the actual convar value. + * + * @param client Client index + * @param convar ConVar handle + * @param value String value to send + * @return True on success, false on failure + * @error Invalid client index, client not in game, or client is fake + */ +native bool:SendConVarValue(client, Handle:convar, const String:value[]);