AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Difference between QueryClientConVar and GetClientInfo (https://forums.alliedmods.net/showthread.php?t=320369)

ImACow 12-18-2019 11:47

Difference between QueryClientConVar and GetClientInfo
 
What is the difference between QueryClientConVar and GetClientInfo and?

I'm trying to understand the difference between the two, and possibly the underlying difference.



API QueryClientConVar
API GetClientInfo

Source for QueryClientConVar

PHP Code:

static cell_t sm_QueryClientConVar(IPluginContext *pContext, const cell_t *params)
{
    
CPlayer *pPlayer;
    
char *name;
    
IPluginFunction *pCallback;

    if (!
g_ConVarManager.IsQueryingSupported())
    {
        if (!
s_QueryAlreadyWarned)
        {
            
s_QueryAlreadyWarned true;
            return 
pContext->ThrowNativeError("Game does not support client convar querying (one time warning)");
        }

        return 
0;
    }

    
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]);
    }

    
/* Trying a query on a bot results in callback not be fired, so don't bother */
    
if (pPlayer->IsFakeClient())
    {
        return 
0;
    }

    
pContext->LocalToString(params[2], &name);
    
pCallback pContext->GetFunctionById(params[3]);

    if (!
pCallback)
    {
        return 
pContext->ThrowNativeError("Invalid function id (%X)"params[3]);
    }

    return 
g_ConVarManager.QueryClientConVar(pPlayer->GetEdict(), namepCallbackparams[4]);


Source for GetClientInfo

PHP Code:

static cell_t sm_GetClientInfo(IPluginContext *pContext, const cell_t *params)
{
    
int client params[1];
    
IGamePlayer *pPlayer playerhelpers->GetGamePlayer(client);
    if (!
pPlayer)
    {
        return 
pContext->ThrowNativeError("Client index %d is invalid"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(clientkey);
    if (!
val)
    {
        return 
false;
    }

    
pContext->StringToLocalUTF8(params[3], params[4], valNULL);
    return 
1;


QueryClientConVar calls QueryClientConVar with a callback
GetClientInfo calls GetClientConVarValue without callback

MAGNAT2645 12-18-2019 12:08

Re: Difference between QueryClientConVar and GetClientInfo
 
Maybe GetClientInfo works only with replicated (or with FCVAR_USERINFO flag) convars while QueryClientConVar allows you to check most client convars?

EDIT:
So, i think, better to use GetClientInfo for convars with FCVAR_USERINFO flag (ex. "cl_language", "cl_cmdrate" etc.)
and QueryClientConVar in every other case.

Also, i think QueryClientConVar uses callback because this function is delayed (like query to Database) and can return error.
while GetClientInfo can get prefetched (not sure 100%) values, so no callback needed.


All times are GMT -4. The time now is 13:11.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.