12345678910111213141516171819202122232425262728293031323334353637 |
- #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);
- }
- CommandManager::~CommandManager()
- {
- }
- void CommandManager::registerCommand(const string& name, void (*command) (IGameServer& gs, ICommandSource&, vector<string>&))
- {
- commands[name] = command;
- }
- void CommandManager::execute(IGameServer& gs, ICommandSource& cs, const string& rawCommand) const
- {
- vector<string> args;
-
- string command;
- if(CommandUtils::splitString(rawCommand, command, args))
- {
- cout << "Invalid command syntax: '" << rawCommand << "'" << endl;
- return;
- }
- if(commands.find(command) == commands.end())
- {
- cout << "Unknown command: '" << command << "'" << endl;
- return;
- }
- commands.begin()->second(gs, cs, args);
- }
|