123456789101112131415161718192021222324252627282930313233343536 |
- #include <iostream>
- #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, void (*command) (IGameServer& gs, ICommandSource&, const std::vector<std::string>&))
- {
- commands[name] = command;
- }
- void CommandManager::execute(IGameServer& gs, ICommandSource& cs, const std::string& rawCommand) const
- {
- std::vector<std::string> args;
-
- std::string command;
- if(CommandUtils::splitString(rawCommand, command, args))
- {
- std::cout << "Invalid command syntax: '" << rawCommand << "'" << std::endl;
- return;
- }
- const std::unordered_map<std::string, Command>::const_iterator& iter = commands.find(command);
- if(iter == commands.end())
- {
- std::cout << "Unknown command: '" << command << "'" << std::endl;
- return;
- }
- iter->second(gs, cs, args);
- }
|