| 76 | } |
| 77 | |
| 78 | StringList 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 | |
| 119 | bool ClientCommandProcessor::debugDisplayEnabled() const { |
| 120 | return m_debugDisplayEnabled; |
no test coverage detected