VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::CommandManager Class Reference

Typed commands for chat and the server console. More...

#include <CommandManager.hpp>

Public Member Functions

 CommandManager (Policy &policy, Translations &translations, PlayerManager &players, EntitySystem &entities, Messages &messages, IPluginContext &host)
 ~CommandManager ()
 CommandManager (const CommandManager &)=delete
CommandManager & operator= (const CommandManager &)=delete
CommandBuilder Add (std::string_view name)
bool HandleChatMessage (Player *caller, std::string_view message)
bool IsForeign (std::string_view message) const
size_t Count () const
void RemoveAll ()

Detailed Description

Typed commands for chat and the server console.

The handler's parameters are the argument spec; dispatch authorizes, binds and replies:

commands.Add("slap")
.Permission("admin.control")
.Run([&](Caller c, Args::Target t, Args::Opt<Args::Int> damage) {
return c.Ok("cmd.slapped", {{"name", t->Name()}});
});
std::string Name() const
Definition Player.cpp:22
Who invoked the command, and how to answer them.
Result< Reply > Ok(std::string_view key, Tokens tokens={}) const

Commands live until the plugin unloads; the framework removes them before the plugin's state. PlayersOnly(), PlayersAndServer() and ServerOnly() also register a console command (see Commands).

Definition at line 37 of file CommandManager.hpp.

Constructor & Destructor Documentation

◆ CommandManager() [1/2]

VoltMod::CommandManager::CommandManager ( Policy & policy,
Translations & translations,
PlayerManager & players,
EntitySystem & entities,
Messages & messages,
IPluginContext & host )

Every argument must outlive the manager. Command names are shared with the other plugins on host.

Definition at line 16 of file CommandManager.cpp.

Referenced by CommandManager(), and operator=().

◆ ~CommandManager()

VoltMod::CommandManager::~CommandManager ( )
default

◆ CommandManager() [2/2]

VoltMod::CommandManager::CommandManager ( const CommandManager & )
delete

References CommandManager().

Member Function Documentation

◆ Add()

CommandBuilder VoltMod::CommandManager::Add ( std::string_view name)

Start a command; .Run(handler) installs it.

Definition at line 29 of file CommandManager.cpp.

References VoltMod::CommandDefinition::Access, and VoltMod::Chat.

◆ Count()

size_t VoltMod::CommandManager::Count ( ) const

Definition at line 148 of file CommandManager.cpp.

◆ HandleChatMessage()

bool VoltMod::CommandManager::HandleChatMessage ( Player * caller,
std::string_view message )

Run message when it is a ! command. Framework only.

Returns
true when it was one, so chat hides the line.

Definition at line 103 of file CommandManager.cpp.

References VoltMod::CommandDefinition::Access, VoltMod::Chat, VoltMod::ServerOnly, VoltMod::Player::Slot(), VoltMod::CommandSyntax::StripPrefix(), and VoltMod::CommandSyntax::Tokenize().

◆ IsForeign()

bool VoltMod::CommandManager::IsForeign ( std::string_view message) const

True when message is another plugin's command, which chat must pass on unfiltered.

Definition at line 136 of file CommandManager.cpp.

References VoltMod::CommandSyntax::StripPrefix(), and VoltMod::CommandSyntax::Tokenize().

◆ operator=()

CommandManager & VoltMod::CommandManager::operator= ( const CommandManager & )
delete

References CommandManager().

◆ RemoveAll()

void VoltMod::CommandManager::RemoveAll ( )

Remove every command. Framework only, on unload.

Definition at line 42 of file CommandManager.cpp.


The documentation for this class was generated from the following files: