123456789101112131415161718192021222324252627282930 |
- #include "server/commands/Commands.h"
- #include "server/commands/DefaultCommands.h"
- #include "server/commands/SnuviCommands.h"
- #include "utils/HashMap.h"
- static HashMap<Commands::Name, Commands::Command> commands;
- void Commands::init() {
- DefaultCommands::init();
- SnuviCommands::init();
- }
- void Commands::add(const Name& name, Command command) {
- commands.add(name, command);
- }
- void Commands::execute(const Raw& raw) {
- Arguments args(raw);
- if(args.getLength() == 0) {
- std::cout << "Invalid command syntax: '" << raw << "'\n";
- return;
- }
- Name command(args[0]);
- Command* c = commands.search(command);
- if(c == nullptr) {
- SnuviCommands::callEvent(args);
- return;
- }
- (*c)(args);
- }
|