UNPKG

rune-sdk

Version:

Build a multiplayer game played by millions! Your game runs inside the Rune app with 10 million installs across [iOS](https://apps.apple.com/app/rune-games-and-voice-chat/id1450358364) and [Android](https://play.google.com/store/apps/details?id=ai.rune.ti

865 lines (846 loc) 31 kB
/* Copyright (c) 2024 Rune AI Inc. All rights reserved. This code is proprietary to Rune AI Inc. The code may be used solely for accessing the Service provided by Rune AI Inc. following the Rune AI Inc. Terms of Service ("Terms") accessible at rune.ai/eula. You may not use this code for any use or purpose other than as expressly permitted by the Terms. Restrictions set forth in the Terms include, but is not limited to, that you may not copy, adapt, modify, prepare derivative works based upon, distribute, license, sell, transfer, publicly display, publicly perform, transmit, stream, broadcast, attempt to discover any source code, reverse engineer, decompile, dissemble, or otherwise exploit the code as a whole or any portion of the code. */ declare function generateId(length?: number): string; type PersistedPlayers<PersistedData> = Record<PlayerId, PersistedData>; type PersistedUsers<PersistedData> = Record<UserId, PersistedData>; type GameStateWithPersisted<GameState, PersistedData> = GameState & { persisted: PersistedPlayers<PersistedData>; }; type UntypedPersistedData = {}; type UntypedGameState = Record<string, any>; type UntypedGameStateWithPersisted = GameStateWithPersisted<UntypedGameState, UntypedPersistedData>; type UntypedInitLogicAction = (params?: any) => void; type UntypedInitLogicActions = Record<string, UntypedInitLogicAction>; type GameConfig = { landscape: boolean; minPlayers: number; maxPlayers: number; updatesPerSecond: number; eventCallbacks: { playerLeft: boolean; playerJoined: boolean; }; update: boolean; persistPlayerData: boolean; reactive: boolean; }; type SessionId = string; type GameId = number; type PlayerId = string; type RandomSeed = number; type Player = { playerId: PlayerId; displayName: string; avatarUrl: string; }; type Players = Record<PlayerId, Player>; type UserId = number; type Spectator = { playerId: undefined; }; type User = (Player | Spectator) & { userId: number; sdkProtocolVersion: number; }; type Users = Record<UserId, User>; type Environment = "runtime" | "devUI" | "test"; type AIPromptResponse = { requestId: string; response: string; }; type AIPromptRequest = { data: AIPromptRequestData; requestId: string; }; type AIPromptMessageContent = { type: "text"; text: string; } | { type: "image_data"; image_url: string; }; type AIPromptRequestData = { messages: { role: string; content: string | AIPromptMessageContent[]; }[]; }; type AIPromptRequestFunction = (data: AIPromptRequestData) => { requestId: string; }; type LogFn = { (obj: object, msg: string): void; (msg: string): void; }; type MsgLogger = { error: LogFn; warn: LogFn; info: LogFn; }; type LogInfo = { devDash: null; } | { devDash: { type: "CLIENT" | "LOGIC"; userType?: "UNKNOWN" | "PLAYER" | "SPECTATOR"; }; }; type ServerErrorMessage = keyof typeof errorMap; declare const errorMap: { SERVER_UPDATE_LOOP_FASTER_THAN_GAME_TIME: { devUIUnexpected: true; logInfo: { devDash: null; }; }; GET_GAME_STATE_FAILED: { devUIUnexpected: true; logInfo: { devDash: null; }; }; SERVER_RECEIVED_MESSAGE_TOO_BIG: { devUIUnexpected: true; logInfo: { devDash: null; }; }; SERVER_MESSAGE_TO_CLIENTS_TOO_BIG: { devUIUnexpected: true; logInfo: { devDash: null; }; }; SERVER_FULL: { devUIUnexpected: true; logInfo: { devDash: null; }; }; ON_PLAYER_JOINED_CALLBACK_MISSING: { devUIUnexpected: true; logInfo: { devDash: null; }; }; ROOM_GAME_STATE_MISSING: { devUIUnexpected: true; logInfo: { devDash: null; }; }; PERSIST_DATA_AFTER_ERROR_NOT_AVAILABLE: { devUIUnexpected: true; logInfo: { devDash: null; }; }; GET_PERSISTED_STATE_FAILED: { devUIUnexpected: true; logInfo: { devDash: null; }; }; GAME_END_PERSIST_USER_NOT_FOUND: { devUIUnexpected: true; logInfo: { devDash: null; }; }; PLAYER_LEFT_NO_USERS_INCORRECT_PERSISTED_PLAYERS: { devUIUnexpected: true; logInfo: { devDash: null; }; }; PERSISTED_STATE_NOT_ENABLED: { devUIUnexpected: true; logInfo: { devDash: null; }; }; UPDATE_LOOP_BEHIND_GAME_TIME: { devUIMessage: string; logInfo: { devDash: null; }; }; AI_PROMPT_REQUEST_FAILED: { devUIUnexpected: true; logInfo: { devDash: null; }; }; ACTION_PARAMS_SIZE_OVER_LIMIT: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PLAYER_JOINED_FAILED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PLAYER_LEFT_FAILED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); AI_PROMPT_RESPONSE_FAILED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); ACTION_TRIGGERED_IN_LOGIC: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); STATE_SYNC_TOO_BIG: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); GAME_OVER_INVALID_OPTIONS: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); SERVER_UPDATE_LOOP_FAILED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); ACTION_FAILED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); SETUP_GAME_OVER_NOT_ALLOWED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); SETUP_FAILED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PERSISTED_STATE_USED_WITHOUT_FLAG: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); SETUP_PERSISTED_KEY_NOT_ALLOWED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PERSISTED_NOT_AN_OBJECT: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PERSISTED_KEY_MISSING: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PERSISTED_EXTRA_KEY_DETECTED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PERSISTED_PLAYER_MISSING: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PERSISTED_PLAYER_NOT_AN_OBJECT: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); PERSISTED_PLAYER_OVER_LIMIT: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); AI_PROMPT_RESPONSE_NOT_DEFINED: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); AI_PROMPT_REQUEST_PARAM_WRONG_FORMAT: { logInfo: LogInfo; } & ({ devUIMessage?: string | ((data: any) => string) | undefined; consoleMessage?: string | ((data: any) => string) | undefined; printExtraDataInDevUI?: boolean | undefined; devUIErrorTitle?: string | undefined; } | { devUIUnexpected: true; }); }; type GameOverResult = "WON" | "LOST" | "TIE" | number; type GameOverOptions = { delayPopUp?: boolean; minimizePopUp?: boolean; } & ({ players: { [playerId: PlayerId]: GameOverResult; }; everyone?: never; } | { players?: never; everyone: GameOverResult; }); type GameOverGameEnded = { reason: "gameEnded"; options: GameOverOptions; }; type GameOverPlayerLeft = { reason: "playerLeft"; }; type GameOverMinPlayers = { reason: "minPlayers"; }; type GameOverError = { reason: "err"; err?: { message: ServerErrorMessage; data?: object; }; }; type GameOverContext = (GameOverMinPlayers | GameOverPlayerLeft | GameOverGameEnded | GameOverError) & { players: Players; }; type ContextWithGameState<Context, GameState, PersistedData> = Context & { game: PersistedData extends false ? GameState : GameStateWithPersisted<GameState, PersistedData>; }; type EventContext = { allPlayerIds: PlayerId[]; }; type UpdateContext = { allPlayerIds: PlayerId[]; }; type ActionContext = { playerId: PlayerId; allPlayerIds: PlayerId[]; }; type InitLogicAIResponse<GameState, PersistedData> = (responseData: AIPromptResponse, eventContext: ContextWithGameState<EventContext, GameState, PersistedData>) => void; type InitLogicEvent<GameState, PersistedData> = (playerId: PlayerId, eventContext: ContextWithGameState<EventContext, GameState, PersistedData>) => void; type InitLogicEvents<GameState, PersistedData> = { playerJoined?: InitLogicEvent<GameState, PersistedData>; playerLeft?: InitLogicEvent<GameState, PersistedData>; }; type InitLogicUpdate<GameState, PersistedData> = (updateContext: ContextWithGameState<UpdateContext, GameState, PersistedData>) => void; type InitLogicActions<GameState, GameActions extends UntypedInitLogicActions, PersistedData> = { [key in keyof GameActions]: (params: Parameters<GameActions[key]>[0], actionContext: ContextWithGameState<ActionContext, GameState, PersistedData>) => void; }; type InitLogicParams<GameState, GameActions extends UntypedInitLogicActions, PersistedData> = { minPlayers: number; maxPlayers: number; landscape?: boolean; updatesPerSecond?: number; setup: (allPlayerIds: PlayerId[], context: PersistedData extends false ? undefined : { game: { persisted: PersistedPlayers<PersistedData>; }; }) => GameState; actions: InitLogicActions<GameState, GameActions, PersistedData>; events?: InitLogicEvents<GameState, PersistedData>; update?: InitLogicUpdate<GameState, PersistedData>; inputDelay?: number; reactive?: boolean; ai?: { promptResponse: InitLogicAIResponse<GameState, PersistedData>; }; } & (PersistedData extends false ? { persistPlayerData?: false; } : { persistPlayerData: true; }); type SharedSdk<GameState, GameActions extends UntypedInitLogicActions, PersistedData> = { initLogic: (params: InitLogicParams<GameState, GameActions, PersistedData>) => void; invalidAction: () => Error; gameOver: (options?: GameOverOptions) => void; /** @deprecated, use gameTime() */ gameTimeInSeconds: () => number; gameTime: () => number; worldTime: () => number; ai: { promptRequest: AIPromptRequestFunction; }; }; type LogicRunnerContext = { serverStartedAt: number; randomSeed: RandomSeed; msPerTick: number; logicTick: number; }; type LogicRunnerResult<T> = { error: "ROOM_GAME_STATE_MISSING"; } | { data: T; aiPromptRequest: AIPromptRequest | null; }; type LogicRunnerGameContext = { gameOver: GameOverContext | null; }; type LogicRunnerReturnContext = { gameContext: LogicRunnerGameContext; stateHash?: number; }; type LogicRunnerAction = (params: { roomId: number; logicContext: LogicRunnerContext; params: any; actionContext: ActionContext; calculateStateHash: boolean; }) => LogicRunnerResult<LogicRunnerReturnContext | false>; type LogicRunnerBindings = { getConfig: () => GameConfig; runSetup: (params: { roomId: number; logicContext: LogicRunnerContext; playerIds: PlayerId[]; calculateStateHash: boolean; persistedPlayers: PersistedPlayers<UntypedPersistedData> | null; }) => LogicRunnerResult<{ gameState: UntypedGameStateWithPersisted; stateHash?: number; }>; runAction: (action: string, ...args: Parameters<LogicRunnerAction>) => ReturnType<LogicRunnerAction>; runUpdate: (params: { roomId: number; logicContext: LogicRunnerContext; updateContext: UpdateContext; }) => LogicRunnerResult<LogicRunnerReturnContext>; runPlayerJoinedEvent: (params: { roomId: number; logicContext: LogicRunnerContext; playerId: PlayerId; eventContext: EventContext; persistedPlayerState: UntypedPersistedData | null; calculateStateHash: boolean; }) => LogicRunnerResult<LogicRunnerReturnContext>; runPlayerLeftEvent: (params: { roomId: number; logicContext: LogicRunnerContext; playerId: PlayerId; eventContext: EventContext; calculateStateHash: boolean; }) => LogicRunnerResult<LogicRunnerReturnContext & { persistedPlayers: PersistedPlayers<UntypedPersistedData> | null; }>; runAIPromptResponseEvent: (params: { roomId: number; logicContext: LogicRunnerContext; aiPromptResponse: AIPromptResponse; eventContext: EventContext; calculateStateHash: boolean; }) => LogicRunnerResult<LogicRunnerReturnContext>; getPersistedData: (roomId: number, playerIds: PlayerId[]) => LogicRunnerResult<{ persistedPlayers: PersistedPlayers<UntypedPersistedData>; }>; state: { aiPromptRequest: AIPromptRequest | null; gameOverContext: GameOverContext | null; }; context: LogicRunnerContext; initParams: InitLogicParams<UntypedGameState, UntypedInitLogicActions, false>; gameConfig: GameConfig; rehydrate: (roomId: number, gameState: UntypedGameStateWithPersisted) => void; getActionNames: () => string[]; getGameState: (roomId: number, calculateStateHash: boolean) => LogicRunnerResult<{ gameState: UntypedGameStateWithPersisted; stateHash?: number; }>; cleanup: (roomId: number) => void; }; type SdkProtocolVersion = number; type SdkMessageCodec = { encodeGameToServer(msg: GameToServer<UntypedInitLogicActions>, compress: boolean): string; encodeServerToGame(msg: ServerToGame<UntypedGameStateWithPersisted, UntypedInitLogicActions>, compress: boolean): string; decodeGameToServer(msg: string, logger: MsgLogger | null): GameToServer<UntypedInitLogicActions> | undefined; decodeServerToGame(msg: string, logger: MsgLogger | null): ServerToGame<UntypedGameStateWithPersisted, UntypedInitLogicActions> | undefined; }; type Only<T, U> = { [P in keyof T]: T[P]; } & { [P in keyof U]?: never; }; type Either<T, U> = Only<T, U> | Only<U, T>; type TimelineEntryStart = { type: "START"; serverSeed: number; initialPlayers: Players; stateHash: number; persisted: PersistedPlayers<UntypedPersistedData> | null; serverStartedAt: number; }; type TimelineEntryEnd = { type: "END"; gameState: UntypedGameStateWithPersisted | string; stateHash: number; reason: GameOverContext["reason"] | "stop"; }; type TimelineEntryWithSuccess<T> = T & ({ success: false; } | { success: true; stateHash: number; }); type TimelineEntryWithoutOrder = { logicTick: number; } & (TimelineEntryStart | TimelineEntryEnd | TimelineEntryWithSuccess<{ type: "ACTION"; playerId: PlayerId; action: string; params: any; randomSeed: number; }> | TimelineEntryWithSuccess<{ type: "AI_PROMPT_RESPONSE"; aiPromptResponse: AIPromptResponse; }> | TimelineEntryWithSuccess<{ type: "PLAYER_JOINED"; player: Player; persisted: UntypedPersistedData | null; }> | TimelineEntryWithSuccess<{ type: "PLAYER_LEFT"; playerId: PlayerId; }>); type TimelineEntry = TimelineEntryWithoutOrder & { order: number; }; type PlayersRandomState = Record<PlayerId, { seed: RandomSeed; actionCount: number; }>; type GameContext = { readonly gameOver: GameOverContext | null; orderNumber: number; sessionId: SessionId; gameId: GameId; serverStartedAt: number; }; type ServerSerializationData<GameStateWithPersisted> = { game: GameStateWithPersisted; } & ServerState; type ServerState = { context: GameContext; random: PlayersRandomState; gameTime: number; updateCount: number; }; type UpdateLoopContext = { logicTick: number; }; type RunGameLogic = { getConfig: LogicRunnerBindings["getConfig"]; getActionNames: (msgLogger: MsgLogger, ...args: Parameters<LogicRunnerBindings["getActionNames"]>) => Promise<ReturnType<LogicRunnerBindings["getActionNames"]>>; getGameState: (msgLogger: MsgLogger, ...args: Parameters<LogicRunnerBindings["getGameState"]>) => Promise<ReturnType<LogicRunnerBindings["getGameState"]>>; getPersistedData: (msgLogger: MsgLogger, ...args: Parameters<LogicRunnerBindings["getPersistedData"]>) => Promise<ReturnType<LogicRunnerBindings["getPersistedData"]>>; runSetup: (msgLogger: MsgLogger, ...args: Parameters<LogicRunnerBindings["runSetup"]>) => Promise<ReturnType<LogicRunnerBindings["runSetup"]>>; runPlayerJoinedEvent: (msgLogger: MsgLogger, ...args: Parameters<LogicRunnerBindings["runPlayerJoinedEvent"]>) => Promise<ReturnType<LogicRunnerBindings["runPlayerJoinedEvent"]>>; runPlayerLeftEvent: (msgLogger: MsgLogger, ...args: Parameters<LogicRunnerBindings["runPlayerLeftEvent"]>) => Promise<ReturnType<LogicRunnerBindings["runPlayerLeftEvent"]>>; runAIPromptResponseEvent: (msgLogger: MsgLogger, ...args: Parameters<LogicRunnerBindings["runAIPromptResponseEvent"]>) => Promise<ReturnType<LogicRunnerBindings["runAIPromptResponseEvent"]>>; runAction: (msgLogger: MsgLogger, ...args: Parameters<LogicRunnerBindings["runAction"]>) => Promise<ReturnType<LogicRunnerBindings["runAction"]>>; runUpdate: (msgLogger: MsgLogger, ...args: Parameters<LogicRunnerBindings["runUpdate"]>) => Promise<ReturnType<LogicRunnerBindings["runUpdate"]>>; rehydrate: (msgLogger: MsgLogger, ...args: Parameters<LogicRunnerBindings["rehydrate"]>) => Promise<ReturnType<LogicRunnerBindings["rehydrate"]>>; cleanup: (msgLogger: MsgLogger, ...args: Parameters<LogicRunnerBindings["cleanup"]>) => Promise<ReturnType<LogicRunnerBindings["cleanup"]>>; }; type GameServer<GameState, PersistedData> = { onMsg: (msgLogger: MsgLogger, userId: UserId, msg: string, info: { serverPreprocessingDurationInMs: number; }) => Promise<void>; onPlayerJoined: (msgLogger: MsgLogger, playerId: PlayerId, persistedUserData: PersistedData) => Promise<void>; onPlayerLeft: (msgLogger: MsgLogger, playerId: PlayerId) => Promise<PersistedData | null>; getDataForSerialization: (msgLogger: MsgLogger) => Promise<ServerSerializationData<GameStateWithPersisted<GameState, PersistedData>>>; getConfig: () => GameConfig; getSessionId: () => SessionId; getGameId: () => GameId; getPersistedUsers: (msgLogger: MsgLogger, userIds?: UserId[]) => Promise<PersistedUsers<UntypedPersistedData>>; isGameOver: () => boolean; onUpdateLoop: (msgLogger: MsgLogger, updateLoopContext: UpdateLoopContext) => Promise<void>; onAIPromptResponse: (msgLogger: MsgLogger, responseData: ({ success: true; } & AIPromptResponse) | { success: false; requestId: string; }) => Promise<void>; cleanup: (msgLogger: MsgLogger) => Promise<PersistedUsers<UntypedPersistedData> | null>; getCodec: () => SdkMessageCodec; }; type NetworkServer = { getUsers: () => Users; broadcastMsg: (msgLogger: MsgLogger, msg: string) => void; sendMsg: (msgLogger: MsgLogger, userId: UserId, msg: string) => void; queueUpdateLoop: (updateLoopContext: UpdateLoopContext) => void; onGameOver: (msgLogger: MsgLogger, reason: GameOverContext["reason"], persistedUsers: PersistedUsers<UntypedPersistedData> | null) => void; onTimelineEntry?: (msgLogger: MsgLogger, timelineEntry: TimelineEntry) => void; getSeedForPlayerId?: (playerId: PlayerId) => number; onError: () => { numberOfImpactedUsers: number; }; onAIPromptRequest: (request: AIPromptRequest) => void; }; type CreateGameServerProps = { initialMsgLogger: MsgLogger; network: NetworkServer; logic: RunGameLogic; flags: { logServerClientGameTime?: boolean; logNetworkMsg?: boolean; logWrongTick?: boolean; logNetworkMsgSize?: boolean; sendInitialStateSync?: boolean; sendStateHash?: boolean; isPersistFeatureEnabled: boolean; }; params: { sessionId: string | null; roomId: number; gameId: GameId; serverSeed: RandomSeed; serverStartedAt: number; } & Either<{ persistedUsers: PersistedUsers<UntypedPersistedData>; }, { initialServerData: ServerSerializationData<UntypedGameStateWithPersisted>; }>; config: { logicTimeoutDuration?: number | false; allowedGameTimeDelay?: number; gameTimeUpdateEveryXTicks?: number; environment: Environment; sdkProtocolVersion: SdkProtocolVersion; }; }; type ServerToGameBase = { orderNumber: number; serverGameTime: number; logicTick: number; }; type OnChangeMsgAction<GameActions extends UntypedInitLogicActions> = { [Key in keyof GameActions]: { action: Key; playerId: PlayerId; params: Parameters<GameActions[Key]>[0]; }; }[keyof GameActions]; type ActionBase = { uuid: string; actionCount: number; sessionId: SessionId; randomSeed: RandomSeed; measureLatencyStart: number; }; type GameToServerAction<GameActions extends UntypedInitLogicActions> = OnChangeMsgAction<GameActions> & ActionBase & { clientGameTime: number; expectedLogicTick: number; }; type ServerToGameAction<GameActions extends UntypedInitLogicActions> = ServerToGameBase & OnChangeMsgAction<GameActions> & ActionBase & { stateHash: number | undefined; }; type ServerToGameGameTimeUpdate = ServerToGameBase & { event: "gameTimeUpdate"; params: { gameContext: GameContext; }; }; type ServerToGameLatencyEstimate = { event: "latencyEstimate"; measureLatencyStart: number; serverGameTime: number; }; type ServerToGameStopGameEvent = { event: "debugStopGame"; }; type ServerToGameStateSyncEvent<GameStateWithPersisted> = ServerToGameBase & { event: "stateSync"; params: { game: GameStateWithPersisted; gameContext: GameContext; players: Players; pastPlayerIds: PlayerId[]; yourPlayerSeed: RandomSeed | undefined; yourPlayerActionCount: number | undefined; yourPlayerId: PlayerId | undefined; serverSeed: RandomSeed; triggeredByUpdateLoop: boolean; measureLatencyStart?: number; latencyRttEstimate?: number; }; dictionary?: string[]; }; type OnChangePlayerJoinedEvent = { event: "playerJoined"; params: { playerId: PlayerId; }; }; type ServerToGamePlayerJoinedEvent = ServerToGameBase & OnChangePlayerJoinedEvent & { params: { playerId: PlayerId; gameContext: GameContext; players: Players; randomSeed: RandomSeed; stateHash: number | undefined; persistedPlayerState?: UntypedPersistedData; }; }; type ServerToGameAIPromptResponseEvent = ServerToGameBase & { event: "aiPromptResponse"; params: { aiPromptResponse: AIPromptResponse; gameContext: GameContext; players: Players; randomSeed: RandomSeed; stateHash: number | undefined; }; }; type OnChangePlayerLeftEvent = { event: "playerLeft"; params: { playerId: PlayerId; }; }; type ServerToGamePlayerLeftEvent = ServerToGameBase & OnChangePlayerLeftEvent & { params: { playerId: PlayerId; gameContext: GameContext; players: Players; randomSeed: RandomSeed; stateHash: number | undefined; }; }; type ServerToGameOnChangeTriggeringEvent<GameStateWithPersisted> = ServerToGameStateSyncEvent<GameStateWithPersisted> | ServerToGamePlayerJoinedEvent | ServerToGamePlayerLeftEvent | ServerToGameAIPromptResponseEvent; type ServerToGameEvent<GameStateWithPersisted> = ServerToGameOnChangeTriggeringEvent<GameStateWithPersisted> | ServerToGameGameTimeUpdate | ServerToGameLatencyEstimate | ServerToGameStopGameEvent; type ServerToGame<GameStateWithPersisted, GameActions extends UntypedInitLogicActions> = ServerToGameAction<GameActions> | ServerToGameEvent<GameStateWithPersisted>; type GameToServer<GameActions extends UntypedInitLogicActions> = GameToServerAction<GameActions> | GameToServerStateSyncRequest | { type: "MEASURE_LATENCY"; measureLatencyStart: number; } | { type: "DEBUG_TIMELINE"; data: any; }; type GameToServerStateSyncRequest = { type: "REQUEST_STATE_SYNC"; measureLatencyStart: number; gameId: number | null; }; declare function isNewUserSpectator(users: Users, gameConfig: GameConfig, isGameOver: boolean): boolean; declare function canSwitchSpectatorToPlayer(users: Users, gameConfig: GameConfig): boolean; declare function createSdkForLogicRunner(environment: Environment): { publicSdk: SharedSdk<UntypedGameState, UntypedInitLogicActions, false>; getLogicRunnerBindings: () => LogicRunnerBindings | undefined; }; declare function createGameServer({ initialMsgLogger, params: { gameId, roomId, sessionId, initialServerData, serverSeed, persistedUsers, serverStartedAt, }, flags: { sendStateHash: sendStateHashFlag, logWrongTick, logNetworkMsg, logNetworkMsgSize, sendInitialStateSync, isPersistFeatureEnabled, }, config: { logicTimeoutDuration, allowedGameTimeDelay, gameTimeUpdateEveryXTicks, environment, sdkProtocolVersion, }, network, logic, }: CreateGameServerProps): Promise<GameServer<UntypedGameState, UntypedPersistedData>>; export { CreateGameServerProps, GameConfig, GameId, GameOverContext, GameServer, LogicRunnerBindings, MsgLogger, PersistedUsers, Player, RunGameLogic, ServerSerializationData, SessionId, UntypedGameState, UntypedGameStateWithPersisted, UntypedPersistedData, User, canSwitchSpectatorToPlayer, createGameServer, createSdkForLogicRunner, generateId, isNewUserSpectator };