MCPcopy Create free account
hub / github.com/TurningWheel/Barony / consoleCommand

Function consoleCommand

src/interface/consolecommand.cpp:200–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

198-------------------------------------------------------------------------------*/
199
200void consoleCommand(char const* const command_str)
201{
202 if (!command_str || command_str[0] == '\0')
203 {
204 return;
205 }
206
207 char buf[1024];
208 size_t size = strlen(command_str);
209 size = std::min(size, sizeof(buf) - 1);
210 memcpy(buf, command_str, size);
211 buf[size] = '\0';
212
213 std::vector<const char*> tokens;
214 auto token = strtok(buf, " ");
215 auto command = token;
216 while (token)
217 {
218 tokens.push_back(token);
219 token = strtok(nullptr, " ");
220 }
221
222 auto& map = getConsoleCommands();
223 auto find = map.find(command);
224 if (find == map.end())
225 {
226 // invalid command
227 if (intro || !initialized)
228 {
229 printlog("Unknown command: '%s'\n", command_str);
230 }
231 else
232 {
233 messagePlayer(clientnum, MESSAGE_MISC, Language::get(305), command_str);
234 }
235 }
236 else
237 {
238 auto& ccmd = find->second;
239 ccmd(tokens.size(), tokens.data());
240 }
241}
242
243const char* FindConsoleCommand(const char* str, int index) {
244 if (!str || str[0] == '\0') {

Callers 10

actDeathGhostFunction · 0.85
playerDebugTestsFunction · 0.85
actPlayerFunction · 0.85
showConsoleCommandsMethod · 0.85
unloadModsMethod · 0.85
loadModsMethod · 0.85
doConsoleCommandsFunction · 0.85
consolecommand.cppFile · 0.85
loadConfigFunction · 0.85

Calls 4

printlogFunction · 0.85
messagePlayerFunction · 0.50
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected