mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-01 23:46:59 +00:00
Use a JSON body for requests instead of query params
This commit is contained in:
parent
a8a4dfb77c
commit
ce3abf7e6e
@ -9,9 +9,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
class HTTP {
|
class HTTP {
|
||||||
public:
|
public:
|
||||||
static bool Download(const std::string& IP, const std::string& Path);
|
static bool Download(const std::string& IP, const std::string& Fields, const std::string& Path);
|
||||||
static std::string Post(const std::string& IP, const std::string& Fields);
|
static std::string Post(const std::string& IP, const std::string& Fields);
|
||||||
static std::string Get(const std::string& IP);
|
static std::string Get(const std::string& IP, const std::string& Fields = "");
|
||||||
static bool ProgressBar(size_t c, size_t t);
|
static bool ProgressBar(size_t c, size_t t);
|
||||||
static void StartProxy();
|
static void StartProxy();
|
||||||
public:
|
public:
|
||||||
|
@ -68,7 +68,7 @@ static size_t CurlWriteCallback(void* contents, size_t size, size_t nmemb, void*
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool HTTP::isDownload = false;
|
bool HTTP::isDownload = false;
|
||||||
std::string HTTP::Get(const std::string& IP) {
|
std::string HTTP::Get(const std::string& IP, const std::string& Fields) {
|
||||||
std::string Ret;
|
std::string Ret;
|
||||||
static thread_local CURL* curl = curl_easy_init();
|
static thread_local CURL* curl = curl_easy_init();
|
||||||
if (curl) {
|
if (curl) {
|
||||||
@ -78,6 +78,11 @@ std::string HTTP::Get(const std::string& IP) {
|
|||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&Ret);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&Ret);
|
||||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10); // seconds
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10); // seconds
|
||||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||||
|
if (!Fields.empty()) {
|
||||||
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
|
||||||
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, Fields.c_str());
|
||||||
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, Fields.size());
|
||||||
|
}
|
||||||
res = curl_easy_perform(curl);
|
res = curl_easy_perform(curl);
|
||||||
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)));
|
||||||
@ -119,12 +124,12 @@ std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
|
|||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HTTP::Download(const std::string& IP, const std::string& Path) {
|
bool HTTP::Download(const std::string& IP, const std::string& Fields, const std::string& Path) {
|
||||||
static std::mutex Lock;
|
static std::mutex Lock;
|
||||||
std::scoped_lock Guard(Lock);
|
std::scoped_lock Guard(Lock);
|
||||||
|
|
||||||
info("Downloading an update (this may take a while)");
|
info("Downloading an update (this may take a while)");
|
||||||
std::string Ret = Get(IP);
|
std::string Ret = Get(IP, Fields);
|
||||||
|
|
||||||
if (Ret.empty()) {
|
if (Ret.empty()) {
|
||||||
error("Download failed");
|
error("Download failed");
|
||||||
|
@ -164,9 +164,9 @@ void CheckName() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 requestBody = R"({"branch": ")" + Branch + R"(","pk":")" + PublicKey + R"("})";
|
||||||
std::string LatestVersion = HTTP::Get(
|
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/launcher", requestBody);
|
||||||
"https://backend.beammp.com/version/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
std::string LatestVersion = HTTP::Get("https://backend.beammp.com/version/launcher", requestBody);
|
||||||
|
|
||||||
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
||||||
std::string EP(GetEP() + GetEN()), Back(GetEP() + "BeamMP-Launcher.back");
|
std::string EP(GetEP() + GetEN()), Back(GetEP() + "BeamMP-Launcher.back");
|
||||||
@ -182,11 +182,7 @@ void CheckForUpdates(const std::string& CV) {
|
|||||||
fs::remove(Back);
|
fs::remove(Back);
|
||||||
fs::rename(EP, Back);
|
fs::rename(EP, Back);
|
||||||
info("Downloading Launcher update " + LatestHash);
|
info("Downloading Launcher update " + LatestHash);
|
||||||
HTTP::Download(
|
HTTP::Download("https://backend.beammp.com/builds/launcher?download=true", requestBody, EP);
|
||||||
"https://backend.beammp.com/builds/launcher?download=true"
|
|
||||||
"&pk="
|
|
||||||
+ PublicKey + "&branch=" + Branch,
|
|
||||||
EP);
|
|
||||||
URelaunch();
|
URelaunch();
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
@ -307,7 +303,8 @@ void PreGame(const std::string& GamePath) {
|
|||||||
info("Game user path: " + GetGamePath());
|
info("Game user path: " + GetGamePath());
|
||||||
|
|
||||||
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 requestBody = R"({"branch": ")" + Branch + R"(","pk":")" + PublicKey + R"("})";
|
||||||
|
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/mod", requestBody);
|
||||||
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); }),
|
||||||
@ -332,10 +329,7 @@ void PreGame(const std::string& GamePath) {
|
|||||||
|
|
||||||
if (FileHash != LatestHash) {
|
if (FileHash != LatestHash) {
|
||||||
info("Downloading BeamMP Update " + LatestHash);
|
info("Downloading BeamMP Update " + LatestHash);
|
||||||
HTTP::Download("https://backend.beammp.com/builds/client?download=true"
|
HTTP::Download("https://backend.beammp.com/builds/client?download=true", requestBody, ZipPath);
|
||||||
"&pk="
|
|
||||||
+ PublicKey + "&branch=" + Branch,
|
|
||||||
ZipPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Target(GetGamePath() + "mods/unpacked/beammp");
|
std::string Target(GetGamePath() + "mods/unpacked/beammp");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user