@zaisma/game-server 1.44.0 → 1.46.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/bin/local-play.js CHANGED
@@ -325,6 +325,8 @@ export async function startLocalPlay(givenOptions) {
325
325
  }
326
326
  }
327
327
  const glass = await loadGlass(localFolder);
328
+ // A mode a player's band no longer has (13–15's solo-focused, since chat left the presets): their band's own start.
329
+ for (const account of state.accounts) if (!glass.isSocialModeAllowed(account.ageBand, account.socialMode)) account.socialMode = glass.startingSocialMode(account.ageBand);
328
330
  const accountOf = (id) => state.accounts.find((account) => account.id === id) ?? null;
329
331
  const accountOfPlayer = (playerId) => state.accounts.find((account) => account.playerId === playerId) ?? null;
330
332
  const asOf = (playerNumber) => state.tabs[playerNumber] ?? "guest";
@@ -370,12 +372,15 @@ export async function startLocalPlay(givenOptions) {
370
372
  const nowSec = Math.floor(now() / 1000);
371
373
  const account = as === "guest" ? null : accountOf(as);
372
374
  const player = account ? { id: account.playerId, name: account.username, kind: "account" } : { ...guestOf(playerNumber), kind: "guest" };
373
- // Who they chat with, by Zaisma's own rules for their age and social mode, and an opaque chat group for their band, never the age.
374
- const chat = account ? glass.chatOf(account.ageBand, account.socialMode) : null;
375
+ // How their chat reaches, by Zaisma's own rules for their age, and an opaque chat group for their band, never the age.
376
+ // who_can_chat is v1's stricter stand-in, for servers that don't read who_reads_my_chat. The bench seals no network:
377
+ // its own chat check lets every message through.
378
+ const chat = account ? glass.chatOf(account.ageBand) : null;
375
379
  const claims = account
376
380
  ? {
377
381
  sub: account.playerId, aud: gameSlug, iss: issuerUrl, pass_version_number: PASS_VERSION_NUMBER, kind: "account",
378
- who_can_chat: chat.whoCanChat, ...(chat.bandGroup ? { chat_group_id: `chat_group_${createHash("sha256").update(`local:${gameSlug}:${chat.bandGroup}`).digest("hex").slice(0, 24)}` } : {}),
382
+ who_can_chat: chat.whoReadsMyChat === "friends" ? "friends" : "anyone", who_reads_my_chat: chat.whoReadsMyChat, chat_reading_enabled: true,
383
+ chat_group_id: `chat_group_${createHash("sha256").update(`local:${gameSlug}:${chat.bandGroup}`).digest("hex").slice(0, 24)}`,
379
384
  player_tag_id: account.playerTagId, friend_player_tag_ids: tagsOf(friendIdsOf(account.id)), block_player_tag_ids: tagsOf(blockIdsOf(account.id)),
380
385
  owned_item_names: ownedNamesOf(account.id), iat: nowSec, exp: nowSec + PASS_DURATION_SEC,
381
386
  }
@@ -568,7 +573,7 @@ export async function startLocalPlay(givenOptions) {
568
573
  // --- The bench's API: everything the Players panel and the dev bar do, as JSON, for the developer's AI as much as for the panel ---
569
574
  // Players are named by their player_id, the ID games see. Answers and errors are shaped as Zaisma's developer API's.
570
575
  const apiPlayer = (account) => ({
571
- player_id: account.playerId, name: account.username, age_band: account.ageBand, social_mode: account.socialMode, who_can_chat: glass.chatOf(account.ageBand, account.socialMode).whoCanChat,
576
+ player_id: account.playerId, name: account.username, age_band: account.ageBand, social_mode: account.socialMode, who_reads_my_chat: glass.chatOf(account.ageBand).whoReadsMyChat,
572
577
  open_player_numbers: openNumbersOf(account), friend_player_ids: playerIdsOf(friendIdsOf(account.id)), block_player_ids: playerIdsOf(blockedIdsOf(account)),
573
578
  blocked_by_player_ids: playerIdsOf(blockerIdsOf(account)), owned_item_names: ownedNamesOf(account.id),
574
579
  });
@@ -1328,10 +1333,31 @@ export async function startLocalPlay(givenOptions) {
1328
1333
  }
1329
1334
  return notLocal();
1330
1335
  }
1331
- // Zaisma's chat check, as the runner's rooms ask it for room.chat (checkChat): the bench lets every message through,
1332
- // nothing flagged, the way /v1/filter stands in below. Zaisma's own filter runs once the game is on Zaisma.
1336
+ // Zaisma's chat check, as the runner's rooms ask it for room.chat (checkChat). The bench keeps Zaisma's witness rule, so
1337
+ // a game sees here what it will there: a message an under-18 sends or reads goes only where two other players read it
1338
+ // (every bench player counts as established, each on a network of its own), and a stranger from outside Zaisma never
1339
+ // chats with an under-18. Its words aren't checked, nothing is flagged, the way /v1/filter stands in below.
1333
1340
  if (request.method === "POST" && path === "/v1/chat/check") {
1334
- await readBody();
1341
+ const body = await readBody();
1342
+ const subOf = (pass) => {
1343
+ if (typeof pass !== "string") return null;
1344
+ try {
1345
+ return JSON.parse(Buffer.from(pass.split(".")[1] ?? "", "base64url").toString("utf8")).sub ?? null;
1346
+ } catch {
1347
+ return null;
1348
+ }
1349
+ };
1350
+ const senderId = subOf(body.senderPass);
1351
+ const passes = Array.isArray(body.receiverPasses) ? body.receiverPasses : [];
1352
+ const readerIds = [...new Set(passes.map(subOf).filter((id) => id !== null && id !== senderId))];
1353
+ const isMinor = (playerId) => {
1354
+ const account = playerId === null ? null : accountOfPlayer(playerId);
1355
+ return account !== null && account.ageBand !== "18+";
1356
+ };
1357
+ const hasMinor = isMinor(senderId) || readerIds.some(isMinor);
1358
+ const hasOutsider = body.senderPass === null || passes.some((pass) => pass === null);
1359
+ const isWitnessed = readerIds.filter((id) => accountOfPlayer(id) !== null).length >= 2;
1360
+ if (hasMinor && (hasOutsider || !isWitnessed)) return reply(200, { isAllowed: false, reason: "not_allowed_to_chat", message: "Chat isn't open for this message.", hasSwearing: false, hasSlur: false });
1335
1361
  return reply(200, { isAllowed: true, reason: null, message: null, hasSwearing: false, hasSlur: false });
1336
1362
  }
1337
1363
  if (request.method === "POST" && ["/v1/pass", "/v1/rooms", "/v1/report", "/v1/filter", "/v1/friends", "/v1/friends/room", "/v1/items/unhandled", "/v1/items/handled"].includes(path)) {
package/bin/node.js CHANGED
@@ -26,7 +26,7 @@ import { createServer } from "node:http";
26
26
  import { fileURLToPath, pathToFileURL } from "node:url";
27
27
  import { basename, dirname, join, resolve } from "node:path";
28
28
  import { readFileSync, realpathSync } from "node:fs";
29
- import { roomMessageProblem, BUSY_CLOSE_CODE, ENDED_CLOSE_CODE, ERROR_TEXT, NO_ANSWER_CLOSE_CODE, PASS_ISSUER_URL, OUTSIDE_ZAISMA_CHAT_SETTINGS, PassError, ReceiptError, REMOVED_CLOSE_CODE, REQUEST_ERROR_HTTP_STATUS, REQUEST_LIMITS, ROOM_LIMITS, ROOM_MESSAGE_LIMITS, ROOM_TUNING, WEBHOOK_LIMITS, GameServerError, RoomCore, chatSettingsOf, checkChat, readChatMessage, restoreInfoOf, passesAreFriends, passesHaveBlockBetween, answerRequest, startSchedules, checkRoomData, checkedOutsidePlayer, clientIdle, defineGameServer, errorMessage, guestPlayer, newServer, isPlayerToken, isRoomCode, readRequestBody, relay, requestError, runWebhook, tidyRoomInfo, verifyPass, verifyReceipt, verifyWebhook } from "../src/internal.js";
29
+ import { CHAT_CHECK_LIMITS, roomMessageProblem, BUSY_CLOSE_CODE, ENDED_CLOSE_CODE, ERROR_TEXT, NO_ANSWER_CLOSE_CODE, PASS_ISSUER_URL, OUTSIDE_ZAISMA_CHAT_SETTINGS, PassError, ReceiptError, REMOVED_CLOSE_CODE, REQUEST_ERROR_HTTP_STATUS, REQUEST_LIMITS, ROOM_LIMITS, ROOM_MESSAGE_LIMITS, ROOM_TUNING, WEBHOOK_LIMITS, GameServerError, RoomCore, chatSettingsOf, checkChat, readChatMessage, restoreInfoOf, passesAreFriends, passesHaveBlockBetween, answerRequest, startSchedules, checkRoomData, checkedOutsidePlayer, clientIdle, defineGameServer, errorMessage, guestPlayer, newServer, isPlayerToken, isRoomCode, readRequestBody, relay, requestError, runWebhook, tidyRoomInfo, verifyPass, verifyReceipt, verifyWebhook } from "../src/internal.js";
30
30
  import { OutsideCallError } from "../src/outside-calls.js";
31
31
  import { startFastLane } from "./fast-lane.js";
32
32
  import { checkedStartServerOptions, dataFilesFrom, loadWasmAsModules, localDatabase, localRoomStates, passKeysFrom, profilesFrom, receiptKeysFrom, secretsFromEnvironment } from "./node-parts.js";
@@ -565,8 +565,10 @@ export function startServer(options) {
565
565
  /**
566
566
  * A player's chat message (room.chat): the room checks it and asks the game server's onChat (startChat),
567
567
  * Zaisma's filter looks (checkChat, with the passes of those who may read it), and it goes to them
568
- * (deliverChat) or the sender hears why not (stopChat). Everyone it may reach is in the sender's chat
569
- * group, so the first CHAT_CHECK_LIMITS.maximumReceiverCount of them stand for the rest.
568
+ * (deliverChat) or the sender hears why not (stopChat). More readers than one check takes go in checks of
569
+ * CHAT_CHECK_LIMITS.maximumReceiverCount, each a full one (the last overlaps the one before), so each sees
570
+ * witnesses as the whole room has them, and every one must allow it. Zaisma may have let it through only for
571
+ * the witnesses it counted, so it goes to every reader or, when one can't read it by then, is stopped.
570
572
  */
571
573
  async function chatIn(room, playerId, chat) {
572
574
  const started = await room.core.startChat(playerId, chat);
@@ -576,10 +578,17 @@ export function startServer(options) {
576
578
  // A player from outside Zaisma goes as null: Zaisma stops their chat with under-18 accounts, and doesn't hear chat among them alone.
577
579
  const passOf = (id) => (room.core.players.get(id)?.kind === "outside_zaisma" ? null : (room.passTexts.get(id) ?? ""));
578
580
  const receiverPasses = started.receiverPlayerIds.map(passOf);
579
- check = await checkChat({ text: started.text, senderPass: passOf(playerId), receiverPasses, isAdultFilterEnabled: definition.adultChatFilterEnabled === true });
581
+ const batchReceiverCount = CHAT_CHECK_LIMITS.maximumReceiverCount;
582
+ for (let endIndex = Math.min(batchReceiverCount, receiverPasses.length); ; endIndex = Math.min(endIndex + batchReceiverCount, receiverPasses.length)) {
583
+ const batch = receiverPasses.slice(Math.max(0, endIndex - batchReceiverCount), endIndex);
584
+ const batchCheck = await checkChat({ text: started.text, senderPass: passOf(playerId), receiverPasses: batch, isAdultFilterEnabled: definition.adultChatFilterEnabled === true });
585
+ check = { ...batchCheck, hasSwearing: check.hasSwearing || batchCheck.hasSwearing, hasSlur: check.hasSlur || batchCheck.hasSlur };
586
+ if (!batchCheck.isAllowed || endIndex === receiverPasses.length) break;
587
+ }
580
588
  }
581
- if (check.isAllowed) room.core.deliverChat(playerId, chat.chatNumber, started.receiverPlayerIds, { text: started.text, hasSwearing: check.hasSwearing, hasSlur: check.hasSlur });
582
- else room.core.stopChat(playerId, chat.chatNumber, check.reason ?? "unchecked", check.message ?? "");
589
+ if (!check.isAllowed) return room.core.stopChat(playerId, chat.chatNumber, check.reason ?? "unchecked", check.message ?? "");
590
+ const isDelivered = room.core.deliverChat(playerId, chat.chatNumber, started.receiverPlayerIds, { text: started.text, hasSwearing: check.hasSwearing, hasSlur: check.hasSlur }, { isEveryReaderNeeded: true });
591
+ if (!isDelivered) room.core.stopChat(playerId, chat.chatNumber, "not_allowed_to_chat", "Chat isn't open for this message.");
583
592
  }
584
593
 
585
594
  /** Keep a room for players on their way, even if it empties meanwhile. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zaisma/game-server",
3
- "version": "1.44.0",
3
+ "version": "1.46.0",
4
4
  "description": "Run your Zaisma game server: the same rooms on Zaisma or on your own server.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://zaisma.com",
package/sdk/zaisma.d.ts CHANGED
@@ -1596,10 +1596,11 @@ declare namespace Zaisma {
1596
1596
  * game's own keys at https://rooms.zaisma.com/v1/pass-keys/<gameSlug>. It proves only who the player is: its sub
1597
1597
  * is the player's ID, kind says guest or account, aud is the game, pass_version_number is 1. A
1598
1598
  * guest's pass also carries their name; an account's name comes from its profile
1599
- * (https://rooms.zaisma.com/v1/players/<id>). An account's pass says who it can chat with:
1600
- * who_can_chat (nobody, friends or anyone, the player's own setting) and, when anyone, an opaque
1601
- * chat_group_id (chat_group_…) that differs in every game. Zaisma never tells a game anyone's age; a
1602
- * game could guess which chat group is the younger one from its size. It carries its friends and
1599
+ * (https://rooms.zaisma.com/v1/players/<id>). An account's pass says how its chat reaches:
1600
+ * who_reads_my_chat (friends, my_age_band or everyone; nobody while its chat is stopped), chat_reading_enabled,
1601
+ * an opaque chat_group_id (chat_group_…) that differs in every game, network_seal (its network, sealed for
1602
+ * Zaisma's witness rule alone), and v1's who_can_chat as a stricter stand-in. Zaisma never tells a game anyone's
1603
+ * age; a game could guess which chat group is the younger one from its size. It carries its friends and
1603
1604
  * blocks, never as a list of players anyone can read: player_tag_id, its own opaque tag in this game
1604
1605
  * (player_tag_…), friend_player_tag_ids, its friends' tags (up to 200), and block_player_tag_ids, the
1605
1606
  * tags of the accounts it has a block with, either way (up to 100). Your own server checks it with
package/src/chat.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  /**
2
- * Zaisma's chat filter for your own server (docs/DECISIONS.md, "The text filter catches what matters and
3
- * leaves the rest alone"). Every chat message to or from an under-18 account is checked on Zaisma's side:
4
- * contact details in any disguise, moving to another app or meeting up, personal details and sexual
5
- * content are stopped. Swearing and slurs are only flagged (hasSwearing, hasSlur): blocking them is your
6
- * call. Between adults it only flags, unless you turn the filter on for them too (isAdultFilterEnabled).
7
- * The answer is one verdict for the whole message, never per receiver, so it never says who's under 18.
2
+ * Zaisma's chat check for your own server ("Chat with witnesses"). Every chat message an under-18 account sends or
3
+ * reads is checked on Zaisma's side, by two rules: it goes only where at least two independent players read it
4
+ * (established accounts on networks unlike the sender's and each other's, whispers and two-player rooms included),
5
+ * and it can't carry contact details, moving to another app or meeting up, in any disguise. Swearing and slurs are
6
+ * only flagged (hasSwearing, hasSlur): blocking them is your call. Between adults it only flags, unless you turn
7
+ * the filter on for them too (isAdultFilterEnabled). The answer is one verdict for the whole message, never per
8
+ * receiver; a message stopped between two players does show that one of them is under 18. Send the passes of the
9
+ * players who really read it: your server is trusted to, as it's trusted to call this at all.
8
10
  *
9
11
  * checkChat sends the players' passes (as your server received them) and the sender's last few messages to
10
12
  * Zaisma (POST <issuer>/v1/chat/check), so a phone number sent a few digits at a time is caught too.
@@ -18,8 +20,9 @@
18
20
  * server running there never sees passes, and checkChat throws a ChatCheckError (own_server_only).
19
21
  */
20
22
  /**
21
- * Why a message was stopped. The same reasons as Zaisma.checkChat, plus chat_paused, not_allowed_to_chat and
22
- * unchecked (Zaisma couldn't be reached). slur is v1's and no longer given: slurs are flagged (hasSlur), never stopped.
23
+ * Why a message was stopped: contact_details, chat_paused, too_long, not_allowed_to_chat (canChat says no for a
24
+ * receiver, or too few independent players read a message an under-18 is in) and unchecked (Zaisma couldn't be
25
+ * reached). personal_details, sexual and slur are v1's and no longer given.
23
26
  */
24
27
  export type ChatCheckReason = "contact_details" | "personal_details" | "slur" | "sexual" | "chat_paused" | "unchecked" | "too_long" | "not_allowed_to_chat";
25
28
  export interface ChatCheck {
@@ -28,7 +31,8 @@ export interface ChatCheck {
28
31
  /**
29
32
  * Why not; null when it's allowed. chat_paused: the sender's chat is paused or removed. unchecked: your
30
33
  * server couldn't reach Zaisma, so don't deliver it (try again in a moment). too_long: over 2000 characters.
31
- * not_allowed_to_chat: canChat says the sender and a receiver may not chat (Zaisma checks it too).
34
+ * not_allowed_to_chat: canChat says a receiver may not read the sender (Zaisma checks it too), or the message has
35
+ * an under-18 in it and fewer than two independent players read it.
32
36
  */
33
37
  reason: ChatCheckReason | null;
34
38
  /** The words to show the sender when it's stopped (never mentions age or the other player); null when it's allowed. */
@@ -45,7 +49,7 @@ export interface ChatCheckOptions {
45
49
  senderPass: string | null;
46
50
  /** The passes of everyone it would reach, up to 50; null for each player from outside Zaisma. */
47
51
  receiverPasses: (string | null)[];
48
- /** Check chat between adults too, as for under-18s; each message Zaisma's AI looks at counts on your hosting meter. False by default. */
52
+ /** Check chat between adults for contact details too, as for under-18s. Free. False by default. */
49
53
  isAdultFilterEnabled?: boolean;
50
54
  }
51
55
  /** Chat in rooms (room.chat), for both Zaisma's rooms and your own server's runner: past any human's typing, so it only stops floods. */
@@ -73,10 +77,10 @@ export declare class ChatCheckError extends Error {
73
77
  constructor(message: string, fix: string);
74
78
  }
75
79
  /**
76
- * Check one chat message with Zaisma's filter. Call it on every chat message your server delivers, after
77
- * canChat says the players may chat, and deliver it only when isAllowed (Zaisma applies canChat's rule
78
- * too, so a message to anyone who may not chat is stopped). It's free, except the checks of chat between
79
- * adults when isAdultFilterEnabled. When Zaisma can't be reached it answers unchecked: don't deliver the message.
80
+ * Check one chat message with Zaisma's filter. Call it on every chat message your server delivers, with the passes
81
+ * of everyone who'd read it, after canChat(sender, reader) says each may, and deliver it only when isAllowed, to all
82
+ * of them (Zaisma applies canChat's rule too, and may allow it only for the witnesses among them). It's free. When
83
+ * Zaisma can't be reached it answers unchecked: don't deliver the message.
80
84
  * The runner (zaisma-game-server) does all this for room.chat in its rooms.
81
85
  *
82
86
  * const check = await checkChat({ text, senderPass, receiverPasses: [receiverPass] });
package/src/chat.js CHANGED
@@ -1,10 +1,12 @@
1
1
  /**
2
- * Zaisma's chat filter for your own server (docs/DECISIONS.md, "The text filter catches what matters and
3
- * leaves the rest alone"). Every chat message to or from an under-18 account is checked on Zaisma's side:
4
- * contact details in any disguise, moving to another app or meeting up, personal details and sexual
5
- * content are stopped. Swearing and slurs are only flagged (hasSwearing, hasSlur): blocking them is your
6
- * call. Between adults it only flags, unless you turn the filter on for them too (isAdultFilterEnabled).
7
- * The answer is one verdict for the whole message, never per receiver, so it never says who's under 18.
2
+ * Zaisma's chat check for your own server ("Chat with witnesses"). Every chat message an under-18 account sends or
3
+ * reads is checked on Zaisma's side, by two rules: it goes only where at least two independent players read it
4
+ * (established accounts on networks unlike the sender's and each other's, whispers and two-player rooms included),
5
+ * and it can't carry contact details, moving to another app or meeting up, in any disguise. Swearing and slurs are
6
+ * only flagged (hasSwearing, hasSlur): blocking them is your call. Between adults it only flags, unless you turn
7
+ * the filter on for them too (isAdultFilterEnabled). The answer is one verdict for the whole message, never per
8
+ * receiver; a message stopped between two players does show that one of them is under 18. Send the passes of the
9
+ * players who really read it: your server is trusted to, as it's trusted to call this at all.
8
10
  *
9
11
  * checkChat sends the players' passes (as your server received them) and the sender's last few messages to
10
12
  * Zaisma (POST <issuer>/v1/chat/check), so a phone number sent a few digits at a time is caught too.
@@ -77,10 +79,10 @@ function rememberText(senderPlayerId, text, nowMs) {
77
79
  recentBySender.set(senderPlayerId, recent.slice(-CHAT_CHECK_LIMITS.recentTextCount));
78
80
  }
79
81
  /**
80
- * Check one chat message with Zaisma's filter. Call it on every chat message your server delivers, after
81
- * canChat says the players may chat, and deliver it only when isAllowed (Zaisma applies canChat's rule
82
- * too, so a message to anyone who may not chat is stopped). It's free, except the checks of chat between
83
- * adults when isAdultFilterEnabled. When Zaisma can't be reached it answers unchecked: don't deliver the message.
82
+ * Check one chat message with Zaisma's filter. Call it on every chat message your server delivers, with the passes
83
+ * of everyone who'd read it, after canChat(sender, reader) says each may, and deliver it only when isAllowed, to all
84
+ * of them (Zaisma applies canChat's rule too, and may allow it only for the witnesses among them). It's free. When
85
+ * Zaisma can't be reached it answers unchecked: don't deliver the message.
84
86
  * The runner (zaisma-game-server) does all this for room.chat in its rooms.
85
87
  *
86
88
  * const check = await checkChat({ text, senderPass, receiverPasses: [receiverPass] });
package/src/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export { SCHEDULE_LIMITS, type Schedule, type ScheduledRun } from "./schedules.t
4
4
  export { WEBHOOK_LIMITS, verifyWebhook, type WebhookError, type WebhookErrorCode, type WebhookEvent, type WebhookEventKind, type WebhookHeaders } from "./webhooks.ts";
5
5
  export { DATABASE_LIMITS, DatabaseError, type DatabaseErrorCode, type DatabaseRow, type DatabaseStatement, type DatabaseValue, type GameDatabase } from "./database.ts";
6
6
  export { OUTSIDE_CALL_LIMITS, OutsideCallError, type OutsideCallErrorCode } from "./outside-calls.ts";
7
- export { PASS_ISSUER_URL, PASS_TOKEN_TYPE, PASS_VERSION_NUMBER, PassError, RECEIPT_ISSUER_URL, RECEIPT_TOKEN_TYPE, RECEIPT_VERSION_NUMBER, ReceiptError, canChat, passesAreFriends, passesHaveBlockBetween, verifyPass, verifyReceipt, type PassClaims, type PassErrorCode, type PassExpectations, type PlayerKind, type PublicKey, type ReceiptClaims, type ReceiptErrorCode, type ReceiptExpectations, type WhoCanChat } from "./pass.ts";
7
+ export { PASS_ISSUER_URL, PASS_TOKEN_TYPE, PASS_VERSION_NUMBER, PassError, RECEIPT_ISSUER_URL, RECEIPT_TOKEN_TYPE, RECEIPT_VERSION_NUMBER, ReceiptError, canChat, passesAreFriends, passesHaveBlockBetween, verifyPass, verifyReceipt, type PassClaims, type PassErrorCode, type PassExpectations, type PlayerKind, type PublicKey, type ReceiptClaims, type ReceiptErrorCode, type ReceiptExpectations, type WhoCanChat, type WhoReadsMyChat, type ChatReach } from "./pass.ts";
8
8
  export { CHAT_CHECK_LIMITS, CHAT_ROOM_LIMITS, ChatCheckError, checkChat, type ChatCheck, type ChatCheckOptions, type ChatCheckReason } from "./chat.ts";
9
9
  export { guestName, isRoomCode } from "./names.ts";
10
10
  export { guestPlayer, signInWithZaismaPlayers, type IdentifyPlayer, type OutsidePlayer, type SignInWithZaismaPlayersOptions } from "./outside-players.ts";
package/src/pass.d.ts CHANGED
@@ -22,15 +22,28 @@ export interface PassClaims {
22
22
  /** guest or account, or a kind added later: treat one your server doesn't know as a guest. */
23
23
  kind: PlayerKind | (string & {});
24
24
  /**
25
- * Who an account lets chat with it: nobody, its friends, or anyone in its chat group, or a choice
26
- * added later (canChat matches only the ones it knows, so an unknown one chats with nobody).
27
- * Guests' passes have none: guests don't chat.
25
+ * v1's chat setting, still sent for servers that don't read who_reads_my_chat: a stricter stand-in for it
26
+ * (nobody when the account's chat is stopped or it reads no chat, friends for Friends, anyone otherwise),
27
+ * read by canChat only on a pass without who_reads_my_chat. Guests' passes have none: guests don't chat.
28
28
  */
29
29
  who_can_chat?: WhoCanChat | (string & {});
30
30
  /**
31
- * For accounts that chat at all (friends or anyone), the group they can chat in (chat_group_…): two
32
- * players chat only when their groups match (canChat), friends included. Opaque and different in every
33
- * game, so it never says an age; a game could guess which group is the younger one from its size.
31
+ * Who reads what this account types: its friends in its chat group, anyone in its chat group, everyone, or
32
+ * nobody while its chat is stopped; a choice added later reaches nobody. Guests' passes have none.
33
+ */
34
+ who_reads_my_chat?: WhoReadsMyChat | "nobody" | (string & {});
35
+ /** Whether this account reads others' chat at all: false when the player turned it off. Guests' passes have none. */
36
+ chat_reading_enabled?: boolean;
37
+ /**
38
+ * The player's network, sealed for Zaisma alone with a fresh nonce on every pass: it says nothing to your
39
+ * server, and two seals of one network look nothing alike. Zaisma's chat check opens it for the witness rule
40
+ * (anyone under 18 types only where two independent players read it). Pass it on as it is, in the pass.
41
+ */
42
+ network_seal?: string;
43
+ /**
44
+ * An account's chat group (chat_group_…): Friends and My age band reach only the same group, and only a
45
+ * sender who chose Everyone crosses it. Opaque and different in every game, so it never says an age; a game
46
+ * could guess which group is the younger one from its size.
34
47
  */
35
48
  chat_group_id?: string;
36
49
  /**
@@ -68,8 +81,26 @@ export interface PassClaims {
68
81
  * guest from elsewhere (outsideGuestsEnabled). Zaisma's rooms and passes never give outside_zaisma.
69
82
  */
70
83
  export type PlayerKind = "guest" | "account" | "outside_zaisma";
71
- /** No chat, friends only, or anyone in the same chat group: the player's "Who can chat with you" setting (docs/DECISIONS.md, "Social settings, with the social modes as presets"). */
84
+ /** v1's chat setting: no chat, friends only, or anyone in the same chat group, both ways. who_reads_my_chat replaces it. */
72
85
  export type WhoCanChat = "nobody" | "friends" | "anyone";
86
+ /** Who reads what a player types: friends in their chat group, anyone in it, or everyone (the only choice that crosses chat groups). */
87
+ export type WhoReadsMyChat = "friends" | "my_age_band" | "everyone";
88
+ /** How far one side of chat reaches: a sender's who_reads_my_chat, or whose chat a reader reads. */
89
+ export type ChatReach = "nobody" | "friends" | "my_age_band" | "everyone";
90
+ /**
91
+ * How far a pass's chat reaches, sending and reading. A pass with who_reads_my_chat says so directly (and reads
92
+ * everyone's chat unless chat_reading_enabled is false); a v1 pass's who_can_chat counts for both sides, as v1's
93
+ * two-way rule did (friends: friends; anyone: the chat group). Guests and unknown choices reach nobody.
94
+ */
95
+ export declare function chatReachOf(claims: Pick<PassClaims, "kind" | "who_can_chat" | "who_reads_my_chat" | "chat_reading_enabled">): {
96
+ sending: ChatReach;
97
+ reading: ChatReach;
98
+ };
99
+ /** Whether one side's reach takes in the other player: everyone; the same chat group; or a friend in it. */
100
+ export declare function isWithinChatReach(reach: ChatReach, other: {
101
+ isSameChatGroup: boolean;
102
+ isFriend: boolean;
103
+ }): boolean;
73
104
  /** A pass's JWS header typ (RFC 8725 explicit typing): verifyPass refuses any other token (wrong_kind). */
74
105
  export declare const PASS_TOKEN_TYPE = "pass+jwt";
75
106
  /** The pass contract this copy reads: verifyPass refuses any other pass_version_number (wrong_version). */
@@ -92,12 +123,12 @@ export declare function passesHaveBlockBetween(first: PassClaims, second: PassCl
92
123
  */
93
124
  export declare function passesAreFriends(first: PassClaims, second: PassClaims): boolean;
94
125
  /**
95
- * Whether two players may chat, by the passes your server checked (verifyPass): both accounts in the same
96
- * chat group, no block between them, neither letting nobody chat, and either friends or both letting
97
- * anyone chat. Guests and accounts set to nobody never chat; accounts set to friends chat only with
98
- * friends (passesAreFriends); friends in different chat groups don't chat. Use it on every message your
99
- * own server delivers, text or voice; Zaisma's chat check (checkChat) applies the same rule, and so do
100
- * rooms (room.chat), on Zaisma and in the runner.
126
+ * Whether the first player's chat may reach the second: first is the sender, second the reader, and the order
127
+ * matters (ask both ways for a two-way check, like voice between two players). Both accounts, no block between
128
+ * them, the reader reads chat, and the sender's choice takes the reader in: everyone; anyone in the same chat
129
+ * group (My age band); or a friend in it (passesAreFriends). Guests never chat. Use it on every message your own
130
+ * server delivers, text or voice; Zaisma's chat check (checkChat) applies the same rule, and the witness rule on
131
+ * top (anyone under 18 types only where two independent players read it), and so do rooms (room.chat).
101
132
  */
102
133
  export declare function canChat(first: PassClaims, second: PassClaims): boolean;
103
134
  export type PublicKey = JsonWebKey & {
package/src/pass.js CHANGED
@@ -3,6 +3,29 @@
3
3
  * and so can any developer's own server, using its game's keys, published at
4
4
  * /v1/pass-keys/<gameSlug>. Any JWT library that supports EdDSA works.
5
5
  */
6
+ /**
7
+ * How far a pass's chat reaches, sending and reading. A pass with who_reads_my_chat says so directly (and reads
8
+ * everyone's chat unless chat_reading_enabled is false); a v1 pass's who_can_chat counts for both sides, as v1's
9
+ * two-way rule did (friends: friends; anyone: the chat group). Guests and unknown choices reach nobody.
10
+ */
11
+ export function chatReachOf(claims) {
12
+ if (claims.kind !== "account")
13
+ return { sending: "nobody", reading: "nobody" };
14
+ if (claims.who_reads_my_chat !== undefined) {
15
+ const sending = ["friends", "my_age_band", "everyone"].find((reach) => reach === claims.who_reads_my_chat) ?? "nobody";
16
+ return { sending, reading: claims.chat_reading_enabled === false ? "nobody" : "everyone" };
17
+ }
18
+ const reach = claims.who_can_chat === "friends" ? "friends" : claims.who_can_chat === "anyone" ? "my_age_band" : "nobody";
19
+ return { sending: reach, reading: reach };
20
+ }
21
+ /** Whether one side's reach takes in the other player: everyone; the same chat group; or a friend in it. */
22
+ export function isWithinChatReach(reach, other) {
23
+ if (reach === "everyone")
24
+ return true;
25
+ if (reach === "my_age_band")
26
+ return other.isSameChatGroup;
27
+ return reach === "friends" && other.isSameChatGroup && other.isFriend;
28
+ }
6
29
  /** A pass's JWS header typ (RFC 8725 explicit typing): verifyPass refuses any other token (wrong_kind). */
7
30
  export const PASS_TOKEN_TYPE = "pass+jwt";
8
31
  /** The pass contract this copy reads: verifyPass refuses any other pass_version_number (wrong_version). */
@@ -44,12 +67,12 @@ export function passesAreFriends(first, second) {
44
67
  return lists(first, second) && lists(second, first);
45
68
  }
46
69
  /**
47
- * Whether two players may chat, by the passes your server checked (verifyPass): both accounts in the same
48
- * chat group, no block between them, neither letting nobody chat, and either friends or both letting
49
- * anyone chat. Guests and accounts set to nobody never chat; accounts set to friends chat only with
50
- * friends (passesAreFriends); friends in different chat groups don't chat. Use it on every message your
51
- * own server delivers, text or voice; Zaisma's chat check (checkChat) applies the same rule, and so do
52
- * rooms (room.chat), on Zaisma and in the runner.
70
+ * Whether the first player's chat may reach the second: first is the sender, second the reader, and the order
71
+ * matters (ask both ways for a two-way check, like voice between two players). Both accounts, no block between
72
+ * them, the reader reads chat, and the sender's choice takes the reader in: everyone; anyone in the same chat
73
+ * group (My age band); or a friend in it (passesAreFriends). Guests never chat. Use it on every message your own
74
+ * server delivers, text or voice; Zaisma's chat check (checkChat) applies the same rule, and the witness rule on
75
+ * top (anyone under 18 types only where two independent players read it), and so do rooms (room.chat).
53
76
  */
54
77
  export function canChat(first, second) {
55
78
  mustBePasses(first, second, "canChat");
@@ -57,13 +80,10 @@ export function canChat(first, second) {
57
80
  return false;
58
81
  if (passesHaveBlockBetween(first, second))
59
82
  return false;
60
- const isOpenTo = (whoCanChat) => whoCanChat === "friends" || whoCanChat === "anyone";
61
- if (!isOpenTo(first.who_can_chat) || !isOpenTo(second.who_can_chat))
83
+ if (typeof first.chat_group_id !== "string" || typeof second.chat_group_id !== "string")
62
84
  return false;
63
- // Chat never leaves a chat group, friends included.
64
- if (typeof first.chat_group_id !== "string" || first.chat_group_id !== second.chat_group_id)
65
- return false;
66
- return passesAreFriends(first, second) || (first.who_can_chat === "anyone" && second.who_can_chat === "anyone");
85
+ const other = { isSameChatGroup: first.chat_group_id === second.chat_group_id, isFriend: passesAreFriends(first, second) };
86
+ return isWithinChatReach(chatReachOf(first).sending, other) && isWithinChatReach(chatReachOf(second).reading, other);
67
87
  }
68
88
  // Plain class fields (no TypeScript-only syntax) so Node can run this file directly.
69
89
  export class PassError extends Error {
@@ -188,6 +208,12 @@ export async function verifyPass(token, keys, expect) {
188
208
  throw new PassError("malformed");
189
209
  if (claims.chat_group_id !== undefined && typeof claims.chat_group_id !== "string")
190
210
  throw new PassError("malformed");
211
+ if (claims.who_reads_my_chat !== undefined && typeof claims.who_reads_my_chat !== "string")
212
+ throw new PassError("malformed");
213
+ if (claims.chat_reading_enabled !== undefined && typeof claims.chat_reading_enabled !== "boolean")
214
+ throw new PassError("malformed");
215
+ if (claims.network_seal !== undefined && typeof claims.network_seal !== "string")
216
+ throw new PassError("malformed");
191
217
  if (claims.player_tag_id !== undefined && typeof claims.player_tag_id !== "string")
192
218
  throw new PassError("malformed");
193
219
  if (claims.friend_player_tag_ids !== undefined && !isStringList(claims.friend_player_tag_ids))
package/src/room.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import { type GameDatabase } from "./database.ts";
10
10
  import { type DoorContract, type DoorShape } from "./doors.ts";
11
- import type { PassClaims, PlayerKind, ReceiptClaims } from "./pass.ts";
11
+ import { type ChatReach, type PassClaims, type PlayerKind, type ReceiptClaims } from "./pass.ts";
12
12
  import type { Server } from "./requests.ts";
13
13
  import { type Schedule, type ScheduledRun } from "./schedules.ts";
14
14
  import { type StateChange } from "./state-sync.ts";
@@ -444,9 +444,8 @@ export interface GameServer<S = any> {
444
444
  stateSyncEnabled?: boolean;
445
445
  /**
446
446
  * Check chat between adults (room.chat) with Zaisma's filter too: contact details, moving apps or
447
- * meeting up, personal details and sexual content are stopped, as they always are for under-18s. Off by
448
- * default, when chat between adults is only flagged (hasSwearing, hasSlur) and your game decides. Each
449
- * message the filter's AI looks at counts on your hosting meter (adult_chat_checks).
447
+ * meeting up are stopped, as they always are where an under-18 sends or reads. Off by default, when chat
448
+ * between adults is only flagged (hasSwearing, hasSlur) and your game decides. Free.
450
449
  */
451
450
  adultChatFilterEnabled?: boolean;
452
451
  /**
@@ -1319,20 +1318,23 @@ export declare function errorMessage(code: RoomErrorCode, message?: string, deta
1319
1318
  chatNumber: number;
1320
1319
  }): string;
1321
1320
  /**
1322
- * Who an account player may chat with, from their pass (who_can_chat and chat_group_id): kept by the
1323
- * room's host, never shown to the game. A guest has none and chats with nobody.
1321
+ * How far an account player's chat reaches, from their pass (chatReachOf): who reads what they type (sending),
1322
+ * whose chat they read (reading), their chat group, and their sealed network for Zaisma's witness rule. Kept by
1323
+ * the room's host, never shown to the game. A guest has none and chats with nobody.
1324
1324
  */
1325
1325
  export interface PlayerChatSettings {
1326
- whoCanChat: "nobody" | "friends" | "anyone";
1326
+ sending: ChatReach;
1327
+ reading: ChatReach;
1327
1328
  chatGroupId: string | null;
1329
+ networkSeal: string | null;
1328
1330
  }
1329
1331
  /**
1330
- * The chat settings of a player your own server let in from outside Zaisma (outside_zaisma): they chat with
1331
- * anyone who chats with anyone, in no chat group, and Zaisma's chat check stops any message between them and
1332
- * an under-18 account. Zaisma's chat groups are chat_group_… IDs, so none is ever this one.
1332
+ * The chat settings of a player your own server let in from outside Zaisma (outside_zaisma): they send to and read
1333
+ * everyone, in a chat group of their own, and Zaisma's chat check stops any message between them and an under-18
1334
+ * account. Zaisma's chat groups are chat_group_… IDs, so none is ever this one.
1333
1335
  */
1334
1336
  export declare const OUTSIDE_ZAISMA_CHAT_SETTINGS: PlayerChatSettings;
1335
- /** A checked pass's chat settings, for RoomCore.setChatSettings: null for a guest. A setting this version doesn't know chats with nobody. */
1337
+ /** A checked pass's chat settings, for RoomCore.setChatSettings: null for a guest. A choice this version doesn't know reaches nobody. */
1336
1338
  export declare function chatSettingsOf(claims: PassClaims): PlayerChatSettings | null;
1337
1339
  /** A chat message from a client as readChatMessage found it, for startChat to check. */
1338
1340
  export interface ChatClientMessage {
@@ -1710,13 +1712,14 @@ export declare class RoomCore<S = any> {
1710
1712
  setFriends(playerId: string, friendPlayerIds: readonly string[]): void;
1711
1713
  /** A player's chat settings from their pass, before join: null for a guest, who chats with nobody. */
1712
1714
  setChatSettings(playerId: string, settings: PlayerChatSettings | null): void;
1713
- /** Whether a player can chat at all: an account whose setting isn't nobody, with a chat group. */
1715
+ /** Whether a player can send chat at all: an account whose chat isn't stopped, with a chat group. */
1714
1716
  canChat(playerId: string): boolean;
1717
+ /** A player's sealed network from their pass, for Zaisma's witness rule: null for a guest, a player from outside Zaisma or an older pass. */
1718
+ networkSealOf(playerId: string): string | null;
1715
1719
  /**
1716
- * Whether one player's chat may reach another, canChat's rule on passes (pass.ts): two accounts in the
1717
- * same chat group with no block either way, friends unless both chat with anyone. A player from outside
1718
- * Zaisma is in no chat group: they chat with anyone who chats with anyone, and Zaisma's chat check stops
1719
- * what would reach an under-18 account or come from one.
1720
+ * Whether one player's chat may reach another, canChat's rule on passes (pass.ts), sender to reader: no block
1721
+ * either way, the reader reads chat, and the sender's choice takes the reader in (everyone; the same chat group;
1722
+ * a friend in it). Zaisma's chat check stops what would reach an under-18 account without witnesses.
1720
1723
  */
1721
1724
  private mayChat;
1722
1725
  /** Who a player's chat may reach: the players in the match (or those of toPlayerIds in it), never spectators, kept only where they may chat. */
@@ -1735,13 +1738,16 @@ export declare class RoomCore<S = any> {
1735
1738
  } | null>;
1736
1739
  /**
1737
1740
  * Send a chat message Zaisma's filter let through to its receivers, and tell the sender it went
1738
- * (chat_sent), even when it reached nobody: the sender never learns who can't read them.
1741
+ * (chat_sent), even when it reached nobody: the sender never learns who can't read them. With isEveryReaderNeeded
1742
+ * (Zaisma counted witnesses among them) it sends nothing and answers false when any of them can't read it now.
1739
1743
  */
1740
1744
  deliverChat(senderPlayerId: string, chatNumber: number, receiverPlayerIds: readonly string[], chat: {
1741
1745
  text: string;
1742
1746
  hasSwearing: boolean;
1743
1747
  hasSlur: boolean;
1744
- }): void;
1748
+ }, options?: {
1749
+ isEveryReaderNeeded?: boolean;
1750
+ }): boolean;
1745
1751
  /** Tell the sender their chat message was stopped: reason is the filter's, or stopped_by_game; message is what they see. */
1746
1752
  stopChat(senderPlayerId: string, chatNumber: number, reason: string, message: string): void;
1747
1753
  /** A player's chat messages from the last CHAT_CHECK_LIMITS.recentTextDurationMs, oldest first, up to recentTextCount. */