cortico-world-parlor 0.27.3 → 0.28.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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.28.0
2
+
3
+ - 普通客厅固定 30 席:默认建厅、网页、Coo 工具与已有库迁移统一;大厅仍为 400 席。
4
+ - 房主可在成员管理中确认删除客厅(归档保留历史),释放在场席位并撤销待接受邀请;未结束牌桌阻止删除。
5
+ - Coo 所在客厅被删除时自动回大厅;网页断流后及时检查席位是否已失效。
6
+
1
7
  ## 0.27.3
2
8
 
3
9
  功能同 GitHub v0.27.2;npm 0.27.2 的暂存记录异常占位,正式发行顺延为 0.27.3。
package/README.md CHANGED
@@ -7,6 +7,12 @@ Owner: `src/definition.ts`
7
7
 
8
8
  ## 行为速览
9
9
 
10
+ - **普通客厅固定 30 人**:新建与已有普通客厅统一为 30 席,网页不再选择容量;大厅保留 400 席。
11
+ 旧客户端传来的 2–30 容量仍兼容,但服务器始终创建 30 席。已有客厅在服务启动迁移时统一。
12
+ - **删除客厅**:房主在网页「成员管理 → 删除客厅」确认后关闭自己的客厅;有未结束牌桌时拒绝。
13
+ 客厅从目录移除、在场席位释放、待接受邀请作废,历史、身份、筹码与战绩保留。大厅和系统默认厅不能删。
14
+ Coo 更新扩展后,所在客厅被删除会自动回大厅;旧版需升级扩展后重新启用。
15
+
10
16
  - **一房多桌**:普通客厅最多 10 张未结束的桌,一人同时坐一张;牌桌动作必须带 `requestId`,出牌还带 `revision`。
11
17
  - **结算即下桌**:打完一局不用退桌,直接开新桌;带桌号的旧动作会诚实回「你不在任何牌桌上」。
12
18
  - **可靠存档与恢复**:每个动作在一个 SQLite 事务里提交;短停机 ≤30 分钟续局(真人至少 10 秒),
package/describe.json CHANGED
@@ -640,7 +640,7 @@
640
640
  },
641
641
  {
642
642
  "name": "parlor_room_create",
643
- "description": "Create a room: name (2–32 chars), visibility public/unlisted/private, optional capacity (2–30) and topic. You do not enter it automatically; use parlor_room_visit afterwards.",
643
+ "description": "Create a room: name (2–32 chars), visibility public/unlisted/private, a fixed capacity of 30 talking seats, and optional topic. You do not enter it automatically; use parlor_room_visit afterwards.",
644
644
  "parameters": {
645
645
  "type": "object",
646
646
  "additionalProperties": false,
@@ -658,12 +658,6 @@
658
658
  ],
659
659
  "description": "public = listed in the directory; unlisted = reachable with the invite; private = invite only."
660
660
  },
661
- "capacity": {
662
- "type": "integer",
663
- "minimum": 2,
664
- "maximum": 30,
665
- "description": "Talking seats, default 8."
666
- },
667
661
  "topic": {
668
662
  "type": "string",
669
663
  "description": "One line shown in the directory."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-parlor",
3
- "version": "0.27.3",
3
+ "version": "0.28.0",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "筆離嘢"
package/src/room/db.ts CHANGED
@@ -166,8 +166,8 @@ export const migrate = (db: Db): void => {
166
166
  db.prepare('UPDATE rooms SET capacity = ? WHERE kind = ? AND capacity = ?')
167
167
  .run(HALL_CAPACITY, 'hall', 32);
168
168
 
169
- // 普通客厅单间上限 30;以前建过的大房按新口径收回来(大厅不动)。
170
- db.prepare('UPDATE rooms SET capacity = ? WHERE kind = ? AND capacity > ?')
169
+ // 所有普通客厅固定 30 席,含归档厅;大厅不动。
170
+ db.prepare('UPDATE rooms SET capacity = ? WHERE kind = ? AND capacity <> ?')
171
171
  .run(MAX_USER_ROOM_CAPACITY, 'room', MAX_USER_ROOM_CAPACITY);
172
172
 
173
173
  const stmt = db.prepare(
@@ -326,7 +326,7 @@ export class RoomHost {
326
326
  * 房主移除成员:立刻停止这一房的访问并释放席位;牌桌锁不拦(牌局由服务器托管到结算)。
327
327
  * 调用方先 `markTableAuto`,这里只管席位与事件。
328
328
  */
329
- remove(cooId: string, now = this.now()): LeaveResult | null {
329
+ remove(cooId: string, now = this.now(), reason: 'removed' | 'room_deleted' = 'removed'): LeaveResult | null {
330
330
  const seat = this.seatOf(cooId);
331
331
  if (!seat) return null;
332
332
  return withTransaction(this.db, () => {
@@ -335,8 +335,8 @@ export class RoomHost {
335
335
  ts: now,
336
336
  from: seat.id,
337
337
  scope: { kind: 'room' },
338
- text: `${seat.name} 被房主移出了${this.placeOf(this.roomId)}。`,
339
- data: { seatId: seat.id, name: seat.name, reason: 'removed' },
338
+ text: reason === 'room_deleted' ? '房主删除了客厅,席位已释放,请回大厅。' : `${seat.name} 被房主移出了${this.placeOf(this.roomId)}。`,
339
+ data: { seatId: seat.id, name: seat.name, reason },
340
340
  });
341
341
  const released = releaseSeat(this.db, this.roomId, seat.id, event.seq, now);
342
342
  return { seat: released, event };
@@ -17,7 +17,7 @@ import type { SeatKind, WakeTier } from './protocol.ts';
17
17
  export const MIN_ROOM_CAPACITY = 2;
18
18
  /** 建厅/改容量的上限:普通客厅 30 人;大厅另由 HALL_CAPACITY 管,库级兜底 500。 */
19
19
  export const MAX_ROOM_CAPACITY = MAX_USER_ROOM_CAPACITY;
20
- export const DEFAULT_ROOM_CAPACITY = 8;
20
+ export const DEFAULT_ROOM_CAPACITY = MAX_USER_ROOM_CAPACITY;
21
21
  export const MAX_ROOM_NAME = 32;
22
22
  export const MAX_ROOM_TOPIC = 80;
23
23
  export const MAX_SEAT_NAME = 24;
@@ -246,7 +246,8 @@ const cleanCapacity = (value: unknown): number => {
246
246
  if (!Number.isInteger(capacity) || (capacity as number) < MIN_ROOM_CAPACITY || (capacity as number) > MAX_ROOM_CAPACITY) {
247
247
  throw new RoomSeatError('invalid', `席位上限要在 ${MIN_ROOM_CAPACITY}–${MAX_ROOM_CAPACITY} 之间`);
248
248
  }
249
- return capacity as number;
249
+ // 兼容旧客户端的 2–30 参数,最终统一为 30 席。
250
+ return DEFAULT_ROOM_CAPACITY;
250
251
  };
251
252
 
252
253
  const cleanRoomId = (value: unknown): string => {
@@ -329,7 +330,7 @@ const createRoomTx = (db: Db, input: CreateRoomInput, now: number): RoomRow => {
329
330
  return requireRoom(db, id);
330
331
  };
331
332
 
332
- /** 建一个普通客厅(kind = 'room')。capacity 只接受 2–30。 */
333
+ /** 建一个普通客厅(kind = 'room')。固定 30 席;兼容旧客户端的 2–30 参数。 */
333
334
  export const createRoom = (db: Db, input: CreateRoomInput, now = Date.now()): RoomRow => (
334
335
  withTransaction(db, () => createRoomTx(db, input, now))
335
336
  );
@@ -21,7 +21,7 @@ import { likePrefix, parseHandleQuery } from './handles.ts';
21
21
  import { GLOBAL_HEADER, IdentityRegistry, enableGlobalIdentity, registeredHandle, identityOrigin, identityRequest, type GlobalPerson } from './global-identity.ts';
22
22
  import { HostError, RoomHost } from './room-host.ts';
23
23
  import {
24
- RoomSeatError, activeSeatForCoo, activeSeats, createRoom, getRoom, hashSeatToken,
24
+ RoomSeatError, activeSeatForCoo, activeSeats, archive, createRoom, getRoom, hashSeatToken,
25
25
  listRooms, memberOf, renameSeat, resolveRoom, seatByTokenHash, seatsForOfflineRelease,
26
26
  touchSeatSeen, type RoomRow,
27
27
  } from './room-seat-db.ts';
@@ -322,7 +322,6 @@ export class WorldServer {
322
322
  name: '默认客厅',
323
323
  ownerCooId: system,
324
324
  visibility: 'unlisted',
325
- capacity: 8,
326
325
  }, this.now());
327
326
  }
328
327
  this.ensureHall();
@@ -943,7 +942,7 @@ export class WorldServer {
943
942
  name,
944
943
  ownerCooId: cooId,
945
944
  ...(visibility ? { visibility } : {}),
946
- ...(capacity ? { capacity } : {}),
945
+ ...(capacity !== undefined ? { capacity } : {}),
947
946
  ...(topic ? { topic } : {}),
948
947
  }, this.now());
949
948
  json(res, 200, { room: roomSummary(this.db, room) });
@@ -964,8 +963,8 @@ export class WorldServer {
964
963
  return;
965
964
  }
966
965
 
967
- // —— 私密厅:成员管理 / 可见性 / 房主邀请 ——
968
- const managed = url.pathname.match(/^\/v1\/rooms\/([^/]+)\/(access|visibility|invite)$/);
966
+ // —— 房主:成员管理 / 可见性 / 房主邀请 / 删除客厅 ——
967
+ const managed = url.pathname.match(/^\/v1\/rooms\/([^/]+)\/(access|visibility|invite|delete)$/);
969
968
  if (managed) {
970
969
  const roomId = managed[1];
971
970
  const what = managed[2];
@@ -973,6 +972,24 @@ export class WorldServer {
973
972
  if (!room) throw new HttpError(404, '客厅不存在');
974
973
  const manager = this.roomManager(req, roomId);
975
974
  const now = this.now();
975
+ if (what === 'delete' && method === 'POST') {
976
+ if (room.kind !== 'room' || room.id === this.defaultRoomId || room.ownerCooId === 'system-owner') {
977
+ throw new HttpError(403, '大厅和系统默认客厅不能删除');
978
+ }
979
+ const host = this.host(roomId);
980
+ withTransaction(this.db, () => {
981
+ const live = this.db.prepare(
982
+ "SELECT 1 FROM tables WHERE room_id = ? AND status IN ('open','bidding','playing') LIMIT 1",
983
+ ).get(roomId);
984
+ if (live) throw new HttpError(409, '客厅里还有未结束的牌桌,请先结束牌局或收起等待中的桌子');
985
+ for (const seat of activeSeats(this.db, roomId)) host.remove(seat.cooId, now, 'room_deleted');
986
+ revokeInvitationsFor(this.db, roomId, null, now);
987
+ archive(this.db, roomId, now);
988
+ });
989
+ json(res, 200, { ok: true, room: roomSummary(this.db, getRoom(this.db, roomId)!) });
990
+ return;
991
+ }
992
+ if (room.archivedAt !== null) throw new HttpError(409, '这个客厅已经删除');
976
993
  if (what === 'access' && method === 'GET') {
977
994
  expireInvitations(this.db, now);
978
995
  const ownerRow = room.ownerCooId
package/src/web/play.js CHANGED
@@ -19,19 +19,8 @@ const RULES = {
19
19
 
20
20
  /** 这版大厅只露出斗地主;哪些游戏露出来由 games/registry.js 的 enabled 决定。 */
21
21
 
22
- /** 建厅时的人数上限(普通客厅最多 30;大厅的 400 不在这里选)。 */
23
- const ROOM_CAPACITY_CHOICES = [8, 16, 30];
24
-
25
- function capacitySelect() {
26
- const select = el('select');
27
- select.setAttribute('aria-label', '人数上限');
28
- for (const value of ROOM_CAPACITY_CHOICES) {
29
- const option = el('option', '', `${value} 人`);
30
- option.value = String(value);
31
- select.append(option);
32
- }
33
- return select;
34
- }
22
+ /** 普通客厅固定 30 人;大厅容量由服务器单独管理。 */
23
+ const ROOM_CAPACITY = 30;
35
24
 
36
25
  const state = {
37
26
  cfg: readStore(),
@@ -214,7 +203,7 @@ async function tryParentEntry(key = '', options = {}) {
214
203
  const played = await fetch('/v1/parent/play', {
215
204
  method: 'POST',
216
205
  headers: { 'content-type': 'application/json' },
217
- body: JSON.stringify(key ? { key } : {}),
206
+ body: JSON.stringify({ ...(key ? { key } : {}), ...(options.room ? { room: options.room } : {}) }),
218
207
  ...timeoutSignal(),
219
208
  });
220
209
  const body = await played.json().catch(() => ({}));
@@ -615,6 +604,8 @@ function connect() {
615
604
  setConn('off');
616
605
  source.close();
617
606
  if (state.stream === source) state.stream = null;
607
+ // 服务端收回席位后及时检查状态,进入重新入场流程。
608
+ scheduleRefresh();
618
609
  state.reconnect = setTimeout(connect, 3000);
619
610
  };
620
611
  }
@@ -988,7 +979,7 @@ function buildShell() {
988
979
  const lobbyTitle = el('h1', '', '灯还亮着。');
989
980
  const lobbySub = el('p');
990
981
  lobbyCopy.append(lobbyEyebrow, lobbyTitle, lobbySub);
991
- lobbyHead.append(lobbyCopy);
982
+ lobbyHead.append(lobbyCopy, roomManage);
992
983
  const gameGrid = el('div', 'game-grid');
993
984
  // 玩法说明由 registry 里的 guide 生成(见 renderGuides);这里只留壳。
994
985
  const guide = el('section', 'panel ddz-guide');
@@ -1037,7 +1028,7 @@ function buildShell() {
1037
1028
  option.value = value;
1038
1029
  hallCreateVis.append(option);
1039
1030
  }
1040
- const hallCreateCap = capacitySelect();
1031
+ const hallCreateCap = el('span', 'muted', '固定 30 人');
1041
1032
  const hallCreateBtn = btn('开一间', () => { void createHallRoom(); }, { primary: true, small: true });
1042
1033
  const hallCreateRow = el('div', 'hall-create-row');
1043
1034
  hallCreateRow.append(hallCreateName, hallCreateVis, hallCreateCap, hallCreateBtn);
@@ -1988,7 +1979,7 @@ async function createHallRoom() {
1988
1979
  body: JSON.stringify({
1989
1980
  name,
1990
1981
  visibility: ui.hallCreateVis.value,
1991
- capacity: Number(ui.hallCreateCap.value),
1982
+ capacity: ROOM_CAPACITY,
1992
1983
  }),
1993
1984
  });
1994
1985
  ui.hallCreateName.value = '';
@@ -2535,7 +2526,7 @@ function ensureRoomsDialog() {
2535
2526
  option.value = value;
2536
2527
  visInput.append(option);
2537
2528
  }
2538
- const capInput = capacitySelect();
2529
+ const capInput = el('span', 'muted', '固定 30 人');
2539
2530
  const createBtn = btn('开一间', async () => {
2540
2531
  const name = nameInput.value.trim();
2541
2532
  if (name.length < 2) {
@@ -2550,7 +2541,7 @@ function ensureRoomsDialog() {
2550
2541
  body: JSON.stringify({
2551
2542
  name,
2552
2543
  visibility: visInput.value,
2553
- capacity: Number(capInput.value),
2544
+ capacity: ROOM_CAPACITY,
2554
2545
  }),
2555
2546
  });
2556
2547
  await goRoom(created.room.id);
@@ -2798,6 +2789,45 @@ function renderAccess(data) {
2798
2789
  visSection.append(visRow);
2799
2790
  visSection.append(el('p', 'note', '改成私密不会自动授权现在在厅里的人,要在这里逐个授权或邀请。'));
2800
2791
  accessBody.append(visSection);
2792
+
2793
+ const deleteSection = el('section', 'access-section');
2794
+ deleteSection.append(el('h3', '', '删除客厅'));
2795
+ deleteSection.append(el('p', 'note', '删除后从目录移除,在场席位和未接受的邀请会失效。历史、身份和筹码保留;有未结束牌桌时不能删除。'));
2796
+ const deleteBtn = btn('删除客厅', () => { void deleteRoom(data.room, deleteBtn); }, {
2797
+ danger: true, small: true,
2798
+ });
2799
+ deleteSection.append(deleteBtn);
2800
+ accessBody.append(deleteSection);
2801
+ }
2802
+
2803
+ async function deleteRoom(room, button) {
2804
+ if (!room || !confirm('确定删除「' + room.name + '」?在场的所有人都会离开,未接受的邀请会失效。')) return;
2805
+ button.disabled = true;
2806
+ try {
2807
+ await api('/v1/rooms/' + encodeURIComponent(room.id) + '/delete', { method: 'POST' });
2808
+ accessDialog.close();
2809
+ if (currentRoom() === room.id) {
2810
+ if (state.stream) state.stream.close();
2811
+ state.stream = null;
2812
+ clearTimeout(state.reconnect);
2813
+ clearTimeout(state.refreshTimer);
2814
+ state.refreshTimer = null;
2815
+ clearStore();
2816
+ if (await tryParentEntry('', { room: 'hall' })) {
2817
+ if (state.cfg) location.href = '/play?room=hall';
2818
+ } else {
2819
+ await loadEntryPolicy();
2820
+ renderJoin('客厅已删除,请重新加入大厅。');
2821
+ }
2822
+ } else {
2823
+ showToast('客厅已删除');
2824
+ void loadHall(true);
2825
+ }
2826
+ } catch (error) {
2827
+ showToast(error.message || '删除失败', 'bad');
2828
+ } finally {
2829
+ button.disabled = false;
2830
+ }
2801
2831
  }
2802
2832
 
2803
2833
  /** verb:成员列表用「移出」,在场列表用「请出」;两处走同一个 revoke。 */
package/src/world.ts CHANGED
@@ -312,7 +312,7 @@ export const PARLOR_TOOL_DECLS: ReadonlyArray<Omit<ToolDef, 'handler'>> = [
312
312
  },
313
313
  {
314
314
  name: 'parlor_room_create',
315
- description: 'Create a room: name (2–32 chars), visibility public/unlisted/private, optional capacity (2–30) and topic. You do not enter it automatically; use parlor_room_visit afterwards.',
315
+ description: 'Create a room: name (2–32 chars), visibility public/unlisted/private, a fixed capacity of 30 talking seats, and optional topic. You do not enter it automatically; use parlor_room_visit afterwards.',
316
316
  tags: ['write'],
317
317
  parameters: {
318
318
  type: 'object',
@@ -320,7 +320,6 @@ export const PARLOR_TOOL_DECLS: ReadonlyArray<Omit<ToolDef, 'handler'>> = [
320
320
  properties: {
321
321
  name: { type: 'string', description: 'Room name, 2–32 characters.' },
322
322
  visibility: { type: 'string', enum: ['public', 'unlisted', 'private'], description: 'public = listed in the directory; unlisted = reachable with the invite; private = invite only.' },
323
- capacity: { type: 'integer', minimum: 2, maximum: 30, description: 'Talking seats, default 8.' },
324
323
  topic: { type: 'string', description: 'One line shown in the directory.' },
325
324
  },
326
325
  required: ['name'],
@@ -648,11 +647,21 @@ export class ParlorWorld implements World {
648
647
 
649
648
  /** 用现有身份入座,拿一枚新令牌;启动和「席位被释放后自动重连」共用。 */
650
649
  private async joinRoom(client: ParlorClient): Promise<void> {
651
- const joined = await client.join(this.inviteCode, {
652
- name: this.baseSeatName(),
653
- kind: 'pet',
654
- tier: this.ctx.cfg.wakeTier,
655
- }, this.roomArg());
650
+ const request = { name: this.baseSeatName(), kind: 'pet' as const, tier: this.ctx.cfg.wakeTier };
651
+ let joined;
652
+ try {
653
+ joined = await client.join(this.inviteCode, request, this.roomArg());
654
+ } catch (error) {
655
+ // 删除客厅后保留身份和账本,回大厅重新入座。
656
+ if (!this.multiRoom || !(error instanceof ParlorHttpError)
657
+ || error.status !== 403 || !error.message.includes('已经归档')) throw error;
658
+ joined = await client.join(this.inviteCode, request, 'hall');
659
+ this.currentRoom = 'hall';
660
+ this.pending = [];
661
+ this.focusBacklog = [];
662
+ this.focused = false;
663
+ await this.reportLink('原客厅已被房主删除,已回到大厅。');
664
+ }
656
665
  this.token = joined.token;
657
666
  // 新网关首次建家长账户时给一次 ownerKey;旧服务器给的是每厅 ownerToken。
658
667
  // 已有账户再次加入不会发新钥匙:这时要留住 .env 里那把,别拿空串覆盖。
@@ -1038,7 +1047,7 @@ export class ParlorWorld implements World {
1038
1047
  const created = await this.client.createRoom({
1039
1048
  name,
1040
1049
  ...(visibility ? { visibility } : {}),
1041
- ...(capacity !== undefined ? { capacity } : {}),
1050
+ capacity: 30,
1042
1051
  ...(typeof args.topic === 'string' && args.topic.trim() ? { topic: args.topic.trim() } : {}),
1043
1052
  }, this.token || undefined);
1044
1053
  const room = created.room;