diff --git a/include/Settings.h b/include/Settings.h index f0c1a2c7..5253ef4d 100644 --- a/include/Settings.h +++ b/include/Settings.h @@ -81,6 +81,7 @@ struct Settings { General_Private, General_IP, General_Port, + General_RegisterIPv6, General_MaxCars, General_LogChat, General_ResourceFolder, diff --git a/src/Http.cpp b/src/Http.cpp index 98bb6ce2..a565b1d8 100644 --- a/src/Http.cpp +++ b/src/Http.cpp @@ -119,11 +119,12 @@ std::string Http::GET(const std::string& url, unsigned int* status) { std::string Ret; CurlLease Lease{}; CURL* curl = Lease.GetHandle(); + bool Register_IPv6 = Application::Settings.getAsBool(Settings::Key::General_RegisterIPv6); if (curl) { CURLcode res; char errbuf[CURL_ERROR_SIZE]; curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + curl_easy_setopt(curl, CURLOPT_IPRESOLVE, Register_IPv6 ? CURL_IPRESOLVE_V6 : CURL_IPRESOLVE_V4); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, reinterpret_cast(&Ret)); @@ -160,11 +161,12 @@ std::string Http::POST(const std::string& url, const std::string& body, const st std::string Ret; CurlLease Lease{}; CURL* curl = Lease.GetHandle(); + bool Register_IPv6 = Application::Settings.getAsBool(Settings::Key::General_RegisterIPv6); if (curl) { CURLcode res; char errbuf[CURL_ERROR_SIZE]; curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + curl_easy_setopt(curl, CURLOPT_IPRESOLVE, Register_IPv6 ? CURL_IPRESOLVE_V6 : CURL_IPRESOLVE_V4); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, reinterpret_cast(&Ret)); curl_easy_setopt(curl, CURLOPT_POST, 1L); diff --git a/src/Settings.cpp b/src/Settings.cpp index bb3c5754..fa227b7e 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -30,6 +30,7 @@ Settings::Settings() { { General_Private, true }, { General_IP, "::"}, { General_Port, 30814 }, + { General_RegisterIPv6, false }, { General_MaxCars, 1 }, { General_LogChat, true }, { General_ResourceFolder, std::string("Resources") }, @@ -50,6 +51,7 @@ Settings::Settings() { { { "General", "Private" }, { General_Private, READ_ONLY } }, { { "General", "IP" }, { General_IP, READ_ONLY } }, { { "General", "Port" }, { General_Port, READ_ONLY } }, + { { "General", "RegisterIPv6" }, { General_RegisterIPv6, READ_ONLY } }, { { "General", "MaxCars" }, { General_MaxCars, READ_WRITE } }, { { "General", "LogChat" }, { General_LogChat, READ_ONLY } }, { { "General", "ResourceFolder" }, { General_ResourceFolder, READ_ONLY } }, diff --git a/src/TConfig.cpp b/src/TConfig.cpp index 818e00fe..fd6f9a60 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -38,6 +38,8 @@ static constexpr std::string_view StrIP = "IP"; static constexpr std::string_view EnvStrIP = "BEAMMP_IP"; static constexpr std::string_view StrPort = "Port"; static constexpr std::string_view EnvStrPort = "BEAMMP_PORT"; +static constexpr std::string_view StrRegisterIPv6 = "RegisterIPv6"; +static constexpr std::string_view EnvStrRegisterIPv6 = "BEAMMP_REGISTER_IPV6"; static constexpr std::string_view StrMaxCars = "MaxCars"; static constexpr std::string_view EnvStrMaxCars = "BEAMMP_MAX_CARS"; static constexpr std::string_view StrMaxPlayers = "MaxPlayers"; @@ -144,6 +146,8 @@ void TConfig::FlushToFile() { SetComment(data["General"][StrIP.data()].comments(), " The IP address to bind the server to, this is NOT related to your public IP. Can be used if your machine has multiple network interfaces"); data["General"][StrPort.data()] = Application::Settings.getAsInt(Settings::Key::General_Port); data["General"][StrName.data()] = Application::Settings.getAsString(Settings::Key::General_Name); + SetComment(data["General"][StrRegisterIPv6.data()].comments(), " If true, connect to and register with your public IPv6 (instead of IPv4) address on the backend"); + data["General"][StrRegisterIPv6.data()] = Application::Settings.getAsBool(Settings::Key::General_RegisterIPv6); SetComment(data["General"][StrTags.data()].comments(), " Add custom identifying tags to your server to make it easier to find. Format should be TagA,TagB,TagC. Note the comma seperation."); data["General"][StrTags.data()] = Application::Settings.getAsString(Settings::Key::General_Tags); data["General"][StrMaxCars.data()] = Application::Settings.getAsInt(Settings::Key::General_MaxCars); @@ -263,6 +267,7 @@ void TConfig::ParseFromFile(std::string_view name) { } else { TryReadValue(data, "General", StrIP, EnvStrIP, Settings::Key::General_IP); } + TryReadValue(data, "General", StrRegisterIPv6, EnvStrRegisterIPv6, Settings::Key::General_RegisterIPv6); TryReadValue(data, "General", StrMaxCars, EnvStrMaxCars, Settings::Key::General_MaxCars); TryReadValue(data, "General", StrMaxPlayers, EnvStrMaxPlayers, Settings::Key::General_MaxPlayers); TryReadValue(data, "General", StrMap, EnvStrMap, Settings::Key::General_Map); @@ -314,6 +319,7 @@ void TConfig::PrintDebug() { beammp_debug(std::string(StrInformationPacket) + ": " + std::string(Application::Settings.getAsBool(Settings::Key::General_InformationPacket) ? "true" : "false")); beammp_debug(std::string(StrPort) + ": " + std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port))); beammp_debug(std::string(StrIP) + ": \"" + Application::Settings.getAsString(Settings::Key::General_IP) + "\""); + beammp_debug(std::string(StrRegisterIPv6) + ": \"" + (Application::Settings.getAsBool(Settings::Key::General_RegisterIPv6) ? "true" : "false") + "\""); beammp_debug(std::string(StrMaxCars) + ": " + std::to_string(Application::Settings.getAsInt(Settings::Key::General_MaxCars))); beammp_debug(std::string(StrMaxPlayers) + ": " + std::to_string(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers))); beammp_debug(std::string(StrMap) + ": \"" + Application::Settings.getAsString(Settings::Key::General_Map) + "\"");