| 325 | } |
| 326 | |
| 327 | String CommandProcessor::spawnItem(ConnectionId connectionId, String const& argumentString) { |
| 328 | if (auto errorMsg = adminCheck(connectionId, "spawn items")) |
| 329 | return *errorMsg; |
| 330 | |
| 331 | auto arguments = m_parser.tokenizeToStringList(argumentString); |
| 332 | |
| 333 | if (arguments.empty()) |
| 334 | return "Not enough arguments to /spawnitem"; |
| 335 | |
| 336 | try { |
| 337 | String kind = arguments.at(0); |
| 338 | Json parameters = JsonObject(); |
| 339 | unsigned amount = 1; |
| 340 | Maybe<float> level; |
| 341 | Maybe<uint64_t> seed; |
| 342 | |
| 343 | if (arguments.size() >= 2) |
| 344 | amount = lexicalCast<unsigned>(arguments.at(1)); |
| 345 | |
| 346 | if (arguments.size() >= 3) |
| 347 | parameters = Json::parse(arguments.at(2)); |
| 348 | |
| 349 | if (arguments.size() >= 4) |
| 350 | level = lexicalCast<float>(arguments.at(3)); |
| 351 | |
| 352 | if (arguments.size() >= 5) |
| 353 | seed = lexicalCast<uint64_t>(arguments.at(4)); |
| 354 | |
| 355 | bool done = m_universe->executeForClient(connectionId, [&](WorldServer* world, PlayerPtr const& player) { |
| 356 | auto itemDatabase = Root::singleton().itemDatabase(); |
| 357 | world->addEntity(ItemDrop::createRandomizedDrop(itemDatabase->item(ItemDescriptor(kind, amount, parameters), level, seed, true), player->aimPosition())); |
| 358 | }); |
| 359 | |
| 360 | return done ? "" : "Invalid client state"; |
| 361 | } catch (JsonParsingException const& exception) { |
| 362 | Logger::warn("Error while processing /spawnitem '{}' command. Json parse problem: {}", arguments.at(0), outputException(exception, false)); |
| 363 | return "Could not parse item parameters"; |
| 364 | } catch (ItemException const& exception) { |
| 365 | Logger::warn("Error while processing /spawnitem '{}' command. Item instantiation problem: {}", arguments.at(0), outputException(exception, false)); |
| 366 | return strf("Could not load item '{}'", arguments.at(0)); |
| 367 | } catch (BadLexicalCast const& exception) { |
| 368 | Logger::warn("Error while processing /spawnitem command. Number expected. Got something else: {}", outputException(exception, false)); |
| 369 | return strf("Could not load item '{}'", arguments.at(0)); |
| 370 | } catch (StarException const& exception) { |
| 371 | Logger::warn("Error while processing /spawnitem command '{}', exception caught: {}", argumentString, outputException(exception, false)); |
| 372 | return strf("Could not load item '{}'", arguments.at(0)); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | String CommandProcessor::spawnTreasure(ConnectionId connectionId, String const& argumentString) { |
| 377 | if (auto errorMsg = adminCheck(connectionId, "spawn items")) |
nothing calls this directly
no test coverage detected