@zhuweiyou/dsh-holdem 0.1.3 → 0.1.4
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/README.md +19 -20
- package/lib/client.js +206 -206
- package/lib/client.js.map +1 -1
- package/lib/index.js +9 -3
- package/lib/index.js.map +1 -1
- package/lib/types/config.d.ts +5 -0
- package/lib/types/config.d.ts.map +1 -1
- package/lib/types/invariant.d.ts +4 -1
- package/lib/types/invariant.d.ts.map +1 -1
- package/lib/types/room/RoomManager.d.ts.map +1 -1
- package/lib/types/types.d.ts +2 -0
- package/lib/types/types.d.ts.map +1 -1
- package/lib/worker.js +10 -3
- package/lib/worker.js.map +1 -1
- package/package.json +1 -1
- package/worker/index.ts +3 -0
package/lib/index.js
CHANGED
|
@@ -15,7 +15,10 @@ const PACKAGE_NAME = "@zhuweiyou/dsh-holdem";
|
|
|
15
15
|
const SUBPROTOCOL = "holdem.v1";
|
|
16
16
|
const ROUTE_PREFIX = "/holdem";
|
|
17
17
|
const MAX_SEATS = 6;
|
|
18
|
-
|
|
18
|
+
/** 观战席位默认值;实际值由设置项 maxSpectators 决定。 */
|
|
19
|
+
const DEFAULT_MAX_SPECTATORS = 16;
|
|
20
|
+
/** 设置项 maxSpectators 能配到的最大值。 */
|
|
21
|
+
const SPECTATORS_LIMIT = 64;
|
|
19
22
|
const MAX_ROOMS = 8;
|
|
20
23
|
const MAX_CHAT_LINES = 80;
|
|
21
24
|
const MAX_HISTORY_HANDS = 50;
|
|
@@ -68,6 +71,7 @@ const Config = z.object({
|
|
|
68
71
|
turnTimeoutSec: z.number().default(30).min(15).max(90),
|
|
69
72
|
autoAdvanceSec: z.number().default(6).min(2).max(30),
|
|
70
73
|
allowSpectators: z.boolean().default(true),
|
|
74
|
+
maxSpectators: z.number().default(DEFAULT_MAX_SPECTATORS).min(0).max(SPECTATORS_LIMIT),
|
|
71
75
|
chatEnabled: z.boolean().default(true),
|
|
72
76
|
maxRooms: z.number().default(MAX_ROOMS).min(1).max(64),
|
|
73
77
|
hostIdleDissolveMin: z.number().default(10).min(1).max(120),
|
|
@@ -92,6 +96,7 @@ function resolveConfig(config) {
|
|
|
92
96
|
turnTimeoutMs: turnTimeoutSec * 1e3,
|
|
93
97
|
autoAdvanceMs: autoAdvanceSec * 1e3,
|
|
94
98
|
allowSpectators: config.allowSpectators !== false,
|
|
99
|
+
maxSpectators: clamp(Math.trunc(config.maxSpectators ?? DEFAULT_MAX_SPECTATORS), 0, SPECTATORS_LIMIT),
|
|
95
100
|
chatEnabled: config.chatEnabled !== false,
|
|
96
101
|
maxRooms: clamp(Math.trunc(config.maxRooms ?? MAX_ROOMS), 1, 64),
|
|
97
102
|
hostIdleDissolveMs: clamp(config.hostIdleDissolveMin ?? 10, 1, 120) * 6e4,
|
|
@@ -3088,6 +3093,7 @@ var RoomManager = class {
|
|
|
3088
3093
|
turnTimeoutMs: this.config.turnTimeoutMs,
|
|
3089
3094
|
autoAdvanceMs: this.config.autoAdvanceMs,
|
|
3090
3095
|
allowSpectators: this.config.allowSpectators,
|
|
3096
|
+
maxSpectators: this.config.maxSpectators,
|
|
3091
3097
|
chatEnabled: this.config.chatEnabled
|
|
3092
3098
|
},
|
|
3093
3099
|
players: /* @__PURE__ */ new Map(),
|
|
@@ -3186,8 +3192,8 @@ var RoomManager = class {
|
|
|
3186
3192
|
const seatedCount = [...room.players.values()].filter((player$1) => player$1.seat !== null).length;
|
|
3187
3193
|
const canSit = wanted === "sit" && invite.sit && room.phase === "lobby" && seatedCount < MAX_SEATS;
|
|
3188
3194
|
if (!canSit) {
|
|
3189
|
-
if (!room.settings.allowSpectators) throw new CommandError("room-full", "房间已满且不允许观战");
|
|
3190
|
-
if ([...room.players.values()].filter((player$1) => player$1.seat === null).length >=
|
|
3195
|
+
if (!room.settings.allowSpectators || room.settings.maxSpectators <= 0) throw new CommandError("room-full", "房间已满且不允许观战");
|
|
3196
|
+
if ([...room.players.values()].filter((player$1) => player$1.seat === null).length >= room.settings.maxSpectators) throw new CommandError("room-full", "观战席已满");
|
|
3191
3197
|
if (wanted === "sit" && invite.sit === false) throw new CommandError("auth", "没有入座权限");
|
|
3192
3198
|
}
|
|
3193
3199
|
const seat = canSit ? this.firstFreeSeat(room) : null;
|