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