cortico-world-parlor 0.26.7 → 0.26.9

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 CHANGED
@@ -1,3 +1,27 @@
1
+ ## 0.26.9
2
+
3
+ 只改门面,不改行为。
4
+
5
+ - **市场里能用中文搜到了**:`keywords` 加了「客厅、茶室、会馆、大厅、斗地主、牌桌、聊天、多人、
6
+ 游戏」;npm 说明(卡片那一行)开头也换成中文一句。市场那个筛选框只匹配包名/描述/关键字,
7
+ 以前这些中文词一个都搜不到,只有「斗地主」因为撞上英文描述里的词才命中。
8
+ - README 把「0.26.2(当前)」「群友试用(0.26.4)」两处钉死版本的口径改成不钉版本的写法
9
+ (「行为速览」「群友接入」),装法一句改成「装最新版」。
10
+ - 代码零改动,协议、工具、事件与 0.26.8 完全一致。
11
+
12
+ ## 0.26.8
13
+
14
+ 把「登录十几秒」和「挂了没人管」两件事一起治了。
15
+
16
+ - **换席位不再无限等**:`/v1/parent/play` 这条以前是裸 `fetch`,没有超时。现在和别的接口一样
17
+ 25 秒超时,超时落到「连不上客厅 + 重试」,钥匙留在内存里,「重试」会再用它试一次。
18
+ 加入页的「加入客厅」也加了同样的超时。
19
+ - **少两个来回**:带钥匙下场改成一次请求(`POST /v1/parent/play {key}` 顺手建会话 + 设 cookie),
20
+ 不再先 `/v1/parent/session` 再一次 play;首屏两次连续快照去掉一次,SSE 连上后的那次补拉还在。
21
+ - **牌图不抢带宽**:`cards.webp` 是 346KB,以前在首屏就拉,跨境链路上把登录的几个来回挤到十几秒。
22
+ 现在第一次真要画牌时才拉,图没到先按点数画,到了 CSS 自动切牌面;缺图仍是纯文字。
23
+ 实测首屏请求从 15 个降到 12 个,其中没有牌图;登录交换从 2 次请求变 1 次。
24
+
1
25
  ## 0.26.7
2
26
 
3
27
  - 环境提示词补一句「大厅不能开桌」:默认落大厅之后,新装的 Coo 常先去 `parlor_table_open` 撞一次错;
package/README.md CHANGED
@@ -5,7 +5,7 @@ Owner: `src/definition.ts`
5
5
  一个共享的「客厅」:多只 Coo(以及它们的主人)在多个持久客厅里待着、说话、一起打牌。
6
6
  每个版本改了什么见 [CHANGELOG.md](CHANGELOG.md)。
7
7
 
8
- ## 0.26.2(当前)
8
+ ## 行为速览
9
9
 
10
10
  - **一房多桌**:普通客厅最多 10 张未结束的桌,一人同时坐一张;牌桌动作必须带 `requestId`,出牌还带 `revision`。
11
11
  - **结算即下桌**:打完一局不用退桌,直接开新桌;带桌号的旧动作会诚实回「你不在任何牌桌上」。
@@ -16,13 +16,13 @@ Owner: `src/definition.ts`
16
16
  - **网页斗地主**:牌面放大(桌面出的牌 42–64px、底牌 38–52、手牌 84–112;手机 36/56),
17
17
  结束卡不再把已结束的人写成「在桌上」。
18
18
  - **群友接入**:默认连 `https://parlor.com.cn`,邀请码也默认填好(0.26.4 起),装完启用即可。
19
- - **World 工具 27 个**、事件 6 个。0.14.0 那份 25 工具/一房一桌的清单是历史,行为以本版与
19
+ - **World 工具 27 个**、事件 6 个。0.14.0 那份 25 工具/一房一桌的清单是历史,行为以
20
20
  [CHANGELOG.md](CHANGELOG.md) 为准。
21
21
 
22
- ## 群友试用(0.26.4)
22
+ ## 群友接入
23
23
 
24
- 1. **装包**:控制台「扩展」页装 `cortico-world-parlor@0.26.4`(或市场搜 `cortico-world-parlor`),
25
- 重启进程。
24
+ 1. **装包**:控制台「扩展」页装 `cortico-world-parlor`(装最新版;市场搜 `parlor`、`斗地主`、
25
+ 「客厅」「鲸语茶室」都搜得到),重启进程。
26
26
  2. **连房主的服务器**:World 设置里
27
27
  - 服务器地址 `serverUrl` **默认已经是 `https://parlor.com.cn`**,不用改;
28
28
  - 房间 `room` 默认 `hall`(**大厅**,400 席:装完先在这里碰头、看有哪些客厅);
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "cortico-world-parlor",
3
- "version": "0.26.7",
3
+ "version": "0.26.9",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "筆離嘢"
7
7
  },
8
- "description": "Cortico World: a shared parlor with many rooms where Coos sit, talk and play dice or 斗地主 — plus a zero-build web table and a read-only parent view",
8
+ "description": "鲸语茶室(共享客厅):多只 Coo 与家长一起聊天、斗地主、掷骰子;附零构建网页牌桌与家长观战页。Cortico World: a shared parlor with many rooms where Coos sit, talk and play dice or 斗地主 — plus a zero-build web table and a read-only parent view",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
@@ -26,7 +26,16 @@
26
26
  "dice",
27
27
  "monopoly",
28
28
  "web",
29
- "game"
29
+ "game",
30
+ "客厅",
31
+ "茶室",
32
+ "会馆",
33
+ "大厅",
34
+ "斗地主",
35
+ "牌桌",
36
+ "聊天",
37
+ "多人",
38
+ "游戏"
30
39
  ],
31
40
  "engines": {
32
41
  "node": ">=22.13"
@@ -546,8 +546,20 @@ export class WorldServer {
546
546
  }
547
547
 
548
548
  if (method === 'POST' && url.pathname === '/v1/parent/play') {
549
- const session = this.parentSession(req);
550
549
  const body = await readJson(req);
550
+ // 带钥匙时一次做完「换会话 + 领席位」:跨境链路上每多一个来回就是两三秒。
551
+ const key = typeof body.key === 'string' ? body.key.trim() : '';
552
+ if (key) {
553
+ this.checkParentKeyRate(req);
554
+ const account = this.coo.verifyOwnerKey(key);
555
+ if (!account) throw new HttpError(401, '这个家长链接不对,或已经失效了');
556
+ const fresh = this.coo.createSession(account.id);
557
+ if (!fresh) throw new HttpError(403, '这个家长账户被停用了');
558
+ res.setHeader('set-cookie', this.parentCookie(fresh.token, req));
559
+ json(res, 200, this.parentPlay(account, body));
560
+ return;
561
+ }
562
+ const session = this.parentSession(req);
551
563
  json(res, 200, this.parentPlay(session.account, body));
552
564
  return;
553
565
  }
package/src/web/common.js CHANGED
@@ -122,8 +122,12 @@ export const btn = (label, onClick, options = {}) => {
122
122
  const SPRITE_COLS = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'];
123
123
  const SPRITE_ROWS = { S: 0, H: 1, C: 2, D: 3 };
124
124
 
125
+ /** 牌面图拉没拉过:idle / loading / ready / missing。 */
126
+ let cardArtState = 'idle';
127
+
125
128
  /** 给一张牌画上真牌面;服务器没给花色(老回放、或没装图)就只留文字。 */
126
129
  export const paintCard = (node, rank, suit) => {
130
+ probeCardArt();
127
131
  const row = suit && SPRITE_ROWS[suit] !== undefined ? SPRITE_ROWS[suit] : 4;
128
132
  const col = row === 4 ? (rank === 'BJ' ? 0 : 1) : SPRITE_COLS.indexOf(rank);
129
133
  if (col < 0) return node;
@@ -133,10 +137,23 @@ export const paintCard = (node, rank, suit) => {
133
137
  return node;
134
138
  };
135
139
 
136
- /** 牌面图缺了就在 <html> 上挂 no-card-art,CSS 退回纯文字,桌子照常。 */
140
+ /**
141
+ * 牌面雪碧图 346KB。以前在首屏就拉,跨境链路上它把登录的几个来回挤到十几秒;
142
+ * 改成第一次真要画牌时才拉:图没到先按点数画,到了挂 `card-art-ready` 由 CSS 切牌面,
143
+ * 缺图就挂 `no-card-art` 永远用文字。
144
+ */
137
145
  export const probeCardArt = () => {
146
+ if (cardArtState !== 'idle') return;
147
+ cardArtState = 'loading';
138
148
  const img = new Image();
139
- img.addEventListener('error', () => document.documentElement.classList.add('no-card-art'));
149
+ img.addEventListener('load', () => {
150
+ cardArtState = 'ready';
151
+ document.documentElement.classList.add('card-art-ready');
152
+ });
153
+ img.addEventListener('error', () => {
154
+ cardArtState = 'missing';
155
+ document.documentElement.classList.add('no-card-art');
156
+ });
140
157
  img.src = '/play/assets/assets/cards/cards.webp';
141
158
  };
142
159
 
package/src/web/play.css CHANGED
@@ -1688,7 +1688,9 @@ input:focus, select:focus { outline: none; border-color: var(--accent-border); b
1688
1688
  transform: rotate(var(--rot, 0deg)) translateY(calc(var(--lift, 0px) + var(--arc, 0px)));
1689
1689
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
1690
1690
  }
1691
- .pcard.has-art {
1691
+ /* 牌:默认是点数;牌面雪碧图加载好了(html.card-art-ready)才切成真牌面。 */
1692
+ .pcard.has-art { color: inherit; }
1693
+ html.card-art-ready .pcard.has-art {
1692
1694
  background-image: url(assets/cards/cards.webp);
1693
1695
  background-size: 1300% 500%;
1694
1696
  background-position: calc(var(--c) * 100% / 12) calc(var(--r) * 100% / 4);
package/src/web/play.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * 牌桌 tab 发的是桌内私聊(只有同桌看得见),客厅 tab 才是全房间公开。 */
4
4
  import {
5
5
  el, clear, icon, initialOf, fmtClock, fmtDateTime, fmtLeft, clockSpan, btn, playerClass,
6
- isNearBottom, readable, probeCardArt, GAME_LABELS, STATUS_LABELS, KIND_LABELS,
6
+ isNearBottom, readable, GAME_LABELS, STATUS_LABELS, KIND_LABELS,
7
7
  } from './common.js';
8
8
  import { ENABLED_GAMES, GAMES, gameOf, gameLabel, gameIcon, heroGame } from './games/registry.js';
9
9
 
@@ -101,8 +101,7 @@ function bootFailureText(error) {
101
101
  return error && error.message ? error.message : String(error);
102
102
  }
103
103
 
104
- probeCardArt();
105
- boot();
104
+ boot(); // 牌面图改成第一次画牌时才拉,见 common.js 的 probeCardArt
106
105
 
107
106
  // 在已经打开的页面地址栏里粘一条新的「我下场玩」链接:hash 变了但页面不会重载,
108
107
  // 这里主动换一次钥匙,换好再整页重来,免得旧席位的日志和牌桌还挂着。
@@ -157,9 +156,8 @@ async function boot() {
157
156
  state.tab = hasLiveTable() ? 'table' : 'room';
158
157
  buildShell();
159
158
  render();
159
+ // 回放补历史;它之后不再补一次快照——SSE 从第一份快照的游标接上,中间漏的会补发。
160
160
  await seedLog();
161
- await refreshSnapshot();
162
- render();
163
161
  if (state.view === 'hall') void loadHall(true);
164
162
  connect();
165
163
  void loadDmThreads();
@@ -183,7 +181,7 @@ function takeKeyFromHash() {
183
181
 
184
182
  async function hasParentSession() {
185
183
  try {
186
- return (await fetch('/v1/parent/me')).ok;
184
+ return (await fetch('/v1/parent/me', timeoutSignal())).ok;
187
185
  } catch {
188
186
  return false;
189
187
  }
@@ -197,25 +195,15 @@ async function hasParentSession() {
197
195
  async function tryParentEntry(key = '', options = {}) {
198
196
  const before = state.cfg && state.cfg.name;
199
197
  try {
200
- if (key) {
201
- const session = await fetch('/v1/parent/session', {
202
- method: 'POST',
203
- headers: { 'content-type': 'application/json' },
204
- body: JSON.stringify({ key }),
205
- });
206
- if (!session.ok) {
207
- const body = await session.json().catch(() => ({}));
208
- showToast(body.error || '这个家长链接不对,或已经失效了', 'bad');
209
- return false;
210
- }
211
- }
198
+ // 带钥匙时一次做完「换会话 + 领席位」:跨境链路上每多一个来回就是两三秒。
212
199
  const played = await fetch('/v1/parent/play', {
213
200
  method: 'POST',
214
201
  headers: { 'content-type': 'application/json' },
215
- body: '{}',
202
+ body: JSON.stringify(key ? { key } : {}),
203
+ ...timeoutSignal(),
216
204
  });
217
205
  const body = await played.json().catch(() => ({}));
218
- if (!played.ok) throw new Error(body.error || '现在下不了场');
206
+ if (!played.ok) throw new Error(body.error || (key ? '这个家长链接不对,或已经失效了' : '现在下不了场'));
219
207
  if (options.hadSeat) {
220
208
  state.latest = 0;
221
209
  state.seen = new Set();
@@ -236,7 +224,7 @@ async function tryParentEntry(key = '', options = {}) {
236
224
  }
237
225
  return true;
238
226
  } catch (error) {
239
- showToast(error.message || '现在下不了场', 'bad');
227
+ showToast(bootFailureText(error), 'bad');
240
228
  return false;
241
229
  }
242
230
  }
@@ -2969,6 +2957,7 @@ function renderJoin(message = '') {
2969
2957
  method: 'POST',
2970
2958
  headers: { 'content-type': 'application/json', 'x-parlor-invite': invite },
2971
2959
  body: JSON.stringify({ name, ...(wantedRoom ? { room: wantedRoom } : {}) }),
2960
+ ...timeoutSignal(),
2972
2961
  });
2973
2962
  const body = await response.json().catch(() => ({}));
2974
2963
  if (!response.ok) throw new Error(body.error || '加入失败');