Remove restricted region

This commit is contained in:
SaltySnail
2026-06-25 18:37:38 +02:00
parent 7f3ea9c626
commit 814da1e9ff
8 changed files with 95 additions and 6 deletions
+10 -5
View File
@@ -94,15 +94,20 @@ std::string Application::GetBackendUrlForSocketIO()
return "https://backend." + RegionToTopLevelDomain(Settings.getAsString(Settings::Key::General_Region));
}
void Application::TopLevelDomainFailed(bool failed)
{
if (failed) {
beammp_info("Top Level Domain (" + mValidTLDs[mTLDIndex % mValidTLDs.size()] + ") failed to respond correctly, switching to " + mValidTLDs[(mTLDIndex + 1) % mValidTLDs.size()]);
mTLDIndex++;
}
}
std::string Application::RegionToTopLevelDomain(const std::string region)
{
if (region == "Restricted") {
return "beammp.ru";
}
else if (region == "Developer") {
if (region == "Developer") {
return "beammp.dev";
}
return "beammp.com"; // Global
return mValidTLDs[mTLDIndex % mValidTLDs.size()]; // Global
}
std::array<uint8_t, 3> Application::VersionStrToInts(const std::string& str) {
+35
View File
@@ -0,0 +1,35 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "RegionHandler.h"
#include "Common.h"
void RegionHandler::TopLevelDomainFailed(bool failed)
{
if (!failed) return;
beammp_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
}
+4
View File
@@ -297,6 +297,10 @@ void TConsole::Command_NetTest(const std::string& cmd, const std::vector<std::st
std::string T = Http::GET(
Application::GetServerCheckUrl() + "/api/v2/beammp/" + std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port)), &status);
if (T == Http::ErrorString || status != 200) {
Application::TopLevelDomainFailed(true);
T = Http::GET(Application::GetServerCheckUrl() + "/api/v2/beammp/" + std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port)), &status);
}
beammp_debugf("Status and response from Server Check API: {0}, {1}", status, T);
+4 -1
View File
@@ -24,7 +24,6 @@
#include "Http.h"
// #include "SocketIO.h"
#include <nlohmann/json.hpp>
#include <sstream>
void THeartbeatThread::operator()() {
RegisterThread("Heartbeat");
@@ -63,6 +62,10 @@ void THeartbeatThread::operator()() {
bool Ok = false;
for (const auto& Url : Application::GetBackendUrlsInOrder()) {
T = Http::POST(Url + Target, Body, "application/json", &ResponseCode, { { "api-v", "2" } });
if (T == Http::ErrorString || ResponseCode != 200) {
Application::TopLevelDomainFailed(true);
T = Http::POST(Url + Target, Body, "application/json", &ResponseCode, { { "api-v", "2" } });
}
if (!Application::Settings.getAsBool(Settings::Key::General_Private)) {
beammp_debug("Backend response was: `" + T + "`");
+4
View File
@@ -457,6 +457,10 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
unsigned int ResponseCode = 0;
AuthResStr = Http::POST(Application::GetBackendUrlForAuth() + Target, AuthReq.dump(), "application/json", &ResponseCode);
if (AuthResStr == Http::ErrorString || ResponseCode != 200) {
Application::TopLevelDomainFailed(true);
AuthResStr = Http::POST(Application::GetBackendUrlForAuth() + Target, AuthReq.dump(), "application/json", &ResponseCode);
}
} catch (const std::exception& e) {
beammp_debugf("Invalid json sent by client, kicking: {}", e.what());