CommandManager.cpp 975 B

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