1 Commits

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

View File

@@ -227,7 +227,7 @@ void Parse(std::string Data, SOCKET CSocket) {
TCPTerminate = true;
Data.clear();
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;

View File

@@ -169,118 +169,118 @@ void set_headers(httplib::Response& res) {
}
void HTTP::StartProxy() {
std::thread proxy([&]() {
httplib::Server HTTPProxy;
httplib::Headers headers = {
{ "User-Agent", "BeamMP-Launcher/" + GetVer() + GetPatch() },
{ "Accept", "*/*" }
};
httplib::Client backend("https://backend.beammp.com");
httplib::Client forum("https://forum.beammp.com");
// std::thread proxy([&]() {
// httplib::Server HTTPProxy;
// httplib::Headers headers = {
// { "User-Agent", "BeamMP-Launcher/" + GetVer() + GetPatch() },
// { "Accept", "*/*" }
// };
// httplib::Client backend("https://backend.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) {
set_headers(res);
if (req.has_header("X-BMP-Authentication")) {
headers.emplace("X-BMP-Authentication", PrivateKey);
}
if (req.has_header("X-API-Version")) {
headers.emplace("X-API-Version", req.get_header_value("X-API-Version"));
}
// auto handle_request = [&](const httplib::Request& req, httplib::Response& res) {
// set_headers(res);
// if (req.has_header("X-BMP-Authentication")) {
// headers.emplace("X-BMP-Authentication", PrivateKey);
// }
// if (req.has_header("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;
const std::string method = req.method;
std::string host = "";
// httplib::Result cli_res;
// const std::string method = req.method;
// std::string host = "";
if (!path.empty())
host = path[0];
// if (!path.empty())
// host = path[0];
if (host == "backend") {
std::string remaining_path = req.path.substr(std::strlen("/backend"));
// if (host == "backend") {
// std::string remaining_path = req.path.substr(std::strlen("/backend"));
if (method == "GET")
cli_res = backend.Get(remaining_path, headers);
else if (method == "POST")
cli_res = backend.Post(remaining_path, headers);
// if (method == "GET")
// cli_res = backend.Get(remaining_path, headers);
// else if (method == "POST")
// cli_res = backend.Post(remaining_path, headers);
} else if (host == "avatar") {
bool error = false;
std::string username;
std::string avatar_size = "100";
// } else if (host == "avatar") {
// bool error = false;
// std::string username;
// std::string avatar_size = "100";
if (path.size() > 1) {
username = path[1];
} else {
error = true;
}
// if (path.size() > 1) {
// username = path[1];
// } else {
// error = true;
// }
if (path.size() > 2) {
try {
if (std::stoi(path[2]) > 0)
avatar_size = path[2];
// if (path.size() > 2) {
// try {
// if (std::stoi(path[2]) > 0)
// avatar_size = path[2];
} catch (std::exception&) { }
}
// } catch (std::exception&) { }
// }
httplib::Result summary_res;
// httplib::Result summary_res;
if (!error) {
summary_res = forum.Get("/u/" + username + ".json", headers);
// if (!error) {
// summary_res = forum.Get("/u/" + username + ".json", headers);
if (!summary_res || summary_res->status != 200) {
error = true;
}
}
// if (!summary_res || summary_res->status != 200) {
// error = true;
// }
// }
if (!error) {
try {
nlohmann::json d = nlohmann::json::parse(summary_res->body, nullptr, false); // can fail with parse_error
// if (!error) {
// try {
// 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 avatar_link_json = user.at("avatar_template"); // 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 = avatar_link_json.get<std::string>();
size_t start_pos = avatar_link.find("{size}");
if (start_pos != std::string::npos)
avatar_link.replace(start_pos, std::strlen("{size}"), avatar_size);
// auto avatar_link = avatar_link_json.get<std::string>();
// size_t start_pos = avatar_link.find("{size}");
// if (start_pos != std::string::npos)
// 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&) {
error = true;
}
}
// } catch (std::exception&) {
// error = true;
// }
// }
if (error) {
cli_res = forum.Get("/user_avatar/forum.beammp.com/user/0/0.png", headers);
}
// if (error) {
// cli_res = forum.Get("/user_avatar/forum.beammp.com/user/0/0.png", headers);
// }
} else {
res.set_content("Host not found", "text/plain");
return;
}
// } else {
// res.set_content("Host not found", "text/plain");
// return;
// }
if (cli_res) {
res.set_content(cli_res->body, cli_res->get_header_value("Content-Type"));
} else {
res.set_content(to_string(cli_res.error()), "text/plain");
}
};
// if (cli_res) {
// res.set_content(cli_res->body, cli_res->get_header_value("Content-Type"));
// } else {
// res.set_content(to_string(cli_res.error()), "text/plain");
// }
// };
HTTPProxy.Get(pattern, [&](const httplib::Request& req, httplib::Response& res) {
handle_request(req, res);
});
// HTTPProxy.Get(pattern, [&](const httplib::Request& req, httplib::Response& res) {
// handle_request(req, res);
// });
HTTPProxy.Post(pattern, [&](const httplib::Request& req, httplib::Response& res) {
handle_request(req, res);
});
// HTTPProxy.Post(pattern, [&](const httplib::Request& req, httplib::Response& res) {
// handle_request(req, res);
// });
ProxyPort = HTTPProxy.bind_to_any_port("127.0.0.1");
debug("HTTP Proxy listening on port " + std::to_string(ProxyPort));
HTTPProxy.listen_after_bind();
});
proxy.detach();
// ProxyPort = HTTPProxy.bind_to_any_port("127.0.0.1");
// debug("HTTP Proxy listening on port " + std::to_string(ProxyPort));
// HTTPProxy.listen_after_bind();
// });
// proxy.detach();
}

View File

@@ -195,47 +195,44 @@ 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 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);
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
beammp_fs_string BP(GetBP() / GetEN()), Back(GetBP() / beammp_wide("BeamMP-Launcher.back"));
// transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
// beammp_fs_string BP(GetBP() / GetEN()), Back(GetBP() / beammp_wide("BeamMP-Launcher.back"));
std::string FileHash = Utils::GetSha256HashReallyFastFile(BP);
// std::string FileHash = Utils::GetSha256HashReallyFastFile(BP);
if (FileHash != LatestHash && IsOutdated(Version(VersionStrToInts(GetVer() + GetPatch())), Version(VersionStrToInts(LatestVersion)))) {
if (!options.no_update) {
info("Launcher update " + LatestVersion + " found!");
#if defined(__linux__)
error("Auto update is NOT implemented for the Linux version. Please update manually ASAP as updates contain security patches.");
#else
info("Downloading Launcher update " + LatestHash);
if (HTTP::Download(
"https://backend.beammp.com/builds/launcher?download=true"
"&pk="
+ PublicKey + "&branch=" + Branch,
GetBP() / (beammp_wide("new_") + GetEN()), LatestHash)) {
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 {
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++;
// if (FileHash != LatestHash && IsOutdated(Version(VersionStrToInts(GetVer() + GetPatch())), Version(VersionStrToInts(LatestVersion)))) {
// if (!options.no_update) {
// info("Launcher update " + LatestVersion + " found!");
// #if defined(__linux__)
// error("Auto update is NOT implemented for the Linux version. Please update manually ASAP as updates contain security patches.");
// #else
// info("Downloading Launcher update " + LatestHash);
// HTTP::Download(
// "https://backend.beammp.com/builds/launcher?download=true"
// "&pk="
// + PublicKey + "&branch=" + Branch,
// GetBP() / (beammp_wide("new_") + GetEN()), LatestHash);
// 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();
// #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++;
}
@@ -350,42 +347,42 @@ void PreGame(const beammp_fs_string& GamePath) {
CheckMP(GetGamePath() / beammp_wide("mods/multiplayer"));
info(beammp_wide("Game user path: ") + beammp_fs_string(GetGamePath()));
if (!options.no_download) {
std::string 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); }),
LatestHash.end());
// if (!options.no_download) {
// std::string 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); }),
// LatestHash.end());
try {
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
// try {
// 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
std::string FileHash = fs::exists(ZipPath) ? Utils::GetSha256HashReallyFastFile(ZipPath) : "";
// std::string FileHash = fs::exists(ZipPath) ? Utils::GetSha256HashReallyFastFile(ZipPath) : "";
if (FileHash != LatestHash) {
info("Downloading BeamMP Update " + LatestHash);
HTTP::Download("https://backend.beammp.com/builds/client?download=true"
"&pk="
+ PublicKey + "&branch=" + Branch,
ZipPath, LatestHash);
}
// if (FileHash != LatestHash) {
// info("Downloading BeamMP Update " + LatestHash);
// 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"));
// 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);
}
}
// if (fs::is_directory(Target) && !fs::is_directory(Target + beammp_wide("/.git"))) {
// fs::remove_all(Target);
// }
// }
}