1234567891011121314151617181920212223242526272829303132333435 |
- #include <iostream>
- #include "server/commands/CommandManager.h"
- #include "server/commands/CommandUtils.h"
- #include "server/commands/GeneralCommands.h"
- CommandManager::CommandManager()
- {
- registerCommand("test", GeneralCommands::test);
- registerCommand("stop", GeneralCommands::stop);
- }
- void CommandManager::registerCommand(const std::string& name, void (*command) (IGameServer& gs, ICommandSource&, const std::vector<std::string>&))
- {
- commands[name] = command;
- }
- void CommandManager::execute(IGameServer& gs, ICommandSource& cs, const std::string& rawCommand) const
- {
- std::vector<std::string> args;
-
- std::string command;
- if(CommandUtils::splitString(rawCommand, command, args))
- {
- std::cout << "Invalid command syntax: '" << rawCommand << "'" << std::endl;
- return;
- }
- if(commands.find(command) == commands.end())
- {
- std::cout << "Unknown command: '" << command << "'" << std::endl;
- return;
- }
- commands.begin()->second(gs, cs, args);
- }
|