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();
|
Data.clear();
|
||||||
futures.push_back(std::async(std::launch::async, []() {
|
futures.push_back(std::async(std::launch::async, []() {
|
||||||
std::string resp = HTTP::Get("https://backend.beammp.com/servers-info", true);
|
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);
|
CoreSend("B" + resp);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-3
@@ -51,9 +51,19 @@ std::string HTTP::Get(std::string IP, const bool& redirect) {
|
|||||||
if (res != CURLE_OK) {
|
if (res != CURLE_OK) {
|
||||||
error("GET to " + IP + " failed: " + std::string(curl_easy_strerror(res)));
|
error("GET to " + IP + " failed: " + std::string(curl_easy_strerror(res)));
|
||||||
error("Curl error: " + std::string(errbuf));
|
error("Curl error: " + std::string(errbuf));
|
||||||
RegionHandler::TopLevelDomainFailed();
|
if (!redirect) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
RegionHandler::TopLevelDomainFailed();
|
||||||
|
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 {
|
} else {
|
||||||
error("Curl easy init failed");
|
error("Curl easy init failed");
|
||||||
return "";
|
return "";
|
||||||
@@ -88,9 +98,19 @@ std::string HTTP::Post(std::string IP, const std::string& Fields, const bool& re
|
|||||||
if (res != CURLE_OK) {
|
if (res != CURLE_OK) {
|
||||||
error("POST to " + IP + " failed: " + std::string(curl_easy_strerror(res)));
|
error("POST to " + IP + " failed: " + std::string(curl_easy_strerror(res)));
|
||||||
error("Curl error: " + std::string(errbuf));
|
error("Curl error: " + std::string(errbuf));
|
||||||
RegionHandler::TopLevelDomainFailed();
|
if (!redirect) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
RegionHandler::TopLevelDomainFailed();
|
||||||
|
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 {
|
} else {
|
||||||
error("Curl easy init failed");
|
error("Curl easy init failed");
|
||||||
return "";
|
return "";
|
||||||
@@ -226,7 +246,7 @@ void HTTP::StartProxy() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
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 {
|
} else {
|
||||||
|
|||||||
@@ -58,10 +58,6 @@ std::string Login(const std::string& fields) {
|
|||||||
info("Attempting to authenticate...");
|
info("Attempting to authenticate...");
|
||||||
try {
|
try {
|
||||||
std::string Buffer = HTTP::Post("https://auth.beammp.com/userlogin", fields);
|
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()) {
|
if (Buffer.empty()) {
|
||||||
return GetFail("Failed to communicate with the auth system!");
|
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 + "\"}");
|
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);
|
nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false);
|
||||||
|
|
||||||
|
|||||||
@@ -333,15 +333,7 @@ bool VerifySignature(const std::filesystem::path& filePath)
|
|||||||
|
|
||||||
void CheckForUpdates(const std::string& CV) {
|
void CheckForUpdates(const std::string& CV) {
|
||||||
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
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);
|
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::regex sha256_pattern(R"(^[a-fA-F0-9]{64}$)");
|
||||||
std::smatch match;
|
std::smatch match;
|
||||||
@@ -371,14 +363,6 @@ void CheckForUpdates(const std::string& CV) {
|
|||||||
"&pk="
|
"&pk="
|
||||||
+ PublicKey + "&branch=" + Branch,
|
+ PublicKey + "&branch=" + Branch,
|
||||||
DownloadLocation, LatestHash);
|
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 (downloadSuccess) {
|
||||||
if (!VerifySignature(DownloadLocation) || !CheckThumbprint(DownloadLocation)) {
|
if (!VerifySignature(DownloadLocation) || !CheckThumbprint(DownloadLocation)) {
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
@@ -533,10 +517,6 @@ void PreGame(const beammp_fs_string& GamePath) {
|
|||||||
|
|
||||||
if (!options.no_download) {
|
if (!options.no_download) {
|
||||||
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/mod?branch=" + Branch + "&pk=" + PublicKey);
|
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);
|
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
||||||
LatestHash.erase(std::remove_if(LatestHash.begin(), LatestHash.end(),
|
LatestHash.erase(std::remove_if(LatestHash.begin(), LatestHash.end(),
|
||||||
[](auto const& c) -> bool { return !std::isalnum(c); }),
|
[](auto const& c) -> bool { return !std::isalnum(c); }),
|
||||||
@@ -570,17 +550,11 @@ void PreGame(const beammp_fs_string& GamePath) {
|
|||||||
|
|
||||||
if (FileHash != LatestHash) {
|
if (FileHash != LatestHash) {
|
||||||
info("Downloading BeamMP Update " + LatestHash);
|
info("Downloading BeamMP Update " + LatestHash);
|
||||||
if (!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"
|
HTTP::Download("https://backend.beammp.com/builds/client?download=true"
|
||||||
"&pk="
|
"&pk="
|
||||||
+ PublicKey + "&branch=" + Branch,
|
+ PublicKey + "&branch=" + Branch,
|
||||||
ZipPath, LatestHash);
|
ZipPath, LatestHash);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
beammp_fs_string Target(GetGamePath() / beammp_wide("mods/unpacked/beammp"));
|
beammp_fs_string Target(GetGamePath() / beammp_wide("mods/unpacked/beammp"));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user