MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / tryExecuteServerCommand

Method tryExecuteServerCommand

source/modes/ConsoleInterface.cpp:92–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92Command::Result ConsoleInterface::tryExecuteServerCommand(const std::vector<std::string>& args, GameMap& gameMap)
93{
94 if(args.empty())
95 {
96 print("Invalid empty command");
97 return Command::Result::INVALID_ARGUMENT;
98 }
99 const std::string& commandName = args[0];
100 auto it = mCommandMap.find(commandName);
101 if(it != mCommandMap.end())
102 {
103 // Check if there is something to do on client side
104 try
105 {
106 Command::Result result = Command::Result::SUCCESS;
107 result = it->second->executeServer(args, *this, gameMap);
108
109 return result;
110 }
111 catch(const std::invalid_argument& e)
112 {
113 print(std::string("Invalid argument: ") + e.what());
114 return Command::Result::INVALID_ARGUMENT;
115 }
116 catch(const std::out_of_range& e)
117 {
118 print(std::string("Argument out of range") + e.what());
119 return Command::Result::INVALID_ARGUMENT;
120 }
121 }
122 else
123 {
124 print("Unknown command: \"" + commandName + "\"");
125 return Command::Result::NOT_FOUND;
126 }
127}
128
129bool ConsoleInterface::tryCompleteCommand(const String_t& prefix, String_t& completedCmd)
130{

Callers 1

handleConsoleCommandMethod · 0.80

Calls 1

executeServerMethod · 0.80

Tested by

no test coverage detected