@hadoku/game-server 0.1.36 → 0.1.38
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/room/ai-faces.d.ts +41 -0
- package/dist/room/ai-faces.js +72 -0
- package/dist/room/lobby.d.ts +31 -5
- package/dist/room/lobby.js +24 -5
- package/dist/room/record.d.ts +2 -4
- package/dist/room/record.js +2 -4
- package/package.json +5 -5
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who an AI seat is: one of the platform's characters, named after it (the operator,
|
|
3
|
+
* 2026-10-19: an AI plays as a character, by that character's own name). Generic to every
|
|
4
|
+
* room — Magic's pods and tournaments draw their AIs here, and so does every plain room
|
|
5
|
+
* (`plainRoomType`'s view, `seatPersonas`), so a bot looks and is named the same in every game.
|
|
6
|
+
*
|
|
7
|
+
* Drawn, never dealt in pool order: every room's first bot used to be the pool's first
|
|
8
|
+
* character. Seeded by room and seat, so every reader of the same room — every page, every
|
|
9
|
+
* restart — sees the same face, with nothing stored.
|
|
10
|
+
*/
|
|
11
|
+
import type { AiPersona } from '@wolffm/platform-wire/seats';
|
|
12
|
+
export type { AiPersona };
|
|
13
|
+
type Face = string | null | undefined;
|
|
14
|
+
/** `knight` → Knight. */
|
|
15
|
+
export declare function personaOf(avatarId: string): AiPersona;
|
|
16
|
+
/**
|
|
17
|
+
* A character drawn at random — seeded by `seed`, so the same room and seat
|
|
18
|
+
* always draws the same face — from the pool's least-used ones. `tiers` are
|
|
19
|
+
* compared in turn: a character that appears fewer times in the first is
|
|
20
|
+
* preferred, a tie goes to the next tier, and what is still tied is drawn
|
|
21
|
+
* from. So nobody shares a face while one is free, and past all of the pool
|
|
22
|
+
* it cycles rather than repeating one face (the operator, 2026-11-01).
|
|
23
|
+
*/
|
|
24
|
+
export declare function drawAvatar(seed: string, ...tiers: readonly (readonly Face[])[]): string;
|
|
25
|
+
/** What `seatPersonas` reads of a room: its id, who holds each seat, and the faces its members wear. */
|
|
26
|
+
export interface PersonaRoom {
|
|
27
|
+
id: string;
|
|
28
|
+
seats: readonly (string | null)[];
|
|
29
|
+
members: readonly {
|
|
30
|
+
id: string;
|
|
31
|
+
avatarId?: string | undefined;
|
|
32
|
+
}[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The AI at each of `room`'s seats (`aiMarker` holds it), in seat order; null for every other
|
|
36
|
+
* seat. Each AI walks its own seeded order of the pool (room id and seat) and takes the first
|
|
37
|
+
* face nobody wears — no member, no AI at an earlier seat. So a bot keeps its face while people
|
|
38
|
+
* come and go, and only redraws when a person puts on exactly that face; and past the pool's
|
|
39
|
+
* size, faces repeat as `drawAvatar`'s least-used rule picks them.
|
|
40
|
+
*/
|
|
41
|
+
export declare function seatPersonas(room: PersonaRoom, aiMarker: string): (AiPersona | null)[];
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { AVATAR_POOL } from '@wolffm/rooms-protocol';
|
|
2
|
+
/** FNV-1a: a stable 32-bit number for a string, so a seeded pick is the same on every run. */
|
|
3
|
+
function seedOf(text) {
|
|
4
|
+
let h = 0x811c9dc5;
|
|
5
|
+
for (let i = 0; i < text.length; i++)
|
|
6
|
+
h = Math.imul(h ^ text.charCodeAt(i), 0x01000193);
|
|
7
|
+
return h >>> 0;
|
|
8
|
+
}
|
|
9
|
+
/** `knight` → Knight. */
|
|
10
|
+
export function personaOf(avatarId) {
|
|
11
|
+
return { name: avatarId.charAt(0).toUpperCase() + avatarId.slice(1), avatarId };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A character drawn at random — seeded by `seed`, so the same room and seat
|
|
15
|
+
* always draws the same face — from the pool's least-used ones. `tiers` are
|
|
16
|
+
* compared in turn: a character that appears fewer times in the first is
|
|
17
|
+
* preferred, a tie goes to the next tier, and what is still tied is drawn
|
|
18
|
+
* from. So nobody shares a face while one is free, and past all of the pool
|
|
19
|
+
* it cycles rather than repeating one face (the operator, 2026-11-01).
|
|
20
|
+
*/
|
|
21
|
+
export function drawAvatar(seed, ...tiers) {
|
|
22
|
+
const counts = tiers.map((faces) => {
|
|
23
|
+
const n = new Map();
|
|
24
|
+
for (const f of faces)
|
|
25
|
+
if (f !== null && f !== undefined)
|
|
26
|
+
n.set(f, (n.get(f) ?? 0) + 1);
|
|
27
|
+
return n;
|
|
28
|
+
});
|
|
29
|
+
let least = [...AVATAR_POOL];
|
|
30
|
+
for (const n of counts) {
|
|
31
|
+
const min = Math.min(...least.map((a) => n.get(a) ?? 0));
|
|
32
|
+
least = least.filter((a) => (n.get(a) ?? 0) === min);
|
|
33
|
+
}
|
|
34
|
+
return least[seedOf(seed) % least.length];
|
|
35
|
+
}
|
|
36
|
+
/** The pool in an order of `seed`'s own: the same seed, the same order (a seeded Fisher–Yates). */
|
|
37
|
+
function poolOrder(seed) {
|
|
38
|
+
const order = [...AVATAR_POOL];
|
|
39
|
+
let state = seedOf(seed) || 1;
|
|
40
|
+
for (let i = order.length - 1; i > 0; i--) {
|
|
41
|
+
// xorshift32: enough spread for a shuffle of a couple of dozen faces.
|
|
42
|
+
state ^= state << 13;
|
|
43
|
+
state ^= state >>> 17;
|
|
44
|
+
state ^= state << 5;
|
|
45
|
+
const j = (state >>> 0) % (i + 1);
|
|
46
|
+
[order[i], order[j]] = [order[j], order[i]];
|
|
47
|
+
}
|
|
48
|
+
return order;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The AI at each of `room`'s seats (`aiMarker` holds it), in seat order; null for every other
|
|
52
|
+
* seat. Each AI walks its own seeded order of the pool (room id and seat) and takes the first
|
|
53
|
+
* face nobody wears — no member, no AI at an earlier seat. So a bot keeps its face while people
|
|
54
|
+
* come and go, and only redraws when a person puts on exactly that face; and past the pool's
|
|
55
|
+
* size, faces repeat as `drawAvatar`'s least-used rule picks them.
|
|
56
|
+
*/
|
|
57
|
+
export function seatPersonas(room, aiMarker) {
|
|
58
|
+
const worn = new Set();
|
|
59
|
+
for (const m of room.members)
|
|
60
|
+
if (m.avatarId !== undefined)
|
|
61
|
+
worn.add(m.avatarId);
|
|
62
|
+
const drawn = [];
|
|
63
|
+
return room.seats.map((holder, seat) => {
|
|
64
|
+
if (holder !== aiMarker)
|
|
65
|
+
return null;
|
|
66
|
+
const seed = `${room.id}:${seat}`;
|
|
67
|
+
const face = poolOrder(seed).find((a) => !worn.has(a)) ?? drawAvatar(seed, [...room.members.map((m) => m.avatarId), ...drawn]);
|
|
68
|
+
worn.add(face);
|
|
69
|
+
drawn.push(face);
|
|
70
|
+
return personaOf(face);
|
|
71
|
+
});
|
|
72
|
+
}
|
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 AiPersona } from './ai-faces.js';
|
|
37
38
|
import type { Caller } from './caller.js';
|
|
38
39
|
import { type Secret } from './provisioning.js';
|
|
39
40
|
import { type GameSeats, type PlatformMember, type PlatformRoomRecord } from './record.js';
|
|
@@ -548,14 +549,39 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
|
|
|
548
549
|
*/
|
|
549
550
|
open(): Promise<number>;
|
|
550
551
|
}
|
|
552
|
+
/** How a plain room is sized, and which of the platform's seat behaviours it opts into. */
|
|
553
|
+
export interface PlainRoomSize {
|
|
554
|
+
/** The seats a new room opens with; trimming never takes it below this. */
|
|
555
|
+
seats: number;
|
|
556
|
+
/** The most seats it grows to. */
|
|
557
|
+
max: number;
|
|
558
|
+
/** A relay room's match seat count: set when the room IS its relay match. */
|
|
559
|
+
relaySeats?: number;
|
|
560
|
+
/**
|
|
561
|
+
* Report seats as stored — `AI_SEAT` and `CLOSED_SEAT` included — rather than `memberSeats`'
|
|
562
|
+
* reading, which shows both as open. A game whose seat list draws bots and closed seats wants
|
|
563
|
+
* this; neither marker is ever a member id, so `gameSeatOf` still only matches a member's own seat.
|
|
564
|
+
*/
|
|
565
|
+
markedSeats?: boolean;
|
|
566
|
+
/**
|
|
567
|
+
* Keep one seat open: whenever every seat is taken (no open and no closed one), add another,
|
|
568
|
+
* up to `max`. The room grows by itself; nobody presses a "+" to make room for the next player,
|
|
569
|
+
* and a seat the leader closed is never reopened by it.
|
|
570
|
+
*/
|
|
571
|
+
keepOneOpen?: boolean;
|
|
572
|
+
}
|
|
573
|
+
/** What a plain room's view adds to the platform's: the AI at each seat, `seatPersonas`'s draw. */
|
|
574
|
+
export interface PlainRoomView {
|
|
575
|
+
/** In seat order; null where no AI sits. */
|
|
576
|
+
aiSeats: (AiPersona | null)[];
|
|
577
|
+
}
|
|
551
578
|
/**
|
|
552
579
|
* The room type of a game that keeps nothing of its own in the room (bomberman): no game part, its
|
|
553
580
|
* players in the platform's game seats, opened with `seats` of them and growing to `max`, an AI or a
|
|
554
581
|
* closed seat in any open one. `relaySeats` when the room is its own relay match.
|
|
582
|
+
*
|
|
583
|
+
* A member who leaves the room gives up their seat (`leaving`): `RoomLobby.leave` drops only the
|
|
584
|
+
* membership, so without it the departed id stayed in the seat for good.
|
|
555
585
|
*/
|
|
556
|
-
export declare function plainRoomType<I extends RoomCreateInput>(size:
|
|
557
|
-
seats: number;
|
|
558
|
-
max: number;
|
|
559
|
-
relaySeats?: number;
|
|
560
|
-
}): RoomTypeHooks<Record<string, never>, I>;
|
|
586
|
+
export declare function plainRoomType<I extends RoomCreateInput>(size: PlainRoomSize): RoomTypeHooks<Record<string, never>, I>;
|
|
561
587
|
export {};
|
package/dist/room/lobby.js
CHANGED
|
@@ -39,6 +39,7 @@ 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
41
|
import { replaceIds } from "../erase/anonymise.js";
|
|
42
|
+
import { seatPersonas } from "./ai-faces.js";
|
|
42
43
|
import { avatarIdOf } from "./avatar.js";
|
|
43
44
|
import { ROOM_STALE_MS, UNNAMED } from "./constants.js";
|
|
44
45
|
import { addRoomMember, isMemberReady, isRoomMember, passRoomLeader, passwordAdmits, removeRoomMember, setMemberReady } from "./membership.js";
|
|
@@ -349,13 +350,16 @@ export class RoomLobby {
|
|
|
349
350
|
const players = this.playersOf(room);
|
|
350
351
|
if (room.members.some((m) => m.id !== memberId && !players.includes(m.id)))
|
|
351
352
|
return;
|
|
352
|
-
const
|
|
353
|
+
const hooks = this.hooksOf(room);
|
|
354
|
+
const how = hooks.autoSeat?.(room, memberId) ?? 'game-seat';
|
|
353
355
|
if (how !== 'game-seat')
|
|
354
356
|
return;
|
|
355
357
|
const open = room.seats.indexOf(null);
|
|
356
358
|
if (open === -1)
|
|
357
359
|
return;
|
|
358
360
|
setGameSeat(room, open, memberId);
|
|
361
|
+
// As every other seat op does: a type that keeps a seat open (`plainRoomType`'s `keepOneOpen`) grows here.
|
|
362
|
+
hooks.trimSeats(room);
|
|
359
363
|
this.log({ event: 'seat-auto', roomId: room.id, seat: open, memberId });
|
|
360
364
|
}
|
|
361
365
|
/** `seatsShutUntil`, for a room in hand. */
|
|
@@ -1046,9 +1050,19 @@ function isStoredSeats(v) {
|
|
|
1046
1050
|
* The room type of a game that keeps nothing of its own in the room (bomberman): no game part, its
|
|
1047
1051
|
* players in the platform's game seats, opened with `seats` of them and growing to `max`, an AI or a
|
|
1048
1052
|
* closed seat in any open one. `relaySeats` when the room is its own relay match.
|
|
1053
|
+
*
|
|
1054
|
+
* A member who leaves the room gives up their seat (`leaving`): `RoomLobby.leave` drops only the
|
|
1055
|
+
* membership, so without it the departed id stayed in the seat for good.
|
|
1049
1056
|
*/
|
|
1050
1057
|
export function plainRoomType(size) {
|
|
1051
1058
|
const open = () => new Array(size.seats).fill(null);
|
|
1059
|
+
const full = (seats) => !seats.some((s) => s === null || s === CLOSED_SEAT);
|
|
1060
|
+
const trim = (room) => {
|
|
1061
|
+
while (room.seats.length > size.seats && room.seats.at(-1) === null)
|
|
1062
|
+
room.seats = room.seats.slice(0, -1);
|
|
1063
|
+
if (size.keepOneOpen === true && room.seats.length < size.max && full(room.seats))
|
|
1064
|
+
room.seats = [...room.seats, null];
|
|
1065
|
+
};
|
|
1052
1066
|
return {
|
|
1053
1067
|
newGame: () => ({ seats: open(), game: {} }),
|
|
1054
1068
|
encode: () => ({}),
|
|
@@ -1058,7 +1072,7 @@ export function plainRoomType(size) {
|
|
|
1058
1072
|
return { seats: app.seats === undefined ? open() : [...app.seats], game: {} };
|
|
1059
1073
|
},
|
|
1060
1074
|
restore: () => ({ dropHolds: false, game: () => ({}) }),
|
|
1061
|
-
view: () => ({}),
|
|
1075
|
+
view: (room) => ({ aiSeats: seatPersonas(room, AI_SEAT) }),
|
|
1062
1076
|
busy: NO_BUSY_HOOK,
|
|
1063
1077
|
liveMatches: () => [],
|
|
1064
1078
|
usesSeats: () => true,
|
|
@@ -1068,10 +1082,15 @@ export function plainRoomType(size) {
|
|
|
1068
1082
|
while (room.seats.length <= seat)
|
|
1069
1083
|
room.seats = [...room.seats, null];
|
|
1070
1084
|
},
|
|
1071
|
-
trimSeats
|
|
1072
|
-
|
|
1073
|
-
|
|
1085
|
+
trimSeats: trim,
|
|
1086
|
+
leaving(room, memberId) {
|
|
1087
|
+
const seat = room.seats.indexOf(memberId);
|
|
1088
|
+
if (seat === -1)
|
|
1089
|
+
return;
|
|
1090
|
+
room.seats = room.seats.map((s, i) => (i === seat ? null : s));
|
|
1091
|
+
trim(room);
|
|
1074
1092
|
},
|
|
1093
|
+
...(size.markedSeats === true ? { seatsView: (room) => room.seats } : {}),
|
|
1075
1094
|
...(size.relaySeats === undefined ? {} : { relaySeats: size.relaySeats }),
|
|
1076
1095
|
};
|
|
1077
1096
|
}
|
package/dist/room/record.d.ts
CHANGED
|
@@ -14,10 +14,8 @@ import type { MemberRow } from './membership.js';
|
|
|
14
14
|
* watching.
|
|
15
15
|
*/
|
|
16
16
|
export type GameSeats = (string | null)[];
|
|
17
|
-
/** The
|
|
18
|
-
export
|
|
19
|
-
/** The marker of a seat its room's leader closed: nobody sits there, and the game is a seat smaller. */
|
|
20
|
-
export declare const CLOSED_SEAT = "closed";
|
|
17
|
+
/** The seat markers: defined in `@hadoku/platform-wire/seats`, which every game's page reads too. */
|
|
18
|
+
export { AI_SEAT, CLOSED_SEAT } from '@wolffm/platform-wire/seats';
|
|
21
19
|
/** What every member record has, whatever the game. */
|
|
22
20
|
export interface PlatformMember extends MemberRow {
|
|
23
21
|
/** The registry userId. null for a member the edge named nobody. */
|
package/dist/room/record.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
/** The
|
|
2
|
-
export
|
|
3
|
-
/** The marker of a seat its room's leader closed: nobody sits there, and the game is a seat smaller. */
|
|
4
|
-
export const CLOSED_SEAT = 'closed';
|
|
1
|
+
/** The seat markers: defined in `@hadoku/platform-wire/seats`, which every game's page reads too. */
|
|
2
|
+
export { AI_SEAT, CLOSED_SEAT } from '@wolffm/platform-wire/seats';
|
|
5
3
|
/**
|
|
6
4
|
* The seat `memberId` holds in the room's game, or null when they hold none (they are watching, or
|
|
7
5
|
* not in the room). A seat whose holder is not a member counts as nobody's.
|
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.38",
|
|
4
|
+
"gitHead": "a4239391dc183d4efad36b3184e672a00cf9c7fa",
|
|
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.38",
|
|
20
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.38",
|
|
21
|
+
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.71",
|
|
22
22
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.27",
|
|
23
23
|
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.109",
|
|
24
24
|
"@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.109",
|