1 Commits

Author SHA1 Message Date
SaltySnail
642dc76a92 Remove backend 2026-03-28 22:23:33 +01:00
7 changed files with 207 additions and 344 deletions

View File

@@ -20,7 +20,7 @@ jobs:
with: with:
vcpkgArguments: 'zlib nlohmann-json openssl cpp-httplib[openssl]' vcpkgArguments: 'zlib nlohmann-json openssl cpp-httplib[openssl]'
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg' vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
vcpkgGitCommitId: 'b5d1a94fb7f88fd835e360fd23a45a09ceedbf48' vcpkgGitCommitId: '40616a5e954f7be1077ef37db3fbddbd5dcd1ca6'
- name: Create Build Environment - name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build-linux run: cmake -E make_directory ${{github.workspace}}/build-linux

View File

@@ -20,7 +20,7 @@ jobs:
with: with:
vcpkgArguments: 'discord-rpc zlib nlohmann-json openssl cpp-httplib[openssl]' vcpkgArguments: 'discord-rpc zlib nlohmann-json openssl cpp-httplib[openssl]'
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg' vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
vcpkgGitCommitId: 'b5d1a94fb7f88fd835e360fd23a45a09ceedbf48' vcpkgGitCommitId: '40616a5e954f7be1077ef37db3fbddbd5dcd1ca6'
vcpkgTriplet: 'x64-windows-static' vcpkgTriplet: 'x64-windows-static'
- name: Create Build Environment - name: Create Build Environment

View File

@@ -227,7 +227,7 @@ void Parse(std::string Data, SOCKET CSocket) {
TCPTerminate = true; TCPTerminate = true;
Data.clear(); Data.clear();
futures.push_back(std::async(std::launch::async, []() { futures.push_back(std::async(std::launch::async, []() {
CoreSend("B" + HTTP::Get("https://backend.beammp.com/servers-info")); // CoreSend("B" + HTTP::Get("https://backend.beammp.com/servers-info"));
})); }));
} }
break; break;

View File

@@ -20,6 +20,45 @@
#include <mutex> #include <mutex>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
void WriteHttpDebug(const httplib::Client& client, const std::string& method, const std::string& target, const httplib::Result& result) try {
const std::filesystem::path folder = ".https_debug";
std::filesystem::create_directories(folder);
if (!std::filesystem::exists(folder / "WHAT IS THIS FOLDER.txt")) {
std::ofstream ignore { folder / "WHAT IS THIS FOLDER.txt" };
ignore << "This folder exists to help debug current issues with the backend. Do not share this folder with anyone but BeamMP staff. It contains detailed logs of any failed http requests." << std::endl;
}
const auto file = folder / (method + ".json");
// 1 MB limit
if (std::filesystem::exists(file) && std::filesystem::file_size(file) > 1'000'000) {
std::filesystem::rename(file, file.generic_string() + ".bak");
}
std::ofstream of { file, std::ios::app };
nlohmann::json js {
{ "utc", std::chrono::system_clock::now().time_since_epoch().count() },
{ "target", target },
{ "client_info", {
{ "openssl_verify_result", client.get_openssl_verify_result() },
{ "host", client.host() },
{ "port", client.port() },
{ "socket_open", client.is_socket_open() },
{ "valid", client.is_valid() },
} },
};
if (result) {
auto value = result.value();
js["result"] = {};
js["result"]["body"] = value.body;
js["result"]["status"] = value.status;
js["result"]["headers"] = value.headers;
js["result"]["version"] = value.version;
js["result"]["location"] = value.location;
js["result"]["reason"] = value.reason;
}
of << js.dump();
} catch (const std::exception& e) {
error(e.what());
}
static size_t CurlWriteCallback(void* contents, size_t size, size_t nmemb, void* userp) { static size_t CurlWriteCallback(void* contents, size_t size, size_t nmemb, void* userp) {
std::string* Result = reinterpret_cast<std::string*>(userp); std::string* Result = reinterpret_cast<std::string*>(userp);
@@ -130,118 +169,118 @@ void set_headers(httplib::Response& res) {
} }
void HTTP::StartProxy() { void HTTP::StartProxy() {
std::thread proxy([&]() { // std::thread proxy([&]() {
httplib::Server HTTPProxy; // httplib::Server HTTPProxy;
httplib::Headers headers = { // httplib::Headers headers = {
{ "User-Agent", "BeamMP-Launcher/" + GetVer() + GetPatch() }, // { "User-Agent", "BeamMP-Launcher/" + GetVer() + GetPatch() },
{ "Accept", "*/*" } // { "Accept", "*/*" }
}; // };
httplib::Client backend("https://backend.beammp.com"); // httplib::Client backend("https://backend.beammp.com");
httplib::Client forum("https://forum.beammp.com"); // httplib::Client forum("https://forum.beammp.com");
const std::string pattern = ".*"; // const std::string pattern = ".*";
auto handle_request = [&](const httplib::Request& req, httplib::Response& res) { // auto handle_request = [&](const httplib::Request& req, httplib::Response& res) {
set_headers(res); // set_headers(res);
if (req.has_header("X-BMP-Authentication")) { // if (req.has_header("X-BMP-Authentication")) {
headers.emplace("X-BMP-Authentication", PrivateKey); // headers.emplace("X-BMP-Authentication", PrivateKey);
} // }
if (req.has_header("X-API-Version")) { // if (req.has_header("X-API-Version")) {
headers.emplace("X-API-Version", req.get_header_value("X-API-Version")); // headers.emplace("X-API-Version", req.get_header_value("X-API-Version"));
} // }
const std::vector<std::string> path = Utils::Split(req.path, "/"); // const std::vector<std::string> path = Utils::Split(req.path, "/");
httplib::Result cli_res; // httplib::Result cli_res;
const std::string method = req.method; // const std::string method = req.method;
std::string host = ""; // std::string host = "";
if (!path.empty()) // if (!path.empty())
host = path[0]; // host = path[0];
if (host == "backend") { // if (host == "backend") {
std::string remaining_path = req.path.substr(std::strlen("/backend")); // std::string remaining_path = req.path.substr(std::strlen("/backend"));
if (method == "GET") // if (method == "GET")
cli_res = backend.Get(remaining_path, headers); // cli_res = backend.Get(remaining_path, headers);
else if (method == "POST") // else if (method == "POST")
cli_res = backend.Post(remaining_path, headers); // cli_res = backend.Post(remaining_path, headers);
} else if (host == "avatar") { // } else if (host == "avatar") {
bool error = false; // bool error = false;
std::string username; // std::string username;
std::string avatar_size = "100"; // std::string avatar_size = "100";
if (path.size() > 1) { // if (path.size() > 1) {
username = path[1]; // username = path[1];
} else { // } else {
error = true; // error = true;
} // }
if (path.size() > 2) { // if (path.size() > 2) {
try { // try {
if (std::stoi(path[2]) > 0) // if (std::stoi(path[2]) > 0)
avatar_size = path[2]; // avatar_size = path[2];
} catch (std::exception&) { } // } catch (std::exception&) { }
} // }
httplib::Result summary_res; // httplib::Result summary_res;
if (!error) { // if (!error) {
summary_res = forum.Get("/u/" + username + ".json", headers); // summary_res = forum.Get("/u/" + username + ".json", headers);
if (!summary_res || summary_res->status != 200) { // if (!summary_res || summary_res->status != 200) {
error = true; // error = true;
} // }
} // }
if (!error) { // if (!error) {
try { // try {
nlohmann::json d = nlohmann::json::parse(summary_res->body, nullptr, false); // can fail with parse_error // nlohmann::json d = nlohmann::json::parse(summary_res->body, nullptr, false); // can fail with parse_error
auto user = d.at("user"); // can fail with out_of_range // auto user = d.at("user"); // can fail with out_of_range
auto avatar_link_json = user.at("avatar_template"); // can fail with out_of_range // auto avatar_link_json = user.at("avatar_template"); // can fail with out_of_range
auto avatar_link = avatar_link_json.get<std::string>(); // auto avatar_link = avatar_link_json.get<std::string>();
size_t start_pos = avatar_link.find("{size}"); // size_t start_pos = avatar_link.find("{size}");
if (start_pos != std::string::npos) // if (start_pos != std::string::npos)
avatar_link.replace(start_pos, std::strlen("{size}"), avatar_size); // avatar_link.replace(start_pos, std::strlen("{size}"), avatar_size);
cli_res = forum.Get(avatar_link, headers); // cli_res = forum.Get(avatar_link, headers);
} catch (std::exception&) { // } catch (std::exception&) {
error = true; // error = true;
} // }
} // }
if (error) { // if (error) {
cli_res = forum.Get("/user_avatar/forum.beammp.com/user/0/0.png", headers); // cli_res = forum.Get("/user_avatar/forum.beammp.com/user/0/0.png", headers);
} // }
} else { // } else {
res.set_content("Host not found", "text/plain"); // res.set_content("Host not found", "text/plain");
return; // return;
} // }
if (cli_res) { // if (cli_res) {
res.set_content(cli_res->body, cli_res->get_header_value("Content-Type")); // res.set_content(cli_res->body, cli_res->get_header_value("Content-Type"));
} else { // } else {
res.set_content(to_string(cli_res.error()), "text/plain"); // res.set_content(to_string(cli_res.error()), "text/plain");
} // }
}; // };
HTTPProxy.Get(pattern, [&](const httplib::Request& req, httplib::Response& res) { // HTTPProxy.Get(pattern, [&](const httplib::Request& req, httplib::Response& res) {
handle_request(req, res); // handle_request(req, res);
}); // });
HTTPProxy.Post(pattern, [&](const httplib::Request& req, httplib::Response& res) { // HTTPProxy.Post(pattern, [&](const httplib::Request& req, httplib::Response& res) {
handle_request(req, res); // handle_request(req, res);
}); // });
ProxyPort = HTTPProxy.bind_to_any_port("127.0.0.1"); // ProxyPort = HTTPProxy.bind_to_any_port("127.0.0.1");
debug("HTTP Proxy listening on port " + std::to_string(ProxyPort)); // debug("HTTP Proxy listening on port " + std::to_string(ProxyPort));
HTTPProxy.listen_after_bind(); // HTTPProxy.listen_after_bind();
}); // });
proxy.detach(); // proxy.detach();
} }

View File

@@ -94,8 +94,7 @@ void UDPClientMain(const std::string& IP, int Port) {
inet_pton(AF_INET, IP.c_str(), &ToServer->sin_addr); inet_pton(AF_INET, IP.c_str(), &ToServer->sin_addr);
UDPSock = socket(AF_INET, SOCK_DGRAM, 0); UDPSock = socket(AF_INET, SOCK_DGRAM, 0);
if (!magic.empty()) if (!magic.empty())
for (int i = 0; i < 10; i++) UDPSend(magic);
UDPSend(magic);
GameSend("P" + std::to_string(ClientID)); GameSend("P" + std::to_string(ClientID));
TCPSend("H", TCPSock); TCPSend("H", TCPSock);
UDPSend("p"); UDPSend("p");

View File

@@ -268,7 +268,7 @@ void LegitimacyCheck() {
std::ifstream libraryFolders(libraryFoldersPath); std::ifstream libraryFolders(libraryFoldersPath);
auto root = tyti::vdf::read(libraryFolders); auto root = tyti::vdf::read(libraryFolders);
for (auto folderInfo : root.childs) { for (auto folderInfo : root.childs) {
if ((folderInfo.second->childs["apps"]->attribs).contains("284160") && std::filesystem::exists(folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/integrity.json")){ if (std::filesystem::exists(folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/integrity.json")){
GameDir = folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/"; GameDir = folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/";
break; break;
} }

View File

@@ -4,6 +4,7 @@
SPDX-License-Identifier: AGPL-3.0-or-later SPDX-License-Identifier: AGPL-3.0-or-later
*/ */
#include "zip_file.h" #include "zip_file.h"
#include <charconv> #include <charconv>
#include <cstring> #include <cstring>
@@ -13,9 +14,9 @@
#if defined(_WIN32) #if defined(_WIN32)
#elif defined(__linux__) #elif defined(__linux__)
#include <unistd.h> #include <unistd.h>
#elif defined(__APPLE__) #elif defined (__APPLE__)
#include <libproc.h>
#include <unistd.h> #include <unistd.h>
#include <libproc.h>
#endif // __APPLE__ #endif // __APPLE__
#include "Http.h" #include "Http.h"
#include "Logger.h" #include "Logger.h"
@@ -83,7 +84,7 @@ beammp_fs_string GetEN() {
} }
std::string GetVer() { std::string GetVer() {
return "2.8"; return "2.7";
} }
std::string GetPatch() { std::string GetPatch() {
return ".0"; return ".0";
@@ -113,7 +114,7 @@ fs::path GetBP(const beammp_fs_char* P) {
// should instead be placed in Application Support. // should instead be placed in Application Support.
proc_pidpath(pid, path, sizeof(path)); proc_pidpath(pid, path, sizeof(path));
fspath = std::string(path); fspath = std::string(path);
#else #else
fspath = beammp_fs_string(P); fspath = beammp_fs_string(P);
#endif #endif
fspath = fs::weakly_canonical(fspath.string() + "/.."); fspath = fs::weakly_canonical(fspath.string() + "/..");
@@ -193,215 +194,48 @@ void CheckName() {
} }
} }
#if defined(_WIN32)
#include <wincrypt.h>
#include <wintrust.h>
#include <softpub.h>
#include <iostream>
#pragma comment(lib, "wintrust.lib")
#pragma comment(lib, "crypt32.lib")
bool CheckThumbprint(std::filesystem::path filepath)
{
HCERTSTORE hStore = NULL;
HCRYPTMSG hMsg = NULL;
if (!CryptQueryObject(
CERT_QUERY_OBJECT_FILE,
filepath.wstring().c_str(),
CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED,
CERT_QUERY_FORMAT_FLAG_BINARY,
0,
NULL, NULL, NULL,
&hStore,
&hMsg,
NULL))
{
return false;
}
DWORD dwSignerInfo = 0;
if (!CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, 0, NULL, &dwSignerInfo) || dwSignerInfo == 0)
return false;
PCMSG_SIGNER_INFO pSignerInfo = (PCMSG_SIGNER_INFO)LocalAlloc(LPTR, dwSignerInfo);
if (!CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, 0, pSignerInfo, &dwSignerInfo))
{
LocalFree(pSignerInfo);
return false;
}
CERT_INFO certInfo = {};
certInfo.Issuer = pSignerInfo->Issuer;
certInfo.SerialNumber = pSignerInfo->SerialNumber;
PCCERT_CONTEXT pCertContext = CertFindCertificateInStore(
hStore,
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
0,
CERT_FIND_SUBJECT_CERT,
&certInfo,
NULL);
if (!pCertContext)
{
LocalFree(pSignerInfo);
return false;
}
BYTE hash[64];
DWORD hashSize = sizeof(hash);
bool match = false;
if (CertGetCertificateContextProperty(pCertContext, CERT_SHA256_HASH_PROP_ID, hash, &hashSize))
{
std::string pubKeyData(
reinterpret_cast<const char*>(pCertContext->pCertInfo->SubjectPublicKeyInfo.PublicKey.pbData),
pCertContext->pCertInfo->SubjectPublicKeyInfo.PublicKey.cbData
);
std::string pubKeyHash = Utils::GetSha256HashReallyFast(pubKeyData, L"PubKey");
debug("pub key hash: " + pubKeyHash);
std::string fileThumbprint;
for (DWORD i = 0; i < hashSize; i++)
{
char buf[3];
sprintf_s(buf, "%02x", hash[i]);
fileThumbprint += buf;
}
debug("File thumbprint: " +fileThumbprint);
debug(filepath);
if (fileThumbprint == "937f055b713de69416926ed4651d65219a0a0e77d7a78c1932c007e14326da33" && pubKeyHash == "2afad4a5773b0ac449f48350ce0d09c372be0d5bcbaa6d01332ce000baffde99"){
match = true;
}
}
CertFreeCertificateContext(pCertContext);
CertCloseStore(hStore, 0);
LocalFree(pSignerInfo);
return match;
}
#include <windows.h>
#include <wintrust.h>
#include <Softpub.h>
#include <filesystem>
#include <string>
#pragma comment(lib, "wintrust")
bool VerifySignature(const std::filesystem::path& filePath)
{
std::wstring path = filePath.wstring();
WINTRUST_FILE_INFO fileInfo = {};
fileInfo.cbStruct = sizeof(WINTRUST_FILE_INFO);
fileInfo.pcwszFilePath = path.c_str();
fileInfo.hFile = NULL;
fileInfo.pgKnownSubject = NULL;
WINTRUST_DATA winTrustData = {};
winTrustData.cbStruct = sizeof(WINTRUST_DATA);
winTrustData.dwUIChoice = WTD_UI_NONE;
winTrustData.dwUnionChoice = WTD_CHOICE_FILE;
winTrustData.pFile = &fileInfo;
winTrustData.dwStateAction = WTD_STATEACTION_VERIFY;
GUID policyGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2;
LONG status = WinVerifyTrust(
NULL,
&policyGUID,
&winTrustData
);
debug(filePath);
debug("Signature check code: " + std::to_string(status));
winTrustData.dwStateAction = WTD_STATEACTION_CLOSE;
WinVerifyTrust(NULL, &policyGUID, &winTrustData);
return (status == CERT_E_UNTRUSTEDROOT);
}
#endif
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);
std::string LatestVersion = HTTP::Get( // std::string LatestVersion = HTTP::Get(
"https://backend.beammp.com/version/launcher?branch=" + Branch + "&pk=" + PublicKey); // "https://backend.beammp.com/version/launcher?branch=" + Branch + "&pk=" + PublicKey);
std::regex sha256_pattern(R"(^[a-fA-F0-9]{64}$)"); // transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
std::smatch match; // beammp_fs_string BP(GetBP() / GetEN()), Back(GetBP() / beammp_wide("BeamMP-Launcher.back"));
if (LatestHash.length() != 64 || !std::regex_match(LatestHash, match, sha256_pattern)) { // std::string FileHash = Utils::GetSha256HashReallyFastFile(BP);
error("Invalid hash from backend, skipping update check.");
debug("Launcher hash in question: " + LatestHash);
return;
}
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower); // if (FileHash != LatestHash && IsOutdated(Version(VersionStrToInts(GetVer() + GetPatch())), Version(VersionStrToInts(LatestVersion)))) {
beammp_fs_string BP(GetBP() / GetEN()), Back(GetBP() / beammp_wide("BeamMP-Launcher.back")); // if (!options.no_update) {
// info("Launcher update " + LatestVersion + " found!");
std::string FileHash = Utils::GetSha256HashReallyFastFile(BP); // #if defined(__linux__)
// error("Auto update is NOT implemented for the Linux version. Please update manually ASAP as updates contain security patches.");
if (FileHash != LatestHash && IsOutdated(Version(VersionStrToInts(GetVer() + GetPatch())), Version(VersionStrToInts(LatestVersion)))) { // #else
if (!options.no_update) { // info("Downloading Launcher update " + LatestHash);
info("Launcher update " + LatestVersion + " found!"); // HTTP::Download(
#if defined(__linux__) // "https://backend.beammp.com/builds/launcher?download=true"
error("Auto update is NOT implemented for the Linux version. Please update manually ASAP as updates contain security patches."); // "&pk="
#else // + PublicKey + "&branch=" + Branch,
info("Downloading Launcher update " + LatestHash); // GetBP() / (beammp_wide("new_") + GetEN()), LatestHash);
std::wstring DownloadLocation = GetBP() / (beammp_wide("new_") + GetEN()); // std::error_code ec;
if (HTTP::Download( // fs::remove(Back, ec);
"https://backend.beammp.com/builds/launcher?download=true" // if (ec == std::errc::permission_denied) {
"&pk=" // error("Failed to remove old backup file: " + ec.message() + ". Using alternative name.");
+ PublicKey + "&branch=" + Branch, // fs::rename(BP, Back + beammp_wide(".") + Utils::ToWString(FileHash.substr(0, 8)));
DownloadLocation, LatestHash)) { // } else {
if (!VerifySignature(DownloadLocation) || !CheckThumbprint(DownloadLocation)) { // fs::rename(BP, Back);
std::error_code ec; // }
fs::remove(DownloadLocation, ec); // fs::rename(GetBP() / (beammp_wide("new_") + GetEN()), BP);
if (ec) { // URelaunch();
error("Failed to remove broken launcher update"); // #endif
} // } else {
throw std::runtime_error("The authenticity of the updated launcher could not be verified, it was corrupted or tampered with."); // warn("Launcher update was found, but not updating because --no-update or --dev was specified.");
} // }
// } else
info("Update signature is valid"); // info("Launcher version is up to date. Latest version: " + LatestVersion);
// TraceBack++;
std::error_code ec;
fs::remove(Back, ec);
if (ec == std::errc::permission_denied) {
error("Failed to remove old backup file: " + ec.message() + ". Using alternative name.");
fs::rename(BP, Back + beammp_wide(".") + Utils::ToWString(FileHash.substr(0, 8)));
} else {
fs::rename(BP, Back);
}
fs::rename(GetBP() / (beammp_wide("new_") + GetEN()), BP);
URelaunch();
} else {
if (fs::exists(DownloadLocation)) {
std::error_code error_code;
fs::remove(DownloadLocation, error_code);
if (error_code) {
error("Failed to remove broken launcher update");
}
}
throw std::runtime_error("Failed to download the launcher update! Please try manually updating it, https://docs.beammp.com/FAQ/Update-launcher/");
}
#endif
} else {
warn("Launcher update was found, but not updating because --no-update or --dev was specified.");
}
} else
info("Launcher version is up to date. Latest version: " + LatestVersion);
TraceBack++;
} }
#ifdef _WIN32 #ifdef _WIN32
void LinuxPatch() { void LinuxPatch() {
HKEY hKey = nullptr; HKEY hKey = nullptr;
@@ -513,51 +347,42 @@ void PreGame(const beammp_fs_string& GamePath) {
CheckMP(GetGamePath() / beammp_wide("mods/multiplayer")); CheckMP(GetGamePath() / beammp_wide("mods/multiplayer"));
info(beammp_wide("Game user path: ") + beammp_fs_string(GetGamePath())); info(beammp_wide("Game user path: ") + beammp_fs_string(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 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); }),
LatestHash.end()); // LatestHash.end());
std::regex sha256_pattern(R"(^[a-fA-F0-9]{64}$)"); // try {
std::smatch match; // if (!fs::exists(GetGamePath() / beammp_wide("mods/multiplayer"))) {
// fs::create_directories(GetGamePath() / beammp_wide("mods/multiplayer"));
// }
// EnableMP();
// } catch (std::exception& e) {
// fatal(e.what());
// }
// #if defined(_WIN32)
// std::wstring ZipPath(GetGamePath() / LR"(mods\multiplayer\BeamMP.zip)");
// #elif defined(__linux__)
// // Linux version of the game cant handle mods with uppercase names
// std::string ZipPath(GetGamePath() / R"(mods/multiplayer/beammp.zip)");
// #endif
if (LatestHash.length() != 64 || !std::regex_match(LatestHash, match, sha256_pattern)) { // std::string FileHash = fs::exists(ZipPath) ? Utils::GetSha256HashReallyFastFile(ZipPath) : "";
error("Invalid hash from backend, skipping mod update check.");
debug("Mod hash in question: " + LatestHash);
return;
}
try { // if (FileHash != LatestHash) {
if (!fs::exists(GetGamePath() / beammp_wide("mods/multiplayer"))) { // info("Downloading BeamMP Update " + LatestHash);
fs::create_directories(GetGamePath() / beammp_wide("mods/multiplayer")); // HTTP::Download("https://backend.beammp.com/builds/client?download=true"
} // "&pk="
EnableMP(); // + PublicKey + "&branch=" + Branch,
} catch (std::exception& e) { // ZipPath, LatestHash);
fatal(e.what()); // }
}
#if defined(_WIN32)
std::wstring ZipPath(GetGamePath() / LR"(mods\multiplayer\BeamMP.zip)");
#elif defined(__linux__)
// Linux version of the game cant handle mods with uppercase names
std::string ZipPath(GetGamePath() / R"(mods/multiplayer/beammp.zip)");
#endif
std::string FileHash = fs::exists(ZipPath) ? Utils::GetSha256HashReallyFastFile(ZipPath) : ""; // beammp_fs_string Target(GetGamePath() / beammp_wide("mods/unpacked/beammp"));
if (FileHash != LatestHash) { // if (fs::is_directory(Target) && !fs::is_directory(Target + beammp_wide("/.git"))) {
info("Downloading BeamMP Update " + LatestHash); // fs::remove_all(Target);
HTTP::Download("https://backend.beammp.com/builds/client?download=true" // }
"&pk=" // }
+ PublicKey + "&branch=" + Branch,
ZipPath, LatestHash);
}
beammp_fs_string Target(GetGamePath() / beammp_wide("mods/unpacked/beammp"));
if (fs::is_directory(Target) && !fs::is_directory(Target + beammp_wide("/.git"))) {
fs::remove_all(Target);
}
}
} }