From e393239fdccf532977aa5535fa53263f26ec43e6 Mon Sep 17 00:00:00 2001 From: SaltySnail Date: Tue, 23 Jun 2026 02:47:21 +0200 Subject: [PATCH] Add region tld --- include/Common.h | 13 +++++-------- include/Settings.h | 1 + src/Common.cpp | 32 ++++++++++++++++++++++++++++++++ src/Settings.cpp | 2 ++ src/TConfig.cpp | 5 +++++ 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/include/Common.h b/include/Common.h index 0e3416c..f835344 100644 --- a/include/Common.h +++ b/include/Common.h @@ -80,16 +80,13 @@ public: static inline struct Settings Settings { }; - static std::vector GetBackendUrlsInOrder() { - return { - "https://backend.beammp.com", - }; - } + static std::vector GetBackendUrlsInOrder(); - static std::string GetServerCheckUrl() { return "https://check.beammp.com"; } + static std::string GetServerCheckUrl(); - static std::string GetBackendUrlForAuth() { return "https://auth.beammp.com"; } - static std::string GetBackendUrlForSocketIO() { return "https://backend.beammp.com"; } + static std::string GetBackendUrlForAuth(); + static std::string GetBackendUrlForSocketIO(); + static std::string RegionToTopLevelDomain(const std::string region); static void CheckForUpdates(); static std::array VersionStrToInts(const std::string& str); static bool IsOutdated(const Version& Current, const Version& Newest); diff --git a/include/Settings.h b/include/Settings.h index f0c1a2c..2b9bda6 100644 --- a/include/Settings.h +++ b/include/Settings.h @@ -87,6 +87,7 @@ struct Settings { General_Debug, General_AllowGuests, General_InformationPacket, + General_Region, }; Sync> SettingsMap; diff --git a/src/Common.cpp b/src/Common.cpp index 1c769a3..1816389 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -73,6 +73,38 @@ std::string Application::ServerVersionString() { return mVersion.AsString(); } +std::vector Application::GetBackendUrlsInOrder() { + return { + "https://backend." + RegionToTopLevelDomain(Settings.getAsString(Settings::Key::General_Region)), + }; +} + +std::string Application::GetServerCheckUrl() +{ + return "https://check." + RegionToTopLevelDomain(Settings.getAsString(Settings::Key::General_Region)); +} + +std::string Application::GetBackendUrlForAuth() +{ + return "https://auth." + RegionToTopLevelDomain(Settings.getAsString(Settings::Key::General_Region)); +} + +std::string Application::GetBackendUrlForSocketIO() +{ + return "https://backend." + RegionToTopLevelDomain(Settings.getAsString(Settings::Key::General_Region)); +} + +std::string Application::RegionToTopLevelDomain(const std::string region) +{ + if (region == "Restricted") { + return "beammp.ru"; + } + else if (region == "Developer") { + return "beammp.dev"; + } + return "beammp.com"; // Global +} + std::array Application::VersionStrToInts(const std::string& str) { std::array Version; std::stringstream ss(str); diff --git a/src/Settings.cpp b/src/Settings.cpp index bb3c575..6d96d0f 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -36,6 +36,7 @@ Settings::Settings() { { General_Debug, false }, { General_AllowGuests, true }, { General_InformationPacket, true }, + { General_Region, std::string("Global")}, { Misc_ImScaredOfUpdates, true }, { Misc_UpdateReminderTime, "30s" } }; @@ -56,6 +57,7 @@ Settings::Settings() { { { "General", "Debug" }, { General_Debug, READ_WRITE } }, { { "General", "AllowGuests" }, { General_AllowGuests, READ_WRITE } }, { { "General", "InformationPacket" }, { General_InformationPacket, READ_WRITE } }, + { { "General", "Region" }, { General_Region, READ_WRITE } }, { { "Misc", "ImScaredOfUpdates" }, { Misc_ImScaredOfUpdates, READ_WRITE } }, { { "Misc", "UpdateReminderTime" }, { Misc_UpdateReminderTime, READ_WRITE } } }; diff --git a/src/TConfig.cpp b/src/TConfig.cpp index 818e00f..ce4b90b 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -52,6 +52,8 @@ static constexpr std::string_view StrTags = "Tags"; static constexpr std::string_view EnvStrTags = "BEAMMP_TAGS"; static constexpr std::string_view StrResourceFolder = "ResourceFolder"; static constexpr std::string_view EnvStrResourceFolder = "BEAMMP_RESOURCE_FOLDER"; +static constexpr std::string_view StrRegion = "Region"; +static constexpr std::string_view EnvStrRegion = "BEAMMP_REGION"; static constexpr std::string_view StrAuthKey = "AuthKey"; static constexpr std::string_view EnvStrAuthKey = "BEAMMP_AUTH_KEY"; static constexpr std::string_view StrLogChat = "LogChat"; @@ -151,6 +153,7 @@ void TConfig::FlushToFile() { data["General"][StrMap.data()] = Application::Settings.getAsString(Settings::Key::General_Map); data["General"][StrDescription.data()] = Application::Settings.getAsString(Settings::Key::General_Description); data["General"][StrResourceFolder.data()] = Application::Settings.getAsString(Settings::Key::General_ResourceFolder); + data["General"][StrRegion.data()] = Application::Settings.getAsString(Settings::Key::General_Region); // data["General"][StrPassword.data()] = Application::Settings.Password; // SetComment(data["General"][StrPassword.data()].comments(), " Sets a password on this server, which restricts people from joining. To join, a player must enter this exact password. Leave empty ("") to disable the password."); // Misc @@ -270,6 +273,7 @@ void TConfig::ParseFromFile(std::string_view name) { TryReadValue(data, "General", StrDescription, EnvStrDescription, Settings::Key::General_Description); TryReadValue(data, "General", StrTags, EnvStrTags, Settings::Key::General_Tags); TryReadValue(data, "General", StrResourceFolder, EnvStrResourceFolder, Settings::Key::General_ResourceFolder); + TryReadValue(data, "General", StrRegion, EnvStrRegion, Settings::Key::General_Region); TryReadValue(data, "General", StrAuthKey, EnvStrAuthKey, Settings::Key::General_AuthKey); TryReadValue(data, "General", StrLogChat, EnvStrLogChat, Settings::Key::General_LogChat); TryReadValue(data, "General", StrAllowGuests, EnvStrAllowGuests, Settings::Key::General_AllowGuests); @@ -322,6 +326,7 @@ void TConfig::PrintDebug() { beammp_debug(std::string(StrTags) + ": " + TagsAsPrettyArray()); beammp_debug(std::string(StrLogChat) + ": \"" + (Application::Settings.getAsBool(Settings::Key::General_LogChat) ? "true" : "false") + "\""); beammp_debug(std::string(StrResourceFolder) + ": \"" + Application::Settings.getAsString(Settings::Key::General_ResourceFolder) + "\""); + beammp_debug(std::string(StrRegion) + ": \"" + Application::Settings.getAsString(Settings::Key::General_Region) + "\""); beammp_debug(std::string(StrAllowGuests) + ": \"" + (Application::Settings.getAsBool(Settings::Key::General_AllowGuests) ? "true" : "false") + "\""); // special! beammp_debug("Key Length: " + std::to_string(Application::Settings.getAsString(Settings::Key::General_AuthKey).length()) + "");