CommandManager.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <iostream>
  2. #include "server/commands/CommandManager.h"
  3. static void commandTest(ServerCommands&, const SplitString& args) {
  4. std::cout << "test command" << std::endl;
  5. for(size_t i = 0; i < args.getLength(); i++) {
  6. std::cout << " - " << args[i] << std::endl;
  7. }
  8. }
  9. static void commandStop(ServerCommands& sc, const SplitString&) {
  10. sc.stop();
  11. }
  12. static void commandEmpty(ServerCommands&, const SplitString&) {
  13. }
  14. CommandManager::CommandManager() : commands("", commandEmpty) {
  15. commands.add("test", commandTest);
  16. commands.add("stop", commandStop);
  17. }
  18. void CommandManager::execute(ServerCommands& sc, const String& rawCommand) {
  19. SplitString args(rawCommand);
  20. if(args.getLength() == 0) {
  21. std::cout << "Invalid command syntax: '" << rawCommand << "'\n";
  22. return;
  23. }
  24. HashedString command(args[0]);
  25. Command c = commands.search(command);
  26. if(c == commandEmpty) {
  27. std::cout << "Unknown command: '" << command << "'" << std::endl;
  28. return;
  29. }
  30. c(sc, args);
  31. }