@hadoku/game-server 0.1.174 → 0.1.176
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/play/host.d.ts +2 -1
- package/dist/play/host.js +120 -25
- package/dist/room/lobby.d.ts +8 -5
- package/dist/room/lobby.js +16 -10
- package/dist/room/membership.d.ts +17 -14
- package/dist/room/membership.js +22 -17
- package/dist/room/record.d.ts +5 -1
- package/package.json +5 -5
package/dist/play/host.d.ts
CHANGED
|
@@ -450,13 +450,14 @@ export type JvmHostFactory<L extends {
|
|
|
450
450
|
attach(record: MatchRecord, events: HostEvents<L, C>): MatchHost<C>;
|
|
451
451
|
handOverAll(): string[];
|
|
452
452
|
reapOnExit(): ReapResult;
|
|
453
|
-
/** JVMs this pool holds, with their matches: for diagnostics and tests. */
|
|
453
|
+
/** JVMs this pool holds, with their matches and the restores waiting in them for an old copy to stop: for placement, diagnostics and tests. */
|
|
454
454
|
jvms(): {
|
|
455
455
|
hostId: string;
|
|
456
456
|
warm: boolean;
|
|
457
457
|
draining: boolean;
|
|
458
458
|
adopted: boolean;
|
|
459
459
|
matches: string[];
|
|
460
|
+
waiting: string[];
|
|
460
461
|
}[];
|
|
461
462
|
/** Place nothing more into this JVM, and retire it once its matches end (a heap past `recycleWanted`). */
|
|
462
463
|
drain(hostId: string, why: string): void;
|
package/dist/play/host.js
CHANGED
|
@@ -256,7 +256,9 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
256
256
|
listener();
|
|
257
257
|
};
|
|
258
258
|
const liveJvms = () => [...jvms].filter((j) => !j.exited && !j.retiring && !j.released);
|
|
259
|
-
|
|
259
|
+
/** The matches a JVM holds, counting the restores waiting in it for their old copy to stop. */
|
|
260
|
+
const load = (jvm) => jvm.matches.size + jvm.waiting.size;
|
|
261
|
+
const hasRoom = (jvm) => load(jvm) < perJvm && !jvm.draining;
|
|
260
262
|
/* ── The record and the streams ── */
|
|
261
263
|
function writeRecord(jvm) {
|
|
262
264
|
if (jvm.released || jvm.exited)
|
|
@@ -384,6 +386,7 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
384
386
|
adopted: from.adopted ?? false,
|
|
385
387
|
released: false,
|
|
386
388
|
matches: new Map(),
|
|
389
|
+
waiting: new Map(),
|
|
387
390
|
lastHeard: Date.now(),
|
|
388
391
|
lastCheck: Date.now(),
|
|
389
392
|
livenessArmed: !from.warm,
|
|
@@ -531,10 +534,19 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
531
534
|
if (h.stopTimer !== null)
|
|
532
535
|
clearTimeout(h.stopTimer);
|
|
533
536
|
closeStream(h);
|
|
534
|
-
pending.
|
|
537
|
+
if (pending.get(h.id) === h)
|
|
538
|
+
pending.delete(h.id);
|
|
535
539
|
const jvm = h.jvm;
|
|
536
|
-
|
|
537
|
-
|
|
540
|
+
// By identity: a restore of this id may be waiting beside it (`held`), or be it.
|
|
541
|
+
if (jvm.matches.get(h.id) === h)
|
|
542
|
+
jvm.matches.delete(h.id);
|
|
543
|
+
if (jvm.waiting.get(h.id) === h)
|
|
544
|
+
jvm.waiting.delete(h.id);
|
|
545
|
+
const next = h.held === null ? jvm.waiting.get(h.id) : undefined;
|
|
546
|
+
if (next !== undefined)
|
|
547
|
+
startHeld(next);
|
|
548
|
+
else
|
|
549
|
+
writeRecord(jvm);
|
|
538
550
|
if (h.events !== null && !h.handed) {
|
|
539
551
|
h.events.exit(h.stopping
|
|
540
552
|
? 'stopped'
|
|
@@ -544,7 +556,7 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
544
556
|
? PLAYED_OUT
|
|
545
557
|
: 'Forge ended the match without being asked to');
|
|
546
558
|
}
|
|
547
|
-
if (jvm
|
|
559
|
+
if (load(jvm) === 0)
|
|
548
560
|
idle(jvm);
|
|
549
561
|
notifyRoom();
|
|
550
562
|
replenish();
|
|
@@ -559,17 +571,19 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
559
571
|
if (jvm.idle !== null)
|
|
560
572
|
clearTimeout(jvm.idle);
|
|
561
573
|
const why = jvm.unresponsive ?? reason;
|
|
562
|
-
const lost = [...jvm.matches.values()].filter((h) => !h.ended);
|
|
574
|
+
const lost = [...jvm.matches.values(), ...jvm.waiting.values()].filter((h) => !h.ended);
|
|
563
575
|
for (const h of lost) {
|
|
564
576
|
h.ended = true;
|
|
565
577
|
if (h.stopTimer !== null)
|
|
566
578
|
clearTimeout(h.stopTimer);
|
|
567
579
|
closeStream(h);
|
|
568
|
-
pending.
|
|
580
|
+
if (pending.get(h.id) === h)
|
|
581
|
+
pending.delete(h.id);
|
|
569
582
|
if (!reaping && h.events !== null && !h.handed)
|
|
570
583
|
h.events.exit(h.stopping ? 'stopped' : why);
|
|
571
584
|
}
|
|
572
585
|
jvm.matches.clear();
|
|
586
|
+
jvm.waiting.clear();
|
|
573
587
|
if (reaping)
|
|
574
588
|
return;
|
|
575
589
|
if (lost.some((h) => !h.stopping)) {
|
|
@@ -606,7 +620,7 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
606
620
|
}
|
|
607
621
|
/** The JVM has no matches: retire it now, or after `idleMs` unless it is the warm one then. */
|
|
608
622
|
function idle(jvm) {
|
|
609
|
-
if (jvm
|
|
623
|
+
if (load(jvm) > 0 || jvm.exited || jvm.retiring || jvm.released)
|
|
610
624
|
return;
|
|
611
625
|
if (closed || !warmWanted || jvm.draining) {
|
|
612
626
|
retire(jvm, closed ? 'closing' : jvm.draining ? 'drained' : 'no match left, and no JVM is kept warm');
|
|
@@ -616,7 +630,7 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
616
630
|
clearTimeout(jvm.idle);
|
|
617
631
|
jvm.idle = setTimeout(() => {
|
|
618
632
|
jvm.idle = null;
|
|
619
|
-
if (jvm
|
|
633
|
+
if (load(jvm) > 0)
|
|
620
634
|
return;
|
|
621
635
|
if (liveJvms().some((other) => other !== jvm && hasRoom(other)))
|
|
622
636
|
retire(jvm, `no match for ${idleMs} ms`);
|
|
@@ -662,10 +676,38 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
662
676
|
}
|
|
663
677
|
}
|
|
664
678
|
/* ── Matches ── */
|
|
679
|
+
/** Send a match's `start` to its JVM: at once, or (`held`) once the old copy of its id there has stopped. */
|
|
680
|
+
function sendStart(h) {
|
|
681
|
+
h.jvm.transport.send(JSON.stringify({ t: 'start', config: bridgeConfig(h.id, h.entry.spec, config.aiFlatMc ?? 'off'), match: h.jvm.hostId }));
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* The old copy of a restored match has stopped in its JVM: the restore takes its place there, its
|
|
685
|
+
* `start` first and then every command it was sent meanwhile, in order. The bridge has let go of the
|
|
686
|
+
* id by then (`PlayBridge.startHosted` removes it before it says `stopped`).
|
|
687
|
+
*/
|
|
688
|
+
function startHeld(h) {
|
|
689
|
+
const held = h.held ?? [];
|
|
690
|
+
const jvm = h.jvm;
|
|
691
|
+
h.held = null;
|
|
692
|
+
jvm.waiting.delete(h.id);
|
|
693
|
+
jvm.matches.set(h.id, h);
|
|
694
|
+
writeRecord(jvm);
|
|
695
|
+
(h.events?.log ?? poolLog)({ evt: 'match-start-released', matchId: h.id, hostId: jvm.hostId, waitedMs: Date.now() - Date.parse(h.entry.startedAt), commands: held.length });
|
|
696
|
+
sendStart(h);
|
|
697
|
+
for (const command of held) {
|
|
698
|
+
persist(h, JSON.stringify({ c: command }));
|
|
699
|
+
jvm.transport.send(JSON.stringify({ ...command, match: h.id }));
|
|
700
|
+
}
|
|
701
|
+
}
|
|
665
702
|
function stopMatch(h) {
|
|
666
703
|
if (h.stopping || h.ended)
|
|
667
704
|
return;
|
|
668
705
|
h.stopping = true;
|
|
706
|
+
// Never started: a `stop` of its id would reach the old copy it waits behind, which is already stopping.
|
|
707
|
+
if (h.held !== null) {
|
|
708
|
+
matchEnded(h);
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
669
711
|
// Out of the record now, not at its `stopped`: a JVM killed before that (remote, unconfirmed)
|
|
670
712
|
// would otherwise offer the match to the next server.
|
|
671
713
|
writeRecord(h.jvm);
|
|
@@ -685,6 +727,10 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
685
727
|
}
|
|
686
728
|
if (h.ended || h.jvm.exited)
|
|
687
729
|
return;
|
|
730
|
+
if (h.held !== null) {
|
|
731
|
+
h.held.push(command);
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
688
734
|
// Kept in the same stream, in the same order, as the lines that came back: a replay
|
|
689
735
|
// has to know which asks the old server had already answered.
|
|
690
736
|
persist(h, JSON.stringify({ c: command }));
|
|
@@ -716,7 +762,8 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
716
762
|
});
|
|
717
763
|
return false;
|
|
718
764
|
}
|
|
719
|
-
|
|
765
|
+
// Not started yet: Forge has no game of it for a later server to take back.
|
|
766
|
+
if (h.ended || h.stopping || h.held !== null || h.jvm.exited || h.jvm.released || h.events === null)
|
|
720
767
|
return false;
|
|
721
768
|
// A bot game is not kept: nobody can watch it, and the room plays it again (`play/botgames.ts`).
|
|
722
769
|
if (h.entry.spec.headless !== undefined)
|
|
@@ -726,26 +773,59 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
726
773
|
},
|
|
727
774
|
};
|
|
728
775
|
}
|
|
729
|
-
/** Where a new match goes: the fullest warm JVM with room, else one booting, else none. */
|
|
730
776
|
/**
|
|
731
|
-
*
|
|
732
|
-
* keeps its id (`MatchRegistry.restore`), and
|
|
733
|
-
*
|
|
777
|
+
* Where a new match goes: the fullest warm JVM with room, else one booting, else none. Never one
|
|
778
|
+
* still holding a match of `matchId`: a restored match keeps its id (`MatchRegistry.restore`), and
|
|
779
|
+
* a JVM routes its lines by id, so the new game must not run beside the old one there.
|
|
734
780
|
*/
|
|
735
781
|
function placeFor(matchId) {
|
|
736
|
-
const open = liveJvms().filter((j) => hasRoom(j) && (matchId === undefined || !j.matches.has(matchId)));
|
|
737
|
-
const warm = open.filter((j) => j.warm).sort((a, b) => b
|
|
782
|
+
const open = liveJvms().filter((j) => hasRoom(j) && (matchId === undefined || (!j.matches.has(matchId) && !j.waiting.has(matchId))));
|
|
783
|
+
const warm = open.filter((j) => j.warm).sort((a, b) => load(b) - load(a));
|
|
738
784
|
return warm[0] ?? open[0] ?? null;
|
|
739
785
|
}
|
|
740
786
|
/**
|
|
741
|
-
*
|
|
742
|
-
*
|
|
787
|
+
* The JVM where `matchId`'s old copy is being stopped, when the restore can take its place there
|
|
788
|
+
* once it goes: a claw runs one JVM, so without this a Restart turn found no room (2026-11-29).
|
|
789
|
+
*/
|
|
790
|
+
function behindOldCopy(matchId) {
|
|
791
|
+
return (liveJvms().find((j) => {
|
|
792
|
+
const old = j.matches.get(matchId);
|
|
793
|
+
return old !== undefined && old.stopping && !old.ended && !j.draining && !j.waiting.has(matchId) && load(j) <= perJvm;
|
|
794
|
+
}) ?? null);
|
|
795
|
+
}
|
|
796
|
+
/** Why no JVM of this pool takes `matchId`, JVM by JVM: "full" only when every one is. */
|
|
797
|
+
function noRoom(matchId) {
|
|
798
|
+
const why = (j) => {
|
|
799
|
+
if (j.retiring)
|
|
800
|
+
return 'is retiring';
|
|
801
|
+
if (j.draining)
|
|
802
|
+
return 'is draining';
|
|
803
|
+
const old = j.matches.get(matchId);
|
|
804
|
+
if (old !== undefined && !old.stopping)
|
|
805
|
+
return 'still runs its old copy, which was not asked to stop';
|
|
806
|
+
if (j.waiting.has(matchId))
|
|
807
|
+
return 'already holds a restore of it, waiting for its old copy to stop';
|
|
808
|
+
return load(j) >= perJvm ? `is full (${load(j)} of ${perJvm})` : 'has room';
|
|
809
|
+
};
|
|
810
|
+
const all = [...jvms];
|
|
811
|
+
if (all.every((j) => why(j).startsWith('is full')))
|
|
812
|
+
return `every Forge JVM is full (${jvms.size} of ${maxJvms()}, ${perJvm} matches each)`;
|
|
813
|
+
return `no Forge JVM here can take ${matchId}: ${all.map((j) => `${j.hostId} ${why(j)}`).join('; ')}; ${jvms.size} of ${maxJvms()} JVMs running`;
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Throws when the match cannot be given a JVM (none can take it at `maxJvms`, or a launch that
|
|
817
|
+
* throws), and leaves nothing behind. The caller fails the match (`Match.start`). A restore whose
|
|
818
|
+
* old copy is being stopped in a JVM waits there for it (`held`) rather than in a JVM still booting
|
|
819
|
+
* or a launch: a match's stop takes far less than a boot.
|
|
743
820
|
*/
|
|
744
821
|
const factory = ((matchId, spec, events) => {
|
|
745
|
-
|
|
822
|
+
const open = placeFor(matchId);
|
|
823
|
+
const after = open?.warm === true ? null : behindOldCopy(matchId);
|
|
824
|
+
const behind = after !== null;
|
|
825
|
+
let jvm = after ?? open;
|
|
746
826
|
if (jvm === null) {
|
|
747
827
|
if (jvms.size >= maxJvms())
|
|
748
|
-
throw new Error(
|
|
828
|
+
throw new Error(noRoom(matchId));
|
|
749
829
|
jvm = launch();
|
|
750
830
|
}
|
|
751
831
|
if (jvm.idle !== null)
|
|
@@ -764,11 +844,25 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
764
844
|
fatal: null,
|
|
765
845
|
stopTimer: null,
|
|
766
846
|
stream: null,
|
|
847
|
+
held: behind ? [] : null,
|
|
767
848
|
};
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
849
|
+
events.log({
|
|
850
|
+
evt: 'match-placed',
|
|
851
|
+
matchId,
|
|
852
|
+
hostId: jvm.hostId,
|
|
853
|
+
warm: jvm.warm,
|
|
854
|
+
matches: load(jvm) + 1,
|
|
855
|
+
aiFlatMc: config.aiFlatMc ?? 'off',
|
|
856
|
+
...(behind ? { behind: 'its old copy, being stopped' } : {}),
|
|
857
|
+
});
|
|
858
|
+
if (behind) {
|
|
859
|
+
jvm.waiting.set(matchId, h);
|
|
860
|
+
}
|
|
861
|
+
else {
|
|
862
|
+
jvm.matches.set(matchId, h);
|
|
863
|
+
writeRecord(jvm);
|
|
864
|
+
sendStart(h);
|
|
865
|
+
}
|
|
772
866
|
notifyRoom();
|
|
773
867
|
replenish();
|
|
774
868
|
return hostFace(h);
|
|
@@ -781,7 +875,7 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
781
875
|
factory.watchRoom = (listener) => {
|
|
782
876
|
roomWatchers.push(listener);
|
|
783
877
|
};
|
|
784
|
-
factory.jvms = () => [...jvms].map((j) => ({ hostId: j.hostId, warm: j.warm, draining: j.draining, adopted: j.adopted, matches: [...j.matches.keys()] }));
|
|
878
|
+
factory.jvms = () => [...jvms].map((j) => ({ hostId: j.hostId, warm: j.warm, draining: j.draining, adopted: j.adopted, matches: [...j.matches.keys()], waiting: [...j.waiting.keys()] }));
|
|
785
879
|
factory.drain = (hostId, why) => {
|
|
786
880
|
const jvm = [...jvms].find((j) => j.hostId === hostId);
|
|
787
881
|
if (jvm === undefined || jvm.draining || jvm.exited || jvm.released)
|
|
@@ -839,6 +933,7 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
839
933
|
fatal: null,
|
|
840
934
|
stopTimer: null,
|
|
841
935
|
stream: null,
|
|
936
|
+
held: null,
|
|
842
937
|
};
|
|
843
938
|
jvm.matches.set(h.id, h);
|
|
844
939
|
if (existsSync(streamFile(dir, h.id))) {
|
package/dist/room/lobby.d.ts
CHANGED
|
@@ -481,8 +481,9 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
|
|
|
481
481
|
subPlaceOf(roomId: string, rest: string): boolean;
|
|
482
482
|
gameSeatOf(roomId: string, memberId: string): number | null;
|
|
483
483
|
/**
|
|
484
|
-
* A member steps out. Removed from `members`; their state and Ready go with their row.
|
|
485
|
-
*
|
|
484
|
+
* A member steps out. Removed from `members`; their state and Ready go with their row. A leader
|
|
485
|
+
* who leaves still leads (`membership.ts`): only `passLeader` moves the lead, except in a testing
|
|
486
|
+
* room, which its seed leaves at once for whoever comes in (`removeRoomMember`'s `handOn`). What it
|
|
486
487
|
* costs their game is the type's (`RoomTypeHooks.leaving`). A room left by its last member is not
|
|
487
488
|
* deleted here (the idle sweep owns deletion) but leaves `offered()` the instant it empties.
|
|
488
489
|
* `no-room` and `not-member` are both answered the same 404 by the HTTP layer.
|
|
@@ -601,14 +602,16 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
|
|
|
601
602
|
flushed(): Promise<void>;
|
|
602
603
|
/**
|
|
603
604
|
* Account erase: every room that still names one of `ids` names `to` instead, and is saved. Answers
|
|
604
|
-
* how many rooms changed. The person leaves first (`leave`), so
|
|
605
|
+
* how many rooms changed. The person leaves first (`leave`), which keeps their lead, so a room they
|
|
606
|
+
* led is led by `to` afterwards: nobody, until an operator takes it (`passLeader`'s `override`).
|
|
605
607
|
*/
|
|
606
608
|
anonymise(ids: ReadonlySet<string>, to: string): number;
|
|
607
609
|
/**
|
|
608
610
|
* Account merge: every room that names the merged-away account names the kept one instead, by
|
|
609
611
|
* `moveIds` — so a room that already names the kept account is a conflict it wins, left for the
|
|
610
|
-
* erase sweep that follows (`erase/rooms.ts` has the person leave it first).
|
|
611
|
-
*
|
|
612
|
+
* erase sweep that follows (`erase/rooms.ts` has the person leave it first). A leave keeps the
|
|
613
|
+
* lead, so a conflict room the merged-away account led is handed to the kept account here, the
|
|
614
|
+
* same person, when it is a member. Each room changed is saved. Answers how many changed.
|
|
612
615
|
*/
|
|
613
616
|
merge(move: IdMove): number;
|
|
614
617
|
/** Does the room's record name any of `ids` anywhere (a member, a seat, a result)? False for no such room. */
|
package/dist/room/lobby.js
CHANGED
|
@@ -431,8 +431,9 @@ export class RoomLobby {
|
|
|
431
431
|
return seat === -1 ? null : seat;
|
|
432
432
|
}
|
|
433
433
|
/**
|
|
434
|
-
* A member steps out. Removed from `members`; their state and Ready go with their row.
|
|
435
|
-
*
|
|
434
|
+
* A member steps out. Removed from `members`; their state and Ready go with their row. A leader
|
|
435
|
+
* who leaves still leads (`membership.ts`): only `passLeader` moves the lead, except in a testing
|
|
436
|
+
* room, which its seed leaves at once for whoever comes in (`removeRoomMember`'s `handOn`). What it
|
|
436
437
|
* costs their game is the type's (`RoomTypeHooks.leaving`). A room left by its last member is not
|
|
437
438
|
* deleted here (the idle sweep owns deletion) but leaves `offered()` the instant it empties.
|
|
438
439
|
* `no-room` and `not-member` are both answered the same 404 by the HTTP layer.
|
|
@@ -444,10 +445,9 @@ export class RoomLobby {
|
|
|
444
445
|
if (!isRoomMember(room, memberId))
|
|
445
446
|
return { ok: false, reason: 'not-member' };
|
|
446
447
|
const cost = this.hooksOf(room).leaving?.(room, memberId) ?? {};
|
|
447
|
-
|
|
448
|
-
removeRoomMember(room, memberId);
|
|
448
|
+
removeRoomMember(room, memberId, room.testing);
|
|
449
449
|
this.persist(room);
|
|
450
|
-
this.log({ event: 'room-left', roomId, members: room.members.length,
|
|
450
|
+
this.log({ event: 'room-left', roomId, members: room.members.length, leader: room.leader });
|
|
451
451
|
return { ok: true, room: this.view(room), ...cost };
|
|
452
452
|
}
|
|
453
453
|
/** The floor a room made from `input` would have: its own, or its game type's when that is stricter (`tier-floor.ts`). */
|
|
@@ -553,7 +553,6 @@ export class RoomLobby {
|
|
|
553
553
|
return { ok: true, room: this.view(room), alreadyMember: false };
|
|
554
554
|
}
|
|
555
555
|
const now = this.now();
|
|
556
|
-
// An empty ledger's first member becomes its leader (an emptied room's new arrival leads it).
|
|
557
556
|
addRoomMember(room, { id: caller.id, userId: caller.userId, name: caller.name, joinedAt: now, state: undefined }, now);
|
|
558
557
|
this.#autoSeat(room, caller.id);
|
|
559
558
|
this.persist(room);
|
|
@@ -1011,7 +1010,8 @@ export class RoomLobby {
|
|
|
1011
1010
|
}
|
|
1012
1011
|
/**
|
|
1013
1012
|
* Account erase: every room that still names one of `ids` names `to` instead, and is saved. Answers
|
|
1014
|
-
* how many rooms changed. The person leaves first (`leave`), so
|
|
1013
|
+
* how many rooms changed. The person leaves first (`leave`), which keeps their lead, so a room they
|
|
1014
|
+
* led is led by `to` afterwards: nobody, until an operator takes it (`passLeader`'s `override`).
|
|
1015
1015
|
*/
|
|
1016
1016
|
anonymise(ids, to) {
|
|
1017
1017
|
let changed = 0;
|
|
@@ -1027,19 +1027,25 @@ export class RoomLobby {
|
|
|
1027
1027
|
/**
|
|
1028
1028
|
* Account merge: every room that names the merged-away account names the kept one instead, by
|
|
1029
1029
|
* `moveIds` — so a room that already names the kept account is a conflict it wins, left for the
|
|
1030
|
-
* erase sweep that follows (`erase/rooms.ts` has the person leave it first).
|
|
1031
|
-
*
|
|
1030
|
+
* erase sweep that follows (`erase/rooms.ts` has the person leave it first). A leave keeps the
|
|
1031
|
+
* lead, so a conflict room the merged-away account led is handed to the kept account here, the
|
|
1032
|
+
* same person, when it is a member. Each room changed is saved. Answers how many changed.
|
|
1032
1033
|
*/
|
|
1033
1034
|
merge(move) {
|
|
1034
1035
|
let changed = 0;
|
|
1035
1036
|
for (const room of this.#rooms.values()) {
|
|
1036
|
-
if (moveIds(room, move) === 0)
|
|
1037
|
+
if (moveIds(room, move) === 0 && !this.#leadToKept(room, move))
|
|
1037
1038
|
continue;
|
|
1038
1039
|
changed++;
|
|
1039
1040
|
this.persist(room);
|
|
1040
1041
|
}
|
|
1041
1042
|
return changed;
|
|
1042
1043
|
}
|
|
1044
|
+
/** A conflict room's lead, held by the merged-away account, to the kept account's member. False when it is not that. */
|
|
1045
|
+
#leadToKept(room, move) {
|
|
1046
|
+
const kept = move.renames.get(room.leader);
|
|
1047
|
+
return kept !== undefined && passRoomLeader(room, kept);
|
|
1048
|
+
}
|
|
1043
1049
|
/** Does the room's record name any of `ids` anywhere (a member, a seat, a result)? False for no such room. */
|
|
1044
1050
|
names(roomId, ids) {
|
|
1045
1051
|
const room = this.#rooms.get(roomId);
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Split out of `room/lobby.ts`'s `join`/`leave`/`setReady`/`viewOf`/`#persist`.
|
|
10
10
|
* These wrap `@wolffm/rooms-server`'s `MembershipLedger` functions, which
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* do the bookkeeping (who is in, readiness). The lead is permanent (the
|
|
12
|
+
* operator, 2026-11-29): whoever leads a room keeps it until they pass it
|
|
13
|
+
* (`passRoomLeader`). Leaving never hands it on, not even out of an emptied
|
|
14
|
+
* room, so the ledger's own succession on a leave is undone here.
|
|
15
15
|
*
|
|
16
16
|
* Every mutator mutates in place and returns nothing but what the caller
|
|
17
17
|
* cannot otherwise observe — the same discipline `lobby.ts`'s own mutators
|
|
@@ -34,23 +34,26 @@ export interface MembershipRoom<M extends MemberRow> {
|
|
|
34
34
|
/** Whether `id` already holds a seat at the table, so to speak — already a member of the room. */
|
|
35
35
|
export declare function isRoomMember<M extends MemberRow>(room: Pick<MembershipRoom<M>, 'members'>, id: string): boolean;
|
|
36
36
|
/**
|
|
37
|
-
* Add `member
|
|
38
|
-
*
|
|
39
|
-
*
|
|
37
|
+
* Add `member`. They lead only a room whose ledger names no leader (one being
|
|
38
|
+
* made, or a `handOn` room emptied); a leader who left keeps the lead, so an
|
|
39
|
+
* arrival in their absence is a member like any other. Mutates `room.members`,
|
|
40
40
|
* `room.leader` and `room.ledger`. The caller still owns auto-seating them
|
|
41
41
|
* and persisting the room.
|
|
42
42
|
*/
|
|
43
43
|
export declare function addRoomMember<M extends MemberRow>(room: MembershipRoom<M>, member: M, joinedAt: number): void;
|
|
44
44
|
/**
|
|
45
45
|
* Remove the member `id` — answers the removed row, or `undefined` when they
|
|
46
|
-
* were never a member.
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
46
|
+
* were never a member. The room's lead does not move, even when `id` held it
|
|
47
|
+
* or was the last one out: a leader away from the room is still its leader,
|
|
48
|
+
* and leads again the moment they are back. Mutates `room.members` and
|
|
49
|
+
* `room.ledger`. The caller still owns anything about the leaving member's
|
|
50
|
+
* GAME state (a pod drop, a table seat, a series) and persisting the room.
|
|
51
|
+
*
|
|
52
|
+
* `handOn` is for a room no person owns (a seeded testing room, made by a seed
|
|
53
|
+
* that leaves at once): its lead passes to whoever remains joined EARLIEST, and
|
|
54
|
+
* an emptied one's first arrival leads it.
|
|
52
55
|
*/
|
|
53
|
-
export declare function removeRoomMember<M extends MemberRow>(room: MembershipRoom<M>, id: string): M | undefined;
|
|
56
|
+
export declare function removeRoomMember<M extends MemberRow>(room: MembershipRoom<M>, id: string, handOn?: boolean): M | undefined;
|
|
54
57
|
/**
|
|
55
58
|
* Hand the room's leadership to the member `to`. Answers false, changing nothing, when `to` is not a
|
|
56
59
|
* member. The caller has checked the hand-off is the current leader's to make, and persists the room.
|
package/dist/room/membership.js
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Split out of `room/lobby.ts`'s `join`/`leave`/`setReady`/`viewOf`/`#persist`.
|
|
10
10
|
* These wrap `@wolffm/rooms-server`'s `MembershipLedger` functions, which
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* do the bookkeeping (who is in, readiness). The lead is permanent (the
|
|
12
|
+
* operator, 2026-11-29): whoever leads a room keeps it until they pass it
|
|
13
|
+
* (`passRoomLeader`). Leaving never hands it on, not even out of an emptied
|
|
14
|
+
* room, so the ledger's own succession on a leave is undone here.
|
|
15
15
|
*
|
|
16
16
|
* Every mutator mutates in place and returns nothing but what the caller
|
|
17
17
|
* cannot otherwise observe — the same discipline `lobby.ts`'s own mutators
|
|
@@ -26,9 +26,9 @@ export function isRoomMember(room, id) {
|
|
|
26
26
|
return room.members.some((m) => m.id === id);
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Add `member
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* Add `member`. They lead only a room whose ledger names no leader (one being
|
|
30
|
+
* made, or a `handOn` room emptied); a leader who left keeps the lead, so an
|
|
31
|
+
* arrival in their absence is a member like any other. Mutates `room.members`,
|
|
32
32
|
* `room.leader` and `room.ledger`. The caller still owns auto-seating them
|
|
33
33
|
* and persisting the room.
|
|
34
34
|
*/
|
|
@@ -39,22 +39,27 @@ export function addRoomMember(room, member, joinedAt) {
|
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Remove the member `id` — answers the removed row, or `undefined` when they
|
|
42
|
-
* were never a member.
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
42
|
+
* were never a member. The room's lead does not move, even when `id` held it
|
|
43
|
+
* or was the last one out: a leader away from the room is still its leader,
|
|
44
|
+
* and leads again the moment they are back. Mutates `room.members` and
|
|
45
|
+
* `room.ledger`. The caller still owns anything about the leaving member's
|
|
46
|
+
* GAME state (a pod drop, a table seat, a series) and persisting the room.
|
|
47
|
+
*
|
|
48
|
+
* `handOn` is for a room no person owns (a seeded testing room, made by a seed
|
|
49
|
+
* that leaves at once): its lead passes to whoever remains joined EARLIEST, and
|
|
50
|
+
* an emptied one's first arrival leads it.
|
|
48
51
|
*/
|
|
49
|
-
export function removeRoomMember(room, id) {
|
|
52
|
+
export function removeRoomMember(room, id, handOn = false) {
|
|
50
53
|
const index = room.members.findIndex((m) => m.id === id);
|
|
51
54
|
if (index === -1)
|
|
52
55
|
return undefined;
|
|
53
56
|
const removed = room.members[index];
|
|
54
57
|
room.members.splice(index, 1);
|
|
55
|
-
const
|
|
56
|
-
if (
|
|
57
|
-
room.
|
|
58
|
+
const next = memberLeft(room.ledger, id);
|
|
59
|
+
if (!handOn)
|
|
60
|
+
room.ledger.leaderId = room.leader;
|
|
61
|
+
else if (next !== null)
|
|
62
|
+
room.leader = next;
|
|
58
63
|
return removed;
|
|
59
64
|
}
|
|
60
65
|
/**
|
package/dist/room/record.d.ts
CHANGED
|
@@ -27,8 +27,12 @@ export interface PlatformMember extends MemberRow {
|
|
|
27
27
|
export interface PlatformRoomRecord<G, M extends PlatformMember = PlatformMember> {
|
|
28
28
|
id: string;
|
|
29
29
|
name: string;
|
|
30
|
+
/**
|
|
31
|
+
* Whoever made the room, never changed after. Not who leads it: an event a service caller made
|
|
32
|
+
* can name that service's account here, and the lead moves by `passLeader` without it. Read `leader`.
|
|
33
|
+
*/
|
|
30
34
|
creator: string;
|
|
31
|
-
/** Mirrors `ledger.leaderId`, kept non-null; it moves when the leader
|
|
35
|
+
/** Mirrors `ledger.leaderId`, kept non-null; it moves only when the leader hands it on (`membership.ts`), never on a leave. */
|
|
32
36
|
leader: string;
|
|
33
37
|
gameType: string;
|
|
34
38
|
/** A seeded, admin-only room: never swept (`room-list.ts`). */
|
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.176",
|
|
4
|
+
"gitHead": "496d4e086f48a863ada4fae6b255f3bd3b63d144",
|
|
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.",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"play/remote/"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.
|
|
21
|
-
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.
|
|
22
|
-
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.
|
|
20
|
+
"@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.176",
|
|
21
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.176",
|
|
22
|
+
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.209",
|
|
23
23
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.2",
|
|
24
24
|
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.145",
|
|
25
25
|
"@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.145",
|