mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-08-27 12:29:53 +00:00
Made regionhandler handled on http level
This commit is contained in:
+19
-1
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user