|
R-Type
Distributed multiplayer game engine in C++
|
Central command dispatcher. More...
#include <CommandHandler.hpp>

Public Member Functions | |
| CommandHandler () | |
| ~CommandHandler ()=default | |
| void | registerCommand (std::shared_ptr< ICommand > command) |
| Register a command. | |
| std::string | handleCommand (const std::string &message, const CommandContext &context) |
| Handle a command message. | |
| const std::vector< std::shared_ptr< ICommand > > & | getCommands () const |
| Get all registered commands. | |
Static Public Member Functions | |
| static bool | isCommand (const std::string &message) |
| Check if a message is a command. | |
Private Member Functions | |
| std::pair< std::string, std::vector< std::string > > | parseCommand (const std::string &message) |
| Parse command message into name and arguments. | |
Private Attributes | |
| std::unordered_map< std::string, std::shared_ptr< ICommand > > | _commands |
| std::vector< std::shared_ptr< ICommand > > | _commandList |
Central command dispatcher.
Manages command registration, parsing and execution. Follows the Command pattern with dependency injection.
Usage: CommandHandler handler; handler.registerCommand(std::make_shared<HelpCommand>()); handler.registerCommand(std::make_shared<KickCommand>());
std::string result = handler.handleCommand("/kick player1", context);
Definition at line 33 of file CommandHandler.hpp.
| server::CommandHandler::CommandHandler | ( | ) |
Definition at line 21 of file CommandHandler.cpp.
References _commandList, and registerCommand().

|
default |
|
inline |
Get all registered commands.
Definition at line 63 of file CommandHandler.hpp.
References _commandList.
| std::string server::CommandHandler::handleCommand | ( | const std::string & | message, |
| const CommandContext & | context | ||
| ) |
Handle a command message.
| message | Full message (including /) |
| context | Execution context |
Definition at line 58 of file CommandHandler.cpp.
References _commands, isCommand(), LOG_DEBUG, LOG_ERROR, parseCommand(), and server::CommandContext::playerId.

|
static |
Check if a message is a command.
| message | Message to check |
Definition at line 37 of file CommandHandler.cpp.
Referenced by handleCommand().
|
private |
Parse command message into name and arguments.
| message | Full command message |
Definition at line 41 of file CommandHandler.cpp.
Referenced by handleCommand().
| void server::CommandHandler::registerCommand | ( | std::shared_ptr< ICommand > | command | ) |
Register a command.
| command | Command instance to register |
Definition at line 30 of file CommandHandler.cpp.
References _commandList, _commands, and LOG_DEBUG.
Referenced by CommandHandler().
|
private |
Definition at line 74 of file CommandHandler.hpp.
Referenced by CommandHandler(), getCommands(), and registerCommand().
|
private |
Definition at line 73 of file CommandHandler.hpp.
Referenced by handleCommand(), and registerCommand().