# Windrose dedicated server module.
#
# Same panel-native Wine pattern as Empyrion / V Rising / Sons of the Forest:
# a minimal Debian 12 image we own (panel-windrose:latest, Debian 12 + Wine
# + Xvfb + tini), with game files populated by the generic SteamCMD updater
# sidecar into a named volume.
#
# Windrose ships as a Windows-only dedicated server (SteamDB app 4129620:
# depot 4129621 is Windows-default, depot 4129622 is a Linux placeholder
# with no manifest). The updater is told to pretend SteamCMD is running on
# Windows (`platform: windows` → +@sSteamCmdForcePlatformType windows), and
# the entrypoint runs WindroseServer.exe under Wine under Xvfb.
#
# There is NO native RCON protocol in Windrose — admin console is in-game
# only, output via StartServerForeground.bat to stdout. We capture that
# stream and surface it in the Console tab; Players tab will be empty until
# a third-party RCON shim is wired in (deferred).
#
# Reference: https://playwindrose.com/dedicated-server-guide/

id: windrose
name: "Windrose"
version: 0.1.0
authors:
  - panel contributors

supported_modes:
  - docker

runtime:
  docker:
    # Built locally from ./Dockerfile. Rebuild with:
    #   docker build -t panel-windrose:latest modules/windrose
    image: panel-windrose:latest
    # Windrose's P2P coop gateway opens a long-lived UDP session to its TURN
    # server (coturn-us.windrose.support:3478). Docker's default bridge NAT
    # on Windows rebinds UDP source ports mid-session, which breaks ICE
    # consent checks and disconnects every joining client (observed:
    # "Check consent was failed for IceControlling. Reach timeout 10000 ms"
    # ~25s after join, which also crashes the Windrose client).
    #
    # Host networking shares the host's network namespace directly — no
    # NAT, stable 5-tuples, clients can join reliably. On Linux hosts this
    # is free and recommended (target deployment: Ubuntu). On Windows Docker
    # Desktop it requires "Enable host networking" in Settings → Resources
    # → Network (4.29+); if disabled, remove this line to fall back to
    # bridge mode (accepting that joins will fail intermittently).
    network_mode: host
    browseable_root: /game-saves
    browseable_roots:
      - name: "Saves & Configs"
        path: /game-saves
        hint: "ServerDescription.json, R5/Saved/SaveProfiles/ world data"
      - name: "Game Files"
        path: /game
        hint: "WindroseServer.exe, R5/ engine files, batch scripts"
    env:
      SERVER_NAME: "panel Windrose"
      DIRECT_PORT: "7777"
      # true  — server listens on host IP:DIRECT_PORT for direct-connect joins
      #         (works when host has a public IP or a port-forward).
      # false — cloud P2P via windrose.support; players join by InviteCode
      #         with NAT-traversal via TURN. Required on a LAN host with no
      #         port-forward.
      # ServerDescription.json's UseDirectConnection field is patched to this
      # value on every boot.
      USE_DIRECT_CONNECTION: "true"
    volumes:
      - { type: volume, name: "panel-$INSTANCE_ID-saves", container: "/game-saves" }
      - { type: volume, name: "panel-$INSTANCE_ID-game",  container: "/game" }
      - { target: "$DATA_PATH/logs", container: "/game-saves/logs" }

# Windrose relies on its own R5 coop API gateway for matchmaking / NAT
# punch-through (r5coopapigateway-*.windrose.support). The only port the
# server LISTENS on is the DirectConnectionServerPort (7777 in the shipped
# default ServerDescription.json). No Steam query — publishing 27015/udp
# collides with the default Palworld/ARK query port on multi-server hosts.
ports:
  - { name: game,  proto: udp, default: 7777,  required: true, env: DIRECT_PORT }

resources:
  min_ram_mb: 4096
  recommended_ram_mb: 8192
# Log-derived player events. Regexes converted from CubeCoders'
# AMPTemplates (windrose.kvp) — .NET (?<n>) syntax -> Go (?P<n>).
# Sourced-from-template; not yet exercised against a live client.
events:
  join:
    pattern: 'ServerAccount\. AccountName ''(?P<name>[^'']+)''\. AccountId (?P<id>\S+?)\. PlayerState'
    kind: join
  leave:
    pattern: '::MoveAccountToListOfDisconnected +Account disconnected\. AccountId (?P<id>\S+)$'
    kind: leave


update_providers:
  - id: stable
    kind: steamcmd
    app_id: "4129620"
    platform: windows          # server is Windows-only — force Windows depot on Linux host
    install_path: /game
    # SteamCMD's app_update ... validate call fails with "Missing configuration"
    # on a fresh empty install dir (same behaviour as Conan Exiles, app 443030).
    # Omit the validate keyword so first-install succeeds; operators can run
    # Update again later for an integrity pass once the tree exists.
    skip_validate: true

# --- Manifest-driven UI metadata (WI-07) --------------------------
# Consumed by the CONTROLLER/dashboard only (the controller loads its
# own ./modules copy at startup); the agent ignores these at runtime.
# ready_pattern is a JavaScript regex (slash-delimited when it needs
# flags) moved verbatim from the dashboard's READY_PATTERNS map.
ready_pattern: '/Host server is ready for owner to connect|LogGlobalStatus:\s*UEngine::LoadMap\s+Load\s+map\s+complete\s+\/Game\/Maps\/(?!Lobby)/i'
appearance:
  emoji: "🧭"
  grad: "linear-gradient(135deg,#1e3a5f,#60a5fa)"
  art: "/game-art/windrose.jpg"
  steam: "3041230"
