@zaisma/game-server 1.43.0 → 1.45.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/glass.js +1060 -206
- package/bin/local-play.js +33 -7
- package/bin/node.js +15 -6
- package/package.json +1 -1
- package/sdk/zaisma.d.ts +13 -7
- package/sdk/zaisma.js +55 -2
- package/src/chat.d.ts +18 -14
- package/src/chat.js +12 -10
- package/src/index.d.ts +1 -1
- package/src/pass.d.ts +44 -13
- package/src/pass.js +38 -12
- package/src/room.d.ts +24 -18
- package/src/room.js +38 -21
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
|
|
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
|
|
448
|
-
*
|
|
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
|
-
*
|
|
1323
|
-
*
|
|
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
|
-
|
|
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
|
|
1331
|
-
*
|
|
1332
|
-
*
|
|
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
|
|
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
|
|
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)
|
|
1717
|
-
*
|
|
1718
|
-
*
|
|
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
|
-
}
|
|
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. */
|
package/src/room.js
CHANGED
|
@@ -10,6 +10,7 @@ import { CHAT_CHECK_LIMITS, CHAT_ROOM_LIMITS } from "./chat.js";
|
|
|
10
10
|
import { DatabaseError } from "./database.js";
|
|
11
11
|
import { answersJson, checkDoor, fieldsOf, gameData, listOf, orNothing, realNumber, schemaProblems, text as textUpTo, yesOrNo } from "./doors.js";
|
|
12
12
|
import { isRoomCode, roomCode } from "./names.js";
|
|
13
|
+
import { chatReachOf, isWithinChatReach } from "./pass.js";
|
|
13
14
|
import { readSchedules } from "./schedules.js";
|
|
14
15
|
import { roomCallChecks } from "./room-calls.js";
|
|
15
16
|
import { newStateTracker } from "./state-sync.js";
|
|
@@ -475,17 +476,25 @@ export function errorMessage(code, message, details) {
|
|
|
475
476
|
return JSON.stringify({ type: "error", code, message: message || ERROR_TEXT[code], ...details });
|
|
476
477
|
}
|
|
477
478
|
/**
|
|
478
|
-
* The chat settings of a player your own server let in from outside Zaisma (outside_zaisma): they
|
|
479
|
-
*
|
|
480
|
-
*
|
|
479
|
+
* The chat settings of a player your own server let in from outside Zaisma (outside_zaisma): they send to and read
|
|
480
|
+
* everyone, in a chat group of their own, and Zaisma's chat check stops any message between them and an under-18
|
|
481
|
+
* account. Zaisma's chat groups are chat_group_… IDs, so none is ever this one.
|
|
481
482
|
*/
|
|
482
|
-
export const OUTSIDE_ZAISMA_CHAT_SETTINGS = {
|
|
483
|
-
/** A checked pass's chat settings, for RoomCore.setChatSettings: null for a guest. A
|
|
483
|
+
export const OUTSIDE_ZAISMA_CHAT_SETTINGS = { sending: "everyone", reading: "everyone", chatGroupId: "outside_zaisma", networkSeal: null };
|
|
484
|
+
/** A checked pass's chat settings, for RoomCore.setChatSettings: null for a guest. A choice this version doesn't know reaches nobody. */
|
|
484
485
|
export function chatSettingsOf(claims) {
|
|
485
486
|
if (claims.kind !== "account")
|
|
486
487
|
return null;
|
|
487
|
-
|
|
488
|
-
|
|
488
|
+
return { ...chatReachOf(claims), chatGroupId: typeof claims.chat_group_id === "string" ? claims.chat_group_id : null, networkSeal: typeof claims.network_seal === "string" ? claims.network_seal : null };
|
|
489
|
+
}
|
|
490
|
+
/** Chat settings a room saved, in today's shape: one saved before who_reads_my_chat reads as v1's two-way setting did. */
|
|
491
|
+
function savedChatSettings(saved) {
|
|
492
|
+
const chatGroupId = typeof saved.chatGroupId === "string" ? saved.chatGroupId : null;
|
|
493
|
+
const networkSeal = typeof saved.networkSeal === "string" ? saved.networkSeal : null;
|
|
494
|
+
if (saved.sending !== undefined && saved.reading !== undefined)
|
|
495
|
+
return { sending: saved.sending, reading: saved.reading, chatGroupId, networkSeal };
|
|
496
|
+
const reach = chatGroupId === OUTSIDE_ZAISMA_CHAT_SETTINGS.chatGroupId ? "everyone" : saved.whoCanChat === "friends" ? "friends" : saved.whoCanChat === "anyone" ? "my_age_band" : "nobody";
|
|
497
|
+
return { sending: reach, reading: reach, chatGroupId, networkSeal };
|
|
489
498
|
}
|
|
490
499
|
/** Room traffic of chat, in the room's message types. */
|
|
491
500
|
export const CHAT_MESSAGE_TYPE = "(chat)";
|
|
@@ -955,7 +964,7 @@ export class RoomCore {
|
|
|
955
964
|
for (const [first, second] of saved.friendships ?? [])
|
|
956
965
|
this.friendships.add(pairKey(first, second));
|
|
957
966
|
for (const [id, settings] of Object.entries(saved.chatSettings ?? {}))
|
|
958
|
-
this.chatSettings.set(id, settings);
|
|
967
|
+
this.chatSettings.set(id, savedChatSettings(settings));
|
|
959
968
|
}
|
|
960
969
|
else if (startOptions.start) {
|
|
961
970
|
const start = startOptions.start;
|
|
@@ -1181,31 +1190,34 @@ export class RoomCore {
|
|
|
1181
1190
|
/** A player's chat settings from their pass, before join: null for a guest, who chats with nobody. */
|
|
1182
1191
|
setChatSettings(playerId, settings) {
|
|
1183
1192
|
if (settings)
|
|
1184
|
-
this.chatSettings.set(playerId, {
|
|
1193
|
+
this.chatSettings.set(playerId, { sending: settings.sending, reading: settings.reading, chatGroupId: settings.chatGroupId, networkSeal: settings.networkSeal });
|
|
1185
1194
|
else if (!this.chatSettings.delete(playerId))
|
|
1186
1195
|
return;
|
|
1187
1196
|
this.dirty = true;
|
|
1188
1197
|
}
|
|
1189
|
-
/** Whether a player can chat at all: an account whose
|
|
1198
|
+
/** Whether a player can send chat at all: an account whose chat isn't stopped, with a chat group. */
|
|
1190
1199
|
canChat(playerId) {
|
|
1191
1200
|
const settings = this.chatSettings.get(playerId);
|
|
1192
|
-
return settings !== undefined && settings.
|
|
1201
|
+
return settings !== undefined && settings.sending !== "nobody" && settings.chatGroupId !== null;
|
|
1202
|
+
}
|
|
1203
|
+
/** 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. */
|
|
1204
|
+
networkSealOf(playerId) {
|
|
1205
|
+
return this.chatSettings.get(playerId)?.networkSeal ?? null;
|
|
1193
1206
|
}
|
|
1194
1207
|
/**
|
|
1195
|
-
* Whether one player's chat may reach another, canChat's rule on passes (pass.ts)
|
|
1196
|
-
*
|
|
1197
|
-
*
|
|
1198
|
-
* what would reach an under-18 account or come from one.
|
|
1208
|
+
* Whether one player's chat may reach another, canChat's rule on passes (pass.ts), sender to reader: no block
|
|
1209
|
+
* either way, the reader reads chat, and the sender's choice takes the reader in (everyone; the same chat group;
|
|
1210
|
+
* a friend in it). Zaisma's chat check stops what would reach an under-18 account without witnesses.
|
|
1199
1211
|
*/
|
|
1200
1212
|
mayChat(senderPlayerId, receiverPlayerId) {
|
|
1201
|
-
if (senderPlayerId === receiverPlayerId || !this.canChat(senderPlayerId) ||
|
|
1213
|
+
if (senderPlayerId === receiverPlayerId || !this.canChat(senderPlayerId) || this.hasBlockBetween(senderPlayerId, receiverPlayerId))
|
|
1202
1214
|
return false;
|
|
1203
1215
|
const sender = this.chatSettings.get(senderPlayerId);
|
|
1204
1216
|
const receiver = this.chatSettings.get(receiverPlayerId);
|
|
1205
|
-
|
|
1206
|
-
if (sender.chatGroupId !== receiver.chatGroupId && !isOutside(sender) && !isOutside(receiver))
|
|
1217
|
+
if (!receiver || receiver.chatGroupId === null)
|
|
1207
1218
|
return false;
|
|
1208
|
-
|
|
1219
|
+
const other = { isSameChatGroup: sender.chatGroupId === receiver.chatGroupId, isFriend: this.areFriends(senderPlayerId, receiverPlayerId) };
|
|
1220
|
+
return isWithinChatReach(sender.sending, other) && isWithinChatReach(receiver.reading, other);
|
|
1209
1221
|
}
|
|
1210
1222
|
/** 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. */
|
|
1211
1223
|
chatReceivers(senderPlayerId, toPlayerIds) {
|
|
@@ -1277,15 +1289,20 @@ export class RoomCore {
|
|
|
1277
1289
|
}
|
|
1278
1290
|
/**
|
|
1279
1291
|
* Send a chat message Zaisma's filter let through to its receivers, and tell the sender it went
|
|
1280
|
-
* (chat_sent), even when it reached nobody: the sender never learns who can't read them.
|
|
1292
|
+
* (chat_sent), even when it reached nobody: the sender never learns who can't read them. With isEveryReaderNeeded
|
|
1293
|
+
* (Zaisma counted witnesses among them) it sends nothing and answers false when any of them can't read it now.
|
|
1281
1294
|
*/
|
|
1282
|
-
deliverChat(senderPlayerId, chatNumber, receiverPlayerIds, chat) {
|
|
1295
|
+
deliverChat(senderPlayerId, chatNumber, receiverPlayerIds, chat, options = {}) {
|
|
1283
1296
|
const sentAt = new Date(this.now()).toISOString();
|
|
1284
1297
|
// Players who left, or blocked the sender, while the filter looked get nothing.
|
|
1285
1298
|
const receivers = receiverPlayerIds.filter((id) => this.players.has(id) && this.mayChat(senderPlayerId, id));
|
|
1299
|
+
// A message Zaisma let through only for the witnesses it counted doesn't go to fewer: the host stops it instead.
|
|
1300
|
+
if (options.isEveryReaderNeeded && receivers.length < receiverPlayerIds.length)
|
|
1301
|
+
return false;
|
|
1286
1302
|
if (receivers.length)
|
|
1287
1303
|
this.sendEach(receivers, JSON.stringify({ type: "chat", fromPlayerId: senderPlayerId, text: chat.text, hasSwearing: chat.hasSwearing, hasSlur: chat.hasSlur, sentAt }), CHAT_MESSAGE_TYPE);
|
|
1288
1304
|
this.sendText(senderPlayerId, JSON.stringify({ type: "chat_sent", chatNumber, sentAt }));
|
|
1305
|
+
return true;
|
|
1289
1306
|
}
|
|
1290
1307
|
/** Tell the sender their chat message was stopped: reason is the filter's, or stopped_by_game; message is what they see. */
|
|
1291
1308
|
stopChat(senderPlayerId, chatNumber, reason, message) {
|