1234567891011121314151617181920212223242526272829303132333435363738 |
- #include <iostream>
- #include "server/commands/CommandManager.h"
- static void commandTest(ServerCommands&, const SplitString& args) {
- std::cout << "test command" << std::endl;
- for(size_t i = 0; i < args.getLength(); i++) {
- std::cout << " - " << args[i] << std::endl;
- }
- }
- static void commandStop(ServerCommands& sc, const SplitString&) {
- sc.stop();
- }
- static void commandEmpty(ServerCommands&, const SplitString&) {
- }
- CommandManager::CommandManager() : commands("", commandEmpty) {
- commands.add("test", commandTest);
- commands.add("stop", commandStop);
- }
- void CommandManager::execute(ServerCommands& sc, const String& rawCommand) {
- SplitString args(rawCommand);
- if(args.getLength() == 0) {
- std::cout << "Invalid command syntax: '" << rawCommand << "'\n";
- return;
- }
- HashedString command(args[0]);
- Command c = commands.search(command);
- if(c == commandEmpty) {
- std::cout << "Unknown command: '" << command << "'" << std::endl;
- return;
- }
- c(sc, args);
- }
|