@hadoku/game-server 0.1.103 → 0.1.104
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/dist/erase/anonymise.d.ts +5 -5
- package/dist/erase/anonymise.js +5 -5
- package/dist/erase/index.d.ts +7 -4
- package/dist/erase/index.js +8 -3
- package/dist/erase/legacy-ids.d.ts +3 -1
- package/dist/erase/legacy-ids.js +23 -14
- package/dist/erase/recordings.d.ts +2 -0
- package/dist/erase/recordings.js +76 -43
- package/dist/erase/rooms.d.ts +17 -0
- package/dist/erase/rooms.js +36 -11
- package/dist/room/events.d.ts +10 -0
- package/dist/room/events.js +8 -1
- package/dist/room/lobby.d.ts +10 -0
- package/dist/room/lobby.js +22 -1
- package/package.json +5 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Adapter: cardtable's binding of `@hadoku/service-kernel/erase`'s `placeholderId`/`replaceIds`
|
|
3
|
-
*
|
|
4
|
-
* at this path for its importers
|
|
5
|
-
* `room/lobby.ts`, `room/tournaments.ts`).
|
|
2
|
+
* Adapter: cardtable's binding of `@hadoku/service-kernel/erase`'s id walks (`placeholderId`/`replaceIds`
|
|
3
|
+
* for an erase, `renameIds`/`moveIds`/`namesAny` for a merge; w93-K3). All are fully generic (no
|
|
4
|
+
* cardtable value baked in), so this is a pure re-export kept at this path for its importers
|
|
5
|
+
* (`erase/recordings.ts`, `room/draftRooms.ts`, `room/events.ts`, `room/lobby.ts`, `room/tournaments.ts`).
|
|
6
6
|
*/
|
|
7
|
-
export { placeholderId, replaceIds } from '@wolffm/service-kernel/erase';
|
|
7
|
+
export { moveIds, namesAny, placeholderId, renameIds, replaceIds, type IdMove } from '@wolffm/service-kernel/erase';
|
package/dist/erase/anonymise.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Adapter: cardtable's binding of `@hadoku/service-kernel/erase`'s `placeholderId`/`replaceIds`
|
|
3
|
-
*
|
|
4
|
-
* at this path for its importers
|
|
5
|
-
* `room/lobby.ts`, `room/tournaments.ts`).
|
|
2
|
+
* Adapter: cardtable's binding of `@hadoku/service-kernel/erase`'s id walks (`placeholderId`/`replaceIds`
|
|
3
|
+
* for an erase, `renameIds`/`moveIds`/`namesAny` for a merge; w93-K3). All are fully generic (no
|
|
4
|
+
* cardtable value baked in), so this is a pure re-export kept at this path for its importers
|
|
5
|
+
* (`erase/recordings.ts`, `room/draftRooms.ts`, `room/events.ts`, `room/lobby.ts`, `room/tournaments.ts`).
|
|
6
6
|
*/
|
|
7
|
-
export { placeholderId, replaceIds } from '@wolffm/service-kernel/erase';
|
|
7
|
+
export { moveIds, namesAny, placeholderId, renameIds, replaceIds } from '@wolffm/service-kernel/erase';
|
package/dist/erase/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Cardtable's binding of `@hadoku/service-kernel/erase` — `POST /api/_account/erase
|
|
2
|
+
* Cardtable's binding of `@hadoku/service-kernel/erase` — `POST /api/_account/erase` and its
|
|
3
|
+
* merge counterpart, `POST /api/_account/merge` (same admission; the kernel's `erase.ts` has the contract).
|
|
3
4
|
*
|
|
4
5
|
* The edge calls it on the tunnel origin with `X-Edge-Auth` (its seal), `X-Hadoku-Tier: member`
|
|
5
6
|
* and `X-User-Id`. Only the seal admits it (`createGameServer` passes `edgeAuth.edgeSealed`), never
|
|
@@ -11,8 +12,10 @@
|
|
|
11
12
|
* What stays here is the `fk:` id a person is also known by (`room/identity.ts`), which the
|
|
12
13
|
* kernel is handed as `deriveParticipantId`, and the steps' shared types.
|
|
13
14
|
*/
|
|
14
|
-
import { ERASE_PATH, type AccountErase, type EraseCounts, type ErasedPerson, type EraseStep } from '@wolffm/service-kernel/erase';
|
|
15
|
-
export { ERASE_PATH };
|
|
16
|
-
export type { AccountErase, EraseCounts, ErasedPerson, EraseStep };
|
|
15
|
+
import { ERASE_PATH, MERGE_PATH, type AccountErase, type AccountIds, type EraseCounts, type ErasedPerson, type EraseStep, type MergedAccounts } from '@wolffm/service-kernel/erase';
|
|
16
|
+
export { ERASE_PATH, MERGE_PATH };
|
|
17
|
+
export type { AccountErase, AccountIds, EraseCounts, ErasedPerson, EraseStep, MergedAccounts };
|
|
17
18
|
export declare const fkOf: (userId: string) => string;
|
|
18
19
|
export declare function personOf(userId: string): ErasedPerson;
|
|
20
|
+
/** One merge of `fromUserId` into `intoUserId`, by cardtable's `fk:` ids too (`POST /api/_account/merge`). */
|
|
21
|
+
export declare function mergedAccountsOf(fromUserId: string, intoUserId: string): MergedAccounts;
|
package/dist/erase/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Cardtable's binding of `@hadoku/service-kernel/erase` — `POST /api/_account/erase
|
|
2
|
+
* Cardtable's binding of `@hadoku/service-kernel/erase` — `POST /api/_account/erase` and its
|
|
3
|
+
* merge counterpart, `POST /api/_account/merge` (same admission; the kernel's `erase.ts` has the contract).
|
|
3
4
|
*
|
|
4
5
|
* The edge calls it on the tunnel origin with `X-Edge-Auth` (its seal), `X-Hadoku-Tier: member`
|
|
5
6
|
* and `X-User-Id`. Only the seal admits it (`createGameServer` passes `edgeAuth.edgeSealed`), never
|
|
@@ -11,10 +12,14 @@
|
|
|
11
12
|
* What stays here is the `fk:` id a person is also known by (`room/identity.ts`), which the
|
|
12
13
|
* kernel is handed as `deriveParticipantId`, and the steps' shared types.
|
|
13
14
|
*/
|
|
14
|
-
import { ERASE_PATH, personOf as kernelPersonOf, } from '@wolffm/service-kernel/erase';
|
|
15
|
+
import { ERASE_PATH, MERGE_PATH, mergedAccountsOf as kernelMergedAccountsOf, personOf as kernelPersonOf, } from '@wolffm/service-kernel/erase';
|
|
15
16
|
import { deriveParticipantId } from '../room/identity.js';
|
|
16
|
-
export { ERASE_PATH };
|
|
17
|
+
export { ERASE_PATH, MERGE_PATH };
|
|
17
18
|
export const fkOf = (userId) => deriveParticipantId({ accountId: userId, socketId: '' });
|
|
18
19
|
export function personOf(userId) {
|
|
19
20
|
return kernelPersonOf(userId, fkOf);
|
|
20
21
|
}
|
|
22
|
+
/** One merge of `fromUserId` into `intoUserId`, by cardtable's `fk:` ids too (`POST /api/_account/merge`). */
|
|
23
|
+
export function mergedAccountsOf(fromUserId, intoUserId) {
|
|
24
|
+
return kernelMergedAccountsOf(fromUserId, intoUserId, fkOf);
|
|
25
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `legacy-ids.done.json`: the record the R12 identity reset's one-off remap left behind on
|
|
3
3
|
* prod (old key-derived id → the userId it was moved to). Nothing reads it any more, but it
|
|
4
|
-
* names people by userId, so an erase removes the person's entries from it
|
|
4
|
+
* names people by userId, so an erase removes the person's entries from it, and a merge points
|
|
5
|
+
* them at the kept account (an old id was that person's, and the person is now the kept account).
|
|
6
|
+
* Absent is fine.
|
|
5
7
|
*/
|
|
6
8
|
import type { EraseStep } from './index.js';
|
|
7
9
|
export declare function legacyIdsStep(file: string): EraseStep;
|
package/dist/erase/legacy-ids.js
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `legacy-ids.done.json`: the record the R12 identity reset's one-off remap left behind on
|
|
3
3
|
* prod (old key-derived id → the userId it was moved to). Nothing reads it any more, but it
|
|
4
|
-
* names people by userId, so an erase removes the person's entries from it
|
|
4
|
+
* names people by userId, so an erase removes the person's entries from it, and a merge points
|
|
5
|
+
* them at the kept account (an old id was that person's, and the person is now the kept account).
|
|
6
|
+
* Absent is fine.
|
|
5
7
|
*/
|
|
6
8
|
import { existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
7
9
|
export function legacyIdsStep(file) {
|
|
10
|
+
/** Rewrite every entry that maps to `userId` (`to`: its new userId, or undefined to drop it). Answers how many. */
|
|
11
|
+
const rewrite = (userId, to) => {
|
|
12
|
+
if (!existsSync(file))
|
|
13
|
+
return 0;
|
|
14
|
+
const map = JSON.parse(readFileSync(file, 'utf8'));
|
|
15
|
+
const theirs = Object.keys(map).filter((old) => map[old] === userId);
|
|
16
|
+
if (theirs.length === 0)
|
|
17
|
+
return 0;
|
|
18
|
+
for (const old of theirs) {
|
|
19
|
+
if (to === undefined)
|
|
20
|
+
delete map[old];
|
|
21
|
+
else
|
|
22
|
+
map[old] = to;
|
|
23
|
+
}
|
|
24
|
+
writeFileSync(`${file}.tmp`, JSON.stringify(map));
|
|
25
|
+
renameSync(`${file}.tmp`, file);
|
|
26
|
+
return theirs.length;
|
|
27
|
+
};
|
|
8
28
|
return {
|
|
9
29
|
what: 'legacyIds',
|
|
10
|
-
erase: ({ userId }) =>
|
|
11
|
-
|
|
12
|
-
return 0;
|
|
13
|
-
const map = JSON.parse(readFileSync(file, 'utf8'));
|
|
14
|
-
const theirs = Object.keys(map).filter((old) => map[old] === userId);
|
|
15
|
-
if (theirs.length === 0)
|
|
16
|
-
return 0;
|
|
17
|
-
for (const old of theirs)
|
|
18
|
-
delete map[old];
|
|
19
|
-
writeFileSync(`${file}.tmp`, JSON.stringify(map));
|
|
20
|
-
renameSync(`${file}.tmp`, file);
|
|
21
|
-
return theirs.length;
|
|
22
|
-
},
|
|
30
|
+
erase: ({ userId }) => rewrite(userId, undefined),
|
|
31
|
+
merge: ({ from, into }) => rewrite(from.userId, into.userId),
|
|
23
32
|
};
|
|
24
33
|
}
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
* A recording from before seats kept their userId names nobody this can match, and is left to
|
|
14
14
|
* its retention, as the ruling says.
|
|
15
15
|
*
|
|
16
|
+
* An account merge moves the seat to the kept account instead (`recordingsStep`'s `merge`).
|
|
17
|
+
*
|
|
16
18
|
* ## Off the event loop
|
|
17
19
|
*
|
|
18
20
|
* Every erase used to gunzip and parse every line of every recording, synchronously: 181–197 ms of
|
package/dist/erase/recordings.js
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
* A recording from before seats kept their userId names nobody this can match, and is left to
|
|
14
14
|
* its retention, as the ruling says.
|
|
15
15
|
*
|
|
16
|
+
* An account merge moves the seat to the kept account instead (`recordingsStep`'s `merge`).
|
|
17
|
+
*
|
|
16
18
|
* ## Off the event loop
|
|
17
19
|
*
|
|
18
20
|
* Every erase used to gunzip and parse every line of every recording, synchronously: 181–197 ms of
|
|
@@ -28,7 +30,7 @@ import { promisify } from 'node:util';
|
|
|
28
30
|
import { gunzip as gunzipCb, gzip as gzipCb } from 'node:zlib';
|
|
29
31
|
import { UNNAMED } from '../room/constants.js';
|
|
30
32
|
import { ACTIONS_SUFFIX, PUBLIC_SUFFIX } from '../play/recording/retention.js';
|
|
31
|
-
import { replaceIds } from './anonymise.js';
|
|
33
|
+
import { renameIds, replaceIds } from './anonymise.js';
|
|
32
34
|
const gunzip = promisify(gunzipCb);
|
|
33
35
|
const gzip = promisify(gzipCb);
|
|
34
36
|
/** A recording file's text, read and unzipped off the event loop. */
|
|
@@ -79,50 +81,81 @@ function seatNames(header, seats) {
|
|
|
79
81
|
const spec = header?.spec;
|
|
80
82
|
return seats.flatMap((seat) => [players[seat], spec?.seats?.[seat]?.name].filter((n) => typeof n === 'string' && n !== '' && n !== UNNAMED));
|
|
81
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Visit every recording whose text holds `userId`, parsed; `change` edits it in place and answers
|
|
86
|
+
* whether it did, and a changed recording is written back. Answers how many changed.
|
|
87
|
+
*/
|
|
88
|
+
async function rewriteRecordings(dir, userId, change) {
|
|
89
|
+
let files;
|
|
90
|
+
try {
|
|
91
|
+
files = await readdir(dir);
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
if (err.code === 'ENOENT')
|
|
95
|
+
return 0;
|
|
96
|
+
throw err;
|
|
97
|
+
}
|
|
98
|
+
const matchIds = new Set(files.flatMap((f) => (f.endsWith(PUBLIC_SUFFIX) ? [f.slice(0, -PUBLIC_SUFFIX.length)] : f.endsWith(ACTIONS_SUFFIX) ? [f.slice(0, -ACTIONS_SUFFIX.length)] : [])));
|
|
99
|
+
let changed = 0;
|
|
100
|
+
for (const matchId of matchIds) {
|
|
101
|
+
const texts = [];
|
|
102
|
+
for (const suffix of [PUBLIC_SUFFIX, ACTIONS_SUFFIX]) {
|
|
103
|
+
if (!files.includes(matchId + suffix))
|
|
104
|
+
continue;
|
|
105
|
+
const path = join(dir, matchId + suffix);
|
|
106
|
+
const text = await readText(path).catch((err) => {
|
|
107
|
+
// Retention may age a file out between the listing and this read: it names no one now.
|
|
108
|
+
if (err.code === 'ENOENT')
|
|
109
|
+
return null;
|
|
110
|
+
throw err;
|
|
111
|
+
});
|
|
112
|
+
if (text !== null)
|
|
113
|
+
texts.push({ path, text });
|
|
114
|
+
}
|
|
115
|
+
if (!texts.some(({ text }) => text.includes(userId)))
|
|
116
|
+
continue;
|
|
117
|
+
const recording = texts.map(({ path, text }) => ({ path, lines: parseLines(text) }));
|
|
118
|
+
if (!change(recording))
|
|
119
|
+
continue;
|
|
120
|
+
for (const { path, lines } of recording)
|
|
121
|
+
await writeLines(path, lines);
|
|
122
|
+
changed++;
|
|
123
|
+
}
|
|
124
|
+
return changed;
|
|
125
|
+
}
|
|
126
|
+
/** Every end line in a recording: the last of each file. */
|
|
127
|
+
const endsOf = (recording) => recording.flatMap(({ lines }) => {
|
|
128
|
+
const end = lines.findLast((l) => l.t === 'end');
|
|
129
|
+
return end === undefined ? [] : [end];
|
|
130
|
+
});
|
|
131
|
+
/** Does an end line name `userId` in a seat? */
|
|
132
|
+
function endNames(end, userId) {
|
|
133
|
+
return (Array.isArray(end.seats) && end.seats.some((s) => s.userId === userId)) || (Array.isArray(end.users) && end.users.includes(userId));
|
|
134
|
+
}
|
|
82
135
|
export function recordingsStep(dir) {
|
|
83
136
|
return {
|
|
84
137
|
what: 'recordings',
|
|
85
|
-
erase:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
throw err;
|
|
108
|
-
});
|
|
109
|
-
if (text !== null)
|
|
110
|
-
texts.push({ path, text });
|
|
111
|
-
}
|
|
112
|
-
if (!texts.some(({ text }) => text.includes(userId)))
|
|
113
|
-
continue;
|
|
114
|
-
const recording = texts.map(({ path, text }) => ({ path, lines: parseLines(text) }));
|
|
115
|
-
const seats = recording.flatMap(({ lines }) => dropUser(lines.findLast((l) => l.t === 'end'), userId));
|
|
116
|
-
if (seats.length === 0)
|
|
117
|
-
continue;
|
|
118
|
-
const names = new Set(recording.flatMap(({ lines }) => seatNames(lines.find((l) => l.t === 'header'), seats)));
|
|
119
|
-
for (const { path, lines } of recording) {
|
|
120
|
-
replaceIds(lines, names, UNNAMED);
|
|
121
|
-
await writeLines(path, lines);
|
|
122
|
-
}
|
|
123
|
-
changed++;
|
|
124
|
-
}
|
|
125
|
-
return changed;
|
|
126
|
-
},
|
|
138
|
+
erase: ({ userId }) => rewriteRecordings(dir, userId, (recording) => {
|
|
139
|
+
const seats = recording.flatMap(({ lines }) => dropUser(lines.findLast((l) => l.t === 'end'), userId));
|
|
140
|
+
if (seats.length === 0)
|
|
141
|
+
return false;
|
|
142
|
+
const names = new Set(recording.flatMap(({ lines }) => seatNames(lines.find((l) => l.t === 'header'), seats)));
|
|
143
|
+
for (const { lines } of recording)
|
|
144
|
+
replaceIds(lines, names, UNNAMED);
|
|
145
|
+
return true;
|
|
146
|
+
}),
|
|
147
|
+
/**
|
|
148
|
+
* The merged-away account's seats become the kept account's, so its replays draw the kept
|
|
149
|
+
* account. The names stay as they were played. A match between the two accounts (an end line
|
|
150
|
+
* naming both) is a conflict the kept account wins: it is left, and the erase sweep plays the
|
|
151
|
+
* merged-away seat as unnamed, as for anyone erased.
|
|
152
|
+
*/
|
|
153
|
+
merge: ({ from, into }) => rewriteRecordings(dir, from.userId, (recording) => {
|
|
154
|
+
const ends = endsOf(recording);
|
|
155
|
+
if (ends.some((end) => endNames(end, into.userId)))
|
|
156
|
+
return false;
|
|
157
|
+
const only = new Map([[from.userId, into.userId]]);
|
|
158
|
+
return ends.reduce((n, end) => n + renameIds([end.seats, end.users], only), 0) > 0;
|
|
159
|
+
}),
|
|
127
160
|
};
|
|
128
161
|
}
|
package/dist/erase/rooms.d.ts
CHANGED
|
@@ -10,9 +10,24 @@
|
|
|
10
10
|
* placeholder instead (`Lobby.anonymise`).
|
|
11
11
|
*
|
|
12
12
|
* The steps run in that order, so a room is never anonymised while they still sit in it.
|
|
13
|
+
*
|
|
14
|
+
* ## Account merge
|
|
15
|
+
*
|
|
16
|
+
* - A live match the merged-away account holds a seat in ends as that seat's forfeit, as an erase
|
|
17
|
+
* ends it. A live game binds its seats to the participant id inside the match (its sockets, the
|
|
18
|
+
* seat owners its recovery record keeps), and nothing carries a seat to another identity
|
|
19
|
+
* mid-game; leaving it running would only have the erase sweep that follows the merge forfeit it
|
|
20
|
+
* a moment later, after the room had already been moved to the kept account under it. A person
|
|
21
|
+
* merges by signing in to their real account, so their guest's game is one they just left.
|
|
22
|
+
* - Every other room names the kept account instead (`Lobby.merge`): its seat, its series, its
|
|
23
|
+
* lead, the room itself when they were alone in it. Nothing is closed and nobody leaves.
|
|
24
|
+
* - A room that already names the kept account (both accounts sat in it) is the kept account's:
|
|
25
|
+
* the merge leaves it, and the erase sweep closes, leaves and anonymises the merged-away
|
|
26
|
+
* account's place in it exactly as above.
|
|
13
27
|
*/
|
|
14
28
|
import type { ParticipantId } from '@wolffm/rooms-protocol';
|
|
15
29
|
import type { EraseStep } from './index.js';
|
|
30
|
+
import type { IdMove } from './anonymise.js';
|
|
16
31
|
export interface LiveMatch {
|
|
17
32
|
seatOf(participantId: ParticipantId): number | null;
|
|
18
33
|
}
|
|
@@ -45,6 +60,8 @@ interface RoomsLobby {
|
|
|
45
60
|
leave(roomId: string, memberId: string): RoomsLeaveResult;
|
|
46
61
|
close(roomId: string, callerId: string): RoomsCloseResult;
|
|
47
62
|
anonymise(ids: ReadonlySet<string>, to: string): number;
|
|
63
|
+
/** Account merge: every room naming the merged-away account, and not the kept one, names the kept one. */
|
|
64
|
+
merge(move: IdMove): number;
|
|
48
65
|
removed(): Promise<void>;
|
|
49
66
|
}
|
|
50
67
|
export interface RoomsEraseDeps<M extends LiveMatch> {
|
package/dist/erase/rooms.js
CHANGED
|
@@ -10,22 +10,38 @@
|
|
|
10
10
|
* placeholder instead (`Lobby.anonymise`).
|
|
11
11
|
*
|
|
12
12
|
* The steps run in that order, so a room is never anonymised while they still sit in it.
|
|
13
|
+
*
|
|
14
|
+
* ## Account merge
|
|
15
|
+
*
|
|
16
|
+
* - A live match the merged-away account holds a seat in ends as that seat's forfeit, as an erase
|
|
17
|
+
* ends it. A live game binds its seats to the participant id inside the match (its sockets, the
|
|
18
|
+
* seat owners its recovery record keeps), and nothing carries a seat to another identity
|
|
19
|
+
* mid-game; leaving it running would only have the erase sweep that follows the merge forfeit it
|
|
20
|
+
* a moment later, after the room had already been moved to the kept account under it. A person
|
|
21
|
+
* merges by signing in to their real account, so their guest's game is one they just left.
|
|
22
|
+
* - Every other room names the kept account instead (`Lobby.merge`): its seat, its series, its
|
|
23
|
+
* lead, the room itself when they were alone in it. Nothing is closed and nobody leaves.
|
|
24
|
+
* - A room that already names the kept account (both accounts sat in it) is the kept account's:
|
|
25
|
+
* the merge leaves it, and the erase sweep closes, leaves and anonymises the merged-away
|
|
26
|
+
* account's place in it exactly as above.
|
|
13
27
|
*/
|
|
14
28
|
/** The steps, in the order the module header gives. */
|
|
15
29
|
export function roomsEraseSteps(deps) {
|
|
30
|
+
const forfeitAll = (participantId) => {
|
|
31
|
+
let n = 0;
|
|
32
|
+
for (const match of deps.liveMatches()) {
|
|
33
|
+
if (match.seatOf(participantId) === null)
|
|
34
|
+
continue;
|
|
35
|
+
deps.forfeit(match, participantId);
|
|
36
|
+
n++;
|
|
37
|
+
}
|
|
38
|
+
return n;
|
|
39
|
+
};
|
|
16
40
|
return [
|
|
17
41
|
{
|
|
18
42
|
what: 'matchesForfeited',
|
|
19
|
-
erase: ({ participantId }) =>
|
|
20
|
-
|
|
21
|
-
for (const match of deps.liveMatches()) {
|
|
22
|
-
if (match.seatOf(participantId) === null)
|
|
23
|
-
continue;
|
|
24
|
-
deps.forfeit(match, participantId);
|
|
25
|
-
n++;
|
|
26
|
-
}
|
|
27
|
-
return n;
|
|
28
|
-
},
|
|
43
|
+
erase: ({ participantId }) => forfeitAll(participantId),
|
|
44
|
+
merge: ({ from }) => forfeitAll(from.participantId),
|
|
29
45
|
},
|
|
30
46
|
{
|
|
31
47
|
what: 'roomsClosed',
|
|
@@ -44,6 +60,8 @@ export function roomsEraseSteps(deps) {
|
|
|
44
60
|
await deps.lobby.removed();
|
|
45
61
|
return n;
|
|
46
62
|
},
|
|
63
|
+
// A merge closes nothing: a room they were alone in moves to the kept account whole (`roomsMoved`).
|
|
64
|
+
merge: () => ({}),
|
|
47
65
|
},
|
|
48
66
|
{
|
|
49
67
|
what: 'roomsLeft',
|
|
@@ -61,7 +79,14 @@ export function roomsEraseSteps(deps) {
|
|
|
61
79
|
}
|
|
62
80
|
return n;
|
|
63
81
|
},
|
|
82
|
+
// A merge leaves nothing: their place moves to the kept account (`roomsMoved`), and a room the
|
|
83
|
+
// kept account is already in is left to the erase sweep, which leaves it for them.
|
|
84
|
+
merge: () => ({}),
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
what: 'roomsAnonymised',
|
|
88
|
+
erase: ({ ids, placeholder }) => deps.lobby.anonymise(ids, placeholder),
|
|
89
|
+
merge: (accounts) => ({ roomsMoved: deps.lobby.merge(accounts) }),
|
|
64
90
|
},
|
|
65
|
-
{ what: 'roomsAnonymised', erase: ({ ids, placeholder }) => deps.lobby.anonymise(ids, placeholder) },
|
|
66
91
|
];
|
|
67
92
|
}
|
package/dist/room/events.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { type IdMove } from '../erase/anonymise.js';
|
|
2
3
|
declare const EventRecordSchema: z.ZodObject<{
|
|
3
4
|
id: z.ZodString;
|
|
4
5
|
roomId: z.ZodString;
|
|
@@ -63,6 +64,15 @@ export interface Events {
|
|
|
63
64
|
events: number;
|
|
64
65
|
forms: number;
|
|
65
66
|
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Account merge: an event they organised and a form they attached are the kept account's
|
|
69
|
+
* (`moveIds`), under the name they gave; one that already names the kept account is left to the
|
|
70
|
+
* erase sweep. Answers how many changed, once saved.
|
|
71
|
+
*/
|
|
72
|
+
merge(move: IdMove): Promise<{
|
|
73
|
+
events: number;
|
|
74
|
+
forms: number;
|
|
75
|
+
}>;
|
|
66
76
|
}
|
|
67
77
|
export declare function openEvents(file: string, log: (entry: Record<string, unknown>) => void, now?: () => number): Promise<Events>;
|
|
68
78
|
export {};
|
package/dist/room/events.js
CHANGED
|
@@ -11,7 +11,7 @@ import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
|
11
11
|
import { dirname } from 'node:path';
|
|
12
12
|
import { randomBytes } from 'node:crypto';
|
|
13
13
|
import { z } from 'zod';
|
|
14
|
-
import { replaceIds } from '../erase/anonymise.js';
|
|
14
|
+
import { moveIds, replaceIds } from '../erase/anonymise.js';
|
|
15
15
|
const EventRecordSchema = z.object({
|
|
16
16
|
id: z.string(),
|
|
17
17
|
roomId: z.string(),
|
|
@@ -199,5 +199,12 @@ export async function openEvents(file, log, now = Date.now) {
|
|
|
199
199
|
throw new Error('events: the anonymised store was not saved');
|
|
200
200
|
return { events: changedEvents, forms: changedForms };
|
|
201
201
|
},
|
|
202
|
+
async merge(move) {
|
|
203
|
+
const movedEvents = events.filter((e) => moveIds(e, move) > 0).length;
|
|
204
|
+
const movedForms = forms.filter((f) => moveIds(f, move) > 0).length;
|
|
205
|
+
if (movedEvents + movedForms > 0 && !(await save()))
|
|
206
|
+
throw new Error('events: the merged store was not saved');
|
|
207
|
+
return { events: movedEvents, forms: movedForms };
|
|
208
|
+
},
|
|
202
209
|
};
|
|
203
210
|
}
|
package/dist/room/lobby.d.ts
CHANGED
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
*/
|
|
35
35
|
import { FileRoomStore, type RoomCodec } from '@wolffm/rooms-server/store';
|
|
36
36
|
import { type Look } from '@wolffm/platform-wire/look';
|
|
37
|
+
import { type IdMove } from '../erase/anonymise.js';
|
|
37
38
|
import { type AiPersona } from './ai-faces.js';
|
|
38
39
|
import type { Caller } from './caller.js';
|
|
39
40
|
import { type Secret } from './provisioning.js';
|
|
@@ -541,6 +542,15 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
|
|
|
541
542
|
* how many rooms changed. The person leaves first (`leave`), so leadership has passed on.
|
|
542
543
|
*/
|
|
543
544
|
anonymise(ids: ReadonlySet<string>, to: string): number;
|
|
545
|
+
/**
|
|
546
|
+
* Account merge: every room that names the merged-away account names the kept one instead, by
|
|
547
|
+
* `moveIds` — so a room that already names the kept account is a conflict it wins, left for the
|
|
548
|
+
* erase sweep that follows (`erase/rooms.ts` has the person leave it first). Each room changed is
|
|
549
|
+
* saved. Answers how many changed.
|
|
550
|
+
*/
|
|
551
|
+
merge(move: IdMove): number;
|
|
552
|
+
/** Does the room's record name any of `ids` anywhere (a member, a seat, a result)? False for no such room. */
|
|
553
|
+
names(roomId: string, ids: ReadonlySet<string>): boolean;
|
|
544
554
|
/** Move the start of the event a room was made for, and its seats' opening with it. False when there is no such room. */
|
|
545
555
|
reschedule(roomId: string, at: number): boolean;
|
|
546
556
|
/**
|
package/dist/room/lobby.js
CHANGED
|
@@ -38,7 +38,7 @@ import { addMember, createMembershipLedger, setReady as ledgerSetReady } from '@
|
|
|
38
38
|
import { seatsOpenAt } from '@wolffm/platform-wire/events';
|
|
39
39
|
import { sameLook } from '@wolffm/platform-wire/look';
|
|
40
40
|
import { ROOM_ID_RE } from '@wolffm/platform-wire/room-feed';
|
|
41
|
-
import { replaceIds } from "../erase/anonymise.js";
|
|
41
|
+
import { moveIds, namesAny, replaceIds } from "../erase/anonymise.js";
|
|
42
42
|
import { seatPersonas } from "./ai-faces.js";
|
|
43
43
|
import { avatarIdOf } from "./avatar.js";
|
|
44
44
|
import { ROOM_STALE_MS, UNNAMED } from "./constants.js";
|
|
@@ -955,6 +955,27 @@ export class RoomLobby {
|
|
|
955
955
|
}
|
|
956
956
|
return changed;
|
|
957
957
|
}
|
|
958
|
+
/**
|
|
959
|
+
* Account merge: every room that names the merged-away account names the kept one instead, by
|
|
960
|
+
* `moveIds` — so a room that already names the kept account is a conflict it wins, left for the
|
|
961
|
+
* erase sweep that follows (`erase/rooms.ts` has the person leave it first). Each room changed is
|
|
962
|
+
* saved. Answers how many changed.
|
|
963
|
+
*/
|
|
964
|
+
merge(move) {
|
|
965
|
+
let changed = 0;
|
|
966
|
+
for (const room of this.#rooms.values()) {
|
|
967
|
+
if (moveIds(room, move) === 0)
|
|
968
|
+
continue;
|
|
969
|
+
changed++;
|
|
970
|
+
this.persist(room);
|
|
971
|
+
}
|
|
972
|
+
return changed;
|
|
973
|
+
}
|
|
974
|
+
/** Does the room's record name any of `ids` anywhere (a member, a seat, a result)? False for no such room. */
|
|
975
|
+
names(roomId, ids) {
|
|
976
|
+
const room = this.#rooms.get(roomId);
|
|
977
|
+
return room !== undefined && namesAny(room, ids);
|
|
978
|
+
}
|
|
958
979
|
/** Move the start of the event a room was made for, and its seats' opening with it. False when there is no such room. */
|
|
959
980
|
reschedule(roomId, at) {
|
|
960
981
|
const room = this.#rooms.get(roomId);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/game-server",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.104",
|
|
4
|
+
"gitHead": "23d61b02b042b181d594268a3e6d1f0f39c7d12a",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "The server parts any hosted game shares, above the kernel: the app config and edge auth, the room core (identity, seats, sessions, membership, the room list, the generic room routes), match hosting (the host contract, local and remote JVMs, placement, the start queue, recordings, the in-process and relay runtimes), streams, erase, telemetry and usage. Knows no game; Magic plugs in from apps/server. MIT; imports only node built-ins, express, socket.io, @wolffm/* and the platform packages.",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"play/remote/"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.
|
|
20
|
-
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.
|
|
21
|
-
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.
|
|
19
|
+
"@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.104",
|
|
20
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.104",
|
|
21
|
+
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.137",
|
|
22
22
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.31",
|
|
23
23
|
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.129",
|
|
24
24
|
"@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.129",
|