import { RpgMap } from './rooms/map'; import { LobbyRoom } from './rooms/lobby'; import { RpgAuthContext } from './RpgServer'; /** Persistent storage available to the RPGJS server runtime. */ export interface RpgServerRuntimeStorage { /** Read one value from room storage. */ get(key: string): Promise; /** Store one value in room storage. */ put(key: string, value: T): Promise; /** Delete one or several values from room storage. */ delete(key: string | string[]): Promise; } /** Low-level room handle owned by an RPGJS server runtime. */ export interface RpgServerRuntimeRoom { /** Stable low-level room identifier. */ readonly id?: string; /** Storage scoped to the room. */ readonly storage: RpgServerRuntimeStorage; } /** * RPGJS-owned structural contract for the room server inherited by * {@link RpgServerEngine}. */ export interface RpgRoomServer { /** Current low-level room handle. */ readonly room: RpgServerRuntimeRoom; /** Current initialized gameplay sub-room. */ subRoom: unknown | null; /** Gameplay room classes available to this server. */ rooms: unknown[]; /** Whether the low-level room runtime is hibernating. */ readonly isHibernate: boolean; /** Storage scoped to the current room. */ readonly roomStorage: RpgServerRuntimeStorage; /** Send a packet to one low-level connection. */ send(connection: unknown, payload: unknown, subRoom: unknown): Promise; /** Send a packet to every low-level connection. */ broadcast(payload: unknown, subRoom: unknown): void; /** Initialize the current room. */ onStart(): Promise; /** Run session garbage collection immediately. */ runGarbageCollector(): Promise; /** Resolve one persisted session. */ getSession(privateId: string): Promise; /** Delete one persisted session. */ deleteSession(privateId: string): Promise; /** Connect a client to the current gameplay room. */ onConnectClient(connection: unknown, context: unknown): Promise; /** Handle an incoming low-level connection. */ onConnect(connection: unknown, context: unknown): Promise; /** Handle an incoming packet. */ onMessage(message: string, sender: unknown): Promise; /** Handle a closed connection. */ onClose(connection: unknown): Promise; /** Handle a room alarm. */ onAlarm(): Promise; /** Handle a connection error. */ onError(connection: unknown, error: Error): Promise; /** Handle an HTTP request routed to the room. */ onRequest(request: Request): Promise; } declare const RpgRoomServerBase: new (room: RpgServerRuntimeRoom) => RpgRoomServer; export type RpgServerRoomKind = string; export interface RpgServerRoomInfo { /** Full low-level room id, for example `lobby-1` or `map-town`. */ id: string; /** RPGJS room category inferred from the room id. */ kind: RpgServerRoomKind; /** Room name without the RPGJS prefix, for example `1` or `town`. */ name: string; /** Runtime class name of the RPGJS room instance. */ className: string; /** Number of players currently present when the room exposes a players signal. */ playersCount: number; /** Whether the current RPGJS room is configured for automatic sync. */ autoSync: boolean; /** Whether the current RPGJS room exposes a database signal. */ hasDatabase: boolean; } export type RpgServerCompatibilityApp = unknown; export type RpgServerCompatibilityIo = unknown; export declare class RpgServerEngine extends RpgRoomServerBase { rooms: unknown[]; private roomRegistry; private _globalConfig; constructor(room: RpgServerRuntimeRoom); /** Run post-acceptance player hooks for the physical WebSocket connection. */ onConnectionAccepted(connection: any, requestContext: any): Promise; private emitServerStep; /** * Optional compatibility handle for integrations that still expose an * application object, such as an Express app in a custom Node entry. * * RPGJS v5 does not create Express automatically. Assign this property from * your host integration when you need to keep v4-style code that reads * `engine.app`. * * @example * ```ts * const app = express() * engine.app = app * ``` */ app?: RpgServerCompatibilityApp; /** * Optional compatibility handle for integrations that still expose a realtime * transport object. * * RPGJS v5 uses Signe rooms instead of socket.io by default. Assign this * property from your host integration when v4-style code still reads * `engine.io`. * * @example * ```ts * const wsServer = new WebSocketServer({ noServer: true }) * engine.io = wsServer * ``` */ io?: RpgServerCompatibilityIo; /** * Current global RPGJS configuration. * * When the current room is a map room, this returns the map's `globalConfig`. * For lobby rooms or not-yet-initialized engines, it returns the last value * assigned to `engine.globalConfig`, or an empty object by default. * * @example * ```ts * const engine = { * onStart(server: RpgServerEngine) { * const globalConfig = server.globalConfig * console.log(globalConfig.startMapId) * } * } * ``` */ get globalConfig(): any; set globalConfig(value: any); /** * Returns the current RPGJS room instance. * * This is the RPGJS sub-room (`LobbyRoom`, `RpgMap`, or a future custom room), * not the low-level Signe/Party room wrapper available as `server.room`. * * @returns The current RPGJS room instance, or `null` before the room is initialized. * * @example * ```ts * const room = server.getCurrentRoom() * if (room) { * console.log(room.database()) * } * ``` */ getCurrentRoom(): T | null; /** * Returns the low-level id of the current room, such as `lobby-1` or * `map-town`. * * @returns The current room id, or `null` when unavailable. */ getCurrentRoomId(): string | null; /** * Returns the RPGJS kind of the current room. * * @returns `"lobby"`, `"map"`, or `"unknown"`. */ getCurrentRoomKind(): RpgServerRoomKind; /** * Returns stable metadata for the current RPGJS room. * * Use this method when you need room diagnostics without depending on Signe * internals such as `subRoom` or the raw `room` wrapper. * * @returns Current room metadata, or `null` before the room is initialized. * * @example * ```ts * const info = server.getCurrentRoomInfo() * console.log(info?.id, info?.kind, info?.playersCount) * ``` */ getCurrentRoomInfo(): RpgServerRoomInfo | null; onConnectClient(conn: any, ctx: any): Promise; protected authenticateConnection(conn: any, ctx: any): Promise; private createAuthContext; private notifyAuthenticationFailed; private createAuthSocket; private prepareAuthenticatedSession; private resolveAuthenticatedPrivateIds; private saveAuthenticatedSession; private addPrivateIdToPublicIndex; private removePrivateIdFromPublicIndex; private ensureAuthenticatedUser; private getRoomKind; private getRoomName; } export {};