169 lines
9.2 KiB
Markdown
169 lines
9.2 KiB
Markdown
# Locker Sync Contract
|
|
|
|
Binding contract for limited-arsenal storage sync between the Arma 3 mods and
|
|
the web app. It covers **personal lockers** (web `locker-storages`, one per
|
|
member) and **structure item storage** (web `game-structures.storedAssets`,
|
|
e.g. the Superstructure). Implement exactly what is written here; do not
|
|
redesign while implementing.
|
|
|
|
## Overview
|
|
|
|
In-game, each storage is a limited ACE Arsenal: every item class has a finite
|
|
quantity. The game server is authoritative for what a player physically takes
|
|
or deposits in a session; the web app is authoritative for everything outside
|
|
the session (member UI edits, admin edits, future crafting/market flows). Two
|
|
existing bridge channels carry the data; **no new extension channels** (same
|
|
precedent as crate sync — the Python module is closed):
|
|
|
|
- **Events (mod to web)**: the `locker.*` event family, delivered through the
|
|
existing `flush_events` ingestion (`POST /api/arma/v1/events`).
|
|
- **Commands (web to mod)**: the `locker.*` command types, delivered through
|
|
the existing `pull_commands` / `ack_command` loop.
|
|
|
|
## Instance identity
|
|
|
|
An `instanceRef` string identifies one storage:
|
|
|
|
| Form | Meaning |
|
|
|---|---|
|
|
| `personal:<steamId>` | The personal locker of the member whose `users.steamId` matches. |
|
|
| `structure:<storageSlug>` | The `storedAssets` of the `game-structures` row with this `storageSlug` (e.g. `structure:superstructure`). |
|
|
|
|
- The mod NEVER embeds a server identifier in an instanceRef. The web resolves
|
|
the owning server authoritatively from the authenticated connection
|
|
(`eventId = ${serverId}:${event.id}`), exactly as in crate sync.
|
|
- `personal:` refs are derived from the opening player's UID at open time; the
|
|
same physical locker box serves every player with their own stock.
|
|
- `structure:` refs are bound to boxes by the TWWK Eden/Zeus module
|
|
(`StructureStorageSlug` argument). Only structures with a `storageSlug`
|
|
expose item storage to the game.
|
|
|
|
## Event family
|
|
|
|
Payloads are flat arrays (`fn_queueEvent` stores `[_id, _type, _payload,
|
|
serverTime]`, payload defaults to `[]`).
|
|
|
|
| Type | Payload | Meaning |
|
|
|---|---|---|
|
|
| `locker.sync` | `[instanceRef, [[itemClass, count], ...]]` | Full stock snapshot for one instance after a committed change. |
|
|
| `locker.seed` | `[instanceRef, [[itemClass, count], ...]]` | Create-only first-bind seed. Applied only when the web has no document (personal) or no `storedAssets` yet (structure); never overwrites existing web state. |
|
|
| `locker.request` | `[instanceRef]` | The game asks the web to push current state for this instance (mission start, player connect, availability refresh). |
|
|
|
|
`locker.sync` snapshot rules:
|
|
|
|
- TOP-LEVEL stock only: `[itemClass, count]` pairs, one per class. Counts are
|
|
integers >= 0, or `-1` for an Antistasi-style **unlimited** entry. Classes
|
|
with count 0 MAY be included (explicit depletion) or omitted (treated as
|
|
unknown/absent, not as zero — see merge rules).
|
|
- Emitted after every committed stock mutation (take settlement, deposit,
|
|
Zeus/Eden edit, `locker.apply` application) while the bridge is enabled.
|
|
- Dedup is web-side by `eventId`; retried flushes never double-apply.
|
|
Snapshots are idempotent wholesale state, so re-application is safe.
|
|
|
|
## Web-side consumption rules
|
|
|
|
`locker.sync` merges into the instance's item array keyed by Arma class name:
|
|
|
|
- `personal:<steamId>`: resolve `users.steamId` → that user's `locker-storages`
|
|
row (created lazily if a linked user has none). Unlinked Steam IDs are
|
|
logged and skipped (same rule as money sync); the game keeps a session-only
|
|
stock for them.
|
|
- `structure:<storageSlug>`: resolve the `game-structures` row by `storageSlug`.
|
|
Unknown slug is logged and skipped.
|
|
- Merge per entry by `asset.className`:
|
|
- Existing web entry whose class appears in the snapshot → `quantity` set to
|
|
the snapshot count (or `1` with `unlimited = true` for `-1`). **All
|
|
web-managed metadata is preserved**: `gridX`, `gridY`, `rotated`, and the
|
|
`equipment` group (attachments, skin, customName) are never touched by the
|
|
merge.
|
|
- Snapshot class with no web entry → create the entry (asset resolved by
|
|
`className`; unknown classes are skipped with a warning) and **auto-place**
|
|
it in the next free grid cell (row-major scan, unrotated). Equipment left
|
|
empty.
|
|
- Web entry whose class is absent from the snapshot → left untouched
|
|
(absence is not deletion; the game only reports classes it tracks).
|
|
- `itemCount` keeps deriving from the array length via its existing hook.
|
|
- Every merged write links the raw `arma-sync-events` row as provenance where
|
|
the storage model supports it.
|
|
|
|
`locker.request` handling:
|
|
|
|
- Enqueue exactly one `locker.apply` command for the requesting server with
|
|
the web's current full snapshot for that instanceRef. Unknown/unlinked
|
|
instanceRefs enqueue nothing.
|
|
- **No-wipe rule**: a linked Steam ID with no `locker-storages` document, and
|
|
an unknown structure slug, are both "unknown" → nothing is enqueued. An
|
|
empty snapshot is only sent for a document that actually exists and is empty.
|
|
The game therefore keeps its local `profileNamespace` stock until the web
|
|
has a real snapshot to apply.
|
|
|
|
## Command envelope and schemas
|
|
|
|
Envelope: `[commandId, commandType, payload]` (what `fn_pollCommands` passes
|
|
and `fn_executeCommand` destructures), stored in `arma-commands`.
|
|
|
|
| Type | Payload | Effect |
|
|
|---|---|---|
|
|
| `locker.apply` | `[instanceRef, [[itemClass, count], ...]]` | Server replaces the instance's stock wholesale with the given pairs, pushes availability to clients, and acks. `-1` means unlimited. |
|
|
|
|
- The web enqueues `locker.apply` when: (a) a member/admin edits locker items
|
|
or structure `storedAssets` in the UI (afterChange hook), or (b) a
|
|
`locker.request` event arrives. Target server: the most recently heartbeated
|
|
game server (single-server assumption, same as crate UI flows).
|
|
- The mod-side handler is registered through the bridge's command-handler
|
|
registry (`ptf_bridge_fnc_registerCommandHandler`); the bridge mod itself
|
|
stays storage-agnostic.
|
|
- Unknown instanceRef → the mod acks FAILED with an error string; the command
|
|
is marked `failed` web-side and is not retried by the mod.
|
|
- Ack shape is the existing `[commandId, success, result, error]`; successful
|
|
acks carry the applied instanceRef in `result` for traceability.
|
|
- Echo guard: web writes that originate from a `locker.sync` merge mark
|
|
`req.context.lockerSyncOrigin = true`; the afterChange enqueue hook skips
|
|
such writes so a game-originated change never bounces back as a command.
|
|
|
|
## Failure rules
|
|
|
|
- Web event processors never throw: malformed payloads are logged and skipped;
|
|
one bad event never aborts the batch or rolls back raw-event ingestion.
|
|
- Duplicate eventIds are deduped (counted as duplicates, no double-apply).
|
|
- Bridge disabled/unreachable: the mod keeps its local stock AND persists it
|
|
to `profileNamespace` (per world, key `twwk_arsenal_store_<world>`, written by
|
|
a debounced saver and at mission end). The store survives mission restarts on
|
|
the same server with the bridge off. Queued `locker.sync` events flush when
|
|
the bridge returns (queue cap drops oldest, per existing bridge behavior).
|
|
- On mission start the mod loads the local store first, then emits
|
|
`locker.request` for every bound structure instance and per connecting
|
|
player; the web replies with `locker.apply` only when it has a document to
|
|
apply (no-wipe rule).
|
|
- New storage instances seed once: `cargo` turns the bound crate's Eden cargo
|
|
into stock and clears the crate; `custom` parses `class:count` pairs;
|
|
`none` starts empty. Personal lockers always start empty (per player) and
|
|
are created on first access.
|
|
|
|
## Security
|
|
|
|
- All channels sit behind `requireArmaServer` (`ARMA_BRIDGE_API_KEY` +
|
|
`x-arma-server-id`); server identity is always derived from the connection.
|
|
- The `storageAccess` group on `game-structures` (anyone / faction / roles /
|
|
users) governs **web UI** visibility/editing of `storedAssets` only; it does
|
|
not constrain the bridge (server-to-server) or in-game physical access.
|
|
|
|
## Mod-side behavior (TWWK `twwk_arsenal`)
|
|
|
|
- Server store: `instanceRef → (className → count)` in missionNamespace, backed
|
|
by the per-world `profileNamespace` store. `-1` is unlimited.
|
|
- Module binding: the Eden/Zeus "Limited Arsenal Storage" module binds the crate
|
|
it is placed on (or synced to) — `attachedTo` → `synchronizedObjects` → a
|
|
downward ray through the module → nearest object within 2.5 m. Eden applies
|
|
its Attributes at mission start; Zeus opens the bind window on placement and
|
|
on double-click.
|
|
- Availability: a class is in the ACE Arsenal virtual-item set iff count != 0
|
|
(shared instances: global `addVirtualItems`/`removeVirtualItems`; personal:
|
|
targeted per-player local set). Zero-stock classes are hidden.
|
|
- Count display: `[xN]` / `[∞]` in the left list's right column, a "Storage"
|
|
stat in the item panel, and a "Stock (high to low)" sort. Unlimited sorts
|
|
above finite stacks.
|
|
- Settlement: client snapshots gear on `ace_arsenal_displayOpened`, diffs on
|
|
`ace_arsenal_displayClosed`, server validates/clamps and commits; live
|
|
over-take into containers is clamped per `ace_arsenal_cargoChanged`.
|
|
- Deposits run through the same commit path with the sign flipped.
|