Add region tld

This commit is contained in:
SaltySnail
2026-06-23 02:47:21 +02:00
parent 54f49d81e2
commit e393239fdc
5 changed files with 45 additions and 8 deletions
+5 -8
View File
@@ -80,16 +80,13 @@ public:
static inline struct Settings Settings { };
static std::vector<std::string> GetBackendUrlsInOrder() {
return {
"https://backend.beammp.com",
};
}
static std::vector<std::string> 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<uint8_t, 3> VersionStrToInts(const std::string& str);
static bool IsOutdated(const Version& Current, const Version& Newest);
+1
View File
@@ -87,6 +87,7 @@ struct Settings {
General_Debug,
General_AllowGuests,
General_InformationPacket,
General_Region,
};
Sync<std::unordered_map<Key, SettingsTypeVariant>> SettingsMap;
+32
View File
@@ -73,6 +73,38 @@ std::string Application::ServerVersionString() {
return mVersion.AsString();
}
std::vector<std::string> 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<uint8_t, 3> Application::VersionStrToInts(const std::string& str) {
std::array<uint8_t, 3> Version;
std::stringstream ss(str);
+2
View File
@@ -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 } }
};
+5
View File
@@ -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()) + "");