VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
ServerCommand.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <functional>
5#include <memory>
6#include <string_view>
7
8namespace VoltMod
9{
10
11/**
12 * @brief RAII server console command: registers a tier1 ConCommand on construction and
13 * unregisters on destruction.
14 *
15 * Use this for server-console, RCON, cfg, and loosely coupled automation surfaces. Invoke
16 * commands through @ref ConVars::ExecuteServerCommand. Prefer ServiceExchange
17 * when two plugins need a typed, versioned contract.
18 *
19 * The handler runs on the game thread. Construct only while the plugin is loaded (ICvar must be
20 * live); typically a manager member, so destruction on unload unregisters it.
21 */
23{
24public:
25 /** @p slot is the player who typed it in their own console, or -1 for the server. */
26 using Handler = std::function<void(const CCommand& args, int slot)>;
27
28 /** Runs for the server console, RCON and cfg files; with @p playersCanRun, also from a
29 * player's own console. Otherwise the engine refuses a player before the handler runs. */
30 ServerCommand(std::string_view name, std::string_view helpText, Handler handler, bool playersCanRun = false);
32 ServerCommand(const ServerCommand&) = delete;
34
35private:
36 struct Impl; // tier1's ConCommand, kept out of this header
37 std::unique_ptr<Impl> _impl;
38};
39
40} // namespace VoltMod
RAII server console command: registers a tier1 ConCommand on construction and unregisters on destruct...
ServerCommand(const ServerCommand &)=delete
std::function< void(const CCommand &args, int slot)> Handler
ServerCommand & operator=(const ServerCommand &)=delete
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56