#include #include "server/commands/CommandManager.h" #include "server/commands/CommandUtils.h" #include "server/commands/GeneralCommands.h" CommandManager::CommandManager() { registerCommand("test", GeneralCommands::test); registerCommand("stop", GeneralCommands::stop); } void CommandManager::registerCommand(const std::string& name, Command command) { commands[name] = command; } void CommandManager::execute(ServerCommands& sc, const std::string& rawCommand) const { std::vector args; std::string command; if(CommandUtils::splitString(rawCommand, command, args)) { std::cout << "Invalid command syntax: '" << rawCommand << "'" << std::endl; return; } const std::unordered_map::const_iterator& iter = commands.find(command); if(iter == commands.end()) { std::cout << "Unknown command: '" << command << "'" << std::endl; return; } iter->second(sc, args); }