@crowdedkingdoms/crowdyjs 18.39.1-test.1 → 18.40.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION.md +62 -0
- package/README.md +401 -2
- package/dist/binary-wire.d.ts +94 -1
- package/dist/binary-wire.d.ts.map +1 -1
- package/dist/binary-wire.js +122 -20
- package/dist/crowdy-client.d.ts +7 -0
- package/dist/crowdy-client.d.ts.map +1 -1
- package/dist/crowdy-client.js +3 -0
- package/dist/default-origin.d.ts +6 -6
- package/dist/default-origin.d.ts.map +1 -1
- package/dist/default-origin.js +6 -6
- package/dist/domains/admin.d.ts +7 -0
- package/dist/domains/admin.d.ts.map +1 -1
- package/dist/domains/admin.js +1 -0
- package/dist/domains/exec.d.ts +91 -3
- package/dist/domains/exec.d.ts.map +1 -1
- package/dist/domains/exec.js +132 -5
- package/dist/domains/fleetSessions.d.ts +87 -0
- package/dist/domains/fleetSessions.d.ts.map +1 -0
- package/dist/domains/fleetSessions.js +87 -0
- package/dist/dropped-read.d.ts +2 -1
- package/dist/dropped-read.d.ts.map +1 -1
- package/dist/dropped-read.js +2 -6
- package/dist/errors.d.ts +59 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +70 -0
- package/dist/fleet/index.d.ts +4 -0
- package/dist/fleet/index.d.ts.map +1 -0
- package/dist/fleet/index.js +21 -0
- package/dist/fleet/session.d.ts +730 -0
- package/dist/fleet/session.d.ts.map +1 -0
- package/dist/fleet/session.js +1376 -0
- package/dist/fleet/socket.d.ts +59 -0
- package/dist/fleet/socket.d.ts.map +1 -0
- package/dist/fleet/socket.js +111 -0
- package/dist/fleet-wire.d.ts +272 -0
- package/dist/fleet-wire.d.ts.map +1 -0
- package/dist/fleet-wire.js +472 -0
- package/dist/generated/graphql-schema.d.ts +176 -13
- package/dist/generated/graphql-schema.d.ts.map +1 -1
- package/dist/generated/graphql-schema.js +15 -3
- package/dist/generated/graphql.d.ts +79 -0
- package/dist/generated/graphql.d.ts.map +1 -1
- package/dist/generated/graphql.js +5 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/server-only.d.ts +54 -0
- package/dist/server-only.d.ts.map +1 -0
- package/dist/server-only.js +55 -0
- package/package.json +5 -1
package/MIGRATION.md
CHANGED
|
@@ -120,6 +120,68 @@ super-admin's session). There is no SDK replacement.
|
|
|
120
120
|
`dev`'s SDL after #417 merged (`npm run schema:sync:paths -- --schema <that schema.gql>`, then
|
|
121
121
|
`npm run codegen`).
|
|
122
122
|
|
|
123
|
+
## 18.40.0: fleet sessions for an organization's game servers
|
|
124
|
+
|
|
125
|
+
Your code needs no change, and nothing here changes a client that does not use it. This
|
|
126
|
+
release adds fleet sessions. They need Application API v2.89.0 or later, realtime servers
|
|
127
|
+
v0.50.3, and ck-exec 0.25.0 for the hub connection. All three have been on dev, test, and prod
|
|
128
|
+
since November 26, 2026. Fleet sessions stay off for an organization until a Crowded Kingdoms
|
|
129
|
+
operator switches them on, and the organization also needs
|
|
130
|
+
[org-managed players](README.md#org-managed-players). Until then, the Application API refuses
|
|
131
|
+
`fleetSessions.open` with `FORBIDDEN`. Every other call needs what 18.39.0 needs: Application
|
|
132
|
+
API v2.85.0 or later. The README's
|
|
133
|
+
[Game servers: fleet sessions](README.md#game-servers-fleet-sessions) is the guide.
|
|
134
|
+
|
|
135
|
+
A fleet session is one realtime session a game server opens for itself, in which it carries
|
|
136
|
+
the players who are on it. It runs on a server your organization runs. An org token and a
|
|
137
|
+
fleet token never go into a browser page or a game client.
|
|
138
|
+
|
|
139
|
+
- **`client.fleetSessions`** (also `client.admin.fleetSessions`): `open(appId)`,
|
|
140
|
+
`refresh({ appId, gameTokenId, currentServer? })`, and `close({ appId, gameTokenId })` wrap
|
|
141
|
+
`openFleetSession`, `refreshFleetSession`, and `closeFleetSession`, with the organization's
|
|
142
|
+
org token (`cko_…`, scope `fleet:session`) as the client's bearer. `open` and `refresh` answer
|
|
143
|
+
a `FleetSessionAnswer`: `token`, `gameTokenId`, `appId`, `expiresAt`, `maxPlayers`, `server`.
|
|
144
|
+
The org token that opened a session is the one that refreshes and closes it: another org token
|
|
145
|
+
of the same organization gets `NOT_FOUND` from `refresh` and `false` from `close`. The calls
|
|
146
|
+
run on a server (Node, Bun, Deno, a server-side worker) and refuse a page or its worker. Revoking an
|
|
147
|
+
org token ends every session and hub connection it opened. A session that is neither
|
|
148
|
+
refreshed nor closed ends at its `expiresAt`, 24 hours after it was opened or last refreshed.
|
|
149
|
+
- **`FleetSession`**, from the new Node entry point `@crowdedkingdoms/crowdyjs/fleet`: the
|
|
150
|
+
session itself, over UDP (`node:dgram`). `connect`, `carry`, `release`, a send for a carried
|
|
151
|
+
player for each of `client.udp`'s sends, `sendHeartbeat`, `setSpeakers`, handlers that receive
|
|
152
|
+
the players a notification is for, `refreshDue`, `refreshInput`, `applyRefresh`, `stats`, and
|
|
153
|
+
`close`. Importing the entry point where `node:dgram` does not exist throws. The
|
|
154
|
+
`genericError` handler receives `(notification, verified)`: a refusal that arrived alone
|
|
155
|
+
carries no signature, so `verified` is false for it, and the session changes nothing on a
|
|
156
|
+
refusal. After a player's token is refreshed,
|
|
157
|
+
`carry({ token, gameTokenId, replaces })` keeps the player carried: sends name the new id
|
|
158
|
+
from the moment the new `FLEET_CARRY` is sent, and a late message about the old id is
|
|
159
|
+
ignored (`stats().replacedIdFrames`). A carry answered "no live token" is sent once more,
|
|
160
|
+
250 ms later, before it settles (`stats().noLiveTokenRetries`).
|
|
161
|
+
- **`client.exec.connectAsServer(appId)`** and `serverEndpoint(appId)` wrap
|
|
162
|
+
`execConnectAsServer`: one hub connection for a game server. `ExecConnection.callAs(player,
|
|
163
|
+
nodeType, key, method, args)` and `callAsRaw` make a call for one of the organization's players
|
|
164
|
+
(client frame `0x05`) and are refused locally, `Denied`, on a connection that is not a
|
|
165
|
+
server's. `ExecConnection.openAsServer(gatewayUrl, token)` and the `isServer` getter are new.
|
|
166
|
+
`ExecClientFrame` gains the `callAs` kind.
|
|
167
|
+
- **Refusals:** `orgTokenRequiredOf` (`ORG_TOKEN_REQUIRED`), `fleetSessionLimitOf`
|
|
168
|
+
(`FLEET_SESSION_LIMIT`), `fleetSessionNotFoundOf` (`NOT_FOUND` on a refresh), and
|
|
169
|
+
`platformBusyOf` (`PLATFORM_BUSY`, with `retryAfterMs`), each with its `*_CODE` constant.
|
|
170
|
+
- **Wire codecs**, pure functions in the root entry point: `createFleetSignContext`,
|
|
171
|
+
`carriedPlayerContext`, `fleetCarryProof`, `serializeFleetCarry` (49), `serializeFleetRelease`
|
|
172
|
+
(50), `parseFleetCarryResult` (51), `parseFleetReleased` (52), `parseFleetDelivery` (53), and
|
|
173
|
+
`parseFleetDatagram`, which verifies a whole datagram. Also new there:
|
|
174
|
+
`serializeActorHeartbeat` (26), `serializeClientCapabilities`, `serializeClientMediaSpeakers`,
|
|
175
|
+
`parseNotification`, `ClientCapability` (with `BOUND_CONTROL` and `FLEET_OWN_STATE`),
|
|
176
|
+
`SpeakerListMode`, and `MAX_MEDIA_SPEAKERS`. `WireMessageType` gains 22, 26, 28, 44 to 46, and
|
|
177
|
+
49 to 53.
|
|
178
|
+
- **Unchanged:** the relay, what a player's session advertises, and every existing call. The
|
|
179
|
+
SDK still has no wrapper for `mintManagedPlayerToken`.
|
|
180
|
+
|
|
181
|
+
`schema.gql` and the generated types are the Application API's at v2.89.1. Beside the fleet
|
|
182
|
+
session fields they carry the project profile's review, the organization's compute ceiling, and
|
|
183
|
+
`portalReturnAllowed`; the SDK wraps none of those in this change.
|
|
184
|
+
|
|
123
185
|
## 18.39.1: a dropped build-status read no longer ends a deploy
|
|
124
186
|
|
|
125
187
|
Your code needs no change. Until this release, one dropped read of a build's status ended a Studio
|
package/README.md
CHANGED
|
@@ -34,6 +34,7 @@ so it needs that Application API or newer; promote the Application API before th
|
|
|
34
34
|
|
|
35
35
|
| CrowdyJS | Needs the Application API (ck-api) |
|
|
36
36
|
| --- | --- |
|
|
37
|
+
| 18.40.0 | as 18.39.0; `client.fleetSessions` and `exec.connectAsServer` need v2.89.0 or later (see [Game servers: fleet sessions](#game-servers-fleet-sessions)) |
|
|
37
38
|
| 18.39.1 | as 18.39.0 |
|
|
38
39
|
| 18.39.0 | v2.85.0 or later (selects `applicationApiUrl`, `applicationApiWsUrl` and `platformConfig`'s `sharedApplicationApi*`; the `gameApi*` names stay as deprecated aliases until January 1, 2027) |
|
|
39
40
|
| 18.33.0 | v2.73.0 or later (exec's mod builds, mods and CLIENT halves select `studioProjectId` and `studioRevision`; `exec.modClientStarter`, `crowdyStudio.links`) |
|
|
@@ -471,13 +472,14 @@ is refused `FORBIDDEN`.
|
|
|
471
472
|
| `client.kit(appId)` | Game Kit: typed clients for the ck-exec starter hubs (world, matchmaking, sessions, NPCs and pets) on one shared connection, their topology, realtime conventions, and parties, guilds and chat (`kit.social`) — see [Game Kit](#game-kit). |
|
|
472
473
|
| `createWorldSession(client, appId, config)` | World Stores: opt-in, SDK-managed game state from the `@crowdedkingdoms/crowdyjs/stores` subpath — see [World Stores](#world-stores). |
|
|
473
474
|
|
|
474
|
-
**Studio-admin surface** (privileged; drive with an org admin's session, or an org token for the managed-player calls
|
|
475
|
-
grouped under `client.admin` and mirrored at the top level):
|
|
475
|
+
**Studio-admin surface** (privileged; drive with an org admin's session, or an org token for the managed-player calls
|
|
476
|
+
and the fleet session calls, grouped under `client.admin` and mirrored at the top level):
|
|
476
477
|
|
|
477
478
|
| Sub-client | What it does |
|
|
478
479
|
|---|---|
|
|
479
480
|
| `client.organizations` | Orgs, members, RBAC roles, org API tokens (with `scopes` and `appIds` for org-managed players). |
|
|
480
481
|
| `client.managedPlayers` | Org-managed players: list, provision, rename, disable, end sessions, delete; assertion signing keys; whether the org pays for their mods in an app; where the org stands on the addendum. See [Org-managed players](#org-managed-players). |
|
|
482
|
+
| `client.fleetSessions` | For an organization's own game servers (18.40.0): `open`, `refresh`, and `close` a fleet session with the organization's org token. The session itself is `FleetSession` from `@crowdedkingdoms/crowdyjs/fleet` (Node), and `client.exec.connectAsServer` opens the server's hub connection. An org token and a fleet token stay on a server your organization runs. See [Game servers: fleet sessions](#game-servers-fleet-sessions). |
|
|
481
483
|
| `client.apps` | App registry, discovery + routing (`create`, `routeFor`, `marketplace`), visibility, and player-code admission mode / allow-list administration. The safety log's state for players (`recording`, readable with an app token) and the app's own documents (`setRequiredDocuments`). |
|
|
482
484
|
| `client.moderation` | An app's safety reports for its moderators (`moderate_safety`): `reports`, `resolveReport`, `escalateReport`. See [Player safety](#player-safety). |
|
|
483
485
|
| `client.appAccess` | Access tiers + per-user grants, and the feature keys a tier grants (`defineFeature`, `grantTierFeature`, `tierFeatures`, …), which a hub checks with the node API's `players.features`; timed bans (`suspend`, `unsuspend`) and `resyncTierGridPermissions`. |
|
|
@@ -1196,6 +1198,381 @@ grid's owner is asked about their own CLIENT halves like anyone; answer yes in `
|
|
|
1196
1198
|
`prompt.authorId` is the player. See
|
|
1197
1199
|
[CLIENT halves](https://docs.dev.crowdedkingdoms.com/exec/client-halves).
|
|
1198
1200
|
|
|
1201
|
+
## Game servers: fleet sessions
|
|
1202
|
+
|
|
1203
|
+
A fleet session is one realtime session that a game server opens for itself and uses for
|
|
1204
|
+
every player on that server. A player signs in once, when they join the game. When the
|
|
1205
|
+
player moves to another of your servers, that server starts to carry them with one UDP
|
|
1206
|
+
message, and neither server calls the Application API.
|
|
1207
|
+
|
|
1208
|
+
**A fleet session runs on a server your organization runs.** Your organization's org token
|
|
1209
|
+
opens it, and its fleet token signs for every player the session carries. An org token and a
|
|
1210
|
+
fleet token never go into a browser page or a game client. A game on a player's device uses
|
|
1211
|
+
`client.udp` with that player's own app token.
|
|
1212
|
+
|
|
1213
|
+
**SDK 18.40.0 carries fleet sessions.** They need Application API v2.89.0 or later, realtime
|
|
1214
|
+
servers v0.50.3, and ck-exec 0.25.0 for the hub connection. All three have been on dev,
|
|
1215
|
+
test, and prod since November 26, 2026. Fleet sessions stay off for an organization until a
|
|
1216
|
+
Crowded Kingdoms operator switches them on, and the organization also needs
|
|
1217
|
+
[org-managed players](#org-managed-players). Until then, the Application API refuses
|
|
1218
|
+
`fleetSessions.open` with `FORBIDDEN`.
|
|
1219
|
+
|
|
1220
|
+
The session is `FleetSession`, from the Node entry point `@crowdedkingdoms/crowdyjs/fleet`.
|
|
1221
|
+
It talks to the realtime server over UDP (`node:dgram`), which a page cannot open, so no
|
|
1222
|
+
other entry point of the package imports it. Importing it where `node:dgram` does not exist
|
|
1223
|
+
throws.
|
|
1224
|
+
|
|
1225
|
+
```ts
|
|
1226
|
+
import { createCrowdyClient } from '@crowdedkingdoms/crowdyjs';
|
|
1227
|
+
import { FleetSession } from '@crowdedkingdoms/crowdyjs/fleet';
|
|
1228
|
+
|
|
1229
|
+
// A client for this server, holding the org token (cko_…, scope fleet:session).
|
|
1230
|
+
// Give it no tokenStore: the org token stays where your server keeps its secrets.
|
|
1231
|
+
const api = createCrowdyClient({ httpUrl: 'https://ck.dev.crowdedkingdoms.com' });
|
|
1232
|
+
api.setToken(process.env.CK_ORG_TOKEN);
|
|
1233
|
+
|
|
1234
|
+
const fleet = new FleetSession({
|
|
1235
|
+
session: await api.fleetSessions.open(appId), // one session for each game server
|
|
1236
|
+
handlers: {
|
|
1237
|
+
actorUpdate: (n) => world.apply(n), // state arrives once for the session
|
|
1238
|
+
text: (n, players) => players?.forEach((p) => chat.deliver(p, n)), // only these players
|
|
1239
|
+
released: (r) => roster.remove(r.playerGameTokenId), // the platform ended a carry
|
|
1240
|
+
},
|
|
1241
|
+
});
|
|
1242
|
+
await fleet.connect();
|
|
1243
|
+
|
|
1244
|
+
// A player joined this server. `player` is the app token your server minted for them
|
|
1245
|
+
// (mintManagedPlayerToken): its token and its gameTokenId.
|
|
1246
|
+
const carry = await fleet.carry({ token: player.token, gameTokenId: player.gameTokenId });
|
|
1247
|
+
if (carry.carried) {
|
|
1248
|
+
await fleet.sendActorUpdate(player.gameTokenId, { chunk, uuid, state });
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
// The player left the game.
|
|
1252
|
+
await fleet.release(player.gameTokenId);
|
|
1253
|
+
|
|
1254
|
+
// In your loop: keep the session, and follow it to another realtime server.
|
|
1255
|
+
if (fleet.refreshDue()) {
|
|
1256
|
+
await fleet.applyRefresh(await api.fleetSessions.refresh(fleet.refreshInput()));
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
// The server stops.
|
|
1260
|
+
await api.fleetSessions.close({ appId: fleet.appId, gameTokenId: fleet.gameTokenId });
|
|
1261
|
+
fleet.close();
|
|
1262
|
+
```
|
|
1263
|
+
|
|
1264
|
+
### The org token that opens a session keeps it and ends it
|
|
1265
|
+
|
|
1266
|
+
`client.fleetSessions` (also `client.admin.fleetSessions`) wraps the three Application API
|
|
1267
|
+
calls. Each takes the org token as the client's bearer. Each refuses to run in a browser
|
|
1268
|
+
page or a page's worker: it runs on Node, Bun, Deno, and server-side workers (the Cloudflare
|
|
1269
|
+
Workers runtime and Vercel's Edge Runtime).
|
|
1270
|
+
|
|
1271
|
+
| Call | Application API | Answer |
|
|
1272
|
+
| --- | --- | --- |
|
|
1273
|
+
| `open(appId)` | `openFleetSession` | `token` (64 characters), `gameTokenId`, `appId`, `expiresAt` (24 hours away), `maxPlayers`, and the realtime `server` (`ip4`, `ip6`, `clientPort`) |
|
|
1274
|
+
| `refresh({ appId, gameTokenId, currentServer? })` | `refreshFleetSession` | The same token and `gameTokenId`, with `expiresAt` moved to 24 hours from now |
|
|
1275
|
+
| `close({ appId, gameTokenId })` | `closeFleetSession` | `true` when a session was ended |
|
|
1276
|
+
|
|
1277
|
+
- **One org token owns a session.** `refresh` and `close` work with the org token that
|
|
1278
|
+
opened the session. Another org token of the same organization gets `NOT_FOUND` from
|
|
1279
|
+
`refresh` and `false` from `close`.
|
|
1280
|
+
- **Revoking an org token ends what it opened:** every fleet session and every hub
|
|
1281
|
+
connection.
|
|
1282
|
+
- **A session ends at its `expiresAt`** when it is neither refreshed nor closed: 24 hours
|
|
1283
|
+
after it was opened or last refreshed.
|
|
1284
|
+
- **Limits.** An organization holds at most 512 fleet sessions at once, and a session
|
|
1285
|
+
carries at most 256 players, unless an operator set other numbers for the organization.
|
|
1286
|
+
The answer's `maxPlayers` is the session's own number. Open one session for each game
|
|
1287
|
+
server.
|
|
1288
|
+
- **The fleet token is a signing key.** The Application API does not accept it as a bearer.
|
|
1289
|
+
|
|
1290
|
+
`FleetSession` makes no Application API call. A server that calls the API with its own HTTP
|
|
1291
|
+
client gives `FleetSession` the same fields.
|
|
1292
|
+
|
|
1293
|
+
### Carrying a player takes one message and proof of the player's token
|
|
1294
|
+
|
|
1295
|
+
`fleet.carry({ token, gameTokenId })` sends `FLEET_CARRY`. The message names the player's
|
|
1296
|
+
`gameTokenId` and carries a proof that your server holds the player's token: an HMAC keyed
|
|
1297
|
+
with that token over the session's `gameTokenId`, the player's `gameTokenId`, and the time.
|
|
1298
|
+
The promise resolves with how the carry ended:
|
|
1299
|
+
|
|
1300
|
+
| `status` | Meaning |
|
|
1301
|
+
| --- | --- |
|
|
1302
|
+
| `carried` | The session carries the player. `userId` is the player's user id. |
|
|
1303
|
+
| `noLiveToken` | The realtime servers know no live token by that id: it expired, the sign-in ended, or it belongs to another app. The session asked twice before it settled on this answer. |
|
|
1304
|
+
| `otherOrganization` | The token belongs to another organization's player. |
|
|
1305
|
+
| `proofFailed` | The proof or its time failed. A clock more than 30 seconds from the server's fails too. |
|
|
1306
|
+
| `sessionFull` | The session carries as many players as it may (`maxPlayers`). |
|
|
1307
|
+
| `timedOut` | No answer came within 5 seconds of the first send. |
|
|
1308
|
+
| `refused` | A status this version of the SDK does not know. `wireStatus` has the byte. |
|
|
1309
|
+
| `tableFull` | Nothing was sent: the session's table already holds `maxPlayers` rows and 32 more, carried players and waiting carries together. Release players who left. |
|
|
1310
|
+
| `released`, `closed` | You called `release` for the player, or `close`, while the carry was waiting. |
|
|
1311
|
+
|
|
1312
|
+
- **An unanswered carry is sent again** every 250 ms, each time with a new time and a new
|
|
1313
|
+
proof (`carryRetryMs`, `carryTimeoutMs`).
|
|
1314
|
+
- **A carry answered "no live token" is sent once more**, 250 ms later, with a new time and
|
|
1315
|
+
a new proof. The promise settles on the answer to that second send.
|
|
1316
|
+
- **Carries are paced.** The session sends at most 60 `FLEET_CARRY` messages a second, first
|
|
1317
|
+
sends and retries together (`maxCarriesPerSecond`). The realtime servers drop a session's
|
|
1318
|
+
carries past 64 a second without an answer.
|
|
1319
|
+
- **A crossing is a carry on the next server.** Stop sending for the player on this server,
|
|
1320
|
+
then give the next server the player's token over your own link. Its session carries the
|
|
1321
|
+
player, and this session's `released` handler fires with reason 1.
|
|
1322
|
+
- **After you refresh a player's token**, call
|
|
1323
|
+
`carry({ token, gameTokenId, replaces })` with the new token, the new `gameTokenId`, and
|
|
1324
|
+
the `gameTokenId` the player was carried under as `replaces`. The next section covers
|
|
1325
|
+
what happens to the player's sends meanwhile.
|
|
1326
|
+
- **`fleet.release(gameTokenId)`** sends `FLEET_RELEASE` when the player leaves the game.
|
|
1327
|
+
The message has no answer. If it is lost, the carry stays on the platform until another
|
|
1328
|
+
session carries the player, their sign-in ends, or they idle out.
|
|
1329
|
+
|
|
1330
|
+
The `released` handler reports a carry the platform ended, with its reason: 1 another
|
|
1331
|
+
session carries the player, 2 the player's sign-in ended or their token expired, 5 the
|
|
1332
|
+
player sent no gameplay input for the app's idle timeout (15 minutes unless the app sets its
|
|
1333
|
+
own).
|
|
1334
|
+
|
|
1335
|
+
The platform sends `FLEET_RELEASED` once. The message can be lost, and it can arrive up to
|
|
1336
|
+
about 6 seconds after the carry ended, so `released` may fire late or never. After a
|
|
1337
|
+
crossing, `UNAUTHORIZED` on the previous server's next send for the player is the sign that
|
|
1338
|
+
the other session carries them. For a few milliseconds after a crossing, and rarely for up
|
|
1339
|
+
to about 5 seconds, the previous session's sends for the player are still accepted, which
|
|
1340
|
+
is why your server stops sending before it hands the player off.
|
|
1341
|
+
|
|
1342
|
+
### A refreshed token replaces the old one with no gap
|
|
1343
|
+
|
|
1344
|
+
A player's token expires. Whoever holds the token refreshes it with `refreshAppToken`
|
|
1345
|
+
before then, and the answer has a new token and a new `gameTokenId`. Carry the player again
|
|
1346
|
+
with both, and name the id the player is carried under now:
|
|
1347
|
+
|
|
1348
|
+
```ts
|
|
1349
|
+
const result = await fleet.carry({
|
|
1350
|
+
token: refreshed.token,
|
|
1351
|
+
gameTokenId: refreshed.gameTokenId,
|
|
1352
|
+
replaces: previousGameTokenId,
|
|
1353
|
+
});
|
|
1354
|
+
```
|
|
1355
|
+
|
|
1356
|
+
- **The player stays carried throughout.** The carry made with the old token stands until
|
|
1357
|
+
the new one takes effect, and the player keeps their actors and their idle clock. No
|
|
1358
|
+
`released` event fires.
|
|
1359
|
+
- **Every send names the new id from the moment the new `FLEET_CARRY` is sent.** The session
|
|
1360
|
+
does this for you: a send you make with either id goes out under the old id before that
|
|
1361
|
+
moment and under the new id after it. A send that names the new id and arrives before
|
|
1362
|
+
the carry took effect waits for the carry.
|
|
1363
|
+
- **Use the new id once the promise resolves `carried`.** From then on the old id names
|
|
1364
|
+
nobody: a send with it rejects with `FleetNotCarriedError`, and `fleet.carries` answers
|
|
1365
|
+
false for it.
|
|
1366
|
+
- **A late message about the old id changes nothing.** The session ignores a
|
|
1367
|
+
`FLEET_RELEASED` or a carry's answer that names an id it replaced, and counts it
|
|
1368
|
+
(`replacedIdFrames` in `fleet.stats()`).
|
|
1369
|
+
- **A refused replacement leaves the player carried under the old id** until the platform
|
|
1370
|
+
ends that carry, which the `released` handler reports. A replacement with no answer in 5
|
|
1371
|
+
seconds ends the carry under both ids, and the promise resolves `timedOut`.
|
|
1372
|
+
|
|
1373
|
+
A `carry` with a new token and no `replaces` also ends with the player carried under the
|
|
1374
|
+
new id, with a gap on the way. The session learns that the two tokens are one player only
|
|
1375
|
+
from the carry's answer. Until that answer arrives its sends name the old id, and the
|
|
1376
|
+
platform refuses the ones that arrive after the new carry took effect. Pass `replaces`.
|
|
1377
|
+
|
|
1378
|
+
### Each send names the player it is for
|
|
1379
|
+
|
|
1380
|
+
The sends of `client.udp` have a `FleetSession` form that takes the carried player's
|
|
1381
|
+
`gameTokenId` first: `sendActorUpdate`, `sendVoxelUpdate`, `sendClientEvent`,
|
|
1382
|
+
`sendTextPacket`, `sendAudioPacket`, `sendVideoPacket`, `sendGenericSpatial`,
|
|
1383
|
+
`sendSingleActorMessage`, `sendChannelMessage`, `sendChannelAudio`,
|
|
1384
|
+
`sendRangedChannelMessage`, and `setSpeakers`. `sendHeartbeat` keeps one of the player's
|
|
1385
|
+
actors present. Each send resolves with the sequence number it was sent under.
|
|
1386
|
+
|
|
1387
|
+
- **The message is the one that player's own session would send.** Its tail carries the
|
|
1388
|
+
player's `gameTokenId`, and its HMAC is keyed with the fleet token.
|
|
1389
|
+
- **The platform applies the player's own rules** to it: their permissions, blocks, age
|
|
1390
|
+
rules, speaker lists, and a budget of 500 messages a second with bursts to 1,000.
|
|
1391
|
+
- **A send for a player the session does not carry** rejects with `FleetNotCarriedError`
|
|
1392
|
+
and puts nothing on the wire.
|
|
1393
|
+
- **Under its own `gameTokenId` the session sends four kinds of message:** its capabilities,
|
|
1394
|
+
`FLEET_CARRY`, `FLEET_RELEASE`, and its keepalive. The realtime servers answer any other
|
|
1395
|
+
`UNAUTHORIZED`.
|
|
1396
|
+
|
|
1397
|
+
The session keeps itself alive with a heartbeat every 2 seconds (`keepAliveIntervalMs`). It
|
|
1398
|
+
also keeps a carried player's actors present: an actor you sent an update for gets a
|
|
1399
|
+
heartbeat under the player's id after 2 seconds without a message (`actorHeartbeatMs`),
|
|
1400
|
+
until you call `fleet.forgetActor(player, uuid)` or the carry ends. A heartbeat is not
|
|
1401
|
+
gameplay input, and neither is voice or video. A carried player who sends no gameplay input
|
|
1402
|
+
for the app's idle timeout is released with reason 5, and the session stays.
|
|
1403
|
+
|
|
1404
|
+
### State arrives once, and a delivery names its players
|
|
1405
|
+
|
|
1406
|
+
Each handler receives the notification and the players it is for.
|
|
1407
|
+
|
|
1408
|
+
- **State arrives once for the session**, with `players` null, when at least one carried
|
|
1409
|
+
player may receive it: actor updates and departures, voxel edits, events, app-defined
|
|
1410
|
+
spatial messages, and chunk changes. A carried player is in range of something once one
|
|
1411
|
+
of their actors stands near it: a session whose players have no actor yet is sent no
|
|
1412
|
+
state.
|
|
1413
|
+
- **Communications arrive with a list** of the carried players who may receive them, at
|
|
1414
|
+
most 32 in one message: spatial voice, text and video, direct messages, channel messages,
|
|
1415
|
+
and channel audio. Deliver each to the listed players and to nobody else. A block, an age
|
|
1416
|
+
rule, a speaker list, or a missing permission takes a player off the list.
|
|
1417
|
+
- **A client's event or an app-defined spatial message** arrives with a list when only some
|
|
1418
|
+
of your players in range may receive it, and plain when all of them may.
|
|
1419
|
+
- **Your own players' state is not sent back to you.** `fleetOwnState: true` (or
|
|
1420
|
+
`fleet.setFleetOwnState(true)`) asks for it when another of your players is in range.
|
|
1421
|
+
With it off, two things still reach the session that caused them: a voxel edit it sent,
|
|
1422
|
+
and the departure of its own player's actor.
|
|
1423
|
+
- **State about a player you carry is stale.** Your server is the authority on its own
|
|
1424
|
+
players. Just after a crossing, the session can receive a few updates for the player it
|
|
1425
|
+
now carries that the previous server sent a moment before. Drop state whose actor belongs
|
|
1426
|
+
to a player the session carries.
|
|
1427
|
+
|
|
1428
|
+
`FleetSession` verifies everything it receives with the fleet token before a handler runs,
|
|
1429
|
+
and no option turns that off. A frame that fails is dropped and counted in `fleet.stats()`
|
|
1430
|
+
(`hmacFailures`, `unsigned`, `malformed`). A notification that names another app than the session's is dropped and counted
|
|
1431
|
+
too (`wrongApp`), since a session is in one app. The one exception is a refusal of a send,
|
|
1432
|
+
which the next section covers. The largest datagram a fleet session is sent is 1,242 bytes.
|
|
1433
|
+
|
|
1434
|
+
### A refused send is signed, and the handler says so
|
|
1435
|
+
|
|
1436
|
+
The `genericError` handler receives a refused send and a second argument, `verified`. A
|
|
1437
|
+
refusal is 3 bytes: the message type, the sequence number of the send, and a code. It names
|
|
1438
|
+
no player, so match its sequence number against the numbers your sends resolved with.
|
|
1439
|
+
|
|
1440
|
+
- **`verified` is true for a refusal that arrived inside a bundle the session verified with
|
|
1441
|
+
the fleet token.** Realtime servers from v0.50.3 send a fleet session every refusal that
|
|
1442
|
+
way.
|
|
1443
|
+
- **`verified` is false for a refusal that arrived alone.** 3 bytes leave no room for a
|
|
1444
|
+
signature, so anyone who can reach the session's socket could have sent it. Treat one as
|
|
1445
|
+
a hint: stop sending for that player, then carry the player again or check their access
|
|
1446
|
+
through the Application API, and act on that answer. A carry's answer is always verified.
|
|
1447
|
+
- **The session changes nothing on a refusal**, whatever its code and whether or not it is
|
|
1448
|
+
verified. Your code decides what a refusal means for the player.
|
|
1449
|
+
- **`TOKEN_EXPIRED` is about a carried player's token.** A send that lands just before the
|
|
1450
|
+
player's token expires is answered `TOKEN_EXPIRED`, and `released` follows with reason 2.
|
|
1451
|
+
The fleet token's own expiry reaches the `sessionReleased` handler with reason 2, in a
|
|
1452
|
+
signed message.
|
|
1453
|
+
|
|
1454
|
+
`UNAUTHORIZED` has nine causes, and the refusal does not say which one applies:
|
|
1455
|
+
|
|
1456
|
+
| Why the send was refused | What to do |
|
|
1457
|
+
| --- | --- |
|
|
1458
|
+
| It names the player's previous `gameTokenId` after a carry with a refreshed token took effect | `FleetSession` names the new id for you. With the codecs alone, name the new id. |
|
|
1459
|
+
| The session no longer carries the player: you released them, they idled out, their sign-in ended, or another session carries them | Carry the player again if your server should still serve them. |
|
|
1460
|
+
| The player lacks a permission the message needs: access to the app, voice, video, text, direct messages, or voxel writes | Grant the permission, or stop sending that kind of message for the player. |
|
|
1461
|
+
| The platform could not read the permissions for that part of the world within 2 seconds, or too many sends were waiting for them | Send again. |
|
|
1462
|
+
| The actor belongs to another player | Send for an actor only under the player who owns it. |
|
|
1463
|
+
| The platform could not confirm whose actor it is within 2 seconds | Send again. |
|
|
1464
|
+
| A communication rule refuses the message: a minor's direct message, or a kind of communication that is switched off | Nothing. The message is not delivered. |
|
|
1465
|
+
| The player's access to the app was suspended or ended | Stop serving the player. |
|
|
1466
|
+
| The message went under the session's own `gameTokenId` and is not one of its four kinds | Send it under a carried player's id. `FleetSession` never sends one. |
|
|
1467
|
+
|
|
1468
|
+
Three other outcomes of a send are not `UNAUTHORIZED`:
|
|
1469
|
+
|
|
1470
|
+
- **A player over their message budget** gets no answer. The message is dropped.
|
|
1471
|
+
- **A player whose token expired** gets `TOKEN_EXPIRED`, then `released` with reason 2.
|
|
1472
|
+
- **A paused app** gets `APP_PAUSED`.
|
|
1473
|
+
|
|
1474
|
+
### The session refreshes before it expires, and follows a move
|
|
1475
|
+
|
|
1476
|
+
`fleet.refreshDue()` is true once 12 of the session's 24 hours have passed. It is also true
|
|
1477
|
+
as soon as the realtime server tells the session to connect to another server, releases it,
|
|
1478
|
+
or says nothing for 45 seconds (the `moveOrdered` and `sessionReleased` handlers). Call
|
|
1479
|
+
`refreshFleetSession` then, with `fleet.refreshInput()`, and give the answer to
|
|
1480
|
+
`fleet.applyRefresh`.
|
|
1481
|
+
|
|
1482
|
+
The realtime server signs both messages, and the session acts on them only after it has
|
|
1483
|
+
verified them. `sessionReleased` carries a reason: 0 means the fleet token was revoked (the
|
|
1484
|
+
session was closed through the Application API, or its organization token was revoked), 2
|
|
1485
|
+
means the fleet token expired, and 1, 3, and 4 mean the server stopped serving the session
|
|
1486
|
+
(it heard nothing from the session, it shed load, or it moved the session). Every reason
|
|
1487
|
+
makes a refresh due.
|
|
1488
|
+
|
|
1489
|
+
- **`refreshInput()` names the server the session is on**, so the session stays there
|
|
1490
|
+
while that server still serves the app. After a move order it names no server, and the
|
|
1491
|
+
answer's `server` is the next one.
|
|
1492
|
+
- **The same server:** the carries stand. The session sends its capabilities at once,
|
|
1493
|
+
because after a refresh the server sends the session nothing until it hears from it.
|
|
1494
|
+
- **Another server**, or the same one after it released the session or went quiet: the
|
|
1495
|
+
session connects, sends its capabilities, and carries every player again with a new time
|
|
1496
|
+
and proof, paced as above. Until a player's answer arrives, sends for that player reject
|
|
1497
|
+
with `FleetNotCarriedError`. Each answer reaches the `carryResult` handler.
|
|
1498
|
+
- **A refresh refused `NOT_FOUND`** means the session ended. Open a new one and carry your
|
|
1499
|
+
players again.
|
|
1500
|
+
- **A session closed through the Application API is told.** If `closeFleetSession` ends a
|
|
1501
|
+
session while its `FleetSession` is still open, the realtime server sends it a signed
|
|
1502
|
+
release with reason 0 within seconds: `sessionReleased` fires, `refreshDue()` turns true,
|
|
1503
|
+
and `refreshFleetSession` then answers `NOT_FOUND`. Open a new session and carry your
|
|
1504
|
+
players again. That one message can be lost. The session also sends its capabilities
|
|
1505
|
+
every 15 seconds and expects a signed acknowledgement of each, so about 45 seconds after
|
|
1506
|
+
the close (`silenceTimeoutMs`) `refreshDue()` turns true and `moveOrdered` fires in any
|
|
1507
|
+
case.
|
|
1508
|
+
|
|
1509
|
+
### The server connects to hubs as itself
|
|
1510
|
+
|
|
1511
|
+
`client.exec.connectAsServer(appId)` opens one hub connection for the game server, with the
|
|
1512
|
+
org token as the client's bearer. Its plain calls are the server's own, and `callAs` makes a
|
|
1513
|
+
call for one of your players:
|
|
1514
|
+
|
|
1515
|
+
```ts
|
|
1516
|
+
const hubs = await api.exec.connectAsServer(appId);
|
|
1517
|
+
|
|
1518
|
+
await hubs.call('lobby', '', 'report', { players: roster.size }); // the server's own call
|
|
1519
|
+
await hubs.callAs(carry.userId, 'player', playerKey, 'grant', { gold: 10 }); // for a player
|
|
1520
|
+
```
|
|
1521
|
+
|
|
1522
|
+
- **A hub sees `Caller::Org`**, with the player the server named or none. Crowded Kingdoms
|
|
1523
|
+
checks that the connection is your organization's. The player a call names is your
|
|
1524
|
+
organization's word, so a hub treats `Caller::Org { player }` as "this organization's
|
|
1525
|
+
server says so".
|
|
1526
|
+
- **`player` is the player's user id** (`FleetCarryResult.userId`), as a `bigint`, a decimal
|
|
1527
|
+
string, or a safe integer.
|
|
1528
|
+
- **Limits.** A server connection has a budget of 2,000 calls a second, and an organization
|
|
1529
|
+
holds at most 256 server connections to one app on one execution host.
|
|
1530
|
+
- **Hubs built with ckx-sdk before 0.15** answer such a call `Denied` until they are built
|
|
1531
|
+
again.
|
|
1532
|
+
- **On any other connection `callAs` is refused locally** with `Denied`, and nothing is
|
|
1533
|
+
sent.
|
|
1534
|
+
- **The connection reconnects** with a fresh server connect token, as a player's does.
|
|
1535
|
+
`onAccessEnded` fires when the org token is revoked or fleet sessions are switched off.
|
|
1536
|
+
On Node before 22, pass `{ WebSocket }` from the `ws` package, as for `connect`.
|
|
1537
|
+
|
|
1538
|
+
### Refusals carry a code
|
|
1539
|
+
|
|
1540
|
+
The four calls raise `CrowdyGraphQLError`. Branch on `extensions.code` with these readers:
|
|
1541
|
+
|
|
1542
|
+
| `extensions.code` | Meaning | Reader |
|
|
1543
|
+
| --- | --- | --- |
|
|
1544
|
+
| `ORG_TOKEN_REQUIRED` | The bearer is not an org token | `orgTokenRequiredOf(err)` |
|
|
1545
|
+
| `ORG_TOKEN_NOT_ALLOWED` | The request came from a browser (it carried an `Origin` header) | `err.code` |
|
|
1546
|
+
| `FLEET_SESSION_LIMIT` | `open`: the organization holds as many sessions as it may | `fleetSessionLimitOf(err)` |
|
|
1547
|
+
| `NOT_FOUND` | `refresh`: the session expired, was closed, or was opened with another org token | `fleetSessionNotFoundOf(err)` |
|
|
1548
|
+
| `PLATFORM_BUSY` | The platform could not start the call in time. Wait `retryAfterMs`, then call again | `platformBusyOf(err)` |
|
|
1549
|
+
| `ORG_LEGAL_ACCEPTANCE_REQUIRED` | An admin has not accepted the current Org-Managed Players Addendum | `orgLegalAcceptanceRequiredOf(err)` |
|
|
1550
|
+
| `FORBIDDEN` | Fleet sessions are not switched on for the organization, or the org token lacks the `fleet:session` scope | `err.code` |
|
|
1551
|
+
| `SCOPE_MISSING` | The app is not in the org token's app list | `err.code` |
|
|
1552
|
+
|
|
1553
|
+
### Keep the tokens out of your logs, and know what a replay can do
|
|
1554
|
+
|
|
1555
|
+
- **Never log the answers of `fleetSessions.open`, `fleetSessions.refresh`, or
|
|
1556
|
+
`exec.serverEndpoint`.** The first two contain the fleet token, and the third contains a
|
|
1557
|
+
hub connect token. A `FleetSession` shows no token when you log or serialize it.
|
|
1558
|
+
- **The hub connect token travels in the WebSocket URL's query string**, as a player's does.
|
|
1559
|
+
It lasts one minute, and the connection asks for a new one at each reconnect. Keep that
|
|
1560
|
+
URL out of your logs too.
|
|
1561
|
+
- **A replayed `FLEET_RELEASED` makes the session report a player released.** The frame is
|
|
1562
|
+
signed, so a copy that someone captured verifies when it is sent again. If the player is
|
|
1563
|
+
still on your server, carry them again.
|
|
1564
|
+
- **The UDP socket is connected to the realtime server's address**, so the operating system
|
|
1565
|
+
drops datagrams from any other address before the session sees them.
|
|
1566
|
+
|
|
1567
|
+
### The wire codecs are pure functions
|
|
1568
|
+
|
|
1569
|
+
A server on another JavaScript runtime can build and read the messages itself, over its
|
|
1570
|
+
own UDP socket. The root entry point exports the codecs, which use WebCrypto and no I/O: `createFleetSignContext`,
|
|
1571
|
+
`carriedPlayerContext` (the signing context that gives any `serialize*` function the tail
|
|
1572
|
+
of a carried player's message), `fleetCarryProof`, `serializeFleetCarry`,
|
|
1573
|
+
`serializeFleetRelease`, `serializeActorHeartbeat`, and `parseFleetDatagram`, which
|
|
1574
|
+
verifies a datagram and returns its carry results, releases, deliveries, and notifications.
|
|
1575
|
+
|
|
1199
1576
|
## Hosting your game
|
|
1200
1577
|
|
|
1201
1578
|
Crowded Kingdoms no longer hosts games: on 2026-10-29 it retired Crowdy Games, with
|
|
@@ -1435,6 +1812,9 @@ still mints tokens: check `isAppPaused(token.runtimeGate)` (or the bootstrap's `
|
|
|
1435
1812
|
before entering the world. For org-managed players: `assertionRejectedOf(err)`
|
|
1436
1813
|
(`ASSERTION_REJECTED`, with the failed check as `reason`) and `managedPlayerNotAllowedOf(err)`
|
|
1437
1814
|
(`MANAGED_PLAYER_NOT_ALLOWED`: no wallet, or mods the organization has not switched on).
|
|
1815
|
+
For an organization's game servers: `orgTokenRequiredOf(err)` (`ORG_TOKEN_REQUIRED`),
|
|
1816
|
+
`fleetSessionLimitOf(err)` (`FLEET_SESSION_LIMIT`), `fleetSessionNotFoundOf(err)` (`NOT_FOUND`
|
|
1817
|
+
on a fleet session's refresh), and `platformBusyOf(err)` (`PLATFORM_BUSY`, with `retryAfterMs`).
|
|
1438
1818
|
|
|
1439
1819
|
The player gate and player safety (18.24.0): `legalAcceptanceRequiredOf(err)`
|
|
1440
1820
|
(`LEGAL_ACCEPTANCE_REQUIRED`, with the `missingDocuments`), `ageRequiredOf(err)` (`AGE_REQUIRED`),
|
|
@@ -1549,6 +1929,21 @@ refused, and the players are deleted. `CROWDY_E2E_UNDER13_SIGNUP=1` also signs u
|
|
|
1549
1929
|
ck-api v2.61.0 that blocks every sign-up from the machine's address and user agent for 24 hours,
|
|
1550
1930
|
so do not set it on a shared builder.
|
|
1551
1931
|
|
|
1932
|
+
`test/e2e/fleet-sessions.test.mjs` plays an organization's two game servers against a tier's
|
|
1933
|
+
realtime servers. It runs only with `CROWDY_FLEET_API_URL` (the GraphQL endpoint),
|
|
1934
|
+
`CROWDY_FLEET_APP_ID`, and `CROWDY_FLEET_ORG_TOKEN` (scopes `players:mint` and `fleet:session`)
|
|
1935
|
+
all set. It opens two fleet sessions, signs in four managed players
|
|
1936
|
+
(`crowdyjs-fleet-e2e-0` to `-3`), carries them, sends and receives state and text, moves one
|
|
1937
|
+
player from one server to the other, refreshes a session, refreshes one player's token and
|
|
1938
|
+
carries the player again while they send, and closes everything. It also opens a third
|
|
1939
|
+
session, closes it through the Application API, and waits for that session to see that a
|
|
1940
|
+
refresh is due.
|
|
1941
|
+
`CROWDY_FLEET_HUB_APP_ID` adds the hub server connection, and `CROWDY_FLEET_IDLE_SECONDS` (the
|
|
1942
|
+
app's idle timeout) adds a wait for one player's idle release. The suite leaves the four
|
|
1943
|
+
players, which every run reuses, and their sign-ins, which last 10 minutes. It prints no token.
|
|
1944
|
+
Its last step fails when the realtime server sent a session anything that is not its own
|
|
1945
|
+
(another app's state, or an unsigned notification), which the SDK drops and counts.
|
|
1946
|
+
|
|
1552
1947
|
## Maintainers: schema artifacts and fixtures
|
|
1553
1948
|
|
|
1554
1949
|
CrowdyJS is a standalone public package: a clean clone builds with
|
|
@@ -1582,6 +1977,10 @@ refresh them from an explicitly supplied source:
|
|
|
1582
1977
|
- The agent tool-descriptor fixture:
|
|
1583
1978
|
`npm run agent-descriptors:drift -- --source <application-api-fixture>`; every
|
|
1584
1979
|
build re-checks the digests.
|
|
1980
|
+
- The ck-exec client frames, `test/unit/fixtures/exec-client-frames.json`: a copy of
|
|
1981
|
+
ck-exec's golden frames, which hold the call-as frame (`0x05`).
|
|
1982
|
+
- The fleet session's golden vectors, in `test/unit/fleet-wire.test.mjs`: the test builds
|
|
1983
|
+
each one with `node:crypto` from the inputs in its header, which the other SDKs use too.
|
|
1585
1984
|
|
|
1586
1985
|
## Migration
|
|
1587
1986
|
|