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 = std::function< void(int slot, ClientConVarStatus status, std::string_view name, std::string_view value)>
 

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 the CServerSideClient::ProcessRespondCvarValue vtable slot, the CServerSideClientBase::m_nClientSlot offset, and 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
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
ClientConVarStatus
How the client answered a convar query (CCLCMsg_RespondCvarValue::status_code).
@ Answered
The client reported the convar's current value.

Definition at line 49 of file ClientConVars.hpp.

Member Typedef Documentation

◆ QueryCallback

using VoltMod::ClientConVars::QueryCallback = 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 56 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 29 of file ClientConVars.cpp.

References VoltMod::ReadFile().

◆ ~ClientConVars()

VoltMod::ClientConVars::~ClientConVars ( )
default

◆ ClientConVars() [2/2]

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

Member Function Documentation

◆ Available()

Status VoltMod::ClientConVars::Available ( ) const

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

Definition at line 43 of file ClientConVars.cpp.

◆ OnServerStartup()

void VoltMod::ClientConVars::OnServerStartup ( )

Definition at line 123 of file ClientConVars.cpp.

◆ operator=()

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

◆ PendingCount()

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

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

Definition at line 118 of file ClientConVars.cpp.

References VoltMod::ReadFile().

◆ 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 86 of file ClientConVars.cpp.

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

Referenced by VoltMod::Internal::ClientLanguage::ClientLanguage().


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