@zaisma/game-server 1.44.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 +50 -81
- package/bin/local-play.js +33 -7
- package/bin/node.js +15 -6
- package/package.json +1 -1
- package/sdk/zaisma.d.ts +5 -4
- 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.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) {
|