diff --git a/src/Network/Resources.cpp b/src/Network/Resources.cpp index 1ebe86d..527433c 100644 --- a/src/Network/Resources.cpp +++ b/src/Network/Resources.cpp @@ -362,13 +362,15 @@ std::string GetSha256HashReallyFast(const std::string& filename) { } struct ModInfo { - static std::vector ParseModInfosFromPacket(const std::string& packet) { + static std::pair> ParseModInfosFromPacket(const std::string& packet) { + bool success = false; std::vector modInfos; try { auto json = nlohmann::json::parse(packet); if (json.empty()) { - return modInfos; + return std::make_pair(true, modInfos); } + for (const auto& entry : json) { ModInfo modInfo { .FileName = entry["file_name"], @@ -377,13 +379,14 @@ struct ModInfo { .HashAlgorithm = entry["hash_algorithm"], }; modInfos.push_back(modInfo); + success = true; } } catch (const std::exception& e) { debug(std::string("Failed to receive mod list: ") + e.what()); error("Failed to receive mod list!"); // TODO: Cry and die } - return modInfos; + return std::make_pair(success, modInfos); } std::string FileName; size_t FileSize; @@ -392,6 +395,13 @@ struct ModInfo { }; void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector ModInfos) { + if (ModInfos.empty()) { + CoreSend("L"); + TCPSend("Done", Sock); + info("Done!"); + return; + } + if (!SecurityWarning()) return; @@ -518,8 +528,8 @@ void SyncResources(SOCKET Sock) { auto ModInfos = ModInfo::ParseModInfosFromPacket(Ret); - if (!ModInfos.empty()) { - NewSyncResources(Sock, Ret, ModInfos); + if (ModInfos.first) { + NewSyncResources(Sock, Ret, ModInfos.second); return; }