#!/bin/bash
# shellcheck source=scripts/functions.sh
source "/home/steam/server/functions.sh"

config_file="/satisfactory/FactoryGame/Saved/Config/LinuxServer/Game.ini"
config_dir=$(dirname "$config_file")

mkdir -p "$config_dir" || exit

export TOTAL_NET_BANDWIDTH=${TOTAL_NET_BANDWIDTH:-104857600}
export MAX_DYNAMIC_BANDWIDTH=${MAX_DYNAMIC_BANDWIDTH:-104857600}
export MIN_DYNAMIC_BANDWIDTH=${MIN_DYNAMIC_BANDWIDTH:-104857600}
export MAX_POSITION_ERROR_SQUARED=${MAX_POSITION_ERROR_SQUARED:-"32.00f"}
export MOVE_REP_SIZE=${MOVE_REP_SIZE:-"512.0f"}
export CLIENT_ADJUST_UPDATE_COST=${CLIENT_ADJUST_UPDATE_COST:-"512.0f"}
export MOVEMENT_TIME_DISCREPANCY_DETECTION=${MOVEMENT_TIME_DISCREPANCY_DETECTION:-false}
export MOVEMENT_TIME_DISCREPANCY_RESOLUTION=${MOVEMENT_TIME_DISCREPANCY_RESOLUTION:-false}
export MOVEMENT_TIME_DISCREPANCY_FORCE_CORRECTIONS_DURING_RESOLUTION=${MOVEMENT_TIME_DISCREPANCY_FORCE_CORRECTIONS_DURING_RESOLUTION:-false}
export MAX_CLIENT_UPDATE_INTERVAL=${MAX_CLIENT_UPDATE_INTERVAL:-"2.20f"}
export MAX_MOVE_DELTA_TIME=${MAX_MOVE_DELTA_TIME:-"0.700f"}
export MAX_CLIENT_SMOOTHING_DELTA_TIME=${MAX_CLIENT_SMOOTHING_DELTA_TIME:-"2.20f"}
export MAX_CLIENT_FORCED_UPDATE_DURATION=${MAX_CLIENT_FORCED_UPDATE_DURATION:-"1.0f"}
export CLIENT_NET_SEND_MOVE_DELTA_TIME=${CLIENT_NET_SEND_MOVE_DELTA_TIME:-"0.0332"}
export CLIENT_NET_SEND_MOVE_DELTA_TIME_STATIONARY=${CLIENT_NET_SEND_MOVE_DELTA_TIME_STATIONARY:-"0.0664"}
export CLIENT_NET_SEND_MOVE_THROTTLE_OVER_PLAYER_COUNT=${CLIENT_NET_SEND_MOVE_THROTTLE_OVER_PLAYER_COUNT:-99}
export SERVER_FORCED_UPDATE_HITCH_THRESHOLD=${SERVER_FORCED_UPDATE_HITCH_THRESHOLD:-"2.800f"}
export CONNECTION_TIMEOUT=${CONNECTION_TIMEOUT:-300.0}
export INITIAL_CONNECT_TIMEOUT=${INITIAL_CONNECT_TIMEOUT:-300.0}
export MAX_PLAYERS=${MAX_PLAYERS:-4}

cat > "$config_file" <<EOF
$(envsubst < /home/steam/server/templates/Game.ini.template)
EOF