@ksaa-nlp/gamehub-sdk 4.5.0 → 5.0.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.
Files changed (55) hide show
  1. package/README.md +50 -45
  2. package/SPEC.md +93 -55
  3. package/dist/gamehub-sdk.js +14 -30
  4. package/dist/gamehub-sdk.js.map +3 -3
  5. package/dist/src/bot-driver.d.ts +2 -1
  6. package/dist/src/bot-driver.d.ts.map +1 -1
  7. package/dist/src/bot-driver.js +11 -1
  8. package/dist/src/bot-driver.js.map +1 -1
  9. package/dist/src/bridge.d.ts.map +1 -1
  10. package/dist/src/bridge.js +0 -35
  11. package/dist/src/bridge.js.map +1 -1
  12. package/dist/src/constants.d.ts +1 -1
  13. package/dist/src/constants.js +1 -1
  14. package/dist/src/init.js +7 -7
  15. package/dist/src/init.js.map +1 -1
  16. package/dist/src/main.d.ts +1 -1
  17. package/dist/src/main.d.ts.map +1 -1
  18. package/dist/src/main.js +3 -4
  19. package/dist/src/main.js.map +1 -1
  20. package/dist/src/multiplayer-client.d.ts +50 -0
  21. package/dist/src/multiplayer-client.d.ts.map +1 -0
  22. package/dist/src/multiplayer-client.js +268 -0
  23. package/dist/src/multiplayer-client.js.map +1 -0
  24. package/dist/src/multiplayer-entry.d.ts +9 -0
  25. package/dist/src/multiplayer-entry.d.ts.map +1 -0
  26. package/dist/src/multiplayer-entry.js +9 -0
  27. package/dist/src/multiplayer-entry.js.map +1 -0
  28. package/dist/src/multiplayer-session.d.ts.map +1 -1
  29. package/dist/src/multiplayer-session.js +3 -3
  30. package/dist/src/multiplayer-session.js.map +1 -1
  31. package/dist/src/multiplayer.d.ts.map +1 -1
  32. package/dist/src/multiplayer.js +2 -1
  33. package/dist/src/multiplayer.js.map +1 -1
  34. package/dist/src/session.d.ts.map +1 -1
  35. package/dist/src/session.js +3 -2
  36. package/dist/src/session.js.map +1 -1
  37. package/dist/src/state.d.ts +1 -2
  38. package/dist/src/state.d.ts.map +1 -1
  39. package/dist/src/state.js +0 -1
  40. package/dist/src/state.js.map +1 -1
  41. package/dist/types/bootstrap.d.ts +6 -45
  42. package/dist/types/bootstrap.d.ts.map +1 -1
  43. package/dist/types/multiplayer-session.d.ts +9 -8
  44. package/dist/types/multiplayer-session.d.ts.map +1 -1
  45. package/dist/vendor/colyseus-schemas/clock.d.ts +15 -0
  46. package/dist/vendor/colyseus-schemas/clock.js +67 -0
  47. package/dist/vendor/colyseus-schemas/common.d.ts +17 -0
  48. package/dist/vendor/colyseus-schemas/common.js +12 -0
  49. package/dist/vendor/colyseus-schemas/multiplayer.d.ts +8 -0
  50. package/dist/vendor/colyseus-schemas/multiplayer.js +26 -0
  51. package/dist/vendor/colyseus-schemas/ugc.d.ts +53 -0
  52. package/dist/vendor/colyseus-schemas/ugc.js +124 -0
  53. package/dist/vendor/gamehub-multiplayer-contracts/index.d.ts +176 -0
  54. package/dist/vendor/gamehub-multiplayer-contracts/index.js +287 -0
  55. package/package.json +33 -3
@@ -1,13 +1,13 @@
1
+ import type { LaunchReference } from '#multiplayer-contracts';
1
2
  import type { MultiplayerLobbyState, MultiplayerEntry } from './multiplayer-session.js';
2
3
  /** Account-wide game preferences. Games own their audio implementation. */
3
4
  export interface GameSettings {
4
5
  readonly musicEnabled: boolean;
5
6
  }
6
7
  /**
7
- * Seat reservation handed off from the GameHub host to the embedded game.
8
- * Mirrors the flat `ISeatReservation` shape returned by Colyseus's
9
- * matchmaker — redeclared here so this types package has no realtime-
10
- * transport dependency.
8
+ * Seat reservation returned by a reserved multiplayer launch. Mirrors the flat
9
+ * `ISeatReservation` shape returned by Colyseus's matchmaker — redeclared here
10
+ * so this types package has no realtime-transport dependency.
11
11
  */
12
12
  export interface SdkSeatReservation {
13
13
  name: string;
@@ -18,33 +18,6 @@ export interface SdkSeatReservation {
18
18
  reconnectionToken?: string;
19
19
  devMode?: boolean;
20
20
  }
21
- /**
22
- * Multiplayer block in the bootstrap payload.
23
- *
24
- * Present iff the host launched the game inside a live multiplayer room.
25
- * The SDK exposes this as-is on `sdk.getBootstrap().multiplayer`. Games
26
- * that want a Colyseus connection consume the seat reservation as the
27
- * blessed first-join path:
28
- *
29
- * const bs = sdk.getBootstrap();
30
- * if (bs.multiplayer) {
31
- * const client = new Client(bs.multiplayer.wsEndpoint);
32
- * const room = await client.consumeSeatReservation(bs.multiplayer.reservation);
33
- * }
34
- *
35
- * `reconnect(reconnectionToken)` is reserved for mid-match recovery
36
- * (laptop lid / network blip) and uses `room.reconnectionToken` minted by
37
- * the server after the initial join.
38
- */
39
- export interface BootstrapMultiplayer {
40
- reservation: SdkSeatReservation;
41
- wsEndpoint: string;
42
- /** Human room code for UI only; not an authentication credential. */
43
- roomCode?: string;
44
- role?: 'host' | 'player' | 'spectator';
45
- /** Per-embed-instance namespace for game-owned reconnect token storage. */
46
- connectionScope?: string;
47
- }
48
21
  export type BootstrapSessionMode = 'authenticated' | 'embed-guest' | 'league-guest';
49
22
  /**
50
23
  * The bootstrap payload the host posts via `GAMEHUB_SDK_BOOTSTRAP`.
@@ -76,7 +49,6 @@ export interface BootstrapConfig {
76
49
  * the chosen profile selects. Omitted → resolver isDefault fallback.
77
50
  */
78
51
  profileId?: string | null;
79
- multiplayer?: BootstrapMultiplayer | null;
80
52
  }
81
53
  /**
82
54
  * Snapshot returned by `sdk.getBootstrap()`. Same shape as
@@ -101,21 +73,10 @@ export interface BootstrapData {
101
73
  teamOneName: string | null;
102
74
  teamTwoName: string | null;
103
75
  profileId: string | null;
104
- multiplayer: BootstrapMultiplayer | null;
105
76
  isBootstrapped: boolean;
106
77
  }
107
- /** Opaque v2 wire context, kept local to avoid a runtime dependency on multiplayer. */
108
- export interface MultiplayerLaunchContext {
109
- recoveryGraceMs?: number;
110
- version: 2;
111
- multiplayerSessionId: string;
112
- roundId: string;
113
- attemptId: string;
114
- seatId: string;
115
- hostInstanceId: string;
116
- gameUrl: string;
117
- scoreAuthority: 'server' | 'unverified';
118
- }
78
+ /** Bound v2 round context; the wire type lives in the shared contracts package. */
79
+ export type MultiplayerLaunchContext = LaunchReference;
119
80
  export type MultiplayerLaunchResult = {
120
81
  status: 'reserved';
121
82
  launch: MultiplayerLaunchContext;
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../types/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,0BAA0B,CAAC;AAClC,2EAA2E;AAC3E,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;CAChC;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,kBAAkB,CAAC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,WAAW,CAAC;IACvC,2EAA2E;IAC3E,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,oBAAoB,GAC5B,eAAe,GACf,aAAa,GACb,cAAc,CAAC;AAEnB;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC3C,kBAAkB,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAAC;IAClD,uEAAuE;IACvE,QAAQ,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAC/B,YAAY,CA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,wBAAwB,CAAC;IACjC,WAAW,EAAE,kBAAkB,CAAC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,MAAM,EAAE,aAAa,GAAG,UAAU,CAAC;IACnC,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,OAAO,CAAC;QACnB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACH,CAAC"}
@@ -1,13 +1,14 @@
1
+ import type { BotLevel, ParticipantKind, SeatType, SessionPhase } from '#multiplayer-contracts';
1
2
  /** Host-controlled lobby operations. No account, session or engine overrides. */
2
3
  export type MultiplayerSessionRequest = {
3
4
  operation: 'create';
4
- type: 'player' | 'spectator';
5
+ type: SeatType;
5
6
  passcode?: string;
6
7
  } | {
7
8
  operation: 'join';
8
9
  roomCode: string;
9
10
  displayName: string;
10
- type: 'player' | 'spectator';
11
+ type: SeatType;
11
12
  passcode?: string;
12
13
  } | {
13
14
  operation: 'ready';
@@ -17,7 +18,7 @@ export type MultiplayerSessionRequest = {
17
18
  seatId: string;
18
19
  } | {
19
20
  operation: 'add-bot';
20
- level?: 'easy' | 'medium' | 'hard';
21
+ level?: BotLevel;
21
22
  } | {
22
23
  operation: 'read' | 'start' | 'leave' | 'rematch';
23
24
  };
@@ -32,7 +33,7 @@ export interface MultiplayerLobbySession {
32
33
  roomCode: string;
33
34
  invitationUrl?: string;
34
35
  spectatorInvitationUrl?: string;
35
- phase: 'waiting' | 'in_round' | 'completed' | 'closed';
36
+ phase: SessionPhase;
36
37
  revision: number;
37
38
  hostSeatId: string;
38
39
  ownSeatId: string;
@@ -47,10 +48,10 @@ export interface MultiplayerLobbySession {
47
48
  seats: {
48
49
  seatId: string;
49
50
  displayName: string;
50
- kind: 'human' | 'bot';
51
+ kind: ParticipantKind;
51
52
  /** Present on bot seats only. */
52
- botLevel?: 'easy' | 'medium' | 'hard';
53
- type: 'player' | 'spectator';
53
+ botLevel?: BotLevel;
54
+ type: SeatType;
54
55
  ready: boolean;
55
56
  online: boolean;
56
57
  }[];
@@ -76,6 +77,6 @@ export type MultiplayerSessionResult = {
76
77
  export interface MultiplayerEntry {
77
78
  action: 'create' | 'join';
78
79
  roomCode?: string;
79
- type?: 'player' | 'spectator';
80
+ type?: SeatType;
80
81
  }
81
82
  //# sourceMappingURL=multiplayer-session.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"multiplayer-session.d.ts","sourceRoot":"","sources":["../../types/multiplayer-session.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,MAAM,MAAM,yBAAyB,GACjC;IAAE,SAAS,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,QAAQ,GAAG,WAAW,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GACxE;IACE,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,QAAQ,GAAG,WAAW,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GACD;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACtC;IAAE,SAAS,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC3C;IAAE,SAAS,EAAE,SAAS,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAA;CAAE,GAC5D;IAAE,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAA;CAAE,CAAC;AAC1D,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;CACpB;AACD,MAAM,WAAW,uBAAuB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,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,uBAAuB,CAAA;CAAE,CAAC;AACvD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Server-clock helper for game clients.
3
+ *
4
+ * Pairs with the `clock:ping` / `clock:pong` handler in the server's
5
+ * `GameRoom` base class. Use the returned `serverNow()` — not
6
+ * `Date.now()` — for any timer math compared across peers (countdowns,
7
+ * deadlines).
8
+ *
9
+ * Each pong updates an EMA-smoothed offset; the first sample replaces it
10
+ * wholesale, subsequent samples blend. The ping loop tears itself down on
11
+ * `room.onLeave`.
12
+ */
13
+ import type { Room } from '@colyseus/sdk';
14
+ import type { Schema } from '@colyseus/schema';
15
+ export declare function attachServerClock(room: Room<any, Schema>): () => number;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Server-clock helper for game clients.
3
+ *
4
+ * Pairs with the `clock:ping` / `clock:pong` handler in the server's
5
+ * `GameRoom` base class. Use the returned `serverNow()` — not
6
+ * `Date.now()` — for any timer math compared across peers (countdowns,
7
+ * deadlines).
8
+ *
9
+ * Each pong updates an EMA-smoothed offset; the first sample replaces it
10
+ * wholesale, subsequent samples blend. The ping loop tears itself down on
11
+ * `room.onLeave`.
12
+ */
13
+ /** How often to send a `clock:ping` to keep the offset fresh. */
14
+ const CLOCK_PING_INTERVAL_MS = 15000;
15
+ /** Message types used for server-clock sync (matches the server's `GameRoom`). */
16
+ const CLOCK_PING_TYPE = 'clock:ping';
17
+ const CLOCK_PONG_TYPE = 'clock:pong';
18
+ /** EMA smoothing factor for incoming clock-pong samples. */
19
+ const SERVER_CLOCK_EMA_ALPHA = 0.2;
20
+ export function attachServerClock(room) {
21
+ let offsetMs = 0;
22
+ let samples = 0;
23
+ let stopped = false;
24
+ /**
25
+ * `Room` from `@colyseus/sdk` exposes its WS state via `room.connection`
26
+ * (also `isConnected` on more recent versions). Both fields are runtime-
27
+ * stable identifiers but neither is part of the public type today, so we
28
+ * read them dynamically and fall back to "try and rely on the try/catch".
29
+ */
30
+ const isOpen = () => {
31
+ const r = room;
32
+ if (typeof r.isConnected === 'boolean')
33
+ return r.isConnected;
34
+ if (r.connection && typeof r.connection.isOpen === 'boolean') {
35
+ return r.connection.isOpen;
36
+ }
37
+ return true;
38
+ };
39
+ const sendPing = () => {
40
+ if (stopped || !isOpen())
41
+ return;
42
+ try {
43
+ room.send(CLOCK_PING_TYPE, { t1: Date.now() });
44
+ }
45
+ catch {
46
+ /* socket may have closed between schedule and send */
47
+ }
48
+ };
49
+ const off = room.onMessage(CLOCK_PONG_TYPE, ({ t1, t2 }) => {
50
+ const t3 = Date.now();
51
+ const sample = t2 - (t1 + t3) / 2;
52
+ offsetMs =
53
+ samples === 0
54
+ ? sample
55
+ : SERVER_CLOCK_EMA_ALPHA * sample +
56
+ (1 - SERVER_CLOCK_EMA_ALPHA) * offsetMs;
57
+ samples += 1;
58
+ });
59
+ sendPing();
60
+ const interval = setInterval(sendPing, CLOCK_PING_INTERVAL_MS);
61
+ room.onLeave(() => {
62
+ stopped = true;
63
+ clearInterval(interval);
64
+ off();
65
+ });
66
+ return () => Date.now() + offsetMs;
67
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Shared types used across more than one engine.
3
+ *
4
+ * Anything specific to a single engine belongs in that engine's file
5
+ * (`ugc.ts`, `multiplayer.ts`, `unityJourney.ts`). Game-content types
6
+ * (`Question`, `QuestionDifficulty`) live in `@ksaa-nlp/gamehub-sdk`
7
+ * (see `types/question.ts`) since they're the contract between the host
8
+ * and game authors. Game-specific types (`Cell`, `Team`, `PowerKind`,
9
+ * etc.) do not belong in this package at all — they live inside the
10
+ * game's own project.
11
+ */
12
+ /**
13
+ * Lifecycle phase of a multiplayer room. The same `Room` carries the
14
+ * lobby and the active game; the lobby UI and the in-game iframe both
15
+ * read this field to decide which view to render.
16
+ */
17
+ export type Phase = 'lobby' | 'loading' | 'active' | 'ended';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Shared types used across more than one engine.
3
+ *
4
+ * Anything specific to a single engine belongs in that engine's file
5
+ * (`ugc.ts`, `multiplayer.ts`, `unityJourney.ts`). Game-content types
6
+ * (`Question`, `QuestionDifficulty`) live in `@ksaa-nlp/gamehub-sdk`
7
+ * (see `types/question.ts`) since they're the contract between the host
8
+ * and game authors. Game-specific types (`Cell`, `Team`, `PowerKind`,
9
+ * etc.) do not belong in this package at all — they live inside the
10
+ * game's own project.
11
+ */
12
+ export {};
@@ -0,0 +1,8 @@
1
+ import { MapSchema } from '@colyseus/schema';
2
+ import { UgcState } from './ugc.js';
3
+ /** Isolated v2 schema identity. Legacy/Unity room wire layouts do not change. */
4
+ export declare class MultiplayerState extends UgcState {
5
+ roundId: string;
6
+ roundPhase: string;
7
+ participantKinds: MapSchema<string, string>;
8
+ }
@@ -0,0 +1,26 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { type, MapSchema } from '@colyseus/schema';
8
+ import { UgcState } from './ugc.js';
9
+ /** Isolated v2 schema identity. Legacy/Unity room wire layouts do not change. */
10
+ export class MultiplayerState extends UgcState {
11
+ constructor() {
12
+ super(...arguments);
13
+ this.roundId = '';
14
+ this.roundPhase = 'loading';
15
+ this.participantKinds = new MapSchema();
16
+ }
17
+ }
18
+ __decorate([
19
+ type('string')
20
+ ], MultiplayerState.prototype, "roundId", void 0);
21
+ __decorate([
22
+ type('string')
23
+ ], MultiplayerState.prototype, "roundPhase", void 0);
24
+ __decorate([
25
+ type({ map: 'string' })
26
+ ], MultiplayerState.prototype, "participantKinds", void 0);
@@ -0,0 +1,53 @@
1
+ /**
2
+ * `UgcState` schema for the `ugc` engine — user-uploaded games whose
3
+ * authoritative server logic runs inside an `isolated-vm` sandbox on the
4
+ * colyseus side. The platform-wide `allowUgcServerLogic` setting AND the
5
+ * per-game `serverLogicApproved` flag must both be true for a room to be
6
+ * created on this engine; otherwise the game falls back to relay.
7
+ *
8
+ * The lobby roster + lifecycle phase mirror the relay engine. Game-defined
9
+ * state is exposed as a `MapSchema` of opaque JSON-encoded values keyed by
10
+ * top-level property name. Game authors mutate `ctx.state.<key> = value`
11
+ * inside the sandbox; the host serializes each top-level value to JSON
12
+ * once per dispatch and writes the result into `state.game`.
13
+ *
14
+ * Storing JSON-encoded scalars/objects (instead of registering arbitrary
15
+ * schemas at runtime) is what lets games ship state of any shape without
16
+ * authoring `@colyseus/schema` classes. The trade-off: a top-level key
17
+ * whose value mutates anywhere in its subtree re-sends the entire JSON
18
+ * blob for that key. Game authors who care about granular updates should
19
+ * shard their state across multiple top-level keys.
20
+ */
21
+ import { Schema, ArraySchema, MapSchema } from '@colyseus/schema';
22
+ import type { Phase } from './common.js';
23
+ export declare class UgcPlayer extends Schema {
24
+ peerId: string;
25
+ userId: string;
26
+ displayName: string;
27
+ avatar: string;
28
+ online: boolean;
29
+ ready: boolean;
30
+ joinedAt: number;
31
+ }
32
+ /** One entry in `UgcState.game`. The value is `JSON.stringify(...)` of any
33
+ * JSON-serializable subtree the guest assigned to that top-level key. */
34
+ export declare class UgcStateValue extends Schema {
35
+ json: string;
36
+ }
37
+ export declare class UgcState extends Schema {
38
+ phase: Phase;
39
+ roomCode: string;
40
+ hostPeerId: string;
41
+ maxPlayers: number;
42
+ createdAt: number;
43
+ startedAtMs: number;
44
+ endedAtMs: number;
45
+ /** Slug of the loaded UGC game. Diagnostic field; matches metadata.gameSlug. */
46
+ gameSlug: string;
47
+ /** sha256 of the currently running server bundle. Lets clients verify the
48
+ * authoritative code matches the version a moderator approved. */
49
+ serverBundleHash: string;
50
+ players: ArraySchema<UgcPlayer>;
51
+ /** Game-defined top-level keys. Each value is a JSON-encoded scalar/object. */
52
+ game: MapSchema<UgcStateValue, string>;
53
+ }
@@ -0,0 +1,124 @@
1
+ /**
2
+ * `UgcState` schema for the `ugc` engine — user-uploaded games whose
3
+ * authoritative server logic runs inside an `isolated-vm` sandbox on the
4
+ * colyseus side. The platform-wide `allowUgcServerLogic` setting AND the
5
+ * per-game `serverLogicApproved` flag must both be true for a room to be
6
+ * created on this engine; otherwise the game falls back to relay.
7
+ *
8
+ * The lobby roster + lifecycle phase mirror the relay engine. Game-defined
9
+ * state is exposed as a `MapSchema` of opaque JSON-encoded values keyed by
10
+ * top-level property name. Game authors mutate `ctx.state.<key> = value`
11
+ * inside the sandbox; the host serializes each top-level value to JSON
12
+ * once per dispatch and writes the result into `state.game`.
13
+ *
14
+ * Storing JSON-encoded scalars/objects (instead of registering arbitrary
15
+ * schemas at runtime) is what lets games ship state of any shape without
16
+ * authoring `@colyseus/schema` classes. The trade-off: a top-level key
17
+ * whose value mutates anywhere in its subtree re-sends the entire JSON
18
+ * blob for that key. Game authors who care about granular updates should
19
+ * shard their state across multiple top-level keys.
20
+ */
21
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
22
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
23
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
24
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
25
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
26
+ };
27
+ import { Schema, type, ArraySchema, MapSchema } from '@colyseus/schema';
28
+ export class UgcPlayer extends Schema {
29
+ constructor() {
30
+ super(...arguments);
31
+ this.peerId = '';
32
+ this.userId = '';
33
+ this.displayName = '';
34
+ this.avatar = '';
35
+ this.online = true;
36
+ this.ready = false;
37
+ this.joinedAt = 0;
38
+ }
39
+ }
40
+ __decorate([
41
+ type('string')
42
+ ], UgcPlayer.prototype, "peerId", void 0);
43
+ __decorate([
44
+ type('string')
45
+ ], UgcPlayer.prototype, "userId", void 0);
46
+ __decorate([
47
+ type('string')
48
+ ], UgcPlayer.prototype, "displayName", void 0);
49
+ __decorate([
50
+ type('string')
51
+ ], UgcPlayer.prototype, "avatar", void 0);
52
+ __decorate([
53
+ type('boolean')
54
+ ], UgcPlayer.prototype, "online", void 0);
55
+ __decorate([
56
+ type('boolean')
57
+ ], UgcPlayer.prototype, "ready", void 0);
58
+ __decorate([
59
+ type('number')
60
+ ], UgcPlayer.prototype, "joinedAt", void 0);
61
+ /** One entry in `UgcState.game`. The value is `JSON.stringify(...)` of any
62
+ * JSON-serializable subtree the guest assigned to that top-level key. */
63
+ export class UgcStateValue extends Schema {
64
+ constructor() {
65
+ super(...arguments);
66
+ this.json = '';
67
+ }
68
+ }
69
+ __decorate([
70
+ type('string')
71
+ ], UgcStateValue.prototype, "json", void 0);
72
+ export class UgcState extends Schema {
73
+ constructor() {
74
+ super(...arguments);
75
+ this.phase = 'lobby';
76
+ this.roomCode = '';
77
+ this.hostPeerId = '';
78
+ this.maxPlayers = 2;
79
+ this.createdAt = 0;
80
+ this.startedAtMs = 0;
81
+ this.endedAtMs = 0;
82
+ /** Slug of the loaded UGC game. Diagnostic field; matches metadata.gameSlug. */
83
+ this.gameSlug = '';
84
+ /** sha256 of the currently running server bundle. Lets clients verify the
85
+ * authoritative code matches the version a moderator approved. */
86
+ this.serverBundleHash = '';
87
+ this.players = new ArraySchema();
88
+ /** Game-defined top-level keys. Each value is a JSON-encoded scalar/object. */
89
+ this.game = new MapSchema();
90
+ }
91
+ }
92
+ __decorate([
93
+ type('string')
94
+ ], UgcState.prototype, "phase", void 0);
95
+ __decorate([
96
+ type('string')
97
+ ], UgcState.prototype, "roomCode", void 0);
98
+ __decorate([
99
+ type('string')
100
+ ], UgcState.prototype, "hostPeerId", void 0);
101
+ __decorate([
102
+ type('number')
103
+ ], UgcState.prototype, "maxPlayers", void 0);
104
+ __decorate([
105
+ type('number')
106
+ ], UgcState.prototype, "createdAt", void 0);
107
+ __decorate([
108
+ type('number')
109
+ ], UgcState.prototype, "startedAtMs", void 0);
110
+ __decorate([
111
+ type('number')
112
+ ], UgcState.prototype, "endedAtMs", void 0);
113
+ __decorate([
114
+ type('string')
115
+ ], UgcState.prototype, "gameSlug", void 0);
116
+ __decorate([
117
+ type('string')
118
+ ], UgcState.prototype, "serverBundleHash", void 0);
119
+ __decorate([
120
+ type([UgcPlayer])
121
+ ], UgcState.prototype, "players", void 0);
122
+ __decorate([
123
+ type({ map: UgcStateValue })
124
+ ], UgcState.prototype, "game", void 0);