# Rust (Facepunch Studios) dedicated server module.
#
# Native Linux binary via SteamCMD app 258550. Uses WebSocket RCON (Facepunch
# dropped Source RCON years ago), which the panel speaks via the
# `websocket_rcon` adapter added in this module's first shipping session.
#
# Reference for flags + ports: Rust dedicated server wiki + widespread
# community configs. No AMP template exists for Rust in CubeCoders' public
# repo (Rust is in AMP's built-in module set, not community-contributed).

id: rust
name: "Rust"
version: 0.1.0
authors:
  - panel contributors

supported_modes:
  - docker

runtime:
  docker:
    # Built locally from ./Dockerfile. Rebuild with:
    #   docker build -t panel-rust:latest modules/rust
    image: panel-rust: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: "server/<identity>/ save data, cfg/, user bans + mutes, oxide/"
      - name: "Game Files"
        path: /game
        hint: "RustDedicated binary + Bundles/ + shipped configs"
    env:
      SERVER_NAME: "panel Rust"
      SERVER_DESCRIPTION: "Powered by panel"
      SERVER_IDENTITY: "panel-rust"
      SERVER_SEED: "12345"
      SERVER_WORLD_SIZE: "3000"     # smaller = faster load; default 4000
      MAX_PLAYERS: "50"
      RCON_PASSWORD: "panel_rcon"
      SERVER_URL: ""
      SERVER_HEADER_IMAGE: ""
      # Level selector: Procedural Map (default), Barren, HapisIsland, SavasIsland, CraggyIsland
      SERVER_LEVEL: "Procedural Map"
      # Pre-declared so allocator-derived ports survive resolve.go's filter.
      GAME_PORT: "28015"
      RCON_PORT: "28016"
      RUSTPLUS_PORT: "28082"
    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" }

# Rust ports:
#   28015/udp — main game traffic (required)
#   28015/tcp — app port for some tooling (optional; not published by default)
#   28016/tcp — WebSocket RCON (internal; panel talks to it)
#   28082/tcp — Rust+ push notifications (optional)
ports:
  - { name: game,    proto: udp, default: 28015, required: true,  env: GAME_PORT }
  - { name: rcon,    proto: tcp, default: 28016, internal: true, env: RCON_PORT }
  - { name: rustplus, proto: tcp, default: 28082, required: false, env: RUSTPLUS_PORT }

resources:
  min_ram_mb: 6144
  recommended_ram_mb: 12288

# Per-instance generated RCON secret. The agent generates a random
# 24-byte token at create time (pkg/module GenerateSecrets), which
# overrides the env default for RCON_PASSWORD below — so every instance
# gets a unique password. The weak env default only applies to
# containers launched outside the panel.
secrets:
  - name: RCON_PASSWORD
    description: "Rust RCON password — generated per instance"
    generated: true

rcon:
  adapter: websocket_rcon
  host_port: rcon
  auth: password_in_url
  password_secret: RCON_PASSWORD
  # Legacy fallback only (pre-generated-secret instances). New instances
  # always get the generated RCON_PASSWORD secret above.
  password_literal: "panel_rcon"
  commands:
    list: "playerlist"
    broadcast: "say {msg}"
    kick: "kick \"{player}\""
    ban: "banid {player}"
    save: "server.save"
    shutdown: "quit"

state_sources:
  - type: rcon
    command: "playerlist"
    every: 60s

# Log-line event patterns (RE2; named groups use (?P<name>...)).
# Rust prints join/leave to both stdout and the save-side log; stdout is
# what the log pump tails.
events:
  join:
    pattern: '(?P<name>.+?)\[[0-9]+/(?P<id>\d{17})\] has entered the game'
    kind: join
  leave:
    pattern: '(?P<id>\d{17})/(?P<name>.+?) disconnecting: (?P<reason>.+)$'
    kind: leave

update_providers:
  - id: stable
    kind: steamcmd
    app_id: "258550"
    install_path: /game

# --- 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 startup complete|Listening on 0\.0\.0\.0:28015/i'
appearance:
  emoji: "🔧"
  grad: "linear-gradient(135deg,#8b4a2b,#d97706)"
  art: "/game-art/rust.jpg"
  steam: "252490"
