Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| aba06eb7cf | |||
| be713728ee | |||
| 706d22ab78 | |||
| 5d408a4ee3 | |||
| 0e90fd819a | |||
| 7a4cf199c2 |
@@ -217,6 +217,15 @@ jobs:
|
|||||||
tar -C module --exclude=.git --exclude=node_modules -cf - . | tar -C core/modules/uo -xf -
|
tar -C module --exclude=.git --exclude=node_modules -cf - . | tar -C core/modules/uo -xf -
|
||||||
npm ci --omit=dev --prefix core/modules/uo/server
|
npm ci --omit=dev --prefix core/modules/uo/server
|
||||||
|
|
||||||
|
# The server-tests job runs the recipes against a fake core, which can say
|
||||||
|
# they build the spec they mean to and not that core accepts it. This is the
|
||||||
|
# only place core's own registry and spec validator see them: the module is
|
||||||
|
# loaded through the real loader and every recipe is filled in through the
|
||||||
|
# path the New event page takes. It works from its own temp copy of the
|
||||||
|
# module, so the copy installed above is not the one it reads.
|
||||||
|
- name: Build every event template through core's real registry
|
||||||
|
run: node module/server/scripts/templateBuild.js --core core --module module
|
||||||
|
|
||||||
- name: Generate core's manifest with this module
|
- name: Generate core's manifest with this module
|
||||||
run: |
|
run: |
|
||||||
npm run routes:manifest --prefix core/server
|
npm run routes:manifest --prefix core/server
|
||||||
|
|||||||
@@ -58,6 +58,13 @@
|
|||||||
# This workflow still never writes to a branch. It tags and publishes, so `main`
|
# This workflow still never writes to a branch. It tags and publishes, so `main`
|
||||||
# needs no push exception.
|
# needs no push exception.
|
||||||
#
|
#
|
||||||
|
# ── And then the uom site ────────────────────────────────────────────────────
|
||||||
|
#
|
||||||
|
# A published release is rolled onto the uom site by the `deploy-uom` job at the
|
||||||
|
# bottom, the module's twin of `website`'s `build-images.yml` deploy. Dispatching
|
||||||
|
# with `redeploy = true` publishes nothing and rolls the newest release out
|
||||||
|
# again — for a deploy that was skipped because the site's core was too old.
|
||||||
|
#
|
||||||
# Prerequisites (Settings → Actions → Secrets on RunicGateway/Module-uo):
|
# Prerequisites (Settings → Actions → Secrets on RunicGateway/Module-uo):
|
||||||
# REGISTRY_TOKEN — Gitea access token with `write:repository`, to push the tag
|
# REGISTRY_TOKEN — Gitea access token with `write:repository`, to push the tag
|
||||||
# and create the release.
|
# and create the release.
|
||||||
@@ -77,6 +84,10 @@ on:
|
|||||||
description: 'Bump level when version is blank: patch | minor | major'
|
description: 'Bump level when version is blank: patch | minor | major'
|
||||||
required: false
|
required: false
|
||||||
default: 'patch'
|
default: 'patch'
|
||||||
|
redeploy:
|
||||||
|
description: 'true = publish nothing; just roll the uom site onto the newest release'
|
||||||
|
required: false
|
||||||
|
default: 'false'
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: release-module-uo
|
group: release-module-uo
|
||||||
@@ -90,6 +101,10 @@ jobs:
|
|||||||
release:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
|
# Read by `deploy-uom` below: whether there is something to roll out, and which.
|
||||||
|
outputs:
|
||||||
|
deploy: ${{ steps.plan.outputs.deploy }}
|
||||||
|
version: ${{ steps.plan.outputs.version }}
|
||||||
steps:
|
steps:
|
||||||
# Full history: the plan step reads every tag and every subject since the
|
# Full history: the plan step reads every tag and every subject since the
|
||||||
# newest one, and a shallow clone has neither.
|
# newest one, and a shallow clone has neither.
|
||||||
@@ -108,6 +123,7 @@ jobs:
|
|||||||
EVENT: ${{ github.event_name }}
|
EVENT: ${{ github.event_name }}
|
||||||
IN_VERSION: ${{ github.event.inputs.version }}
|
IN_VERSION: ${{ github.event.inputs.version }}
|
||||||
IN_BUMP: ${{ github.event.inputs.bump }}
|
IN_BUMP: ${{ github.event.inputs.bump }}
|
||||||
|
IN_REDEPLOY: ${{ github.event.inputs.redeploy }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
@@ -119,6 +135,27 @@ jobs:
|
|||||||
RANGE="${LAST_TAG:+${LAST_TAG}..}HEAD"
|
RANGE="${LAST_TAG:+${LAST_TAG}..}HEAD"
|
||||||
echo "module.json declares ${DECLARED}; newest tag is ${LAST_TAG:-<none>}"
|
echo "module.json declares ${DECLARED}; newest tag is ${LAST_TAG:-<none>}"
|
||||||
|
|
||||||
|
# The redeploy button: publish nothing, hand the newest tag to
|
||||||
|
# `deploy-uom`. For a deploy that was skipped (core too old) or failed,
|
||||||
|
# once whatever stopped it is fixed — a plain re-run of the workflow
|
||||||
|
# would find that version already released and deploy nothing.
|
||||||
|
if [ "${EVENT:-}" = workflow_dispatch ] && [ "${IN_REDEPLOY:-false}" = true ]; then
|
||||||
|
if [ -z "$CURRENT" ]; then
|
||||||
|
echo "::error::Redeploy asked for, but there is no release to deploy."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "dispatch: redeploying ${LAST_TAG} to the uom site, publishing nothing"
|
||||||
|
{
|
||||||
|
echo "version=${CURRENT}"
|
||||||
|
echo "tag=${LAST_TAG}"
|
||||||
|
echo "release=false"
|
||||||
|
echo "reuse_tag=false"
|
||||||
|
echo "bump=none"
|
||||||
|
echo "deploy=true"
|
||||||
|
} >> "$GITHUB_OUTPUT"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
SUBJECTS="$(git log --no-merges --format='%s' $RANGE || true)"
|
SUBJECTS="$(git log --no-merges --format='%s' $RANGE || true)"
|
||||||
BODIES="$(git log --no-merges --format='%B' $RANGE || true)"
|
BODIES="$(git log --no-merges --format='%B' $RANGE || true)"
|
||||||
|
|
||||||
@@ -263,6 +300,7 @@ jobs:
|
|||||||
echo "release=${RELEASE}" >> "$GITHUB_OUTPUT"
|
echo "release=${RELEASE}" >> "$GITHUB_OUTPUT"
|
||||||
echo "reuse_tag=${REUSE_TAG}" >> "$GITHUB_OUTPUT"
|
echo "reuse_tag=${REUSE_TAG}" >> "$GITHUB_OUTPUT"
|
||||||
echo "bump=${BUMP}" >> "$GITHUB_OUTPUT"
|
echo "bump=${BUMP}" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "deploy=${RELEASE}" >> "$GITHUB_OUTPUT"
|
||||||
echo "==> release=${RELEASE} version=${VERSION} bump=${BUMP} declared=${DECLARED} last_tag=${LAST_TAG:-<none>}"
|
echo "==> release=${RELEASE} version=${VERSION} bump=${BUMP} declared=${DECLARED} last_tag=${LAST_TAG:-<none>}"
|
||||||
|
|
||||||
# Before anything is built or tagged, so a repo without secrets fails
|
# Before anything is built or tagged, so a repo without secrets fails
|
||||||
@@ -442,3 +480,211 @@ jobs:
|
|||||||
-F "attachment=@dist/${f}" >/dev/null
|
-F "attachment=@dist/${f}" >/dev/null
|
||||||
echo " uploaded ${f}"
|
echo " uploaded ${f}"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# ── Roll the uom site onto the release ────────────────────────────────────
|
||||||
|
#
|
||||||
|
# The website's own `build-images.yml` rolls the uom site onto every new core
|
||||||
|
# image from this same runner; this does the same for the uo module. It does
|
||||||
|
# not unpack anything itself: it points the site's MODULES declaration at the
|
||||||
|
# new release and recreates the app container, and core's own start-up
|
||||||
|
# (website `server/src/modules/declared.js`) fetches it, verifies the sha256 in
|
||||||
|
# the manifest and unpacks it — the path every operator's install takes.
|
||||||
|
#
|
||||||
|
# 1. Ask the RUNNING core whether it can load this release (the manifest's
|
||||||
|
# coreApi against its MODULE_API_VERSION). If not, warn and change
|
||||||
|
# nothing: the version already there keeps running until the site's core
|
||||||
|
# catches up, and then the Redeploy button (Run workflow, redeploy = true)
|
||||||
|
# rolls it out.
|
||||||
|
# 2. Rewrite the `uo@…` entry of the MODULES line in .env, in place (other
|
||||||
|
# entries and every other line are kept; the file keeps its owner and
|
||||||
|
# mode). No MODULES line yet, as on a site where uo was installed from
|
||||||
|
# Admin → Modules, appends one. Only id@version is ever printed — this
|
||||||
|
# file holds the site's secrets.
|
||||||
|
# 3. Recreate only the app container (not the db, not the bot) and wait for
|
||||||
|
# core to log `registered module "uo" v<version>`.
|
||||||
|
# 4. If it does not, put the entry back to the version that was running and
|
||||||
|
# recreate again, so a bad release leaves the site where it was, and fail
|
||||||
|
# the job either way.
|
||||||
|
#
|
||||||
|
# `needs: release` with the job's own `deploy` output: only a run that
|
||||||
|
# published a release (or a redeploy dispatch) gets here, and only after its
|
||||||
|
# assets are uploaded.
|
||||||
|
#
|
||||||
|
# Runner: `uom-deploy-runner`, the one `website`'s deploy job uses, on the
|
||||||
|
# production host. It needs Docker Compose and write access to the site's
|
||||||
|
# .env. The site directory defaults to the one `website`'s deploy job uses;
|
||||||
|
# set the Actions variable UOM_SITE_DIR to move it.
|
||||||
|
deploy-uom:
|
||||||
|
needs: release
|
||||||
|
if: needs.release.outputs.deploy == 'true' && github.ref == 'refs/heads/main'
|
||||||
|
runs-on: uom-deploy-runner
|
||||||
|
timeout-minutes: 20
|
||||||
|
env:
|
||||||
|
SITE_DIR: ${{ vars.UOM_SITE_DIR || '/home/perry/website' }}
|
||||||
|
VERSION: ${{ needs.release.outputs.version }}
|
||||||
|
steps:
|
||||||
|
- name: Check the running core, declare the release, restart the app
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
cd "$SITE_DIR"
|
||||||
|
|
||||||
|
manifest() { echo "https://${GITEA_HOST}/${REPO}/releases/download/v$1/module-uo-$1.json"; }
|
||||||
|
NEW="uo@${VERSION}=$(manifest "$VERSION")"
|
||||||
|
|
||||||
|
test -f .env || { echo "::error::${SITE_DIR}/.env is missing."; exit 1; }
|
||||||
|
test -w .env || { echo "::error::The runner cannot write ${SITE_DIR}/.env."; exit 1; }
|
||||||
|
COUNT="$(grep -cE '^[[:space:]]*MODULES[[:space:]]*=' .env || true)"
|
||||||
|
if [ "${COUNT:-0}" -gt 1 ]; then
|
||||||
|
echo "::error::.env sets MODULES ${COUNT} times. Leave one line, then press Redeploy."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ── 1. Can the running core load it? ─────────────────────────────
|
||||||
|
# Asked inside the app container: it has core's own version and range
|
||||||
|
# check, and the network path core itself will use to fetch the bundle.
|
||||||
|
# Prints one line: `ok|skip <core API> <uo version now> <coreApi range>`.
|
||||||
|
if ! CHECK="$(docker compose exec -T app node -e '
|
||||||
|
const [url, want] = process.argv.slice(1)
|
||||||
|
const fs = require("fs")
|
||||||
|
const path = require("path")
|
||||||
|
const { satisfies } = require("/app/server/src/modules/semver")
|
||||||
|
const { MODULE_API_VERSION: core } = require("/app/server/src/modules/version")
|
||||||
|
let prev = "none"
|
||||||
|
try {
|
||||||
|
const dir = process.env.MODULES_DIR || "/app/modules"
|
||||||
|
prev = JSON.parse(fs.readFileSync(path.join(dir, "uo", "module.json"), "utf8")).version || "none"
|
||||||
|
} catch {}
|
||||||
|
fetch(url).then(async (r) => {
|
||||||
|
if (!r.ok) throw new Error(`the manifest answered HTTP ${r.status}`)
|
||||||
|
const m = await r.json()
|
||||||
|
if (m.id !== "uo" || m.version !== want) throw new Error(`the manifest is ${m.id}@${m.version}, not uo@${want}`)
|
||||||
|
console.log(`${satisfies(core, m.coreApi) ? "ok" : "skip"} ${core} ${prev} ${m.coreApi}`)
|
||||||
|
}).catch((e) => { console.log(`error ${e.message}`); process.exit(1) })
|
||||||
|
' "$(manifest "$VERSION")" "$VERSION")"; then
|
||||||
|
echo "::error::Could not check the running site: ${CHECK:-the app container did not answer (is it running?)}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
read -r VERDICT CORE PREV RANGE <<< "$CHECK"
|
||||||
|
echo "uom site: core API ${CORE}, uo ${PREV} on the volume; release v${VERSION} needs ${RANGE}"
|
||||||
|
|
||||||
|
if [ "$VERDICT" = skip ]; then
|
||||||
|
echo "::warning::uo v${VERSION} needs core API ${RANGE} and the uom site runs ${CORE}. Nothing changed; uo ${PREV} keeps running. Once the site's core is updated, run Release with redeploy = true."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if [ "$PREV" = "$VERSION" ] && grep -qF "$NEW" .env; then
|
||||||
|
echo "uo v${VERSION} is already declared and on the volume. Nothing to do."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# MODULES set under `environment:` in docker-compose.yml wins over .env,
|
||||||
|
# so editing .env would change nothing. Catch it before touching anything.
|
||||||
|
ENV_MODULES="$(docker compose exec -T app printenv MODULES 2>/dev/null || true)"
|
||||||
|
if [ -n "$ENV_MODULES" ] && [ "${COUNT:-0}" -eq 0 ]; then
|
||||||
|
echo "::error::The app has MODULES set but .env has no MODULES line, so it comes from docker-compose.yml's environment:, which wins over .env. Move it into .env, then press Redeploy."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Core logs `registered module` at info. With a quieter LOG_LEVEL that
|
||||||
|
# line never reaches `docker compose logs`, so success is judged by the
|
||||||
|
# volume instead (failures are logged at error and still show).
|
||||||
|
LOG_LEVEL_NOW="$(docker compose exec -T app printenv LOG_LEVEL 2>/dev/null || true)"
|
||||||
|
case "$(echo "${LOG_LEVEL_NOW:-info}" | tr '[:upper:]' '[:lower:]')" in
|
||||||
|
warn|error) QUIET=true; echo "The app runs with LOG_LEVEL=${LOG_LEVEL_NOW}; checking the volume rather than the info log." ;;
|
||||||
|
*) QUIET=false ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# ── 2. Point MODULES at it ───────────────────────────────────────
|
||||||
|
ORIG="$(mktemp)"; TMP="$(mktemp)"
|
||||||
|
trap 'rm -f "$ORIG" "$TMP"' EXIT
|
||||||
|
cat .env > "$ORIG"
|
||||||
|
|
||||||
|
# Rewrites the uo entry of the original file's MODULES line (or appends
|
||||||
|
# the line), then writes the result over .env in place with `cat >`, so
|
||||||
|
# the file keeps its inode, owner and mode. If that write does not land
|
||||||
|
# intact (a full disk), the original goes back before the job fails.
|
||||||
|
# Plain `[ \t]`, not `[[:space:]]`: older mawk, Ubuntu's default awk,
|
||||||
|
# has no character classes in regex literals.
|
||||||
|
set_entry() {
|
||||||
|
awk -v entry="$1" -v sq="'" '
|
||||||
|
/^[ \t]*MODULES[ \t]*=/ {
|
||||||
|
v = $0
|
||||||
|
sub(/^[ \t]*MODULES[ \t]*=[ \t]*/, "", v)
|
||||||
|
sub(/[ \t]+#.*$/, "", v)
|
||||||
|
gsub(/"/, "", v); gsub(sq, "", v)
|
||||||
|
n = split(v, parts, /[, \t]+/)
|
||||||
|
out = ""
|
||||||
|
for (i = 1; i <= n; i++) if (parts[i] != "" && parts[i] !~ /^uo@/) out = out parts[i] ","
|
||||||
|
print "MODULES=" out entry
|
||||||
|
found = 1
|
||||||
|
next
|
||||||
|
}
|
||||||
|
{ print }
|
||||||
|
END { if (!found) print "MODULES=" entry }
|
||||||
|
' "$ORIG" > "$TMP"
|
||||||
|
test -s "$TMP" || { echo "::error::Rewriting .env produced an empty file; .env left as it was."; exit 1; }
|
||||||
|
if ! { cat "$TMP" > .env && cmp -s "$TMP" .env; }; then
|
||||||
|
cat "$ORIG" > .env || true
|
||||||
|
echo "::error::Writing .env failed; the original was put back. Nothing was restarted by this step."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
# id@version of each declared entry — never the URLs, never the rest of the file.
|
||||||
|
declared() {
|
||||||
|
local d
|
||||||
|
d="$(grep -E '^[[:space:]]*MODULES[[:space:]]*=' "$1" \
|
||||||
|
| grep -oE '[A-Za-z0-9_.-]+@[^=[:space:],]+=' | tr -d '=' | paste -sd' ' - || true)"
|
||||||
|
echo "${d:-(none)}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ── 3. Recreate the app and wait for core to say so ─────────────
|
||||||
|
# Only uo's own lines and MODULES errors are ever printed from the app log.
|
||||||
|
uo_lines() { grep -E 'module "uo"|declared module "uo|MODULES' <<< "$1" | tail -n 20 || true; }
|
||||||
|
restart_and_wait() {
|
||||||
|
local want="$1" since logs on_volume settled=0
|
||||||
|
since="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
||||||
|
docker compose up -d --no-deps --force-recreate app
|
||||||
|
for _ in $(seq 1 60); do
|
||||||
|
sleep 5
|
||||||
|
logs="$(docker compose logs --no-color --since "$since" app 2>&1 || true)"
|
||||||
|
if grep -qE 'could not resolve declared module "uo@|module "uo" (failed to|was not started)|MODULES: ' <<< "$logs"; then
|
||||||
|
uo_lines "$logs"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
# Anchored after the version, so v1.2.1 is not satisfied by v1.2.10.
|
||||||
|
if grep -qE "registered module \"uo\" v${want//./\\.}([^0-9A-Za-z.+-]|\$)" <<< "$logs"; then return 0; fi
|
||||||
|
if [ "$QUIET" = true ]; then
|
||||||
|
on_volume="$(docker compose exec -T app node -p 'require((process.env.MODULES_DIR || "/app/modules") + "/uo/module.json").version' 2>/dev/null || true)"
|
||||||
|
# The load fails, if it fails, right after the unpack. Give it
|
||||||
|
# three quiet polls on the new version before calling it good.
|
||||||
|
if [ "$on_volume" = "$want" ]; then settled=$((settled + 1)); else settled=0; fi
|
||||||
|
if [ "$settled" -ge 3 ]; then return 0; fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo "No word from the app about uo v${want} after 5 minutes. Its uo lines:"
|
||||||
|
uo_lines "$logs"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "MODULES before: $(declared "$ORIG")"
|
||||||
|
set_entry "$NEW"
|
||||||
|
echo "MODULES after: $(declared .env)"
|
||||||
|
if restart_and_wait "$VERSION"; then
|
||||||
|
echo "uo v${VERSION} is registered on the uom site."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ── 4. It did not come up: put back what was running ─────────────
|
||||||
|
if [ "$PREV" = none ]; then
|
||||||
|
echo "::error::uo v${VERSION} did not come up, and there was no earlier uo to roll back to."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Rolling the uom site back to uo v${PREV}."
|
||||||
|
set_entry "uo@${PREV}=$(manifest "$PREV")"
|
||||||
|
echo "MODULES now: $(declared .env)"
|
||||||
|
if restart_and_wait "$PREV"; then
|
||||||
|
echo "::error::uo v${VERSION} did not come up on the uom site. Rolled back to v${PREV}, which is running."
|
||||||
|
else
|
||||||
|
echo "::error::uo v${VERSION} did not come up, and neither did the rollback to v${PREV}. The site is up without uo; see Admin → Modules."
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
|||||||
14
README.md
14
README.md
@@ -105,7 +105,8 @@ server/utils/ sidecar client, visibility, ingest, town crier, cliloc,
|
|||||||
server/config/ the push stream catalog, the engagement triggers and audiences
|
server/config/ the push stream catalog, the engagement triggers and audiences
|
||||||
server/db/schema.sql idempotent fragment, replayed by core's ensureSchema()
|
server/db/schema.sql idempotent fragment, replayed by core's ensureSchema()
|
||||||
server/db/purge.sql destructive; only ever run by an explicit purge
|
server/db/purge.sql destructive; only ever run by an explicit purge
|
||||||
server/scripts/ the three checks: imports, the fragment, the frozen manifest
|
server/eventTemplates.js the four event recipes (announcement, boss raid, seasonal event, gathering giveaway)
|
||||||
|
server/scripts/ the checks: imports, the fragment, the frozen manifest, the recipes through core
|
||||||
server/test/ node --test, with a fake ctx standing in for core
|
server/test/ node --test, with a fake ctx standing in for core
|
||||||
client/src/entry.jsx the chunk's entry — registers routes, nav, slots, feature provider
|
client/src/entry.jsx the chunk's entry — registers routes, nav, slots, feature provider
|
||||||
client/src/shim/ react, react-dom, react-router-dom, jsx-runtime, from window.__rg
|
client/src/shim/ react, react-dom, react-router-dom, jsx-runtime, from window.__rg
|
||||||
@@ -158,6 +159,17 @@ For a change with nothing releasable behind it — a widened `coreApi`, a new mo
|
|||||||
run the **Release** workflow by hand (Actions → Release → Run workflow). Leave `version` blank to
|
run the **Release** workflow by hand (Actions → Release → Run workflow). Leave `version` blank to
|
||||||
bump the newest tag by `bump` (default `patch`), or type an exact version to publish that.
|
bump the newest tag by `bump` (default `patch`), or type an exact version to publish that.
|
||||||
|
|
||||||
|
**Every release then rolls onto the uom site** — the `deploy-uom` job, the module's twin of the
|
||||||
|
website's own deploy, on the same `uom-deploy-runner`. It asks the running core whether it can load
|
||||||
|
the release (`coreApi` against `MODULE_API_VERSION`); if it cannot, it warns and changes nothing.
|
||||||
|
Otherwise it rewrites the `uo@…` entry of the `MODULES` line in the site's `.env` (appending the line
|
||||||
|
if there is none; other entries are kept), recreates only the app container, and waits for core to
|
||||||
|
log `registered module "uo" v<version>`. If that does not come, it declares the version that was
|
||||||
|
running before, recreates again, and fails. **Run workflow** with `redeploy = true` publishes nothing
|
||||||
|
and rolls the newest release out again — for a deploy that was skipped until the site's core caught
|
||||||
|
up. The site directory defaults to `/home/perry/website`; the Actions variable `UOM_SITE_DIR`
|
||||||
|
overrides it.
|
||||||
|
|
||||||
Each release carries:
|
Each release carries:
|
||||||
|
|
||||||
| Asset | What it is |
|
| Asset | What it is |
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
"core.js",
|
"core.js",
|
||||||
"data",
|
"data",
|
||||||
"db",
|
"db",
|
||||||
|
"eventTemplates.js",
|
||||||
"index.js",
|
"index.js",
|
||||||
"model",
|
"model",
|
||||||
"package.json",
|
"package.json",
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ import { CreaturePortrait } from '../public/Atlas.jsx'
|
|||||||
// for.
|
// for.
|
||||||
//
|
//
|
||||||
// **Nothing on this page throws for an operator-visible problem.** A shard that
|
// **Nothing on this page throws for an operator-visible problem.** A shard that
|
||||||
// is down, an asset plane switched off, a Linux host with no libgdiplus, a client
|
// is down, an asset plane switched off, a client with no cliloc file — each is a
|
||||||
// with no cliloc file — each is a reported state with a reason naming what to
|
// reported state with a reason naming what to
|
||||||
// fix. A red box that says "500" would be the one thing an operator cannot act
|
// fix. A red box that says "500" would be the one thing an operator cannot act
|
||||||
// on, and every one of these states is ordinary.
|
// on, and every one of these states is ordinary.
|
||||||
|
|
||||||
@@ -332,7 +332,6 @@ export default function ClientFiles() {
|
|||||||
// want opposite things from this page: one needs its buttons disabled, the
|
// want opposite things from this page: one needs its buttons disabled, the
|
||||||
// other needs them available so the operator can retry.
|
// other needs them available so the operator can retry.
|
||||||
const linked = Boolean(assets?.linked)
|
const linked = Boolean(assets?.linked)
|
||||||
const imagingBroken = shard?.imaging && shard.imaging.ok === false
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 20 }}>
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 20 }}>
|
||||||
@@ -394,21 +393,6 @@ export default function ClientFiles() {
|
|||||||
</section>
|
</section>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{imagingBroken && (
|
|
||||||
<section
|
|
||||||
style={{ border: '1px solid #c58f4a', borderRadius: 10, padding: 16, background: 'rgba(197,143,74,0.08)' }}
|
|
||||||
className="sans"
|
|
||||||
>
|
|
||||||
<strong style={{ color: 'var(--head)' }}>The shard host cannot render images.</strong>
|
|
||||||
<p style={{ margin: '6px 0 0', color: 'var(--muted)', fontSize: '0.86rem', lineHeight: 1.6 }}>
|
|
||||||
{shard.imaging.reason ||
|
|
||||||
'A Linux shard host needs libgdiplus before it can decode a single sprite.'}{' '}
|
|
||||||
Names (the cliloc table) are unaffected and can still be imported — they have no pixels
|
|
||||||
in them.
|
|
||||||
</p>
|
|
||||||
</section>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{review.assets && (
|
{review.assets && (
|
||||||
<VanishedReview
|
<VanishedReview
|
||||||
review={review.assets}
|
review={review.assets}
|
||||||
|
|||||||
@@ -2303,6 +2303,7 @@ module.exports = {
|
|||||||
MAX_GRANT_STACK,
|
MAX_GRANT_STACK,
|
||||||
GRANTABLE,
|
GRANTABLE,
|
||||||
SEASONAL_EVENTS,
|
SEASONAL_EVENTS,
|
||||||
|
SEASONAL_LABELS,
|
||||||
SPAWNER_OPTIONS,
|
SPAWNER_OPTIONS,
|
||||||
PERMANENT_STATUSES,
|
PERMANENT_STATUSES,
|
||||||
webUserId,
|
webUserId,
|
||||||
|
|||||||
593
server/eventTemplates.js
Normal file
593
server/eventTemplates.js
Normal file
@@ -0,0 +1,593 @@
|
|||||||
|
// ── Event templates ("recipes") ─────────────────────────────────────────────
|
||||||
|
//
|
||||||
|
// Four named starting points for a new event, through core's
|
||||||
|
// `api.registerEventTemplates` (MODULE_API 1.13.0). The author fills in a few
|
||||||
|
// inputs; `build()` turns them into an ordinary draft — phases, steps, params —
|
||||||
|
// which the editor opens unsaved. Core validates the plan as a spec and keeps
|
||||||
|
// nothing about the template, so this file can change without touching a single
|
||||||
|
// event it was ever used for.
|
||||||
|
//
|
||||||
|
// uo.template.announce tell everyone, and optionally leave a news item up
|
||||||
|
// uo.template.boss_raid a named boss at a landmark for a while
|
||||||
|
// uo.template.seasonal one of ServUO's seasonal events, on for a few hours
|
||||||
|
// uo.template.gathering_giveaway a gift for everyone who turned up
|
||||||
|
//
|
||||||
|
// **`build()` makes no sidecar or shard call, and reads no database.** A recipe
|
||||||
|
// has to fill in while the shard is down — the dry run is what checks the live
|
||||||
|
// world — so everything checked here is what the inputs alone can say: formats,
|
||||||
|
// ranges, and rules between two inputs. Whether the landmark exists or the
|
||||||
|
// creature can be built is the actions' own business, at the dry run.
|
||||||
|
//
|
||||||
|
// **There is no teardown step in any of these, and that is on purpose.** What a
|
||||||
|
// run made with a `reversible: 'ledger'` action (a boss, a news article, a
|
||||||
|
// participation slot) or a `core.lease` is put back by core when the run ends.
|
||||||
|
// A phase with `advance.after` is what keeps it alive until then: the hold IS
|
||||||
|
// the length of the event.
|
||||||
|
//
|
||||||
|
// **No `default` on an input** — core drops the key — so every default lives in
|
||||||
|
// `build()`, and an input left empty arrives as absent.
|
||||||
|
|
||||||
|
const {
|
||||||
|
MAX_BROADCAST_LEN,
|
||||||
|
MAX_NEWS_TITLE,
|
||||||
|
MAX_NEWS_BODY,
|
||||||
|
MAX_AREA_RADIUS,
|
||||||
|
MAX_BOSSES,
|
||||||
|
MAX_BOSS_MULTIPLIER,
|
||||||
|
MAX_GRANT_STACK,
|
||||||
|
MAX_PROP_LEASE_MS,
|
||||||
|
GRANTABLE,
|
||||||
|
SEASONAL_EVENTS,
|
||||||
|
SEASONAL_LABELS,
|
||||||
|
} = require('./config/uoEventActions')
|
||||||
|
|
||||||
|
/** How long a Town Cryer news item stays up when the author gives a title and no length: a day. */
|
||||||
|
const DEFAULT_NEWS_MINUTES = 1440
|
||||||
|
|
||||||
|
/** The default area a giveaway counts around its place, in tiles. */
|
||||||
|
const DEFAULT_RADIUS = 40
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The longest a phase may be held: thirty days, core's own paste guard on
|
||||||
|
* `advance.after` (`MAX_AFTER_SECONDS` in the spec validator). Not a policy of
|
||||||
|
* ours — a hold longer than any event this is for is a typo, and core would
|
||||||
|
* refuse it anyway, but in its words rather than the author's.
|
||||||
|
*/
|
||||||
|
const MAX_HOLD_MINUTES = 30 * 24 * 60
|
||||||
|
|
||||||
|
/** What a seasonal lease may be held for, in minutes. The lease declares 12 hours. */
|
||||||
|
const MAX_SEASONAL_MINUTES = Math.floor(MAX_PROP_LEASE_MS / 60_000)
|
||||||
|
|
||||||
|
// ── Small readers ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/** An optional input is absent, null or empty. */
|
||||||
|
const isBlank = (v) => v === undefined || v === null || (typeof v === 'string' && v.trim() === '')
|
||||||
|
|
||||||
|
/** A string input, trimmed and collapsed to one line — or '' when absent. */
|
||||||
|
const oneLine = (v) => (isBlank(v) ? '' : String(v).replace(/\s+/g, ' ').trim())
|
||||||
|
|
||||||
|
/** "30 minutes", "1 hour", "3 hours", "90 minutes". */
|
||||||
|
function minutesWords(n) {
|
||||||
|
if (n >= 60 && n % 60 === 0) {
|
||||||
|
const hours = n / 60
|
||||||
|
return `${hours} hour${hours === 1 ? '' : 's'}`
|
||||||
|
}
|
||||||
|
return `${n} minute${n === 1 ? '' : 's'}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/** "OrcCaptain" → "Orc Captain". A name that is not plain CamelCase is left as the shard spells it. */
|
||||||
|
function creatureWords(type) {
|
||||||
|
return /^[A-Za-z]+$/.test(type) ? type.replace(/([a-z])([A-Z])/g, '$1 $2') : type
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A place as the author picked it, `facet/name` or `facet/group/name`, or null. */
|
||||||
|
function readPlace(raw) {
|
||||||
|
const place = oneLine(raw)
|
||||||
|
const parts = place.split('/')
|
||||||
|
if (parts.length < 2 || parts.some((p) => p.trim() === '')) return null
|
||||||
|
return { value: place, name: parts[parts.length - 1].trim() }
|
||||||
|
}
|
||||||
|
|
||||||
|
const placeRefusal = (raw) => `"${raw}" is not a place — pick one from the list, as facet/name`
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A whole number of minutes in 1..max, or a refusal in the author's words.
|
||||||
|
* `what` finishes "<what> lasts 1 to N minutes": "the raid", "the event".
|
||||||
|
*/
|
||||||
|
function readMinutes(raw, max, what) {
|
||||||
|
const minutes = Number(raw)
|
||||||
|
if (isBlank(raw) || !Number.isInteger(minutes) || minutes < 1 || minutes > max) {
|
||||||
|
return { ok: false, error: `${what} lasts 1 to ${max} minutes, and "${raw}" is not that` }
|
||||||
|
}
|
||||||
|
return { ok: true, minutes }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A broadcast line: one line of at most `MAX_BROADCAST_LEN` characters. */
|
||||||
|
function readMessage(raw, what) {
|
||||||
|
const text = oneLine(raw)
|
||||||
|
if (text.length > MAX_BROADCAST_LEN) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
error: `${what} is sent as one broadcast, which is capped at ${MAX_BROADCAST_LEN} characters, and this is ${text.length}`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { ok: true, text }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 1. Announcement ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const announce = {
|
||||||
|
id: 'uo.template.announce',
|
||||||
|
label: 'Announcement',
|
||||||
|
description:
|
||||||
|
'Tells everyone who is online a message, once. Add a news title and the same text is also posted in the in-game Town Cryer news window, and stays there for the length you choose. Nothing in the world changes; you can change every part of the plan before saving it.',
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
name: 'text',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
example: 'The gates of Britain open at dusk. Gather at the bank.',
|
||||||
|
description: `What to tell everyone online, up to ${MAX_BROADCAST_LEN} characters. It goes out once.`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'hue',
|
||||||
|
type: 'int',
|
||||||
|
required: false,
|
||||||
|
example: 1153,
|
||||||
|
description: 'The colour of the message, as an Ultima Online colour number. Left empty, the shard uses its usual system colour.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'newsTitle',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
example: 'The Britannian Midsummer Fair',
|
||||||
|
description: `A heading for a Town Cryer news article carrying the same text, up to ${MAX_NEWS_TITLE} characters. Leave it empty to post no article.`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'newsMinutes',
|
||||||
|
type: 'int',
|
||||||
|
required: false,
|
||||||
|
example: 1440,
|
||||||
|
duration: 'minutes',
|
||||||
|
description: `How long the news article stays up, in minutes. Only with a news title. Left empty, it stays ${DEFAULT_NEWS_MINUTES} minutes (a day).`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
build({ inputs }) {
|
||||||
|
const message = readMessage(inputs.text, 'the announcement')
|
||||||
|
if (!message.ok) return message
|
||||||
|
if (!message.text) return { ok: false, error: 'the announcement has no text to send' }
|
||||||
|
|
||||||
|
let hue
|
||||||
|
if (!isBlank(inputs.hue)) {
|
||||||
|
hue = Number(inputs.hue)
|
||||||
|
if (!Number.isInteger(hue) || hue < 0) {
|
||||||
|
return { ok: false, error: `"${inputs.hue}" is not a colour this shard will take; use a whole number, 0 or more` }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const newsTitle = oneLine(inputs.newsTitle)
|
||||||
|
if (!newsTitle && !isBlank(inputs.newsMinutes)) {
|
||||||
|
return { ok: false, error: 'a news length needs a news title; give the article a title, or clear the length' }
|
||||||
|
}
|
||||||
|
|
||||||
|
const steps = [
|
||||||
|
{
|
||||||
|
actionId: 'uo.broadcast',
|
||||||
|
label: 'Tell everyone online',
|
||||||
|
params: { text: message.text, ...(hue === undefined ? {} : { hue }) },
|
||||||
|
},
|
||||||
|
]
|
||||||
|
const phase = { key: 'announce', label: 'Announce', steps }
|
||||||
|
let summary = `Tells everyone online "${message.text}".`
|
||||||
|
|
||||||
|
if (newsTitle) {
|
||||||
|
if (newsTitle.length > MAX_NEWS_TITLE) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
error: `a news title is capped at ${MAX_NEWS_TITLE} characters and this is ${newsTitle.length}`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The body is the broadcast text, which is already within the broadcast cap;
|
||||||
|
// the check is for the day the two caps move apart.
|
||||||
|
if (message.text.length > MAX_NEWS_BODY) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
error: `a news article is capped at ${MAX_NEWS_BODY} characters and the text is ${message.text.length}`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let minutes = DEFAULT_NEWS_MINUTES
|
||||||
|
if (!isBlank(inputs.newsMinutes)) {
|
||||||
|
const read = readMinutes(inputs.newsMinutes, MAX_HOLD_MINUTES, 'the news article')
|
||||||
|
if (!read.ok) return read
|
||||||
|
minutes = read.minutes
|
||||||
|
}
|
||||||
|
|
||||||
|
steps.push({
|
||||||
|
actionId: 'uo.news.post',
|
||||||
|
label: 'Post the news article',
|
||||||
|
// `announce: false`: the broadcast above has already told everyone, and the
|
||||||
|
// criers proclaiming the title as well would be the same news twice.
|
||||||
|
params: { title: newsTitle, body: message.text, announce: false },
|
||||||
|
})
|
||||||
|
// The article is taken down when the run ends, so the hold is what keeps it
|
||||||
|
// posted — the phase lasts exactly as long as the article should.
|
||||||
|
phase.advance = { after: `${minutes}m` }
|
||||||
|
summary += ` Posts "${newsTitle}" in the Town Cryer news for ${minutesWords(minutes)}.`
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: `Announcement: ${message.text.length > 60 ? `${message.text.slice(0, 57)}...` : message.text}`,
|
||||||
|
summary,
|
||||||
|
spec: { schedule: { kind: 'manual' }, phases: [phase] },
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 2. Boss raid ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const bossRaid = {
|
||||||
|
id: 'uo.template.boss_raid',
|
||||||
|
label: 'Boss raid',
|
||||||
|
description:
|
||||||
|
'A named boss appears at a landmark, the shard is told so, and the boss is removed when the time is up. It needs boss spawning to be switched on: actions that put things in the world are off until an operator enables them. The boss is cleared when the run ends, even if nobody kills it.',
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
name: 'place',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
example: 'Felucca/Britain',
|
||||||
|
source: 'uo.options.landmarks',
|
||||||
|
description: 'Where the boss appears.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'creature',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
example: 'OrcCaptain',
|
||||||
|
source: 'uo.options.creatures',
|
||||||
|
description: 'The kind of creature the boss is built from.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'name',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
example: 'Gruk the Unbroken',
|
||||||
|
description: 'What the boss is called. An unnamed boss is just a hard monster.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'minutes',
|
||||||
|
type: 'int',
|
||||||
|
required: true,
|
||||||
|
example: 30,
|
||||||
|
duration: 'minutes',
|
||||||
|
description: 'How many minutes the boss stays before it is cleared away.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'count',
|
||||||
|
type: 'int',
|
||||||
|
required: false,
|
||||||
|
example: 1,
|
||||||
|
description: `How many bosses, 1 to ${MAX_BOSSES}. Left empty, one.`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'strength',
|
||||||
|
type: 'float',
|
||||||
|
required: false,
|
||||||
|
example: 3,
|
||||||
|
description: `How many times tougher than normal, and how many times harder it hits, 1 to ${MAX_BOSS_MULTIPLIER}. Left empty, or 1, it is as strong as the creature normally is.`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'message',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
example: 'Gruk the Unbroken has appeared near Britain!',
|
||||||
|
description: `What the shard is told when the boss appears, up to ${MAX_BROADCAST_LEN} characters. Left empty, "<name> has appeared near <place>!".`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
build({ inputs }) {
|
||||||
|
const place = readPlace(inputs.place)
|
||||||
|
if (!place) return { ok: false, error: placeRefusal(inputs.place) }
|
||||||
|
|
||||||
|
const creature = oneLine(inputs.creature)
|
||||||
|
if (!creature) return { ok: false, error: 'pick a creature for the boss to be built from' }
|
||||||
|
|
||||||
|
const name = oneLine(inputs.name)
|
||||||
|
if (!name) return { ok: false, error: 'a boss needs a name' }
|
||||||
|
|
||||||
|
const read = readMinutes(inputs.minutes, MAX_HOLD_MINUTES, 'a raid')
|
||||||
|
if (!read.ok) return read
|
||||||
|
const { minutes } = read
|
||||||
|
|
||||||
|
let count = 1
|
||||||
|
if (!isBlank(inputs.count)) {
|
||||||
|
count = Number(inputs.count)
|
||||||
|
if (!Number.isInteger(count) || count < 1 || count > MAX_BOSSES) {
|
||||||
|
return { ok: false, error: `a raid has 1 to ${MAX_BOSSES} bosses, and "${inputs.count}" is not that` }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let strength = 1
|
||||||
|
if (!isBlank(inputs.strength)) {
|
||||||
|
strength = Number(inputs.strength)
|
||||||
|
if (!Number.isFinite(strength) || strength < 1 || strength > MAX_BOSS_MULTIPLIER) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
error: `a boss is 1 to ${MAX_BOSS_MULTIPLIER} times as strong as normal, and "${inputs.strength}" is not`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const message = readMessage(
|
||||||
|
isBlank(inputs.message) ? `${name} has appeared near ${place.name}!` : inputs.message,
|
||||||
|
isBlank(inputs.message) ? 'the default message (shorten the boss name or write your own)' : 'the message',
|
||||||
|
)
|
||||||
|
if (!message.ok) return message
|
||||||
|
|
||||||
|
const spawn = {
|
||||||
|
place: place.value,
|
||||||
|
creature,
|
||||||
|
name,
|
||||||
|
count,
|
||||||
|
// 1 is "as normal", so it is left out rather than written as a multiplier
|
||||||
|
// that does nothing.
|
||||||
|
...(strength > 1 ? { hitsMultiplier: strength, damageMultiplier: strength } : {}),
|
||||||
|
}
|
||||||
|
|
||||||
|
const who = count === 1 ? name : `${count} bosses called ${name}`
|
||||||
|
return {
|
||||||
|
title: `${creatureWords(creature)} raid at ${place.value} for ${minutesWords(minutes)}`,
|
||||||
|
summary:
|
||||||
|
`${who}, built from ${creatureWords(creature)}${strength > 1 ? ` and ${strength} times as strong` : ''}, ` +
|
||||||
|
`appear${count === 1 ? 's' : ''} near ${place.value} and ${count === 1 ? 'is' : 'are'} removed after ${minutesWords(minutes)}.`,
|
||||||
|
spec: {
|
||||||
|
schedule: { kind: 'manual' },
|
||||||
|
phases: [
|
||||||
|
{
|
||||||
|
key: 'raid',
|
||||||
|
label: 'The raid',
|
||||||
|
// The boss is cleared when the run ends, so the hold is its lifetime.
|
||||||
|
advance: { after: `${minutes}m` },
|
||||||
|
steps: [
|
||||||
|
{ actionId: 'uo.boss.spawn', label: count === 1 ? 'Spawn the boss' : 'Spawn the bosses', params: spawn },
|
||||||
|
{ actionId: 'uo.broadcast', label: 'Tell everyone it has appeared', params: { text: message.text } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 3. Seasonal event ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const seasonal = {
|
||||||
|
id: 'uo.template.seasonal',
|
||||||
|
label: 'Seasonal event for a few hours',
|
||||||
|
description:
|
||||||
|
`Switches one of ServUO's own seasonal events on, and back off by itself when the time is up (up to ${MAX_SEASONAL_MINUTES / 60} hours). Six of the eight add or remove things in the world when they change, so this is a bigger switch than it looks. It borrows the event's setting and puts the old one back when the run ends.`,
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
name: 'event',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
example: 'Fellowship',
|
||||||
|
source: 'uo.options.seasonal',
|
||||||
|
description: 'Which of the shard\'s seasonal events to switch on.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'minutes',
|
||||||
|
type: 'int',
|
||||||
|
required: true,
|
||||||
|
example: 180,
|
||||||
|
duration: 'minutes',
|
||||||
|
description: `How many minutes it stays on, up to ${MAX_SEASONAL_MINUTES} (${MAX_SEASONAL_MINUTES / 60} hours). 180 is three hours.`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'message',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
example: 'The Krampus has come to Britannia for a few hours!',
|
||||||
|
description: `What the shard is told once it is on, up to ${MAX_BROADCAST_LEN} characters. Left empty, nobody is told.`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
build({ inputs }) {
|
||||||
|
const event = oneLine(inputs.event)
|
||||||
|
if (!SEASONAL_EVENTS.includes(event)) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
error: `"${inputs.event}" is not a seasonal event this recipe can switch on — pick one from the list`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const read = readMinutes(inputs.minutes, MAX_SEASONAL_MINUTES, 'a seasonal event')
|
||||||
|
if (!read.ok) return read
|
||||||
|
const { minutes } = read
|
||||||
|
|
||||||
|
const message = readMessage(inputs.message, 'the message')
|
||||||
|
if (!message.ok) return message
|
||||||
|
|
||||||
|
const label = SEASONAL_LABELS[event] || event
|
||||||
|
const steps = [
|
||||||
|
{
|
||||||
|
actionId: 'core.lease',
|
||||||
|
label: `Switch on ${label}`,
|
||||||
|
params: { lease: 'uo.seasonal.status', target: event, value: 'Active', minutes },
|
||||||
|
},
|
||||||
|
]
|
||||||
|
if (message.text) {
|
||||||
|
steps.push({ actionId: 'uo.broadcast', label: 'Tell everyone it is on', params: { text: message.text } })
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: `${label} for ${minutesWords(minutes)}`,
|
||||||
|
summary: `Switches ${label} on for ${minutesWords(minutes)}, then puts it back as it was.`,
|
||||||
|
spec: {
|
||||||
|
schedule: { kind: 'manual' },
|
||||||
|
phases: [
|
||||||
|
{
|
||||||
|
key: 'season',
|
||||||
|
label,
|
||||||
|
// The lease is given back when the run ends, so the hold is how long the
|
||||||
|
// event stays on — and the lease's own `minutes` is the game's deadline.
|
||||||
|
advance: { after: `${minutes}m` },
|
||||||
|
steps,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 4. Gathering giveaway ───────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const gatheringGiveaway = {
|
||||||
|
id: 'uo.template.gathering_giveaway',
|
||||||
|
label: 'Gathering giveaway',
|
||||||
|
description:
|
||||||
|
'Players gather at a landmark for a while; when the time is up, everyone the shard counted in the area during that window is given the item. Gifts go into backpacks and cannot be taken back, so check the item and amount before you start.',
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
name: 'place',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
example: 'Felucca/Britain',
|
||||||
|
source: 'uo.options.landmarks',
|
||||||
|
description: 'Where players gather.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'minutes',
|
||||||
|
type: 'int',
|
||||||
|
required: true,
|
||||||
|
example: 30,
|
||||||
|
duration: 'minutes',
|
||||||
|
description: 'How many minutes players have to gather before the gifts are handed out.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'item',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
example: 'gold',
|
||||||
|
source: 'uo.options.items',
|
||||||
|
description: 'What everyone is given. The list is what the shard is willing to hand out.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'amount',
|
||||||
|
type: 'int',
|
||||||
|
required: false,
|
||||||
|
example: 500,
|
||||||
|
description: `How many each, up to ${MAX_GRANT_STACK}. Only items that stack, like gold, can be given more than one at a time. Left empty, one.`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'radius',
|
||||||
|
type: 'int',
|
||||||
|
required: false,
|
||||||
|
example: DEFAULT_RADIUS,
|
||||||
|
description: `How many tiles around the place count as being there, 1 to ${MAX_AREA_RADIUS}. Left empty, ${DEFAULT_RADIUS}.`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'message',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
example: 'Gather near Britain in the next 30 minutes for a gift!',
|
||||||
|
description: `What the shard is told when the gathering opens, up to ${MAX_BROADCAST_LEN} characters. Left empty, "Gather near <place> in the next <minutes> minutes for a gift!".`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
build({ inputs }) {
|
||||||
|
const place = readPlace(inputs.place)
|
||||||
|
if (!place) return { ok: false, error: placeRefusal(inputs.place) }
|
||||||
|
|
||||||
|
const read = readMinutes(inputs.minutes, MAX_HOLD_MINUTES, 'a gathering')
|
||||||
|
if (!read.ok) return read
|
||||||
|
const { minutes } = read
|
||||||
|
|
||||||
|
const itemKey = oneLine(inputs.item)
|
||||||
|
const item = GRANTABLE.find((g) => g.key === itemKey)
|
||||||
|
if (!item) {
|
||||||
|
return { ok: false, error: `this shard does not give out "${inputs.item}" — pick one from the list` }
|
||||||
|
}
|
||||||
|
|
||||||
|
let amount = 1
|
||||||
|
if (!isBlank(inputs.amount)) {
|
||||||
|
amount = Number(inputs.amount)
|
||||||
|
if (!Number.isInteger(amount) || amount < 1 || amount > MAX_GRANT_STACK) {
|
||||||
|
return { ok: false, error: `give 1 to ${MAX_GRANT_STACK} each, and "${inputs.amount}" is not that` }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!item.stackable && amount > 1) {
|
||||||
|
return { ok: false, error: `${item.label} does not stack, so it can only be given one at a time` }
|
||||||
|
}
|
||||||
|
|
||||||
|
let radius = DEFAULT_RADIUS
|
||||||
|
if (!isBlank(inputs.radius)) {
|
||||||
|
radius = Number(inputs.radius)
|
||||||
|
if (!Number.isInteger(radius) || radius < 1 || radius > MAX_AREA_RADIUS) {
|
||||||
|
return { ok: false, error: `the gathering area is 1 to ${MAX_AREA_RADIUS} tiles, and "${inputs.radius}" is not that` }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const custom = !isBlank(inputs.message)
|
||||||
|
const message = readMessage(
|
||||||
|
custom ? inputs.message : `Gather near ${place.name} in the next ${minutesWords(minutes)} for a gift!`,
|
||||||
|
custom ? 'the message' : 'the default message (write your own)',
|
||||||
|
)
|
||||||
|
if (!message.ok) return message
|
||||||
|
|
||||||
|
const gift = amount === 1 ? `one ${item.label.toLowerCase()}` : `${amount} ${item.label.toLowerCase()}`
|
||||||
|
return {
|
||||||
|
title: `Gathering giveaway at ${place.value} for ${minutesWords(minutes)}`,
|
||||||
|
summary:
|
||||||
|
`Players gather within ${radius} tiles of ${place.value} for ${minutesWords(minutes)}; ` +
|
||||||
|
`then everyone who was there is given ${gift} each. Gifts cannot be taken back.`,
|
||||||
|
spec: {
|
||||||
|
schedule: { kind: 'manual' },
|
||||||
|
phases: [
|
||||||
|
{
|
||||||
|
key: 'gather',
|
||||||
|
label: 'Gather',
|
||||||
|
// The counting slot is given back when the run ends, so this hold is the
|
||||||
|
// window: the reward phase starts when it is up, not before.
|
||||||
|
advance: { after: `${minutes}m` },
|
||||||
|
steps: [
|
||||||
|
{ actionId: 'uo.broadcast', label: 'Invite everyone', params: { text: message.text } },
|
||||||
|
{
|
||||||
|
actionId: 'uo.participation.open',
|
||||||
|
label: 'Start counting who is there',
|
||||||
|
params: { place: place.value, radius },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'reward',
|
||||||
|
label: 'Give the gifts',
|
||||||
|
steps: [
|
||||||
|
{ actionId: 'uo.participation.collect', label: 'Record who was there', params: {} },
|
||||||
|
{ actionId: 'uo.item.grant', label: 'Give everyone the gift', params: { item: item.key, amount } },
|
||||||
|
{
|
||||||
|
actionId: 'uo.broadcast',
|
||||||
|
label: 'Say thank you',
|
||||||
|
params: { text: 'Thank you for coming — gifts are in your backpacks.' },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const TEMPLATES = [announce, bossRaid, seasonal, gatheringGiveaway]
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
TEMPLATES,
|
||||||
|
DEFAULT_NEWS_MINUTES,
|
||||||
|
DEFAULT_RADIUS,
|
||||||
|
MAX_HOLD_MINUTES,
|
||||||
|
MAX_SEASONAL_MINUTES,
|
||||||
|
minutesWords,
|
||||||
|
creatureWords,
|
||||||
|
}
|
||||||
@@ -48,6 +48,7 @@ module.exports = function register(ctx, api) {
|
|||||||
const shardAudiences = require('./config/shardAudiences')
|
const shardAudiences = require('./config/shardAudiences')
|
||||||
const engagementSeeds = require('./config/engagementSeeds')
|
const engagementSeeds = require('./config/engagementSeeds')
|
||||||
const uoEventActions = require('./config/uoEventActions')
|
const uoEventActions = require('./config/uoEventActions')
|
||||||
|
const eventTemplates = require('./eventTemplates')
|
||||||
const townCrierLeg = require('./utils/shardAnnounce')
|
const townCrierLeg = require('./utils/shardAnnounce')
|
||||||
const teamProvider = require('./model/teamProvider/teamProvider.model')
|
const teamProvider = require('./model/teamProvider/teamProvider.model')
|
||||||
const guildCommand = require('./commands/guild.command')
|
const guildCommand = require('./commands/guild.command')
|
||||||
@@ -181,6 +182,10 @@ const engagementSeeds = require('./config/engagementSeeds')
|
|||||||
// two-events-one-target check and the teardown restore.
|
// two-events-one-target check and the teardown restore.
|
||||||
api.registerEventLeases(uoEventActions.LEASES)
|
api.registerEventLeases(uoEventActions.LEASES)
|
||||||
api.registerEventOptionSources(uoEventActions.OPTION_SOURCES)
|
api.registerEventOptionSources(uoEventActions.OPTION_SOURCES)
|
||||||
|
// MODULE_API 1.13.0. Four recipes — named starting points built out of the verbs
|
||||||
|
// above. They are only declarations: `build()` runs when an author fills one in,
|
||||||
|
// and makes no shard call, so they work with the shard down.
|
||||||
|
api.registerEventTemplates(eventTemplates.TEMPLATES)
|
||||||
|
|
||||||
api.onBoot(boot.onBoot)
|
api.onBoot(boot.onBoot)
|
||||||
api.onShutdown(boot.onShutdown)
|
api.onShutdown(boot.onShutdown)
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ function removeSprite(name) {
|
|||||||
* operator can read it:
|
* operator can read it:
|
||||||
*
|
*
|
||||||
* `skipped` no shard configured — the file era had no equivalent here
|
* `skipped` no shard configured — the file era had no equivalent here
|
||||||
* `unavailable` the shard could not answer (down, plane off, no libgdiplus)
|
* `unavailable` the shard could not answer (down, plane off)
|
||||||
* `unchanged` the client files match what was imported; nothing fetched
|
* `unchanged` the client files match what was imported; nothing fetched
|
||||||
* `imported` fetched and applied
|
* `imported` fetched and applied
|
||||||
* `needsReview` a key we hold has vanished from the shard's manifest
|
* `needsReview` a key we hold has vanished from the shard's manifest
|
||||||
@@ -197,17 +197,6 @@ async function importAssets({ force = false, approve = false, by = null } = {})
|
|||||||
return failure(err, 'client file manifest')
|
return failure(err, 'client file manifest')
|
||||||
}
|
}
|
||||||
|
|
||||||
// §4.4: a Linux shard host without libgdiplus cannot render a sprite at all.
|
|
||||||
// It is reported on the source gate precisely so an operator meets it while
|
|
||||||
// setting the shard up rather than from an empty bestiary weeks later.
|
|
||||||
if (sources.imaging && sources.imaging.ok === false) {
|
|
||||||
return {
|
|
||||||
status: 'unavailable',
|
|
||||||
code: 'NO_IMAGING',
|
|
||||||
reason: sources.imaging.reason || 'the shard host cannot render images',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const meta = await db.getMeta().catch(() => null)
|
const meta = await db.getMeta().catch(() => null)
|
||||||
|
|
||||||
if (!force && bridge.sameSources(sources, meta?.sources)) {
|
if (!force && bridge.sameSources(sources, meta?.sources)) {
|
||||||
@@ -561,7 +550,6 @@ async function getStatus() {
|
|||||||
extractorVersion: sources.extractorVersion,
|
extractorVersion: sources.extractorVersion,
|
||||||
hashing: sources.hashing,
|
hashing: sources.hashing,
|
||||||
complete: sources.complete,
|
complete: sources.complete,
|
||||||
imaging: sources.imaging,
|
|
||||||
// Which §5 families this overlay serves. A phase-3 or phase-4 overlay says
|
// Which §5 families this overlay serves. A phase-3 or phase-4 overlay says
|
||||||
// `['body']`, which is what an admin panel needs in order to say "update
|
// `['body']`, which is what an admin panel needs in order to say "update
|
||||||
// your plugin" rather than showing an item-art pipeline that cannot work.
|
// your plugin" rather than showing an item-art pipeline that cannot work.
|
||||||
|
|||||||
@@ -288,14 +288,6 @@ async function warm({ limit = WARM_BATCH, force = false } = {}) {
|
|||||||
return failure(err, 'client file manifest')
|
return failure(err, 'client file manifest')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sources.imaging && sources.imaging.ok === false) {
|
|
||||||
return {
|
|
||||||
status: 'unavailable',
|
|
||||||
code: 'NO_IMAGING',
|
|
||||||
reason: sources.imaging.reason || 'the shard host cannot render images',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A phase-3 or phase-4 overlay serves bodies and nothing else. Asking it for a
|
// A phase-3 or phase-4 overlay serves bodies and nothing else. Asking it for a
|
||||||
// static is refused per request, which would be a warn on every pass forever —
|
// static is refused per request, which would be a warn on every pass forever —
|
||||||
// so it is checked once, here, and reported as the ordinary state it is.
|
// so it is checked once, here, and reported as the ordinary state it is.
|
||||||
|
|||||||
@@ -377,7 +377,7 @@ shardRouter.get(
|
|||||||
'/assets',
|
'/assets',
|
||||||
// #swagger.tags = ['Admin · Shard']
|
// #swagger.tags = ['Admin · Shard']
|
||||||
// #swagger.summary = 'Client asset import status: what is loaded, what the shard has, whether they differ (admin only)'
|
// #swagger.summary = 'Client asset import status: what is loaded, what the shard has, whether they differ (admin only)'
|
||||||
// #swagger.description = 'What the site currently holds (the imported body catalogue, how many sprites are stored, how many atlas creatures resolved to a body id) beside what the shard reports for the client files those pictures come from. `drift: true` means the client files have changed since the last import — press Import. `shard.hashing: true` means a null hash is “not computed yet”, not “changed”: the shard hashes 195 MB anim files off the request path. `shard.imaging.ok: false` is the named NO_IMAGING state — a Linux shard host without libgdiplus cannot render a sprite at all, and the reason names the package to install. A shard with no link configured, or one that is down, is a reported state with a reason rather than an error.'
|
// #swagger.description = 'What the site currently holds (the imported body catalogue, how many sprites are stored, how many atlas creatures resolved to a body id) beside what the shard reports for the client files those pictures come from. `drift: true` means the client files have changed since the last import — press Import. `shard.hashing: true` means a null hash is “not computed yet”, not “changed”: the shard hashes 195 MB anim files off the request path. A shard with no link configured, or one that is down, is a reported state with a reason rather than an error.'
|
||||||
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
||||||
/* #swagger.responses[200] = { description: 'Asset import status', content: { "application/json": { schema: { $ref: "#/components/schemas/UoAssetStatus" } } } } */
|
/* #swagger.responses[200] = { description: 'Asset import status', content: { "application/json": { schema: { $ref: "#/components/schemas/UoAssetStatus" } } } } */
|
||||||
/* #swagger.responses[403] = { description: 'Admin role required', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
/* #swagger.responses[403] = { description: 'Admin role required', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
@@ -403,7 +403,7 @@ shardRouter.post(
|
|||||||
'/assets/warm',
|
'/assets/warm',
|
||||||
// #swagger.tags = ['Admin · Shard']
|
// #swagger.tags = ['Admin · Shard']
|
||||||
// #swagger.summary = 'Fetch item and land artwork the site is missing, now (admin only)'
|
// #swagger.summary = 'Fetch item and land artwork the site is missing, now (admin only)'
|
||||||
// #swagger.description = 'Runs one pass of the item-art warm loop instead of waiting for its timer. The pass works out which item pictures this site's own rows name — every distinct (ItemID, hue) on a player vendor, plus anything a character sheet has shown since the last pass — and fetches the ones it does not already hold from the shard, hued and stored under uploads/items/. There is deliberately NO manifest and no bulk import here: the client addresses 49,152 item graphics times three thousand hues, so the working set is defined by what the site actually displays. `force` re-fetches pictures the site already holds, which is how an operator recovers a wiped uploads volume. `limit` bounds one pass; the default is 400, because the shard serves one asset request at a time and a pass must not hold that slot against an import. Nothing throws for an operator-visible problem: no shard configured, a shard that is down, an asset plane switched off, a host with no libgdiplus, or a plugin overlay too old to serve item art all answer 200 with status "unavailable"/"skipped" and a reason naming what to fix.'
|
// #swagger.description = 'Runs one pass of the item-art warm loop instead of waiting for its timer. The pass works out which item pictures this site's own rows name — every distinct (ItemID, hue) on a player vendor, plus anything a character sheet has shown since the last pass — and fetches the ones it does not already hold from the shard, hued and stored under uploads/items/. There is deliberately NO manifest and no bulk import here: the client addresses 49,152 item graphics times three thousand hues, so the working set is defined by what the site actually displays. `force` re-fetches pictures the site already holds, which is how an operator recovers a wiped uploads volume. `limit` bounds one pass; the default is 400, because the shard serves one asset request at a time and a pass must not hold that slot against an import. Nothing throws for an operator-visible problem: no shard configured, a shard that is down, an asset plane switched off, or a plugin overlay too old to serve item art all answer 200 with status "unavailable"/"skipped" and a reason naming what to fix.'
|
||||||
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
||||||
/* #swagger.requestBody = { required: false, content: { "application/json": { schema: { type: "object", properties: { force: { type: "boolean", description: "Re-fetch pictures this site already holds." }, limit: { type: "integer", description: "How many keys this pass may fetch (1-2000)." } } } } } } */
|
/* #swagger.requestBody = { required: false, content: { "application/json": { schema: { type: "object", properties: { force: { type: "boolean", description: "Re-fetch pictures this site already holds." }, limit: { type: "integer", description: "How many keys this pass may fetch (1-2000)." } } } } } } */
|
||||||
/* #swagger.responses[200] = { description: 'What the pass did', content: { "application/json": { schema: { $ref: "#/components/schemas/UoItemArtWarmResult" } } } } */
|
/* #swagger.responses[200] = { description: 'What the pass did', content: { "application/json": { schema: { $ref: "#/components/schemas/UoItemArtWarmResult" } } } } */
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
// records the action in the admin activity log.
|
// records the action in the admin activity log.
|
||||||
//
|
//
|
||||||
// **An import result is not an exception**, exactly as for clilocs. A shard that
|
// **An import result is not an exception**, exactly as for clilocs. A shard that
|
||||||
// is down, an asset plane the operator has switched off, a Linux host with no
|
// is down, an asset plane the operator has switched off, a client patched
|
||||||
// libgdiplus, a client patched halfway through the walk — each is a 200 carrying
|
// halfway through the walk — each is a 200 carrying
|
||||||
// `status: 'unavailable'` and a reason naming what to fix, not a 500 that says
|
// `status: 'unavailable'` and a reason naming what to fix, not a 500 that says
|
||||||
// only "something broke". The one thing that DOES 500 is this file having a bug.
|
// only "something broke". The one thing that DOES 500 is this file having a bug.
|
||||||
//
|
//
|
||||||
|
|||||||
299
server/scripts/templateBuild.js
Normal file
299
server/scripts/templateBuild.js
Normal file
@@ -0,0 +1,299 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
// ── Do core's own validators accept the event recipes? ─────────────────────
|
||||||
|
//
|
||||||
|
// `test/eventTemplates.test.js` runs against a FAKE core. It can say a recipe
|
||||||
|
// builds the spec it means to; it cannot say core agrees, because the things core
|
||||||
|
// would object to — a phase key's grammar, a step param that action no longer has,
|
||||||
|
// a lease core cannot find, an input shape `registerEventTemplates` refuses — are
|
||||||
|
// facts about core's code, not ours. A recipe core refuses is also worse than a
|
||||||
|
// missing one: a template that fails `registerEventTemplates` fails the whole
|
||||||
|
// module's load, and one whose `build()` returns a spec core rejects shows an
|
||||||
|
// author "made a plan core cannot accept" for a form they filled in correctly.
|
||||||
|
//
|
||||||
|
// So this script puts the module through core's real loader and builds every
|
||||||
|
// recipe through `buildFromTemplate`, which is the path the New event page takes:
|
||||||
|
// inputs checked against the declaration, `build()` called, the spec run through
|
||||||
|
// core's real `spec.validate` with this module's actions registered.
|
||||||
|
//
|
||||||
|
// It needs a core checkout with its server dependencies installed, and nothing
|
||||||
|
// else: no database (the pool is pointed at a closed port, as core's own tests do
|
||||||
|
// and for the same reason), no shard, no network except the one `npm ci` below.
|
||||||
|
//
|
||||||
|
// The module is COPIED to a temp directory as `uo`, never symlinked (core's loader
|
||||||
|
// skips a link silently) and never installed over the checkout — a check that
|
||||||
|
// rewrote the tree it was checking would be a strange thing to run locally.
|
||||||
|
// `client/dist/entry.js` has to exist before the loader accepts the module at all;
|
||||||
|
// CI builds it in the step before, and locally `npm run build --prefix client`.
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// node server/scripts/templateBuild.js --core <core checkout> --module <module dir>
|
||||||
|
|
||||||
|
const fs = require('fs')
|
||||||
|
const os = require('os')
|
||||||
|
const path = require('path')
|
||||||
|
const { createRequire } = require('module')
|
||||||
|
const { spawnSync } = require('child_process')
|
||||||
|
|
||||||
|
// ── The fixtures ────────────────────────────────────────────────────────────
|
||||||
|
//
|
||||||
|
// Every recipe, with and without its optional inputs, plus a few refusals, which
|
||||||
|
// prove the author's sentence survives core's handling intact. An `expect` of
|
||||||
|
// `'refused'` means core must answer `ok: false` with status 400 and the given
|
||||||
|
// words in the first error; otherwise the build must come back `ok: true`, which
|
||||||
|
// means the spec passed core's real validator.
|
||||||
|
|
||||||
|
const FIXTURES = [
|
||||||
|
{
|
||||||
|
template: 'uo.template.announce',
|
||||||
|
label: 'text only',
|
||||||
|
inputs: { text: 'The gates of Britain open at dusk. Gather at the bank.' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
template: 'uo.template.announce',
|
||||||
|
label: 'with colour and a news article',
|
||||||
|
inputs: { text: 'The fair opens on Friday.', hue: 1153, newsTitle: 'The Britannian Midsummer Fair', newsMinutes: 2880 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
template: 'uo.template.announce',
|
||||||
|
label: 'news title, default length',
|
||||||
|
inputs: { text: 'The fair opens on Friday.', newsTitle: 'The Fair' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
template: 'uo.template.announce',
|
||||||
|
label: 'a news length with no title is refused',
|
||||||
|
inputs: { text: 'Hello', newsMinutes: 60 },
|
||||||
|
expect: 'refused',
|
||||||
|
words: /news title/,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
template: 'uo.template.boss_raid',
|
||||||
|
label: 'required inputs only',
|
||||||
|
inputs: { place: 'Felucca/Britain', creature: 'OrcCaptain', name: 'Gruk the Unbroken', minutes: 30 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
template: 'uo.template.boss_raid',
|
||||||
|
label: 'every input',
|
||||||
|
inputs: {
|
||||||
|
place: 'Felucca/Cities/Britain',
|
||||||
|
creature: 'OrcCaptain',
|
||||||
|
name: 'Gruk the Unbroken',
|
||||||
|
minutes: 90,
|
||||||
|
count: 3,
|
||||||
|
strength: 2.5,
|
||||||
|
message: 'Gruk and his warband march on Britain!',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
template: 'uo.template.boss_raid',
|
||||||
|
label: 'a count above the cap is refused',
|
||||||
|
inputs: { place: 'Felucca/Britain', creature: 'OrcCaptain', name: 'Gruk', minutes: 30, count: 99 },
|
||||||
|
expect: 'refused',
|
||||||
|
words: /bosses/,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
template: 'uo.template.seasonal',
|
||||||
|
label: 'required inputs only',
|
||||||
|
inputs: { event: 'Fellowship', minutes: 180 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
template: 'uo.template.seasonal',
|
||||||
|
label: 'with a message, at the lease ceiling',
|
||||||
|
inputs: { event: 'KrampusEncounter', minutes: 720, message: 'The Krampus has come to Britannia!' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
template: 'uo.template.seasonal',
|
||||||
|
label: 'an event the lease excludes is refused',
|
||||||
|
inputs: { event: 'TreasuresOfTokuno', minutes: 60 },
|
||||||
|
expect: 'refused',
|
||||||
|
words: /not a seasonal event/,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
template: 'uo.template.gathering_giveaway',
|
||||||
|
label: 'required inputs only',
|
||||||
|
inputs: { place: 'Felucca/Britain', minutes: 30, item: 'gold' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
template: 'uo.template.gathering_giveaway',
|
||||||
|
label: 'every input',
|
||||||
|
inputs: {
|
||||||
|
place: 'Felucca/Cities/Britain',
|
||||||
|
minutes: 45,
|
||||||
|
item: 'gold',
|
||||||
|
amount: 500,
|
||||||
|
radius: 100,
|
||||||
|
message: 'Come to Britain for a gift of gold!',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
template: 'uo.template.gathering_giveaway',
|
||||||
|
label: 'a non-stacking item, one each',
|
||||||
|
inputs: { place: 'Felucca/Britain', minutes: 60, item: 'cloak' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
template: 'uo.template.gathering_giveaway',
|
||||||
|
label: 'a non-stacking item in quantity is refused',
|
||||||
|
inputs: { place: 'Felucca/Britain', minutes: 60, item: 'cloak', amount: 5 },
|
||||||
|
expect: 'refused',
|
||||||
|
words: /does not stack/,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
// ── Plumbing ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
function parseArgs(argv) {
|
||||||
|
const out = {}
|
||||||
|
for (let i = 0; i < argv.length; i++) {
|
||||||
|
if (argv[i] === '--core') out.core = argv[++i]
|
||||||
|
else if (argv[i] === '--module') out.module = argv[++i]
|
||||||
|
else throw new Error(`unknown argument "${argv[i]}"`)
|
||||||
|
}
|
||||||
|
if (!out.core || !out.module) {
|
||||||
|
throw new Error('usage: node server/scripts/templateBuild.js --core <core checkout> --module <module dir>')
|
||||||
|
}
|
||||||
|
return { core: path.resolve(out.core), module: path.resolve(out.module) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Copy the module as `<tmp>/uo`, without `.git` or any `node_modules`, and install its production deps. */
|
||||||
|
function stageModule(moduleDir, tmpRoot) {
|
||||||
|
const dest = path.join(tmpRoot, 'uo')
|
||||||
|
fs.cpSync(moduleDir, dest, {
|
||||||
|
recursive: true,
|
||||||
|
filter: (src) => {
|
||||||
|
const base = path.basename(src)
|
||||||
|
return base !== '.git' && base !== 'node_modules'
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if (!fs.existsSync(path.join(dest, 'client', 'dist', 'entry.js'))) {
|
||||||
|
throw new Error(
|
||||||
|
`${path.join(moduleDir, 'client', 'dist', 'entry.js')} is missing — the loader refuses a module with no client chunk. ` +
|
||||||
|
'Build it first: npm run build --prefix client',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
// What the release ships and CI installs: the production dependencies, from the
|
||||||
|
// lockfile. One command string through a shell, because npm is a .cmd on Windows
|
||||||
|
// and Node will not spawn one directly; the only path in it is our own temp dir.
|
||||||
|
const install = spawnSync(`npm ci --omit=dev --no-audit --no-fund --prefix "${path.join(dest, 'server')}"`, {
|
||||||
|
encoding: 'utf8',
|
||||||
|
shell: true,
|
||||||
|
})
|
||||||
|
if (install.status !== 0) {
|
||||||
|
throw new Error(`npm ci in the staged module failed:\n${install.stdout || ''}${install.stderr || ''}`)
|
||||||
|
}
|
||||||
|
return dest
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const args = parseArgs(process.argv.slice(2))
|
||||||
|
const coreServer = path.join(args.core, 'server')
|
||||||
|
if (!fs.existsSync(path.join(coreServer, 'node_modules'))) {
|
||||||
|
throw new Error(`${coreServer}/node_modules is missing — run npm ci --prefix ${path.join(args.core, 'server')}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'uo-template-build-'))
|
||||||
|
let exitCode = 1
|
||||||
|
let db = null
|
||||||
|
try {
|
||||||
|
stageModule(args.module, tmpRoot)
|
||||||
|
|
||||||
|
// BEFORE core is required: the loader reads MODULES_DIR once, when its file is
|
||||||
|
// evaluated, and the pool opens a connection lazily against whatever these say.
|
||||||
|
// A closed port makes a stray query fail at once instead of hanging a check
|
||||||
|
// that is meant to need no database.
|
||||||
|
process.env.MODULES_DIR = tmpRoot
|
||||||
|
process.env.DB_HOST = '127.0.0.1'
|
||||||
|
process.env.DB_PORT = '59999'
|
||||||
|
|
||||||
|
const coreRequire = createRequire(path.join(coreServer, 'package.json'))
|
||||||
|
const express = coreRequire('express')
|
||||||
|
db = coreRequire('./src/utils/db')
|
||||||
|
const registries = coreRequire('./src/modules/registries')
|
||||||
|
const loader = coreRequire('./src/modules/loader')
|
||||||
|
const definitions = coreRequire('./src/model/events/eventDefinitions.model')
|
||||||
|
|
||||||
|
// The module fills `admin.users.detail`, a slot core's own users router
|
||||||
|
// declares as it is required (`registries.declareSlot`). Requiring that router
|
||||||
|
// is what declares it for real, rather than this script claiming a slot exists.
|
||||||
|
coreRequire('./src/router/v1/admin/users.router')
|
||||||
|
|
||||||
|
// The same three tier routers core's own step-editor test hands the loader.
|
||||||
|
loader.load({ public: express.Router(), admin: express.Router(), player: express.Router() })
|
||||||
|
const record = loader.list().find((m) => m.id === 'uo')
|
||||||
|
if (!record || record.state !== 'registered') {
|
||||||
|
throw new Error(`core did not register the module: ${record ? `${record.state} — ${record.reason}` : 'it was not found'}`)
|
||||||
|
}
|
||||||
|
// Core's own actions (`core.lease`, `core.wait`…) are what a recipe's spec may
|
||||||
|
// name beside the module's, and they are registered separately from the scan.
|
||||||
|
registries.registerCore()
|
||||||
|
|
||||||
|
const catalog = registries.allEventTemplates().filter((t) => t.owner === 'uo')
|
||||||
|
const registered = new Set(catalog.map((t) => t.id))
|
||||||
|
const covered = new Set(FIXTURES.map((f) => f.template))
|
||||||
|
let failures = 0
|
||||||
|
for (const id of registered) {
|
||||||
|
if (!covered.has(id)) {
|
||||||
|
failures++
|
||||||
|
console.log(`FAIL ${id} has no fixture in templateBuild.js`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const id of covered) {
|
||||||
|
if (!registered.has(id)) {
|
||||||
|
failures++
|
||||||
|
console.log(`FAIL ${id} is not registered by the module`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const fixture of FIXTURES) {
|
||||||
|
const name = `${fixture.template} (${fixture.label})`
|
||||||
|
let result
|
||||||
|
try {
|
||||||
|
result = await definitions.buildFromTemplate(fixture.template, fixture.inputs)
|
||||||
|
} catch (err) {
|
||||||
|
failures++
|
||||||
|
console.log(`FAIL ${name} threw: ${err.message}`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fixture.expect === 'refused') {
|
||||||
|
const said = (result.errors || [])[0] || ''
|
||||||
|
if (result.ok === false && result.status === 400 && fixture.words.test(said)) {
|
||||||
|
console.log(`OK ${name} refused: ${said}`)
|
||||||
|
} else {
|
||||||
|
failures++
|
||||||
|
console.log(`FAIL ${name} expected a 400 refusal matching ${fixture.words}, got ${JSON.stringify(result)}`)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.ok === true) {
|
||||||
|
const phases = result.draft.spec.phases.map((p) => p.key).join(' > ')
|
||||||
|
console.log(`OK ${name} "${result.draft.title}" [${phases}]`)
|
||||||
|
} else {
|
||||||
|
failures++
|
||||||
|
console.log(`FAIL ${name} status ${result.status}: ${(result.errors || []).join(' | ')}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(failures ? `\n${failures} failure(s)` : `\nAll ${FIXTURES.length} fixtures passed through core's registry and spec validator.`)
|
||||||
|
exitCode = failures ? 1 : 0
|
||||||
|
} finally {
|
||||||
|
// Close core's pool or the process hangs on it, then take the copy away.
|
||||||
|
try {
|
||||||
|
if (db && typeof db.close === 'function') await db.close()
|
||||||
|
} catch {
|
||||||
|
/* the pool never opened a connection; nothing to close */
|
||||||
|
}
|
||||||
|
fs.rmSync(tmpRoot, { recursive: true, force: true })
|
||||||
|
}
|
||||||
|
return exitCode
|
||||||
|
}
|
||||||
|
|
||||||
|
main().then(
|
||||||
|
(code) => process.exit(code),
|
||||||
|
(err) => {
|
||||||
|
console.error(`templateBuild: ${err.message}`)
|
||||||
|
process.exit(1)
|
||||||
|
},
|
||||||
|
)
|
||||||
@@ -684,16 +684,6 @@ module.exports = {
|
|||||||
extractorVersion: { type: 'integer', example: 1 },
|
extractorVersion: { type: 'integer', example: 1 },
|
||||||
hashing: { type: 'boolean', description: 'A hash is being computed in the background. A null `sha256` while this is true means “not yet”, never “changed”.', example: false },
|
hashing: { type: 'boolean', description: 'A hash is being computed in the background. A null `sha256` while this is true means “not yet”, never “changed”.', example: false },
|
||||||
complete: { type: 'boolean', description: 'Every client file has a content hash.', example: true },
|
complete: { type: 'boolean', description: 'Every client file has a content hash.', example: true },
|
||||||
imaging: {
|
|
||||||
type: 'object',
|
|
||||||
nullable: true,
|
|
||||||
description: 'Whether the shard host can render an image at all. `ok: false` is the named NO_IMAGING state: ServUO under Mono needs libgdiplus, and without it a Linux shard cannot decode a sprite. Cliloc and atlas import are unaffected.',
|
|
||||||
properties: {
|
|
||||||
ok: { type: 'boolean', example: true },
|
|
||||||
code: { type: 'string', nullable: true, example: null },
|
|
||||||
reason: { type: 'string', nullable: true },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
families: {
|
families: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
items: { type: 'string' },
|
items: { type: 'string' },
|
||||||
@@ -713,14 +703,14 @@ module.exports = {
|
|||||||
type: 'string',
|
type: 'string',
|
||||||
nullable: true,
|
nullable: true,
|
||||||
description: 'Machine-readable cause of `reason`.',
|
description: 'Machine-readable cause of `reason`.',
|
||||||
enum: ['DISABLED', 'NO_SOURCE', 'SHARD_DOWN', 'PROTOCOL', 'BUSY', 'NO_IMAGING', 'SOURCE_CHANGED', 'UNAVAILABLE'],
|
enum: ['DISABLED', 'NO_SOURCE', 'SHARD_DOWN', 'PROTOCOL', 'BUSY', 'SOURCE_CHANGED', 'UNAVAILABLE'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
UoAssetImportResult: {
|
UoAssetImportResult: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
description:
|
description:
|
||||||
'Outcome of an asset import. Reported rather than thrown, so a shard that is down or a host that cannot render images is an answer and not a 500.',
|
'Outcome of an asset import. Reported rather than thrown, so a shard that is down is an answer and not a 500.',
|
||||||
properties: {
|
properties: {
|
||||||
status: {
|
status: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
@@ -732,8 +722,8 @@ module.exports = {
|
|||||||
code: {
|
code: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
nullable: true,
|
nullable: true,
|
||||||
description: 'Machine-readable cause. `NO_IMAGING` is a shard host with no libgdiplus; `SOURCE_CHANGED` is a client patched partway through the walk, in which case nothing was applied.',
|
description: 'Machine-readable cause. `SOURCE_CHANGED` is a client patched partway through the walk, in which case nothing was applied.',
|
||||||
enum: ['DISABLED', 'NO_SOURCE', 'SHARD_DOWN', 'PROTOCOL', 'BUSY', 'NO_IMAGING', 'SOURCE_CHANGED', 'INCOMPLETE', 'STUCK', 'MALFORMED', 'TOO_LARGE', 'UNAVAILABLE'],
|
enum: ['DISABLED', 'NO_SOURCE', 'SHARD_DOWN', 'PROTOCOL', 'BUSY', 'SOURCE_CHANGED', 'INCOMPLETE', 'STUCK', 'MALFORMED', 'TOO_LARGE', 'UNAVAILABLE'],
|
||||||
},
|
},
|
||||||
catalog: { type: 'string', nullable: true, example: 'a3f9c21d4b8e0771' },
|
catalog: { type: 'string', nullable: true, example: 'a3f9c21d4b8e0771' },
|
||||||
extractorVersion: { type: 'integer', nullable: true, example: 1 },
|
extractorVersion: { type: 'integer', nullable: true, example: 1 },
|
||||||
@@ -821,8 +811,8 @@ module.exports = {
|
|||||||
type: 'string',
|
type: 'string',
|
||||||
nullable: true,
|
nullable: true,
|
||||||
description:
|
description:
|
||||||
'Machine-readable cause. `NO_IMAGING` is a shard host with no libgdiplus. `UNSUPPORTED` is a plugin overlay that serves the creature catalogue but not item art — update the overlay.',
|
'Machine-readable cause. `UNSUPPORTED` is a plugin overlay that serves the creature catalogue but not item art — update the overlay.',
|
||||||
enum: ['DISABLED', 'NO_SOURCE', 'SHARD_DOWN', 'PROTOCOL', 'BUSY', 'NO_IMAGING', 'UNSUPPORTED', 'INCOMPLETE', 'STUCK', 'MALFORMED', 'TOO_LARGE', 'UNAVAILABLE'],
|
enum: ['DISABLED', 'NO_SOURCE', 'SHARD_DOWN', 'PROTOCOL', 'BUSY', 'UNSUPPORTED', 'INCOMPLETE', 'STUCK', 'MALFORMED', 'TOO_LARGE', 'UNAVAILABLE'],
|
||||||
},
|
},
|
||||||
catalog: {
|
catalog: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ function fakeApi() {
|
|||||||
eventActions: null,
|
eventActions: null,
|
||||||
eventBudgets: null,
|
eventBudgets: null,
|
||||||
eventOptionSources: null,
|
eventOptionSources: null,
|
||||||
|
eventTemplates: null,
|
||||||
hooks: {},
|
hooks: {},
|
||||||
}
|
}
|
||||||
const called = new Set()
|
const called = new Set()
|
||||||
@@ -147,6 +148,9 @@ function fakeApi() {
|
|||||||
// for a second one: a verb this module calls and this fake does not have is a
|
// for a second one: a verb this module calls and this fake does not have is a
|
||||||
// TypeError in `entry.test.js` rather than a surprise at somebody's boot.
|
// TypeError in `entry.test.js` rather than a surprise at somebody's boot.
|
||||||
registerEventLeases(leases) { once('registerEventLeases'); record.eventLeases = leases },
|
registerEventLeases(leases) { once('registerEventLeases'); record.eventLeases = leases },
|
||||||
|
// MODULE_API 1.13.0. `once` as for the rest: core stages a registrant's whole
|
||||||
|
// batch and applies it as one.
|
||||||
|
registerEventTemplates(templates) { once('registerEventTemplates'); record.eventTemplates = templates },
|
||||||
onBoot(fn) { once('onBoot'); record.hooks.onBoot = fn },
|
onBoot(fn) { once('onBoot'); record.hooks.onBoot = fn },
|
||||||
onShutdown(fn) { once('onShutdown'); record.hooks.onShutdown = fn },
|
onShutdown(fn) { once('onShutdown'); record.hooks.onShutdown = fn },
|
||||||
// MODULE_API 1.20.0 (account deletion, ACCOUNT_DELETION.md §4.4).
|
// MODULE_API 1.20.0 (account deletion, ACCOUNT_DELETION.md §4.4).
|
||||||
|
|||||||
@@ -107,7 +107,6 @@ const sourcesReply = (extra = {}) =>
|
|||||||
ok({
|
ok({
|
||||||
kind: 'assets.sources.ok',
|
kind: 'assets.sources.ok',
|
||||||
extractorVersion: 1,
|
extractorVersion: 1,
|
||||||
imaging: { ok: true },
|
|
||||||
hashing: false,
|
hashing: false,
|
||||||
complete: true,
|
complete: true,
|
||||||
files: [
|
files: [
|
||||||
@@ -334,16 +333,16 @@ test('a busy shard is retried rather than failing the walk', async (t) => {
|
|||||||
assert.equal(assets.size, 1)
|
assert.equal(assets.size, 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('a shard host with no libgdiplus is named, not reported as a dead shard', async (t) => {
|
test('a 503 is a shard that is down, whatever its reason says', async (t) => {
|
||||||
saved.getAssetManifest = uoLinkClient.getAssetManifest
|
saved.getAssetManifest = uoLinkClient.getAssetManifest
|
||||||
t.after(restore)
|
t.after(restore)
|
||||||
|
|
||||||
uoLinkClient.getAssetManifest = async () =>
|
uoLinkClient.getAssetManifest = async () =>
|
||||||
fail(503, { reason: "this shard host cannot render images - Mono's System.Drawing needs libgdiplus" })
|
fail(503, { reason: 'the shard is not connected' })
|
||||||
|
|
||||||
await assert.rejects(
|
await assert.rejects(
|
||||||
() => bridge.readManifest(),
|
() => bridge.readManifest(),
|
||||||
(err) => err.code === 'NO_IMAGING',
|
(err) => err.code === 'SHARD_DOWN',
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ const sourcesReply = (file = {}) =>
|
|||||||
ok({
|
ok({
|
||||||
kind: 'assets.sources.ok',
|
kind: 'assets.sources.ok',
|
||||||
extractorVersion: 1,
|
extractorVersion: 1,
|
||||||
imaging: { ok: true },
|
|
||||||
hashing: false,
|
hashing: false,
|
||||||
complete: true,
|
complete: true,
|
||||||
files: [
|
files: [
|
||||||
|
|||||||
@@ -128,6 +128,17 @@ test('registers exactly what module.json declares', () => {
|
|||||||
'uo.options.spawners',
|
'uo.options.spawners',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
// The four recipes (MODULE_API 1.13.0). Each id carries this module's prefix, which
|
||||||
|
// core's loader enforces, and its own suite is eventTemplates.test.js.
|
||||||
|
assert.deepStrictEqual(
|
||||||
|
api.record.eventTemplates.map((t) => t.id).sort(),
|
||||||
|
[
|
||||||
|
'uo.template.announce',
|
||||||
|
'uo.template.boss_raid',
|
||||||
|
'uo.template.gathering_giveaway',
|
||||||
|
'uo.template.seasonal',
|
||||||
|
],
|
||||||
|
)
|
||||||
assert.ok(api.record.streams.length > 0)
|
assert.ok(api.record.streams.length > 0)
|
||||||
assert.strictEqual(typeof api.record.hooks.onBoot, 'function')
|
assert.strictEqual(typeof api.record.hooks.onBoot, 'function')
|
||||||
assert.strictEqual(typeof api.record.hooks.onShutdown, 'function')
|
assert.strictEqual(typeof api.record.hooks.onShutdown, 'function')
|
||||||
|
|||||||
395
server/test/eventTemplates.test.js
Normal file
395
server/test/eventTemplates.test.js
Normal file
@@ -0,0 +1,395 @@
|
|||||||
|
// The four event recipes (MODULE_API 1.13.0): what each one builds, and what it
|
||||||
|
// refuses in words an author can read.
|
||||||
|
//
|
||||||
|
// This suite runs against a FAKE core, so it can say a spec has the right shape
|
||||||
|
// but not that core accepts it. That half is `scripts/templateBuild.js`, which
|
||||||
|
// builds every recipe through core's own registry and spec validator in CI.
|
||||||
|
|
||||||
|
const test = require('node:test')
|
||||||
|
const assert = require('node:assert')
|
||||||
|
|
||||||
|
const register = require('../index')
|
||||||
|
const { fakeCtx, fakeApi } = require('./_fakes')
|
||||||
|
const templates = require('../eventTemplates')
|
||||||
|
const actions = require('../config/uoEventActions')
|
||||||
|
|
||||||
|
const byId = (id) => templates.TEMPLATES.find((t) => t.id === id)
|
||||||
|
const build = (id, inputs) => byId(id).build({ inputs })
|
||||||
|
|
||||||
|
const ID_GRAMMAR = /^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$/
|
||||||
|
const PHASE_KEY = /^[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*$/
|
||||||
|
// What core's `checkActionParam` lets through (registries.js).
|
||||||
|
const INPUT_KEYS = ['name', 'type', 'required', 'example', 'description', 'source', 'duration', 'max']
|
||||||
|
const TYPES = ['string', 'int', 'float', 'boolean', 'datetime', 'url']
|
||||||
|
|
||||||
|
const refused = (result, pattern) => {
|
||||||
|
assert.strictEqual(result.ok, false, 'expected a refusal')
|
||||||
|
assert.strictEqual(typeof result.error, 'string')
|
||||||
|
assert.ok(result.error.length > 10, 'a refusal is a sentence')
|
||||||
|
if (pattern) assert.match(result.error, pattern)
|
||||||
|
}
|
||||||
|
|
||||||
|
const stepIds = (phase) => phase.steps.map((s) => s.actionId)
|
||||||
|
|
||||||
|
// ── Registration and declarations ───────────────────────────────────────────
|
||||||
|
|
||||||
|
test('index.js registers the four recipes, once, through registerEventTemplates', () => {
|
||||||
|
const api = fakeApi()
|
||||||
|
register(fakeCtx(), api)
|
||||||
|
assert.deepStrictEqual(
|
||||||
|
api.record.eventTemplates.map((t) => t.id).sort(),
|
||||||
|
['uo.template.announce', 'uo.template.boss_raid', 'uo.template.gathering_giveaway', 'uo.template.seasonal'],
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('every recipe is shaped the way core\'s registry demands', () => {
|
||||||
|
assert.strictEqual(templates.TEMPLATES.length, 4)
|
||||||
|
const actionIds = new Set(actions.ACTIONS.map((a) => a.id).concat('core.lease'))
|
||||||
|
const leaseIds = new Set(actions.LEASES.map((l) => l.id))
|
||||||
|
const sourceIds = new Set(actions.OPTION_SOURCES.map((s) => s.id))
|
||||||
|
|
||||||
|
for (const t of templates.TEMPLATES) {
|
||||||
|
assert.match(t.id, ID_GRAMMAR)
|
||||||
|
assert.ok(t.id.startsWith('uo.'), `${t.id} must carry this module's prefix`)
|
||||||
|
assert.ok(t.label, `${t.id} has no label`)
|
||||||
|
assert.ok(t.description.length > 40, `${t.id} needs a description an author can read`)
|
||||||
|
assert.strictEqual(typeof t.build, 'function')
|
||||||
|
assert.ok(t.inputs.length >= 1 && t.inputs.length <= 8, `${t.id} asks for ${t.inputs.length} inputs`)
|
||||||
|
|
||||||
|
const seen = new Set()
|
||||||
|
for (const input of t.inputs) {
|
||||||
|
const where = `${t.id}.${input.name}`
|
||||||
|
assert.match(input.name, /^[A-Za-z][A-Za-z0-9_]*$/, where)
|
||||||
|
assert.ok(!seen.has(input.name), `${where} declared twice`)
|
||||||
|
seen.add(input.name)
|
||||||
|
assert.ok(TYPES.includes(input.type), `${where} has type ${input.type}`)
|
||||||
|
for (const key of Object.keys(input)) assert.ok(INPUT_KEYS.includes(key), `${where} has unknown key ${key}`)
|
||||||
|
// Core refuses an input with no example, optional or not, and silently drops `default`.
|
||||||
|
assert.ok(input.example !== undefined && input.example !== null && input.example !== '', `${where} needs an example`)
|
||||||
|
assert.ok(input.description && input.description.length > 10, `${where} needs a plain-English description`)
|
||||||
|
assert.strictEqual(input.default, undefined, `${where}: core drops \`default\`; apply it in build()`)
|
||||||
|
assert.strictEqual(input.multiple, undefined, `${where}: a template input cannot be multiple`)
|
||||||
|
assert.strictEqual(typeof input.required, 'boolean', `${where} should say whether it is required`)
|
||||||
|
if (input.duration !== undefined) {
|
||||||
|
assert.strictEqual(input.duration, 'minutes')
|
||||||
|
assert.ok(input.type === 'int' || input.type === 'float', `${where}: a duration is a number`)
|
||||||
|
}
|
||||||
|
if (input.source) assert.ok(sourceIds.has(input.source), `${where} names a source no module declares`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The actions and lease the recipes build steps out of all exist.
|
||||||
|
const used = new Set()
|
||||||
|
const sample = {
|
||||||
|
'uo.template.announce': { text: 'Hello', newsTitle: 'News' },
|
||||||
|
'uo.template.boss_raid': { place: 'Felucca/Britain', creature: 'OrcCaptain', name: 'Gruk', minutes: 10 },
|
||||||
|
'uo.template.seasonal': { event: 'Fellowship', minutes: 60, message: 'On' },
|
||||||
|
'uo.template.gathering_giveaway': { place: 'Felucca/Britain', minutes: 10, item: 'gold' },
|
||||||
|
}
|
||||||
|
for (const [id, inputs] of Object.entries(sample)) {
|
||||||
|
const built = build(id, inputs)
|
||||||
|
for (const phase of built.spec.phases) {
|
||||||
|
for (const step of phase.steps) {
|
||||||
|
used.add(step.actionId)
|
||||||
|
assert.ok(actionIds.has(step.actionId), `${id} uses ${step.actionId}, which nobody declares`)
|
||||||
|
if (step.actionId === 'core.lease') assert.ok(leaseIds.has(step.params.lease), `${id} leases ${step.params.lease}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert.ok(used.size >= 7)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('every built plan is a plain spec: three top-level keys at most, legal phase keys, one gate form', () => {
|
||||||
|
const fixtures = [
|
||||||
|
['uo.template.announce', { text: 'Hello', newsTitle: 'News', newsMinutes: 90, hue: 5 }],
|
||||||
|
['uo.template.boss_raid', { place: 'Felucca/Britain', creature: 'OrcCaptain', name: 'Gruk', minutes: 30, count: 2, strength: 2.5 }],
|
||||||
|
['uo.template.seasonal', { event: 'RisingTide', minutes: 720 }],
|
||||||
|
['uo.template.gathering_giveaway', { place: 'Felucca/Cities/Britain', minutes: 30, item: 'cloak' }],
|
||||||
|
]
|
||||||
|
for (const [id, inputs] of fixtures) {
|
||||||
|
const built = build(id, inputs)
|
||||||
|
assert.ok(!('ok' in built), `${id}: ${built.error}`)
|
||||||
|
assert.ok(built.title && built.summary)
|
||||||
|
assert.deepStrictEqual(built.spec.schedule, { kind: 'manual' })
|
||||||
|
for (const key of Object.keys(built.spec)) assert.ok(['schedule', 'phases', 'starts'].includes(key), `${id}: ${key}`)
|
||||||
|
const keys = new Set()
|
||||||
|
for (const phase of built.spec.phases) {
|
||||||
|
assert.match(phase.key, PHASE_KEY)
|
||||||
|
assert.ok(!keys.has(phase.key))
|
||||||
|
keys.add(phase.key)
|
||||||
|
assert.ok(phase.label)
|
||||||
|
assert.ok(phase.steps.length > 0)
|
||||||
|
if (phase.advance) assert.match(phase.advance.after, /^\d+m$/)
|
||||||
|
for (const step of phase.steps) {
|
||||||
|
assert.ok(step.label)
|
||||||
|
assert.strictEqual(typeof step.params, 'object')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// ── Announcement ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
test('announce: a broadcast alone has no hold', () => {
|
||||||
|
const built = build('uo.template.announce', { text: ' The gates open at dusk. ' })
|
||||||
|
assert.strictEqual(built.spec.phases.length, 1)
|
||||||
|
const [phase] = built.spec.phases
|
||||||
|
assert.strictEqual(phase.key, 'announce')
|
||||||
|
assert.deepStrictEqual(stepIds(phase), ['uo.broadcast'])
|
||||||
|
assert.deepStrictEqual(phase.steps[0].params, { text: 'The gates open at dusk.' })
|
||||||
|
assert.strictEqual(phase.advance, undefined)
|
||||||
|
assert.match(built.title, /^Announcement: The gates open at dusk\.$/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('announce: a hue is passed through, and an empty one is left out', () => {
|
||||||
|
const [phase] = build('uo.template.announce', { text: 'Hi', hue: 1153 }).spec.phases
|
||||||
|
assert.deepStrictEqual(phase.steps[0].params, { text: 'Hi', hue: 1153 })
|
||||||
|
const [bare] = build('uo.template.announce', { text: 'Hi', hue: '' }).spec.phases
|
||||||
|
assert.deepStrictEqual(bare.steps[0].params, { text: 'Hi' })
|
||||||
|
// Zero is a colour, not an empty box.
|
||||||
|
const [zero] = build('uo.template.announce', { text: 'Hi', hue: 0 }).spec.phases
|
||||||
|
assert.strictEqual(zero.steps[0].params.hue, 0)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('announce: a news title adds the article, holds the phase for a day by default, and does not proclaim twice', () => {
|
||||||
|
const built = build('uo.template.announce', { text: 'Fair opens Friday.', newsTitle: ' The Fair ' })
|
||||||
|
const [phase] = built.spec.phases
|
||||||
|
assert.deepStrictEqual(stepIds(phase), ['uo.broadcast', 'uo.news.post'])
|
||||||
|
assert.deepStrictEqual(phase.steps[1].params, { title: 'The Fair', body: 'Fair opens Friday.', announce: false })
|
||||||
|
assert.deepStrictEqual(phase.advance, { after: '1440m' })
|
||||||
|
assert.match(built.summary, /Town Cryer news for 24 hours/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('announce: newsMinutes sets the hold', () => {
|
||||||
|
const [phase] = build('uo.template.announce', { text: 'x y', newsTitle: 'T', newsMinutes: 90 }).spec.phases
|
||||||
|
assert.deepStrictEqual(phase.advance, { after: '90m' })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('announce: refusals are sentences', () => {
|
||||||
|
refused(build('uo.template.announce', { text: ' ' }), /no text/)
|
||||||
|
refused(build('uo.template.announce', { text: 'x'.repeat(actions.MAX_BROADCAST_LEN + 1) }), /capped at 300/)
|
||||||
|
// At the cap is fine.
|
||||||
|
assert.ok(!('ok' in build('uo.template.announce', { text: 'x'.repeat(actions.MAX_BROADCAST_LEN) })))
|
||||||
|
refused(build('uo.template.announce', { text: 'Hi', hue: -1 }), /colour/)
|
||||||
|
refused(build('uo.template.announce', { text: 'Hi', hue: 1.5 }), /colour/)
|
||||||
|
refused(build('uo.template.announce', { text: 'Hi', newsMinutes: 60 }), /needs a news title/)
|
||||||
|
refused(build('uo.template.announce', { text: 'Hi', newsTitle: 'T'.repeat(actions.MAX_NEWS_TITLE + 1) }), /news title is capped/)
|
||||||
|
refused(build('uo.template.announce', { text: 'Hi', newsTitle: 'T', newsMinutes: 0 }), /1 to \d+ minutes/)
|
||||||
|
refused(build('uo.template.announce', { text: 'Hi', newsTitle: 'T', newsMinutes: 1.5 }), /1 to \d+ minutes/)
|
||||||
|
refused(build('uo.template.announce', { text: 'Hi', newsTitle: 'T', newsMinutes: templates.MAX_HOLD_MINUTES + 1 }), /1 to \d+ minutes/)
|
||||||
|
})
|
||||||
|
|
||||||
|
// ── Boss raid ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const RAID = { place: 'Felucca/Britain', creature: 'OrcCaptain', name: 'Gruk the Unbroken', minutes: 30 }
|
||||||
|
|
||||||
|
test('boss raid: defaults — one boss, no strength keys, a plain message, held for the raid', () => {
|
||||||
|
const built = build('uo.template.boss_raid', RAID)
|
||||||
|
assert.strictEqual(built.title, 'Orc Captain raid at Felucca/Britain for 30 minutes')
|
||||||
|
assert.match(built.summary, /^Gruk the Unbroken, built from Orc Captain, appears near Felucca\/Britain and is removed after 30 minutes\.$/)
|
||||||
|
const [phase] = built.spec.phases
|
||||||
|
assert.strictEqual(built.spec.phases.length, 1)
|
||||||
|
assert.strictEqual(phase.key, 'raid')
|
||||||
|
assert.deepStrictEqual(phase.advance, { after: '30m' })
|
||||||
|
assert.deepStrictEqual(stepIds(phase), ['uo.boss.spawn', 'uo.broadcast'])
|
||||||
|
assert.deepStrictEqual(phase.steps[0].params, {
|
||||||
|
place: 'Felucca/Britain',
|
||||||
|
creature: 'OrcCaptain',
|
||||||
|
name: 'Gruk the Unbroken',
|
||||||
|
count: 1,
|
||||||
|
})
|
||||||
|
assert.deepStrictEqual(phase.steps[1].params, { text: 'Gruk the Unbroken has appeared near Britain!' })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('boss raid: strength 1 is the same as leaving it out', () => {
|
||||||
|
const [phase] = build('uo.template.boss_raid', { ...RAID, strength: 1 }).spec.phases
|
||||||
|
assert.strictEqual(phase.steps[0].params.hitsMultiplier, undefined)
|
||||||
|
assert.strictEqual(phase.steps[0].params.damageMultiplier, undefined)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('boss raid: strength sets both multipliers, and a count and message are kept', () => {
|
||||||
|
const built = build('uo.template.boss_raid', { ...RAID, strength: 2.5, count: 3, message: ' Run! ', minutes: 120 })
|
||||||
|
const [phase] = built.spec.phases
|
||||||
|
assert.strictEqual(phase.steps[0].params.hitsMultiplier, 2.5)
|
||||||
|
assert.strictEqual(phase.steps[0].params.damageMultiplier, 2.5)
|
||||||
|
assert.strictEqual(phase.steps[0].params.count, 3)
|
||||||
|
assert.deepStrictEqual(phase.steps[1].params, { text: 'Run!' })
|
||||||
|
assert.deepStrictEqual(phase.advance, { after: '120m' })
|
||||||
|
assert.match(built.title, /for 2 hours$/)
|
||||||
|
assert.match(built.summary, /^3 bosses called Gruk the Unbroken, built from Orc Captain and 2\.5 times as strong, appear near/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('boss raid: the bounds are the action\'s own', () => {
|
||||||
|
const top = build('uo.template.boss_raid', { ...RAID, count: actions.MAX_BOSSES, strength: actions.MAX_BOSS_MULTIPLIER })
|
||||||
|
assert.ok(!('ok' in top))
|
||||||
|
refused(build('uo.template.boss_raid', { ...RAID, count: actions.MAX_BOSSES + 1 }), /1 to 4 bosses/)
|
||||||
|
refused(build('uo.template.boss_raid', { ...RAID, count: 0 }), /1 to 4 bosses/)
|
||||||
|
refused(build('uo.template.boss_raid', { ...RAID, strength: actions.MAX_BOSS_MULTIPLIER + 0.5 }), /1 to 10 times/)
|
||||||
|
refused(build('uo.template.boss_raid', { ...RAID, strength: 0.5 }), /1 to 10 times/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('boss raid: refusals are sentences', () => {
|
||||||
|
refused(build('uo.template.boss_raid', { ...RAID, place: 'Britain' }), /not a place/)
|
||||||
|
refused(build('uo.template.boss_raid', { ...RAID, place: 'Felucca/' }), /not a place/)
|
||||||
|
refused(build('uo.template.boss_raid', { ...RAID, creature: ' ' }), /pick a creature/)
|
||||||
|
refused(build('uo.template.boss_raid', { ...RAID, name: '' }), /needs a name/)
|
||||||
|
refused(build('uo.template.boss_raid', { ...RAID, minutes: 0 }), /1 to \d+ minutes/)
|
||||||
|
refused(build('uo.template.boss_raid', { ...RAID, minutes: 'soon' }), /1 to \d+ minutes/)
|
||||||
|
refused(build('uo.template.boss_raid', { ...RAID, message: 'x'.repeat(301) }), /capped at 300/)
|
||||||
|
// The default message is what overflows when the name is huge, and the refusal says so.
|
||||||
|
refused(build('uo.template.boss_raid', { ...RAID, name: 'N'.repeat(300) }), /default message/)
|
||||||
|
})
|
||||||
|
|
||||||
|
// ── Seasonal ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
test('seasonal: one lease step on the chosen event, held for the same length, no broadcast without a message', () => {
|
||||||
|
const built = build('uo.template.seasonal', { event: 'KrampusEncounter', minutes: 180 })
|
||||||
|
const [phase] = built.spec.phases
|
||||||
|
assert.strictEqual(phase.key, 'season')
|
||||||
|
assert.deepStrictEqual(phase.advance, { after: '180m' })
|
||||||
|
assert.deepStrictEqual(stepIds(phase), ['core.lease'])
|
||||||
|
assert.deepStrictEqual(phase.steps[0].params, {
|
||||||
|
lease: 'uo.seasonal.status',
|
||||||
|
target: 'KrampusEncounter',
|
||||||
|
value: 'Active',
|
||||||
|
minutes: 180,
|
||||||
|
})
|
||||||
|
assert.strictEqual(built.title, 'Krampus Encounter for 3 hours')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('seasonal: a message adds a broadcast after the lease', () => {
|
||||||
|
const [phase] = build('uo.template.seasonal', { event: 'Fellowship', minutes: 45, message: 'It is on!' }).spec.phases
|
||||||
|
assert.deepStrictEqual(stepIds(phase), ['core.lease', 'uo.broadcast'])
|
||||||
|
assert.deepStrictEqual(phase.steps[1].params, { text: 'It is on!' })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('seasonal: every event the lease allows builds, and the lease ceiling is the limit', () => {
|
||||||
|
for (const event of actions.SEASONAL_EVENTS) {
|
||||||
|
assert.ok(!('ok' in build('uo.template.seasonal', { event, minutes: 60 })), event)
|
||||||
|
}
|
||||||
|
assert.strictEqual(templates.MAX_SEASONAL_MINUTES, actions.MAX_PROP_LEASE_MS / 60_000)
|
||||||
|
assert.strictEqual(templates.MAX_SEASONAL_MINUTES, 720)
|
||||||
|
assert.ok(!('ok' in build('uo.template.seasonal', { event: 'Fellowship', minutes: 720 })))
|
||||||
|
refused(build('uo.template.seasonal', { event: 'Fellowship', minutes: 721 }), /1 to 720 minutes/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('seasonal: refusals are sentences', () => {
|
||||||
|
refused(build('uo.template.seasonal', { event: 'TreasuresOfTokuno', minutes: 60 }), /not a seasonal event/)
|
||||||
|
refused(build('uo.template.seasonal', { event: 'Christmas', minutes: 60 }), /not a seasonal event/)
|
||||||
|
refused(build('uo.template.seasonal', { event: 'Fellowship', minutes: 0 }), /1 to 720 minutes/)
|
||||||
|
refused(build('uo.template.seasonal', { event: 'Fellowship', minutes: 2.5 }), /1 to 720 minutes/)
|
||||||
|
refused(build('uo.template.seasonal', { event: 'Fellowship', minutes: 60, message: 'x'.repeat(301) }), /capped at 300/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('seasonal: the description carries the warnings the decision asks for', () => {
|
||||||
|
const { description } = byId('uo.template.seasonal')
|
||||||
|
assert.match(description, /back off by itself|puts the old one back/)
|
||||||
|
assert.match(description, /six of the eight/i)
|
||||||
|
assert.match(description, /12 hours/)
|
||||||
|
})
|
||||||
|
|
||||||
|
// ── Gathering giveaway ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const GIVEAWAY = { place: 'Felucca/Britain', minutes: 30, item: 'gold' }
|
||||||
|
|
||||||
|
test('giveaway: two phases — gather (held), then reward — with defaults applied', () => {
|
||||||
|
const built = build('uo.template.gathering_giveaway', GIVEAWAY)
|
||||||
|
assert.strictEqual(built.spec.phases.length, 2)
|
||||||
|
const [gather, reward] = built.spec.phases
|
||||||
|
|
||||||
|
assert.strictEqual(gather.key, 'gather')
|
||||||
|
assert.deepStrictEqual(gather.advance, { after: '30m' })
|
||||||
|
assert.deepStrictEqual(stepIds(gather), ['uo.broadcast', 'uo.participation.open'])
|
||||||
|
assert.deepStrictEqual(gather.steps[0].params, { text: 'Gather near Britain in the next 30 minutes for a gift!' })
|
||||||
|
assert.deepStrictEqual(gather.steps[1].params, { place: 'Felucca/Britain', radius: 40 })
|
||||||
|
|
||||||
|
assert.strictEqual(reward.key, 'reward')
|
||||||
|
assert.strictEqual(reward.advance, undefined)
|
||||||
|
assert.deepStrictEqual(stepIds(reward), ['uo.participation.collect', 'uo.item.grant', 'uo.broadcast'])
|
||||||
|
assert.deepStrictEqual(reward.steps[0].params, {})
|
||||||
|
assert.deepStrictEqual(reward.steps[1].params, { item: 'gold', amount: 1 })
|
||||||
|
assert.deepStrictEqual(reward.steps[2].params, { text: 'Thank you for coming — gifts are in your backpacks.' })
|
||||||
|
|
||||||
|
assert.strictEqual(built.title, 'Gathering giveaway at Felucca/Britain for 30 minutes')
|
||||||
|
assert.match(built.summary, /Gifts cannot be taken back\.$/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('giveaway: amount, radius and message are carried', () => {
|
||||||
|
const built = build('uo.template.gathering_giveaway', { ...GIVEAWAY, amount: 500, radius: 100, message: 'Come on down' })
|
||||||
|
const [gather, reward] = built.spec.phases
|
||||||
|
assert.deepStrictEqual(gather.steps[0].params, { text: 'Come on down' })
|
||||||
|
assert.deepStrictEqual(gather.steps[1].params, { place: 'Felucca/Britain', radius: 100 })
|
||||||
|
assert.deepStrictEqual(reward.steps[1].params, { item: 'gold', amount: 500 })
|
||||||
|
assert.match(built.summary, /500 gold each/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('giveaway: a long window reads in hours in the default message', () => {
|
||||||
|
const [gather] = build('uo.template.gathering_giveaway', { ...GIVEAWAY, minutes: 120 }).spec.phases
|
||||||
|
assert.match(gather.steps[0].params.text, /in the next 2 hours for a gift!$/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('giveaway: a non-stackable item is one each, and says why when asked for more', () => {
|
||||||
|
const ok = build('uo.template.gathering_giveaway', { ...GIVEAWAY, item: 'cloak', amount: 1 })
|
||||||
|
assert.deepStrictEqual(ok.spec.phases[1].steps[1].params, { item: 'cloak', amount: 1 })
|
||||||
|
refused(build('uo.template.gathering_giveaway', { ...GIVEAWAY, item: 'cloak', amount: 2 }), /does not stack/)
|
||||||
|
// Every non-stackable on the allowlist behaves the same; gold alone stacks.
|
||||||
|
for (const g of actions.GRANTABLE) {
|
||||||
|
const result = build('uo.template.gathering_giveaway', { ...GIVEAWAY, item: g.key, amount: 2 })
|
||||||
|
if (g.stackable) assert.ok(!('ok' in result), g.key)
|
||||||
|
else refused(result, /does not stack/)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test('giveaway: refusals are sentences', () => {
|
||||||
|
refused(build('uo.template.gathering_giveaway', { ...GIVEAWAY, place: 'nowhere' }), /not a place/)
|
||||||
|
refused(build('uo.template.gathering_giveaway', { ...GIVEAWAY, minutes: -5 }), /1 to \d+ minutes/)
|
||||||
|
refused(build('uo.template.gathering_giveaway', { ...GIVEAWAY, item: 'dragon' }), /does not give out "dragon"/)
|
||||||
|
refused(build('uo.template.gathering_giveaway', { ...GIVEAWAY, amount: 0 }), /1 to 1000 each/)
|
||||||
|
refused(build('uo.template.gathering_giveaway', { ...GIVEAWAY, amount: actions.MAX_GRANT_STACK + 1 }), /1 to 1000 each/)
|
||||||
|
assert.ok(!('ok' in build('uo.template.gathering_giveaway', { ...GIVEAWAY, amount: actions.MAX_GRANT_STACK })))
|
||||||
|
refused(build('uo.template.gathering_giveaway', { ...GIVEAWAY, radius: 0 }), /1 to 300 tiles/)
|
||||||
|
refused(build('uo.template.gathering_giveaway', { ...GIVEAWAY, radius: actions.MAX_AREA_RADIUS + 1 }), /1 to 300 tiles/)
|
||||||
|
assert.ok(!('ok' in build('uo.template.gathering_giveaway', { ...GIVEAWAY, radius: actions.MAX_AREA_RADIUS })))
|
||||||
|
refused(build('uo.template.gathering_giveaway', { ...GIVEAWAY, message: 'x'.repeat(301) }), /capped at 300/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('giveaway: the description says who gets it and that it cannot be undone', () => {
|
||||||
|
const { description } = byId('uo.template.gathering_giveaway')
|
||||||
|
assert.match(description, /everyone the shard counted/)
|
||||||
|
assert.match(description, /cannot be taken back/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('boss raid: the description says boss spawning must be on and the boss is cleared at the end', () => {
|
||||||
|
const { description } = byId('uo.template.boss_raid')
|
||||||
|
assert.match(description, /switched on/)
|
||||||
|
assert.match(description, /cleared when the run ends/)
|
||||||
|
})
|
||||||
|
|
||||||
|
// ── No shard calls ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
test('build() makes no sidecar call and reads no database', async () => {
|
||||||
|
const link = require('../utils/uoLinkClient')
|
||||||
|
const atlas = require('../model/shardAtlas/shardAtlas.model')
|
||||||
|
const real = {}
|
||||||
|
const touched = []
|
||||||
|
// Every function either module exposes is replaced by one that records the call.
|
||||||
|
for (const [name, mod] of [['uoLinkClient', link], ['shardAtlas', atlas]]) {
|
||||||
|
for (const key of Object.keys(mod)) {
|
||||||
|
if (typeof mod[key] !== 'function') continue
|
||||||
|
real[`${name}.${key}`] = mod[key]
|
||||||
|
mod[key] = (...args) => { touched.push(`${name}.${key}`); return Promise.resolve({ ok: false }) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await build('uo.template.boss_raid', RAID)
|
||||||
|
await build('uo.template.seasonal', { event: 'Fellowship', minutes: 60 })
|
||||||
|
await build('uo.template.gathering_giveaway', GIVEAWAY)
|
||||||
|
await build('uo.template.announce', { text: 'Hi', newsTitle: 'T' })
|
||||||
|
} finally {
|
||||||
|
for (const [full, fn] of Object.entries(real)) {
|
||||||
|
const [name, key] = full.split('.')
|
||||||
|
;(name === 'uoLinkClient' ? link : atlas)[key] = fn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert.deepStrictEqual(touched, [])
|
||||||
|
})
|
||||||
@@ -61,7 +61,6 @@ function stubEverything({ manifest, fetched, held = new Map(), meta = null, sour
|
|||||||
extractorVersion: 1,
|
extractorVersion: 1,
|
||||||
hashing: false,
|
hashing: false,
|
||||||
complete: true,
|
complete: true,
|
||||||
imaging: { ok: true },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bridge.readManifest = async () => manifest
|
bridge.readManifest = async () => manifest
|
||||||
@@ -162,7 +161,6 @@ test('unchanged client files import nothing at all', async (t) => {
|
|||||||
extractorVersion: 1,
|
extractorVersion: 1,
|
||||||
hashing: false,
|
hashing: false,
|
||||||
complete: true,
|
complete: true,
|
||||||
imaging: { ok: true },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stubEverything({ manifest: manifestOf([]), meta: { sources }, sources })
|
stubEverything({ manifest: manifestOf([]), meta: { sources }, sources })
|
||||||
@@ -177,27 +175,6 @@ test('unchanged client files import nothing at all', async (t) => {
|
|||||||
assert.equal(result.status, 'unchanged')
|
assert.equal(result.status, 'unchanged')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('a host that cannot render images is named rather than walked', async (t) => {
|
|
||||||
// §4.4: reported on the SOURCE gate, so an operator meets it while setting the
|
|
||||||
// shard up rather than from an empty bestiary weeks later.
|
|
||||||
stubEverything({
|
|
||||||
manifest: manifestOf([]),
|
|
||||||
sources: {
|
|
||||||
files: {},
|
|
||||||
extractorVersion: 1,
|
|
||||||
hashing: false,
|
|
||||||
complete: true,
|
|
||||||
imaging: { ok: false, code: 'NO_IMAGING', reason: 'needs libgdiplus' },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
t.after(restore)
|
|
||||||
|
|
||||||
const result = await model.importAssets()
|
|
||||||
|
|
||||||
assert.equal(result.status, 'unavailable')
|
|
||||||
assert.equal(result.code, 'NO_IMAGING')
|
|
||||||
})
|
|
||||||
|
|
||||||
// ── the diff (§6) ─────────────────────────────────────────────────────────
|
// ── the diff (§6) ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
test('only the keys whose hash moved are fetched', async (t) => {
|
test('only the keys whose hash moved are fetched', async (t) => {
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ function stub({
|
|||||||
extractorVersion: 2,
|
extractorVersion: 2,
|
||||||
hashing: false,
|
hashing: false,
|
||||||
complete: true,
|
complete: true,
|
||||||
imaging: { ok: true },
|
|
||||||
families,
|
families,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -178,25 +177,6 @@ test('no shard link is skipped, not failed', async (t) => {
|
|||||||
assert.equal((await model.warm()).status, 'skipped')
|
assert.equal((await model.warm()).status, 'skipped')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('a host that cannot render images is the named NO_IMAGING state', async (t) => {
|
|
||||||
stub()
|
|
||||||
t.after(restore)
|
|
||||||
|
|
||||||
bridge.sourceFingerprint = async () => ({
|
|
||||||
files: {},
|
|
||||||
extractorVersion: 2,
|
|
||||||
hashing: false,
|
|
||||||
complete: true,
|
|
||||||
imaging: { ok: false, reason: 'libgdiplus is not installed' },
|
|
||||||
families: ['body', 'static'],
|
|
||||||
})
|
|
||||||
|
|
||||||
const result = await model.warm()
|
|
||||||
|
|
||||||
assert.equal(result.status, 'unavailable')
|
|
||||||
assert.equal(result.code, 'NO_IMAGING')
|
|
||||||
})
|
|
||||||
|
|
||||||
// ── what gets asked for ────────────────────────────────────────────────────
|
// ── what gets asked for ────────────────────────────────────────────────────
|
||||||
|
|
||||||
test('only the keys we do not already hold under the shard’s current catalogue are fetched', async (t) => {
|
test('only the keys we do not already hold under the shard’s current catalogue are fetched', async (t) => {
|
||||||
|
|||||||
@@ -317,7 +317,6 @@ test('a tree-only shard tells the client-file readers so, rather than looking em
|
|||||||
extractorVersion: 3,
|
extractorVersion: 3,
|
||||||
assetsEnabled: false,
|
assetsEnabled: false,
|
||||||
treeEnabled: true,
|
treeEnabled: true,
|
||||||
imaging: { ok: true },
|
|
||||||
families: ['tree'],
|
families: ['tree'],
|
||||||
files: [],
|
files: [],
|
||||||
more: false,
|
more: false,
|
||||||
|
|||||||
@@ -118,11 +118,7 @@ function describeFailure(res, what) {
|
|||||||
'BUSY',
|
'BUSY',
|
||||||
)
|
)
|
||||||
case 503:
|
case 503:
|
||||||
// The named `NO_IMAGING` outcome arrives this way: a Linux shard host with
|
return new AssetBridgeError(reason, 'SHARD_DOWN')
|
||||||
// no libgdiplus cannot render a sprite at all, and §4.4 requires that be an
|
|
||||||
// actionable sentence rather than a stack trace. The shard's own wording
|
|
||||||
// already names the package and the command, so it is passed through.
|
|
||||||
return new AssetBridgeError(reason, /libgdiplus/i.test(reason) ? 'NO_IMAGING' : 'SHARD_DOWN')
|
|
||||||
case 504:
|
case 504:
|
||||||
return new AssetBridgeError(`The shard did not answer: ${reason}`, 'SHARD_DOWN')
|
return new AssetBridgeError(`The shard did not answer: ${reason}`, 'SHARD_DOWN')
|
||||||
default:
|
default:
|
||||||
@@ -214,7 +210,7 @@ const SOURCE_FILES = [
|
|||||||
* Stage 1 of the import gate (§6): have the client files this family reads
|
* Stage 1 of the import gate (§6): have the client files this family reads
|
||||||
* changed at all?
|
* changed at all?
|
||||||
*
|
*
|
||||||
* Returns `{ files, extractorVersion, hashing, complete, imaging }` where `files`
|
* Returns `{ files, extractorVersion, hashing, complete, families }` where `files`
|
||||||
* is a `{ name: { size, mtime, sha256 } }` map over `SOURCE_FILES` — a file the
|
* is a `{ name: { size, mtime, sha256 } }` map over `SOURCE_FILES` — a file the
|
||||||
* shard does not have is simply absent, which is normal (few clients carry all
|
* shard does not have is simply absent, which is normal (few clients carry all
|
||||||
* five anim files).
|
* five anim files).
|
||||||
@@ -260,7 +256,6 @@ async function sourceFingerprint() {
|
|||||||
extractorVersion: Number(res.data?.extractorVersion) || 0,
|
extractorVersion: Number(res.data?.extractorVersion) || 0,
|
||||||
hashing: Boolean(res.data?.hashing),
|
hashing: Boolean(res.data?.hashing),
|
||||||
complete: Boolean(res.data?.complete),
|
complete: Boolean(res.data?.complete),
|
||||||
imaging: res.data?.imaging ?? null,
|
|
||||||
// Which §5 key families this overlay can be asked for (phase 5). Absent on a
|
// Which §5 key families this overlay can be asked for (phase 5). Absent on a
|
||||||
// phase-3 or phase-4 overlay, which served bodies and nothing else — so the
|
// phase-3 or phase-4 overlay, which served bodies and nothing else — so the
|
||||||
// fallback is `['body']` rather than `[]`: an older shard is not a shard with
|
// fallback is `['body']` rather than `[]`: an older shard is not a shard with
|
||||||
|
|||||||
@@ -116,7 +116,7 @@
|
|||||||
"Admin · Shard"
|
"Admin · Shard"
|
||||||
],
|
],
|
||||||
"summary": "Client asset import status: what is loaded, what the shard has, whether they differ (admin only)",
|
"summary": "Client asset import status: what is loaded, what the shard has, whether they differ (admin only)",
|
||||||
"description": "What the site currently holds (the imported body catalogue, how many sprites are stored, how many atlas creatures resolved to a body id) beside what the shard reports for the client files those pictures come from. `drift: true` means the client files have changed since the last import — press Import. `shard.hashing: true` means a null hash is “not computed yet”, not “changed”: the shard hashes 195 MB anim files off the request path. `shard.imaging.ok: false` is the named NO_IMAGING state — a Linux shard host without libgdiplus cannot render a sprite at all, and the reason names the package to install. A shard with no link configured, or one that is down, is a reported state with a reason rather than an error.",
|
"description": "What the site currently holds (the imported body catalogue, how many sprites are stored, how many atlas creatures resolved to a body id) beside what the shard reports for the client files those pictures come from. `drift: true` means the client files have changed since the last import — press Import. `shard.hashing: true` means a null hash is “not computed yet”, not “changed”: the shard hashes 195 MB anim files off the request path. A shard with no link configured, or one that is down, is a reported state with a reason rather than an error.",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Asset import status",
|
"description": "Asset import status",
|
||||||
@@ -9007,68 +9007,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"imaging": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"type": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "object"
|
|
||||||
},
|
|
||||||
"nullable": {
|
|
||||||
"type": "boolean",
|
|
||||||
"example": true
|
|
||||||
},
|
|
||||||
"description": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "Whether the shard host can render an image at all. `ok: false` is the named NO_IMAGING state: ServUO under Mono needs libgdiplus, and without it a Linux shard cannot decode a sprite. Cliloc and atlas import are unaffected."
|
|
||||||
},
|
|
||||||
"properties": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"ok": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"type": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "boolean"
|
|
||||||
},
|
|
||||||
"example": {
|
|
||||||
"type": "boolean",
|
|
||||||
"example": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"code": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"type": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "string"
|
|
||||||
},
|
|
||||||
"nullable": {
|
|
||||||
"type": "boolean",
|
|
||||||
"example": true
|
|
||||||
},
|
|
||||||
"example": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"reason": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"type": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "string"
|
|
||||||
},
|
|
||||||
"nullable": {
|
|
||||||
"type": "boolean",
|
|
||||||
"example": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"families": {
|
"families": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -9167,7 +9105,6 @@
|
|||||||
"SHARD_DOWN",
|
"SHARD_DOWN",
|
||||||
"PROTOCOL",
|
"PROTOCOL",
|
||||||
"BUSY",
|
"BUSY",
|
||||||
"NO_IMAGING",
|
|
||||||
"SOURCE_CHANGED",
|
"SOURCE_CHANGED",
|
||||||
"UNAVAILABLE"
|
"UNAVAILABLE"
|
||||||
],
|
],
|
||||||
@@ -9190,7 +9127,7 @@
|
|||||||
},
|
},
|
||||||
"description": {
|
"description": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "Outcome of an asset import. Reported rather than thrown, so a shard that is down or a host that cannot render images is an answer and not a 500."
|
"example": "Outcome of an asset import. Reported rather than thrown, so a shard that is down is an answer and not a 500."
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
@@ -9252,7 +9189,7 @@
|
|||||||
},
|
},
|
||||||
"description": {
|
"description": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "Machine-readable cause. `NO_IMAGING` is a shard host with no libgdiplus; `SOURCE_CHANGED` is a client patched partway through the walk, in which case nothing was applied."
|
"example": "Machine-readable cause. `SOURCE_CHANGED` is a client patched partway through the walk, in which case nothing was applied."
|
||||||
},
|
},
|
||||||
"enum": {
|
"enum": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
@@ -9262,7 +9199,6 @@
|
|||||||
"SHARD_DOWN",
|
"SHARD_DOWN",
|
||||||
"PROTOCOL",
|
"PROTOCOL",
|
||||||
"BUSY",
|
"BUSY",
|
||||||
"NO_IMAGING",
|
|
||||||
"SOURCE_CHANGED",
|
"SOURCE_CHANGED",
|
||||||
"INCOMPLETE",
|
"INCOMPLETE",
|
||||||
"STUCK",
|
"STUCK",
|
||||||
@@ -9906,7 +9842,7 @@
|
|||||||
},
|
},
|
||||||
"description": {
|
"description": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "Machine-readable cause. `NO_IMAGING` is a shard host with no libgdiplus. `UNSUPPORTED` is a plugin overlay that serves the creature catalogue but not item art — update the overlay."
|
"example": "Machine-readable cause. `UNSUPPORTED` is a plugin overlay that serves the creature catalogue but not item art — update the overlay."
|
||||||
},
|
},
|
||||||
"enum": {
|
"enum": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
@@ -9916,7 +9852,6 @@
|
|||||||
"SHARD_DOWN",
|
"SHARD_DOWN",
|
||||||
"PROTOCOL",
|
"PROTOCOL",
|
||||||
"BUSY",
|
"BUSY",
|
||||||
"NO_IMAGING",
|
|
||||||
"UNSUPPORTED",
|
"UNSUPPORTED",
|
||||||
"INCOMPLETE",
|
"INCOMPLETE",
|
||||||
"STUCK",
|
"STUCK",
|
||||||
|
|||||||
Reference in New Issue
Block a user