#include #include #include #include "server/commands/CommandManager.h" #include "server/commands/CommandUtils.h" static void commandTest(ServerCommands&, const std::vector& args) { std::cout << "test command" << std::endl; for(size_t i = 0; i < args.size(); i++) { std::cout << " - " << args[i] << std::endl; } } static void commandStop(ServerCommands& sc, const std::vector&) { sc.stop(); } typedef void (*Command) (ServerCommands&, const std::vector&); static std::unordered_map commands( { {"test", commandTest}, {"stop", commandStop} }); void CommandManager::execute(ServerCommands& sc, const std::string& rawCommand) { std::vector args; std::string command; if(CommandUtils::splitString(rawCommand, command, args)) { std::cout << "Invalid command syntax: '" << rawCommand << "'\n"; 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); }