mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 02:43:44 +00:00
feat: bind_ip setting for the server sockets
bind_ip in sharedconfig.ini picks the local IPv4 address every server's RakNet sockets listen on (auth, chat, master, world, the dashboard's connection to master), separate from external_ip, the address players are sent. Empty or 0.0.0.0 keeps listening on all interfaces; localhost means 127.0.0.1. Anything that isn't an IPv4 address stops the server with an error, and each server logs what it bound to. Fixes #225 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -271,6 +271,26 @@ std::vector<std::u16string> GeneralUtils::SplitString(const std::u16string_view
|
||||
return vector;
|
||||
}
|
||||
|
||||
std::optional<std::string> GeneralUtils::ParseBindAddress(const std::string_view value) {
|
||||
const auto first = value.find_first_not_of(" \t\r\n");
|
||||
if (first == std::string_view::npos) return std::string{};
|
||||
const auto trimmed = value.substr(first, value.find_last_not_of(" \t\r\n") - first + 1);
|
||||
|
||||
if (trimmed == "*" || trimmed == "0.0.0.0") return std::string{};
|
||||
if (CaseInsensitiveStringCompare(trimmed, "localhost")) return std::string{ "127.0.0.1" };
|
||||
|
||||
// Dotted quad only: four decimal octets of 0-255, no signs, no empty parts, no leading zeros that read as octal
|
||||
const auto octets = SplitString(trimmed, '.');
|
||||
if (octets.size() != 4) return std::nullopt;
|
||||
for (const auto& octet : octets) {
|
||||
if (octet.empty() || octet.size() > 3) return std::nullopt;
|
||||
if (octet.find_first_not_of("0123456789") != std::string::npos) return std::nullopt;
|
||||
if (octet.size() > 1 && octet[0] == '0') return std::nullopt;
|
||||
if (std::stoi(octet) > 255) return std::nullopt;
|
||||
}
|
||||
return std::string{ trimmed };
|
||||
}
|
||||
|
||||
std::vector<std::string> GeneralUtils::SplitString(const std::string_view str, const char delimiter) {
|
||||
std::vector<std::string> vector = std::vector<std::string>();
|
||||
std::string current = "";
|
||||
|
||||
@@ -153,6 +153,12 @@ namespace GeneralUtils {
|
||||
|
||||
std::vector<std::string> GetSqlFileNamesFromFolder(const std::string_view folder);
|
||||
|
||||
/**
|
||||
* Reads a bind address setting (bind_ip). Returns the IPv4 address to bind to, an empty string for all
|
||||
* interfaces (empty, "*" or "0.0.0.0"), "127.0.0.1" for "localhost", or nullopt when the value isn't an IPv4 address.
|
||||
*/
|
||||
[[nodiscard]] std::optional<std::string> ParseBindAddress(const std::string_view value);
|
||||
|
||||
/**
|
||||
* Transparent string hasher - used to allow string_view key lookups for maps storing std::string keys
|
||||
* https://www.reddit.com/r/cpp_questions/comments/12xw3sn/find_stdstring_view_in_unordered_map_with/jhki225/
|
||||
|
||||
Reference in New Issue
Block a user