@babylonjs-toolkit/server 0.0.0-stage → 9.35.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.
Files changed (236) hide show
  1. package/CUSTOM.md +1690 -0
  2. package/DEPLOY.md +2012 -0
  3. package/README.md +1081 -2
  4. package/lib/AbuseLimits.d.ts +64 -0
  5. package/lib/AbuseLimits.js +121 -0
  6. package/lib/Authentication.d.ts +86 -0
  7. package/lib/Authentication.js +272 -0
  8. package/lib/BootSessionOwner.d.ts +86 -0
  9. package/lib/BootSessionOwner.js +116 -0
  10. package/lib/ColyseusLoggerAdapter.d.ts +32 -0
  11. package/lib/ColyseusLoggerAdapter.js +73 -0
  12. package/lib/DedicatedSceneRegistry.d.ts +52 -0
  13. package/lib/DedicatedSceneRegistry.js +74 -0
  14. package/lib/DedicatedSession.d.ts +152 -0
  15. package/lib/DedicatedSession.js +173 -0
  16. package/lib/DualTransport.d.ts +112 -0
  17. package/lib/DualTransport.js +197 -0
  18. package/lib/GameServer.d.ts +64 -0
  19. package/lib/GameServer.js +647 -0
  20. package/lib/GameServerConfig.d.ts +387 -0
  21. package/lib/GameServerConfig.js +1059 -0
  22. package/lib/GameServerLobbyRoom.d.ts +33 -0
  23. package/lib/GameServerLobbyRoom.js +56 -0
  24. package/lib/GameServerLogger.d.ts +111 -0
  25. package/lib/GameServerLogger.js +190 -0
  26. package/lib/GameServerMetrics.d.ts +158 -0
  27. package/lib/GameServerMetrics.js +276 -0
  28. package/lib/GameServerState.d.ts +164 -0
  29. package/lib/GameServerState.js +26 -0
  30. package/lib/HeadlessRuntime.d.ts +316 -0
  31. package/lib/HeadlessRuntime.js +380 -0
  32. package/lib/JoinGate.d.ts +34 -0
  33. package/lib/JoinGate.js +221 -0
  34. package/lib/NetworkAddresses.d.ts +33 -0
  35. package/lib/NetworkAddresses.js +90 -0
  36. package/lib/PlayerTokens.d.ts +17 -0
  37. package/lib/PlayerTokens.js +24 -0
  38. package/lib/RoomServerTransport.d.ts +73 -0
  39. package/lib/RoomServerTransport.js +90 -0
  40. package/lib/ServerEndpoints.d.ts +133 -0
  41. package/lib/ServerEndpoints.js +247 -0
  42. package/lib/ServerInit.d.ts +28 -0
  43. package/lib/ServerInit.js +113 -0
  44. package/lib/SessionRoom.d.ts +391 -0
  45. package/lib/SessionRoom.js +930 -0
  46. package/lib/TlsCertificates.d.ts +35 -0
  47. package/lib/TlsCertificates.js +130 -0
  48. package/lib/admin/AccountRoutes.d.ts +8 -0
  49. package/lib/admin/AccountRoutes.js +502 -0
  50. package/lib/admin/AdminAccounts.d.ts +329 -0
  51. package/lib/admin/AdminAccounts.js +607 -0
  52. package/lib/admin/AdminApiRouter.d.ts +202 -0
  53. package/lib/admin/AdminApiRouter.js +465 -0
  54. package/lib/admin/AdminApiTypes.d.ts +1782 -0
  55. package/lib/admin/AdminApiTypes.js +4 -0
  56. package/lib/admin/AdminAudit.d.ts +113 -0
  57. package/lib/admin/AdminAudit.js +266 -0
  58. package/lib/admin/AdminCli.d.ts +7 -0
  59. package/lib/admin/AdminCli.js +351 -0
  60. package/lib/admin/AdminClock.d.ts +51 -0
  61. package/lib/admin/AdminClock.js +10 -0
  62. package/lib/admin/AdminConsole.d.ts +39 -0
  63. package/lib/admin/AdminConsole.js +325 -0
  64. package/lib/admin/AdminConstants.d.ts +147 -0
  65. package/lib/admin/AdminConstants.js +167 -0
  66. package/lib/admin/AdminCrypto.d.ts +19 -0
  67. package/lib/admin/AdminCrypto.js +29 -0
  68. package/lib/admin/AdminExtensionsHost.d.ts +176 -0
  69. package/lib/admin/AdminExtensionsHost.js +307 -0
  70. package/lib/admin/AdminPasswords.d.ts +33 -0
  71. package/lib/admin/AdminPasswords.js +92 -0
  72. package/lib/admin/AdminPermissions.d.ts +28 -0
  73. package/lib/admin/AdminPermissions.js +74 -0
  74. package/lib/admin/AdminRecords.d.ts +196 -0
  75. package/lib/admin/AdminRecords.js +3 -0
  76. package/lib/admin/AdminRequestBodies.d.ts +47 -0
  77. package/lib/admin/AdminRequestBodies.js +84 -0
  78. package/lib/admin/AdminRequestGate.d.ts +38 -0
  79. package/lib/admin/AdminRequestGate.js +59 -0
  80. package/lib/admin/AdminResponses.d.ts +103 -0
  81. package/lib/admin/AdminResponses.js +164 -0
  82. package/lib/admin/AdminServices.d.ts +99 -0
  83. package/lib/admin/AdminServices.js +4 -0
  84. package/lib/admin/AdminStaticFiles.d.ts +29 -0
  85. package/lib/admin/AdminStaticFiles.js +97 -0
  86. package/lib/admin/AdminStore.d.ts +152 -0
  87. package/lib/admin/AdminStore.js +46 -0
  88. package/lib/admin/AlertChannels.d.ts +43 -0
  89. package/lib/admin/AlertChannels.js +120 -0
  90. package/lib/admin/AlertEngine.d.ts +231 -0
  91. package/lib/admin/AlertEngine.js +681 -0
  92. package/lib/admin/AlertRoutes.d.ts +8 -0
  93. package/lib/admin/AlertRoutes.js +180 -0
  94. package/lib/admin/ApiKeyRoutes.d.ts +8 -0
  95. package/lib/admin/ApiKeyRoutes.js +53 -0
  96. package/lib/admin/ApiKeys.d.ts +63 -0
  97. package/lib/admin/ApiKeys.js +167 -0
  98. package/lib/admin/AuditRoutes.d.ts +8 -0
  99. package/lib/admin/AuditRoutes.js +106 -0
  100. package/lib/admin/AuthToolRoutes.d.ts +13 -0
  101. package/lib/admin/AuthToolRoutes.js +164 -0
  102. package/lib/admin/BanList.d.ts +87 -0
  103. package/lib/admin/BanList.js +152 -0
  104. package/lib/admin/CborDecoder.d.ts +18 -0
  105. package/lib/admin/CborDecoder.js +201 -0
  106. package/lib/admin/ColyseusCloudClient.d.ts +313 -0
  107. package/lib/admin/ColyseusCloudClient.js +272 -0
  108. package/lib/admin/ColyseusCloudRoutes.d.ts +8 -0
  109. package/lib/admin/ColyseusCloudRoutes.js +91 -0
  110. package/lib/admin/ColyseusCloudService.d.ts +180 -0
  111. package/lib/admin/ColyseusCloudService.js +476 -0
  112. package/lib/admin/ColyseusCloudSettings.d.ts +16 -0
  113. package/lib/admin/ColyseusCloudSettings.js +29 -0
  114. package/lib/admin/ColyseusCloudViews.d.ts +105 -0
  115. package/lib/admin/ColyseusCloudViews.js +371 -0
  116. package/lib/admin/CommonPasswords.d.ts +6 -0
  117. package/lib/admin/CommonPasswords.js +19 -0
  118. package/lib/admin/ConfigOverrides.d.ts +174 -0
  119. package/lib/admin/ConfigOverrides.js +406 -0
  120. package/lib/admin/ConfigRoutes.d.ts +8 -0
  121. package/lib/admin/ConfigRoutes.js +91 -0
  122. package/lib/admin/ConsoleSessions.d.ts +112 -0
  123. package/lib/admin/ConsoleSessions.js +201 -0
  124. package/lib/admin/DedicatedRoutes.d.ts +21 -0
  125. package/lib/admin/DedicatedRoutes.js +254 -0
  126. package/lib/admin/ExtensionRoutes.d.ts +8 -0
  127. package/lib/admin/ExtensionRoutes.js +145 -0
  128. package/lib/admin/FileAdminStore.d.ts +157 -0
  129. package/lib/admin/FileAdminStore.js +349 -0
  130. package/lib/admin/FleetDirectory.d.ts +323 -0
  131. package/lib/admin/FleetDirectory.js +489 -0
  132. package/lib/admin/FleetLeader.d.ts +43 -0
  133. package/lib/admin/FleetLeader.js +89 -0
  134. package/lib/admin/FleetRoutes.d.ts +55 -0
  135. package/lib/admin/FleetRoutes.js +465 -0
  136. package/lib/admin/HealthWarnings.d.ts +10 -0
  137. package/lib/admin/HealthWarnings.js +95 -0
  138. package/lib/admin/LeaderboardRoutes.d.ts +8 -0
  139. package/lib/admin/LeaderboardRoutes.js +569 -0
  140. package/lib/admin/LogBuffer.d.ts +60 -0
  141. package/lib/admin/LogBuffer.js +92 -0
  142. package/lib/admin/LogRedaction.d.ts +15 -0
  143. package/lib/admin/LogRedaction.js +72 -0
  144. package/lib/admin/LogRoutes.d.ts +45 -0
  145. package/lib/admin/LogRoutes.js +307 -0
  146. package/lib/admin/MaintenanceMode.d.ts +41 -0
  147. package/lib/admin/MaintenanceMode.js +74 -0
  148. package/lib/admin/MaintenanceWindows.d.ts +91 -0
  149. package/lib/admin/MaintenanceWindows.js +207 -0
  150. package/lib/admin/MetricsRoutes.d.ts +8 -0
  151. package/lib/admin/MetricsRoutes.js +209 -0
  152. package/lib/admin/MetricsSampler.d.ts +124 -0
  153. package/lib/admin/MetricsSampler.js +211 -0
  154. package/lib/admin/OneTimeCodes.d.ts +60 -0
  155. package/lib/admin/OneTimeCodes.js +162 -0
  156. package/lib/admin/OpenIdConnect.d.ts +146 -0
  157. package/lib/admin/OpenIdConnect.js +335 -0
  158. package/lib/admin/Passkeys.d.ts +130 -0
  159. package/lib/admin/Passkeys.js +432 -0
  160. package/lib/admin/PlayerRoutes.d.ts +20 -0
  161. package/lib/admin/PlayerRoutes.js +676 -0
  162. package/lib/admin/RedisAdminStore.d.ts +114 -0
  163. package/lib/admin/RedisAdminStore.js +258 -0
  164. package/lib/admin/RolloutCoordinator.d.ts +99 -0
  165. package/lib/admin/RolloutCoordinator.js +321 -0
  166. package/lib/admin/ServerEvents.d.ts +57 -0
  167. package/lib/admin/ServerEvents.js +89 -0
  168. package/lib/admin/SessionRoutes.d.ts +113 -0
  169. package/lib/admin/SessionRoutes.js +386 -0
  170. package/lib/admin/UserRoutes.d.ts +8 -0
  171. package/lib/admin/UserRoutes.js +214 -0
  172. package/lib/cli.d.ts +2 -0
  173. package/lib/cli.js +221 -0
  174. package/lib/console/assets/index-CI5N7c-T.js +21 -0
  175. package/lib/console/assets/index-DPitvzLp.css +1 -0
  176. package/lib/console/favicon.svg +1 -0
  177. package/lib/console/index.html +16 -0
  178. package/lib/discord/DiscordOAuth.d.ts +57 -0
  179. package/lib/discord/DiscordOAuth.js +127 -0
  180. package/lib/discord/DiscordSessions.d.ts +79 -0
  181. package/lib/discord/DiscordSessions.js +135 -0
  182. package/lib/discord/DiscordSignInConstants.d.ts +54 -0
  183. package/lib/discord/DiscordSignInConstants.js +55 -0
  184. package/lib/discord/DiscordSignInRoutes.d.ts +51 -0
  185. package/lib/discord/DiscordSignInRoutes.js +359 -0
  186. package/lib/index.d.ts +24 -0
  187. package/lib/index.js +18 -0
  188. package/lib/leaderboards/FileLeaderboardRankStore.d.ts +293 -0
  189. package/lib/leaderboards/FileLeaderboardRankStore.js +808 -0
  190. package/lib/leaderboards/LeaderboardConstants.d.ts +63 -0
  191. package/lib/leaderboards/LeaderboardConstants.js +70 -0
  192. package/lib/leaderboards/LeaderboardError.d.ts +15 -0
  193. package/lib/leaderboards/LeaderboardError.js +20 -0
  194. package/lib/leaderboards/LeaderboardIdentity.d.ts +44 -0
  195. package/lib/leaderboards/LeaderboardIdentity.js +72 -0
  196. package/lib/leaderboards/LeaderboardPublicApi.d.ts +17 -0
  197. package/lib/leaderboards/LeaderboardPublicApi.js +389 -0
  198. package/lib/leaderboards/LeaderboardRankStore.d.ts +296 -0
  199. package/lib/leaderboards/LeaderboardRankStore.js +18 -0
  200. package/lib/leaderboards/LeaderboardRules.d.ts +122 -0
  201. package/lib/leaderboards/LeaderboardRules.js +472 -0
  202. package/lib/leaderboards/LeaderboardScheduler.d.ts +43 -0
  203. package/lib/leaderboards/LeaderboardScheduler.js +103 -0
  204. package/lib/leaderboards/LeaderboardService.d.ts +669 -0
  205. package/lib/leaderboards/LeaderboardService.js +1667 -0
  206. package/lib/leaderboards/LeaderboardTransfer.d.ts +35 -0
  207. package/lib/leaderboards/LeaderboardTransfer.js +580 -0
  208. package/lib/leaderboards/RedisLeaderboardRankStore.d.ts +282 -0
  209. package/lib/leaderboards/RedisLeaderboardRankStore.js +691 -0
  210. package/package.json +64 -4
  211. package/templates/init/Caddyfile +6 -0
  212. package/templates/init/DEPLOY.md +233 -0
  213. package/templates/init/Dockerfile +12 -0
  214. package/templates/init/app.json +21 -0
  215. package/templates/init/aws/README.md +118 -0
  216. package/templates/init/aws/ecs-fargate-alb.yml +207 -0
  217. package/templates/init/aws/ecs-fargate-nlb-quic.yml +210 -0
  218. package/templates/init/babylon-game-server.config.mjs +158 -0
  219. package/templates/init/colyseus-cloud/README.md +133 -0
  220. package/templates/init/colyseus-cloud/babylon-game-server.config.mjs +36 -0
  221. package/templates/init/colyseus-cloud/ecosystem.config.cjs +35 -0
  222. package/templates/init/colyseus-cloud/gitignore +6 -0
  223. package/templates/init/colyseus-cloud/package.json +15 -0
  224. package/templates/init/digitalocean-app.yaml +30 -0
  225. package/templates/init/docker-compose.full.yml +45 -0
  226. package/templates/init/docker-compose.websocket.yml +41 -0
  227. package/templates/init/fly.toml +56 -0
  228. package/templates/init/heroku.yml +11 -0
  229. package/templates/init/kubernetes/deployment.yaml +71 -0
  230. package/templates/init/kubernetes/redis.yaml +73 -0
  231. package/templates/init/kubernetes/service.yaml +24 -0
  232. package/templates/init/monitoring/grafana-dashboard.json +539 -0
  233. package/templates/init/monitoring/prometheus-alerts.yml +51 -0
  234. package/templates/init/monitoring/prometheus-scrape.yml +17 -0
  235. package/templates/init/railway.json +13 -0
  236. package/templates/init/render.yaml +19 -0
@@ -0,0 +1,316 @@
1
+ import type { AuthIdentity } from "./Authentication.js";
2
+ /** A session's public description, as TOOLKIT.SessionInfo. */
3
+ export interface FusionSessionInfo {
4
+ /** Session name players join by. */
5
+ name: string;
6
+ /** True when new players may join. */
7
+ isOpen: boolean;
8
+ /** True when the session is listed in the lobby. */
9
+ isVisible: boolean;
10
+ /** Players connected now. */
11
+ playerCount: number;
12
+ /** Most players the session accepts. */
13
+ maxPlayers: number;
14
+ /** Custom session properties. */
15
+ properties: Record<string, string | number | boolean>;
16
+ }
17
+ /** What a client sends when it joins, as TOOLKIT.NetworkConnectRequest (the join options of a session room). */
18
+ export interface FusionConnectRequest {
19
+ /** Session to create or join. */
20
+ sessionName: string;
21
+ /** The joiner's TOOLKIT.GameMode value. */
22
+ gameMode: number;
23
+ /** Most players. */
24
+ playerCount: number;
25
+ /** True when new players may join. */
26
+ isOpen: boolean;
27
+ /** True when the session is listed in the lobby. */
28
+ isVisible: boolean;
29
+ /** Custom session properties. */
30
+ sessionProperties: Record<string, string | number | boolean>;
31
+ /** The joiner's tick rate. */
32
+ tickRate: number;
33
+ /** The joiner's prefab table hash. */
34
+ prefabTableHash: number;
35
+ /** Bytes the host sees in onConnectRequest, as base64. */
36
+ connectionTokenBase64: string;
37
+ /** The player id to resume after a drop, or 0 for a new player. */
38
+ reconnectPlayerId: number;
39
+ /** True when a runner restarts after a host migration: it resumes reconnectPlayerId (D31). */
40
+ hostMigration?: boolean;
41
+ /** The joiner's TOOLKIT.NETWORK_PROTOCOL_VERSION; missing from runtimes that predate it (counts as 0, D5). */
42
+ protocolVersion?: number;
43
+ /** The identity the server verified from the join's token; the room overwrites any client-sent value (D12). */
44
+ authIdentity?: AuthIdentity | null;
45
+ }
46
+ /** The session's answer to a join, as TOOLKIT.NetworkWelcome (the fields the room reads). */
47
+ export interface FusionWelcome {
48
+ /** The joiner's player id. */
49
+ playerId: number;
50
+ }
51
+ /** Where the session logic sends its output, as TOOLKIT.FusionSessionOutputs. */
52
+ export interface FusionSessionOutputs {
53
+ /**
54
+ * Delivers a frame to one client.
55
+ * @param clientKey The receiving client's session id.
56
+ * @param sourcePlayerId The sending player (0 = the session).
57
+ * @param frame The frame.
58
+ * @param channel The TOOLKIT.RpcChannel it travels on (default Reliable); Unreliable may go as a datagram (D7).
59
+ */
60
+ sendFrame(clientKey: string, sourcePlayerId: number, frame: Uint8Array, channel?: number): void;
61
+ /**
62
+ * Delivers a control message to one client.
63
+ * @param clientKey The receiving client's session id.
64
+ * @param name The control message name.
65
+ * @param payload The JSON-able payload.
66
+ */
67
+ sendControl(clientKey: string, name: string, payload: object): void;
68
+ /**
69
+ * Publishes the session description (lobby listing).
70
+ * @param session The description.
71
+ */
72
+ setSessionMetadata(session: FusionSessionInfo): void;
73
+ /**
74
+ * Locks or unlocks the session against new joins.
75
+ * @param locked True when full or closed.
76
+ */
77
+ lockSession(locked: boolean): void;
78
+ /** @returns The session clock, in milliseconds. */
79
+ nowMilliseconds(): number;
80
+ }
81
+ /** The rules of one networked session, as TOOLKIT.FusionSessionLogic (the members the room calls). */
82
+ export interface FusionSessionLogicApi {
83
+ /**
84
+ * Admits a joining client.
85
+ * @throws Error named after the TOOLKIT.ShutdownReason that refuses the join.
86
+ */
87
+ join(clientKey: string, request: FusionConnectRequest): FusionWelcome;
88
+ /** Routes a client's envelope (route byte + uint16 target + frame) received on a TOOLKIT.RpcChannel (default Reliable, D7). */
89
+ receiveFrame(clientKey: string, payload: Uint8Array, channel?: number): void;
90
+ /** Applies a client's control message. */
91
+ receiveControl(clientKey: string, name: string, payload: object): void;
92
+ /** Expires reconnect holds. */
93
+ update(nowMilliseconds: number): void;
94
+ /** Holds a dropped client's slot for a reconnect. */
95
+ drop(clientKey: string): void;
96
+ /** Removes a client for good (during a host migration: holds its slot for the restarted runner). */
97
+ leave(clientKey: string): void;
98
+ /** True while a host migration waits for the elected host to rejoin (D31). */
99
+ readonly isMigratingHost: boolean;
100
+ /** The session's TOOLKIT.GameMode, or null before the first join. */
101
+ readonly gameMode: number | null;
102
+ /** Every player the session knows, connected or held for a reconnect (game-server-admin-console DR §6.6). */
103
+ readonly players: FusionSessionPlayer[];
104
+ /** The Shared-mode master client's player id, or 0 when there is none. */
105
+ readonly masterClientPlayerId: number;
106
+ /**
107
+ * Makes a dedicated server runner the session's authority (A17): it is player 0 and answers connect requests.
108
+ * @param endpoint The server runner's side of the session.
109
+ * @param request The server runner's connect request (session name, players, tick rate, prefab table hash).
110
+ * @returns The server runner's welcome.
111
+ */
112
+ attachDedicatedServer(endpoint: FusionSessionServerEndpoint, request: FusionConnectRequest): FusionWelcome;
113
+ /** Sends a frame from the dedicated server on a TOOLKIT.RpcChannel: ToPlayer to that client, any other route to every client. */
114
+ sendFromServer(route: number, targetPlayerId: number, frame: Uint8Array, channel?: number): void;
115
+ /** Sends a control message from the dedicated server to one player, or to everyone with target 0. */
116
+ sendControlFromServer(name: string, payload: object, targetPlayerId: number): void;
117
+ }
118
+ /** One player of a session, as TOOLKIT.FusionSessionClient. */
119
+ export interface FusionSessionPlayer {
120
+ /** The client's session id. */
121
+ clientKey: string;
122
+ /** The player id. */
123
+ playerId: number;
124
+ /** False while the player is held for a reconnect. */
125
+ connected: boolean;
126
+ /** True for the Host-mode host. */
127
+ isHost: boolean;
128
+ }
129
+ /** The dedicated runner's side of a session, as TOOLKIT.FusionSessionServerEndpoint (T13). */
130
+ export interface FusionSessionServerEndpoint {
131
+ /** Receives a frame a player sent to the server. */
132
+ receiveFrame(sourcePlayerId: number, frame: Uint8Array): void;
133
+ /** Receives a control message for the server. */
134
+ receiveControl(name: string, payload: object): void;
135
+ }
136
+ /** The Babylon Toolkit Networking members of the runtime's TOOLKIT namespace the server uses (built into the toolkit bundle). */
137
+ export interface NetworkingToolkitApi {
138
+ /** The session rules class (D10). */
139
+ FusionSessionLogic: new (outputs: FusionSessionOutputs) => FusionSessionLogicApi;
140
+ /** The wire codecs; the room prefixes room-to-client frames with their source player (D11). */
141
+ NetworkProtocol: {
142
+ prefixSource(sourcePlayerId: number, frame: Uint8Array): Uint8Array;
143
+ };
144
+ /** Bytes message type of client-to-room frames. */
145
+ FUSION_BYTES_TO_ROOM: number;
146
+ /** Bytes message type of room-to-client frames. */
147
+ FUSION_BYTES_FROM_ROOM: number;
148
+ /** Seconds a dropped player's slot is held for a reconnect. */
149
+ NETWORK_RECONNECT_GRACE_SECONDS: number;
150
+ /** Version of the wire format and session rules; client and server must match (D5). */
151
+ NETWORK_PROTOCOL_VERSION: number;
152
+ /** Message type of client-to-room frames on the unreliable channel (D7). */
153
+ FUSION_UNRELIABLE_TO_ROOM: number;
154
+ /** Message type of room-to-client frames on the unreliable channel (D7). */
155
+ FUSION_UNRELIABLE_FROM_ROOM: number;
156
+ /** Largest prefixed frame, in bytes, sent as a datagram (D7). */
157
+ NETWORK_MAX_UNRELIABLE_FRAME_BYTES: number;
158
+ /** Session property naming the dedicated scene a Client-mode join starts on demand (D19). */
159
+ NETWORK_DEDICATED_SCENE_PROPERTY: string;
160
+ /** The delivery channels, as TOOLKIT.RpcChannel. */
161
+ RpcChannel: {
162
+ Reliable: number;
163
+ Unreliable: number;
164
+ };
165
+ /** The shutdown reasons by name, as TOOLKIT.ShutdownReason. */
166
+ ShutdownReason: Record<string, number>;
167
+ /** The game modes the server checks, as TOOLKIT.GameMode (a TypeScript enum, so it also maps values to names). */
168
+ GameMode: {
169
+ Client: number;
170
+ Server: number;
171
+ Shared: number;
172
+ [value: number]: string;
173
+ };
174
+ /** Control message that ends the session for its receiver. */
175
+ FUSION_CONTROL_SHUTDOWN: string;
176
+ /** Control message of a notice from the server's operators (protocol 2, game-server-admin-console D13). */
177
+ FUSION_CONTROL_NOTICE: string;
178
+ }
179
+ /** The runtime globals the server shares with the browser build. */
180
+ export interface ToolkitGlobals {
181
+ /** The Babylon.js namespace (babylonjs, with loaders and GUI). */
182
+ BABYLON: object;
183
+ /** The toolkit namespace of the UMD bundle, with Babylon Toolkit Networking built in. A game's own classes are PROJECT's. */
184
+ TOOLKIT: NetworkingToolkitApi;
185
+ }
186
+ /**
187
+ * Loads the browser runtime into Node (D25): babylonjs, its loaders and GUI, then the toolkit UMD bundle, which publishes
188
+ * TOOLKIT (networking included) on globalThis. The session logic and protocol the server runs are therefore the same code as the
189
+ * browser's. Loads once; later calls return the same globals.
190
+ * @returns The BABYLON and TOOLKIT namespaces.
191
+ */
192
+ export declare function loadToolkitRuntime(): Promise<ToolkitGlobals>;
193
+ /**
194
+ * The loaded runtime, for code that runs after createGameServer has loaded it (rooms).
195
+ * @returns The runtime globals.
196
+ * @throws Error when loadToolkitRuntime has not completed.
197
+ */
198
+ export declare function getToolkitRuntime(): ToolkitGlobals;
199
+ /** The engine of a headless scene: a Babylon.js NullEngine. */
200
+ export interface HeadlessEngine {
201
+ /** The device limits the engine reports (a NullEngine invents them). */
202
+ getCaps(): {
203
+ maxTexturesImageUnits: number;
204
+ };
205
+ /** Calls the render function every frame (timer-driven in Node). */
206
+ runRenderLoop(renderFunction: () => void): void;
207
+ /** Stops every render loop. */
208
+ stopRenderLoop(): void;
209
+ /** Releases the engine and its scenes. */
210
+ dispose(): void;
211
+ }
212
+ /** A headless scene: a Babylon.js Scene on a NullEngine. */
213
+ export interface HeadlessScene {
214
+ /** The scene's cameras; Babylon renders a frame only with one. */
215
+ readonly cameras: object[];
216
+ /** Renders one frame (scripts, physics, the network runner's ticks; nothing is drawn). */
217
+ render(): void;
218
+ /** Resolves once the scene is ready. */
219
+ whenReadyAsync(): Promise<void>;
220
+ /** Releases the scene. */
221
+ dispose(): void;
222
+ }
223
+ /** A loaded headless scene and its engine. */
224
+ export interface HeadlessSceneHandle {
225
+ /** The NullEngine. */
226
+ engine: HeadlessEngine;
227
+ /** The scene, with its render loop running. */
228
+ scene: HeadlessScene;
229
+ }
230
+ /** A Babylon.js scene loader plugin, as the glTF loader exposes it to OnPluginActivatedObservable. */
231
+ interface HeadlessLoaderPlugin {
232
+ /** The plugin name ("gltf" for the glTF loader). */
233
+ name: string;
234
+ /** True to load no materials (and so no textures). */
235
+ skipMaterials?: boolean;
236
+ /** Maps every URL the loader fetches (buffers, images) before it is loaded. */
237
+ preprocessUrlAsync?: (url: string) => Promise<string>;
238
+ }
239
+ /** The parts of BABYLON.SceneLoader the headless runtime adapts. */
240
+ interface HeadlessSceneLoaderApi {
241
+ /** Notifies every activated loader plugin. */
242
+ OnPluginActivatedObservable: {
243
+ add(callback: (plugin: HeadlessLoaderPlugin) => void): unknown;
244
+ };
245
+ /** The scene loader's entry points, by name. */
246
+ [entryPoint: string]: unknown;
247
+ }
248
+ /** The parts of Babylon.js the headless runtime drives. */
249
+ interface HeadlessBabylonApi {
250
+ /** The engine class that renders nothing. */
251
+ NullEngine: new () => HeadlessEngine;
252
+ /** The camera class engine.html adds to a scene without a camera. */
253
+ FreeCamera: new (name: string, position: object, scene: HeadlessScene) => object;
254
+ /** The vector class. */
255
+ Vector3: new (x: number, y: number, z: number) => object;
256
+ /** Script loading, replaced by the Node script loader. */
257
+ Tools: {
258
+ LoadScriptAsync: (scriptUrl: string, scriptId?: string) => Promise<void>;
259
+ LoadScript: (scriptUrl: string, onSuccess?: () => void, onError?: (message?: string, exception?: unknown) => void, scriptId?: string) => void;
260
+ };
261
+ /** The scene loader. */
262
+ SceneLoader: HeadlessSceneLoaderApi;
263
+ }
264
+ /**
265
+ * Adds URL prefixes to the allow-list of the fetch helpers (D19). The first call turns the allow-list on: from then on
266
+ * only data: URLs and URLs under an allowed prefix load.
267
+ * @param prefixes The URL prefixes (scene roots and project scripts); none turns the allow-list on with only data: URLs.
268
+ */
269
+ export declare function allowScriptUrlPrefixes(prefixes: string[]): void;
270
+ /**
271
+ * Turns the allow-list off again (every URL allowed), as before any game server ran. createGameServer's close calls it.
272
+ */
273
+ export declare function resetScriptUrlAllowList(): void;
274
+ /**
275
+ * Whether the fetch helpers may load a URL (D19).
276
+ * @param url The URL.
277
+ * @returns True for a data: URL, for any URL while the allow-list is off, else when the URL starts with an allowed prefix.
278
+ */
279
+ export declare function isUrlAllowed(url: string): boolean;
280
+ /**
281
+ * The cache key of a script URL: its lower-cased file name, as the toolkit keys its project bundles (CanvasTools.ts).
282
+ * @param scriptUrl The script URL.
283
+ * @returns The key.
284
+ */
285
+ export declare function scriptCacheKey(scriptUrl: string): string;
286
+ /**
287
+ * Loads a script in Node, as Babylon's LoadScriptAsync does in a page (T13 step 2): fetches it and runs it in this context,
288
+ * once per file name; a file name already loaded resolves at once.
289
+ * @param scriptUrl The script URL.
290
+ * @returns Resolves once it ran.
291
+ * @throws Error when the server answers with an error status (the toolkit then warns that the bundle was not found), or
292
+ * when the URL is not on the dedicated allow-list (D19).
293
+ */
294
+ export declare function loadNodeScriptAsync(scriptUrl: string): Promise<void>;
295
+ /**
296
+ * Replaces Babylon's DOM-based loaders with Node ones, once (T13 step 2): BABYLON.Tools.LoadScriptAsync / LoadScript use
297
+ * the Node script loader, so the toolkit's project bundle auto-load works unchanged; BABYLON.SceneLoader's entry points
298
+ * fetch the scene file over HTTP and hand it over as data, and the glTF loader fetches its buffers the same way and loads
299
+ * no materials (no textures headless). Babylon's own versions use a script element and XMLHttpRequest, which Node lacks.
300
+ * @param babylon The BABYLON namespace.
301
+ */
302
+ export declare function installNodeLoaders(babylon: HeadlessBabylonApi): void;
303
+ /**
304
+ * Loads an exported toolkit scene headless (T13 step 2): the same .gltf the browser loads, fetched over HTTP, on a
305
+ * NullEngine with Havok, the toolkit runtime initialised without a page (A18) and no materials or textures; the scene's
306
+ * project script bundle auto-loads through the Node script loader. As engine.html does, a scene without a camera gets a
307
+ * default one and the render loop starts; it resolves once the toolkit has created the scene's components and the scene
308
+ * is ready (TOOLKIT.SceneManager.WhenSceneReady).
309
+ * @param sceneRootUrl The folder URL of the scene: http(s):// (for example "http://localhost:8877/scenes/") or file://.
310
+ * @param sceneFile The scene file (for example "networktestbed.gltf").
311
+ * @param onFrameRendered Receives each frame's duration in seconds (the dedicated frame metrics, D16).
312
+ * @returns The engine and the ready, rendering scene.
313
+ * @throws Error when the toolkit does not report the scene ready.
314
+ */
315
+ export declare function loadHeadlessScene(sceneRootUrl: string, sceneFile: string, onFrameRendered?: (seconds: number) => void): Promise<HeadlessSceneHandle>;
316
+ export {};