mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-08-27 04:37:41 +00:00
Made get and download try a second time on fail
This commit is contained in:
@@ -228,10 +228,6 @@ void Parse(std::string Data, SOCKET CSocket) {
|
||||
Data.clear();
|
||||
futures.push_back(std::async(std::launch::async, []() {
|
||||
std::string resp = HTTP::Get("https://backend.beammp.com/servers-info", true);
|
||||
if (resp == "") {
|
||||
RegionHandler::TopLevelDomainFailed();
|
||||
resp = HTTP::Get("https://backend.beammp.com/servers-info", true);
|
||||
}
|
||||
CoreSend("B" + resp);
|
||||
}));
|
||||
}
|
||||
|
||||
+23
-3
@@ -51,8 +51,18 @@ std::string HTTP::Get(std::string IP, const bool& redirect) {
|
||||
if (res != CURLE_OK) {
|
||||
error("GET to " + IP + " failed: " + std::string(curl_easy_strerror(res)));
|
||||
error("Curl error: " + std::string(errbuf));
|
||||
if (!redirect) {
|
||||
return "";
|
||||
}
|
||||
RegionHandler::TopLevelDomainFailed();
|
||||
return "";
|
||||
IP = RegionHandler::RedirectURL(IP);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, IP.c_str());
|
||||
res = curl_easy_perform(curl);
|
||||
if (res != CURLE_OK) {
|
||||
error("GET to " + IP + " failed: " + std::string(curl_easy_strerror(res)));
|
||||
error("Curl error: " + std::string(errbuf));
|
||||
return "";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error("Curl easy init failed");
|
||||
@@ -88,8 +98,18 @@ std::string HTTP::Post(std::string IP, const std::string& Fields, const bool& re
|
||||
if (res != CURLE_OK) {
|
||||
error("POST to " + IP + " failed: " + std::string(curl_easy_strerror(res)));
|
||||
error("Curl error: " + std::string(errbuf));
|
||||
if (!redirect) {
|
||||
return "";
|
||||
}
|
||||
RegionHandler::TopLevelDomainFailed();
|
||||
return "";
|
||||
IP = RegionHandler::RedirectURL(IP);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, IP.c_str());
|
||||
res = curl_easy_perform(curl);
|
||||
if (res != CURLE_OK) {
|
||||
error("GET to " + IP + " failed: " + std::string(curl_easy_strerror(res)));
|
||||
error("Curl error: " + std::string(errbuf));
|
||||
return "";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error("Curl easy init failed");
|
||||
@@ -226,7 +246,7 @@ void HTTP::StartProxy() {
|
||||
}
|
||||
|
||||
if (error) {
|
||||
cli_res = forum.Get("/user_avatar/forum./user/0/0.png", headers);
|
||||
cli_res = forum.Get("/user_avatar/forum.beammp.com/user/0/0.png", headers);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
@@ -58,10 +58,6 @@ std::string Login(const std::string& fields) {
|
||||
info("Attempting to authenticate...");
|
||||
try {
|
||||
std::string Buffer = HTTP::Post("https://auth.beammp.com/userlogin", fields);
|
||||
if (Buffer == "") {
|
||||
RegionHandler::TopLevelDomainFailed();
|
||||
Buffer = HTTP::Post("https://auth.beammp.com/userlogin", fields);
|
||||
}
|
||||
|
||||
if (Buffer.empty()) {
|
||||
return GetFail("Failed to communicate with the auth system!");
|
||||
@@ -122,10 +118,6 @@ void CheckLocalKey() {
|
||||
}
|
||||
|
||||
Buffer = HTTP::Post("https://auth.beammp.com/userlogin", R"({"pk":")" + Buffer + "\"}");
|
||||
if (Buffer == "") {
|
||||
RegionHandler::TopLevelDomainFailed();
|
||||
Buffer = HTTP::Post("https://auth.beammp.com/userlogin", R"({"pk":")" + Buffer + "\"}");
|
||||
}
|
||||
|
||||
nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false);
|
||||
|
||||
|
||||
+2
-28
@@ -333,15 +333,7 @@ bool VerifySignature(const std::filesystem::path& filePath)
|
||||
|
||||
void CheckForUpdates(const std::string& CV) {
|
||||
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
||||
if (LatestHash == "") {
|
||||
RegionHandler::TopLevelDomainFailed();
|
||||
LatestHash = HTTP::Get("https://backend.beammp.com/sha/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
||||
}
|
||||
std::string LatestVersion = HTTP::Get("https://backend.beammp.com/version/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
||||
if (LatestVersion == "") {
|
||||
RegionHandler::TopLevelDomainFailed();
|
||||
LatestVersion = HTTP::Get("https://backend.beammp.com/version/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
||||
}
|
||||
|
||||
std::regex sha256_pattern(R"(^[a-fA-F0-9]{64}$)");
|
||||
std::smatch match;
|
||||
@@ -371,14 +363,6 @@ void CheckForUpdates(const std::string& CV) {
|
||||
"&pk="
|
||||
+ PublicKey + "&branch=" + Branch,
|
||||
DownloadLocation, LatestHash);
|
||||
if (!downloadSuccess) {
|
||||
RegionHandler::TopLevelDomainFailed();
|
||||
downloadSuccess = HTTP::Download(
|
||||
"https://backend.beammp.com/builds/launcher?download=true"
|
||||
"&pk="
|
||||
+ PublicKey + "&branch=" + Branch,
|
||||
DownloadLocation, LatestHash);
|
||||
}
|
||||
if (downloadSuccess) {
|
||||
if (!VerifySignature(DownloadLocation) || !CheckThumbprint(DownloadLocation)) {
|
||||
std::error_code ec;
|
||||
@@ -533,10 +517,6 @@ void PreGame(const beammp_fs_string& GamePath) {
|
||||
|
||||
if (!options.no_download) {
|
||||
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/mod?branch=" + Branch + "&pk=" + PublicKey);
|
||||
if (LatestHash == "") {
|
||||
RegionHandler::TopLevelDomainFailed();
|
||||
LatestHash = HTTP::Get("https://backend.beammp.com/sha/mod?branch=" + Branch + "&pk=" + PublicKey);
|
||||
}
|
||||
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
||||
LatestHash.erase(std::remove_if(LatestHash.begin(), LatestHash.end(),
|
||||
[](auto const& c) -> bool { return !std::isalnum(c); }),
|
||||
@@ -570,16 +550,10 @@ void PreGame(const beammp_fs_string& GamePath) {
|
||||
|
||||
if (FileHash != LatestHash) {
|
||||
info("Downloading BeamMP Update " + LatestHash);
|
||||
if (!HTTP::Download("https://backend.beammp.com/builds/client?download=true"
|
||||
HTTP::Download("https://backend.beammp.com/builds/client?download=true"
|
||||
"&pk="
|
||||
+ PublicKey + "&branch=" + Branch,
|
||||
ZipPath, LatestHash)) {
|
||||
RegionHandler::TopLevelDomainFailed();
|
||||
HTTP::Download("https://backend.beammp.com/builds/client?download=true"
|
||||
"&pk="
|
||||
+ PublicKey + "&branch=" + Branch,
|
||||
ZipPath, LatestHash);
|
||||
}
|
||||
ZipPath, LatestHash);
|
||||
}
|
||||
|
||||
beammp_fs_string Target(GetGamePath() / beammp_wide("mods/unpacked/beammp"));
|
||||
|
||||
Reference in New Issue
Block a user