mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-01 23:46:59 +00:00
Fix empty modlist (#136)
This PR fixes the launcher getting confused when the server sends an empty mod list using the new downloading system. Related server PR: https://github.com/BeamMP/BeamMP-Server/pull/377
This commit is contained in:
commit
9ebd218856
1
.gitignore
vendored
1
.gitignore
vendored
@ -12,3 +12,4 @@ Resources/
|
|||||||
bin/
|
bin/
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
key
|
key
|
||||||
|
out/
|
||||||
|
@ -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,13 @@ 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!");
|
warn("Failed to receive new mod list format! This server may be outdated, but everything should still work as expected.");
|
||||||
// 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 +394,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;
|
||||||
|
|
||||||
@ -514,11 +523,17 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<Mo
|
|||||||
void SyncResources(SOCKET Sock) {
|
void SyncResources(SOCKET Sock) {
|
||||||
std::string Ret = Auth(Sock);
|
std::string Ret = Auth(Sock);
|
||||||
|
|
||||||
auto ModInfos = ModInfo::ParseModInfosFromPacket(Ret);
|
debug("Mod info: " + Ret);
|
||||||
|
|
||||||
if (!ModInfos.empty()) {
|
if (Ret.starts_with("R")) {
|
||||||
NewSyncResources(Sock, Ret, ModInfos);
|
debug("This server is likely outdated, not trying to parse new mod info format");
|
||||||
return;
|
} else {
|
||||||
|
auto [success, modInfo] = ModInfo::ParseModInfosFromPacket(Ret);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
NewSyncResources(Sock, Ret, modInfo);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ret.empty())
|
if (Ret.empty())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user