| 498 | } |
| 499 | |
| 500 | bool NetworkService::replaceResource( |
| 501 | std::string const& resourceId, |
| 502 | IntVector2D const& worldSize, |
| 503 | int numParticles, |
| 504 | std::string const& mainData, |
| 505 | std::string const& settings, |
| 506 | std::string const& statistics) |
| 507 | { |
| 508 | log(Priority::Important, "network: replace resource with id='" + resourceId + "'"); |
| 509 | |
| 510 | std::vector<std::string> chunks; |
| 511 | for (size_t i = 0; i < mainData.length(); i += MaxChunkSize) { |
| 512 | std::string chunk = mainData.substr(i, MaxChunkSize); |
| 513 | chunks.emplace_back(chunk); |
| 514 | } |
| 515 | |
| 516 | httplib::SSLClient client(_serverAddress); |
| 517 | configureClient(client); |
| 518 | |
| 519 | httplib::MultipartFormDataItems items = { |
| 520 | {"userName", *_loggedInUserName, "", ""}, |
| 521 | {"password", *_password, "", ""}, |
| 522 | {"simId", resourceId, "", ""}, |
| 523 | {"width", std::to_string(worldSize.x), "", ""}, |
| 524 | {"height", std::to_string(worldSize.y), "", ""}, |
| 525 | {"particles", std::to_string(numParticles), "", ""}, |
| 526 | {"version", Const::ProgramVersion, "", ""}, |
| 527 | {"content", chunks.front(), "", "application/octet-stream"}, |
| 528 | {"settings", settings, "", ""}, |
| 529 | {"symbolMap", "", "", ""}, |
| 530 | {"statistics", statistics, "", ""}, |
| 531 | }; |
| 532 | |
| 533 | try { |
| 534 | auto result = executeRequest([&] { return client.Post("/alien-server/replacesimulation.php", items); }); |
| 535 | if (!parseBoolResult(result->body)) { |
| 536 | return false; |
| 537 | } |
| 538 | } catch (...) { |
| 539 | logNetworkError(); |
| 540 | return false; |
| 541 | } |
| 542 | |
| 543 | int index = 1; |
| 544 | for (auto const& chunk : chunks | std::views::drop(1)) { |
| 545 | if (!appendResourceData(resourceId, chunk, toInt(index))) { |
| 546 | deleteResource(resourceId); |
| 547 | return false; |
| 548 | } |
| 549 | ++index; |
| 550 | } |
| 551 | _downloadCache.insertOrAssign(resourceId, ResourceData{mainData, settings, statistics}); |
| 552 | |
| 553 | return true; |
| 554 | } |
| 555 | |
| 556 | bool NetworkService::downloadResource(std::string& mainData, std::string& auxiliaryData, std::string& statistics, std::string const& simId) |
| 557 | { |
no test coverage detected