From e8dd510f61515a54f802e018108b532698c298b3 Mon Sep 17 00:00:00 2001 From: Diyagi Date: Wed, 9 Oct 2024 05:00:35 -0300 Subject: [PATCH 01/28] Fix permission for x11-unix file --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ca734dd..6fc9a3b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,7 +33,8 @@ RUN set -x \ && rm -rf /var/lib/apt/lists/* RUN mkdir /tmp/.X11-unix \ - && chown -R "${USER}:${USER}" /tmp/.X11-unix + && chmod 1777 /tmp/.X11-unix \ + && chown root /tmp/.X11-unix ENV WORLD_INDEX=0 \ From 27bd5afa540a0466258e91f93a76b12879b9feeb Mon Sep 17 00:00:00 2001 From: Diyagi Date: Wed, 9 Oct 2024 05:02:35 -0300 Subject: [PATCH 02/28] Fix possible error while cleaning up x99-lock file --- launch.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/launch.sh b/launch.sh index 3b28673..a1ced21 100644 --- a/launch.sh +++ b/launch.sh @@ -26,7 +26,8 @@ fi set -m -rm -f /tmp/.X99-lock +#Restart cleanup +if [ -f "/tmp/.X99-lock" ]; then rm /tmp/.X99-lock; fi Xvfb :99 -screen 0 1x1x24 -nolisten tcp & export DISPLAY=:99 From cb9fdc6862969d8da216a4116b211638b4eb478d Mon Sep 17 00:00:00 2001 From: Diyagi Date: Fri, 11 Oct 2024 21:49:24 +0000 Subject: [PATCH 03/28] Major refactor Reorder Dockerfile and remove unnecessary dependencies Move bash scripts to their own folder Add environment variables for PUID and PGID Refactor and move parameter compilation to its own script Refactor server launch script and remove unnecessary code --- Dockerfile | 44 +++++++-------- entry.sh | 15 ----- launch.sh | 100 ---------------------------------- scripts/compile-parameters.sh | 33 +++++++++++ scripts/entry.sh | 38 +++++++++++++ scripts/launch.sh | 48 ++++++++++++++++ scripts/setup.sh | 24 ++++++++ 7 files changed, 165 insertions(+), 137 deletions(-) delete mode 100644 entry.sh delete mode 100644 launch.sh create mode 100644 scripts/compile-parameters.sh create mode 100644 scripts/entry.sh create mode 100644 scripts/launch.sh create mode 100644 scripts/setup.sh diff --git a/Dockerfile b/Dockerfile index 6fc9a3b..ff6ffcb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,34 +10,38 @@ ENV STEAMAPPID_TOOL 1963720 ENV STEAMAPP core-keeper ENV STEAMAPPDIR "${HOMEDIR}/${STEAMAPP}-dedicated" ENV STEAMAPPDATADIR "${HOMEDIR}/${STEAMAPP}-data" +ENV SCRIPTSDIR "${HOMEDIR}/scripts" ENV DLURL https://raw.githubusercontent.com/escapingnetwork/core-keeper-dedicated -COPY ./entry.sh ${HOMEDIR}/entry.sh -COPY ./launch.sh ${HOMEDIR}/launch.sh - RUN dpkg --add-architecture i386 # Install Core Keeper server dependencies and clean up -# libx32gcc-s1 lib32gcc-s1 build-essential <- fixes tile generation bug (obsidian wall around spawn) without graphic cards mounted to server -# need all 3 + dpkg i do not know why but every other combination would run the server at an extreme speed - that combination worked for me. -# Thanks to https://www.reddit.com/r/CoreKeeperGame/comments/uym86p/comment/iays04w/?utm_source=share&utm_medium=web2x&context=3 RUN set -x \ && apt-get update \ && apt-get install -y --no-install-recommends --no-install-suggests \ - xvfb mesa-utils libx32gcc-s1 lib32gcc-s1 build-essential libxi6 x11-utils tini \ - && mkdir -p "${STEAMAPPDIR}" \ - && mkdir -p "${STEAMAPPDATADIR}" \ - && chmod +x "${HOMEDIR}/entry.sh" \ - && chmod +x "${HOMEDIR}/launch.sh" \ - && chown -R "${USER}:${USER}" "${HOMEDIR}/entry.sh" "${HOMEDIR}/launch.sh" "${STEAMAPPDIR}" "${STEAMAPPDATADIR}" \ + xvfb \ + libxi6 \ + tini \ + tzdata \ && rm -rf /var/lib/apt/lists/* +# Setup X11 Sockets folder RUN mkdir /tmp/.X11-unix \ - && chmod 1777 /tmp/.X11-unix \ - && chown root /tmp/.X11-unix + && chmod 1777 /tmp/.X11-unix \ + && chown root /tmp/.X11-unix +# Setup folders +COPY ./scripts ${SCRIPTSDIR} +RUN set -x \ + && chmod +x -R "${SCRIPTSDIR}" \ + && mkdir -p "${STEAMAPPDIR}" \ + && mkdir -p "${STEAMAPPDATADIR}" \ + && chown -R "${USER}:${USER}" "${SCRIPTSDIR}" "${STEAMAPPDIR}" "${STEAMAPPDATADIR}" -ENV WORLD_INDEX=0 \ +# Declare envs and their default values +ENV PUID=1000 \ + PGID=1000 \ + WORLD_INDEX=0 \ WORLD_NAME="Core Keeper Server" \ WORLD_SEED=0 \ WORLD_MODE=0 \ @@ -46,17 +50,13 @@ ENV WORLD_INDEX=0 \ MAX_PLAYERS=10 \ SEASON=-1 \ SERVER_IP="" \ - SERVER_PORT="" - -# Switch to user -USER ${USER} + SERVER_PORT="" \ + DISCORD_HOOK="" # Switch to workdir WORKDIR ${HOMEDIR} -VOLUME ${STEAMAPPDIR} - # Use tini as the entrypoint for signal handling ENTRYPOINT ["/usr/bin/tini", "--"] -CMD ["bash", "entry.sh"] +CMD ["bash", "scripts/entry.sh"] diff --git a/entry.sh b/entry.sh deleted file mode 100644 index f1ff2dd..0000000 --- a/entry.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -mkdir -p "${STEAMAPPDIR}" || true - -# Override SteamCMD launch arguments if necessary -# Used for subscribing to betas or for testing -if [ -z "$STEAMCMD_UPDATE_ARGS" ]; then - bash "${STEAMCMDDIR}/steamcmd.sh" +force_install_dir "$STEAMAPPDIR" +login anonymous +app_update "$STEAMAPPID" +app_update "$STEAMAPPID_TOOL" +quit -else - steamcmd_update_args=($STEAMCMD_UPDATE_ARGS) - bash "${STEAMCMDDIR}/steamcmd.sh" +force_install_dir "$STEAMAPPDIR" +login anonymous +app_update "$STEAMAPPID" +app_update "$STEAMAPPID_TOOL" "${steamcmd_update_args[@]}" +quit -fi - -bash "${STEAMCMDDIR}/steamcmd.sh" +force_install_dir "$STEAMAPPDIR" +login anonymous +app_update "$STEAMAPPID" +app_update "$STEAMAPPID_TOOL" +quit - -exec bash "./launch.sh" diff --git a/launch.sh b/launch.sh deleted file mode 100644 index a1ced21..0000000 --- a/launch.sh +++ /dev/null @@ -1,100 +0,0 @@ -#!/bin/bash - -# Switch to workdir -cd "${STEAMAPPDIR}" - -xvfbpid="" -ckpid="" - -function kill_corekeeperserver { - if [[ ! -z "$ckpid" ]]; then - kill $ckpid - wait $ckpid - fi - if [[ ! -z "$xvfbpid" ]]; then - kill $xvfbpid - fi -} - -trap kill_corekeeperserver EXIT - -if ! (dpkg -l xvfb >/dev/null) ; then - echo "Installing xvfb dependency..." - sleep 1 - sudo apt-get update -yy && sudo apt-get install xvfb -yy -fi - -set -m - -#Restart cleanup -if [ -f "/tmp/.X99-lock" ]; then rm /tmp/.X99-lock; fi - -Xvfb :99 -screen 0 1x1x24 -nolisten tcp & -export DISPLAY=:99 -xvfbpid=$! - -# Wait for xvfb ready. -# Thanks to https://hg.mozilla.org/mozilla-central/file/922e64883a5b4ebf6f2345dfb85f04b487a0e714/testing/docker/desktop-build/bin/build.sh -retry_count=0 -max_retries=2 -xvfb_test=0 -until [ $retry_count -gt $max_retries ]; do - xvinfo - xvfb_test=$? - if [ $xvfb_test != 255 ]; then - retry_count=$(($max_retries + 1)) - else - retry_count=$(($retry_count + 1)) - echo "Failed to start Xvfb, retry: $retry_count" - sleep 2 - fi done - if [ $xvfb_test == 255 ]; then exit 255; fi - -rm -f GameID.txt - -chmod +x ./CoreKeeperServer - -#Build Parameters -declare -a params -params=(-batchmode -logfile "CoreKeeperServerLog.txt") -if [ ! -z "${WORLD_INDEX}" ]; then params=( "${params[@]}" -world "${WORLD_INDEX}" ); fi -if [ ! -z "${WORLD_NAME}" ]; then params=( "${params[@]}" -worldname "${WORLD_NAME}" ); fi -if [ ! -z "${WORLD_SEED}" ]; then params=( "${params[@]}" -worldseed "${WORLD_SEED}" ); fi -if [ ! -z "${WORLD_MODE}" ]; then params=( "${params[@]}" -worldmode "${WORLD_MODE}" ); fi -if [ ! -z "${GAME_ID}" ]; then params=( "${params[@]}" -gameid "${GAME_ID}" ); fi -if [ ! -z "${DATA_PATH}" ]; then params=( "${params[@]}" -datapath "${DATA_PATH}" ); fi -if [ ! -z "${MAX_PLAYERS}" ]; then params=( "${params[@]}" -maxplayers "${MAX_PLAYERS}" ); fi -if [ ! -z "${SEASON}" ]; then params=( "${params[@]}" -season "${SEASON}" ); fi -if [ ! -z "${SERVER_IP}" ]; then params=( "${params[@]}" -ip "${SERVER_IP}" ); fi -if [ ! -z "${SERVER_PORT}" ]; then params=( "${params[@]}" -port "${SERVER_PORT}" ); fi - -echo "${params[@]}" - -DISPLAY=:99 LD_LIBRARY_PATH="$LD_LIBRARY_PATH:../Steamworks SDK Redist/linux64/" ./CoreKeeperServer "${params[@]}"& - -ckpid=$! - -echo "Started server process with pid $ckpid" - -while [ ! -f GameID.txt ]; do - sleep 0.1 -done - -gameid=$(cat GameID.txt) -echo "Game ID: ${gameid}" - -if [ -z "$DISCORD" ]; then - DISCORD=0 -fi - -if [ $DISCORD -eq 1 ]; then - if [ -z "$DISCORD_HOOK" ]; then - echo "Please set DISCORD_WEBHOOK url." - else - format="${DISCORD_PRINTF_STR:-%s}" - curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{\"content\": \"$(printf "${format}" "${gameid}")\"}" "${DISCORD_HOOK}" - fi -fi - -wait $ckpid -ckpid="" diff --git a/scripts/compile-parameters.sh b/scripts/compile-parameters.sh new file mode 100644 index 0000000..20d4c9d --- /dev/null +++ b/scripts/compile-parameters.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# This scripts compiles parameters from an ENV arg to an array +# this should be run with source, so the params ENV becomes avaliable. + +add_param() { + local param_name="$1" + local param_value="$2" + + if [ -n "$param_value" ]; then + params+=("$param_name" "$param_value") + fi +} + +# Makes log file avaliable for other uses. +logfile="${STEAMAPPDIR}/logs/$(date '+%Y-%m-%d_%H-%M-%S').log" +params=( + "-batchmode" + "-logfile" "$logfile" +) + +add_param "-world" "$WORLD_INDEX" +add_param "-worldname" "$WORLD_NAME" +add_param "-worldseed" "$WORLD_SEED" +add_param "-worldmode" "$WORLD_MODE" +add_param "-gameid" "$GAME_ID" +add_param "-datapath" "$DATA_PATH" +add_param "-maxplayers" "$MAX_PLAYERS" +add_param "-season" "$SEASON" +add_param "-ip" "$SERVER_IP" +add_param "-port" "$SERVER_PORT" + +echo "${params[@]}" diff --git a/scripts/entry.sh b/scripts/entry.sh new file mode 100644 index 0000000..3e8c9e2 --- /dev/null +++ b/scripts/entry.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# From: https://github.com/thijsvanloef/palworld-server-docker/blob/32ffe489daecbc332701592f2facf0fe3237c65f/scripts/init.sh#L15 +# Checks for root, updates UID and GID of user steam +# and updates folders owners +if [[ "$(id -u)" -eq 0 ]] && [[ "$(id -g)" -eq 0 ]]; then + if [[ "${PUID}" -ne 0 ]] && [[ "${PGID}" -ne 0 ]]; then + echo "EXECUTING USERMOD" + usermod -o -u "${PUID}" "${USER}" + groupmod -o -g "${PGID}" "${USER}" + chown -R "${USER}:${USER}" "${HOMEDIR}" + else + echo "Running as root is not supported, please fix your PUID and PGID!" + exit 1 + fi +elif [[ "$(id -u)" -eq 0 ]] || [[ "$(id -g)" -eq 0 ]]; then + echo "Running as root is not supported, please fix your user!" + exit 1 +fi + +if ! [ -w "${STEAMAPPDIR}" ]; then + echo "${STEAMAPPDIR} is not writable." + exit 1 +fi + +if ! [ -w "${STEAMAPPDATADIR}" ]; then + echo "${STEAMAPPDATADIR} is not writable." + exit 1 +fi + +#Restart cleanup +if [ -f "/tmp/.X99-lock" ]; then rm /tmp/.X99-lock; fi + +if [[ "$(id -u)" -eq 0 ]]; then + exec su "${USER}" -c "exec bash ${SCRIPTSDIR}/setup.sh" +else + exec bash "${SCRIPTSDIR}/setup.sh" +fi diff --git a/scripts/launch.sh b/scripts/launch.sh new file mode 100644 index 0000000..c9eb670 --- /dev/null +++ b/scripts/launch.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# Switch to workdir +cd "${STEAMAPPDIR}" + +### Function for gracefully shutdown +function kill_corekeeperserver { + if [[ -n "$ckpid" ]]; then + kill $ckpid + wait $ckpid + fi + if [[ -n "$xvfbpid" ]]; then + kill $xvfbpid + fi +} + +trap kill_corekeeperserver EXIT TERM + +if [ -f "GameID.txt" ]; then rm GameID.txt; fi + +# Compile Parameters +# Populates `params` array with parameters. +# Creates `logfile` var with log file path. +source "${SCRIPTSDIR}/compile-parameters.sh" + +# Start Xvfb +Xvfb :99 -screen 0 1x1x24 -nolisten tcp & +xvfbpid=$! + +# Start Core Keeper Server +DISPLAY=:99 LD_LIBRARY_PATH="$LD_LIBRARY_PATH:../Steamworks SDK Redist/linux64/" ./CoreKeeperServer "${params[@]}" & +ckpid=$! + +echo "Started server process with pid ${ckpid}" + +tail --pid "$ckpid" -n +1 -f "$logfile" & + +until [ -f GameID.txt ]; do + sleep 0.1 +done + +gameid=$(< GameID.txt) +if [ -n "$DISCORD_HOOK" ]; then + format="${DISCORD_PRINTF_STR:-%s}" + curl -fsSL -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{\"content\": \"$(printf "${format}" "${gameid}")\"}" "${DISCORD_HOOK}" +fi + +wait $ckpid diff --git a/scripts/setup.sh b/scripts/setup.sh new file mode 100644 index 0000000..6f55d19 --- /dev/null +++ b/scripts/setup.sh @@ -0,0 +1,24 @@ +#!/bin/bash +mkdir -p "${STEAMAPPDIR}" || true + +# Initialize arguments array +args=( + "+force_install_dir" "$STEAMAPPDIR" + "+login" "anonymous" + "+app_update" "$STEAMAPPID" "validate" + "+app_update" "$STEAMAPPID_TOOL" "validate" +) + +# Override SteamCMD launch arguments if necessary +# Used for subscribing to betas or for testing +if [ -n "$STEAMCMD_UPDATE_ARGS" ]; then + args+=("${STEAMCMD_UPDATE_ARGS[@]}") +fi + +# Add the quit command +args+=("+quit") + +# Run SteamCMD with the arguments +bash "${STEAMCMDDIR}/steamcmd.sh" "${args[@]}" + +exec bash "${SCRIPTSDIR}/launch.sh" From bfdc8ae0435912484e87dd5533255a796fa71be3 Mon Sep 17 00:00:00 2001 From: Diyagi Date: Fri, 11 Oct 2024 21:52:26 +0000 Subject: [PATCH 04/28] Fix formatting --- Dockerfile | 28 ++++++++++++++-------------- scripts/compile-parameters.sh | 2 +- scripts/launch.sh | 4 ++-- scripts/setup.sh | 10 +++++----- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index ff6ffcb..7e013f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,27 +16,27 @@ ENV DLURL https://raw.githubusercontent.com/escapingnetwork/core-keeper-dedicate RUN dpkg --add-architecture i386 # Install Core Keeper server dependencies and clean up -RUN set -x \ - && apt-get update \ - && apt-get install -y --no-install-recommends --no-install-suggests \ +RUN set -x && + apt-get update && + apt-get install -y --no-install-recommends --no-install-suggests \ xvfb \ libxi6 \ tini \ - tzdata \ - && rm -rf /var/lib/apt/lists/* + tzdata && + rm -rf /var/lib/apt/lists/* # Setup X11 Sockets folder -RUN mkdir /tmp/.X11-unix \ - && chmod 1777 /tmp/.X11-unix \ - && chown root /tmp/.X11-unix +RUN mkdir /tmp/.X11-unix && + chmod 1777 /tmp/.X11-unix && + chown root /tmp/.X11-unix # Setup folders COPY ./scripts ${SCRIPTSDIR} -RUN set -x \ - && chmod +x -R "${SCRIPTSDIR}" \ - && mkdir -p "${STEAMAPPDIR}" \ - && mkdir -p "${STEAMAPPDATADIR}" \ - && chown -R "${USER}:${USER}" "${SCRIPTSDIR}" "${STEAMAPPDIR}" "${STEAMAPPDATADIR}" +RUN set -x && + chmod +x -R "${SCRIPTSDIR}" && + mkdir -p "${STEAMAPPDIR}" && + mkdir -p "${STEAMAPPDATADIR}" && + chown -R "${USER}:${USER}" "${SCRIPTSDIR}" "${STEAMAPPDIR}" "${STEAMAPPDATADIR}" # Declare envs and their default values ENV PUID=1000 \ @@ -50,7 +50,7 @@ ENV PUID=1000 \ MAX_PLAYERS=10 \ SEASON=-1 \ SERVER_IP="" \ - SERVER_PORT="" \ + SERVER_PORT="" \ DISCORD_HOOK="" # Switch to workdir diff --git a/scripts/compile-parameters.sh b/scripts/compile-parameters.sh index 20d4c9d..36038e8 100644 --- a/scripts/compile-parameters.sh +++ b/scripts/compile-parameters.sh @@ -15,7 +15,7 @@ add_param() { # Makes log file avaliable for other uses. logfile="${STEAMAPPDIR}/logs/$(date '+%Y-%m-%d_%H-%M-%S').log" params=( - "-batchmode" + "-batchmode" "-logfile" "$logfile" ) diff --git a/scripts/launch.sh b/scripts/launch.sh index c9eb670..4fdc465 100644 --- a/scripts/launch.sh +++ b/scripts/launch.sh @@ -36,10 +36,10 @@ echo "Started server process with pid ${ckpid}" tail --pid "$ckpid" -n +1 -f "$logfile" & until [ -f GameID.txt ]; do - sleep 0.1 + sleep 0.1 done -gameid=$(< GameID.txt) +gameid=$( Date: Fri, 11 Oct 2024 22:06:29 +0000 Subject: [PATCH 05/28] Fix Dockerfile --- Dockerfile | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7e013f6..2428de9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,27 +16,27 @@ ENV DLURL https://raw.githubusercontent.com/escapingnetwork/core-keeper-dedicate RUN dpkg --add-architecture i386 # Install Core Keeper server dependencies and clean up -RUN set -x && - apt-get update && - apt-get install -y --no-install-recommends --no-install-suggests \ +RUN set -x \ + && apt-get update \ + && apt-get install -y --no-install-recommends --no-install-suggests \ xvfb \ libxi6 \ tini \ - tzdata && - rm -rf /var/lib/apt/lists/* + tzdata \ + && rm -rf /var/lib/apt/lists/* # Setup X11 Sockets folder -RUN mkdir /tmp/.X11-unix && - chmod 1777 /tmp/.X11-unix && - chown root /tmp/.X11-unix +RUN mkdir /tmp/.X11-unix \ + && chmod 1777 /tmp/.X11-unix \ + && chown root /tmp/.X11-unix # Setup folders COPY ./scripts ${SCRIPTSDIR} -RUN set -x && - chmod +x -R "${SCRIPTSDIR}" && - mkdir -p "${STEAMAPPDIR}" && - mkdir -p "${STEAMAPPDATADIR}" && - chown -R "${USER}:${USER}" "${SCRIPTSDIR}" "${STEAMAPPDIR}" "${STEAMAPPDATADIR}" +RUN set -x \ + && chmod +x -R "${SCRIPTSDIR}" \ + && mkdir -p "${STEAMAPPDIR}" \ + && mkdir -p "${STEAMAPPDATADIR}" \ + && chown -R "${USER}:${USER}" "${SCRIPTSDIR}" "${STEAMAPPDIR}" "${STEAMAPPDATADIR}" # Declare envs and their default values ENV PUID=1000 \ From 91ad6a823c564c669395838f79b6fc2b477802bc Mon Sep 17 00:00:00 2001 From: Diyagi Date: Fri, 11 Oct 2024 22:06:47 +0000 Subject: [PATCH 06/28] Fix tail race condition --- scripts/launch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/launch.sh b/scripts/launch.sh index 4fdc465..d939bc7 100644 --- a/scripts/launch.sh +++ b/scripts/launch.sh @@ -33,7 +33,7 @@ ckpid=$! echo "Started server process with pid ${ckpid}" -tail --pid "$ckpid" -n +1 -f "$logfile" & +tail --pid "$ckpid" -n +1 -F "$logfile" & until [ -f GameID.txt ]; do sleep 0.1 From 95f7b0677b8ea8e2502b41287d6407729ebb8ab8 Mon Sep 17 00:00:00 2001 From: Diyagi Date: Tue, 15 Oct 2024 16:22:50 +0000 Subject: [PATCH 07/28] Add option for default param values --- scripts/compile-parameters.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/compile-parameters.sh b/scripts/compile-parameters.sh index 36038e8..f67891a 100644 --- a/scripts/compile-parameters.sh +++ b/scripts/compile-parameters.sh @@ -1,14 +1,19 @@ #!/bin/bash -# This scripts compiles parameters from an ENV arg to an array +# This scripts compiles parameters from an set of ENV variables to an array # this should be run with source, so the params ENV becomes avaliable. +# Function to add arguments to parameter array +# usage: add_param <$env_value> [default_value] add_param() { local param_name="$1" local param_value="$2" + local param_default="$3" if [ -n "$param_value" ]; then params+=("$param_name" "$param_value") + elif [ -n "$param_default" ]; then + params+=("$param_name" "$param_default") fi } @@ -24,7 +29,7 @@ add_param "-worldname" "$WORLD_NAME" add_param "-worldseed" "$WORLD_SEED" add_param "-worldmode" "$WORLD_MODE" add_param "-gameid" "$GAME_ID" -add_param "-datapath" "$DATA_PATH" +add_param "-datapath" "$DATA_PATH" "${STEAMAPPDATADIR}" add_param "-maxplayers" "$MAX_PLAYERS" add_param "-season" "$SEASON" add_param "-ip" "$SERVER_IP" From bb82ca051c7083ded5cd3211d384a3b247069628 Mon Sep 17 00:00:00 2001 From: Diyagi Date: Tue, 15 Oct 2024 16:23:56 +0000 Subject: [PATCH 08/28] Create log file before starting the server --- scripts/launch.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/launch.sh b/scripts/launch.sh index d939bc7..58a6672 100644 --- a/scripts/launch.sh +++ b/scripts/launch.sh @@ -23,6 +23,10 @@ if [ -f "GameID.txt" ]; then rm GameID.txt; fi # Creates `logfile` var with log file path. source "${SCRIPTSDIR}/compile-parameters.sh" +# Create the log file and folder. +mkdir -p "${STEAMAPPDIR}/logs" +touch "$logfile" + # Start Xvfb Xvfb :99 -screen 0 1x1x24 -nolisten tcp & xvfbpid=$! @@ -33,7 +37,7 @@ ckpid=$! echo "Started server process with pid ${ckpid}" -tail --pid "$ckpid" -n +1 -F "$logfile" & +tail --pid "$ckpid" -n +1 -f "$logfile" & until [ -f GameID.txt ]; do sleep 0.1 From 6e297855add325f75ab4d1fab0bb7274cefec0ef Mon Sep 17 00:00:00 2001 From: Diyagi Date: Fri, 18 Oct 2024 01:53:27 -0300 Subject: [PATCH 09/28] Switch to gosu to fix unreliable shutdown Using su causes issues with tini, because su creates a new process hierarchy tini cannot properly forward signals to its childs, causing the game server to not shutdown properly in some cases, using gosu fully fixes those issues --- Dockerfile | 2 ++ scripts/entry.sh | 2 +- scripts/launch.sh | 9 +++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2428de9..96a297e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,7 @@ ENV STEAMAPP core-keeper ENV STEAMAPPDIR "${HOMEDIR}/${STEAMAPP}-dedicated" ENV STEAMAPPDATADIR "${HOMEDIR}/${STEAMAPP}-data" ENV SCRIPTSDIR "${HOMEDIR}/scripts" +ENV MODSDIR "${STEAMAPPDATADIR}/StreamingAssets/Mods" ENV DLURL https://raw.githubusercontent.com/escapingnetwork/core-keeper-dedicated RUN dpkg --add-architecture i386 @@ -23,6 +24,7 @@ RUN set -x \ libxi6 \ tini \ tzdata \ + gosu \ && rm -rf /var/lib/apt/lists/* # Setup X11 Sockets folder diff --git a/scripts/entry.sh b/scripts/entry.sh index 3e8c9e2..b03e72d 100644 --- a/scripts/entry.sh +++ b/scripts/entry.sh @@ -32,7 +32,7 @@ fi if [ -f "/tmp/.X99-lock" ]; then rm /tmp/.X99-lock; fi if [[ "$(id -u)" -eq 0 ]]; then - exec su "${USER}" -c "exec bash ${SCRIPTSDIR}/setup.sh" + exec gosu "${USER}" bash "${SCRIPTSDIR}/setup.sh" else exec bash "${SCRIPTSDIR}/setup.sh" fi diff --git a/scripts/launch.sh b/scripts/launch.sh index 58a6672..a6851ce 100644 --- a/scripts/launch.sh +++ b/scripts/launch.sh @@ -9,12 +9,13 @@ function kill_corekeeperserver { kill $ckpid wait $ckpid fi - if [[ -n "$xvfbpid" ]]; then - kill $xvfbpid - fi + if [[ ! -z "$xvfbpid" ]]; then + kill $xvfbpid + wait $xvfbpid + fi } -trap kill_corekeeperserver EXIT TERM +trap kill_corekeeperserver EXIT if [ -f "GameID.txt" ]; then rm GameID.txt; fi From 4152561b4ca4a5412cd9d77bf137ed1f9f7198f5 Mon Sep 17 00:00:00 2001 From: Diyagi Date: Fri, 18 Oct 2024 01:55:57 -0300 Subject: [PATCH 10/28] Fix formatting --- scripts/launch.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/launch.sh b/scripts/launch.sh index a6851ce..6fe9b4c 100644 --- a/scripts/launch.sh +++ b/scripts/launch.sh @@ -9,10 +9,10 @@ function kill_corekeeperserver { kill $ckpid wait $ckpid fi - if [[ ! -z "$xvfbpid" ]]; then - kill $xvfbpid + if [[ ! -z "$xvfbpid" ]]; then + kill $xvfbpid wait $xvfbpid - fi + fi } trap kill_corekeeperserver EXIT From bc3f53a4da133e68f912f4710dad43e07c9c2701 Mon Sep 17 00:00:00 2001 From: Diyagi Date: Fri, 18 Oct 2024 11:35:50 -0300 Subject: [PATCH 11/28] Add .shellcheckrc and more formatting --- .shellcheckrc | 1 + scripts/compile-parameters.sh | 20 ++++++++++---------- scripts/launch.sh | 5 +++-- 3 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 .shellcheckrc diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 0000000..256d0e6 --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1 @@ +external-sources=true \ No newline at end of file diff --git a/scripts/compile-parameters.sh b/scripts/compile-parameters.sh index f67891a..3601e50 100644 --- a/scripts/compile-parameters.sh +++ b/scripts/compile-parameters.sh @@ -6,22 +6,22 @@ # Function to add arguments to parameter array # usage: add_param <$env_value> [default_value] add_param() { - local param_name="$1" - local param_value="$2" - local param_default="$3" + local param_name="$1" + local param_value="$2" + local param_default="$3" - if [ -n "$param_value" ]; then - params+=("$param_name" "$param_value") - elif [ -n "$param_default" ]; then - params+=("$param_name" "$param_default") - fi + if [ -n "$param_value" ]; then + params+=("$param_name" "$param_value") + elif [ -n "$param_default" ]; then + params+=("$param_name" "$param_default") + fi } # Makes log file avaliable for other uses. logfile="${STEAMAPPDIR}/logs/$(date '+%Y-%m-%d_%H-%M-%S').log" params=( - "-batchmode" - "-logfile" "$logfile" + "-batchmode" + "-logfile" "$logfile" ) add_param "-world" "$WORLD_INDEX" diff --git a/scripts/launch.sh b/scripts/launch.sh index 6fe9b4c..fb7df41 100644 --- a/scripts/launch.sh +++ b/scripts/launch.sh @@ -1,7 +1,7 @@ #!/bin/bash # Switch to workdir -cd "${STEAMAPPDIR}" +cd "${STEAMAPPDIR}" || exit ### Function for gracefully shutdown function kill_corekeeperserver { @@ -9,7 +9,7 @@ function kill_corekeeperserver { kill $ckpid wait $ckpid fi - if [[ ! -z "$xvfbpid" ]]; then + if [[ -n "$xvfbpid" ]]; then kill $xvfbpid wait $xvfbpid fi @@ -47,6 +47,7 @@ done gameid=$( Date: Fri, 18 Oct 2024 12:00:11 -0300 Subject: [PATCH 12/28] Add .gitattributes --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..d8c6dc6 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Ensure the scripts use LF line endings, not CRLF +*.sh text eol=lf \ No newline at end of file From 706fd865d66358e378d18ed629cc357e8ee50270 Mon Sep 17 00:00:00 2001 From: Diyagi Date: Fri, 18 Oct 2024 12:03:26 -0300 Subject: [PATCH 13/28] Change from tabs to space --- Dockerfile | 52 +++++++++++++++++------------------ scripts/compile-parameters.sh | 20 +++++++------- scripts/entry.sh | 34 +++++++++++------------ scripts/launch.sh | 24 ++++++++-------- scripts/setup.sh | 10 +++---- 5 files changed, 70 insertions(+), 70 deletions(-) diff --git a/Dockerfile b/Dockerfile index 96a297e..b04bfb1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,42 +18,42 @@ RUN dpkg --add-architecture i386 # Install Core Keeper server dependencies and clean up RUN set -x \ - && apt-get update \ - && apt-get install -y --no-install-recommends --no-install-suggests \ - xvfb \ - libxi6 \ - tini \ - tzdata \ - gosu \ - && rm -rf /var/lib/apt/lists/* + && apt-get update \ + && apt-get install -y --no-install-recommends --no-install-suggests \ + xvfb \ + libxi6 \ + tini \ + tzdata \ + gosu \ + && rm -rf /var/lib/apt/lists/* # Setup X11 Sockets folder RUN mkdir /tmp/.X11-unix \ - && chmod 1777 /tmp/.X11-unix \ - && chown root /tmp/.X11-unix + && chmod 1777 /tmp/.X11-unix \ + && chown root /tmp/.X11-unix # Setup folders COPY ./scripts ${SCRIPTSDIR} RUN set -x \ - && chmod +x -R "${SCRIPTSDIR}" \ - && mkdir -p "${STEAMAPPDIR}" \ - && mkdir -p "${STEAMAPPDATADIR}" \ - && chown -R "${USER}:${USER}" "${SCRIPTSDIR}" "${STEAMAPPDIR}" "${STEAMAPPDATADIR}" + && chmod +x -R "${SCRIPTSDIR}" \ + && mkdir -p "${STEAMAPPDIR}" \ + && mkdir -p "${STEAMAPPDATADIR}" \ + && chown -R "${USER}:${USER}" "${SCRIPTSDIR}" "${STEAMAPPDIR}" "${STEAMAPPDATADIR}" # Declare envs and their default values ENV PUID=1000 \ - PGID=1000 \ - WORLD_INDEX=0 \ - WORLD_NAME="Core Keeper Server" \ - WORLD_SEED=0 \ - WORLD_MODE=0 \ - GAME_ID="" \ - DATA_PATH="${STEAMAPPDATADIR}" \ - MAX_PLAYERS=10 \ - SEASON=-1 \ - SERVER_IP="" \ - SERVER_PORT="" \ - DISCORD_HOOK="" + PGID=1000 \ + WORLD_INDEX=0 \ + WORLD_NAME="Core Keeper Server" \ + WORLD_SEED=0 \ + WORLD_MODE=0 \ + GAME_ID="" \ + DATA_PATH="${STEAMAPPDATADIR}" \ + MAX_PLAYERS=10 \ + SEASON=-1 \ + SERVER_IP="" \ + SERVER_PORT="" \ + DISCORD_HOOK="" # Switch to workdir WORKDIR ${HOMEDIR} diff --git a/scripts/compile-parameters.sh b/scripts/compile-parameters.sh index 3601e50..f67891a 100644 --- a/scripts/compile-parameters.sh +++ b/scripts/compile-parameters.sh @@ -6,22 +6,22 @@ # Function to add arguments to parameter array # usage: add_param <$env_value> [default_value] add_param() { - local param_name="$1" - local param_value="$2" - local param_default="$3" + local param_name="$1" + local param_value="$2" + local param_default="$3" - if [ -n "$param_value" ]; then - params+=("$param_name" "$param_value") - elif [ -n "$param_default" ]; then - params+=("$param_name" "$param_default") - fi + if [ -n "$param_value" ]; then + params+=("$param_name" "$param_value") + elif [ -n "$param_default" ]; then + params+=("$param_name" "$param_default") + fi } # Makes log file avaliable for other uses. logfile="${STEAMAPPDIR}/logs/$(date '+%Y-%m-%d_%H-%M-%S').log" params=( - "-batchmode" - "-logfile" "$logfile" + "-batchmode" + "-logfile" "$logfile" ) add_param "-world" "$WORLD_INDEX" diff --git a/scripts/entry.sh b/scripts/entry.sh index b03e72d..4f7db95 100644 --- a/scripts/entry.sh +++ b/scripts/entry.sh @@ -4,35 +4,35 @@ # Checks for root, updates UID and GID of user steam # and updates folders owners if [[ "$(id -u)" -eq 0 ]] && [[ "$(id -g)" -eq 0 ]]; then - if [[ "${PUID}" -ne 0 ]] && [[ "${PGID}" -ne 0 ]]; then - echo "EXECUTING USERMOD" - usermod -o -u "${PUID}" "${USER}" - groupmod -o -g "${PGID}" "${USER}" - chown -R "${USER}:${USER}" "${HOMEDIR}" - else - echo "Running as root is not supported, please fix your PUID and PGID!" - exit 1 - fi + if [[ "${PUID}" -ne 0 ]] && [[ "${PGID}" -ne 0 ]]; then + echo "EXECUTING USERMOD" + usermod -o -u "${PUID}" "${USER}" + groupmod -o -g "${PGID}" "${USER}" + chown -R "${USER}:${USER}" "${HOMEDIR}" + else + echo "Running as root is not supported, please fix your PUID and PGID!" + exit 1 + fi elif [[ "$(id -u)" -eq 0 ]] || [[ "$(id -g)" -eq 0 ]]; then - echo "Running as root is not supported, please fix your user!" - exit 1 + echo "Running as root is not supported, please fix your user!" + exit 1 fi if ! [ -w "${STEAMAPPDIR}" ]; then - echo "${STEAMAPPDIR} is not writable." - exit 1 + echo "${STEAMAPPDIR} is not writable." + exit 1 fi if ! [ -w "${STEAMAPPDATADIR}" ]; then - echo "${STEAMAPPDATADIR} is not writable." - exit 1 + echo "${STEAMAPPDATADIR} is not writable." + exit 1 fi #Restart cleanup if [ -f "/tmp/.X99-lock" ]; then rm /tmp/.X99-lock; fi if [[ "$(id -u)" -eq 0 ]]; then - exec gosu "${USER}" bash "${SCRIPTSDIR}/setup.sh" + exec gosu "${USER}" bash "${SCRIPTSDIR}/setup.sh" else - exec bash "${SCRIPTSDIR}/setup.sh" + exec bash "${SCRIPTSDIR}/setup.sh" fi diff --git a/scripts/launch.sh b/scripts/launch.sh index fb7df41..9475167 100644 --- a/scripts/launch.sh +++ b/scripts/launch.sh @@ -5,14 +5,14 @@ cd "${STEAMAPPDIR}" || exit ### Function for gracefully shutdown function kill_corekeeperserver { - if [[ -n "$ckpid" ]]; then - kill $ckpid - wait $ckpid - fi - if [[ -n "$xvfbpid" ]]; then - kill $xvfbpid - wait $xvfbpid - fi + if [[ -n "$ckpid" ]]; then + kill $ckpid + wait $ckpid + fi + if [[ -n "$xvfbpid" ]]; then + kill $xvfbpid + wait $xvfbpid + fi } trap kill_corekeeperserver EXIT @@ -41,14 +41,14 @@ echo "Started server process with pid ${ckpid}" tail --pid "$ckpid" -n +1 -f "$logfile" & until [ -f GameID.txt ]; do - sleep 0.1 + sleep 0.1 done gameid=$( Date: Mon, 21 Oct 2024 19:11:12 -0300 Subject: [PATCH 14/28] Fix LD Lib Path It being wrong didnt cause any issues but better to fix it anyway --- scripts/launch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/launch.sh b/scripts/launch.sh index 9475167..ee191e9 100644 --- a/scripts/launch.sh +++ b/scripts/launch.sh @@ -33,7 +33,7 @@ Xvfb :99 -screen 0 1x1x24 -nolisten tcp & xvfbpid=$! # Start Core Keeper Server -DISPLAY=:99 LD_LIBRARY_PATH="$LD_LIBRARY_PATH:../Steamworks SDK Redist/linux64/" ./CoreKeeperServer "${params[@]}" & +DISPLAY=:99 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${STEAMCMDDIR}/linux64/" ./CoreKeeperServer "${params[@]}" & ckpid=$! echo "Started server process with pid ${ckpid}" From 42e49dbfddabea0f4f0ff947e0488ccdd458334a Mon Sep 17 00:00:00 2001 From: Diyagi Date: Mon, 21 Oct 2024 21:55:52 -0300 Subject: [PATCH 15/28] Update readme and env example --- README.md | 41 ++++++++++++++++++--------------- docker-compose-example/core.env | 14 +++++++---- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index a756dc2..b17c5b5 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Create two directories where you want to run your server : ### Using Docker Compose Create a `docker-compose.yml` with the following content: -``` +```yml version: "3" services: @@ -45,15 +45,16 @@ volumes: ``` Create a `core.env` file, it should contain the environment variables for the dedicated server, see configuration for reference. Example: -``` +```env +PUID=1000 +PGID=1000 WORLD_INDEX=0 WORLD_NAME=Core Keeper Server WORLD_SEED=0 WORLD_MODE=0 GAME_ID= -DATA_PATH=/home/steam/core-keeper-data +DATA_PATH= MAX_PLAYERS=10 -DISCORD=1 DISCORD_HOOK=https://discord.com/api/webhooks/{id}/{token} SEASON=-1 SERVER_IP= @@ -70,21 +71,23 @@ To query the game ID run: ## Configuration These are the arguments you can use to customize server behavior with default values. -``` -WORLD_INDEX Which world index to use. -WORLD_NAME The name to use for the server. -WORLD_SEED The seed to use for a new world. Set to 0 to generate random seed. -WORLD_MODE Sets the world mode for the world. Can be Normal (0), Hard (1), Creative (2), Casual (4). NOTE: Changing between Creative and non-Creative worlds not currently supported. -GAME_ID Game ID to use for the server. Need to be at least 28 characters and alphanumeric, excluding Y,y,x,0,O. Empty or not valid means a new ID will be generated at start. -DATA_PATH Save file location. If not set it defaults to a sub-folder named "DedicatedServer" at the default Core Keeper save location. -MAX_PLAYERS Maximum number of players that will be allowed to connect to server. -DISCORD Enables discord webhook features which sends GameID to a channel. -DISCORD_HOOK Webhook url (Edit channel > Integrations > Create Webhook). -DISCORD_PRINTF_STR The format string used to generate the content of the Discord webook. Default is `%s`, simply sending the GameID. -SEASON Overrides current season by setting to any of None (0), Easter (1), Halloween (2), Christmas (3), Valentine (4), Anniversary (5), CherryBlossom (6), LunarNewYear(7). -1 is default setting where it is set depending on system date. -SERVER_IP Only used if port is set. Sets the address that the server will bind to. -SERVER_PORT What port to bind to. If not set, then the server will use the Steam relay network. If set the clients will connect to the server directly and the port needs to be open. -``` + +| Argument | Default | Description | +| :---: | :---: | :---: | +| PUID | 1000 | The user ID on the host that the container should use for file ownership and permissions. | +| PGID | 1000 | The group ID on the host that the container should use for file ownership and permissions. | +| WORLD_INDEX | 0 | Which world index to use. | +| WORLD_NAME | "" | The name to use for the server. | +| WORLD_SEED | 0 | The seed to use for a new world. Set to 0 to generate random seed. | +| WORLD_MODE | 0 | Sets the world mode for the world. Can be Normal (0), Hard (1), Creative (2), Casual (4). | +| SEASON | -1 | Overrides current season by setting to any of None (0), Easter (1), Halloween (2), Christmas (3), Valentine (4), Anniversary (5), CherryBlossom (6), LunarNewYear(7) or Normal Date (-1). | +| GAME_ID | "" | Game ID to use for the server. Need to be at least 28 characters and alphanumeric, excluding Y,y,x,0,O. Empty or not valid means a new ID will be generated at start. | +| MAX_PLAYERS | 3 | Maximum number of players that will be allowed to connect to server. | +| DATA_PATH | "/home/steam/core-keeper-data" | Save file location. | +| DISCORD_HOOK | "" | Webhook url (Edit channel > Integrations > Create Webhook). | +| DISCORD_PRINTF_STR | "%s" | The format string used to generate the content of the Discord webook. | +| SERVER_IP | No Default | Only used if port is set. Sets the address that the server will bind to. | +| SERVER_PORT | No Default | What port to bind to. If not set, then the server will use the Steam relay network. If set the clients will connect to the server directly and the port needs to be open. | ### Contributors diff --git a/docker-compose-example/core.env b/docker-compose-example/core.env index 915b678..a178472 100644 --- a/docker-compose-example/core.env +++ b/docker-compose-example/core.env @@ -1,9 +1,13 @@ -GAME_ID= +PUID=1000 +PGID=1000 WORLD_INDEX=0 WORLD_NAME=Core Keeper Server WORLD_SEED=0 +WORLD_MODE=0 +GAME_ID= +DATA_PATH= MAX_PLAYERS=10 -DATA_PATH=/home/steam/core-keeper-data -DISCORD=1 -DISCORD_HOOK=https://discord.com/api/webhooks/id/token -SEASON=0 +DISCORD_HOOK=https://discord.com/api/webhooks/{id}/{token} +SEASON=-1 +SERVER_IP= +SERVER_PORT= From ac77651d097428abc482905646a6037dc8454ce0 Mon Sep 17 00:00:00 2001 From: Diyagi Date: Mon, 21 Oct 2024 22:01:27 -0300 Subject: [PATCH 16/28] Update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b17c5b5..ba289f6 100644 --- a/README.md +++ b/README.md @@ -77,12 +77,12 @@ These are the arguments you can use to customize server behavior with default va | PUID | 1000 | The user ID on the host that the container should use for file ownership and permissions. | | PGID | 1000 | The group ID on the host that the container should use for file ownership and permissions. | | WORLD_INDEX | 0 | Which world index to use. | -| WORLD_NAME | "" | The name to use for the server. | +| WORLD_NAME | "Core Keeper Server" | The name to use for the server. | | WORLD_SEED | 0 | The seed to use for a new world. Set to 0 to generate random seed. | | WORLD_MODE | 0 | Sets the world mode for the world. Can be Normal (0), Hard (1), Creative (2), Casual (4). | | SEASON | -1 | Overrides current season by setting to any of None (0), Easter (1), Halloween (2), Christmas (3), Valentine (4), Anniversary (5), CherryBlossom (6), LunarNewYear(7) or Normal Date (-1). | | GAME_ID | "" | Game ID to use for the server. Need to be at least 28 characters and alphanumeric, excluding Y,y,x,0,O. Empty or not valid means a new ID will be generated at start. | -| MAX_PLAYERS | 3 | Maximum number of players that will be allowed to connect to server. | +| MAX_PLAYERS | 10 | Maximum number of players that will be allowed to connect to server. | | DATA_PATH | "/home/steam/core-keeper-data" | Save file location. | | DISCORD_HOOK | "" | Webhook url (Edit channel > Integrations > Create Webhook). | | DISCORD_PRINTF_STR | "%s" | The format string used to generate the content of the Discord webook. | From 1948d94a253e236322ce82af5d16a83efa69c7c3 Mon Sep 17 00:00:00 2001 From: Diyagi Date: Tue, 22 Oct 2024 04:07:25 -0300 Subject: [PATCH 17/28] Remove version element from compose Level element has been deprecated, removing it should still be compatible with older compose versions --- README.md | 2 -- docker-compose-example/docker-compose.yml | 2 -- 2 files changed, 4 deletions(-) diff --git a/README.md b/README.md index ba289f6..a6676ee 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,6 @@ Create two directories where you want to run your server : Create a `docker-compose.yml` with the following content: ```yml -version: "3" - services: core-keeper: container_name: core-keeper-dedicated diff --git a/docker-compose-example/docker-compose.yml b/docker-compose-example/docker-compose.yml index aa8d924..15fc80e 100644 --- a/docker-compose-example/docker-compose.yml +++ b/docker-compose-example/docker-compose.yml @@ -1,5 +1,3 @@ -version: "3" - services: core-keeper: container_name: core-keeper-dedicated From d5bc07e2498b374802b598a883d6f435ef60f61c Mon Sep 17 00:00:00 2001 From: ArrowPrint <62302385+ArrowPrint@users.noreply.github.com> Date: Tue, 8 Oct 2024 16:53:39 +0200 Subject: [PATCH 18/28] Updated launch.sh with Discord integration --- scripts/launch.sh | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/scripts/launch.sh b/scripts/launch.sh index ee191e9..9c93931 100644 --- a/scripts/launch.sh +++ b/scripts/launch.sh @@ -45,10 +45,51 @@ until [ -f GameID.txt ]; do done gameid=$( Date: Tue, 8 Oct 2024 18:33:53 +0200 Subject: [PATCH 19/28] Update launch.sh --- scripts/launch.sh | 54 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/scripts/launch.sh b/scripts/launch.sh index 9c93931..239f23b 100644 --- a/scripts/launch.sh +++ b/scripts/launch.sh @@ -50,9 +50,9 @@ if [ -z "$DISCORD_HOOK" ]; then else echo "Discord gameid" format="${DISCORD_PRINTF_STR:-%s}" - curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{\"content\": \"$(printf "${format}" "${gameid}")\"}" "${DISCORD_HOOK}" + # curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{\"content\": \"$(printf "${format}" "${gameid}")\"}" "${DISCORD_HOOK}" - # Monitor server logs for player join/leave + # Monitor server logs for player join/leave, server start, and server stop tail -f CoreKeeperServerLog.txt | while read LOGLINE; do # Add timestamp to each log line echo "$(date '+%Y-%m-%d %H:%M:%S') - $LOGLINE" @@ -60,9 +60,9 @@ else # Detect player join based on log: [userid:12345] is using new name PlayerName if echo "$LOGLINE" | grep -q "is using new name"; then PLAYER_NAME=$(echo "$LOGLINE" | grep -oP "is using new name \K\w+") - echo "Player Name: $PLAYER_NAME" # Debugging: ensure player name is correct - if [ -n "$PLAYER_NAME" ]; then - WELCOME_MSG=$(echo "${DISCORD_MESSAGE_WELCOME:-'Welcome, \$\$user!'}" | sed "s/\$\$user/$PLAYER_NAME/g") + echo "Player Name: $PLAYER_NAME" # Debugging: ensure player name is correct + if [ -n "$DISCORD_MESSAGE_WELCOME" ]; then # Only send if DISCORD_MESSAGE_WELCOME is set + WELCOME_MSG=$(echo "$DISCORD_MESSAGE_WELCOME" | sed "s/\$\$user/$PLAYER_NAME/g") echo "Generated Welcome Message: $WELCOME_MSG" # Debugging: ensure message is correct # Check if WELCOME_MSG is empty before sending @@ -71,14 +71,16 @@ else else curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST --data "{\"content\": \"$(printf "${format}" "${WELCOME_MSG}")\"}" "${DISCORD_HOOK}" fi + else + echo "DISCORD_MESSAGE_WELCOME not set. Skipping Discord notification." fi fi # Detect potential player leave if echo "$LOGLINE" | grep -q "Accepted connection from .* with result OK awaiting authentication"; then PLAYER_NAME=$(echo "$LOGLINE" | grep -oP "Connected to userid:.*") - if [ -n "$PLAYER_NAME" ]; then - BYE_MSG=$(echo "${DISCORD_MESSAGE_BYE:-'Goodbye, $$user!'}" | sed "s/\$\$user/$PLAYER_NAME/g") + if [ -n "$DISCORD_MESSAGE_BYE" ]; then # Only send if DISCORD_MESSAGE_BYE is set + BYE_MSG=$(echo "$DISCORD_MESSAGE_BYE" | sed "s/\$\$user/$PLAYER_NAME/g") echo "Generated Bye Message: $BYE_MSG" # Debugging: ensure message is correct # Check if BYE_MSG is empty before sending @@ -87,6 +89,44 @@ else else curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST --data "{\"content\": \"$(printf "${format}" "${BYE_MSG}")\"}" "${DISCORD_HOOK}" fi + else + echo "DISCORD_MESSAGE_BYE not set. Skipping Discord notification." + fi + fi + + # Detect server start message: Started session with Game ID + if echo "$LOGLINE" | grep -q "Started session with Game ID"; then + echo "Server start detected" # Debugging: detect start request + if [ -n "$DISCORD_MESSAGE_START" ]; then # Only send if DISCORD_MESSAGE_START is set + START_MSG=$(echo "$DISCORD_MESSAGE_START" | sed "s/\$\$WORLD_NAME/$WORLD_NAME/g" | sed "s/\$\$gameid/$gameid/g") + echo "Generated Start Message: $START_MSG" # Debugging: ensure start message is correct + + # Check if START_MSG is empty before sending + if [ -z "$START_MSG" ]; then + echo "Error: Start message is empty" + else + curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST --data "{\"content\": \"$(printf "${format}" "${START_MSG}")\"}" "${DISCORD_HOOK}" + fi + else + echo "DISCORD_MESSAGE_START not set. Skipping Discord notification." + fi + fi + + # Detect server stop message: Got quit request + if echo "$LOGLINE" | grep -q "Got quit request"; then + echo "Server stop detected" # Debugging: detect quit request + if [ -n "$DISCORD_MESSAGE_STOP" ]; then # Only send if DISCORD_MESSAGE_STOP is set + STOP_MSG=$(echo "$DISCORD_MESSAGE_STOP" | sed "s/\$\$WORLD_NAME/$WORLD_NAME/g") + echo "Generated Stop Message: $STOP_MSG" # Debugging: ensure stop message is correct + + # Check if STOP_MSG is empty before sending + if [ -z "$STOP_MSG" ]; then + echo "Error: Stop message is empty" + else + curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST --data "{\"content\": \"$(printf "${format}" "${STOP_MSG}")\"}" "${DISCORD_HOOK}" + fi + else + echo "DISCORD_MESSAGE_STOP not set. Skipping Discord notification." fi fi done From 2c7f4e406b7e922c1351a844ecbcee296e8d8d6e Mon Sep 17 00:00:00 2001 From: Diyagi Date: Sun, 27 Oct 2024 12:55:38 -0300 Subject: [PATCH 20/28] Change add_param function --- scripts/compile-parameters.sh | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/scripts/compile-parameters.sh b/scripts/compile-parameters.sh index f67891a..be1d213 100644 --- a/scripts/compile-parameters.sh +++ b/scripts/compile-parameters.sh @@ -4,16 +4,13 @@ # this should be run with source, so the params ENV becomes avaliable. # Function to add arguments to parameter array -# usage: add_param <$env_value> [default_value] +# usage: add_param <$env_value> add_param() { local param_name="$1" local param_value="$2" - local param_default="$3" if [ -n "$param_value" ]; then params+=("$param_name" "$param_value") - elif [ -n "$param_default" ]; then - params+=("$param_name" "$param_default") fi } @@ -24,15 +21,15 @@ params=( "-logfile" "$logfile" ) -add_param "-world" "$WORLD_INDEX" -add_param "-worldname" "$WORLD_NAME" -add_param "-worldseed" "$WORLD_SEED" -add_param "-worldmode" "$WORLD_MODE" -add_param "-gameid" "$GAME_ID" -add_param "-datapath" "$DATA_PATH" "${STEAMAPPDATADIR}" -add_param "-maxplayers" "$MAX_PLAYERS" -add_param "-season" "$SEASON" -add_param "-ip" "$SERVER_IP" -add_param "-port" "$SERVER_PORT" +add_param "-world" "${WORLD_INDEX}" +add_param "-worldname" "${WORLD_NAME}" +add_param "-worldseed" "${WORLD_SEED}" +add_param "-worldmode" "${WORLD_MODE}" +add_param "-gameid" "${GAME_ID}" +add_param "-datapath" "${DATA_PATH:-${STEAMAPPDATADIR}}" +add_param "-maxplayers" "${MAX_PLAYERS}" +add_param "-season" "${SEASON}" +add_param "-ip" "${SERVER_IP}" +add_param "-port" "${SERVER_PORT}" echo "${params[@]}" From c3de98aaeb5b3374df6cf9355fb68b23dd9d5960 Mon Sep 17 00:00:00 2001 From: Diyagi Date: Sun, 27 Oct 2024 12:57:11 -0300 Subject: [PATCH 21/28] Refactor log parsing and discord webhook function --- Dockerfile | 24 ++++++++- scripts/discord.sh | 14 +++++ scripts/entry.sh | 11 ++-- scripts/helper-functions.sh | 60 +++++++++++++++++++++ scripts/launch.sh | 105 ++++-------------------------------- scripts/logfile-parser.sh | 51 ++++++++++++++++++ 6 files changed, 165 insertions(+), 100 deletions(-) create mode 100644 scripts/discord.sh create mode 100644 scripts/helper-functions.sh create mode 100644 scripts/logfile-parser.sh diff --git a/Dockerfile b/Dockerfile index b04bfb1..66dbd63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,6 +25,8 @@ RUN set -x \ tini \ tzdata \ gosu \ + jo \ + gettext-base \ && rm -rf /var/lib/apt/lists/* # Setup X11 Sockets folder @@ -53,7 +55,27 @@ ENV PUID=1000 \ SEASON=-1 \ SERVER_IP="" \ SERVER_PORT="" \ - DISCORD_HOOK="" + DISCORD_WEBHOOK_URL="" \ + # Player Join + DISCORD_PLAYER_JOIN_ENABLED=true \ + DISCORD_PLAYER_JOIN_MESSAGE='${char_name} (${steamid}) has joined the server.' \ + DISCORD_PLAYER_JOIN_TITLE="Player Joined" \ + DISCORD_PLAYER_JOIN_COLOR="47456" \ + # Player Leave + DISCORD_PLAYER_LEAVE_ENABLED=true \ + DISCORD_PLAYER_LEAVE_MESSAGE='${char_name} (${steamid}) has disconnected. Reason: ${reason}.' \ + DISCORD_PLAYER_LEAVE_TITLE="Player left" \ + DISCORD_PLAYER_LEAVE_COLOR="11477760" \ + # Server Start + DISCORD_SERVER_START_ENABLED=true \ + DISCORD_SERVER_START_MESSAGE='**World:** ${world_name}\n**GameID:** ${gameid}' \ + DISCORD_SERVER_START_TITLE="Server Started" \ + DISCORD_SERVER_START_COLOR="2013440" \ + # Server Stop + DISCORD_SERVER_STOP_ENABLED=true \ + DISCORD_SERVER_STOP_MESSAGE="" \ + DISCORD_SERVER_STOP_TITLE="Server Stopped" \ + DISCORD_SERVER_STOP_COLOR="12779520" # Switch to workdir WORKDIR ${HOMEDIR} diff --git a/scripts/discord.sh b/scripts/discord.sh new file mode 100644 index 0000000..0181b16 --- /dev/null +++ b/scripts/discord.sh @@ -0,0 +1,14 @@ +#!/bin/bash +source "${SCRIPTSDIR}/helper-functions.sh" + +TITLE=$1 +MESSAGE=$2 +COLOR=$3 +URL=$4 + +DISCORD_URL="${URL:-${DISCORD_WEBHOOK_URL}}" + +JSON=$(jo embeds[]="$(jo title="$TITLE" description="$MESSAGE" color="$COLOR")") + +LogInfo "Sending Discord json: ${JSON}" +curl -sfSL -H "Content-Type: application/json" -d "$JSON" "$DISCORD_URL" diff --git a/scripts/entry.sh b/scripts/entry.sh index 4f7db95..115c929 100644 --- a/scripts/entry.sh +++ b/scripts/entry.sh @@ -1,30 +1,31 @@ #!/bin/bash +source "${SCRIPTSDIR}/helper-functions.sh" # From: https://github.com/thijsvanloef/palworld-server-docker/blob/32ffe489daecbc332701592f2facf0fe3237c65f/scripts/init.sh#L15 # Checks for root, updates UID and GID of user steam # and updates folders owners if [[ "$(id -u)" -eq 0 ]] && [[ "$(id -g)" -eq 0 ]]; then if [[ "${PUID}" -ne 0 ]] && [[ "${PGID}" -ne 0 ]]; then - echo "EXECUTING USERMOD" + LogAction "EXECUTING USERMOD" usermod -o -u "${PUID}" "${USER}" groupmod -o -g "${PGID}" "${USER}" chown -R "${USER}:${USER}" "${HOMEDIR}" else - echo "Running as root is not supported, please fix your PUID and PGID!" + LogError "Running as root is not supported, please fix your PUID and PGID!" exit 1 fi elif [[ "$(id -u)" -eq 0 ]] || [[ "$(id -g)" -eq 0 ]]; then - echo "Running as root is not supported, please fix your user!" + LogError "Running as root is not supported, please fix your user!" exit 1 fi if ! [ -w "${STEAMAPPDIR}" ]; then - echo "${STEAMAPPDIR} is not writable." + LogError "${STEAMAPPDIR} is not writable." exit 1 fi if ! [ -w "${STEAMAPPDATADIR}" ]; then - echo "${STEAMAPPDATADIR} is not writable." + LogError "${STEAMAPPDATADIR} is not writable." exit 1 fi diff --git a/scripts/helper-functions.sh b/scripts/helper-functions.sh new file mode 100644 index 0000000..489885f --- /dev/null +++ b/scripts/helper-functions.sh @@ -0,0 +1,60 @@ +#!/bin/bash + + +## Logging Functions +declare -A COLORS=( + ["RESET"]='\033[0m' + ["WHITE"]='\033[0;37m' + ["RED_BOLD"]='\033[1;31m' + ["GREEN_BOLD"]='\033[1;32m' + ["YELLOW_BOLD"]='\033[1;33m' + ["CYAN_BOLD"]='\033[1;36m' + ["BLUE"]='\033[0;34m' +) + +# Generic logging function +Log() { + local message="$1" + local color="$2" + printf "${color}%s${COLORS["RESET"]}\n" "$message" +} + +# Specific logging functions +LogInfo() { + Log "$1" "${COLORS["WHITE"]}" +} +LogWarn() { + Log "$1" "${COLORS["YELLOW_BOLD"]}" +} +LogError() { + Log "$1" "${COLORS["RED_BOLD"]}" +} +LogSuccess() { + Log "$1" "${COLORS["GREEN_BOLD"]}" +} +LogAction() { + Log "$1" "${COLORS["CYAN_BOLD"]}" +} +LogDebug() { + if [[ "${DEBUG,,}" == true ]]; then + Log "$1" "${COLORS["BLUE"]}" + fi +} + +SendDiscordMessage() { + local title="$1" + local message="$2" + local color="$3" + local wait="$4" + + if [ -n "${DISCORD_WEBHOOK_URL}" ]; then + # printf is to solve issues with literal \n and jo + # shellcheck disable=SC2059 + "${SCRIPTSDIR}"/discord.sh "$title" "$(printf "$message")" "$color" & + waitpid=$! + fi + + if [[ "${wait,,}" == true ]]; then + wait "$waitpid" + fi +} diff --git a/scripts/launch.sh b/scripts/launch.sh index 239f23b..6799a00 100644 --- a/scripts/launch.sh +++ b/scripts/launch.sh @@ -1,4 +1,5 @@ #!/bin/bash +source "${SCRIPTSDIR}/helper-functions.sh" # Switch to workdir cd "${STEAMAPPDIR}" || exit @@ -13,6 +14,12 @@ function kill_corekeeperserver { kill $xvfbpid wait $xvfbpid fi + + # Sends stop message + if [[ "${DISCORD_SERVER_STOP_ENABLED,,}" == true ]]; then + wait=true + SendDiscordMessage "$DISCORD_SERVER_STOP_TITLE" "$DISCORD_SERVER_STOP_MESSAGE" "$DISCORD_SERVER_STOP_COLOR" "$wait" + fi } trap kill_corekeeperserver EXIT @@ -36,100 +43,10 @@ xvfbpid=$! DISPLAY=:99 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${STEAMCMDDIR}/linux64/" ./CoreKeeperServer "${params[@]}" & ckpid=$! -echo "Started server process with pid ${ckpid}" - -tail --pid "$ckpid" -n +1 -f "$logfile" & - -until [ -f GameID.txt ]; do - sleep 0.1 -done - -gameid=$( Date: Mon, 28 Oct 2024 03:36:12 -0300 Subject: [PATCH 22/28] Update readme and .env examples Also fixes the issue with seasons --- Dockerfile | 4 +-- README.md | 56 +++++++++++++++++++++++++++------ docker-compose-example/core.env | 34 +++++++++++++++----- 3 files changed, 75 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index 66dbd63..3f28e3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,7 +52,7 @@ ENV PUID=1000 \ GAME_ID="" \ DATA_PATH="${STEAMAPPDATADIR}" \ MAX_PLAYERS=10 \ - SEASON=-1 \ + SEASON="" \ SERVER_IP="" \ SERVER_PORT="" \ DISCORD_WEBHOOK_URL="" \ @@ -64,7 +64,7 @@ ENV PUID=1000 \ # Player Leave DISCORD_PLAYER_LEAVE_ENABLED=true \ DISCORD_PLAYER_LEAVE_MESSAGE='${char_name} (${steamid}) has disconnected. Reason: ${reason}.' \ - DISCORD_PLAYER_LEAVE_TITLE="Player left" \ + DISCORD_PLAYER_LEAVE_TITLE="Player Left" \ DISCORD_PLAYER_LEAVE_COLOR="11477760" \ # Server Start DISCORD_SERVER_START_ENABLED=true \ diff --git a/README.md b/README.md index a6676ee..d51e452 100644 --- a/README.md +++ b/README.md @@ -47,16 +47,36 @@ Create a `core.env` file, it should contain the environment variables for the de PUID=1000 PGID=1000 WORLD_INDEX=0 -WORLD_NAME=Core Keeper Server +WORLD_NAME="Core Keeper Server" WORLD_SEED=0 WORLD_MODE=0 -GAME_ID= -DATA_PATH= +GAME_ID="" +DATA_PATH="${STEAMAPPDATADIR}" MAX_PLAYERS=10 -DISCORD_HOOK=https://discord.com/api/webhooks/{id}/{token} -SEASON=-1 -SERVER_IP= -SERVER_PORT= +SEASON="" +SERVER_IP="" +SERVER_PORT="" +DISCORD_WEBHOOK_URL="" +# Player Join +DISCORD_PLAYER_JOIN_ENABLED=true +DISCORD_PLAYER_JOIN_MESSAGE="$${char_name} ($${steamid}) has joined the server." +DISCORD_PLAYER_JOIN_TITLE="Player Joined" +DISCORD_PLAYER_JOIN_COLOR="47456" +# Player Leave +DISCORD_PLAYER_LEAVE_ENABLED=true +DISCORD_PLAYER_LEAVE_MESSAGE="$${char_name} ($${steamid}) has disconnected. Reason: $${reason}." +DISCORD_PLAYER_LEAVE_TITLE="Player Left" +DISCORD_PLAYER_LEAVE_COLOR="11477760" +# Server Start +DISCORD_SERVER_START_ENABLED=true +DISCORD_SERVER_START_MESSAGE="**World:** $${world_name}\n**GameID:** $${gameid}" +DISCORD_SERVER_START_TITLE="Server Started" +DISCORD_SERVER_START_COLOR="2013440" +# Server Stop +DISCORD_SERVER_STOP_ENABLED=true +DISCORD_SERVER_STOP_MESSAGE="" +DISCORD_SERVER_STOP_TITLE="Server Stopped" +DISCORD_SERVER_STOP_COLOR="12779520" ``` On the folder which contains the files run `docker-compose up -d`. @@ -78,14 +98,30 @@ These are the arguments you can use to customize server behavior with default va | WORLD_NAME | "Core Keeper Server" | The name to use for the server. | | WORLD_SEED | 0 | The seed to use for a new world. Set to 0 to generate random seed. | | WORLD_MODE | 0 | Sets the world mode for the world. Can be Normal (0), Hard (1), Creative (2), Casual (4). | -| SEASON | -1 | Overrides current season by setting to any of None (0), Easter (1), Halloween (2), Christmas (3), Valentine (4), Anniversary (5), CherryBlossom (6), LunarNewYear(7) or Normal Date (-1). | +| SEASON | No Default | Overrides current season by setting to any of None (0), Easter (1), Halloween (2), Christmas (3), Valentine (4), Anniversary (5), CherryBlossom (6), LunarNewYear(7).\n**Do not set this env var if you want real date season.** | | GAME_ID | "" | Game ID to use for the server. Need to be at least 28 characters and alphanumeric, excluding Y,y,x,0,O. Empty or not valid means a new ID will be generated at start. | | MAX_PLAYERS | 10 | Maximum number of players that will be allowed to connect to server. | | DATA_PATH | "/home/steam/core-keeper-data" | Save file location. | -| DISCORD_HOOK | "" | Webhook url (Edit channel > Integrations > Create Webhook). | -| DISCORD_PRINTF_STR | "%s" | The format string used to generate the content of the Discord webook. | | SERVER_IP | No Default | Only used if port is set. Sets the address that the server will bind to. | | SERVER_PORT | No Default | What port to bind to. If not set, then the server will use the Steam relay network. If set the clients will connect to the server directly and the port needs to be open. | +| DISCORD_WEBHOOK_URL | "" | Webhook url (Edit channel > Integrations > Create Webhook). | +| DISCORD_PLAYER_JOIN_ENABLED | true | Enable/Disable message on player join | +| DISCORD_PLAYER_JOIN_MESSAGE | "\$\${char_name} (\$\${steamid}) has joined the server." | Embed message | +| DISCORD_PLAYER_JOIN_TITLE | "Player Joined" | Embed title | +| DISCORD_PLAYER_JOIN_COLOR | "47456" | Embed color | +| DISCORD_PLAYER_LEAVE_ENABLED | true | Enable/Disable message on player leave | +| DISCORD_PLAYER_LEAVE_MESSAGE | "\$\${char_name} (\$\${steamid}) has disconnected. Reason: \$\${reason}." | Embed message | +| DISCORD_PLAYER_LEAVE_TITLE | "Player Left" | Embed title | +| DISCORD_PLAYER_LEAVE_COLOR | "11477760" | Embed color | +| DISCORD_SERVER_START_ENABLED | true | Enable/Disable message on server start | +| DISCORD_SERVER_START_MESSAGE | "\*\*World:\*\* \$\${world_name}\n\*\*GameID:\*\* \$\${gameid}" | Embed message | +| DISCORD_SERVER_START_TITLE | "Server Started" | Embed title | +| DISCORD_SERVER_START_COLOR | "2013440" | Embed color | +| DISCORD_SERVER_STOP_ENABLED | true | Enable/Disable message on server stop | +| DISCORD_SERVER_STOP_MESSAGE | "" | Embed message | +| DISCORD_SERVER_STOP_TITLE | "Server Stopped" | Embed title | +| DISCORD_SERVER_STOP_COLOR | "12779520" | Embed color | + ### Contributors diff --git a/docker-compose-example/core.env b/docker-compose-example/core.env index a178472..3e812ea 100644 --- a/docker-compose-example/core.env +++ b/docker-compose-example/core.env @@ -1,13 +1,33 @@ PUID=1000 PGID=1000 WORLD_INDEX=0 -WORLD_NAME=Core Keeper Server +WORLD_NAME="Core Keeper Server" WORLD_SEED=0 WORLD_MODE=0 -GAME_ID= -DATA_PATH= +GAME_ID="" +DATA_PATH="${STEAMAPPDATADIR}" MAX_PLAYERS=10 -DISCORD_HOOK=https://discord.com/api/webhooks/{id}/{token} -SEASON=-1 -SERVER_IP= -SERVER_PORT= +SEASON="" +SERVER_IP="" +SERVER_PORT="" +DISCORD_WEBHOOK_URL="" +# Player Join +DISCORD_PLAYER_JOIN_ENABLED=true +DISCORD_PLAYER_JOIN_MESSAGE="$${char_name} ($${steamid}) has joined the server." +DISCORD_PLAYER_JOIN_TITLE="Player Joined" +DISCORD_PLAYER_JOIN_COLOR="47456" +# Player Leave +DISCORD_PLAYER_LEAVE_ENABLED=true +DISCORD_PLAYER_LEAVE_MESSAGE="$${char_name} ($${steamid}) has disconnected. Reason: $${reason}." +DISCORD_PLAYER_LEAVE_TITLE="Player Left" +DISCORD_PLAYER_LEAVE_COLOR="11477760" +# Server Start +DISCORD_SERVER_START_ENABLED=true +DISCORD_SERVER_START_MESSAGE="**World:** $${world_name}\n**GameID:** $${gameid}" +DISCORD_SERVER_START_TITLE="Server Started" +DISCORD_SERVER_START_COLOR="2013440" +# Server Stop +DISCORD_SERVER_STOP_ENABLED=true +DISCORD_SERVER_STOP_MESSAGE="" +DISCORD_SERVER_STOP_TITLE="Server Stopped" +DISCORD_SERVER_STOP_COLOR="12779520" From 9120f768a76bdee8328a0548a9c579cda2cf023b Mon Sep 17 00:00:00 2001 From: Diyagi Date: Mon, 28 Oct 2024 03:42:41 -0300 Subject: [PATCH 23/28] Inline messages in readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d51e452..1f7e1ab 100644 --- a/README.md +++ b/README.md @@ -106,15 +106,15 @@ These are the arguments you can use to customize server behavior with default va | SERVER_PORT | No Default | What port to bind to. If not set, then the server will use the Steam relay network. If set the clients will connect to the server directly and the port needs to be open. | | DISCORD_WEBHOOK_URL | "" | Webhook url (Edit channel > Integrations > Create Webhook). | | DISCORD_PLAYER_JOIN_ENABLED | true | Enable/Disable message on player join | -| DISCORD_PLAYER_JOIN_MESSAGE | "\$\${char_name} (\$\${steamid}) has joined the server." | Embed message | +| DISCORD_PLAYER_JOIN_MESSAGE | `"$${char_name} ($${steamid}) has joined the server."` | Embed message | | DISCORD_PLAYER_JOIN_TITLE | "Player Joined" | Embed title | | DISCORD_PLAYER_JOIN_COLOR | "47456" | Embed color | | DISCORD_PLAYER_LEAVE_ENABLED | true | Enable/Disable message on player leave | -| DISCORD_PLAYER_LEAVE_MESSAGE | "\$\${char_name} (\$\${steamid}) has disconnected. Reason: \$\${reason}." | Embed message | +| DISCORD_PLAYER_LEAVE_MESSAGE | `"$${char_name} ($${steamid}) has disconnected. Reason: $${reason}."` | Embed message | | DISCORD_PLAYER_LEAVE_TITLE | "Player Left" | Embed title | | DISCORD_PLAYER_LEAVE_COLOR | "11477760" | Embed color | | DISCORD_SERVER_START_ENABLED | true | Enable/Disable message on server start | -| DISCORD_SERVER_START_MESSAGE | "\*\*World:\*\* \$\${world_name}\n\*\*GameID:\*\* \$\${gameid}" | Embed message | +| DISCORD_SERVER_START_MESSAGE | `"**World:** $${world_name}\n**GameID:** $${gameid}"` | Embed message | | DISCORD_SERVER_START_TITLE | "Server Started" | Embed title | | DISCORD_SERVER_START_COLOR | "2013440" | Embed color | | DISCORD_SERVER_STOP_ENABLED | true | Enable/Disable message on server stop | From cee763ff43241c67890d975cfc94ecab103d2175 Mon Sep 17 00:00:00 2001 From: Diyagi Date: Mon, 28 Oct 2024 04:04:26 -0300 Subject: [PATCH 24/28] Update image build action --- .github/workflows/docker-image.yml | 77 ++++++++++++++++++------------ 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index fbf877e..7f8e41f 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,41 +1,58 @@ -name: Docker Image CI +name: Release on: - push: - branches: [ main ] - pull_request: - branches: [ main ] + release: + types: [published] jobs: + # Builds the Dockerfile and pushes it to dockerhub and GHCR + release: + name: Release - Docker image + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 - build: + - name: Docker - Login + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} - runs-on: ubuntu-latest + - name: Docker - GHCR Login + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} - steps: - - uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - - name: Docker Login - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v5.0.0 - with: - images: escaping/core-keeper-dedicated - tags: | - type=raw,value=latest - - - name: Build and push - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker - Metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ github.repository }} + ghcr.io/${{ github.repository }} + # generate Docker tags based on the following events/attributes + tags: | + type=semver,pattern=v{{version}} + type=semver,pattern=v{{major}}.{{minor}} + type=semver,pattern=v{{major}} + flavor: latest=true + + - name: Docker - Build / Push + id: docker_build + uses: docker/build-push-action@v5 + with: + platforms: linux/amd64 + push: true + tags: ${{ steps.meta.outputs.tags }} # - name: Update repo description # uses: peter-evans/dockerhub-description@v2 From befce9461500eaeef11f3de3fe3e817f613e9b32 Mon Sep 17 00:00:00 2001 From: Diyagi Date: Mon, 28 Oct 2024 04:17:03 -0300 Subject: [PATCH 25/28] Fix legacy warnings in Dockerfile --- Dockerfile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3f28e3a..961082f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,14 +5,14 @@ FROM cm2network/steamcmd:root LABEL maintainer="leandro.martin@protonmail.com" -ENV STEAMAPPID 1007 -ENV STEAMAPPID_TOOL 1963720 -ENV STEAMAPP core-keeper -ENV STEAMAPPDIR "${HOMEDIR}/${STEAMAPP}-dedicated" -ENV STEAMAPPDATADIR "${HOMEDIR}/${STEAMAPP}-data" -ENV SCRIPTSDIR "${HOMEDIR}/scripts" -ENV MODSDIR "${STEAMAPPDATADIR}/StreamingAssets/Mods" -ENV DLURL https://raw.githubusercontent.com/escapingnetwork/core-keeper-dedicated +ENV STEAMAPPID=1007 +ENV STEAMAPPID_TOOL=1963720 +ENV STEAMAPP=core-keeper +ENV STEAMAPPDIR="${HOMEDIR}/${STEAMAPP}-dedicated" +ENV STEAMAPPDATADIR="${HOMEDIR}/${STEAMAPP}-data" +ENV SCRIPTSDIR="${HOMEDIR}/scripts" +ENV MODSDIR="${STEAMAPPDATADIR}/StreamingAssets/Mods" +ENV DLURL=https://raw.githubusercontent.com/escapingnetwork/core-keeper-dedicated RUN dpkg --add-architecture i386 From e8b26f6ca90457cbabefd2da578257b811fc1f94 Mon Sep 17 00:00:00 2001 From: Diyagi Date: Mon, 28 Oct 2024 04:17:21 -0300 Subject: [PATCH 26/28] Update action build --- .github/workflows/docker-image.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 7f8e41f..51f0502 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -42,8 +42,6 @@ jobs: # generate Docker tags based on the following events/attributes tags: | type=semver,pattern=v{{version}} - type=semver,pattern=v{{major}}.{{minor}} - type=semver,pattern=v{{major}} flavor: latest=true - name: Docker - Build / Push From e86e15d6c7dea18abf2c4bf6443fe3b3e6af758a Mon Sep 17 00:00:00 2001 From: Diyagi Date: Mon, 28 Oct 2024 04:34:18 -0300 Subject: [PATCH 27/28] Add --pid to tail --- scripts/launch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/launch.sh b/scripts/launch.sh index 6799a00..aa4868f 100644 --- a/scripts/launch.sh +++ b/scripts/launch.sh @@ -47,6 +47,6 @@ LogDebug "Started server process with pid ${ckpid}" # Monitor server logs for player join/leave, server start, and server stop source "${SCRIPTSDIR}/logfile-parser.sh" -tail -f "$logfile" | LogParser & +tail --pid "$ckpid" -f "$logfile" | LogParser & wait $ckpid From 0d05ddf4bac99d95683405f9e689efa950d31ea6 Mon Sep 17 00:00:00 2001 From: Diyagi Date: Wed, 30 Oct 2024 05:22:42 -0300 Subject: [PATCH 28/28] Fix new line in readme env table --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f7e1ab..13eb701 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ These are the arguments you can use to customize server behavior with default va | WORLD_NAME | "Core Keeper Server" | The name to use for the server. | | WORLD_SEED | 0 | The seed to use for a new world. Set to 0 to generate random seed. | | WORLD_MODE | 0 | Sets the world mode for the world. Can be Normal (0), Hard (1), Creative (2), Casual (4). | -| SEASON | No Default | Overrides current season by setting to any of None (0), Easter (1), Halloween (2), Christmas (3), Valentine (4), Anniversary (5), CherryBlossom (6), LunarNewYear(7).\n**Do not set this env var if you want real date season.** | +| SEASON | No Default | Overrides current season by setting to any of None (0), Easter (1), Halloween (2), Christmas (3), Valentine (4), Anniversary (5), CherryBlossom (6), LunarNewYear(7).
**Do not set this env var if you want real date season.** | | GAME_ID | "" | Game ID to use for the server. Need to be at least 28 characters and alphanumeric, excluding Y,y,x,0,O. Empty or not valid means a new ID will be generated at start. | | MAX_PLAYERS | 10 | Maximum number of players that will be allowed to connect to server. | | DATA_PATH | "/home/steam/core-keeper-data" | Save file location. |