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
17namespace server {
18
34 public:
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
Central command dispatcher.
const std::vector< std::shared_ptr< ICommand > > & getCommands() const
Get all registered commands.
void registerCommand(std::shared_ptr< ICommand > command)
Register a command.
std::string handleCommand(const std::string &message, const CommandContext &context)
Handle a command message.
std::pair< std::string, std::vector< std::string > > parseCommand(const std::string &message)
Parse command message into name and arguments.
std::vector< std::shared_ptr< ICommand > > _commandList
static bool isCommand(const std::string &message)
Check if a message is a command.
std::unordered_map< std::string, std::shared_ptr< ICommand > > _commands
Context information for command execution.