# AnimStream Originals — local game protocol 1

This is the normative reference for the WebSocket protocol between AnimStream
Studio and a native Originals game. The Godot, Unity and Unreal SDKs implement it;
a custom client must follow it exactly. Everything added after the first release
is optional, so games built against the first SDK keep working unchanged.

- Transport: one WebSocket text connection to `ws://127.0.0.1:<port>/v1`.
- Encoding: UTF-8 JSON objects, one message per frame, at most 64 KiB per frame.
- Times: Unix milliseconds. IDs: 1–128 characters unless stated otherwise.
- Every message carries `type` and `sessionId`. A frame with another session ID,
  invalid JSON, a binary frame or an oversized frame ends the session.

## 1. Compatibility rules

| Rule | Why |
|------|-----|
| `protocol` stays `1`. New fields are optional. | Old games run unchanged. |
| Clients ignore unknown fields in any Studio message. | Studio may add optional fields. |
| Studio never sends a new message type unprompted. `response` answers a client `request`; `notify` follows only a successful `bindings.list`. | Old clients stop on unknown message types. |
| A client sends `state` or `request` only if `ready.features` lists the capability. | Studio 0.1.285 and older omit `features` and close the session on unknown messages. |
| Manifest extensions reach only Studio versions that announce them. Older Studio versions receive the base manifest without `stackable`, `defaultBindings`, `presets`, action `image`, `leaderboard` and `giftWall` (`giftWall.sort` `preset` arrives as `manifest` without `presets`). Without the `action-effects` extension they receive it without action `effect` and `giftWall.split` — byte-identical to the manifest of a build that never had them. | Older Studio versions reject unknown manifest keys. |

A game must therefore work without stacking, default rules, presets, a
configured Gift Wall, state reporting and leaderboards. It only loses those conveniences on an old Studio.

## 2. Launch

Studio starts the reviewed entrypoint with these environment variables. They are
the only credentials a game receives:

| Variable | Meaning |
|----------|---------|
| `ANIMSTREAM_GAME_ID` | Immutable game ID (`^[a-z0-9][a-z0-9-]{0,95}$`) |
| `ANIMSTREAM_BUILD_ID` | Build ID of this exact release |
| `ANIMSTREAM_SESSION_ID` | ID of this launch session |
| `ANIMSTREAM_GAME_URL` | `ws://127.0.0.1:<ephemeral-port>/v1` |
| `ANIMSTREAM_GAME_TOKEN` | Random one-launch token (`^[A-Za-z0-9_-]{32,256}$`) |

The token is not an account token or the cloud lease secret. Never log, persist,
display or put it on a command line. Without valid variables the game was not
started by Studio: the SDKs stop with `launch_required`.

## 3. Session lifecycle

1. The client connects and sends `hello` within 8 seconds.
2. Studio answers `ready` with the reviewed manifest. Only then may gameplay
   accept stream input.
3. Studio sends `ping` every 2 seconds; the client answers `pong`. After 8 seconds
   without a ping the client stops (`heartbeat_lost`).
4. Studio renews the 90-second cloud lease every 30 seconds and relays each
   renewal as `lease`. At `leaseExpiresAt` the client stops (`lease_expired`).
5. `stop`, a closed socket or any protocol violation ends the session. Default
   SDK behavior quits the game. Custom pause behavior must gate all gameplay and
   never resume a dead session. There is no reconnect and no replay.

Exactly one connection is accepted per launch. If a bundled helper process speaks
the protocol instead of the entrypoint, the entrypoint must not connect as well.

## 4. Messages from Studio

### `ready`

```json
{ "type": "ready", "protocol": 1, "sessionId": "…", "leaseExpiresAt": 1767225600000,
  "heartbeatMs": 2000, "manifest": { "schemaVersion": 1, "gameId": "zombie-prank" },
  "features": ["source", "stack", "state", "leaderboard", "bindings", "leaderboard-avatars"],
  "session": { "language": "de", "streamerHandle": "streamer_name" } }
```

| Field | Type | Notes |
|-------|------|-------|
| `manifest` | object | The reviewed manifest (section 7). The game cannot replace it. |
| `features` | string[]? | Optional. Absent on Studio 0.1.285 and older. Values: `source` (actions carry `source`), `stack` (Studio merges stackable actions), `state` (client may send `state`), `leaderboard` (client may request `leaderboard.*`), `bindings` (client may request `bindings.list`), `leaderboard-avatars` (`leaderboard.top` entries carry `avatarUrl`, section 8). Ignore unknown values. |
| `session.language` | `"de"` \| `"en"` | Optional. Studio UI language. |
| `session.streamerHandle` | string? | Optional TikTok username without `@`: 2–24 characters `[A-Za-z0-9._]`. Present only if the streamer allowed sharing it in Studio. Display data, not an authentication factor. |

### `ping` / `lease` / `cancel` / `stop`

```json
{ "type": "ping",   "sessionId": "…", "at": 1767225600000 }
{ "type": "lease",  "sessionId": "…", "expiresAt": 1767225690000 }
{ "type": "cancel", "sessionId": "…", "id": "<action id>" }
{ "type": "stop",   "sessionId": "…", "reason": "originals-cancelled" }
```

`cancel` asks the game to stop the pending effects of one action. `stop` ends the
session.

### `action`

```json
{ "type": "action", "sessionId": "…", "id": "5b0c…", "actionId": "spawn-zombies",
  "params": { "count": 99 }, "expiresAt": 1767225603000, "dryRun": false,
  "viewer": { "name": "Viewer Name", "handle": "viewer_handle" },
  "source": { "code": "GIFT", "giftId": "5655", "giftName": "Rose", "giftCoins": 1, "giftCount": 99 } }
```

| Field | Type | Notes |
|-------|------|-------|
| `id` | string | Unique request ID. Execute each ID at most once, also after acknowledging it. Ignore a repeated ID silently: no second execution and no second `action-result`. |
| `actionId` | string | An action ID from the manifest. Unknown IDs: reply `rejected`. |
| `params` | object | Primitive values. Validate them against the manifest again; reject unknown keys. |
| `expiresAt` | number | The game rejects a command that arrives after `expiresAt` or more than 15 s in the future. Expired pending work is cancelled. |
| `dryRun` | boolean | Validate and reply `simulated` without calling gameplay code. |
| `viewer` | object? | The viewer who triggered the rule: `name` (≤ 80 chars, display name) and optional `handle` (≤ 80 chars). |
| `source` | object? | Optional (feature `source`). `code` is the triggering event code (`GIFT`, `COMMENT`, `FOLLOW`, …, `HOTKEY` for Studio tests). Gift fields are present for gifts: `giftId` and `giftName` (≤ 160 chars), `giftCoins` (coins per gift), `giftCount` (gifts this action represents; summed when stacked). |

Viewer and gift strings are untrusted display data. Never interpret them as code,
commands, paths or markup.

### `event`

Raw normalized stream events for the event codes the manifest lists in `events`.

```json
{ "type": "event", "sessionId": "…", "id": "9f2e…",
  "event": { "code": "GIFT", "platform": "tiktok", "ts": 1767225600000, "user": "Viewer Name",
             "handle": "viewer_handle", "giftName": "Rose", "giftId": "5655", "giftCount": 5, "giftCoins": 1 } }
```

| Field | Type | Notes |
|-------|------|-------|
| `event.code` | string | Uppercase normalized code (`GIFT`, `LIKE`, `COMMENT`, `FOLLOW`, `SHARE`, `JOIN`, `SUBSCRIBE`, …). |
| `event.platform` | string | `tiktok`, `twitch`, … |
| `event.ts` | number | Event time. Clients ignore events more than 60 s away from their clock. |
| `event.user` | string | Display name (≤ 80 chars). |
| `event.handle`, `giftName`, `giftId` | string? | ≤ 160 chars. |
| `event.comment` | string? | ≤ 1000 chars. |
| `event.giftCount`, `giftCoins` | number? | Finite numbers. |

> **Avoid double triggering.** A gift can reach the game twice: as a raw `event`
> and as an `action` from a Studio gift rule. Use gift rules (actions) for
> gameplay effects — they are streamer-configurable, stackable, shown on the Gift
> Wall and editable in Studio's game control window. Use raw events only for effects that no
> gift rule produces, such as a gift ticker or ambient reactions.

### `response` and `notify`

`response` answers exactly one client `request`. `notify` with topic `bindings`
tells a client that has successfully requested `bindings.list` that the gift
rules changed; request the list again.

```json
{ "type": "response", "sessionId": "…", "id": "req-3", "ok": true, "data": { } }
{ "type": "response", "sessionId": "…", "id": "req-4", "ok": false, "error": "rate_limited" }
{ "type": "notify",   "sessionId": "…", "topic": "bindings" }
```

## 5. Messages from the game

### `hello`

```json
{ "type": "hello", "protocol": 1, "gameId": "…", "buildId": "…", "sessionId": "…", "token": "…" }
```

Exactly these keys. Send once, then forget the token.

### `pong`

```json
{ "type": "pong", "sessionId": "…", "at": 1767225600000 }
```

Echo the `at` value of the ping.

### `action-result`

```json
{ "type": "action-result", "sessionId": "…", "id": "5b0c…", "status": "completed" }
{ "type": "action-result", "sessionId": "…", "id": "5b0c…", "status": "rejected", "error": "busy" }
```

| Field | Type | Notes |
|-------|------|-------|
| `status` | `"completed"` \| `"rejected"` \| `"simulated"` | `completed` after the handler finished, `simulated` for `dryRun`, `rejected` otherwise. |
| `error` | string? | Safe error code, ≤ 160 chars (`invalid_action`, `invalid_parameters`, `busy`, `cancelled`, `expired`, `handler_failed`, …). |

Studio processes one action at a time per game and sends the next action after
the result. Acknowledge as soon as the effect has started (for example when the
zombies are spawned, not when they die). An acknowledgement means the handler
completed, not that an external side effect was transactionally rolled back.

### `event-result`

```json
{ "type": "event-result", "sessionId": "…", "id": "9f2e…", "status": "accepted" }
```

`accepted` if at least one handler consumed the event, otherwise `ignored`.

### `state` (feature `state`)

```json
{ "type": "state", "sessionId": "…", "acceptingActions": false, "phase": "round-over", "score": 1250 }
```

| Field | Type | Notes |
|-------|------|-------|
| `acceptingActions` | boolean | `false` pauses dispatch (see below). |
| `phase` | string | `^[a-z0-9][a-z0-9-]{0,31}$`, for example `lobby`, `playing`, `round-over`. |
| `score` | number? | Current score for Studio flows and overlays. Finite, \|score\| ≤ 10¹⁵. Not a leaderboard submission. |

Send `state` when it changes, at most 10 times per second. Studio applies every
valid message immediately (the latest wins) and does not end the session for a
faster rate, but it raises the Flow event at most 10 times per second, so
intermediate phases can be skipped. Before the first `state` a game counts as
accepting actions.

While `acceptingActions` is `false`, Studio sends no new `action` frames.
Waiting actions stay queued and do not expire for up to 60 seconds of continuous
pause; after resuming, each waiting action gets a fresh expiry window. An action
already sent before the pause continues normally. Use this for menus, round
transitions and cutscenes instead of rejecting every incoming action.

In Studio, phase or acceptance changes trigger the Flow event **Game state**, and
the condition fields *game phase*, *game score* and *game accepting actions* read
the latest state.

### `request` (features `leaderboard`, `bindings`)

```json
{ "type": "request", "sessionId": "…", "id": "req-3", "op": "leaderboard.submit", "params": { "score": 4200 } }
```

| `op` | `params` | `response.data` |
|------|----------|-----------------|
| `leaderboard.submit` | `{ "score": integer }`, 0 ≤ score ≤ 10¹² | `{ "best": number, "rank": number \| null, "improved": boolean }` |
| `leaderboard.top` | `{ "limit"?: 1–50 }` (default 10) | `{ "label": {de, en}, "order": "desc" \| "asc", "entries": [{ "rank", "name", "score", "avatarUrl"? }], "self"?: { "rank", "score", "avatarUrl"? } }` |
| `bindings.list` | `{}` | `{ "bindings": [{ "giftName", "giftId"?, "giftImageUrl"?, "giftCoins"?, "actionId", "label": {de, en}, "params" }] }` |

`params` may be omitted for `{}`. In `leaderboard.top`, `name` is `@` plus the
TikTok username of a streamer who allowed sharing it, otherwise the localized
anonymous label (`Anonym` / `Anonymous`). With feature `leaderboard-avatars`,
every entry and `self` carry `avatarUrl`: a profile picture URL or `null`
(section 8). Without the feature the field is absent; treat it as `null`.

Limits and their error codes: a fifth request while 4 are in flight is answered
`busy`; a second `leaderboard.submit` within 2 seconds `rate_limited` (also when
the cloud rate-limits); parameters out of range or an ID that is already in
flight `invalid`; an unknown `op` or a capability not announced `unsupported`.
Offline, signed-out or cloud errors are `unavailable`. Studio answers every
request within 15 seconds, otherwise with `timeout`.

A `state` or `request` frame with a wrong shape (unknown keys, wrong types, an
invalid phase) is a protocol violation and ends the session, like any other
invalid frame. So does `state` without the `state` feature.

The official SDKs also complete requests locally. Without sending anything:
`unsupported` (capability not announced), `not_ready` (before `ready`),
`invalid` (rejected by local validation), `busy` (4 in flight). After sending:
`timeout` (no response within 15 s), `stopped` (session ended first),
`invalid_response` (malformed `response` data). Studio itself never sends
`not_ready`, `stopped` or `invalid_response`.

## 6. Studio behavior games can rely on

### Gift rules and the game control window

Streamers connect gifts to manifest actions with gift rules. Studio provides the
complete management UI; games implement none of it:

- **Game control window.** When an Originals game connects, Studio opens a
  separate *game control* window beside it without taking focus. It shows the
  connection, queue and reported state, lists the manifest actions with test
  buttons, maps TikTok gifts from the gift catalog to actions with parameters,
  enables, disables and deletes gift rules, recreates a deleted Gift Wall and
  shows the leaderboard.
- **F7.** While a game runs, F7 brings the control window above a borderless or
  windowed fullscreen game and back. Reserve F7: never bind it in a game.
  Exclusive fullscreen can hide Studio windows; prefer borderless fullscreen.
- **Gift Wall.** A Gift Wall widget bound to a game fills itself from the
  game's gift rules: gift icon and coins from the gift catalog, label from the
  localized action label. Walls not bound to a game keep their manual entries.

### First start, Gift Wall and updates

There is no setup button. When a game starts:

- **Presets.** If the streamer has no gift rules for the game and the started
  build has `presets`, Studio opens a picker *before* the game starts: one card
  per preset (title, description, up to 8 combinations with gift image, coins,
  action image and action label) plus *Build your own set*. Picking a preset
  creates its gift rules and the Gift Wall (cells in preset order when
  `giftWall.sort` is `preset` or `manifest`) and starts the game without a
  further question. Presets that are new in an update are offered as a notice,
  never applied over existing rules. Keep preset and action IDs stable.
- **First start without presets** (or on a Studio without the `presets`
  extension). If the streamer has no gift rules for the game, Studio
  creates the rules from `defaultBindings` immediately, without asking, and
  shows a one-time notice with *Undo* (Undo removes exactly the rules and the
  wall this setup created, unless the streamer has changed them since). It also
  creates one Gift Wall bound to the game in the active scene, configured from
  the `giftWall` of the started build (Studio's defaults when it is absent).
  Existing rules and walls are never overwritten or duplicated; a second start
  creates nothing.
- **Split wall (help vs. sabotage).** Studio copies each action's `effect` onto
  the wall cells of its gift rules. With `giftWall.split` (extension
  `action-effects`) the wall is split: help actions on one side (left by
  default), sabotage actions on the other, each under a header; neutral and
  unclassified actions in a row below (or with the side named by
  `split.neutral`). A streamer's later change of a cell's effect or of the split
  settings is never overwritten. Without `split` the wall stays one block (the
  streamer can still switch the split on).
- **Updates.** When a newer build brings a changed `giftWall`, Studio applies
  the changed values at the next start to every field the streamer has not
  changed. Fields the streamer changed stay; the wall settings offer *Reset to
  the game's defaults*.
- **Live.** Creating, deleting, disabling or editing a gift rule updates the
  wall immediately, also while the game runs. Disabled rules disappear from the
  wall. Clients that requested `bindings.list` still receive `notify` with
  topic `bindings`.
- **Deleted wall.** If the streamer deletes the automatically created wall,
  Studio does not create it again; the game control window offers *Recreate
  Gift Wall (game defaults)*.

### Stacking (`stackable`)

TikTok viewers often send the same gift dozens of times per second. For an action
with `"stackable": "count"`, Studio merges waiting actions of the same gift rule,
viewer and gift into one action and sums `count`:

- A gift streak delivers every gift as it arrives. Rose ×99 for an action whose
  rule sets `count: 1` becomes one action with `count: 99` (if `max` ≥ 99).
- With `count: 3` per gift, each gift adds 3. The result stays within the
  parameter's `min`/`max`. Gifts beyond `max` start another action; nothing is
  dropped for exceeding the bound.
- Only actions that were not yet sent are merged. `source.giftCount` is the
  number of gifts the action represents.
- During a rule cooldown, gifts accumulate in one waiting action that is sent
  when the cooldown ends.

A stackable handler must accept any `count` between `min` and `max`.

### Queue limits

Up to 100 actions wait per game. Each action expires after its rule's time to
live (1–10 s) unless it is paused by `state`.

## 7. Manifest

The manifest is reviewed with each build. Studio validates every action and
parameter against it before sending.

```json
{
  "schemaVersion": 1,
  "gameId": "zombie-prank",
  "title": { "de": "Zombie-Streich", "en": "Zombie Prank" },
  "description": { "de": "Zuschauer schicken Zombies.", "en": "Viewers send zombies." },
  "actions": [
    { "id": "spawn-zombies", "label": { "de": "Zombies schicken", "en": "Send zombies" },
      "description": { "de": "Schickt Zombies auf den Streamer los.", "en": "Sends zombies after the streamer." },
      "image": "media/actions/spawn-zombies.png",
      "effect": "sabotage",
      "stackable": "count",
      "parameters": [{ "key": "count", "label": { "de": "Anzahl", "en": "Count" }, "type": "integer", "min": 1, "max": 200, "default": 1 }] },
    { "id": "heal", "label": { "de": "Heilen", "en": "Heal" },
      "description": { "de": "Gibt dem Streamer Leben zurück.", "en": "Gives the streamer health back." },
      "image": "media/actions/heal.png",
      "effect": "help",
      "parameters": [{ "key": "amount", "label": { "de": "Leben", "en": "Health" }, "type": "integer", "min": 1, "max": 100, "default": 20 }] }
  ],
  "events": ["GIFT"],
  "defaultBindings": [
    { "giftName": "Rose", "actionId": "spawn-zombies", "params": { "count": 1 } },
    { "giftName": "Doughnut", "actionId": "heal", "params": { "amount": 10 } }
  ],
  "presets": [
    { "id": "small-budget", "title": { "de": "Kleines Budget", "en": "Small budget" },
      "description": { "de": "Geschenke bis 30 Münzen.", "en": "Gifts up to 30 coins." },
      "bindings": [{ "giftName": "Rose", "actionId": "spawn-zombies", "params": { "count": 1 } }, { "giftName": "Doughnut", "actionId": "heal", "params": { "amount": 10 } }] },
    { "id": "medium", "title": { "de": "Mittel", "en": "Medium" },
      "bindings": [{ "giftName": "Hearts", "actionId": "spawn-zombies", "params": { "count": 25 } }, { "giftName": "Corgi", "actionId": "heal", "params": { "amount": 40 } }] },
    { "id": "big-gifts", "title": { "de": "Große Geschenke", "en": "Big gifts" },
      "bindings": [{ "giftName": "Galaxy", "actionId": "spawn-zombies", "params": { "count": 200 } }, { "giftName": "Money Gun", "actionId": "heal", "params": { "amount": 100 } }] }
  ],
  "leaderboard": { "label": { "de": "Überlebte Wellen", "en": "Waves survived" }, "order": "desc" },
  "giftWall": { "columns": 4, "sort": "preset", "showCoins": true, "showLabels": true, "title": { "de": "Zombies schicken", "en": "Send zombies" }, "split": true }
}
```

| Field | Rules |
|-------|-------|
| `schemaVersion` | `1` |
| `gameId` | Your immutable dashboard game ID. |
| `title`, `description` | `{ "de", "en" }`, non-empty; title ≤ 160, description ≤ 1000 chars. |
| `actions` | ≤ 128. `id`: `^[a-z][a-z0-9-]{0,63}$`, unique. `label` ≤ 160 chars, `description` ≤ 1000 (keep it ≤ 120: Studio's preset builder and the store page show it; the tools warn above 120). |
| `actions[].image` | Optional (extension `action-images`). A path inside the build ZIP: one file directly under `media/actions/`, `.png` or `.webp` (name `[A-Za-z0-9_-][A-Za-z0-9._-]{0,95}`, no reserved Windows name), or the `https://animstream.b-cdn.net/game-media/<gameId>/…` URL of an uploaded image, ≤ 512 chars. The file: a still PNG or WebP **with alpha**, square, 256–1024 px, ≤ 300 KB, extension matching the format. Build verification extracts only the referenced files and serves them from the CDN; Studio (and the game's `ready.manifest`) only ever receives the resolved CDN URL; an image uploaded in the dashboard or with `animstream-release media --action-image` replaces the build's image. `animstream-pack --all` copies the files from next to `manifest.json` into every ZIP. |
| `actions[].parameters` | ≤ 16. `key` like `id`; `type`: `integer`, `number`, `boolean`, `string` (`maxLength` 1–256), `enum` (1–32 `options` `{ value ≤ 128, label }`). Optional `required`, `default`, `min`/`max` (numeric only, \|x\| ≤ 10⁹, `min` ≤ `max`). |
| `actions[].stackable` | Optional. Key of an `integer` parameter of the same action with `min` ≥ 1 and `max` set. |
| `actions[].effect` | Optional (extension `action-effects`). `help` (mercy: helps the streamer — heal, shield, extra time; green in ART-DIRECTION.md), `sabotage` (gets in the streamer's way — enemies, shaking, stealing; red) or `neutral` (neither; use it rarely). Omitted = unclassified, treated like `neutral`. Any other value is rejected. Studio copies it onto the Gift Wall cells and groups the split wall by it; the store page groups the actions into *Helps the streamer* / *Against the streamer*. Every Original classifies **every** action; the tools warn when only some actions have an `effect`. |
| `events` | Event codes for raw `event` messages: `GIFT`, `FOLLOW`, `LIKE`, `SHARE`, `COMMENT`, `JOIN`, `SUBSCRIBE`, `TEAM_JOIN`, `LEVEL_UP`, `MULTIPLIER`, `MULTIPLIER_GIFT`, `BOOSTED_GIFT`, `MULTIPLIER_PREDICT`, `CHEER`, `RAID`, `RESUBSCRIBE`, `SUB_GIFT`, `REWARD`, `SHOUTOUT`, `CHARITY_DONATE`. Unique. May be empty. |
| `defaultBindings` | Optional, ≤ 32. `giftName`: TikTok gift display name (1–80 chars, no control characters or `* \| \ [ ] { }`), unique case-insensitively. Studio matches gifts by name because gift IDs differ between regional servers. Write the English display name: TikTok delivers a gift under the name of the streamer's language ("Donut" for Doughnut on a German system), and Studio recognises it in every language. Studio 0.1.306 and older compared the name as delivered, so such a gift did not start its action there. `giftId`: optional hint `^[A-Za-z0-9_-]{1,40}$`. `actionId`: an action of this manifest. `params`: validated against that action; defaults fill missing values. |
| `presets` | Optional (extension `presets`), 1–6. `id`: `^[a-z0-9][a-z0-9-]{0,31}$`, unique; `title` `{de, en}` ≤ 40 chars; optional `description` ≤ 120; `bindings`: 1–8 gift rules `{ giftName, actionId, params }` with the rules of `defaultBindings` (no `giftId`), `giftName` unique per preset. Studio offers them before the first start (section 6). Recommended for every Original: three presets by coin value — every gift ≤ 30 coins, 99–299 and ≥ 500 — each mixing sabotage and mercy actions — balanced, for example 4 `help` + 4 `sabotage` (the tools warn when a preset has no help or no sabotage action or one side has more than three times the other; Studio shows the count per preset, for example "4 Hilfe · 4 Böse"). Keep `defaultBindings` for Studios without presets. |
| `leaderboard` | Optional. `label` `{de, en}` ≤ 40 chars; `order` `desc` (higher is better, default) or `asc` (lower is better, for example times in ms). |
| `giftWall` | Optional layout of the game's Gift Wall (section 6). `columns`: required integer 1–12. `sort`: `coins-asc`, `coins-desc`, `preset` (order of the chosen preset) or `manifest` (the same: preset order, else the order of `defaultBindings`); without it the rule order. Studios without `presets` receive `manifest` for `preset`. `showCoins`: boolean, default `false`. `showLabels`: show action names, boolean, default `true`. `title`: optional `{de, en}` ≤ 40 chars. `split` (extension `action-effects`, optional, recommended for Originals): `true` (split with the defaults), `false` (plain wall) or `{ helpSide, helpTitle, sabotageTitle, showHeaders, neutral }`, every key optional — `helpSide` `left` (default) or `right`; `helpTitle` / `sabotageTitle` `{de, en}` ≤ 40 chars (default: Studio's texts "Hilft dem Streamer" / "Gegen den Streamer"); `showHeaders` boolean, default `true`; `neutral` `bottom` (default, a row below both sides), `help` or `sabotage`. No other keys. |

The serialized manifest must not exceed 48 KiB (UTF-8).

## 8. Leaderboards

Every published game automatically has one global leaderboard on AnimStream.
Developers need no database or server.

- Players are streamers. Each AnimStream account has one entry per game: its
  best score according to `order`. Submit the final score of a round or run with
  `leaderboard.submit`; submitting a worse score changes nothing.
- Studio submits through the authenticated game session; the game never receives
  account credentials. Scores are integers from 0 to 10¹². Submit durations as
  integer milliseconds with `"order": "asc"`.
- Names: an entry shows the streamer's TikTok username only if they allowed it
  in Studio; otherwise it is listed as anonymous. Usernames are reported by
  Studio and are not verified with TikTok; one username can appear on one
  account per game.
- `leaderboard.top` returns the top entries and the current streamer's own rank.
  The public ranking is shown at `https://animstream.com/<locale>/games/originals/<slug>/leaderboard`
  and as a preview on the game page.
- Pictures (feature `leaderboard-avatars`): see below.

This is cooperative scoring by a game the streamer runs. It is not cheat-proof;
administrators can remove entries.

### Profile pictures (`avatarUrl`)

With feature `leaderboard-avatars`, `leaderboard.top` entries and `self` carry
`avatarUrl` (string or `null`). Studio 0.1.286 and older omit it; games without
picture support need no change.

- **Consent.** A picture appears only if the streamer allowed both sharing the
  TikTok username and *showing the profile picture on leaderboards* in Studio
  (off by default). Anonymous entries always have `null`. Revoking the consent
  or deleting the account removes the picture from every leaderboard and from
  the CDN at once; administrators can hide pictures (`null`).
- **Delivery.** AnimStream copies the TikTok picture to its own CDN as a
  128×128 PNG without metadata. The URL is public and stable: no cookies, no
  `Referer`, no token or tracking parameters. A new picture gets a new URL, so
  cache images by URL. Web clients may load the same path with `.webp`.
- **Validation.** Accept only `https://` URLs on `animstream.b-cdn.net`,
  `animstream.com` or `*.animstream.com` with a path ending in `.png`, at most
  512 characters, without query, fragment, port, credentials or `..`
  (`^https://(?:animstream\.b-cdn\.net|(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*animstream\.com)(?:/[A-Za-z0-9_-][A-Za-z0-9._-]{0,127}){1,8}\.png$`).
  Treat anything else as `null`, never as an error. The official SDKs also accept
  `http://127.0.0.1:<port>/….png`: only the mock Studio sends such URLs.
- **Loading.** Load pictures asynchronously with a short timeout (5 s) and a
  size cap (1 MiB). A missing picture (`null`, 404, timeout, bytes that are not a
  PNG) shows a fallback such as the name's first letter. Never delay gameplay or
  the round-over screen for a picture.

## 9. Packages and helper processes

Packages are ZIP archives of a native export (Windows, macOS or Linux; x64 or
arm64). Action images referenced by the manifest (`media/actions/…`) must be in
every package at that path; verification reads only those files from the ZIP.
Limits: 100 GiB compressed, 100 GiB expanded and 50,000 entries. Standard ZIP and
ZIP64 are supported; no split archives, symlinks, absolute or traversal paths,
duplicate names or encryption. Entries larger than 1 MiB may expand at most
1000:1; stored and deflate are the supported compression methods.

Installing these large packages requires an updated Studio that announces the
`large-packages` catalog capability. Older Studio versions receive the latest
compatible smaller build, when one exists; otherwise Studio must be updated.

**Bundled helper processes are allowed** under these rules. Studio stops the
complete process tree when a session ends (Windows `taskkill /T /F`; macOS and
Linux: the process group).

1. Helpers are native executables inside the same reviewed package (for example
   a `bun build --compile` binary). Nothing is downloaded, unpacked into other
   locations or generated as an executable at runtime.
2. The entrypoint (or one of its children) starts helpers as ordinary child
   processes from the installation directory. They must not detach or escape the
   process tree: no `setsid`/new process groups, no `DETACHED_PROCESS`,
   `CREATE_NEW_PROCESS_GROUP` or `CREATE_BREAKAWAY_FROM_JOB`, no `start`, `open`,
   `nohup`, services, daemons, launch agents, scheduled tasks or autostart entries.
3. Helpers exit when their parent exits and never outlive the session.
4. No elevation (UAC, sudo), no installers, no changes outside the game's own
   files and the user's per-game data directory.
5. Helpers listen only on `127.0.0.1`. At most one process holds the Studio
   protocol connection. The launch token stays in process environments and is
   never written to disk, logs or command lines.
6. Declare each helper (file name and purpose) in the build's review notes.

Verification rejects installer and script launcher formats (`.msi`, `.msix`,
`.appx`, `.pkg`, `.dmg`, `.deb`, `.rpm`, `.bat`, `.cmd`, `.ps1`, `.vbs`, `.wsf`,
`.hta`, `.scr`, `.pif`, `.lnk`, `.reg`, `.command`, `.psm1`, `.vbe`, `.wsh`,
`.msixbundle`, `.appxbundle`, `.mpkg`) and macOS `LaunchAgents`, `LaunchDaemons`,
`LoginItems` and `LaunchServices` folders, and records every additional native
executable for the reviewer.
Administrators reject packages whose helpers violate these rules.

## 10. Security model

This is license enforcement in cooperative game clients, not unbreakable DRM.
Studio trusts authenticated HTTPS catalog metadata and checks the package
SHA-256. The local socket listens on loopback only, accepts one authenticated
peer and rejects browser origins. Games never receive account tokens, download
URLs or the cloud lease secret.
