@ksaa-nlp/gamehub-react-native-sdk 0.0.0-stage → 1.1.1
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/README.md +272 -2
- package/SPEC.md +265 -0
- package/dist/src/api-client.d.ts +7 -0
- package/dist/src/api-client.d.ts.map +1 -0
- package/dist/src/api-client.js +123 -0
- package/dist/src/api-client.js.map +1 -0
- package/dist/src/config.d.ts +15 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +45 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/constants.d.ts +6 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +6 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/content.d.ts +7 -0
- package/dist/src/content.d.ts.map +1 -0
- package/dist/src/content.js +70 -0
- package/dist/src/content.js.map +1 -0
- package/dist/src/host-events.d.ts +7 -0
- package/dist/src/host-events.d.ts.map +1 -0
- package/dist/src/host-events.js +20 -0
- package/dist/src/host-events.js.map +1 -0
- package/dist/src/identity.d.ts +10 -0
- package/dist/src/identity.d.ts.map +1 -0
- package/dist/src/identity.js +27 -0
- package/dist/src/identity.js.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +54 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/launch.d.ts +16 -0
- package/dist/src/launch.d.ts.map +1 -0
- package/dist/src/launch.js +115 -0
- package/dist/src/launch.js.map +1 -0
- package/dist/src/lobby-request.d.ts +4 -0
- package/dist/src/lobby-request.d.ts.map +1 -0
- package/dist/src/lobby-request.js +46 -0
- package/dist/src/lobby-request.js.map +1 -0
- package/dist/src/lobby.d.ts +33 -0
- package/dist/src/lobby.d.ts.map +1 -0
- package/dist/src/lobby.js +308 -0
- package/dist/src/lobby.js.map +1 -0
- package/dist/src/match-context.d.ts +10 -0
- package/dist/src/match-context.d.ts.map +1 -0
- package/dist/src/match-context.js +41 -0
- package/dist/src/match-context.js.map +1 -0
- package/dist/src/multiplayer-client.d.ts +27 -0
- package/dist/src/multiplayer-client.d.ts.map +1 -0
- package/dist/src/multiplayer-client.js +163 -0
- package/dist/src/multiplayer-client.js.map +1 -0
- package/dist/src/multiplayer-react.d.ts +4 -0
- package/dist/src/multiplayer-react.d.ts.map +1 -0
- package/dist/src/multiplayer-react.js +8 -0
- package/dist/src/multiplayer-react.js.map +1 -0
- package/dist/src/multiplayer-storage.d.ts +22 -0
- package/dist/src/multiplayer-storage.d.ts.map +1 -0
- package/dist/src/multiplayer-storage.js +65 -0
- package/dist/src/multiplayer-storage.js.map +1 -0
- package/dist/src/multiplayer-types.d.ts +54 -0
- package/dist/src/multiplayer-types.d.ts.map +1 -0
- package/dist/src/multiplayer-types.js +2 -0
- package/dist/src/multiplayer-types.js.map +1 -0
- package/dist/src/multiplayer.d.ts +5 -0
- package/dist/src/multiplayer.d.ts.map +1 -0
- package/dist/src/multiplayer.js +4 -0
- package/dist/src/multiplayer.js.map +1 -0
- package/dist/src/react.d.ts +11 -0
- package/dist/src/react.d.ts.map +1 -0
- package/dist/src/react.js +20 -0
- package/dist/src/react.js.map +1 -0
- package/dist/src/score.d.ts +9 -0
- package/dist/src/score.d.ts.map +1 -0
- package/dist/src/score.js +168 -0
- package/dist/src/score.js.map +1 -0
- package/dist/src/session-view.d.ts +4 -0
- package/dist/src/session-view.d.ts.map +1 -0
- package/dist/src/session-view.js +276 -0
- package/dist/src/session-view.js.map +1 -0
- package/dist/src/session.d.ts +10 -0
- package/dist/src/session.d.ts.map +1 -0
- package/dist/src/session.js +142 -0
- package/dist/src/session.js.map +1 -0
- package/dist/src/settings.d.ts +4 -0
- package/dist/src/settings.d.ts.map +1 -0
- package/dist/src/settings.js +40 -0
- package/dist/src/settings.js.map +1 -0
- package/dist/src/types.d.ts +125 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +5 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +16 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/vendor/colyseus-schemas/clock.d.ts +15 -0
- package/dist/vendor/colyseus-schemas/clock.js +67 -0
- package/dist/vendor/colyseus-schemas/common.d.ts +35 -0
- package/dist/vendor/colyseus-schemas/common.js +15 -0
- package/dist/vendor/colyseus-schemas/multiplayer.d.ts +8 -0
- package/dist/vendor/colyseus-schemas/multiplayer.js +26 -0
- package/dist/vendor/colyseus-schemas/ugc.d.ts +53 -0
- package/dist/vendor/colyseus-schemas/ugc.js +124 -0
- package/dist/vendor/gamehub-multiplayer-contracts/index.d.ts +200 -0
- package/dist/vendor/gamehub-multiplayer-contracts/index.js +289 -0
- package/dist/vendor/match.d.ts +37 -0
- package/dist/vendor/match.d.ts.map +1 -0
- package/dist/vendor/match.js +2 -0
- package/dist/vendor/match.js.map +1 -0
- package/dist/vendor/multiplayer-client.d.ts +50 -0
- package/dist/vendor/multiplayer-client.d.ts.map +1 -0
- package/dist/vendor/multiplayer-client.js +268 -0
- package/dist/vendor/multiplayer-client.js.map +1 -0
- package/dist/vendor/multiplayer-session.d.ts +82 -0
- package/dist/vendor/multiplayer-session.d.ts.map +1 -0
- package/dist/vendor/multiplayer-session.js +2 -0
- package/dist/vendor/multiplayer-session.js.map +1 -0
- package/dist/vendor/question.d.ts +35 -0
- package/dist/vendor/question.d.ts.map +1 -0
- package/dist/vendor/question.js +20 -0
- package/dist/vendor/question.js.map +1 -0
- package/dist/vendor/session.d.ts +158 -0
- package/dist/vendor/session.d.ts.map +1 -0
- package/dist/vendor/session.js +2 -0
- package/dist/vendor/session.js.map +1 -0
- package/dist/vendor/word.d.ts +147 -0
- package/dist/vendor/word.d.ts.map +1 -0
- package/dist/vendor/word.js +15 -0
- package/dist/vendor/word.js.map +1 -0
- package/package.json +90 -4
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Narrow an untrusted JSON object without accepting arrays. */
|
|
2
|
+
export declare function record(value: unknown): Record<string, unknown> | null;
|
|
3
|
+
export declare const integer: (v: unknown) => v is number;
|
|
4
|
+
export declare function freeze<T>(value: T): T;
|
|
5
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAIrE;AAED,eAAO,MAAM,OAAO,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,MACC,CAAC;AAC5C,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAMrC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Narrow an untrusted JSON object without accepting arrays. */
|
|
2
|
+
export function record(value) {
|
|
3
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
4
|
+
? value
|
|
5
|
+
: null;
|
|
6
|
+
}
|
|
7
|
+
export const integer = (v) => Number.isSafeInteger(v) && Number(v) >= 0;
|
|
8
|
+
export function freeze(value) {
|
|
9
|
+
if (value && typeof value === 'object') {
|
|
10
|
+
for (const child of Object.values(value))
|
|
11
|
+
freeze(child);
|
|
12
|
+
Object.freeze(value);
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,MAAM,UAAU,MAAM,CAAC,KAAc;IACnC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACzE,CAAC,CAAE,KAAiC;QACpC,CAAC,CAAC,IAAI,CAAC;AACX,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAU,EAAe,EAAE,CACjD,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAC5C,MAAM,UAAU,MAAM,CAAI,KAAQ;IAChC,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;YAAE,MAAM,CAAC,KAAK,CAAC,CAAC;QACxD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -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,35 @@
|
|
|
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';
|
|
18
|
+
export declare const PLATFORM_MESSAGES: {
|
|
19
|
+
readonly RETURN_TO_PLATFORM: "platform:return-to-platform";
|
|
20
|
+
readonly ROOM_DETAILS: "platform:room-details";
|
|
21
|
+
};
|
|
22
|
+
export interface PlatformReturnToPlatformPayload {
|
|
23
|
+
roomCode: string;
|
|
24
|
+
requestedByPeerId: string;
|
|
25
|
+
requestedAt: number;
|
|
26
|
+
reason?: 'TEAM_EMPTY' | 'NOT_ENOUGH_PLAYERS';
|
|
27
|
+
teamId?: string;
|
|
28
|
+
}
|
|
29
|
+
/** Host request and server presentation state for the TV joining overlay. */
|
|
30
|
+
export interface PlatformRoomDetailsPayload {
|
|
31
|
+
visible: boolean;
|
|
32
|
+
/** Private destination-host capability; requests only, never broadcast. */
|
|
33
|
+
controlToken?: string;
|
|
34
|
+
roomCode?: string;
|
|
35
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 const PLATFORM_MESSAGES = {
|
|
13
|
+
RETURN_TO_PLATFORM: 'platform:return-to-platform',
|
|
14
|
+
ROOM_DETAILS: 'platform:room-details',
|
|
15
|
+
};
|
|
@@ -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);
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/** Plain-data v2 wire contract. This entry must remain dependency and side-effect free. */
|
|
2
|
+
export declare const LAUNCH_VERSION: 2;
|
|
3
|
+
export declare const MULTIPLAYER_CAPABILITY: "multiplayer.launch.v2";
|
|
4
|
+
export declare const MULTIPLAYER_LOBBY_CAPABILITY: "multiplayer.lobby.v2";
|
|
5
|
+
export type LobbyMode = 'platform' | 'game';
|
|
6
|
+
export declare const CONTROL_TIMEOUT_MS = 10000;
|
|
7
|
+
export declare const ARRIVAL_WINDOW_MS = 90000;
|
|
8
|
+
export declare const RECOVERY_GRACE_MS = 60000;
|
|
9
|
+
export declare const RESERVATION_LEASE_MS = 15000;
|
|
10
|
+
export type ParticipantKind = 'human' | 'bot';
|
|
11
|
+
export declare const BOT_LEVELS: readonly ["easy", "medium", "hard"];
|
|
12
|
+
export type BotLevel = (typeof BOT_LEVELS)[number];
|
|
13
|
+
/** Bots stored before levels existed play at `medium`. */
|
|
14
|
+
export declare const DEFAULT_BOT_LEVEL: BotLevel;
|
|
15
|
+
export declare const isBotLevel: (value: unknown) => value is BotLevel;
|
|
16
|
+
/** UGC bots are game-owned; quiz bots are played by the built-in engine. Relay has none. */
|
|
17
|
+
export declare const BOT_ENGINES: readonly Engine[];
|
|
18
|
+
export interface PlayerPolicy {
|
|
19
|
+
minPlayers: number;
|
|
20
|
+
maxPlayers: number;
|
|
21
|
+
minHumanPlayers: number;
|
|
22
|
+
maxBots: number;
|
|
23
|
+
maxSpectators: number;
|
|
24
|
+
}
|
|
25
|
+
/** Missing policy identifies an existing two-human v2 package/round. */
|
|
26
|
+
export declare function playerPolicy(binding: {
|
|
27
|
+
playerPolicy?: PlayerPolicy;
|
|
28
|
+
}): PlayerPolicy;
|
|
29
|
+
export declare function parsePlayerPolicy(manifest: Record<string, unknown>, ceiling?: number): PlayerPolicy;
|
|
30
|
+
export type SeatType = 'player' | 'spectator';
|
|
31
|
+
export type SessionPhase = 'waiting' | 'in_round' | 'completed' | 'closed';
|
|
32
|
+
export type RoundPhase = 'preparing' | 'loading' | 'playing' | 'finishing' | 'completed' | 'aborted' | 'interrupted';
|
|
33
|
+
export type Authority = 'server' | 'unverified';
|
|
34
|
+
export type Engine = 'ugc' | 'quiz-template' | 'relay';
|
|
35
|
+
export interface PackageBinding {
|
|
36
|
+
lobbyMode?: LobbyMode;
|
|
37
|
+
/** Manifest lobbyUi:"game" capability required when the admin selects a game-owned lobby. */
|
|
38
|
+
gameLobbySupported?: boolean;
|
|
39
|
+
playerPolicy?: PlayerPolicy;
|
|
40
|
+
gameId: string;
|
|
41
|
+
gameSlug: string;
|
|
42
|
+
ownerId: string;
|
|
43
|
+
versionId: string;
|
|
44
|
+
versionKey: string;
|
|
45
|
+
contentHash: string;
|
|
46
|
+
serverHash: string | null;
|
|
47
|
+
gameUrl: string;
|
|
48
|
+
engine: Engine;
|
|
49
|
+
protocol: 'gamehub.v2';
|
|
50
|
+
scorePolicy?: 'history-only' | 'account';
|
|
51
|
+
profileId?: string | null;
|
|
52
|
+
questions?: 'none' | 'required';
|
|
53
|
+
}
|
|
54
|
+
export interface Seat {
|
|
55
|
+
/** Omitted only on records created before participant support; means human. */
|
|
56
|
+
kind?: ParticipantKind;
|
|
57
|
+
/** Bot seats only; omitted on bots created before levels means `medium`. */
|
|
58
|
+
botLevel?: BotLevel;
|
|
59
|
+
seatId: string;
|
|
60
|
+
displayName: string;
|
|
61
|
+
type: SeatType;
|
|
62
|
+
ready: boolean;
|
|
63
|
+
online: boolean;
|
|
64
|
+
status: 'joined' | 'left' | 'removed';
|
|
65
|
+
}
|
|
66
|
+
export interface LaunchReference {
|
|
67
|
+
recoveryGraceMs?: number;
|
|
68
|
+
version: 2;
|
|
69
|
+
multiplayerSessionId: string;
|
|
70
|
+
roundId: string;
|
|
71
|
+
attemptId: string;
|
|
72
|
+
seatId: string;
|
|
73
|
+
hostInstanceId: string;
|
|
74
|
+
gameUrl: string;
|
|
75
|
+
scoreAuthority: Authority;
|
|
76
|
+
}
|
|
77
|
+
export interface Reservation {
|
|
78
|
+
name: string;
|
|
79
|
+
roomId: string;
|
|
80
|
+
sessionId: string;
|
|
81
|
+
processId?: string;
|
|
82
|
+
publicAddress?: string;
|
|
83
|
+
}
|
|
84
|
+
export declare const ERROR_CODES: readonly ["INVALID_REQUEST", "UNAUTHORIZED", "LOGIN_REQUIRED", "FORBIDDEN", "NOT_FOUND", "GAME_MISMATCH", "GAME_UNAVAILABLE", "NO_QUESTIONS", "PROTOCOL_UNSUPPORTED", "PASSCODE_REQUIRED", "INVALID_PASSCODE", "ROOM_FULL", "SEAT_REMOVED", "SEAT_LEFT", "ROSTER_FROZEN", "NOT_HOST", "STALE_REVISION", "NOT_READY", "STALE_ATTEMPT", "STALE_GENERATION", "ALREADY_CONNECTED", "LAUNCH_PENDING", "LAUNCH_EXPIRED", "ARRIVAL_TIMEOUT", "RECOVERY_EXPIRED", "INTERRUPTED", "ROUND_TERMINAL", "RESULT_CONFLICT", "INVALID_RESULT", "RATE_LIMITED", "UNAVAILABLE", "CANCELLED", "STORAGE_UNAVAILABLE"];
|
|
85
|
+
export type ErrorCode = (typeof ERROR_CODES)[number];
|
|
86
|
+
export interface MultiplayerError {
|
|
87
|
+
code: ErrorCode;
|
|
88
|
+
retryable: boolean;
|
|
89
|
+
message: string;
|
|
90
|
+
phase?: RoundPhase | SessionPhase;
|
|
91
|
+
retryAfterMs?: number;
|
|
92
|
+
}
|
|
93
|
+
export declare class MultiplayerFault extends Error {
|
|
94
|
+
readonly code: ErrorCode;
|
|
95
|
+
readonly retryable: boolean;
|
|
96
|
+
readonly status: number;
|
|
97
|
+
constructor(code: ErrorCode, retryable?: boolean, status?: number);
|
|
98
|
+
toJSON(): MultiplayerError;
|
|
99
|
+
}
|
|
100
|
+
export type LaunchOutcome = {
|
|
101
|
+
status: 'reserved';
|
|
102
|
+
launch: LaunchReference;
|
|
103
|
+
reservation: Reservation;
|
|
104
|
+
wsEndpoint: string;
|
|
105
|
+
generation: number;
|
|
106
|
+
expiresAt: number;
|
|
107
|
+
} | {
|
|
108
|
+
status: 'recoverable' | 'terminal';
|
|
109
|
+
error: MultiplayerError;
|
|
110
|
+
};
|
|
111
|
+
export interface SessionView {
|
|
112
|
+
/** Normal rooms use host Start without confirmations; party/league retain readiness. */
|
|
113
|
+
lobbyReadyRequired?: boolean;
|
|
114
|
+
/** Derived public website URLs. Absent/null outside waiting or for invalid site configuration. */
|
|
115
|
+
invitations?: {
|
|
116
|
+
playerUrl: string;
|
|
117
|
+
spectatorUrl: string | null;
|
|
118
|
+
} | null;
|
|
119
|
+
/** Trusted host telemetry identity, excluded from the game lobby projection. */
|
|
120
|
+
gameId?: string;
|
|
121
|
+
/** Frozen presentation choice; old sessions retain the platform lobby. */
|
|
122
|
+
lobbyMode?: LobbyMode;
|
|
123
|
+
lobbyGameUrl?: string;
|
|
124
|
+
playerPolicy?: PlayerPolicy;
|
|
125
|
+
version: 2;
|
|
126
|
+
multiplayerSessionId: string;
|
|
127
|
+
roomCode: string;
|
|
128
|
+
gameSlug: string;
|
|
129
|
+
phase: SessionPhase;
|
|
130
|
+
revision: number;
|
|
131
|
+
hostSeatId: string;
|
|
132
|
+
ownSeatId: string;
|
|
133
|
+
rematchAllowed?: boolean;
|
|
134
|
+
/** Trusted host metadata; never part of the game-owned launch reference. */
|
|
135
|
+
contentOrigin?: string | null;
|
|
136
|
+
contentReady?: boolean;
|
|
137
|
+
seats: Seat[];
|
|
138
|
+
round: null | {
|
|
139
|
+
roundId: string;
|
|
140
|
+
revision?: number;
|
|
141
|
+
phase: RoundPhase;
|
|
142
|
+
reason: string | null;
|
|
143
|
+
projection?: 'pending' | 'applied' | 'rejected';
|
|
144
|
+
projectionReason?: string | null;
|
|
145
|
+
result: CanonicalResult | null;
|
|
146
|
+
launch: LaunchReference;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
export interface ResultProposal {
|
|
150
|
+
version: 2;
|
|
151
|
+
scores: Record<string, number>;
|
|
152
|
+
winnerSeatIds: string[];
|
|
153
|
+
reason: 'win' | 'draw' | 'forfeit' | 'abort';
|
|
154
|
+
metadata?: Record<string, string | number | boolean | null>;
|
|
155
|
+
}
|
|
156
|
+
export interface CanonicalResult extends ResultProposal {
|
|
157
|
+
participants?: Array<{
|
|
158
|
+
seatId: string;
|
|
159
|
+
displayName: string;
|
|
160
|
+
kind: ParticipantKind;
|
|
161
|
+
}>;
|
|
162
|
+
roundId: string;
|
|
163
|
+
multiplayerSessionId: string;
|
|
164
|
+
authority: Authority;
|
|
165
|
+
package: PackageBinding;
|
|
166
|
+
startedAt: number;
|
|
167
|
+
endedAt: number;
|
|
168
|
+
}
|
|
169
|
+
/** Public presentation of a party game's result; contains no admission credentials. */
|
|
170
|
+
export interface PartyGameResult {
|
|
171
|
+
multiplayerSessionId: string;
|
|
172
|
+
roundId: string;
|
|
173
|
+
gameSlug: string;
|
|
174
|
+
completed: boolean;
|
|
175
|
+
reason: ResultProposal['reason'] | null;
|
|
176
|
+
memberMetric?: 'correct-answers';
|
|
177
|
+
teams: Array<{
|
|
178
|
+
teamId: string;
|
|
179
|
+
name: string;
|
|
180
|
+
score: number | null;
|
|
181
|
+
winner: boolean;
|
|
182
|
+
members: Array<{
|
|
183
|
+
seatId: string;
|
|
184
|
+
displayName: string;
|
|
185
|
+
score: number | null;
|
|
186
|
+
correctAnswers?: number | null;
|
|
187
|
+
}>;
|
|
188
|
+
}>;
|
|
189
|
+
}
|
|
190
|
+
export declare const terminalRound: (phase: RoundPhase) => boolean;
|
|
191
|
+
export declare function canTransition(from: RoundPhase, to: RoundPhase): boolean;
|
|
192
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
193
|
+
export declare function isBoundedId(value: unknown): value is string;
|
|
194
|
+
export declare function isLaunchReference(value: unknown): value is LaunchReference;
|
|
195
|
+
export declare function isLaunchOutcome(value: unknown): value is LaunchOutcome;
|
|
196
|
+
export declare function parseResultProposal(value: unknown, participantSeatIds: readonly string[]): ResultProposal;
|
|
197
|
+
/** Stable, bounded canonical JSON; callers validate their domain payload first. */
|
|
198
|
+
export declare function canonicalJson(value: unknown): string;
|
|
199
|
+
export declare function normalizeError(error: unknown): MultiplayerError;
|
|
200
|
+
export declare function errorMessage(code: ErrorCode): string;
|