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")
return c.Ok("cmd.slapped", {{"name", t->Name()}});
});
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
Who invoked the command, and how to answer them.

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

Definition at line 36 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.

◆ ~CommandManager()

VoltMod::CommandManager::~CommandManager ( )
default

◆ CommandManager() [2/2]

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

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::Players, and VoltMod::ReadFile().

◆ Count()

size_t VoltMod::CommandManager::Count ( ) const

Definition at line 143 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 98 of file CommandManager.cpp.

References VoltMod::Chat, VoltMod::ReadFile(), VoltMod::ServerOnly, 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 131 of file CommandManager.cpp.

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

◆ operator=()

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

◆ 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: