diff --git a/Dockerfile b/Dockerfile index 5fa14ba..0036353 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,21 @@ -FROM ubuntu:22.04 +FROM ubuntu:24.04 RUN dpkg --add-architecture i386 && \ apt-get update && \ echo steam steam/question select "I AGREE" | debconf-set-selections && \ echo steam steam/license note '' | debconf-set-selections && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y wine64 steamcmd && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y wine64 steamcmd curl dos2unix && \ apt-get clean autoclean && \ apt-get autoremove -y && \ rm -rf /var/lib/apt/lists/* ENV PATH="$PATH:/usr/games" +ENV UsePerfThreads=true +ENV NoAsyncLoadingThread=true +ENV AutoUpdate=true WORKDIR /steamcmd COPY ./entrypoint.sh /entrypoint.sh +RUN dos2unix /entrypoint.sh ENTRYPOINT ["bash", "/entrypoint.sh"] diff --git a/README.md b/README.md index 995fe14..e13ce17 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,12 @@ For operating a dedicated server in Docker in order to use it under Linux. The container uses Wine to run the server under Linux. +## NEW - Added Discord Webhook Integration for Session Code + +- Added discord webhook integration via container environment variable to spit out the invite code to any text channel you'd like. +- Add the environment variable "DISCORD_WEBHOOK_URL" and give it the webhook URL from the discord text channel you want it posted in. +- See [`docker-compose.yml.example`](docker-compose.yml.example) for an example. + ## Setup 1. Create a new empty directory in any location with enough storage space. 2. Create a file named `docker-compose.yml` and copy the content of [`docker-compose.yml.example`](docker-compose.yml.example) into it. diff --git a/docker-compose.yml.example b/docker-compose.yml.example index 428410a..9981fc0 100644 --- a/docker-compose.yml.example +++ b/docker-compose.yml.example @@ -1,6 +1,6 @@ services: abiotic-server: - image: "ghcr.io/pleut/abiotic-factor-linux-docker:latest" + image: "thisismynameok/abiotic-factor-linux-docker:latest" restart: unless-stopped volumes: - "./gamefiles:/server" @@ -16,6 +16,7 @@ services: - WorldSaveName=Cascade # - AutoUpdate=true # - AdditionalArgs=-SandboxIniPath=Config/WindowsServer/Server1Sandbox.ini + - DISCORD_WEBOOK_URL: ports: - "0.0.0.0:7777:7777/udp" - "0.0.0.0:27015:27015/udp" diff --git a/entrypoint.sh b/entrypoint.sh index 2e67b10..6bb8de4 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,3 +1,7 @@ +#!/bin/bash +set -euo pipefail + +# Configure server arguments SetUsePerfThreads="-useperfthreads " if [[ $UsePerfThreads == "false" ]]; then SetUsePerfThreads="" @@ -16,18 +20,46 @@ SteamServerName="${SteamServerName:-LinuxServer}" WorldSaveName="${WorldSaveName:-Cascade}" AdditionalArgs="${AdditionalArgs:-}" +# The Discord webhook URL is provided as an environment variable. +# If not provided, the game server still starts but without webhook integration. +DISCORD_WEBHOOK_URL="${DISCORD_WEBHOOK_URL:-}" + # Check for updates/perform initial installation if [ ! -d "/server/AbioticFactor/Binaries/Win64" ] || [[ $AutoUpdate == "true" ]]; then steamcmd \ - +@sSteamCmdForcePlatformType windows \ - +force_install_dir /server \ - +login anonymous \ - +app_update 2857200 validate \ - +quit + +@sSteamCmdForcePlatformType windows \ + +force_install_dir /server \ + +login anonymous \ + +app_update 2857200 validate \ + +quit fi pushd /server/AbioticFactor/Binaries/Win64 > /dev/null -wine AbioticFactorServer-Win64-Shipping.exe $SetUsePerfThreads$SetNoAsyncLoadingThread-MaxServerPlayers=$MaxServerPlayers \ - -PORT=$Port -QueryPort=$QueryPort -ServerPassword=$ServerPassword \ - -SteamServerName="$SteamServerName" -WorldSaveName="$WorldSaveName" -tcp $AdditionalArgs + +echo "Starting game server..." +if [ -z "$DISCORD_WEBHOOK_URL" ]; then + echo "Discord webhook URL not provided; server will run without webhook notifications." + wine AbioticFactorServer-Win64-Shipping.exe ${SetUsePerfThreads}${SetNoAsyncLoadingThread}-MaxServerPlayers=${MaxServerPlayers} \ + -PORT=${Port} -QueryPort=${QueryPort} -ServerPassword=${ServerPassword} \ + -SteamServerName="${SteamServerName}" -WorldSaveName="${WorldSaveName}" -tcp ${AdditionalArgs} +else + echo "Discord webhook enabled; monitoring logs for join code..." + # Run the game server, piping output to tee which both prints the log and sends it to the notifier. + wine AbioticFactorServer-Win64-Shipping.exe ${SetUsePerfThreads}${SetNoAsyncLoadingThread}-MaxServerPlayers=${MaxServerPlayers} \ + -PORT=${Port} -QueryPort=${QueryPort} -ServerPassword=${ServerPassword} \ + -SteamServerName="${SteamServerName}" -WorldSaveName="${WorldSaveName}" -tcp ${AdditionalArgs} \ + | tee >(while IFS= read -r line; do + # Forward the line to stdout + echo "$line" + # Look for the join code line – adjust this regex if needed. + if echo "$line" | grep -q "Session short code:"; then + join_code=$(echo "$line" | sed -n 's/.*Session short code: \([A-Z0-9]\+\).*/\1/p') + # Send only the join code to Discord via webhook + curl -H "Content-Type: application/json" \ + -d "{\"content\": \"${join_code}\"}" \ + "$DISCORD_WEBHOOK_URL" + fi + done) +fi + popd > /dev/null