9#include <engine/igameeventsystem.h>
12#include <networkbasetypes.pb.h>
13#include <networksystem/inetworkmessages.h>
14#include <networksystem/netmessage.h>
17#include <tier1/convar.h>
22static std::string_view
Text(
const char* value)
24 return value ? std::string_view(value) : std::string_view{};
28 const char* oldValue,
void* )
43 : Changed({.OnFirst = [
this] {
return RouteChanges(); }, .OnLast = [
this] { StopRoutingChanges(); }}),
55 if (!_interfaces.
CVar)
72 if (
command.find_first_of(
"\r\n") != std::string_view::npos)
74 Log::Warn(
"ConVars: refused a server command with an embedded newline.");
80 if (
line.empty() ||
line.back() !=
'\n')
93 return std::unexpected(
text.error());
99 const auto end =
rest.find(
'\n');
100 const std::string_view
raw =
rest.substr(0,
end);
101 rest =
end == std::string_view::npos ? std::string_view{} :
rest.substr(
end + 1);
121 return _setConVarMsg;
130 _setConVarMsg =
messages->FindNetworkMessagePartial(
"SetConVar");
133 Log::Warn(
"ConVars: CNETMsg_SetConVar not found; per-client convar overrides are unavailable.");
136 return _setConVarMsg;
139bool ConVars::SendToClient(
int slot, std::string_view name, std::string_view value)
146 auto*
msgType = SetConVarMessage();
162 cvar->set_name(std::string(name));
163 cvar->set_value(std::string(value));
173bool ConVars::RouteChanges()
183 Log::Warn(
"ConVars: ICvar is not resolved; convar change handlers will not fire.");
189 _routingChanges =
true;
193void ConVars::StopRoutingChanges()
195 if (!_routingChanges)
206 _routingChanges =
false;
static std::string_view Text(const char *value)
static void GlobalConVarChangeCallback(ConVarRefAbstract *ref, CSplitScreenSlot, const char *newValue, const char *oldValue, void *)
static VoltMod::ConVars * g_changeCallback
void SetByConsole(std::string_view name, std::string_view value)
Assign a convar over the console, quoting the value.
Status ExecuteFile(std::string_view path)
ConVars(Interfaces &interfaces)
Event< const ConVarChange & > Changed
void ExecuteServerCommand(std::string_view command)
static std::string Trim(std::string_view str)
static std::string QuoteConsoleArg(std::string_view value)
void Warn(std::format_string< Args... > fmt, Args &&... args)
static std::string ReadFile(const std::filesystem::path &path)
constexpr bool IsValidSlot(int slot)
Result< std::string > ReadAllText(std::string_view path)
Read path (resolved via ResolvePath) into a string.
std::expected< void, Error > Status
static Error NotReady(std::string detail)
Centralized holder for all HL2SDK interface pointers.
IGameEventSystem * GameEventSystem
INetworkMessages * NetworkMessages