Commands.cpp 842 B

123456789101112131415161718192021222324252627282930313233
  1. #include "server/commands/Commands.h"
  2. #include "server/commands/DefaultCommands.h"
  3. #include "server/commands/SnuviCommands.h"
  4. #include "utils/HashMap.h"
  5. #include "utils/Logger.h"
  6. static HashMap<Commands::Name, Commands::Command> commands;
  7. void Commands::init() {
  8. DefaultCommands::init();
  9. SnuviCommands::init();
  10. }
  11. void Commands::add(const Name& name, Command command) {
  12. commands.add(name, command);
  13. }
  14. void Commands::execute(const Raw& raw) {
  15. Arguments args(raw);
  16. if(args.getLength() == 0) {
  17. LOG_INFO(StringBuffer<100>("invalid command syntax: '")
  18. .append(raw)
  19. .append("'"));
  20. return;
  21. }
  22. Name command(args[0]);
  23. Command* c = commands.search(command);
  24. if(c == nullptr) {
  25. SnuviCommands::callEvent(args);
  26. return;
  27. }
  28. (*c)(args);
  29. }