VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
ServerCommand.cpp
Go to the documentation of this file.
1
#include <
VoltMod/Engine/Server/ServerCommand.hpp
>
2
#include <string>
3
#include <tier0/convar.h>
4
#include <utility>
5
6
namespace
VoltMod
7
{
8
9
struct
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),
14
_help
(helpText),
15
_command
(
_name
.c_str(), this,
_help
.c_str(), FCVAR_RELEASE | FCVAR_GAMEDLL | flags)
16
{}
17
18
void
CommandCallback
(
const
CCommandContext& context,
const
CCommand& command)
override
19
{
20
if
(
_handler
)
21
{
22
_handler
(command, context.GetPlayerSlot().Get());
23
}
24
}
25
26
Handler
_handler
;
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.
35
ServerCommand::ServerCommand
(std::string_view name, std::string_view helpText,
Handler
handler,
bool
playersCanRun)
36
: _impl(std::make_unique<
Impl
>(name, helpText, std::move(handler), playersCanRun ? FCVAR_CLIENT_CAN_EXECUTE : 0))
37
{}
38
39
ServerCommand::~ServerCommand
() =
default
;
40
41
}
// namespace VoltMod
ServerCommand.hpp
VoltMod::ServerCommand::Handler
std::function< void(const CCommand &args, int slot)> Handler
Definition
ServerCommand.hpp:26
VoltMod::ServerCommand::~ServerCommand
~ServerCommand()
VoltMod::ServerCommand::ServerCommand
ServerCommand(std::string_view name, std::string_view helpText, Handler handler, bool playersCanRun=false)
Definition
ServerCommand.cpp:35
VoltMod
Definition
Options.hpp:13
VoltMod::ServerCommand::Impl
Definition
ServerCommand.cpp:10
VoltMod::ServerCommand::Impl::_command
ConCommand _command
Definition
ServerCommand.cpp:31
VoltMod::ServerCommand::Impl::_name
std::string _name
Definition
ServerCommand.cpp:29
VoltMod::ServerCommand::Impl::CommandCallback
void CommandCallback(const CCommandContext &context, const CCommand &command) override
Definition
ServerCommand.cpp:18
VoltMod::ServerCommand::Impl::Impl
Impl(std::string_view name, std::string_view helpText, Handler handler, uint64 flags)
Definition
ServerCommand.cpp:11
VoltMod::ServerCommand::Impl::_handler
Handler _handler
Definition
ServerCommand.cpp:26
VoltMod::ServerCommand::Impl::_help
std::string _help
Definition
ServerCommand.cpp:30
src
Engine
Server
ServerCommand.cpp
Generated by
1.15.0