Skip to content

Commit bcb035b

Browse files
authored
Provider env ip (#432)
Adds `BEAMMP_PROVIDER_IP_ENV` for hosting panels, which allows the server owner to configure which env var is read to get the ip interface to bind to. --- By creating this pull request, I understand that code that is AI generated or otherwise automatically generated may be rejected without further discussion. I declare that I fully understand all code I pushed into this PR, and wrote all this code myself and own the rights to this code.
2 parents b7cf304 + 068f553 commit bcb035b

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

include/Env.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ enum class Key {
2727
PROVIDER_UPDATE_MESSAGE,
2828
PROVIDER_DISABLE_CONFIG,
2929
PROVIDER_PORT_ENV,
30+
PROVIDER_IP_ENV
3031
};
3132

3233
std::optional<std::string> Get(Key key);

src/Env.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ std::string_view Env::ToString(Env::Key key) {
3939
case Key::PROVIDER_PORT_ENV:
4040
return "BEAMMP_PROVIDER_PORT_ENV";
4141
break;
42+
case Key::PROVIDER_IP_ENV:
43+
return "BEAMMP_PROVIDER_IP_ENV";
44+
break;
4245
}
4346
return "";
4447
}

src/TConfig.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,11 @@ void TConfig::ParseFromFile(std::string_view name) {
258258
} else {
259259
TryReadValue(data, "General", StrPort, EnvStrPort, Settings::Key::General_Port);
260260
}
261-
TryReadValue(data, "General", StrIP, EnvStrIP, Settings::Key::General_IP);
261+
if (Env::Get(Env::Key::PROVIDER_IP_ENV).has_value()) {
262+
TryReadValue(data, "General", StrIP, Env::Get(Env::Key::PROVIDER_IP_ENV).value(), Settings::Key::General_IP);
263+
} else {
264+
TryReadValue(data, "General", StrIP, EnvStrIP, Settings::Key::General_IP);
265+
}
262266
TryReadValue(data, "General", StrMaxCars, EnvStrMaxCars, Settings::Key::General_MaxCars);
263267
TryReadValue(data, "General", StrMaxPlayers, EnvStrMaxPlayers, Settings::Key::General_MaxPlayers);
264268
TryReadValue(data, "General", StrMap, EnvStrMap, Settings::Key::General_Map);
@@ -309,6 +313,7 @@ void TConfig::PrintDebug() {
309313
beammp_debug(std::string(StrPrivate) + ": " + std::string(Application::Settings.getAsBool(Settings::Key::General_Private) ? "true" : "false"));
310314
beammp_debug(std::string(StrInformationPacket) + ": " + std::string(Application::Settings.getAsBool(Settings::Key::General_InformationPacket) ? "true" : "false"));
311315
beammp_debug(std::string(StrPort) + ": " + std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port)));
316+
beammp_debug(std::string(StrIP) + ": \"" + Application::Settings.getAsString(Settings::Key::General_IP) + "\"");
312317
beammp_debug(std::string(StrMaxCars) + ": " + std::to_string(Application::Settings.getAsInt(Settings::Key::General_MaxCars)));
313318
beammp_debug(std::string(StrMaxPlayers) + ": " + std::to_string(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)));
314319
beammp_debug(std::string(StrMap) + ": \"" + Application::Settings.getAsString(Settings::Key::General_Map) + "\"");

0 commit comments

Comments
 (0)