diff --git a/Dockerfile b/Dockerfile index f5454c5..c84d49a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -154,25 +154,30 @@ ENV DEBIAN_FRONTEND=noninteractive \ # Gameserver start settings MULTITHREAD_ENABLED=true \ COMMUNITY_SERVER=true \ - # Config setting - Warning: using 'auto' will overwrite the settings in the config file with the environment variables + # Config setting - Warning: using 'auto' will overwrite the settings in the PalWorldSettings file with the environment variables SERVER_SETTINGS_MODE=auto \ + # Engine Configuration Mode: + # - 'full' will overwrite the settings in the config file with the environment variables or default values + # - 'modular' will only set the settings in the config file when the corresponding environment variable is set and not empty + # - 'skip' will skip the configuration of the settings in the config file + ENGINE_CONFIG_MODE=modular \ # Engine.ini - LAN_SERVER_MAX_TICK_RATE=120 \ + LAN_SERVER_MAX_TICK_RATE= \ NET_SERVER_MAX_TICK_RATE=120 \ - CONFIGURED_INTERNET_SPEED=104857600 \ - CONFIGURED_LAN_SPEED=104857600 \ - MAX_CLIENT_RATE=104857600 \ - MAX_INTERNET_CLIENT_RATE=104857600 \ - SMOOTH_FRAME_RATE=true \ - SMOOTH_FRAME_RATE_UPPER_BOUND=30.000000 \ - SMOOTH_FRAME_RATE_LOWER_BOUND=120.000000 \ - MIN_DESIRED_FRAME_RATE=60.000000 \ - USE_FIXED_FRAME_RATE=false \ - FIXED_FRAME_RATE=120.000000 \ - NET_CLIENT_TICKS_PER_SECOND=120 \ - TIME_BETWEEN_PURGING_PENDING_KILL_OBJECTS=30 \ - THREADED_RENDERING=true \ - THREADED_PHYSICS=true \ + CONFIGURED_INTERNET_SPEED= \ + CONFIGURED_LAN_SPEED= \ + MAX_CLIENT_RATE= \ + MAX_INTERNET_CLIENT_RATE= \ + SMOOTH_FRAME_RATE= \ + SMOOTH_FRAME_RATE_UPPER_BOUND= \ + SMOOTH_FRAME_RATE_LOWER_BOUND= \ + MIN_DESIRED_FRAME_RATE= \ + USE_FIXED_FRAME_RATE= \ + FIXED_FRAME_RATE= \ + NET_CLIENT_TICKS_PER_SECOND= \ + TIME_BETWEEN_PURGING_PENDING_KILL_OBJECTS= \ + THREADED_RENDERING= \ + THREADED_PHYSICS= \ # PalWorldSettings.ini DIFFICULTY=None \ DAY_TIME_SPEEDRATE=1.000000 \ diff --git a/default.env b/default.env index 964f19f..ae4a631 100644 --- a/default.env +++ b/default.env @@ -86,26 +86,34 @@ MULTITHREAD_ENABLED=true # Enable this if you want your server to show up in the community servers tab, USE WITH SERVER_PASSWORD! COMMUNITY_SERVER=false -# Config-setting - Warning: Every setting below here will be affected! +# Server Configuration Mode - Warning: Every setting below here will be affected! +# - `auto`: Modify configuration files with by env vars, file will be overwritten always +# - `manual`: Modify only by editing the file directly, environment variables are ignored SERVER_SETTINGS_MODE=auto +# Engine Configuration Mode (only used when SERVER_SETTINGS_MODE is set to 'auto'): +# - 'full' will overwrite the settings in the config file with the environment variables or default values +# - 'modular' will only set the settings in the config file when the corresponding environment variable is set and not empty +# - 'skip' will skip the configuration of the settings in the config file +ENGINE_CONFIG_MODE=modular + # Engine.ini settings -LAN_SERVER_MAX_TICK_RATE=120 +LAN_SERVER_MAX_TICK_RATE= NET_SERVER_MAX_TICK_RATE=120 -CONFIGURED_INTERNET_SPEED=104857600 -CONFIGURED_LAN_SPEED=104857600 -MAX_CLIENT_RATE=104857600 -MAX_INTERNET_CLIENT_RATE=104857600 -SMOOTH_FRAME_RATE=true -SMOOTH_FRAME_RATE_UPPER_BOUND=30.000000 -SMOOTH_FRAME_RATE_LOWER_BOUND=120.000000 -MIN_DESIRED_FRAME_RATE=60.000000 -USE_FIXED_FRAME_RATE=false -FIXED_FRAME_RATE=120.000000 -NET_CLIENT_TICKS_PER_SECOND=120 -TIME_BETWEEN_PURGING_PENDING_KILL_OBJECTS=30 -THREADED_RENDERING=true -THREADED_PHYSICS=true +CONFIGURED_INTERNET_SPEED= +CONFIGURED_LAN_SPEED= +MAX_CLIENT_RATE= +MAX_INTERNET_CLIENT_RATE= +SMOOTH_FRAME_RATE= +SMOOTH_FRAME_RATE_UPPER_BOUND= +SMOOTH_FRAME_RATE_LOWER_BOUND= +MIN_DESIRED_FRAME_RATE= +USE_FIXED_FRAME_RATE= +FIXED_FRAME_RATE= +NET_CLIENT_TICKS_PER_SECOND= +TIME_BETWEEN_PURGING_PENDING_KILL_OBJECTS= +THREADED_RENDERING= +THREADED_PHYSICS= # PalWorldSettings.ini settings DIFFICULTY=None diff --git a/docs/ENV_VARS.md b/docs/ENV_VARS.md index 11ee3fb..30dc3e6 100644 --- a/docs/ENV_VARS.md +++ b/docs/ENV_VARS.md @@ -9,8 +9,9 @@ Due to the extensive control options, the settings are split into categories: - [TZ identifiers](#tz-identifiers) - [Dedicated Server Settings](#dedicated-server-settings) - [Special Features](#special-features) - - [Server Settings](#server-settings) - [Cron expression](#cron-expression) + - [Server Settings](#server-settings) + - [Engine Configuration Mode](#engine-configuration-mode) - [Engine Settings](#engine-settings) - [Palworld Game Settings](#palworld-game-settings) - [Webhook Settings](#webhook-settings) @@ -73,22 +74,6 @@ These settings control the special features of the server: | `PLAYER_MONITOR_ENABLED` | Enables player monitoring for the server | `false` | `false`/`true` | | `PLAYER_MONITOR_INTERVAL` | The interval in seconds for the player monitoring (lower values means more impact on system resources) | `60` | Integer | - -### Server Settings - -| Variable | Description | Default value | Allowed value | -| ---------------------- | -------------------------------------------------------------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `MULTITHREAD_ENABLED` | Sets options for "Improved multi-threaded CPU " | `true` | `false`/`true` | -| `COMMUNITY_SERVER` | Set to enabled, the server will appear in the Community Server list | `true` | `false`/`true` | -| `SERVER_SETTINGS_MODE` | Whether settings (game and engine) are configured via env vars or via file | `auto` | `auto`: Modified by env vars, file will be overwritten always
`manual`: Modified only by editing the file directly, environment variables are ignored | - -> [!IMPORTANT] -> -> Take special attention to `SERVER_SETTINGS_MODE`, if you want to change the server settings via environment variables use the default value (`auto`), otherwise change it to `manual` and edit the config file directly. -> The RCON config file will be configured accordingly to the `SERVER_SETTINGS_MODE` value. -> If you change the `SERVER_SETTINGS_MODE` to `manual`, it will grab the settings from the file and ignore the environment variables. -> If you change the `SERVER_SETTINGS_MODE` to `auto`, it will grab the settings from the environment variables and ignore the file. - #### Cron expression In a Cron-Expression, you define an interval for when to run jobs. @@ -100,8 +85,53 @@ Default values for the cron expressions: - Auto updates: `0 3 * * *` (Every day at 3am) - Auto backups: `0 * * * *` (Every hour) +### Server Settings + +| Variable | Description | Default value | Allowed value | +| --------------------- | ------------------------------------------------------------------- | ------------- | -------------- | +| `MULTITHREAD_ENABLED` | Sets options for "Improved multi-threaded CPU" | `true` | `false`/`true` | +| `COMMUNITY_SERVER` | Set to enabled, the server will appear in the Community Server list | `true` | `false`/`true` | + +> [!IMPORTANT] +> +> Take special attention to `SERVER_SETTINGS_MODE`, if you want to change the server settings via environment variables use the default value (`auto`), otherwise change it to `manual` and edit the config file directly. + +This setting controls how the server settings files (`PalWorldSettings.ini` and `Engine.ini`) are configured: + - `auto`: will use environment variables to configure the files + - `manual`: will skip the configuration of the files and files will have to be edited manually + +| Variable | Description | Default value | Allowed value | +| ---------------------- | --------------------------------------------------------------------------------- | ------------- | --------------- | +| `SERVER_SETTINGS_MODE` | Whether settings are configured via environment variables or manually on the file | `auto` | `auto`/`manual` | + +> [!NOTE] +> +> For `PalWorldSettings.ini`, all settings with empty values (e.g. `EXP_RATE=""`) will be overwritten the default value. +> For `Engine.ini` refer to the [Engine Settings](#engine-settings) section for more information. +> +> The rules below apply to both `PalWorldSettings.ini` and `Engine.ini`: +> All settings which are in a wrong format (putting a string in a float variable like `EXP_RATE="very_fast"`) will be ignored and the default value will be used instead. +> Integers on float variables will be converted to floats (e.g. `EXP_RATE=2` will be converted to `2.000000`). +> Floats with more than 6 decimal places will be rounded to 6 decimal places (e.g. `EXP_RATE=2.123456789` will be converted to `2.123457`). +> Variables where we have multiple options (like `DIFFICULTY`) will always be converted to lowercase (e.g. `DIFFICULTY="Normal"` will be converted to `difficulty="normal"`) to maintain consistency. + +### Engine Configuration Mode + +When `SERVER_SETTINGS_MODE` is set to `auto`, we will use environment variables to configure the engine settings. + +The `ENGINE_CONFIG_MODE` environment variable controls how the engine settings are configured: + - `full`: will add all the settings in the Engine.ini.template file with the environment variables values or the default values for those settings + - `modular`: will only set the settings in the engine file when the corresponding environment variable is set and not empty + - `skip`: will always skip the configuration of the settings in the engine file (even if `SERVER_SETTINGS_MODE` to `auto`) + +| Variable | Description | Default value | Allowed value | +| -------------------- | ----------------------------------- | ------------- | ----------------------- | +| `ENGINE_CONFIG_MODE` | How `Engine.ini` file is configured | `modular` | `full`/`modular`/`skip` | + ### Engine Settings +This section contains all the settings currently adjustable via environment variables, based on the **order** and **contents of the [`Engine.ini.template`](../scripts/config/templates/Engine.ini.template)**. + | Variable | Game setting | Description | Default value | Allowed value | | ------------------------------------------- | ------------------------------------ | --------------------------------------------------------------------------------------------------------------- | ------------- | ------------------- | | `LAN_SERVER_MAX_TICK_RATE` | LanServerMaxTickRate | Changes the TickRate of the server, be very careful with this! | `120` | Integer | @@ -129,9 +159,9 @@ Default values for the cron expressions: ### Palworld Game Settings -This section lists all the settings currently adjustable via Docker environment variables, based on the **order** and **contents of the DefaultPalWorldSettings.ini**. -Information sources and credits to the following websites: +This section lists all the settings currently adjustable via environment variables, based on the **order** and **contents of the [`PalWorldSettings.ini.template`](../scripts/config/templates/PalWorldSettings.ini.template)** (which is the same as `DefaultPalWorldSettings.ini`). +Information sources and credits to the following websites: - [Palworld Official Tech Guide](https://tech.palworldgame.com/settings-and-operation/configuration) for the game server documentation - [Palworld Setting Generator](https://dysoncheng.github.io/PalWorldSettingGenerator/setting.html) for variable descriptions - [Palworld Unofficial Wiki](https://palworld.wiki.gg/wiki/PalWorldSettings.ini) for variable descriptions @@ -341,6 +371,8 @@ Below are the environment variables for each type of webhook message: > [!NOTE] > > `PLAYER_NAME` is a variable that will be replaced with the name of the player that left the server. +> `PLAYER_NAME` is a variable that will be replaced with the name of the player that left the server. +> `PLAYER_NAME` is a variable that will be replaced with the name of the player that left the server. > Use it on the title and/or description to show the player's name. | Variable | Description | Default Value | diff --git a/scripts/config/setup_configs.sh b/scripts/config/setup_configs.sh index 88b1914..8966090 100644 --- a/scripts/config/setup_configs.sh +++ b/scripts/config/setup_configs.sh @@ -10,12 +10,17 @@ source "${SERVER_DIR}"/scripts/config/setup_rcon_yaml.sh # Function to setup the server configs function setup_configs() { if [[ -n ${SERVER_SETTINGS_MODE} ]] && [[ ${SERVER_SETTINGS_MODE,,} == "auto" ]]; then - log_warning ">> SERVER_SETTINGS_MODE is set to '${SERVER_SETTINGS_MODE}', using environment variables to configure the server!" + log_warning ">> 'SERVER_SETTINGS_MODE' is set to '${SERVER_SETTINGS_MODE}', environment variables used to configure the server!" setup_engine_ini setup_palworld_settings_ini else - log_warning ">> SERVER_SETTINGS_MODE is set to '${SERVER_SETTINGS_MODE}', NOT using environment variables to configure the server!" - log_warning ">> File ${GAME_SETTINGS_FILE} has to be manually set by user." + log_warning ">> 'SERVER_SETTINGS_MODE' is set to '${SERVER_SETTINGS_MODE}', environment variables NOT used to configure the server!" + + # Copy default-config, which comes with SteamCMD to gameserver save location + cp "${GAME_ROOT}/DefaultPalWorldSettings.ini" "${GAME_SETTINGS_FILE}" + + log_warning ">> File '${GAME_ENGINE_FILE}' has to be manually set by user." + log_warning ">> File '${GAME_SETTINGS_FILE}' has to be manually set by user." fi setup_rcon_yaml } diff --git a/scripts/config/setup_engine_ini.sh b/scripts/config/setup_engine_ini.sh index 3b24fc3..60fc37c 100644 --- a/scripts/config/setup_engine_ini.sh +++ b/scripts/config/setup_engine_ini.sh @@ -6,39 +6,47 @@ source "${SERVER_DIR}"/scripts/config/utils.sh function setup_engine_ini() { # Setup the engine config file - log_warning ">> Setting up Engine.ini ..." # Create the config directory if it doesn't exist mkdir -p "${GAME_CONFIG_PATH}/" - template_file=${SERVER_DIR}/scripts/config/templates/Engine.ini.template + if [[ -n ${ENGINE_CONFIG_MODE} ]] && { [[ ${ENGINE_CONFIG_MODE,,} == "full" ]] || [[ ${ENGINE_CONFIG_MODE,,} == "modular" ]]; }; then + log_warning ">> 'ENGINE_CONFIG_MODE' is set to '${ENGINE_CONFIG_MODE}', environment variables will be used to configure the server!" + log_warning ">> Setting up Engine.ini ..." - cp "${template_file}" "${GAME_ENGINE_FILE}" + template_file=${SERVER_DIR}/scripts/config/templates/Engine.ini.template + cp "${template_file}" "${GAME_ENGINE_FILE}.tmp" - check_and_export "int" "LanServerMaxTickRate" "${LAN_SERVER_MAX_TICK_RATE}" "120" - check_and_export "int" "NetServerMaxTickRate" "${NET_SERVER_MAX_TICK_RATE}" "120" + check_and_export_if_not_empty "int" "LanServerMaxTickRate" "${LAN_SERVER_MAX_TICK_RATE}" "120" + check_and_export_if_not_empty "int" "NetServerMaxTickRate" "${NET_SERVER_MAX_TICK_RATE}" "120" - check_and_export "int" "ConfiguredInternetSpeed" "${CONFIGURED_INTERNET_SPEED}" "104857600" - check_and_export "int" "ConfiguredLanSpeed" "${CONFIGURED_LAN_SPEED}" "104857600" + check_and_export_if_not_empty "int" "ConfiguredInternetSpeed" "${CONFIGURED_INTERNET_SPEED}" "104857600" + check_and_export_if_not_empty "int" "ConfiguredLanSpeed" "${CONFIGURED_LAN_SPEED}" "104857600" - check_and_export "int" "MaxClientRate" "${MAX_CLIENT_RATE}" "104857600" - check_and_export "int" "MaxInternetClientRate" "${MAX_INTERNET_CLIENT_RATE}" "104857600" + check_and_export_if_not_empty "int" "MaxClientRate" "${MAX_CLIENT_RATE}" "104857600" + check_and_export_if_not_empty "int" "MaxInternetClientRate" "${MAX_INTERNET_CLIENT_RATE}" "104857600" - check_and_export "bool" "bSmoothFrameRate" "${SMOOTH_FRAME_RATE}" "true" - check_and_export "float" "SmoothedFrameRateRangeLowerBound" "${SMOOTH_FRAME_RATE_UPPER_BOUND}" "30.000000" - check_and_export "float" "SmoothedFrameRateRangeUpperBound" "${SMOOTH_FRAME_RATE_LOWER_BOUND}" "120.000000" - check_and_export "float" "MinDesiredFrameRate" "${MIN_DESIRED_FRAME_RATE}" "60.000000" - check_and_export "bool" "bUseFixedFrameRate" "${USE_FIXED_FRAME_RATE}" "false" - check_and_export "float" "FixedFrameRate" "${FIXED_FRAME_RATE}" "120.000000" - check_and_export "int" "NetClientTicksPerSecond" "${NET_CLIENT_TICKS_PER_SECOND}" "120" + check_and_export_if_not_empty "bool" "bSmoothFrameRate" "${SMOOTH_FRAME_RATE}" "true" + check_and_export_if_not_empty "float" "SmoothedFrameRateRangeLowerBound" "${SMOOTH_FRAME_RATE_UPPER_BOUND}" "30.000000" + check_and_export_if_not_empty "float" "SmoothedFrameRateRangeUpperBound" "${SMOOTH_FRAME_RATE_LOWER_BOUND}" "120.000000" + check_and_export_if_not_empty "float" "MinDesiredFrameRate" "${MIN_DESIRED_FRAME_RATE}" "60.000000" + check_and_export_if_not_empty "bool" "bUseFixedFrameRate" "${USE_FIXED_FRAME_RATE}" "false" + check_and_export_if_not_empty "float" "FixedFrameRate" "${FIXED_FRAME_RATE}" "120.000000" + check_and_export_if_not_empty "int" "NetClientTicksPerSecond" "${NET_CLIENT_TICKS_PER_SECOND}" "120" - check_and_export "int" "TimeBetweenPurgingPendingKillObjects" "${TIME_BETWEEN_PURGING_PENDING_KILL_OBJECTS}" "30" + check_and_export_if_not_empty "int" "TimeBetweenPurgingPendingKillObjects" "${TIME_BETWEEN_PURGING_PENDING_KILL_OBJECTS}" "30" - check_and_export "bool" "rThreadedRendering" "${THREADED_RENDERING}" "true" - check_and_export "bool" "rThreadedPhysics" "${THREADED_PHYSICS}" "true" + check_and_export_if_not_empty "bool" "rThreadedRendering" "${THREADED_RENDERING}" "true" + check_and_export_if_not_empty "bool" "rThreadedPhysics" "${THREADED_PHYSICS}" "true" - envsubst < "${GAME_ENGINE_FILE}" > "${GAME_ENGINE_FILE}.tmp" && mv "${GAME_ENGINE_FILE}.tmp" "${GAME_ENGINE_FILE}" + envsubst < "${GAME_ENGINE_FILE}.tmp" > "${GAME_ENGINE_FILE}" && rm "${GAME_ENGINE_FILE}.tmp" + + log_success ">>> Finished setting up Engine.ini!" + + trim_file "${GAME_ENGINE_FILE}" + else + log_warning ">> 'ENGINE_CONFIG_MODE' is set to '${ENGINE_CONFIG_MODE}', skipping '${GAME_ENGINE_FILE}' configuration!" + fi - log_success ">>> Finished setting up Engine.ini!" } \ No newline at end of file diff --git a/scripts/config/setup_palworld_settings_ini.sh b/scripts/config/setup_palworld_settings_ini.sh index ea7f9ce..6ee1821 100644 --- a/scripts/config/setup_palworld_settings_ini.sh +++ b/scripts/config/setup_palworld_settings_ini.sh @@ -13,8 +13,8 @@ function setup_palworld_settings_ini(){ template_file=${SERVER_DIR}/scripts/config/templates/PalWorldSettings.ini.template - # Remove the first line of the template file and remove the newlines and carriage returns - awk 'NR==1{print;next}{printf "%s",$0}' "${template_file}" | tr -d '\r' > "${GAME_SETTINGS_FILE}" + # Skip the first line of the template file and remove the newlines and carriage returns for the rest of the file + awk 'NR==1{print;next}{printf "%s",$0}' "${template_file}" | tr -d '\r' > "${GAME_SETTINGS_FILE}.tmp" difficulty_options=("None" "Normal" "Difficult") check_and_export "list" "Difficulty" "${DIFFICULTY}" "None" "${difficulty_options[@]}" @@ -82,8 +82,7 @@ function setup_palworld_settings_ini(){ check_and_export "other" "BanListURL" "${BAN_LIST_URL}" "" check_and_export "bool" "bShowPlayerList" "${SHOW_PLAYER_LIST}" "true" - envsubst < "${GAME_SETTINGS_FILE}" > "${GAME_SETTINGS_FILE}.tmp" && mv "${GAME_SETTINGS_FILE}.tmp" "${GAME_SETTINGS_FILE}" + envsubst < "${GAME_SETTINGS_FILE}.tmp" > "${GAME_SETTINGS_FILE}" && rm "${GAME_SETTINGS_FILE}.tmp" log_success ">>> Finished setting up PalWorldSettings.ini" - } diff --git a/scripts/config/setup_rcon_yaml.sh b/scripts/config/setup_rcon_yaml.sh index b1ea8e1..0c8365e 100644 --- a/scripts/config/setup_rcon_yaml.sh +++ b/scripts/config/setup_rcon_yaml.sh @@ -5,53 +5,55 @@ source "${SERVER_DIR}"/scripts/utils/logs.sh source "${SERVER_DIR}"/scripts/config/utils.sh + + +# Function to setup the rcon.yaml config file +# +# Description: +# This function sets up the 'rcon.yaml' config file for the server. +# It will always use 'PalWorldSettings.ini' file to configure the 'rcon.yaml' file. function setup_rcon_yaml () { if [[ -n ${RCON_ENABLED+x} ]] && [ "${RCON_ENABLED,,}" == "true" ] ; then - log_info "> RCON is enabled, setting 'rcon.yaml' config file..." + log_info "> RCON is enabled" mkdir -p "$(dirname "${RCON_CONFIG_FILE}")" cp "${SERVER_DIR}/scripts/config/templates/rcon.yaml.template" "${RCON_CONFIG_FILE}" - if [[ "${SERVER_SETTINGS_MODE,,}" == "auto" ]]; then - # Use environment variables - log_warning ">> Using environment variables to configure 'rcon.yaml' config file." - log_info -n "> Admin Password: " && log_base "'██████████'" - log_info -n "> RCON Port: " && log_base "'██████████'" - - if [[ -n ${RCON_PORT+x} ]]; then - sed -i "s/###RCON_PORT###/$RCON_PORT/" "$RCON_CONFIG_FILE" - else - log_error ">>> RCON_PORT is not set, please set it for RCON functionality to work!" - fi - if [[ -n ${ADMIN_PASSWORD+x} ]]; then - sed -i "s/###ADMIN_PASSWORD###/$ADMIN_PASSWORD/" "$RCON_CONFIG_FILE" - else - log_error ">>> ADMIN_PASSWORD is not set, please set it for RCON functionality to work!" - fi - else - log_warning ">> Using file '$GAME_SETTINGS_FILE' to configure..." + if [[ -f "${GAME_SETTINGS_FILE}" ]]; then + log_warning ">> Using file '${GAME_SETTINGS_FILE}' to configure '${RCON_CONFIG_FILE}'..." # Use file information - admin_password=$(awk -F'AdminPassword="' '{print $2}' "$GAME_SETTINGS_FILE" | awk -F'"' '{print $1}' | tr -d '\n') - rcon_port=$(awk -F'RCONPort=' '{print $2}' "$GAME_SETTINGS_FILE" | awk -F',' '{print $1}' | tr -d '\n') + admin_password=$(awk -F'AdminPassword="' '{print $2}' "${GAME_SETTINGS_FILE}" | awk -F'"' '{print $1}' | tr -d '\n') + rcon_port=$(awk -F'RCONPort=' '{print $2}' "${GAME_SETTINGS_FILE}" | awk -F',' '{print $1}' | tr -d '\n') + + # Check if rcon port is valid + if [ "$(is_valid_port "${rcon_port}" "0")" = 0 ]; then + log_error ">>> RCON_PORT is not a valid port number, please set a valid port number for RCON functionality to work!" + exit 1 + fi log_info -n "> Admin Password: " && log_base "'██████████'" log_info -n "> RCON Port: " && log_base "'██████████'" if [[ -n ${rcon_port+x} ]]; then - sed -i "s/###RCON_PORT###/$rcon_port/" "$RCON_CONFIG_FILE" + sed -i "s/###RCON_PORT###/${rcon_port}/" "${RCON_CONFIG_FILE}" else log_error ">>> RCON_PORT is not set in the file, please set it for RCON functionality to work!" fi if [[ -n ${admin_password+x} ]]; then - sed -i "s/###ADMIN_PASSWORD###/$admin_password/" "$RCON_CONFIG_FILE" + sed -i "s/###ADMIN_PASSWORD###/${admin_password}/" "${RCON_CONFIG_FILE}" else log_error ">>> ADMIN_PASSWORD is not set in the file, please set it for RCON functionality to work!" fi - fi - log_success ">>> Finished setting up 'rcon.yaml' config file." + log_success ">>> Finished setting up 'rcon.yaml' config file." + else + log_warning ">> File '${GAME_SETTINGS_FILE}' does not exist." + log_warning ">> Restart the server after configuring '${GAME_SETTINGS_FILE}'." + log_warning ">> RCON features will not work!" + fi else - log_warning ">> RCON is disabled, skipping 'rcon.yaml' config file!" + log_warning ">> RCON is disabled, skipping '${RCON_CONFIG_FILE}' config file!" + log_warning ">> RCON features will be disabled!" fi } diff --git a/scripts/config/templates/Engine.ini.template b/scripts/config/templates/Engine.ini.template index ccfe569..90a3d3b 100644 --- a/scripts/config/templates/Engine.ini.template +++ b/scripts/config/templates/Engine.ini.template @@ -84,7 +84,7 @@ ConfiguredLanSpeed=${ConfiguredLanSpeed} ; Sets the LAN speed, ensurin ; Socket Subsystem Epic Configuration ; Tailoring the max client rate for both local and internet clients, this optimizes data transfer rates, ; ensuring that the server can handle high volumes of data without causing lag. -[/Script/SocketSubsystemSpic.EpicNetDriver] +[/Script/SocketSubsystemEpic.EpicNetDriver] MaxClientRate=${MaxClientRate} ; Maximum data transfer rate per client for all connections, set to a high value to prevent data capping. MaxInternetClientRate=${MaxInternetClientRate} ; Specifically targets internet clients, allowing for high-volume data transfer without restrictions. @@ -99,14 +99,12 @@ bUseFixedFrameRate=${bUseFixedFrameRate} ; Disables the use of a fixed FixedFrameRate=${FixedFrameRate} ; (Not active due to bUseFixedFrameRate set to false) Placeholder for a fixed frame rate if needed. NetClientTicksPerSecond=${NetClientTicksPerSecond} ; Increases the update frequency for clients, enhancing responsiveness and reducing lag. - ; Garbage Collection Settings ; These settings manage how the game handles memory management and garbage collection, ; which can impact the game's performance and stability. [/Script/Engine.GarbageCollectionSettings] TimeBetweenPurgingPendingKillObjects=${TimeBetweenPurgingPendingKillObjects} ; Sets the time in seconds between purging pending kill objects, freeing up memory and reducing memory leaks. - ; Renderer Settings ; These settings manage how the game's rendering is handled, which can impact the game's performance and visual quality. ; Enabling threaded rendering and physics can improve performance by distributing the workload across multiple threads. diff --git a/scripts/config/utils.sh b/scripts/config/utils.sh index f73bc6f..46e727e 100755 --- a/scripts/config/utils.sh +++ b/scripts/config/utils.sh @@ -118,7 +118,17 @@ function is_valid_port() { fi } - +# Function to check if passed value is valid and to export it +# +# Arguments: +# $1 - The type of the value +# $2 - The name of the variable to export +# $3 - The value to check +# $4 - The default value to return if the value is not valid +# $5 - The list of strings (optional) +# +# Description: +# This function checks if the given value is valid and exports it. function check_and_export() { local type=$1 local name=$2 @@ -154,7 +164,79 @@ function check_and_export() { to_export="${to_export/"###RANDOM###"/$RANDOM}" export "$name"="\"${to_export}\"" esac + log_info -n "> Setting '" && log_base -n "$name" && log_info -n "' to '" && log_base -n "$to_export" && log_info "'" +} + + +# Wrapper function to check if passed value is not empty and to export it +# +# Arguments: +# Same as check_and_export function +# +# Description: +# This function is a wrapper around check_and_export function. +# It checks if the given value environment variable/value is not empty +# and calls check_and_export function with the given arguments. +# If the env_var value is empty, it sets the type to "other" and +# the env_var to "###TO_REMOVE###" that marks the place where the +# variable is replaced to be removed from the file. +# +# NOTE: +# This is used on Engine.ini configuration +# It will only change values if ENGINE_CONFIG_MODE is `full` or `modular` +function check_and_export_if_not_empty() { + local type=$1 + local name=$2 + local env_var=$3 + local default=$4 + local array=("${@:5}") + + if [[ -z "$env_var" ]] && [[ "${ENGINE_CONFIG_MODE,,}" == "modular" ]]; then + #echo "Removing ${name} from ${GAME_ENGINE_FILE}.tmp..." + sed -i "/${name}/d" "${GAME_ENGINE_FILE}.tmp" + return + fi + + check_and_export "$type" "$name" "$env_var" "$default" "${array[@]}" +} + + +# Function to trim the file from empty configs and comments +# +# Arguments: +# $1 - The file to trim +# +# NOTE: +# This is used on Engine.ini configuration +# It will only trim if ENGINE_CONFIG_MODE=modular +function trim_file() { + local file="$1" + + # Remove files modules that have no settings + temp_file=$(mktemp) + + while IFS= read -r line; do + if [[ $line =~ ^\[/Script/ ]]; then + # If the next line is empty, skip to the next iteration + IFS= read -r next_line + if [ -z "$next_line" ]; then + continue + fi + # Print the line and the next line + echo "$line" + echo "$next_line" + elif [[ $line =~ ^\;\ ]]; then + continue + else + # Print the line + echo "$line" + fi + + done < "$file" > "$temp_file" + + mv "$temp_file" "$file" } +