@zaisma/game-server 1.29.0 → 1.31.0
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/bench/brand/README.md +1 -1
- package/bench/brand/sign-in/city-day-phone.webp +0 -0
- package/bench/brand/sign-in/city-day.webp +0 -0
- package/bench/brand/sign-in/city-night-phone.webp +0 -0
- package/bench/brand/sign-in/city-night.webp +0 -0
- package/bench/glass.js +3570 -448
- package/bin/local-play.js +1 -1
- package/bin/node-parts.js +1 -1
- package/bin/node.d.ts +1 -1
- package/bin/node.js +2 -2
- package/package.json +1 -1
- package/sdk/zaisma.d.ts +1 -1
- package/src/doors.d.ts +14 -0
- package/src/doors.js +26 -3
- package/src/pass.d.ts +2 -2
- package/src/pass.js +2 -2
- package/bench/brand/world/day-phone.webp +0 -0
- package/bench/brand/world/day.webp +0 -0
- package/bench/brand/world/night-phone.webp +0 -0
- package/bench/brand/world/night.webp +0 -0
package/bin/local-play.js
CHANGED
|
@@ -1244,7 +1244,7 @@ export async function startLocalPlay(givenOptions) {
|
|
|
1244
1244
|
response.writeHead(204, { ...cors, "Access-Control-Allow-Methods": "GET, POST", "Access-Control-Allow-Headers": "Content-Type" });
|
|
1245
1245
|
return response.end();
|
|
1246
1246
|
}
|
|
1247
|
-
if (path ===
|
|
1247
|
+
if (path === `/v1/pass-keys/${gameSlug}`) return reply(200, jwks([passSigning.publicKey]), { "Access-Control-Allow-Origin": "*" });
|
|
1248
1248
|
if (path === "/.well-known/receipt-jwks.json") return reply(200, jwks([receiptSigning.publicKey]), { "Access-Control-Allow-Origin": "*" });
|
|
1249
1249
|
const readBody = async () => {
|
|
1250
1250
|
const chunks = [];
|
package/bin/node-parts.js
CHANGED
|
@@ -40,7 +40,7 @@ function keysFrom(jwksUrl) {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
/** The pass keys a JWKS URL publishes (Zaisma's: <issuerUrl
|
|
43
|
+
/** The pass keys a JWKS URL publishes (Zaisma's, for one game: <issuerUrl>/v1/pass-keys/<gameSlug>), as startServer's loadPassKeys takes them. */
|
|
44
44
|
export function passKeysFrom(jwksUrl) {
|
|
45
45
|
return keysFrom(jwksUrl);
|
|
46
46
|
}
|
package/bin/node.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface StartServerOptions {
|
|
|
13
13
|
origins?: string[];
|
|
14
14
|
/** Who signs your players' passes. Default https://rooms.zaisma.com (PASS_ISSUER_URL). */
|
|
15
15
|
issuerUrl?: string;
|
|
16
|
-
/** The keys that check passes. Default: the ones `<issuerUrl
|
|
16
|
+
/** The keys that check passes. Default: this game's, the ones `<issuerUrl>/v1/pass-keys/<gameSlug>` publishes, kept an hour. Called with true to fetch them again. */
|
|
17
17
|
loadPassKeys?: (isRefreshing?: boolean) => Promise<PublicKey[]>;
|
|
18
18
|
/** The keys that check receipts (room.verifyReceipt). Default: the ones `<issuerUrl>/.well-known/receipt-jwks.json` publishes. */
|
|
19
19
|
loadReceiptKeys?: (isRefreshing?: boolean) => Promise<PublicKey[]>;
|
package/bin/node.js
CHANGED
|
@@ -64,7 +64,7 @@ const CATCH_UP_MS = 50;
|
|
|
64
64
|
* wrong kind a bad_option, before anything listens): gameServer (a game server object) and gameSlug
|
|
65
65
|
* (its Zaisma slug) are required. port (8080), origins (allowed page origins, by default
|
|
66
66
|
* https://<gameSlug>.zaismausercontent.com; none allows any page), issuerUrl (who signs the passes; Zaisma's),
|
|
67
|
-
* loadPassKeys (async (isRefreshing) => the pass keys; by default from <issuerUrl
|
|
67
|
+
* loadPassKeys (async (isRefreshing) => the pass keys; by default this game's, from <issuerUrl>/v1/pass-keys/<gameSlug>),
|
|
68
68
|
* loadReceiptKeys (the same for room.verifyReceipt and server.verifyReceipt; by default from
|
|
69
69
|
* <issuerUrl>/.well-known/receipt-jwks.json), loadProfile (async (playerId) => an account's public profile or null),
|
|
70
70
|
* database (room.database and server.database; by default a local file, zaisma-database.sqlite, made the
|
|
@@ -84,7 +84,7 @@ const CATCH_UP_MS = 50;
|
|
|
84
84
|
* has stopped; fastLaneReady settles once the fast lane listens (at once without one), or rejects saying why it can't.
|
|
85
85
|
*/
|
|
86
86
|
export function startServer(options) {
|
|
87
|
-
const { gameServer, gameSlug, port: portNumber, origins, issuerUrl, loadPassKeys = passKeysFrom(`${issuerUrl}
|
|
87
|
+
const { gameServer, gameSlug, port: portNumber, origins, issuerUrl, loadPassKeys = passKeysFrom(`${issuerUrl}/v1/pass-keys/${gameSlug}`), loadReceiptKeys = receiptKeysFrom(`${issuerUrl}/.well-known/receipt-jwks.json`), loadProfile = profilesFrom(issuerUrl), database = localDatabase("zaisma-database.sqlite"), secrets = secretsFromEnvironment(), webhookSigningSecret = process.env.ZAISMA_WEBHOOK_SIGNING_SECRET, roomStateFile = "zaisma-room-states.sqlite", zaismaKey = process.env.ZAISMA_KEY, developerApiUrl = "https://zaisma.com/api/dev", webtransportPort, certificatePath, certificateKeyPath, identifyPlayer, outsideGuestsEnabled } = checkedStartServerOptions(options, PASS_ISSUER_URL);
|
|
88
88
|
const definition = defineGameServer(gameServer);
|
|
89
89
|
// Exactly once needs Zaisma's record of what's handled: without a key, purchases would come twice, so it doesn't start.
|
|
90
90
|
if ((definition.onPurchase || definition.onRefund) && !zaismaKey) {
|
package/package.json
CHANGED
package/sdk/zaisma.d.ts
CHANGED
|
@@ -1563,7 +1563,7 @@ declare namespace Zaisma {
|
|
|
1563
1563
|
interface PlayerWithPass extends Player {
|
|
1564
1564
|
/**
|
|
1565
1565
|
* The player pass: a standard EdDSA JWT (header typ "pass+jwt") any server can check against the
|
|
1566
|
-
* keys at https://rooms.zaisma.com
|
|
1566
|
+
* game's own keys at https://rooms.zaisma.com/v1/pass-keys/<gameSlug>. It proves only who the player is: its sub
|
|
1567
1567
|
* is the player's ID, kind says guest or account, aud is the game, pass_version_number is 1. A
|
|
1568
1568
|
* guest's pass also carries their name; an account's name comes from its profile
|
|
1569
1569
|
* (https://rooms.zaisma.com/v1/players/<id>). An account's pass says who it can chat with:
|
package/src/doors.d.ts
CHANGED
|
@@ -161,8 +161,22 @@ export interface DoorLimitBinding {
|
|
|
161
161
|
key: string;
|
|
162
162
|
}): Promise<object>;
|
|
163
163
|
}
|
|
164
|
+
/** Where a Worker writes what real traffic needs of each counter: Workers Analytics Engine, as Workers gives it. */
|
|
165
|
+
export interface LimitNeedsDataset {
|
|
166
|
+
writeDataPoint(point: {
|
|
167
|
+
indexes?: string[];
|
|
168
|
+
blobs?: string[];
|
|
169
|
+
doubles?: number[];
|
|
170
|
+
}): void;
|
|
171
|
+
}
|
|
164
172
|
export type DoorLimitBindings = {
|
|
165
173
|
[Level in DoorLimitLevel as `LIMIT_${Uppercase<Level>}`]?: DoorLimitBinding;
|
|
174
|
+
} & {
|
|
175
|
+
LIMIT_NEEDS?: LimitNeedsDataset;
|
|
176
|
+
};
|
|
177
|
+
/** The level just below each one, whose number a counter's real traffic is held against before a lower limit ships (scripts/limit-needs.mjs). */
|
|
178
|
+
export declare const LOWER_DOOR_LIMIT_LEVEL: {
|
|
179
|
+
readonly [Level in DoorLimitLevel]: DoorLimitLevel | null;
|
|
166
180
|
};
|
|
167
181
|
/** Whether a call goes past a level's limit: door's own counter, for one subject. Keys never leave Cloudflare's counter. */
|
|
168
182
|
export declare function isPastLevel(env: DoorLimitBindings, level: DoorLimitLevel, counterName: string, subject: string): Promise<boolean>;
|
package/src/doors.js
CHANGED
|
@@ -36,13 +36,36 @@ export const DOOR_NO_LIMIT_REASONS = {
|
|
|
36
36
|
counted_by_its_call: "All it does is make calls that have their own limit.",
|
|
37
37
|
room_token_bucket: "A room's message bucket takes a token for each message, per player, before any door runs.",
|
|
38
38
|
};
|
|
39
|
+
/** The level just below each one, whose number a counter's real traffic is held against before a lower limit ships (scripts/limit-needs.mjs). */
|
|
40
|
+
export const LOWER_DOOR_LIMIT_LEVEL = { very_rare: null, guess: "very_rare", rare: "guess", steady: "rare", busy: "steady", building: "busy" };
|
|
41
|
+
const bindingOf = (env, level) => env[`LIMIT_${level.toUpperCase()}`];
|
|
42
|
+
const isRefused = (answer) => !("success" in answer && answer.success === true);
|
|
39
43
|
/** Whether a call goes past a level's limit: door's own counter, for one subject. Keys never leave Cloudflare's counter. */
|
|
40
44
|
export async function isPastLevel(env, level, counterName, subject) {
|
|
41
|
-
const binding = env
|
|
45
|
+
const binding = bindingOf(env, level);
|
|
42
46
|
if (!binding)
|
|
43
47
|
return false;
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
if (isRefused(await binding.limit({ key: `${counterName}:${subject}` })))
|
|
49
|
+
return true;
|
|
50
|
+
await noteLimitNeed(env, level, counterName, subject);
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Notes a counter whose real traffic passed the level below its own, so a change that lowers its limit is held at ship
|
|
55
|
+
* (scripts/limit-needs.mjs). Only the counter's name and level are written, never the subject, and at most twice a
|
|
56
|
+
* minute per counter and level in each Cloudflare location. A Worker without the dataset or the level below's binding notes nothing.
|
|
57
|
+
*/
|
|
58
|
+
async function noteLimitNeed(env, level, counterName, subject) {
|
|
59
|
+
const lowerLevel = LOWER_DOOR_LIMIT_LEVEL[level];
|
|
60
|
+
const lowerBinding = lowerLevel && bindingOf(env, lowerLevel);
|
|
61
|
+
const noteBinding = bindingOf(env, "very_rare");
|
|
62
|
+
if (!env.LIMIT_NEEDS || !lowerLevel || !lowerBinding || !noteBinding)
|
|
63
|
+
return;
|
|
64
|
+
if (!isRefused(await lowerBinding.limit({ key: `need:${counterName}:${subject}` })))
|
|
65
|
+
return;
|
|
66
|
+
if (isRefused(await noteBinding.limit({ key: `need_noted:${counterName}:${level}` })))
|
|
67
|
+
return;
|
|
68
|
+
env.LIMIT_NEEDS.writeDataPoint({ indexes: [counterName], blobs: [counterName, level, lowerLevel], doubles: [DOOR_LIMIT_LEVELS[lowerLevel]] });
|
|
46
69
|
}
|
|
47
70
|
/** Whether a call goes past a door's limit. doorName names its counter unless its limit shares a group. */
|
|
48
71
|
export async function isPastDoorLimit(env, limit, doorName, subject) {
|
package/src/pass.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Player passes: standard JWTs signed with Ed25519 (EdDSA). Our rooms check them,
|
|
3
|
-
* and so can any developer's own server, using
|
|
4
|
-
*
|
|
3
|
+
* and so can any developer's own server, using its game's keys, published at
|
|
4
|
+
* /v1/pass-keys/<gameSlug>. Any JWT library that supports EdDSA works.
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* What a pass proves: who the player is, for which game, until when. Nothing more; anything else
|
package/src/pass.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Player passes: standard JWTs signed with Ed25519 (EdDSA). Our rooms check them,
|
|
3
|
-
* and so can any developer's own server, using
|
|
4
|
-
*
|
|
3
|
+
* and so can any developer's own server, using its game's keys, published at
|
|
4
|
+
* /v1/pass-keys/<gameSlug>. Any JWT library that supports EdDSA works.
|
|
5
5
|
*/
|
|
6
6
|
/** A pass's JWS header typ (RFC 8725 explicit typing): verifyPass refuses any other token (wrong_kind). */
|
|
7
7
|
export const PASS_TOKEN_TYPE = "pass+jwt";
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|