VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
NetChannel.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <optional>
6#include <string_view>
7
8namespace VoltMod
9{
10
11/** How the server is keeping up with one client's usercmds. */
13{
14 int LastExecuted = 0;
15 int LastReceived = 0;
16 /** Seconds between a usercmd arriving and its tick running; negative before the first one. */
17 float ReceiveMargin = -1.0f;
18 /** Ticks the client's command queue ran dry or overflowed; zero unless @ref HasQueueStats. */
19 int StarvedTicks = 0;
21 bool HasQueueStats = false;
22};
23
24/**
25 * @brief Per-client network access: latency, userids, usercmd status and the client's replicated
26 * userinfo cvars.
27 *
28 * Stateless wrapper over IVEngineServer2 and ISource2GameClients: every call reads the engine live,
29 * so nothing here needs a lifecycle. Bots, empty slots and clients already torn down have no channel, and each accessor
30 * degrades to a null/zero result rather than asserting.
31 */
33{
34public:
35 /** @p interfaces supplies IVEngineServer2; it must outlive this service. */
36 explicit NetChannels(Interfaces& interfaces) : _interfaces(interfaces) {}
37
38 /** The client's channel, or nullptr when @p slot has none (bot, empty, disconnecting). */
39 INetChannelInfo* GetNetInfo(int slot) const;
40
41 /** Whether @p slot holds a human client: false for a bot, an empty slot or one disconnecting. */
42 bool HasClient(int slot) const { return GetNetInfo(slot) != nullptr; }
43
44 /** Round-trip time in seconds, or 0 when the channel is unavailable. */
45 float EngineLatency(int slot) const;
46
47 /** The userid game events name the player by, or -1 when @p slot is empty. Bots have one too. */
48 int GetUserId(int slot) const;
49
50 /** How the server is keeping up with @p slot's usercmds, or empty when it has no player. A rising
51 * gap between received and executed, or starved and discarded ticks, is how fakelag shows. */
52 std::optional<CommandStatus> GetCommandStatus(int slot) const;
53
54 /**
55 * The client's value for the userinfo convar @p name, or empty when the slot has no client,
56 * the engine is unavailable, or the client never sent one.
57 *
58 * The view borrows the engine's own buffer, which the next userinfo update replaces: read it
59 * or copy it before returning to the engine, and never store it.
60 */
61 std::string_view GetUserInfoCvar(int slot, std::string_view name) const;
62
63private:
64 Interfaces& _interfaces;
65};
66
67} // namespace VoltMod
bool HasClient(int slot) const
std::optional< CommandStatus > GetCommandStatus(int slot) const
std::string_view GetUserInfoCvar(int slot, std::string_view name) const
NetChannels(Interfaces &interfaces)
float EngineLatency(int slot) const
INetChannelInfo * GetNetInfo(int slot) const
int GetUserId(int slot) const
Centralized holder for all SDK interface pointers.