Made regionhandler handled on http level

This commit is contained in:
SaltySnail
2026-07-19 02:53:27 +02:00
parent 75d844d5a6
commit a3d50be997
5 changed files with 37 additions and 9 deletions
+19 -1
View File
@@ -19,9 +19,14 @@
#include "RegionHandler.h"
#include "Common.h"
#include <regex>
void RegionHandler::TopLevelDomainFailed()
{
beammp_info("Top level domain of " + mValidTLDs[mRegionIndex % mValidTLDs.size()] + " didn't respond correctly , changing domain to " + mValidTLDs[(mRegionIndex + 1) % mValidTLDs.size()]);
static bool isDeveloperRegion = Application::Settings.getAsString(Settings::Key::General_Region) == "Developer";
if (!isDeveloperRegion) {
beammp_info("Top level domain of " + mValidTLDs[mRegionIndex % mValidTLDs.size()] + " didn't respond correctly , changing domain to " + mValidTLDs[(mRegionIndex + 1) % mValidTLDs.size()]);
}
mRegionIndex++;
}
@@ -33,3 +38,16 @@ std::string RegionHandler::RegionToTopLevelDomain()
}
return mValidTLDs[mRegionIndex % mValidTLDs.size()]; // Global
}
std::string RegionHandler::RedirectURL(const std::string &URL)
{
std::regex link_pattern(R"(^(https:\/\/.*)beammp\.com(\/.*)?$)");
std::smatch link_match;
if (std::regex_search(URL, link_match, link_pattern) && link_match.position() == 0) {
//TLD matched beammp.com
std::string before = link_match[1].str(); // "https://..." up to beammp
std::string after = link_match[2].matched ? link_match[2].str() : ""; // "/path" or ""
return before + RegionToTopLevelDomain() + after;
}
return URL; //if it didn't match, just return the unmodified URL
}