MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / handleCommand

Method handleCommand

source/frontend/StarClientCommandProcessor.cpp:78–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78StringList ClientCommandProcessor::handleCommand(String const& commandLine, bool userInput) {
79 Maybe<Input::ClipboardUnlock> unlock;
80 if (userInput) // allow clipboard usage during this code
81 unlock = Input::singleton().unlockClipboard();
82 try {
83 if (!commandLine.beginsWith("/"))
84 throw StarException("ClientCommandProcessor expected command, does not start with '/'");
85
86 String allArguments = commandLine.substr(1);
87 String command = allArguments.extract();
88
89 StringList result;
90 if (auto builtinCommand = m_builtinCommands.maybe(command)) {
91 result.append((*builtinCommand)(allArguments));
92 } else if (auto macroCommand = m_macroCommands.maybe(command)) {
93 for (auto const& c : *macroCommand) {
94 if (c.beginsWith("/"))
95 result.appendAll(handleCommand(c));
96 else
97 result.append(c);
98 }
99 } else {
100 auto player = m_universeClient->mainPlayer();
101 if (auto messageResult = player->receiveMessage(connectionForEntity(player->entityId()), "/" + command, {allArguments})) {
102 if (messageResult->isType(Json::Type::String))
103 result.append(*messageResult->stringPtr());
104 else if (!messageResult->isNull())
105 result.append(messageResult->repr(1, true));
106 } else
107 m_universeClient->sendChat(commandLine, ChatSendMode::Broadcast);
108 }
109 return result;
110 } catch (ShellParsingException const& e) {
111 Logger::error("Shell parsing exception: {}", outputException(e, false));
112 return {"Shell parsing exception"};
113 } catch (std::exception const& e) {
114 Logger::error("Exception caught handling client command {}: {}", commandLine, outputException(e, true));
115 return {strf("Exception caught handling client command {}", commandLine)};
116 }
117}
118
119bool ClientCommandProcessor::debugDisplayEnabled() const {
120 return m_debugDisplayEnabled;

Callers 2

makeChatCallbacksMethod · 0.45
doChatMethod · 0.45

Calls 15

singletonClass · 0.85
StarExceptionClass · 0.85
connectionForEntityFunction · 0.85
errorFunction · 0.85
strfFunction · 0.85
unlockClipboardMethod · 0.80
extractMethod · 0.80
appendAllMethod · 0.80
mainPlayerMethod · 0.80
entityIdMethod · 0.80
sendChatMethod · 0.80
outputExceptionFunction · 0.50

Tested by

no test coverage detected