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

Bookkeeping for ClientConVars: per-slot, cookie-keyed queries awaiting an answer. More...

#include <PendingConVarQueries.hpp>

Public Member Functions

void Prune (int slot, double now)
 
PendingConVarQuery * Find (int slot, std::string_view name)
 
bool Full (int slot) const
 
int NextCookie (int slot)
 
void Add (int slot, int cookie, std::string name, ClientConVars::QueryCallback callback, double now)
 
std::optional< PendingConVarQuery > Take (int slot, int cookie, std::string_view name)
 
void Clear (int slot)
 
void ClearAll ()
 
size_t Count (int slot) const
 

Static Public Attributes

static constexpr size_t MaxPendingPerSlot = 11
 
static constexpr double TimeoutSec = 10.0
 
static constexpr uint32_t MaxCookie = 0x7FFFFFFF
 

Detailed Description

Bookkeeping for ClientConVars: per-slot, cookie-keyed queries awaiting an answer.

Split out of the service so the matching and expiry rules are testable without the SDK. Time is caller-supplied (seconds, any monotonic origin) and expiry is lazy: nothing is dropped until the next Prune() for that slot, which the service runs on every Query().

A client need never answer, so the table is capped per slot - beyond MaxPendingPerSlot, queries are refused rather than queued behind a silent client.

Definition at line 34 of file PendingConVarQueries.hpp.

Member Function Documentation

◆ Add()

void VoltMod::PendingConVarQueries::Add ( int  slot,
int  cookie,
std::string  name,
ClientConVars::QueryCallback  callback,
double  now 
)

Track a query sent with a cookie from NextCookie.

Definition at line 63 of file PendingConVarQueries.cpp.

References VoltMod::IsValidSlot(), and VoltMod::ReadFile().

◆ Clear()

void VoltMod::PendingConVarQueries::Clear ( int  slot)

Definition at line 95 of file PendingConVarQueries.cpp.

References VoltMod::IsValidSlot(), and VoltMod::ReadFile().

◆ ClearAll()

void VoltMod::PendingConVarQueries::ClearAll ( )

Definition at line 103 of file PendingConVarQueries.cpp.

References VoltMod::ReadFile().

◆ Count()

size_t VoltMod::PendingConVarQueries::Count ( int  slot) const

Definition at line 111 of file PendingConVarQueries.cpp.

References VoltMod::IsValidSlot(), and VoltMod::ReadFile().

Referenced by Full().

◆ Find()

PendingConVarQuery * VoltMod::PendingConVarQueries::Find ( int  slot,
std::string_view  name 
)

The query for name already in flight on slot, or null.

Definition at line 20 of file PendingConVarQueries.cpp.

References VoltMod::IsValidSlot(), VoltMod::PendingConVarQuery::Name, and VoltMod::ReadFile().

◆ Full()

bool VoltMod::PendingConVarQueries::Full ( int  slot) const

True when slot has no room for another query.

Definition at line 32 of file PendingConVarQueries.cpp.

References Count(), MaxPendingPerSlot, and VoltMod::ReadFile().

◆ NextCookie()

int VoltMod::PendingConVarQueries::NextCookie ( int  slot)

Next cookie unused on slot, or -1 when none could be found. Cookies increase monotonically and wrap back to 1 at MaxCookie.

Definition at line 37 of file PendingConVarQueries.cpp.

References VoltMod::IsValidSlot(), MaxCookie, MaxPendingPerSlot, and VoltMod::ReadFile().

◆ Prune()

void VoltMod::PendingConVarQueries::Prune ( int  slot,
double  now 
)

Drop slot's queries older than TimeoutSec. Their callbacks never fire.

Definition at line 9 of file PendingConVarQueries.cpp.

References VoltMod::IsValidSlot(), VoltMod::ReadFile(), and TimeoutSec.

◆ Take()

std::optional< PendingConVarQuery > VoltMod::PendingConVarQueries::Take ( int  slot,
int  cookie,
std::string_view  name 
)

Remove and return slot's query cookie, but only when name matches the convar it asked for: a client answering with a different name is answering a question nobody posed.

Definition at line 75 of file PendingConVarQueries.cpp.

References VoltMod::IsValidSlot(), and VoltMod::ReadFile().

Member Data Documentation

◆ MaxCookie

constexpr uint32_t VoltMod::PendingConVarQueries::MaxCookie = 0x7FFFFFFF
staticconstexpr

Largest cookie handed out; the protobuf field is an int32.

Definition at line 44 of file PendingConVarQueries.hpp.

Referenced by NextCookie().

◆ MaxPendingPerSlot

constexpr size_t VoltMod::PendingConVarQueries::MaxPendingPerSlot = 11
staticconstexpr

Outstanding queries allowed per slot before Query() starts refusing.

Definition at line 38 of file PendingConVarQueries.hpp.

Referenced by Full(), and NextCookie().

◆ TimeoutSec

constexpr double VoltMod::PendingConVarQueries::TimeoutSec = 10.0
staticconstexpr

Age at which an unanswered query is dropped, in seconds.

Definition at line 41 of file PendingConVarQueries.hpp.

Referenced by Prune().


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