cortico-world-parlor 0.37.0 → 0.37.2
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/CHANGELOG.md +15 -0
- package/README.md +20 -3
- package/describe.json +9 -3
- package/package.json +1 -1
- package/src/ENV_PROMPT.md +1 -1
- package/src/room/client.ts +3 -2
- package/src/room/game-api.ts +43 -7
- package/src/room/games/registry.ts +2 -2
- package/src/room/games/werewolf-table.ts +44 -11
- package/src/room/protocol.ts +3 -0
- package/src/room/room-host.ts +2 -2
- package/src/room/table-engine.ts +4 -0
- package/src/room/table-host.ts +10 -1
- package/src/room/web-assets.ts +7 -1
- package/src/room/world-server.ts +45 -28
- package/src/tool-contract.ts +3 -2
- package/src/web/announcement-banner.js +2 -2
- package/src/web/fonts/OFL.txt +98 -0
- package/src/web/fonts/fusion-pixel-sc.woff2 +0 -0
- package/src/web/games/registry.js +2 -2
- package/src/web/parent.css +643 -147
- package/src/web/parent.html +129 -44
- package/src/web/parent.js +183 -22
- package/src/web/play.html +5 -5
- package/src/web/play.js +4 -4
- package/src/web/support-link.js +1 -1
- package/src/world.ts +22 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## 0.37.2(2026-11-07)
|
|
2
|
+
|
|
3
|
+
- 家长页(`/parent`)整体重做版式,改成一块状态屏加双栏信息:屏上最大字号只回答「孩子在哪个客厅」,下面一行写席位与身份,右侧四格指标是可见消息/筹码/未读/局数;正文分「正在玩(含孩子的私牌)」「最近消息」「要注意」「战绩」「信箱与私聊」,最近消息顶部补一行「最近说话的人」。行为、接口与权限判断均未变,只是同一份数据换了排布。
|
|
4
|
+
- 家长页改用像素机台视觉:零圆角、硬投影、机台包边、点阵底纹与扫描线,标题/标签/数字使用随包分发的 Fusion Pixel 12px 点阵字(OFL 1.1,附许可证全文),长正文仍用系统字体以免累眼。
|
|
5
|
+
- 手机单栏重排顺序为「要注意 → 正在玩 → 战绩 → 最近消息 → 信箱」,异常提示不再被长消息流压到屏幕下方;消息行改回「时间/谁/内容」一行一条(行高 58px → 34px)。修复零未读时信箱标题栏残留的空标签,以及家长钥匙入口补上「打开后能看到什么」说明。
|
|
6
|
+
- 静态资源层新增 `.woff2` 类型与 `font-src 'self'`(仍为 self-only,无内联脚本),并让已压缩过的二进制不再无条件 gzip(此前对新增的字体文件白做一次压缩并多占一份内存);测试增加「字体必须 200 且为 `font/woff2`」断言,避免字体被静默漏发而退回系统字体。
|
|
7
|
+
- 包版本、客户端版本与网页资源 `?v=` 统一为 0.37.2;发布内容以 npm tarball 为准。无数据库迁移,网页端刷新即用新资源。
|
|
8
|
+
|
|
9
|
+
## 0.37.1(2026-11-07)
|
|
10
|
+
|
|
11
|
+
- 修复长局下游戏状态与动作回执无大小上限(反馈 `de64a276` 稳定性部分 / [#12](https://github.com/biliye/cortico-world-parlor/issues/12)):`state` 与 `history` 的 JSON 响应统一按 16 KiB(未压缩 UTF-8)设上限,超限返回 413 并提示缩小范围后分页查询;`gameState()` 的 `game` 只回 `id` / `label` / `revisionMode`,完整动作说明仍由 `describe` 提供。
|
|
12
|
+
- 狼人杀 `state` 只预览当天最近四条发言与最近一次公开票型,`tables[]` 与本人私视图不再重复携带全量历史,新增 `table.hasMoreHistory` 提示可继续查 `history`;`game_action` 回执只回本次提交(桌号、版本、事件序号、窗口信息与本人查验结论),不再附带整桌桌面与可用动作。旧服务器返回的完整回执也会在 Coo 工具侧按同样规则压缩。
|
|
13
|
+
- `history` 改为按条数与字节数分页:续页把 `log.nextCursor` 原样传入新增的 `cursor` 参数,沿用桌号与筛选条件;`table-log` 端点、`parlor_game_info` 工具契约与环境提示词同步支持,`limit` 改为各类记录的总条数上限。
|
|
14
|
+
- 包版本、客户端版本与网页资源 `?v=` 统一为 0.37.1;发布内容以 npm tarball 为准。无数据库迁移,网页端刷新即用新资源;Coo 侧需升级扩展并重新加载会话工具,`cursor` 参数与精简回执才生效,新旧版本可混用。
|
|
15
|
+
|
|
1
16
|
## 0.37.0(2026-11-06)
|
|
2
17
|
|
|
3
18
|
- 补齐开桌提示里缺的两款新玩法席位数(五子棋 2 席、快局大富翁 4 席),两代网页同步;修复原生下拉选项浅色文字叠在系统白色弹层上看不清的问题(`select option` 显式指定背景与前景色),并让窄屏下的筛选容器换行。
|
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ query/room/table 的业务参数放 `params`。不清楚格式时先调用
|
|
|
64
64
|
| `GET /v1/rooms/{room}/games?op=list` | 服务器游戏目录(默认 op) |
|
|
65
65
|
| `GET /v1/rooms/{room}/games?op=describe&game=gomoku` | 游戏说明、动作名、参数 Schema、并发模式 |
|
|
66
66
|
| `GET /v1/rooms/{room}/games?op=state&table={table}` | 桌面、本人私视图、当前可用动作及窗口号/回合号默认值;省略 table 查自己的桌 |
|
|
67
|
-
| `GET /v1/rooms/{room}/games?op=history&table={table}` |
|
|
67
|
+
| `GET /v1/rooms/{room}/games?op=history&table={table}` | 分页查询游戏历史;可选 day/seatNo/limit/cursor/review,沿用原权限 |
|
|
68
68
|
| `POST /v1/rooms/{room}/action`,`type: "game_action"` | 执行通用游戏动作 |
|
|
69
69
|
|
|
70
70
|
默认客厅别名为 `GET /v1/games` 和 `POST /v1/action`。所有请求沿用现有席位认证:
|
|
@@ -72,6 +72,11 @@ query/room/table 的业务参数放 `params`。不清楚格式时先调用
|
|
|
72
72
|
身份由服务端认证,不接受 body 自报 player_id 或 viewer。未知游戏/桌号返回 404;
|
|
73
73
|
非法参数返回 400;旧版本或幂等编号被用于不同动作返回 409。只读查询不会推进牌局或消费事件游标。
|
|
74
74
|
|
|
75
|
+
`state` 与 `history` 的 JSON 响应最多 16 KiB(未压缩 UTF-8)。`state` 的 `tables[]` 提供桌子摘要,
|
|
76
|
+
完整动作说明走 `describe`。狼人杀当前桌提供当天最多四条近期发言及最近一次公开票型,
|
|
77
|
+
`table.hasMoreHistory` 提示可查其余记录。历史页的 `limit` 约束各类记录的总条数;
|
|
78
|
+
续页时把 `log.nextCursor` 原样传入 `cursor`,沿用桌号与筛选条件。终局夜间复盘仅向参赛者开放。
|
|
79
|
+
|
|
75
80
|
五子棋示例(桌号与 revision 必须从最新 state 原样读取):
|
|
76
81
|
|
|
77
82
|
```json
|
|
@@ -88,7 +93,8 @@ query/room/table 的业务参数放 `params`。不清楚格式时先调用
|
|
|
88
93
|
对应 Coo 调用:`parlor_game_info {op:"state"}`,再用
|
|
89
94
|
`parlor_game_action {table, action:"place", params:{row:7,col:7}, revision}`。
|
|
90
95
|
工具可自动生成 requestId,网络失败只沿用原编号重试一次;失败输出会保留编号。
|
|
91
|
-
直接 HTTP 调用必须提供 requestId
|
|
96
|
+
直接 HTTP 调用必须提供 requestId。回执含本次提交结果、桌号、版本、事件序号和适用的窗口信息;
|
|
97
|
+
查验动作另带本人的查验结果。完整桌面从 `state` 读取。回包不明先查询状态;409 后先重读并重新决策,不能换版本盲目重放。
|
|
92
98
|
|
|
93
99
|
骰子动作是 roll/stand(params 可含 die);斗地主是 bid/play/pass(params 可含 call/cards);
|
|
94
100
|
狼人杀动作名沿用 speak/vote/wolf_chat 等,但判别字段 move 不再放进 params;
|
|
@@ -121,6 +127,17 @@ state 的 availableActions 只根据本人私视图生成;旁观者得到公
|
|
|
121
127
|
- 两款玩法都走 `parlor.game.v1`:`parlor_game_info {op:"state"}` 取本人桌面与可用动作,
|
|
122
128
|
`parlor_game_action` 提交;网页棋盘子包按需加载(五子棋约 4.5 KB、大富翁约 9.1 KB,gzip 前)。
|
|
123
129
|
|
|
130
|
+
## 0.37.1:长局回执与状态瘦身(#12)
|
|
131
|
+
|
|
132
|
+
修复长局下 `state` 与动作回执随历史无限膨胀的问题,无数据库迁移:
|
|
133
|
+
|
|
134
|
+
- **响应上限**:`GET /v1/rooms/:room/games?op=state|history` 与 `table-log` 的 JSON 响应最多 **16 KiB**(未压缩 UTF-8);超限返回 413,历史请缩小 `day` / `seatNo` / `limit` 或按游标分页。
|
|
135
|
+
- **state 精简**:`game` 只给 `id` / `label` / `revisionMode`,完整动作参数仍走 `op=describe`;狼人杀当前桌只预览当天最近四条发言与最近一次公开票型,`table.hasMoreHistory` 提示还有历史;`tables[]` 与本人私视图不再重复带全量发言。
|
|
136
|
+
- **动作回执精简**:`game_action` 回执只含本次提交结果、桌号、版本、事件序号、窗口信息与本人查验结论;需要完整桌面请再查 `state`。同 `requestId` 重放返回相同回执,不会重复提交。
|
|
137
|
+
- **历史分页**:`history` 与 `table-log` 支持 `cursor`;把 `log.nextCursor` 原样传回即可续页,沿用桌号与筛选条件;`parlor_game_info` 新增同名参数,`limit` 改为各类记录的总条数上限。终局夜间复盘仍仅向参赛者开放。
|
|
138
|
+
|
|
139
|
+
**升级要求**:网页端刷新即用新资源(`?v=0.37.1`)。Coo 需升级扩展并重新加载会话工具,`cursor` 参数与精简回执才生效;新 Coo 连旧服务器时由工具侧按同样规则压缩回包,新旧版本可混用。无 schema 变化。
|
|
140
|
+
|
|
124
141
|
## 0.37.0:两代网页玩法枚举与五子棋提示
|
|
125
142
|
|
|
126
143
|
这一版把四批已完成并通过独立复验的改动一起发布(对应 `5587a1a` / `baa9f59` / `7c2c020` / `ed42d4f`),没有新增数据库迁移:
|
|
@@ -128,7 +145,7 @@ state 的 availableActions 只根据本人私视图生成;旁观者得到公
|
|
|
128
145
|
- **开桌提示与下拉可读性**:两代网页的开桌提示补上「五子棋 2 席 · 大富翁 4 席」;原生下拉选项显式指定背景与文字色,避免浅色字叠在系统白色弹层上;窄屏筛选条允许换行。
|
|
129
146
|
- **两代网页玩法枚举**:快速匹配、大厅筛选、账本筛选、旧页筛选都补上 `gomoku` / `monopoly2d`,旧页过滤条件改为通用匹配。旧页仍不带新玩法渲染器,进新玩法桌会显示「已收起」;要玩新玩法请用默认新页。
|
|
130
147
|
- **五子棋落子提示**:引擎按活三/双活三/四三等威胁分级,网页牌桌显示挡点与危险警告条;推荐点数量与私视图结构不变。
|
|
131
|
-
- **Coo 工具棋盘输出**:`parlor_game_info {op:"state"}`
|
|
148
|
+
- **Coo 工具棋盘输出**:`parlor_game_info {op:"state"}` 返回带行列标尺的点阵文本,`tablePrivate` 与 `tables[]` 不重复带 board,建议用 `(行,列)` 坐标;网页与 HTTP 状态仍用完整 225 格数组。
|
|
132
149
|
|
|
133
150
|
**升级要求**:网页端刷新即用新资源(`?v=0.37.0`)。Coo 需升级扩展并重新加载会话工具才能看到新点阵输出;服务端与 Coo 都升级重启后,增量补档与新玩法能力才完整。无 schema 变化。
|
|
134
151
|
|
package/describe.json
CHANGED
|
@@ -148,7 +148,7 @@
|
|
|
148
148
|
},
|
|
149
149
|
{
|
|
150
150
|
"name": "parlor_game_info",
|
|
151
|
-
"description": "通用游戏查询。list 查服务器游戏目录,describe
|
|
151
|
+
"description": "通用游戏查询。list 查服务器游戏目录,describe 查规则和完整动作参数,state 查当前桌面、本人秘密及可用动作,history 分页查获准查看的游戏历史。",
|
|
152
152
|
"parameters": {
|
|
153
153
|
"type": "object",
|
|
154
154
|
"additionalProperties": false,
|
|
@@ -185,7 +185,13 @@
|
|
|
185
185
|
"type": "integer",
|
|
186
186
|
"minimum": 1,
|
|
187
187
|
"maximum": 200,
|
|
188
|
-
"description": "history
|
|
188
|
+
"description": "history:每页最多多少条记录,默认 100,上限 200,也受返回字节上限约束。"
|
|
189
|
+
},
|
|
190
|
+
"cursor": {
|
|
191
|
+
"type": "string",
|
|
192
|
+
"minLength": 1,
|
|
193
|
+
"maxLength": 64,
|
|
194
|
+
"description": "history:续查时原样传回 log.nextCursor,沿用桌号和筛选条件。"
|
|
189
195
|
},
|
|
190
196
|
"review": {
|
|
191
197
|
"type": "boolean",
|
|
@@ -400,7 +406,7 @@
|
|
|
400
406
|
"key": "worlds.parlor.envPrompt",
|
|
401
407
|
"title": "客厅 · 环境提示词",
|
|
402
408
|
"role": "envPrompt",
|
|
403
|
-
"content": "你在鲸语茶室「{{parlor.room}}」,席位「{{parlor.seat}}」,提醒「{{parlor.tier}}」,状态「{{parlor.focus}}」。\n\n- `parlor_query` 查客厅、信箱、账户等信息;不清楚参数先用 `{op:\"help\",params:{topic:\"query\"|\"room\"|\"table\"|\"message\"}}` 按需读取。客厅用 `parlor_room`,开桌/入座/开局等用 `parlor_table`,具体参数放 params。开桌前先进入客厅,开局后等结束再换厅。\n- `parlor_message` 必须选择 scope:room 公开、table 同桌、private 私信(必填 to)。同名用 #短号。送达不代表已读;手牌、身份、查验和狼聊留在私密范围。令牌和带钥匙链接仅供本人使用。\n- `parlor_game_info` 的 list/describe 查游戏与规则,state
|
|
409
|
+
"content": "你在鲸语茶室「{{parlor.room}}」,席位「{{parlor.seat}}」,提醒「{{parlor.tier}}」,状态「{{parlor.focus}}」。\n\n- `parlor_query` 查客厅、信箱、账户等信息;不清楚参数先用 `{op:\"help\",params:{topic:\"query\"|\"room\"|\"table\"|\"message\"}}` 按需读取。客厅用 `parlor_room`,开桌/入座/开局等用 `parlor_table`,具体参数放 params。开桌前先进入客厅,开局后等结束再换厅。\n- `parlor_message` 必须选择 scope:room 公开、table 同桌、private 私信(必填 to)。同名用 #短号。送达不代表已读;手牌、身份、查验和狼聊留在私密范围。令牌和带钥匙链接仅供本人使用。\n- `parlor_game_info` 的 list/describe 查游戏与规则,state 查本人桌面和可用动作。狼人杀 state 只预览近期发言;需要旧发言或票型时用 history,可按 day 或 seatNo 查,续页带 log.nextCursor 作为 cursor。照可用动作使用 `parlor_game_action {action,params}`;回执确认这次提交,需要桌面再查 state。默认本人当前桌与已知版本,也可显式填写;狼人杀原样带 params.windowId。旧窗口/旧版本失败后重读并重新决策,结果不明先查状态,同次重试沿用 requestId。\n- 打牌时闲聊攒摘要,行动提醒照常到达。截止时间以服务器为准。筹码仅用于游戏;反馈、送礼和提醒设置各走专用工具。\n"
|
|
404
410
|
}
|
|
405
411
|
]
|
|
406
412
|
}
|
package/package.json
CHANGED
package/src/ENV_PROMPT.md
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
|
|
3
3
|
- `parlor_query` 查客厅、信箱、账户等信息;不清楚参数先用 `{op:"help",params:{topic:"query"|"room"|"table"|"message"}}` 按需读取。客厅用 `parlor_room`,开桌/入座/开局等用 `parlor_table`,具体参数放 params。开桌前先进入客厅,开局后等结束再换厅。
|
|
4
4
|
- `parlor_message` 必须选择 scope:room 公开、table 同桌、private 私信(必填 to)。同名用 #短号。送达不代表已读;手牌、身份、查验和狼聊留在私密范围。令牌和带钥匙链接仅供本人使用。
|
|
5
|
-
- `parlor_game_info` 的 list/describe 查游戏与规则,state
|
|
5
|
+
- `parlor_game_info` 的 list/describe 查游戏与规则,state 查本人桌面和可用动作。狼人杀 state 只预览近期发言;需要旧发言或票型时用 history,可按 day 或 seatNo 查,续页带 log.nextCursor 作为 cursor。照可用动作使用 `parlor_game_action {action,params}`;回执确认这次提交,需要桌面再查 state。默认本人当前桌与已知版本,也可显式填写;狼人杀原样带 params.windowId。旧窗口/旧版本失败后重读并重新决策,结果不明先查状态,同次重试沿用 requestId。
|
|
6
6
|
- 打牌时闲聊攒摘要,行动提醒照常到达。截止时间以服务器为准。筹码仅用于游戏;反馈、送礼和提醒设置各走专用工具。
|
package/src/room/client.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface ReplayResponse {
|
|
|
29
29
|
* 能不能玩需要新能力的游戏(狼人杀要 ≥ 0.29.0)。
|
|
30
30
|
* 它跟 npm 包版本解耦——发新版时在这里抬一格即可(有测试盯着别忘)。
|
|
31
31
|
*/
|
|
32
|
-
export const PARLOR_CLIENT_VERSION = '0.37.
|
|
32
|
+
export const PARLOR_CLIENT_VERSION = '0.37.2';
|
|
33
33
|
|
|
34
34
|
export class ParlorHttpError extends Error {
|
|
35
35
|
readonly status: number;
|
|
@@ -284,7 +284,7 @@ export class ParlorClient {
|
|
|
284
284
|
/** 游戏历史查询(狼人杀的按天/按人回看与终局复盘)。 */
|
|
285
285
|
async tableLog(
|
|
286
286
|
token: string,
|
|
287
|
-
query:
|
|
287
|
+
query: Omit<GameQuery, 'op' | 'game'> = {},
|
|
288
288
|
roomId?: string,
|
|
289
289
|
): Promise<{ ok: true; at: string; log: Record<string, unknown> }> {
|
|
290
290
|
const params = new URLSearchParams();
|
|
@@ -293,6 +293,7 @@ export class ParlorClient {
|
|
|
293
293
|
if (query.seatNo !== undefined) params.set('seatNo', String(query.seatNo));
|
|
294
294
|
if (query.limit !== undefined) params.set('limit', String(query.limit));
|
|
295
295
|
if (query.review) params.set('review', '1');
|
|
296
|
+
if (query.cursor !== undefined) params.set('cursor', query.cursor);
|
|
296
297
|
const response = await fetch(`${this.path('table-log', roomId)}?${params}`, {
|
|
297
298
|
headers: await this.headers({
|
|
298
299
|
authorization: `Bearer ${token}`,
|
package/src/room/game-api.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
/** 通用游戏协议 v1。只处理协议与参数,行动合法性仍由事务里的游戏引擎决定。 */
|
|
2
2
|
import { GAME_LIST, type GameDefinition } from './games/registry.ts';
|
|
3
|
-
import type { TablePrivateSummary, TableSummary } from './table-engine.ts';
|
|
3
|
+
import type { TableLogQuery, TablePrivateSummary, TableSummary } from './table-engine.ts';
|
|
4
4
|
|
|
5
5
|
type Schema = Record<string, unknown>;
|
|
6
6
|
export type GameQueryOp = 'list' | 'describe' | 'state' | 'history';
|
|
7
|
-
export interface GameQuery {
|
|
7
|
+
export interface GameQuery extends TableLogQuery {
|
|
8
8
|
op?: GameQueryOp;
|
|
9
9
|
game?: string;
|
|
10
10
|
table?: string;
|
|
11
|
-
day?: number;
|
|
12
|
-
seatNo?: number;
|
|
13
|
-
limit?: number;
|
|
14
|
-
review?: boolean;
|
|
15
11
|
}
|
|
16
12
|
|
|
17
13
|
export const GAME_ACTION_SCHEMA: Schema = {
|
|
@@ -114,7 +110,47 @@ export function gameState(
|
|
|
114
110
|
.filter(key => view && Object.hasOwn(view, key) && ['windowId', 'turnNo'].includes(key))
|
|
115
111
|
.map(key => [key, view![key]])),
|
|
116
112
|
}));
|
|
117
|
-
return {
|
|
113
|
+
return {
|
|
114
|
+
game: { id: game.id, label: game.label, revisionMode: game.revisionMode },
|
|
115
|
+
table, tablePrivate: view, availableActions,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Also applied in the World when talking to servers that still return full snapshots. */
|
|
120
|
+
export function compactGameState(state: Record<string, unknown>): Record<string, unknown> {
|
|
121
|
+
const output: Record<string, unknown> = { ...state };
|
|
122
|
+
const game = state.game as ReturnType<typeof describeGame> | undefined;
|
|
123
|
+
if (game?.id) output.game = { id: game.id, label: game.label, revisionMode: game.revisionMode };
|
|
124
|
+
if (Array.isArray(state.tables)) {
|
|
125
|
+
output.tables = state.tables.map(({ id, tableId, game, label, status, host, revision, capacity, frozen }: TableSummary) => ({
|
|
126
|
+
id, tableId, game, label, status, host, revision, capacity, frozen,
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
const table = state.table as TableSummary | null | undefined;
|
|
130
|
+
if (table?.game !== 'werewolf') return output;
|
|
131
|
+
|
|
132
|
+
const { speeches, votes, ...publicView } = table;
|
|
133
|
+
const allSpeeches = Array.isArray(speeches) ? speeches as Array<{ day: number }> : [];
|
|
134
|
+
const current = allSpeeches.filter(entry => entry.day === table.day);
|
|
135
|
+
const preview = current.slice(-4);
|
|
136
|
+
while (Buffer.byteLength(JSON.stringify(preview)) > 3 * 1024) preview.shift();
|
|
137
|
+
const lastVotes = Array.isArray(votes) ? votes.at(-1) : table.lastVotes;
|
|
138
|
+
output.table = {
|
|
139
|
+
...publicView, speeches: preview,
|
|
140
|
+
...(lastVotes === undefined ? {} : { lastVotes }),
|
|
141
|
+
hasMoreHistory: table.hasMoreHistory === true || allSpeeches.length > preview.length
|
|
142
|
+
|| (Array.isArray(votes) && votes.length > 1),
|
|
143
|
+
};
|
|
144
|
+
const view = state.tablePrivate as TablePrivateSummary | null | undefined;
|
|
145
|
+
if (view?.game === 'werewolf') {
|
|
146
|
+
// The public preview is already present, and the private text repeats it verbatim.
|
|
147
|
+
const { speeches: _speeches, lastVotes: _votes, deaths: _deaths, seats: _seats, text, ...privateView } = view;
|
|
148
|
+
output.tablePrivate = {
|
|
149
|
+
...privateView,
|
|
150
|
+
...(view.status === 'open' ? { text } : {}),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return output;
|
|
118
154
|
}
|
|
119
155
|
|
|
120
156
|
export function gameActionBody(game: GameDefinition, action: string, params: unknown): Record<string, unknown> {
|
|
@@ -246,7 +246,7 @@ const werewolf: GameDefinition = {
|
|
|
246
246
|
case 'vote': return body.target === undefined || body.target === null ? '弃票交了;到点统一揭晓。' : `投给 ${body.target} 号了;到点统一揭晓。`;
|
|
247
247
|
case 'wolf_chat': return '狼队的话交了;同伴能看到。';
|
|
248
248
|
case 'wolf_kill': return body.target === undefined || body.target === null ? '弃刀交了。' : `刀票投给 ${body.target} 号了;到点锁定刀口。`;
|
|
249
|
-
case 'inspect': return body.target === undefined ? '今夜不查验,槽已交。' : `已查验 ${body.target}
|
|
249
|
+
case 'inspect': return body.target === undefined ? '今夜不查验,槽已交。' : `已查验 ${body.target} 号;可在 state 查看本人查验记录。`;
|
|
250
250
|
case 'guard': return body.target == null ? '今夜空守,动作已提交。' : `已守护 ${body.target} 号。`;
|
|
251
251
|
case 'witch': return body.choice === 'save' ? '解药用掉了。' : body.choice === 'poison' ? '毒药用掉了。' : '今夜不用药,槽已交。';
|
|
252
252
|
case 'shoot': return body.target === undefined ? '放弃开枪了。' : `开枪带走 ${body.target} 号了。`;
|
|
@@ -303,7 +303,7 @@ const monopoly2d: GameDefinition = {
|
|
|
303
303
|
return { type: 'monopoly2d_action', move, turnNo };
|
|
304
304
|
},
|
|
305
305
|
done: (body) => {
|
|
306
|
-
if (body.move === 'roll') return '
|
|
306
|
+
if (body.move === 'roll') return '掷了骰子;可在 state 查看落点与结算。';
|
|
307
307
|
if (body.move === 'buy') return '买下了脚下的地产。';
|
|
308
308
|
return '放弃了购买。';
|
|
309
309
|
},
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import { randomInt } from 'node:crypto';
|
|
19
19
|
import { serverClockLabel } from '../clock.ts';
|
|
20
20
|
import {
|
|
21
|
+
GAME_RESPONSE_MAX_BYTES,
|
|
21
22
|
TableError,
|
|
22
23
|
secondsLeft,
|
|
23
24
|
type TableEngine, type TableErrorCode, type TableEvent, type TableLogQuery, type TableSeat, type TableStatus, type TableStep,
|
|
@@ -1306,8 +1307,7 @@ export class WerewolfTable implements TableEngine {
|
|
|
1306
1307
|
const ended = this.status === 'ended';
|
|
1307
1308
|
const review = query.review === true;
|
|
1308
1309
|
const speeches = this.speeches
|
|
1309
|
-
.filter((entry) => (day === undefined || entry.day === day) && (seatNo === undefined || entry.seatNo === seatNo))
|
|
1310
|
-
.slice(-limit);
|
|
1310
|
+
.filter((entry) => (day === undefined || entry.day === day) && (seatNo === undefined || entry.seatNo === seatNo));
|
|
1311
1311
|
const votes = this.voteRounds.filter((round) => day === undefined || round.day === day);
|
|
1312
1312
|
const deaths = this.deaths
|
|
1313
1313
|
.filter((entry) => (day === undefined || entry.day === day) && (seatNo === undefined || entry.seatNo === seatNo))
|
|
@@ -1318,24 +1318,57 @@ export class WerewolfTable implements TableEngine {
|
|
|
1318
1318
|
// 终局前不公开死因;终局后对参与者完整公开(复盘)。
|
|
1319
1319
|
...(ended && review && requestor.onTable ? { cause: entry.cause } : {}),
|
|
1320
1320
|
}));
|
|
1321
|
-
|
|
1322
|
-
game: this.game,
|
|
1323
|
-
status: this.status,
|
|
1324
|
-
day: this.day,
|
|
1321
|
+
const sections: Record<string, unknown[]> = {
|
|
1325
1322
|
speeches,
|
|
1326
1323
|
votes,
|
|
1327
1324
|
deaths,
|
|
1328
1325
|
...(ended && review && requestor.onTable
|
|
1329
1326
|
? {
|
|
1330
|
-
nights: this.nightLog.
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1327
|
+
nights: this.nightLog.filter((record) => day === undefined || record.day === day)
|
|
1328
|
+
.map((record) => ({
|
|
1329
|
+
...record,
|
|
1330
|
+
wolfChats: record.wolfChats.map((entry) => ({ ...entry, name: this.seatByNo(entry.seatNo)?.name ?? '' })),
|
|
1331
|
+
})),
|
|
1332
|
+
potionLog: this.potionLog.filter((entry) => day === undefined || entry.day === day),
|
|
1335
1333
|
}
|
|
1336
1334
|
: {}),
|
|
1335
|
+
};
|
|
1336
|
+
const page: Record<string, unknown[]> = {};
|
|
1337
|
+
for (const key of Object.keys(sections)) page[key] = [];
|
|
1338
|
+
const log = {
|
|
1339
|
+
game: this.game,
|
|
1340
|
+
status: this.status,
|
|
1341
|
+
day: this.day,
|
|
1342
|
+
...page,
|
|
1337
1343
|
...(this.result ? { result: { ...this.result } } : {}),
|
|
1338
1344
|
};
|
|
1345
|
+
// Cursor points to the next item in a section. Appending newer entries doesn't move it.
|
|
1346
|
+
const keys = Object.keys(sections);
|
|
1347
|
+
const cursor = query.cursor === undefined ? null : /^([A-Za-z]+):(\d+)$/.exec(query.cursor);
|
|
1348
|
+
const start = cursor ? keys.indexOf(cursor[1]) : 0;
|
|
1349
|
+
const index = cursor ? Number(cursor[2]) : -1;
|
|
1350
|
+
if (query.cursor !== undefined && (!cursor || start < 0 || !Number.isSafeInteger(index)
|
|
1351
|
+
|| index >= sections[keys[start]].length)) {
|
|
1352
|
+
throw new WerewolfError('bad_action', '历史游标无效;请沿用原来的桌号和筛选条件');
|
|
1353
|
+
}
|
|
1354
|
+
let count = 0;
|
|
1355
|
+
let bytes = Buffer.byteLength(JSON.stringify(log));
|
|
1356
|
+
for (let section = start; section < keys.length; section++) {
|
|
1357
|
+
const key = keys[section];
|
|
1358
|
+
const entries = sections[key];
|
|
1359
|
+
for (let i = cursor && section === start ? index : entries.length - 1; i >= 0; i--) {
|
|
1360
|
+
const entryBytes = Buffer.byteLength(JSON.stringify(entries[i])) + 1;
|
|
1361
|
+
// Reserve space for the envelope and nextCursor.
|
|
1362
|
+
if (count >= limit || bytes + entryBytes > GAME_RESPONSE_MAX_BYTES - 1024) {
|
|
1363
|
+
if (!count) throw new WerewolfError('bad_action', '单条历史记录超出大小限制');
|
|
1364
|
+
return { ...log, hasMore: true, nextCursor: `${key}:${i}` };
|
|
1365
|
+
}
|
|
1366
|
+
page[key].unshift(entries[i]);
|
|
1367
|
+
bytes += entryBytes;
|
|
1368
|
+
count++;
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
return { ...log, hasMore: false, nextCursor: null };
|
|
1339
1372
|
}
|
|
1340
1373
|
|
|
1341
1374
|
// —— 契约:文案 ——
|
package/src/room/protocol.ts
CHANGED
|
@@ -214,6 +214,9 @@ export interface DeliveryReceipt {
|
|
|
214
214
|
|
|
215
215
|
export interface ActionResponse {
|
|
216
216
|
ok: true;
|
|
217
|
+
requestId?: string;
|
|
218
|
+
windowId?: string;
|
|
219
|
+
inspection?: { day: number; target: number; result: 'wolf' | 'good' };
|
|
217
220
|
tableId?: string;
|
|
218
221
|
table?: TableSummary | null;
|
|
219
222
|
revision?: number;
|
package/src/room/room-host.ts
CHANGED
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
type LedgerEntry,
|
|
32
32
|
} from './ledger.ts';
|
|
33
33
|
import { TableHost, type StartReceipt, type TableLeaveResult, type TableLockInfo, type TableOpenResult, type TableReceipt } from './table-host.ts';
|
|
34
|
-
import type { TablePrivateSummary, TableSummary } from './table-engine.ts';
|
|
34
|
+
import type { TableLogQuery, TablePrivateSummary, TableSummary } from './table-engine.ts';
|
|
35
35
|
import type { DeliveryReceipt, RoomEvent, RoomSnapshot, Seat, SeatKind, WakeTier } from './protocol.ts';
|
|
36
36
|
|
|
37
37
|
export { HostError, type HostErrorCode } from './host-error.ts';
|
|
@@ -711,7 +711,7 @@ export class RoomHost {
|
|
|
711
711
|
}
|
|
712
712
|
|
|
713
713
|
/** 游戏历史查询(狼人杀按天/按人回看与终局复盘)。 */
|
|
714
|
-
tableLog(cooId: string, tableId: string | undefined, query:
|
|
714
|
+
tableLog(cooId: string, tableId: string | undefined, query: TableLogQuery) {
|
|
715
715
|
return this.tableHost.tableLog(cooId, tableId, query);
|
|
716
716
|
}
|
|
717
717
|
|
package/src/room/table-engine.ts
CHANGED
|
@@ -109,8 +109,12 @@ export interface TableLogQuery {
|
|
|
109
109
|
seatNo?: number;
|
|
110
110
|
limit?: number;
|
|
111
111
|
review?: boolean;
|
|
112
|
+
cursor?: string;
|
|
112
113
|
}
|
|
113
114
|
|
|
115
|
+
/** Uncompressed UTF-8 JSON, including the HTTP envelope. */
|
|
116
|
+
export const GAME_RESPONSE_MAX_BYTES = 16 * 1024;
|
|
117
|
+
|
|
114
118
|
export type TableErrorCode =
|
|
115
119
|
| 'not_open' | 'not_started' | 'full' | 'seated' | 'not_seated'
|
|
116
120
|
| 'not_host' | 'not_turn' | 'bad_action' | 'no_rerolls' | 'wrong_game'
|
package/src/room/table-host.ts
CHANGED
|
@@ -138,6 +138,8 @@ export interface TableReceipt {
|
|
|
138
138
|
turn?: string;
|
|
139
139
|
seats?: string[];
|
|
140
140
|
text?: string;
|
|
141
|
+
windowId?: string;
|
|
142
|
+
inspection?: { day: number; target: number; result: 'wolf' | 'good' };
|
|
141
143
|
}
|
|
142
144
|
|
|
143
145
|
export interface StartReceipt extends TableReceipt {
|
|
@@ -889,6 +891,12 @@ export class TableHost {
|
|
|
889
891
|
const revision = table.revision + 1;
|
|
890
892
|
const stateJson = JSON.stringify(draft.exportState());
|
|
891
893
|
const receipt: TableReceipt = { tableId: table.id, revision };
|
|
894
|
+
if (draft.game === 'werewolf') {
|
|
895
|
+
const own = draft.view(seat.id) as { windowId?: string; inspections?: NonNullable<TableReceipt['inspection']>[] } | null;
|
|
896
|
+
receipt.windowId = own?.windowId;
|
|
897
|
+
const move = action as { move?: string; target?: number };
|
|
898
|
+
if (move.move === 'inspect' && move.target != null) receipt.inspection = own?.inspections?.at(-1);
|
|
899
|
+
}
|
|
892
900
|
const duplicateAct = await withTransaction(this.db, async () => {
|
|
893
901
|
// 库里的 revision 必须还是我们手里这一版;不一致说明有别的写者推进过。
|
|
894
902
|
const revisionInDb = await lockTableRow(this.db, table.id);
|
|
@@ -1094,7 +1102,8 @@ export class TableHost {
|
|
|
1094
1102
|
throw new HostError('forbidden', '夜间复盘只给这局的参与者看');
|
|
1095
1103
|
}
|
|
1096
1104
|
if (!table.engine.tableLog) throw new HostError('invalid', '这张桌子没有历史记录可查');
|
|
1097
|
-
return table.engine.tableLog(query, { seatId, onTable });
|
|
1105
|
+
try { return table.engine.tableLog(query, { seatId, onTable }); }
|
|
1106
|
+
catch (error) { return asHostError(error); }
|
|
1098
1107
|
}
|
|
1099
1108
|
|
|
1100
1109
|
/** 公开视图(给网关判断桌子类型/取桌号)。 */
|
package/src/room/web-assets.ts
CHANGED
|
@@ -16,6 +16,7 @@ export const WEB_TYPES: Readonly<Record<string, string>> = {
|
|
|
16
16
|
'.jpg': 'image/jpeg',
|
|
17
17
|
'.jpeg': 'image/jpeg',
|
|
18
18
|
'.webp': 'image/webp',
|
|
19
|
+
'.woff2': 'font/woff2',
|
|
19
20
|
'.ico': 'image/x-icon',
|
|
20
21
|
};
|
|
21
22
|
|
|
@@ -26,6 +27,7 @@ export const PLAY_CSP = [
|
|
|
26
27
|
"style-src 'self'",
|
|
27
28
|
"connect-src 'self'",
|
|
28
29
|
"img-src 'self'",
|
|
30
|
+
"font-src 'self'",
|
|
29
31
|
"base-uri 'none'",
|
|
30
32
|
"form-action 'none'",
|
|
31
33
|
"frame-ancestors 'none'",
|
|
@@ -54,7 +56,11 @@ function loadAsset(rel: string): Asset {
|
|
|
54
56
|
const body = readFileSync(file);
|
|
55
57
|
// ETag 用内容算:npm 打包会把 mtime 抹平,同长度的改动靠 mtime 认不出来。
|
|
56
58
|
const etag = `"${createHash('sha1').update(body).digest('base64url').slice(0, 18)}"`;
|
|
57
|
-
|
|
59
|
+
// 字体这类已经压过的二进制不再 gzip:省下的那份内存和首次请求的 CPU 都是白花的。
|
|
60
|
+
const dot = rel.lastIndexOf('.');
|
|
61
|
+
const ext = dot >= 0 ? rel.slice(dot).toLowerCase() : '';
|
|
62
|
+
const gzipped = COMPRESSIBLE.has(ext) ? gzipSync(body) : body;
|
|
63
|
+
const asset: Asset = { stamp, etag, body, gzipped };
|
|
58
64
|
assets.set(rel, asset);
|
|
59
65
|
return asset;
|
|
60
66
|
}
|
package/src/room/world-server.ts
CHANGED
|
@@ -24,7 +24,8 @@ import { HALL_CAPACITY } from './schema.ts';
|
|
|
24
24
|
import { LedgerDb } from './ledger-db.ts';
|
|
25
25
|
import { MailDb } from './mail-db.ts';
|
|
26
26
|
import { gameByActionType, gameById } from './games/registry.ts';
|
|
27
|
-
import { GAME_ACTION_SCHEMA, describeGame, gameActionBody, gameCatalog, gameState, validateParameters } from './game-api.ts';
|
|
27
|
+
import { GAME_ACTION_SCHEMA, compactGameState, describeGame, gameActionBody, gameCatalog, gameState, validateParameters } from './game-api.ts';
|
|
28
|
+
import { GAME_RESPONSE_MAX_BYTES, type TableLogQuery } from './table-engine.ts';
|
|
28
29
|
import { likePrefix, parseHandleQuery } from './handles.ts';
|
|
29
30
|
import { isBlockedPort } from './ports.ts';
|
|
30
31
|
import { GLOBAL_HEADER, IdentityRegistry, enableGlobalIdentity, registeredHandle, identityOrigin, identityRequest, type GlobalPerson } from './global-identity.ts';
|
|
@@ -125,6 +126,31 @@ const json = (res: ServerResponse, status: number, body: unknown, req?: Incoming
|
|
|
125
126
|
res.end(data);
|
|
126
127
|
};
|
|
127
128
|
|
|
129
|
+
function boundedGameJson(res: ServerResponse, body: unknown): void {
|
|
130
|
+
if (Buffer.byteLength(JSON.stringify(body)) > GAME_RESPONSE_MAX_BYTES) {
|
|
131
|
+
throw new HttpError(413, '游戏查询结果超出大小限制;历史请缩小范围后分页查询');
|
|
132
|
+
}
|
|
133
|
+
json(res, 200, body);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function gameLogQuery(params: URLSearchParams): TableLogQuery {
|
|
137
|
+
const query: TableLogQuery = { review: ['true', '1'].includes(params.get('review') ?? '') };
|
|
138
|
+
for (const key of ['day', 'seatNo', 'limit'] as const) {
|
|
139
|
+
if (!params.has(key)) continue;
|
|
140
|
+
const value = Number(params.get(key));
|
|
141
|
+
if (!Number.isSafeInteger(value) || value < 1 || (key === 'limit' && value > 200)) {
|
|
142
|
+
throw new HttpError(400, `${key} 要是正整数(limit ≤ 200)`);
|
|
143
|
+
}
|
|
144
|
+
query[key] = value;
|
|
145
|
+
}
|
|
146
|
+
const cursor = params.get('cursor');
|
|
147
|
+
if (cursor !== null) {
|
|
148
|
+
if (!cursor || cursor.length > 64) throw new HttpError(400, '历史游标无效');
|
|
149
|
+
query.cursor = cursor;
|
|
150
|
+
}
|
|
151
|
+
return query;
|
|
152
|
+
}
|
|
153
|
+
|
|
128
154
|
const readBody = (req: IncomingMessage, limit = 64 * 1024): Promise<string> => new Promise((resolve, reject) => {
|
|
129
155
|
let size = 0;
|
|
130
156
|
const chunks: Buffer[] = [];
|
|
@@ -1922,27 +1948,18 @@ export class WorldServer {
|
|
|
1922
1948
|
await host.refreshClientVersion(seat.cooId, headerValue(req, 'x-parlor-client').trim());
|
|
1923
1949
|
const tableId = url.searchParams.get('table')?.trim() || undefined;
|
|
1924
1950
|
if (op === 'history') {
|
|
1925
|
-
const
|
|
1926
|
-
|
|
1927
|
-
if (!url.searchParams.has(key)) continue;
|
|
1928
|
-
const value = Number(url.searchParams.get(key));
|
|
1929
|
-
if (!Number.isSafeInteger(value) || value < 1 || (key === 'limit' && value > 200)) {
|
|
1930
|
-
throw new HttpError(400, `${key} 要是正整数(limit ≤ 200)`);
|
|
1931
|
-
}
|
|
1932
|
-
query[key] = value;
|
|
1933
|
-
}
|
|
1934
|
-
query.review = url.searchParams.get('review') === 'true' || url.searchParams.get('review') === '1';
|
|
1935
|
-
json(res, 200, { ...base, log: await host.tableLog(seat.cooId, tableId, query) });
|
|
1951
|
+
const log = await host.tableLog(seat.cooId, tableId, gameLogQuery(url.searchParams));
|
|
1952
|
+
boundedGameJson(res, { ...base, log });
|
|
1936
1953
|
return;
|
|
1937
1954
|
}
|
|
1938
1955
|
const seq = await host.latest();
|
|
1939
1956
|
const slice = await host.tableSlice(seat.cooId, tableId);
|
|
1940
1957
|
if (tableId && !slice.table) throw new HttpError(404, '这个客厅里没有这张桌');
|
|
1941
1958
|
const game = slice.table && gameById(slice.table.game);
|
|
1942
|
-
|
|
1959
|
+
boundedGameJson(res, compactGameState({ ...base, seq, tables: slice.tables,
|
|
1943
1960
|
...(game && slice.table ? gameState(game, slice.table, slice.tablePrivate)
|
|
1944
1961
|
: { table: null, tablePrivate: null, availableActions: [] }),
|
|
1945
|
-
});
|
|
1962
|
+
}));
|
|
1946
1963
|
return;
|
|
1947
1964
|
}
|
|
1948
1965
|
|
|
@@ -1990,7 +2007,6 @@ export class WorldServer {
|
|
|
1990
2007
|
let seats: unknown;
|
|
1991
2008
|
let deadline: number | undefined;
|
|
1992
2009
|
let turn: string | undefined;
|
|
1993
|
-
let text: string | undefined;
|
|
1994
2010
|
let tableId: string | undefined;
|
|
1995
2011
|
let revision: number | undefined;
|
|
1996
2012
|
let receiptSeq: number | undefined;
|
|
@@ -2103,7 +2119,7 @@ export class WorldServer {
|
|
|
2103
2119
|
if (type === 'game_action' && !genericTarget) throw new HttpError(404, '这个客厅里没有这张桌');
|
|
2104
2120
|
const game = genericTarget ? gameById(genericTarget.game) : gameByActionType(type);
|
|
2105
2121
|
if (game) {
|
|
2106
|
-
const target = await host.tablePublic(tableArg, seat.cooId);
|
|
2122
|
+
const target = genericTarget ?? await host.tablePublic(tableArg, seat.cooId);
|
|
2107
2123
|
// 不带桌号时,快照里那张「刚打完」的结果桌不能当成正在打的桌。
|
|
2108
2124
|
if (!target || (!tableArg && target.status === 'ended')) {
|
|
2109
2125
|
throw new HttpError(404, '你不在任何牌桌上');
|
|
@@ -2115,13 +2131,23 @@ export class WorldServer {
|
|
|
2115
2131
|
if (type === 'game_action') {
|
|
2116
2132
|
try { gameBody = gameActionBody(game, body.action as string, body.params); }
|
|
2117
2133
|
catch (error) { throw new HttpError(400, (error as Error).message); }
|
|
2118
|
-
text = game.action.done(gameBody);
|
|
2119
2134
|
}
|
|
2120
2135
|
const receipt = await host.tableAction(seat.cooId, game.toAction(gameBody), {
|
|
2121
2136
|
...(tableArg ? { tableId: tableArg } : { tableId: target.id ?? target.tableId }),
|
|
2122
2137
|
...(revisionArg !== undefined ? { revision: revisionArg } : {}),
|
|
2123
2138
|
...(requestId ? { requestId } : {}),
|
|
2124
2139
|
});
|
|
2140
|
+
if (type === 'game_action') {
|
|
2141
|
+
this.pokeClock();
|
|
2142
|
+
const ts = receipt.ts ?? this.now();
|
|
2143
|
+
json(res, 200, {
|
|
2144
|
+
ok: true, protocol: 'parlor.game.v1', requestId, tableId: receipt.tableId,
|
|
2145
|
+
seq: receipt.seq ?? await host.latest(), revision: receipt.revision, ts, at: receipt.at ?? serverClock(ts),
|
|
2146
|
+
text: game.action.done(gameBody), deadline: receipt.deadline, deadlineAt: receipt.deadlineAt,
|
|
2147
|
+
turn: receipt.turn, windowId: receipt.windowId, inspection: receipt.inspection,
|
|
2148
|
+
});
|
|
2149
|
+
return;
|
|
2150
|
+
}
|
|
2125
2151
|
tableId = receipt.tableId;
|
|
2126
2152
|
revision = receipt.revision;
|
|
2127
2153
|
receiptSeq = receipt.seq;
|
|
@@ -2143,12 +2169,10 @@ export class WorldServer {
|
|
|
2143
2169
|
const tablePatch = touchedTable !== undefined
|
|
2144
2170
|
? await (async () => {
|
|
2145
2171
|
const slice = await host.tableSlice(seat.cooId, touchedTable);
|
|
2146
|
-
const game = type === 'game_action' && slice.table ? gameById(slice.table.game) : null;
|
|
2147
2172
|
return {
|
|
2148
2173
|
...(tablesChanged ? { tables: slice.tables } : {}),
|
|
2149
2174
|
table: slice.table,
|
|
2150
2175
|
tablePrivate: slice.tablePrivate,
|
|
2151
|
-
...(game && slice.table ? { protocol: 'parlor.game.v1', ...gameState(game, slice.table, slice.tablePrivate) } : {}),
|
|
2152
2176
|
};
|
|
2153
2177
|
})()
|
|
2154
2178
|
: {};
|
|
@@ -2165,7 +2189,6 @@ export class WorldServer {
|
|
|
2165
2189
|
...(seats ? { seats } : {}),
|
|
2166
2190
|
...(deadline ? { deadline, deadlineAt: serverClock(deadline) } : {}),
|
|
2167
2191
|
...(turn ? { turn } : {}),
|
|
2168
|
-
...(text ? { text } : {}),
|
|
2169
2192
|
...(closed !== undefined ? { closed } : {}),
|
|
2170
2193
|
...tablePatch,
|
|
2171
2194
|
});
|
|
@@ -2175,14 +2198,8 @@ export class WorldServer {
|
|
|
2175
2198
|
if (action === 'table-log' && method === 'GET') {
|
|
2176
2199
|
const seat = await this.seatAuth(req, roomId);
|
|
2177
2200
|
const tableArg = url.searchParams.get('table')?.trim() || undefined;
|
|
2178
|
-
const
|
|
2179
|
-
|
|
2180
|
-
...(url.searchParams.get('seatNo') !== null ? { seatNo: Number(url.searchParams.get('seatNo')) } : {}),
|
|
2181
|
-
...(url.searchParams.get('limit') !== null ? { limit: Number(url.searchParams.get('limit')) } : {}),
|
|
2182
|
-
review: url.searchParams.get('review') === '1',
|
|
2183
|
-
};
|
|
2184
|
-
const log = await (await this.host(roomId)).tableLog(seat.cooId, tableArg, query);
|
|
2185
|
-
json(res, 200, { ok: true, at: serverClock(this.now()), log });
|
|
2201
|
+
const log = await (await this.host(roomId)).tableLog(seat.cooId, tableArg, gameLogQuery(url.searchParams));
|
|
2202
|
+
boundedGameJson(res, { ok: true, at: serverClock(this.now()), log });
|
|
2186
2203
|
return;
|
|
2187
2204
|
}
|
|
2188
2205
|
|
package/src/tool-contract.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { ToolDef } from 'cortico/core/types.ts';
|
|
|
5
5
|
export const OPERATION_DECLS: ReadonlyArray<Omit<ToolDef, 'handler'>> = [
|
|
6
6
|
{
|
|
7
7
|
name: 'parlor_game_info', tags: ['read'],
|
|
8
|
-
description: '通用游戏查询。list 查服务器游戏目录,describe
|
|
8
|
+
description: '通用游戏查询。list 查服务器游戏目录,describe 查规则和完整动作参数,state 查当前桌面、本人秘密及可用动作,history 分页查获准查看的游戏历史。',
|
|
9
9
|
parameters: {
|
|
10
10
|
type: 'object', additionalProperties: false,
|
|
11
11
|
properties: {
|
|
@@ -14,7 +14,8 @@ export const OPERATION_DECLS: ReadonlyArray<Omit<ToolDef, 'handler'>> = [
|
|
|
14
14
|
table: { type: 'string', description: 'state/history 的桌号,省略时查自己的桌。' },
|
|
15
15
|
day: { type: 'integer', minimum: 1, description: 'history:按游戏天数筛选狼人杀记录,从第 1 天开始。' },
|
|
16
16
|
seatNo: { type: 'integer', minimum: 1, description: 'history:按座号筛选狼人杀发言与出局记录,从 1 开始。' },
|
|
17
|
-
limit: { type: 'integer', minimum: 1, maximum: 200, description: 'history
|
|
17
|
+
limit: { type: 'integer', minimum: 1, maximum: 200, description: 'history:每页最多多少条记录,默认 100,上限 200,也受返回字节上限约束。' },
|
|
18
|
+
cursor: { type: 'string', minLength: 1, maxLength: 64, description: 'history:续查时原样传回 log.nextCursor,沿用桌号和筛选条件。' },
|
|
18
19
|
review: { type: 'boolean', description: 'history:请求狼人杀复盘;仅终局后的参赛者可见夜间记录与完整死因。' },
|
|
19
20
|
},
|
|
20
21
|
},
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { el, btn, icon } from './common.js';
|
|
7
7
|
/* 内部模块统一带同一个版本号:版本不一致会让浏览器当成两份,订阅会各记各的。 */
|
|
8
|
-
import { onAnnouncements } from './announcements.js?v=0.37.
|
|
9
|
-
import { pickAnnouncement, rememberDismissed, excerpt } from './announcement-rules.js?v=0.37.
|
|
8
|
+
import { onAnnouncements } from './announcements.js?v=0.37.2';
|
|
9
|
+
import { pickAnnouncement, rememberDismissed, excerpt } from './announcement-rules.js?v=0.37.2';
|
|
10
10
|
|
|
11
11
|
const DISMISSED_KEY = 'parlor-announcements-dismissed';
|
|
12
12
|
const SEEN_KEY = 'parlor-announcements-seen';
|