mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-07-12 17:54:04 +00:00
Remove restricted region
This commit is contained in:
@@ -55,6 +55,7 @@ set(PRJ_HEADERS
|
||||
include/ChronoWrapper.h
|
||||
include/TConnectionLimiter.h
|
||||
include/TLuaResult.h
|
||||
include/RegionHandler.h
|
||||
)
|
||||
# add all source files (.cpp) to this, except the one with main()
|
||||
set(PRJ_SOURCES
|
||||
@@ -84,6 +85,7 @@ set(PRJ_SOURCES
|
||||
src/ChronoWrapper.cpp
|
||||
src/TConnectionLimiter.cpp
|
||||
src/TLuaResult.cpp
|
||||
src/RegionHandler.cpp
|
||||
)
|
||||
|
||||
find_package(Lua REQUIRED)
|
||||
|
||||
@@ -86,6 +86,7 @@ public:
|
||||
|
||||
static std::string GetBackendUrlForAuth();
|
||||
static std::string GetBackendUrlForSocketIO();
|
||||
static void TopLevelDomainFailed(bool failed);
|
||||
static std::string RegionToTopLevelDomain(const std::string region);
|
||||
static void CheckForUpdates();
|
||||
static std::array<uint8_t, 3> VersionStrToInts(const std::string& str);
|
||||
@@ -125,6 +126,8 @@ private:
|
||||
static inline bool mShutdown { false };
|
||||
static inline std::mutex mShutdownHandlersMutex {};
|
||||
static inline std::deque<TShutdownHandler> mShutdownHandlers {};
|
||||
static inline int mTLDIndex { 0 };
|
||||
static inline std::vector<std::string> mValidTLDs {"beammp.com", "beammp.ru"};
|
||||
|
||||
static inline Version mVersion { 3, 9, 3 };
|
||||
};
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// 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/>.
|
||||
|
||||
#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
-5
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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 + "`");
|
||||
|
||||
@@ -440,6 +440,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());
|
||||
|
||||
Reference in New Issue
Block a user