From 471da79fa5d2e5eb3f42acb778bda70e69a2f82e Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 8 Feb 2007 20:37:24 +0000 Subject: [PATCH] added a wrapper for getclientconvarvalue fixed a bug in the player manager --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40462 --- core/CPlayerManager.cpp | 2 +- core/smn_player.cpp | 27 +++++++++++++++++++++++++++ plugins/include/sourcemod.inc | 11 +++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/core/CPlayerManager.cpp b/core/CPlayerManager.cpp index eb23cd26..53e240b6 100644 --- a/core/CPlayerManager.cpp +++ b/core/CPlayerManager.cpp @@ -350,7 +350,7 @@ int CPlayerManager::GetMaxClients() CPlayer *CPlayerManager::GetPlayerByIndex(int client) const { - if (client > m_maxClients || client < 0) + if (client > m_maxClients || client < 1) { return NULL; } diff --git a/core/smn_player.cpp b/core/smn_player.cpp index 76ef0750..804a0a17 100644 --- a/core/smn_player.cpp +++ b/core/smn_player.cpp @@ -175,6 +175,32 @@ static cell_t sm_PrintToServer(IPluginContext *pCtx, const cell_t *params) return 1; } +static cell_t sm_GetClientInfo(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Invalid client index %d.", client); + } + if (!pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client %d is not connected.", client); + } + + char *key; + pContext->LocalToString(params[2], &key); + + const char *val = engine->GetClientConVarValue(client, key); + if (!val) + { + return false; + } + + pContext->StringToLocalUTF8(params[3], params[4], val, NULL); + return 1; +} + static cell_t sm_PrintToConsole(IPluginContext *pCtx, const cell_t *params) { int index = params[1]; @@ -217,6 +243,7 @@ REGISTER_NATIVES(playernatives) {"IsPlayerFakeClient", sm_IsPlayerFakeClient}, {"PrintToServer", sm_PrintToServer}, {"PrintToConsole", sm_PrintToConsole}, + {"GetClientInfo", sm_GetClientInfo}, {NULL, NULL} }; diff --git a/plugins/include/sourcemod.inc b/plugins/include/sourcemod.inc index 21fcd148..3aa2a633 100644 --- a/plugins/include/sourcemod.inc +++ b/plugins/include/sourcemod.inc @@ -226,6 +226,17 @@ native bool:IsPlayerAuthorized(client); */ native bool:IsPlayerFakeClient(client); +/** + * Retrieves values from client replicated keys. + * + * @param client Player's index. + * @param key Key string. + * @param value Buffer to store value. + * @param maxlen Maximum length of valve (UTF-8 safe). + * @return True on success, false otherwise. + */ +native bool:GetClientInfo(client, const String:key[], String:value[], maxlen); + /** * Sends a message to the server console. *