mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-01 07:25:34 +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>
|
||||
class HTTP {
|
||||
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 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 void StartProxy();
|
||||
public:
|
||||
|
@ -68,7 +68,7 @@ static size_t CurlWriteCallback(void* contents, size_t size, size_t nmemb, void*
|
||||
}
|
||||
|
||||
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;
|
||||
static thread_local CURL* curl = curl_easy_init();
|
||||
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_CONNECTTIMEOUT, 10); // seconds
|
||||
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);
|
||||
if (res != CURLE_OK) {
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
std::scoped_lock Guard(Lock);
|
||||
|
||||
info("Downloading an update (this may take a while)");
|
||||
std::string Ret = Get(IP);
|
||||
std::string Ret = Get(IP, Fields);
|
||||
|
||||
if (Ret.empty()) {
|
||||
error("Download failed");
|
||||
|
@ -164,9 +164,9 @@ void CheckName() {
|
||||
}
|
||||
|
||||
void CheckForUpdates(const std::string& CV) {
|
||||
std::string 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 requestBody = R"({"branch": ")" + Branch + R"(","pk":")" + PublicKey + R"("})";
|
||||
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/launcher", requestBody);
|
||||
std::string LatestVersion = HTTP::Get("https://backend.beammp.com/version/launcher", requestBody);
|
||||
|
||||
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
||||
std::string EP(GetEP() + GetEN()), Back(GetEP() + "BeamMP-Launcher.back");
|
||||
@ -182,11 +182,7 @@ void CheckForUpdates(const std::string& CV) {
|
||||
fs::remove(Back);
|
||||
fs::rename(EP, Back);
|
||||
info("Downloading Launcher update " + LatestHash);
|
||||
HTTP::Download(
|
||||
"https://backend.beammp.com/builds/launcher?download=true"
|
||||
"&pk="
|
||||
+ PublicKey + "&branch=" + Branch,
|
||||
EP);
|
||||
HTTP::Download("https://backend.beammp.com/builds/launcher?download=true", requestBody, EP);
|
||||
URelaunch();
|
||||
#endif
|
||||
} else {
|
||||
@ -307,7 +303,8 @@ void PreGame(const std::string& GamePath) {
|
||||
info("Game user path: " + GetGamePath());
|
||||
|
||||
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);
|
||||
LatestHash.erase(std::remove_if(LatestHash.begin(), LatestHash.end(),
|
||||
[](auto const& c) -> bool { return !std::isalnum(c); }),
|
||||
@ -332,10 +329,7 @@ void PreGame(const std::string& GamePath) {
|
||||
|
||||
if (FileHash != LatestHash) {
|
||||
info("Downloading BeamMP Update " + LatestHash);
|
||||
HTTP::Download("https://backend.beammp.com/builds/client?download=true"
|
||||
"&pk="
|
||||
+ PublicKey + "&branch=" + Branch,
|
||||
ZipPath);
|
||||
HTTP::Download("https://backend.beammp.com/builds/client?download=true", requestBody, ZipPath);
|
||||
}
|
||||
|
||||
std::string Target(GetGamePath() + "mods/unpacked/beammp");
|
||||
|
Loading…
x
Reference in New Issue
Block a user