# panel-native Conan Exiles runtime image.
#
# Conan Exiles Dedicated Server is a Windows-only UE4 build. We bring just
# enough Wine + Xvfb to host it headlessly. SteamCMD is NOT installed here —
# the panel's generic updater sidecar uses the official steamcmd image and
# writes into our /game volume.
#
# Expected runtime layout inside the container:
#   /game                                                               — SteamCMD install
#   /game/ConanSandbox/Binaries/Win64/ConanSandboxServer-Win64-Shipping.exe — server binary
#   /game/ConanSandbox/Saved/Config/WindowsServer/*.ini                 — config files
#   /game/ConanSandbox/Mods/                                            — workshop paks + modlist.txt
#   /game-saves                                                         — saves, configs, logs
#   /entrypoint.sh                                                      — boot Xvfb, launch exe under Wine

FROM debian:12-slim

ENV DEBIAN_FRONTEND=noninteractive \
    TZ=Etc/UTC \
    LANG=en_US.UTF-8 \
    LC_ALL=en_US.UTF-8 \
    WINEDEBUG=-all \
    WINEPREFIX=/home/panel/.wine \
    DISPLAY=:99

# Wine pulls in ~500 MB of deps. Keep the 64-bit stack (dedicated binary is
# x86_64). cabextract + winbind satisfy Wine's helpers; procps for signal
# handling and pgrep/pkill debugging.
#
# The libfontconfig1 ... libasound2 block is the UE5 dedicated-server runtime
# dep set for the native Linux Conan Enhanced binary at
# /game/ConanSandbox/Binaries/Linux/ConanSandboxServer-Linux-Shipping. Funcom's
# UE5 ELF dynamically links against these even in headless server mode (UE5
# pulls in font/X/SDL/audio plumbing during engine init). Kept alongside Wine
# so a single image can host either edition — Wine still drives the legacy
# UE4 (conan-exiles-legacy) Windows-only path.
RUN dpkg --add-architecture i386 \
 && apt-get update \
 && apt-get install -y --no-install-recommends \
    ca-certificates \
    locales \
    tini \
    curl \
    xvfb \
    xauth \
    wine64 \
    wine \
    winbind \
    cabextract \
    procps \
    libfontconfig1 \
    libfreetype6 \
    libxcursor1 \
    libxinerama1 \
    libxi6 \
    libxrandr2 \
    libxxf86vm1 \
    libgl1 \
    libvulkan1 \
    libsdl2-2.0-0 \
    libpulse0 \
    libasound2 \
 && sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
 && locale-gen \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*

RUN groupadd -g 1000 panel \
 && useradd -u 1000 -g 1000 -m -s /bin/bash panel \
 && mkdir -p /game /game-saves \
 && chown -R panel:panel /game /game-saves /home/panel

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Conan Exiles default ports (see module.yaml comment for reference).
EXPOSE 7777/tcp 7777/udp 7778/udp 27015/udp
EXPOSE 25575/tcp

ENTRYPOINT ["/usr/bin/tini", "--", "/entrypoint.sh"]
