VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::ClientConVars Class Reference

Asks a connected client what one of its own convars is set to. More...

#include <ClientConVars.hpp>

Public Types

using QueryCallback

Public Member Functions

 ClientConVars (Interfaces &interfaces, const Bindings &bindings, SlotEvents &slots)
 ~ClientConVars ()
 ClientConVars (const ClientConVars &)=delete
ClientConVars & operator= (const ClientConVars &)=delete
Status Available () const
bool Query (int slot, std::string_view cvarName, QueryCallback callback)
size_t PendingCount (int slot) const
void OnServerStartup ()

Detailed Description

Asks a connected client what one of its own convars is set to.

The server sends CSVCMsg_GetCvarValue with a cookie. The client answers later with CCLCMsg_RespondCvarValue, intercepted through a vtable hook on CServerSideClient. Queries are asynchronous, unordered, and may never complete.

A modified client can answer with anything, so treat the result as evidence, not proof.

This optional load step depends on an RTTI or symbol lookup of the CServerSideClient vtable. These values drift with engine updates. On failure Available carries the reason.

runtime.ClientConVars.Query(slot, "sensitivity",
[](int slot, ClientConVarStatus status, std::string_view name, std::string_view value) {
Log::Info("{} = {}", name, value);
});
void Info(std::format_string< Args... > fmt, Args &&... args)
Definition Log.hpp:79
ClientConVarStatus
How the client answered a convar query (CCLCMsg_RespondCvarValue::status_code).
@ Answered
The client reported the convar's current value.

Definition at line 47 of file ClientConVars.hpp.

Member Typedef Documentation

◆ QueryCallback

Initial value:
std::function<void(int slot, ClientConVarStatus status, std::string_view name, std::string_view value)>

Invoked on the game thread when the client answers. name and value borrow the decoded message, so copy what you keep. value is empty unless status is Answered.

Definition at line 54 of file ClientConVars.hpp.

Constructor & Destructor Documentation

◆ ClientConVars() [1/2]

VoltMod::ClientConVars::ClientConVars ( Interfaces & interfaces,
const Bindings & bindings,
SlotEvents & slots )

interfaces and bindings drive the response hook and the query send path. slots tells the service when a slot changes hands, so an answer can never reach the callback of whoever held the slot before. All three must outlive it; the Runtime declares them above. Installs the response hook; a failure leaves the service inert and names itself in Available.

Definition at line 28 of file ClientConVars.cpp.

References VoltMod::SlotEvents::Changed.

Referenced by ClientConVars(), and operator=().

◆ ~ClientConVars()

VoltMod::ClientConVars::~ClientConVars ( )
default

◆ ClientConVars() [2/2]

VoltMod::ClientConVars::ClientConVars ( const ClientConVars & )
delete

References ClientConVars().

Member Function Documentation

◆ Available()

Status VoltMod::ClientConVars::Available ( ) const

Why queries cannot be sent: the error the hook install returned.

Definition at line 42 of file ClientConVars.cpp.

◆ OnServerStartup()

void VoltMod::ClientConVars::OnServerStartup ( )

Definition at line 118 of file ClientConVars.cpp.

◆ operator=()

ClientConVars & VoltMod::ClientConVars::operator= ( const ClientConVars & )
delete

References ClientConVars().

◆ PendingCount()

size_t VoltMod::ClientConVars::PendingCount ( int slot) const

Number of queries awaiting an answer on slot. Diagnostics only.

Definition at line 113 of file ClientConVars.cpp.

◆ Query()

bool VoltMod::ClientConVars::Query ( int slot,
std::string_view cvarName,
QueryCallback callback )

Ask slot for its value of cvarName. False when the service is not Available, the slot holds a bot or nobody, the per-slot pending cap is reached, or the message could not be sent.

A convar already in flight for that slot re-targets the outstanding request rather than sending a second one, so polling cannot flood a client. Pending entries expire silently after 10 seconds.

Definition at line 81 of file ClientConVars.cpp.

References VoltMod::IsValidSlot(), and VoltMod::Time::MonotonicSeconds().


The documentation for this class was generated from the following files: