# Terraria — panel-native dedicated server module.
#
# Uses direct download from terraria.org (headless zip). Vanilla Terraria
# has no RCON — admin console is stdin. Ships without RCON/Players tab
# for v1 (same story as Empyrion / Barotrauma). Users running the
# tShock fork add Source RCON and can switch adapters later.
#
# Reference: https://github.com/CubeCoders/AMPTemplates (Terraria.kvp)

id: terraria
name: "Terraria"
version: 0.1.0
authors:
  - panel contributors

supported_modes:
  - docker

runtime:
  docker:
    image: panel-terraria:latest
    # Host networking -- container shares the host net namespace, so
    # any port the game/mod binds is directly on the LAN. AMP-like
    # model. Multi-instance safety comes from env-driven per-instance
    # ports (panel allocator + env: mapping on each ports entry).
    network_mode: host
    browseable_root: /game-saves
    browseable_roots:
      - name: "Saves & Configs"
        path: /game-saves
        hint: "Worlds/, serverconfig.txt"
      - name: "Game Files"
        path: /game
        hint: "Terraria binaries"
    env:
      WORLD_NAME: "DedicatedWorld"
      WORLD_SIZE: "2"       # 1=small, 2=medium, 3=large
      MAX_PLAYERS: "8"
      SERVER_PASSWORD: ""
      # Pre-declared so the agent's resolve.go filter lets the panel-allocated
      # port flow through to the container env. The entrypoint passes it as
      # -port (and seeds serverconfig.txt); without it the server binds the
      # hardcoded 7777 and ignores the panel allocation. Default matches the
      # port default.
      GAME_PORT: "7777"
    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" }

ports:
  - { name: game, proto: tcp, default: 7777, required: true, env: GAME_PORT }

resources:
  min_ram_mb: 1024
  recommended_ram_mb: 2048

rcon:
  # Vanilla Terraria admin is stdin-only. Commands like "say", "save",
  # "exit" go straight to the server process.
  adapter: stdio
  commands:
    save: "save"
    say:  "say {msg}"
    kick: "kick {player}"
    shutdown: "exit"
# Log-derived player events. Regexes converted from CubeCoders'
# AMPTemplates (terraria.kvp) — .NET (?<n>) syntax -> Go (?P<n>).
# Sourced-from-template; not yet exercised against a live client.
events:
  join:
    pattern: '^(?P<name>.+?) has joined\.$'
    kind: join
  leave:
    pattern: '^(?P<name>.+?) has left\.$'
    kind: leave
  chat:
    pattern: '^<(?P<name>.+?)> (?P<msg>.+)$'
    kind: chat


update_providers:
  # Terraria ships headless Linux server as a versioned zip from terraria.org.
  # AMP hard-codes the latest-known URL; we take the same approach. Bump when
  # Re-Logic cuts a new version. NOTE: the direct provider does NOT extract —
  # it writes the raw bytes to BrowseableRoot+target_path (so this lands at
  # /game-saves/terraria-server.zip). The entrypoint unzips it into /game on
  # the next boot and deletes the zip.
  - id: stable
    kind: direct
    url: "https://terraria.org/api/download/pc-dedicated-server/terraria-server-1449.zip"
    target_path: /terraria-server.zip

# --- 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: '/Server started|Listening on port \d+/i'
appearance:
  emoji: "🌳"
  grad: "linear-gradient(135deg,#2d7141,#78c87a)"
  art: "/game-art/terraria.jpg"
  steam: "105600"
