Files
ark-stronghold-protocol/server/skland/recovery.js
T
herryyun 7c25c89992
CI / test (ubuntu-latest, node 22) (push) Failing after 33m10s
CI / test (ubuntu-latest, node 24) (push) Failing after 34m41s
CI / tooling (lint, imports, typecheck) (push) Failing after 36m11s
CI / test (windows-latest, node 22) (push) Canceled after 0s
CI / test (windows-latest, node 24) (push) Canceled after 0s
实现账号绑定、持久登录与跨设备对局恢复
2026-10-14 23:22:50 +08:00

23 lines
1016 B
JavaScript

// Account recovery describes only the selected role's live server-side seat. It never reads browser caches.
import { randomUUID } from 'node:crypto';
export function createAccountRecovery({ registry, lobby }) {
const roomIds = new WeakMap();
return {
describe(playerId) {
const session = playerId && registry.byId(playerId);
if (!session || registry.isExpired(session, registry.now())) return null;
const room = lobby.roomOf(session);
if (!room || room.disposed) return null;
if (!roomIds.has(room)) roomIds.set(room, randomUUID());
return {
// A selector, not a credential: a replaced room or a later match must not satisfy a stale recovery request.
id: roomIds.get(room) + ':' + room.matchCount,
name: session.name, code: room.code, mode: room.mode, difficulty: room.difficulty,
inMatch: !!room.match, round: room.match?.round ?? 0,
connected: session.connected, spectating: !!room.spectatorOf(playerId),
};
},
};
}