From 39e1961472b86bb60c17054fd333da6d920f2a06 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 28 Feb 2025 14:37:39 +1100 Subject: [PATCH 1/8] Add discord webhook integration for invite code --- Dockerfile | 2 +- entrypoint.sh | 54 +++++++++++++++++++++++++++++++++++++---------- notify_discord.py | 38 +++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 12 deletions(-) create mode 100644 notify_discord.py diff --git a/Dockerfile b/Dockerfile index 5fa14ba..e825bbb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ 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 && \ apt-get clean autoclean && \ apt-get autoremove -y && \ rm -rf /var/lib/apt/lists/* diff --git a/entrypoint.sh b/entrypoint.sh index 2e67b10..20bfa3c 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,10 +1,14 @@ +#!/bin/bash +set -euo pipefail + +# Configure server arguments SetUsePerfThreads="-useperfthreads " -if [[ $UsePerfThreads == "false" ]]; then +if [[ "${UsePerfThreads:-true}" == "false" ]]; then SetUsePerfThreads="" fi SetNoAsyncLoadingThread="-NoAsyncLoadingThread " -if [[ $NoAsyncLoadingThread == "false" ]]; then +if [[ "${NoAsyncLoadingThread:-true}" == "false" ]]; then SetNoAsyncLoadingThread="" fi @@ -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 +if [ ! -d "/server/AbioticFactor/Binaries/Win64" ] || [[ "${AutoUpdate:-false}" == "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 diff --git a/notify_discord.py b/notify_discord.py new file mode 100644 index 0000000..cd7a859 --- /dev/null +++ b/notify_discord.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +import sys +import re +import requests + +# Replace with your actual Discord webhook URL +WEBHOOK_URL = "https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN" + +def send_to_discord(join_code): + """Send the join code to the Discord channel via webhook.""" + data = {"content": join_code} + try: + response = requests.post(WEBHOOK_URL, json=data) + if response.status_code == 204: + print("Discord webhook sent successfully!") + else: + print(f"Failed to send webhook: {response.status_code}, {response.text}") + except Exception as e: + print(f"Error sending webhook: {e}") + +def main(): + # Compile the regex to capture the join code (assuming it's a sequence of letters/digits) + pattern = re.compile(r"Session short code:\s*([A-Z0-9]+)") + already_sent = False # Optional: prevents sending duplicate codes + + for line in sys.stdin: + # Optionally, print the log normally + sys.stdout.write(line) + sys.stdout.flush() + + match = pattern.search(line) + if match and not already_sent: + join_code = match.group(1) + send_to_discord(join_code) + already_sent = True # Remove or adjust this if your code might change periodically + +if __name__ == "__main__": + main() From d6d302ff74ecebc600f036b328c633fc7f747de0 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 28 Feb 2025 14:57:24 +1100 Subject: [PATCH 2/8] Update README and docker-compose example --- README.md | 6 ++++++ docker-compose.yml.example | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) 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" From ebc0e6928340c1e8a22fee723fe16af297e42ef6 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 28 Feb 2025 15:20:21 +1100 Subject: [PATCH 3/8] Remove un-needed changes to server args --- entrypoint.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 20bfa3c..6bb8de4 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,12 +3,12 @@ set -euo pipefail # Configure server arguments SetUsePerfThreads="-useperfthreads " -if [[ "${UsePerfThreads:-true}" == "false" ]]; then +if [[ $UsePerfThreads == "false" ]]; then SetUsePerfThreads="" fi SetNoAsyncLoadingThread="-NoAsyncLoadingThread " -if [[ "${NoAsyncLoadingThread:-true}" == "false" ]]; then +if [[ $NoAsyncLoadingThread == "false" ]]; then SetNoAsyncLoadingThread="" fi @@ -25,7 +25,7 @@ AdditionalArgs="${AdditionalArgs:-}" DISCORD_WEBHOOK_URL="${DISCORD_WEBHOOK_URL:-}" # Check for updates/perform initial installation -if [ ! -d "/server/AbioticFactor/Binaries/Win64" ] || [[ "${AutoUpdate:-false}" == "true" ]]; then +if [ ! -d "/server/AbioticFactor/Binaries/Win64" ] || [[ $AutoUpdate == "true" ]]; then steamcmd \ +@sSteamCmdForcePlatformType windows \ +force_install_dir /server \ From ffe7d381c484269f41c9b678a2ed06bddb208677 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 28 Feb 2025 15:26:20 +1100 Subject: [PATCH 4/8] Remove un-needed notify_discord.py script - changes integrated into entrypoint.sh --- notify_discord.py | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 notify_discord.py diff --git a/notify_discord.py b/notify_discord.py deleted file mode 100644 index cd7a859..0000000 --- a/notify_discord.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python3 -import sys -import re -import requests - -# Replace with your actual Discord webhook URL -WEBHOOK_URL = "https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN" - -def send_to_discord(join_code): - """Send the join code to the Discord channel via webhook.""" - data = {"content": join_code} - try: - response = requests.post(WEBHOOK_URL, json=data) - if response.status_code == 204: - print("Discord webhook sent successfully!") - else: - print(f"Failed to send webhook: {response.status_code}, {response.text}") - except Exception as e: - print(f"Error sending webhook: {e}") - -def main(): - # Compile the regex to capture the join code (assuming it's a sequence of letters/digits) - pattern = re.compile(r"Session short code:\s*([A-Z0-9]+)") - already_sent = False # Optional: prevents sending duplicate codes - - for line in sys.stdin: - # Optionally, print the log normally - sys.stdout.write(line) - sys.stdout.flush() - - match = pattern.search(line) - if match and not already_sent: - join_code = match.group(1) - send_to_discord(join_code) - already_sent = True # Remove or adjust this if your code might change periodically - -if __name__ == "__main__": - main() From 138610b7bbb2b4920980a0c4ff31f9a41e7ba01a Mon Sep 17 00:00:00 2001 From: Steven Schmidt Date: Wed, 5 Mar 2025 15:23:12 +1100 Subject: [PATCH 5/8] Add EOL sequence conversion --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e825bbb..9468843 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ 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 curl && \ + 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/* @@ -14,4 +14,5 @@ ENV PATH="$PATH:/usr/games" WORKDIR /steamcmd COPY ./entrypoint.sh /entrypoint.sh +RUN dos2unix /entrypoint.sh ENTRYPOINT ["bash", "/entrypoint.sh"] From a64e83cadd9d0245523b8aafdcf6bf017861cd60 Mon Sep 17 00:00:00 2001 From: Steven Schmidt Date: Wed, 5 Mar 2025 20:51:49 +1100 Subject: [PATCH 6/8] Update base ubuntu image from 22.04 to 24.04 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9468843..08aac97 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:22.04 +FROM ubuntu:24.04 RUN dpkg --add-architecture i386 && \ apt-get update && \ From ea3a1e114d953a4c3d4432e49b469bc4b48c66df Mon Sep 17 00:00:00 2001 From: SugoiDogo Date: Sat, 21 Jun 2025 23:51:40 -0700 Subject: [PATCH 7/8] add default environment variables --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 08aac97..7e3e8a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,8 @@ RUN dpkg --add-architecture i386 && \ rm -rf /var/lib/apt/lists/* ENV PATH="$PATH:/usr/games" +ENV UsePerfThreads=true +ENV NoAsyncLoadingThread=true WORKDIR /steamcmd From d393427df2abded3590eadd5c8c356b4a352e32a Mon Sep 17 00:00:00 2001 From: SugoiDogo Date: Sun, 22 Jun 2025 00:07:13 -0700 Subject: [PATCH 8/8] Update Dockerfile --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 7e3e8a8..0036353 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,7 @@ RUN dpkg --add-architecture i386 && \ ENV PATH="$PATH:/usr/games" ENV UsePerfThreads=true ENV NoAsyncLoadingThread=true +ENV AutoUpdate=true WORKDIR /steamcmd