R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
CommandHandler.hpp
Go to the documentation of this file.
1
/*
2
** EPITECH PROJECT, 2025
3
** Created on 14/01/2026.
4
** File description:
5
** CommandHandler.hpp
6
*/
7
8
#pragma once
9
10
#include <memory>
11
#include <string>
12
#include <unordered_map>
13
#include <vector>
14
#include "
CommandContext.hpp
"
15
#include "
ICommand.hpp
"
16
17
namespace
server
{
18
33
class
CommandHandler
{
34
public
:
35
CommandHandler
();
36
~CommandHandler
() =
default
;
37
42
void
registerCommand
(std::shared_ptr<ICommand> command);
43
50
std::string
handleCommand
(
const
std::string &message,
const
CommandContext
&context);
51
57
static
bool
isCommand
(
const
std::string &message);
58
63
const
std::vector<std::shared_ptr<ICommand>> &
getCommands
()
const
{
return
_commandList
; }
64
65
private
:
71
std::pair<std::string, std::vector<std::string>>
parseCommand
(
const
std::string &message);
72
73
std::unordered_map<std::string, std::shared_ptr<ICommand>>
_commands
;
74
std::vector<std::shared_ptr<ICommand>>
_commandList
;
// For help command
75
};
76
77
}
// namespace server
CommandContext.hpp
ICommand.hpp
server::CommandHandler
Central command dispatcher.
Definition
CommandHandler.hpp:33
server::CommandHandler::CommandHandler
CommandHandler()
Definition
CommandHandler.cpp:21
server::CommandHandler::getCommands
const std::vector< std::shared_ptr< ICommand > > & getCommands() const
Get all registered commands.
Definition
CommandHandler.hpp:63
server::CommandHandler::registerCommand
void registerCommand(std::shared_ptr< ICommand > command)
Register a command.
Definition
CommandHandler.cpp:30
server::CommandHandler::~CommandHandler
~CommandHandler()=default
server::CommandHandler::handleCommand
std::string handleCommand(const std::string &message, const CommandContext &context)
Handle a command message.
Definition
CommandHandler.cpp:58
server::CommandHandler::parseCommand
std::pair< std::string, std::vector< std::string > > parseCommand(const std::string &message)
Parse command message into name and arguments.
Definition
CommandHandler.cpp:41
server::CommandHandler::_commandList
std::vector< std::shared_ptr< ICommand > > _commandList
Definition
CommandHandler.hpp:74
server::CommandHandler::isCommand
static bool isCommand(const std::string &message)
Check if a message is a command.
Definition
CommandHandler.cpp:37
server::CommandHandler::_commands
std::unordered_map< std::string, std::shared_ptr< ICommand > > _commands
Definition
CommandHandler.hpp:73
server
Definition
CommandContext.hpp:16
server::CommandContext
Context information for command execution.
Definition
CommandContext.hpp:28
server
Commands
CommandHandler.hpp
Generated by
1.9.8