CommandManager.cpp 1017 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <iostream>
  2. #include "server/commands/CommandManager.h"
  3. #include "server/commands/CommandUtils.h"
  4. #include "server/commands/GeneralCommands.h"
  5. CommandManager::CommandManager()
  6. {
  7. registerCommand("test", GeneralCommands::test);
  8. registerCommand("stop", GeneralCommands::stop);
  9. }
  10. void CommandManager::registerCommand(const std::string& name, void (*command) (IGameServer& gs, ICommandSource&, const std::vector<std::string>&))
  11. {
  12. commands[name] = command;
  13. }
  14. void CommandManager::execute(IGameServer& gs, ICommandSource& cs, const std::string& rawCommand) const
  15. {
  16. std::vector<std::string> args;
  17. std::string command;
  18. if(CommandUtils::splitString(rawCommand, command, args))
  19. {
  20. std::cout << "Invalid command syntax: '" << rawCommand << "'" << std::endl;
  21. return;
  22. }
  23. if(commands.find(command) == commands.end())
  24. {
  25. std::cout << "Unknown command: '" << command << "'" << std::endl;
  26. return;
  27. }
  28. commands.begin()->second(gs, cs, args);
  29. }