Remove restricted region

This commit is contained in:
SaltySnail committed 2026-06-25 18:35:42 +02:00
1 parent 52e607cf2c
commit d7277151cc
8 files changed
+104 -26

No files matched your search

+1 -1
View File
@@ -37,4 +37,4 @@ else(WIN32) #MINGW
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -s --static") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -s --static")
target_link_libraries(${PROJECT_NAME} ssl crypto ws2_32 ssp crypt32 z CURL::libcurl) target_link_libraries(${PROJECT_NAME} ssl crypto ws2_32 ssp crypt32 z CURL::libcurl)
endif(WIN32) endif(WIN32)
target_include_directories(${PROJECT_NAME} PRIVATE "include") target_include_directories(${PROJECT_NAME} PRIVATE "include" "include/Network")
+21
View File
@@ -0,0 +1,21 @@
/*
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
SPDX-License-Identifier: AGPL-3.0-or-later
*/
#pragma once
#include <vector>
#include <string>
#include <array>
class RegionHandler final {
public:
RegionHandler() = delete;
static void TopLevelDomainFailed(bool failed);
static std::string RegionToTopLevelDomain(const std::string region);
private:
static inline unsigned int mRegionIndex { 0 };
const static inline std::array<std::string, 2> mValidTLDs {"beammp.com", "beammp.ru"};
};
-10
View File
@@ -336,14 +336,4 @@ namespace Utils {
throw std::runtime_error("Game disconnected"); throw std::runtime_error("Game disconnected");
} }
} }
inline std::string RegionToTopLevelDomain(const std::string region) {
if (region == "Restricted") {
return "beammp.ru";
}
else if (region == "Developer") {
return "beammp.dev";
}
return "beammp.com"; // Global
}
}; };
+7 -1
View File
@@ -5,6 +5,7 @@
*/ */
#include "Http.h" #include "Http.h"
#include "RegionHandler.h"
#include "Network/network.hpp" #include "Network/network.hpp"
#include "Security/Init.h" #include "Security/Init.h"
#include "Utils.h" #include "Utils.h"
@@ -226,7 +227,12 @@ 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." + Utils::RegionToTopLevelDomain(options.region) + "/servers-info")); std::string resp = HTTP::Get("https://backend." + RegionHandler::RegionToTopLevelDomain(options.region) + "/servers-info");
if (resp == "") {
RegionHandler::TopLevelDomainFailed(true);
resp = HTTP::Get("https://backend." + RegionHandler::RegionToTopLevelDomain(options.region) + "/servers-info");
}
CoreSend("B" + resp);
})); }));
} }
break; break;
+4 -3
View File
@@ -6,6 +6,7 @@
#include "Http.h" #include "Http.h"
#include "RegionHandler.h"
#include "Options.h" #include "Options.h"
#include <Logger.h> #include <Logger.h>
#include <Network/network.hpp> #include <Network/network.hpp>
@@ -137,8 +138,8 @@ void HTTP::StartProxy() {
{ "User-Agent", "BeamMP-Launcher/" + GetVer() + GetPatch() }, { "User-Agent", "BeamMP-Launcher/" + GetVer() + GetPatch() },
{ "Accept", "*/*" } { "Accept", "*/*" }
}; };
httplib::Client backend("https://backend." + Utils::RegionToTopLevelDomain(options.region)); httplib::Client backend("https://backend." + RegionHandler::RegionToTopLevelDomain(options.region));
httplib::Client forum("https://forum." + Utils::RegionToTopLevelDomain(options.region)); httplib::Client forum("https://forum." + RegionHandler::RegionToTopLevelDomain(options.region));
const std::string pattern = ".*"; const std::string pattern = ".*";
@@ -217,7 +218,7 @@ void HTTP::StartProxy() {
} }
if (error) { if (error) {
cli_res = forum.Get("/user_avatar/forum." + Utils::RegionToTopLevelDomain(options.region) + "/user/0/0.png", headers); cli_res = forum.Get("/user_avatar/forum." + RegionHandler::RegionToTopLevelDomain(options.region) + "/user/0/0.png", headers);
} }
} else { } else {
+23
View File
@@ -0,0 +1,23 @@
/*
Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
Licensed under AGPL-3.0 (or later), see <https://www.gnu.org/licenses/>.
SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include "RegionHandler.h"
#include "Logger.h"
void RegionHandler::TopLevelDomainFailed(bool failed)
{
if (!failed) return;
info("Top level domain of " + mValidTLDs[mRegionIndex % mValidTLDs.size()] + " didn't respond correctly , changing domain to " + mValidTLDs[(mRegionIndex + 1) % mValidTLDs.size()]);
mRegionIndex++;
}
std::string RegionHandler::RegionToTopLevelDomain(const std::string region)
{
if (region == "Developer") {
return "beammp.dev";
}
return mValidTLDs[mRegionIndex % mValidTLDs.size()]; // Global
}
+11 -2
View File
@@ -7,6 +7,7 @@
#include "Http.h" #include "Http.h"
#include "Options.h" #include "Options.h"
#include "RegionHandler.h"
#include "Logger.h" #include "Logger.h"
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
@@ -56,7 +57,11 @@ std::string Login(const std::string& fields) {
} }
info("Attempting to authenticate..."); info("Attempting to authenticate...");
try { try {
std::string Buffer = HTTP::Post("https://auth." + Utils::RegionToTopLevelDomain(options.region) + "/userlogin", fields); std::string Buffer = HTTP::Post("https://auth." + RegionHandler::RegionToTopLevelDomain(options.region) + "/userlogin", fields);
if (Buffer == "") {
RegionHandler::TopLevelDomainFailed(true);
Buffer = HTTP::Post("https://auth." + RegionHandler::RegionToTopLevelDomain(options.region) + "/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!");
@@ -116,7 +121,11 @@ void CheckLocalKey() {
} }
} }
Buffer = HTTP::Post("https://auth." + Utils::RegionToTopLevelDomain(options.region) + "/userlogin", R"({"pk":")" + Buffer + "\"}"); Buffer = HTTP::Post("https://auth." + RegionHandler::RegionToTopLevelDomain(options.region) + "/userlogin", R"({"pk":")" + Buffer + "\"}");
if (Buffer == "") {
RegionHandler::TopLevelDomainFailed(true);
Buffer = HTTP::Post("https://auth." + RegionHandler::RegionToTopLevelDomain(options.region) + "/userlogin", R"({"pk":")" + Buffer + "\"}");
}
nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false); nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false);
+37 -9
View File
@@ -24,6 +24,7 @@
#include "Security/Init.h" #include "Security/Init.h"
#include "Startup.h" #include "Startup.h"
#include "Utils.h" #include "Utils.h"
#include "RegionHandler.h"
#include "hashpp.h" #include "hashpp.h"
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
@@ -331,9 +332,16 @@ bool VerifySignature(const std::filesystem::path& filePath)
#endif #endif
void CheckForUpdates(const std::string& CV) { void CheckForUpdates(const std::string& CV) {
std::string LatestHash = HTTP::Get("https://backend." + Utils::RegionToTopLevelDomain(options.region) + "/sha/launcher?branch=" + Branch + "&pk=" + PublicKey); std::string LatestHash = HTTP::Get("https://backend." + RegionHandler::RegionToTopLevelDomain(options.region) + "/sha/launcher?branch=" + Branch + "&pk=" + PublicKey);
std::string LatestVersion = HTTP::Get( if (LatestHash == "") {
"https://backend." + Utils::RegionToTopLevelDomain(options.region) + "/version/launcher?branch=" + Branch + "&pk=" + PublicKey); RegionHandler::TopLevelDomainFailed(true);
LatestHash = HTTP::Get("https://backend." + RegionHandler::RegionToTopLevelDomain(options.region) + "/sha/launcher?branch=" + Branch + "&pk=" + PublicKey);
}
std::string LatestVersion = HTTP::Get("https://backend." + RegionHandler::RegionToTopLevelDomain(options.region) + "/version/launcher?branch=" + Branch + "&pk=" + PublicKey);
if (LatestVersion == "") {
RegionHandler::TopLevelDomainFailed(true);
LatestVersion = HTTP::Get("https://backend." + RegionHandler::RegionToTopLevelDomain(options.region) + "/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;
@@ -357,11 +365,21 @@ void CheckForUpdates(const std::string& CV) {
#else #else
info("Downloading Launcher update " + LatestHash); info("Downloading Launcher update " + LatestHash);
std::wstring DownloadLocation = GetBP() / (beammp_wide("new_") + GetEN()); std::wstring DownloadLocation = GetBP() / (beammp_wide("new_") + GetEN());
if (HTTP::Download( bool downloadSuccess = false;
"https://backend." + Utils::RegionToTopLevelDomain(options.region) + "/builds/launcher?download=true" downloadSuccess = HTTP::Download(
"https://backend." + RegionHandler::RegionToTopLevelDomain(options.region) + "/builds/launcher?download=true"
"&pk=" "&pk="
+ PublicKey + "&branch=" + Branch, + PublicKey + "&branch=" + Branch,
DownloadLocation, LatestHash)) { DownloadLocation, LatestHash);
if (!downloadSuccess) {
RegionHandler::TopLevelDomainFailed(true);
downloadSuccess = HTTP::Download(
"https://backend." + RegionHandler::RegionToTopLevelDomain(options.region) + "/builds/launcher?download=true"
"&pk="
+ PublicKey + "&branch=" + Branch,
DownloadLocation, LatestHash);
}
if (downloadSuccess) {
if (!VerifySignature(DownloadLocation) || !CheckThumbprint(DownloadLocation)) { if (!VerifySignature(DownloadLocation) || !CheckThumbprint(DownloadLocation)) {
std::error_code ec; std::error_code ec;
fs::remove(DownloadLocation, ec); fs::remove(DownloadLocation, ec);
@@ -514,7 +532,11 @@ void PreGame(const beammp_fs_string& GamePath) {
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." + Utils::RegionToTopLevelDomain(options.region) + "/sha/mod?branch=" + Branch + "&pk=" + PublicKey); std::string LatestHash = HTTP::Get("https://backend." + RegionHandler::RegionToTopLevelDomain(options.region) + "/sha/mod?branch=" + Branch + "&pk=" + PublicKey);
if (LatestHash == "") {
RegionHandler::TopLevelDomainFailed(true);
LatestHash = HTTP::Get("https://backend." + RegionHandler::RegionToTopLevelDomain(options.region) + "/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); }),
@@ -548,10 +570,16 @@ void PreGame(const beammp_fs_string& GamePath) {
if (FileHash != LatestHash) { if (FileHash != LatestHash) {
info("Downloading BeamMP Update " + LatestHash); info("Downloading BeamMP Update " + LatestHash);
HTTP::Download("https://backend." + Utils::RegionToTopLevelDomain(options.region) + "/builds/client?download=true" if (!HTTP::Download("https://backend." + RegionHandler::RegionToTopLevelDomain(options.region) + "/builds/client?download=true"
"&pk=" "&pk="
+ PublicKey + "&branch=" + Branch, + PublicKey + "&branch=" + Branch,
ZipPath, LatestHash); ZipPath, LatestHash)) {
RegionHandler::TopLevelDomainFailed(true);
HTTP::Download("https://backend." + RegionHandler::RegionToTopLevelDomain(options.region) + "/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"));