mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-01 23:46:59 +00:00
Handle new modlist being empty but still valid
This commit is contained in:
parent
3cf1a2e51b
commit
4fbd25b551
@ -362,13 +362,15 @@ std::string GetSha256HashReallyFast(const std::string& filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct ModInfo {
|
struct ModInfo {
|
||||||
static std::vector<ModInfo> ParseModInfosFromPacket(const std::string& packet) {
|
static std::pair<bool, std::vector<ModInfo>> ParseModInfosFromPacket(const std::string& packet) {
|
||||||
|
bool success = false;
|
||||||
std::vector<ModInfo> modInfos;
|
std::vector<ModInfo> modInfos;
|
||||||
try {
|
try {
|
||||||
auto json = nlohmann::json::parse(packet);
|
auto json = nlohmann::json::parse(packet);
|
||||||
if (json.empty()) {
|
if (json.empty()) {
|
||||||
return modInfos;
|
return std::make_pair(true, modInfos);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& entry : json) {
|
for (const auto& entry : json) {
|
||||||
ModInfo modInfo {
|
ModInfo modInfo {
|
||||||
.FileName = entry["file_name"],
|
.FileName = entry["file_name"],
|
||||||
@ -377,13 +379,14 @@ struct ModInfo {
|
|||||||
.HashAlgorithm = entry["hash_algorithm"],
|
.HashAlgorithm = entry["hash_algorithm"],
|
||||||
};
|
};
|
||||||
modInfos.push_back(modInfo);
|
modInfos.push_back(modInfo);
|
||||||
|
success = true;
|
||||||
}
|
}
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
debug(std::string("Failed to receive mod list: ") + e.what());
|
debug(std::string("Failed to receive mod list: ") + e.what());
|
||||||
error("Failed to receive mod list!");
|
error("Failed to receive mod list!");
|
||||||
// TODO: Cry and die
|
// TODO: Cry and die
|
||||||
}
|
}
|
||||||
return modInfos;
|
return std::make_pair(success, modInfos);
|
||||||
}
|
}
|
||||||
std::string FileName;
|
std::string FileName;
|
||||||
size_t FileSize;
|
size_t FileSize;
|
||||||
@ -392,6 +395,13 @@ struct ModInfo {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<ModInfo> ModInfos) {
|
void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<ModInfo> ModInfos) {
|
||||||
|
if (ModInfos.empty()) {
|
||||||
|
CoreSend("L");
|
||||||
|
TCPSend("Done", Sock);
|
||||||
|
info("Done!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!SecurityWarning())
|
if (!SecurityWarning())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -518,8 +528,8 @@ void SyncResources(SOCKET Sock) {
|
|||||||
|
|
||||||
auto ModInfos = ModInfo::ParseModInfosFromPacket(Ret);
|
auto ModInfos = ModInfo::ParseModInfosFromPacket(Ret);
|
||||||
|
|
||||||
if (!ModInfos.empty()) {
|
if (ModInfos.first) {
|
||||||
NewSyncResources(Sock, Ret, ModInfos);
|
NewSyncResources(Sock, Ret, ModInfos.second);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user