VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
ServerCommand.cpp
Go to the documentation of this file.
2#include <string>
3#include <tier1/convar.h>
4#include <utility>
5
6namespace VoltMod
7{
8
9struct ServerCommand::Impl final : ICommandCallback
10{
11 Impl(std::string_view name, std::string_view helpText, Handler handler, uint64 flags)
12 : _handler(std::move(handler)),
13 _name(name),
16 {}
17
19 {
20 if (_handler)
21 {
22 _handler(command, context.GetPlayerSlot().Get());
23 }
24 }
25
27 // ConCommand keeps these pointers rather than copying, so the strings have to outlive it -
28 // hence owned here, and declared above _command so they are destroyed after it.
29 std::string _name;
30 std::string _help;
31 ConCommand _command; // last member: unregisters (dtor) before the handler is destroyed
32};
33
34// Without FCVAR_CLIENT_CAN_EXECUTE the engine refuses the command from a client before any handler runs.
35ServerCommand::ServerCommand(std::string_view name, std::string_view helpText, Handler handler, bool playersCanRun)
37{}
38
40
41} // namespace VoltMod
std::function< void(const CCommand &args, int slot)> Handler
ServerCommand(std::string_view name, std::string_view helpText, Handler handler, bool playersCanRun=false)
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
void CommandCallback(const CCommandContext &context, const CCommand &command) override
Impl(std::string_view name, std::string_view helpText, Handler handler, uint64 flags)