@babylonjs-toolkit/server 0.0.0-stage → 9.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,29 @@
1
+ // Settings of the console's Colyseus Cloud page derived from the server config (colyseus-cloud-console D8, D11).
2
+ import { isColyseusCloud } from "../GameServerConfig.js";
3
+ /**
4
+ * Whether the console's Colyseus Cloud page applies to this server (colyseus-cloud-console D8): "configured" when a
5
+ * Cloud API token is set, "setupNeeded" on Colyseus Cloud without one (the page explains how to add it), else "off".
6
+ * @param config The resolved server config.
7
+ * @param environment The process environment (COLYSEUS_CLOUD is set only on Colyseus Cloud).
8
+ * @returns The feature state.
9
+ */
10
+ export function colyseusCloudFeatureOf(config, environment) {
11
+ if (config.admin.colyseusCloud.apiToken != null)
12
+ return "configured";
13
+ return isColyseusCloud(environment) ? "setupNeeded" : "off";
14
+ }
15
+ /**
16
+ * The host name players reach this server at, from publicUrl, used to mark this console's own Cloud instance (D11).
17
+ * @param config The resolved server config.
18
+ * @returns The host name, or null when publicUrl is unset or not a URL.
19
+ */
20
+ export function ownHostNameOf(config) {
21
+ if (config.publicUrl == null)
22
+ return null;
23
+ try {
24
+ return new URL(config.publicUrl).hostname;
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ }
@@ -0,0 +1,105 @@
1
+ import type { CloudApplicationView, CloudBillingView, CloudDeployDetailView, CloudDeployView, CloudEgressView, CloudFreshnessView, CloudHistoryView, CloudLoadView, CloudPart, CloudProblemView } from "./AdminApiTypes.js";
2
+ import type { CloudApiApplication, CloudApiBilling, CloudApiCurrentMetrics, CloudApiDeploy, CloudApiDeployDetail, CloudApiEgress, CloudApiHistory } from "./ColyseusCloudClient.js";
3
+ /** A stored Cloud resource: the last good data and the last attempt (D3, D5). */
4
+ export interface CloudSnapshot<Data> {
5
+ /** The last good data, or null. */
6
+ data: Data | null;
7
+ /** Last successful fetch (ISO), or null. */
8
+ fetchedAt: string | null;
9
+ /** Last attempt (ISO). */
10
+ attemptedAt: string;
11
+ /** When the next attempt may run after a 5xx or no answer (ISO); replaces the normal schedule; null otherwise. */
12
+ retryAt: string | null;
13
+ /** The last attempt's problem, or null when it succeeded. */
14
+ problem: CloudProblemView | null;
15
+ }
16
+ /** Which application the page shows, from GET /applications (D9). */
17
+ export interface ApplicationChoice {
18
+ /** The chosen application, or null when none could be chosen. */
19
+ application: CloudApplicationView | null;
20
+ /** The team's slugs when several exist and none is configured. */
21
+ choices: string[];
22
+ /** Why none was chosen, or null. */
23
+ setupProblem: CloudProblemView | null;
24
+ }
25
+ /** The fleet-wide pause after a Cloud 429 (D5). */
26
+ export interface CloudRateLimitRecord {
27
+ /** No refresh runs before this time (ISO). */
28
+ blockedUntil: string;
29
+ }
30
+ /** The fleet-wide log request gate (D5). */
31
+ export interface CloudLogGateRecord {
32
+ /** No new log request is sent before this time (ISO). */
33
+ nextAllowedAt: string;
34
+ }
35
+ /**
36
+ * Chooses the application the page shows (D9): the configured slug when it is in the team, else the team's only
37
+ * application; otherwise no application, with the problem and (for an unknown slug or several applications) every slug.
38
+ * @param applications The team's applications from GET /applications.
39
+ * @param configuredSlug The configured slug (admin.colyseusCloud.application), or null.
40
+ * @param ownHostName publicUrl's host name, to mark this console's own instance (D11), or null.
41
+ * @returns The choice.
42
+ */
43
+ export declare function resolveApplication(applications: CloudApiApplication[], configuredSlug: string | null, ownHostName: string | null): ApplicationChoice;
44
+ /**
45
+ * Converts an application of GET /applications.
46
+ * @param application The raw application.
47
+ * @param ownHostName publicUrl's host name, to mark this console's own instance (D11), or null.
48
+ * @returns The application view.
49
+ */
50
+ export declare function toApplicationView(application: CloudApiApplication, ownHostName: string | null): CloudApplicationView;
51
+ /**
52
+ * Converts GET /metrics/current; the application totals sum players and rooms and take the highest CPU and memory over
53
+ * the locations that have totals (Colyseus's rule), and are null when every location is silent.
54
+ * @param metrics The raw current metrics.
55
+ * @returns The load view.
56
+ */
57
+ export declare function toLoadView(metrics: CloudApiCurrentMetrics): CloudLoadView;
58
+ /**
59
+ * Converts GET /metrics.
60
+ * @param history The raw history.
61
+ * @returns The history view.
62
+ */
63
+ export declare function toHistoryView(history: CloudApiHistory): CloudHistoryView;
64
+ /**
65
+ * Converts GET /egress.
66
+ * @param egress The raw traffic.
67
+ * @returns The traffic view.
68
+ */
69
+ export declare function toEgressView(egress: CloudApiEgress): CloudEgressView;
70
+ /**
71
+ * Converts a deploy of GET /deploys.
72
+ * @param deploy The raw deploy.
73
+ * @returns The deploy view.
74
+ */
75
+ export declare function toDeployView(deploy: CloudApiDeploy): CloudDeployView;
76
+ /**
77
+ * Converts GET /deploys/{id} data.
78
+ * @param deploy The raw deploy with its output.
79
+ * @returns The deploy view with its output.
80
+ */
81
+ export declare function toDeployDetailView(deploy: CloudApiDeployDetail): CloudDeployDetailView;
82
+ /**
83
+ * Converts GET /billing for one application: the account, and the subscription of the application with that slug.
84
+ * @param billing The raw billing figures.
85
+ * @param slug The slug of the application the page shows.
86
+ * @returns The billing view (subscription null when that application has none or is not listed).
87
+ */
88
+ export declare function toBillingView(billing: CloudApiBilling, slug: string): CloudBillingView;
89
+ /**
90
+ * How current a stored resource is: stale when its last attempt failed or its data is older than
91
+ * COLYSEUS_CLOUD_STALE_REFRESH_MULTIPLIER refresh intervals plus COLYSEUS_CLOUD_STALE_GRACE_MS.
92
+ * @param snapshot The stored snapshot, or null before the first attempt.
93
+ * @param refreshSeconds How often Colyseus refreshes this resource, in seconds.
94
+ * @param nowMilliseconds The current time, in epoch milliseconds.
95
+ * @returns The freshness view.
96
+ */
97
+ export declare function freshnessOf(snapshot: CloudSnapshot<unknown> | null, refreshSeconds: number, nowMilliseconds: number): CloudFreshnessView;
98
+ /**
99
+ * A page part from a stored resource: its last good data and its freshness.
100
+ * @param snapshot The stored snapshot, or null before the first attempt.
101
+ * @param refreshSeconds How often Colyseus refreshes this resource, in seconds.
102
+ * @param nowMilliseconds The current time, in epoch milliseconds.
103
+ * @returns The part.
104
+ */
105
+ export declare function partOf<Data>(snapshot: CloudSnapshot<Data> | null, refreshSeconds: number, nowMilliseconds: number): CloudPart<Data>;
@@ -0,0 +1,371 @@
1
+ // Pure conversions behind the console's Colyseus Cloud page (colyseus-cloud-console D9, D11, D12): Colyseus's raw
2
+ // snake_case answers become the console's camelCase views, a stored snapshot becomes its freshness, and the team's
3
+ // applications become the application choice. Nothing here reads the clock; callers pass nowMilliseconds.
4
+ import { COLYSEUS_CLOUD_STALE_GRACE_MS, COLYSEUS_CLOUD_STALE_REFRESH_MULTIPLIER, MILLISECONDS_PER_SECOND } from "./AdminConstants.js";
5
+ /** The environment variable a team with several applications sets to choose one (D9). */
6
+ const APPLICATION_VARIABLE = "GAME_SERVER_ADMIN_COLYSEUS_CLOUD_APPLICATION";
7
+ /** Status of a problem that is not an answer of Colyseus. */
8
+ const NOT_AN_ANSWER_STATUS = 0;
9
+ /**
10
+ * Chooses the application the page shows (D9): the configured slug when it is in the team, else the team's only
11
+ * application; otherwise no application, with the problem and (for an unknown slug or several applications) every slug.
12
+ * @param applications The team's applications from GET /applications.
13
+ * @param configuredSlug The configured slug (admin.colyseusCloud.application), or null.
14
+ * @param ownHostName publicUrl's host name, to mark this console's own instance (D11), or null.
15
+ * @returns The choice.
16
+ */
17
+ export function resolveApplication(applications, configuredSlug, ownHostName) {
18
+ const slugs = applications.map((application) => application.slug);
19
+ if (configuredSlug != null) {
20
+ const configured = applications.find((application) => application.slug === configuredSlug);
21
+ if (configured != null)
22
+ return chosenApplication(configured, ownHostName);
23
+ const message = "The application " + configuredSlug + " is not in this team. Set " + APPLICATION_VARIABLE + " to one of: " + slugs.join(", ") + ".";
24
+ return unchosenApplication("unknown_application", message, slugs);
25
+ }
26
+ if (applications.length === 0)
27
+ return unchosenApplication("no_applications", "This team has no application yet.", []);
28
+ if (applications.length > 1) {
29
+ const message = "This team has several applications. Set " + APPLICATION_VARIABLE + " to the one this console watches.";
30
+ return unchosenApplication("several_applications", message, slugs);
31
+ }
32
+ return chosenApplication(applications[0], ownHostName);
33
+ }
34
+ /**
35
+ * Converts an application of GET /applications.
36
+ * @param application The raw application.
37
+ * @param ownHostName publicUrl's host name, to mark this console's own instance (D11), or null.
38
+ * @returns The application view.
39
+ */
40
+ export function toApplicationView(application, ownHostName) {
41
+ return {
42
+ id: application.id,
43
+ slug: application.slug,
44
+ name: application.name,
45
+ maintenanceMode: application.maintenance_mode,
46
+ createdAt: application.created_at,
47
+ locations: application.locations.map((location) => toLocationView(location, ownHostName))
48
+ };
49
+ }
50
+ /**
51
+ * Converts GET /metrics/current; the application totals sum players and rooms and take the highest CPU and memory over
52
+ * the locations that have totals (Colyseus's rule), and are null when every location is silent.
53
+ * @param metrics The raw current metrics.
54
+ * @returns The load view.
55
+ */
56
+ export function toLoadView(metrics) {
57
+ const locations = metrics.locations.map(toLocationLoadView);
58
+ const reportingTotals = [];
59
+ for (const location of locations) {
60
+ if (location.totals != null)
61
+ reportingTotals.push(location.totals);
62
+ }
63
+ return { windowMinutes: metrics.window_minutes, locations: locations, totals: combineTotals(reportingTotals) };
64
+ }
65
+ /**
66
+ * Converts GET /metrics.
67
+ * @param history The raw history.
68
+ * @returns The history view.
69
+ */
70
+ export function toHistoryView(history) {
71
+ return {
72
+ resolution: history.resolution,
73
+ from: history.from,
74
+ to: history.to,
75
+ locations: history.locations.map(toLocationHistoryView)
76
+ };
77
+ }
78
+ /**
79
+ * Converts GET /egress.
80
+ * @param egress The raw traffic.
81
+ * @returns The traffic view.
82
+ */
83
+ export function toEgressView(egress) {
84
+ return {
85
+ from: egress.from,
86
+ to: egress.to,
87
+ collectedAt: egress.collected_at,
88
+ locations: egress.locations.map(toLocationEgressView)
89
+ };
90
+ }
91
+ /**
92
+ * Converts a deploy of GET /deploys.
93
+ * @param deploy The raw deploy.
94
+ * @returns The deploy view.
95
+ */
96
+ export function toDeployView(deploy) {
97
+ return {
98
+ id: deploy.id,
99
+ status: deploy.status,
100
+ branch: deploy.branch,
101
+ commit: deploy.commit,
102
+ message: deploy.message,
103
+ startedAt: deploy.started_at,
104
+ finishedAt: deploy.finished_at
105
+ };
106
+ }
107
+ /**
108
+ * Converts GET /deploys/{id} data.
109
+ * @param deploy The raw deploy with its output.
110
+ * @returns The deploy view with its output.
111
+ */
112
+ export function toDeployDetailView(deploy) {
113
+ return { ...toDeployView(deploy), output: deploy.output };
114
+ }
115
+ /**
116
+ * Converts GET /billing for one application: the account, and the subscription of the application with that slug.
117
+ * @param billing The raw billing figures.
118
+ * @param slug The slug of the application the page shows.
119
+ * @returns The billing view (subscription null when that application has none or is not listed).
120
+ */
121
+ export function toBillingView(billing, slug) {
122
+ const listed = billing.applications.find((application) => application.slug === slug);
123
+ const subscription = listed?.subscription ?? null;
124
+ return {
125
+ account: billing.account == null ? null : toAccountView(billing.account),
126
+ subscription: subscription == null ? null : toSubscriptionView(subscription),
127
+ fetchedAt: billing.fetched_at
128
+ };
129
+ }
130
+ /**
131
+ * How current a stored resource is: stale when its last attempt failed or its data is older than
132
+ * COLYSEUS_CLOUD_STALE_REFRESH_MULTIPLIER refresh intervals plus COLYSEUS_CLOUD_STALE_GRACE_MS.
133
+ * @param snapshot The stored snapshot, or null before the first attempt.
134
+ * @param refreshSeconds How often Colyseus refreshes this resource, in seconds.
135
+ * @param nowMilliseconds The current time, in epoch milliseconds.
136
+ * @returns The freshness view.
137
+ */
138
+ export function freshnessOf(snapshot, refreshSeconds, nowMilliseconds) {
139
+ if (snapshot == null)
140
+ return { fetchedAt: null, attemptedAt: null, refreshSeconds: refreshSeconds, isStale: false, problem: null };
141
+ const staleAfterMilliseconds = refreshSeconds * MILLISECONDS_PER_SECOND * COLYSEUS_CLOUD_STALE_REFRESH_MULTIPLIER + COLYSEUS_CLOUD_STALE_GRACE_MS;
142
+ const isTooOld = snapshot.fetchedAt != null && nowMilliseconds - Date.parse(snapshot.fetchedAt) > staleAfterMilliseconds;
143
+ return {
144
+ fetchedAt: snapshot.fetchedAt,
145
+ attemptedAt: snapshot.attemptedAt,
146
+ refreshSeconds: refreshSeconds,
147
+ isStale: snapshot.problem != null || isTooOld,
148
+ problem: snapshot.problem
149
+ };
150
+ }
151
+ /**
152
+ * A page part from a stored resource: its last good data and its freshness.
153
+ * @param snapshot The stored snapshot, or null before the first attempt.
154
+ * @param refreshSeconds How often Colyseus refreshes this resource, in seconds.
155
+ * @param nowMilliseconds The current time, in epoch milliseconds.
156
+ * @returns The part.
157
+ */
158
+ export function partOf(snapshot, refreshSeconds, nowMilliseconds) {
159
+ return { data: snapshot?.data ?? null, freshness: freshnessOf(snapshot, refreshSeconds, nowMilliseconds) };
160
+ }
161
+ /**
162
+ * The choice of one application.
163
+ * @param application The chosen raw application.
164
+ * @param ownHostName publicUrl's host name, or null.
165
+ * @returns The choice without a problem.
166
+ */
167
+ function chosenApplication(application, ownHostName) {
168
+ return { application: toApplicationView(application, ownHostName), choices: [], setupProblem: null };
169
+ }
170
+ /**
171
+ * The choice of no application, with why.
172
+ * @param code The problem code.
173
+ * @param message The problem message.
174
+ * @param choices The slugs the page lists.
175
+ * @returns The choice without an application.
176
+ */
177
+ function unchosenApplication(code, message, choices) {
178
+ return { application: null, choices: choices, setupProblem: { status: NOT_AN_ANSWER_STATUS, code: code, message: message } };
179
+ }
180
+ /**
181
+ * The host name of an address.
182
+ * @param text The address, or null.
183
+ * @returns Its host name, or null for null or an invalid URL.
184
+ */
185
+ function hostNameOf(text) {
186
+ if (text == null)
187
+ return null;
188
+ try {
189
+ return new URL(text).hostname;
190
+ }
191
+ catch {
192
+ return null;
193
+ }
194
+ }
195
+ /**
196
+ * Converts a location of GET /applications.
197
+ * @param location The raw location.
198
+ * @param ownHostName publicUrl's host name, or null.
199
+ * @returns The location view.
200
+ */
201
+ function toLocationView(location, ownHostName) {
202
+ return {
203
+ id: location.id,
204
+ regionCode: location.region.code,
205
+ city: location.region.city,
206
+ country: location.region.country,
207
+ status: location.status,
208
+ scaleStrategy: location.scale_strategy,
209
+ endpoint: location.endpoint,
210
+ plan: { vcpus: location.plan.vcpus, ramMegabytes: location.plan.ram_mb, transferGigabytes: location.plan.transfer_gb },
211
+ instances: location.instances.map((instance) => toInstanceView(instance, ownHostName))
212
+ };
213
+ }
214
+ /**
215
+ * Converts an instance of GET /applications; it is this console's own instance when its endpoint's host name is
216
+ * publicUrl's host name (D11).
217
+ * @param instance The raw instance.
218
+ * @param ownHostName publicUrl's host name, or null.
219
+ * @returns The instance view.
220
+ */
221
+ function toInstanceView(instance, ownHostName) {
222
+ return {
223
+ id: instance.id,
224
+ endpoint: instance.endpoint,
225
+ status: instance.status,
226
+ deployStatus: instance.deploy_status,
227
+ deployedAt: instance.deployed_at,
228
+ isThisInstance: ownHostName != null && hostNameOf(instance.endpoint) === ownHostName
229
+ };
230
+ }
231
+ /**
232
+ * Converts a location of GET /metrics/current.
233
+ * @param location The raw location metrics.
234
+ * @returns The location load view.
235
+ */
236
+ function toLocationLoadView(location) {
237
+ return {
238
+ id: location.id,
239
+ regionCode: location.region,
240
+ totals: location.totals == null ? null : toTotalsView(location.totals),
241
+ instances: location.instances.map(toInstanceLoadView)
242
+ };
243
+ }
244
+ /**
245
+ * Converts an instance sample; a silent instance (no sample within Colyseus's window) has null values and no processes.
246
+ * @param sample The raw instance sample.
247
+ * @returns The instance load view.
248
+ */
249
+ function toInstanceLoadView(sample) {
250
+ const isSilent = sample.sampled_at == null || sample.cpu_percent == null;
251
+ if (isSilent) {
252
+ return { id: sample.id, sampledAt: sample.sampled_at, isSilent: true, players: null, rooms: null, cpuPercent: null, memoryPercent: null, processes: [] };
253
+ }
254
+ return {
255
+ id: sample.id,
256
+ sampledAt: sample.sampled_at,
257
+ isSilent: false,
258
+ players: sample.ccu,
259
+ rooms: sample.rooms,
260
+ cpuPercent: sample.cpu_percent,
261
+ memoryPercent: sample.memory_percent,
262
+ processes: sample.processes.map(toProcessView)
263
+ };
264
+ }
265
+ /**
266
+ * Converts a process of GET /metrics/current.
267
+ * @param rawProcess The raw process.
268
+ * @returns The process view.
269
+ */
270
+ function toProcessView(rawProcess) {
271
+ return {
272
+ id: rawProcess.id,
273
+ status: rawProcess.status,
274
+ startedAt: rawProcess.started_at,
275
+ restarts: rawProcess.restarts,
276
+ cpuPercent: rawProcess.cpu_percent,
277
+ memoryMegabytes: rawProcess.memory_mb,
278
+ players: rawProcess.ccu,
279
+ rooms: rawProcess.rooms,
280
+ nodeVersion: rawProcess.node_version
281
+ };
282
+ }
283
+ /**
284
+ * Converts Colyseus's load totals.
285
+ * @param totals The raw totals.
286
+ * @returns The totals view.
287
+ */
288
+ function toTotalsView(totals) {
289
+ return { players: totals.ccu, rooms: totals.rooms, cpuPercent: totals.cpu_percent, memoryPercent: totals.memory_percent };
290
+ }
291
+ /**
292
+ * Combines several totals by Colyseus's rule: players and rooms summed, CPU and memory the highest.
293
+ * @param totalsList The totals to combine.
294
+ * @returns The combined totals, or null when the list is empty.
295
+ */
296
+ function combineTotals(totalsList) {
297
+ if (totalsList.length === 0)
298
+ return null;
299
+ const combined = { players: 0, rooms: 0, cpuPercent: 0, memoryPercent: 0 };
300
+ for (const totals of totalsList) {
301
+ combined.players += totals.players;
302
+ combined.rooms += totals.rooms;
303
+ combined.cpuPercent = Math.max(combined.cpuPercent, totals.cpuPercent);
304
+ combined.memoryPercent = Math.max(combined.memoryPercent, totals.memoryPercent);
305
+ }
306
+ return combined;
307
+ }
308
+ /**
309
+ * Converts a location of GET /metrics.
310
+ * @param location The raw location history.
311
+ * @returns The location history view.
312
+ */
313
+ function toLocationHistoryView(location) {
314
+ return { id: location.id, regionCode: location.region, points: location.points.map(toHistoryPointView) };
315
+ }
316
+ /**
317
+ * Converts a point of GET /metrics.
318
+ * @param point The raw point.
319
+ * @returns The point view.
320
+ */
321
+ function toHistoryPointView(point) {
322
+ return { time: point.time, ...toTotalsView(point) };
323
+ }
324
+ /**
325
+ * Converts a location of GET /egress.
326
+ * @param location The raw location traffic.
327
+ * @returns The location traffic view.
328
+ */
329
+ function toLocationEgressView(location) {
330
+ return {
331
+ id: location.id,
332
+ regionCode: location.region,
333
+ outgoingBytes: location.outgoing_bytes,
334
+ incomingBytes: location.incoming_bytes,
335
+ days: location.days.map(toEgressDayView)
336
+ };
337
+ }
338
+ /**
339
+ * Converts a day of GET /egress.
340
+ * @param day The raw day.
341
+ * @returns The day view.
342
+ */
343
+ function toEgressDayView(day) {
344
+ return { date: day.date, outgoingBytes: day.outgoing_bytes, incomingBytes: day.incoming_bytes };
345
+ }
346
+ /**
347
+ * Converts the billing account of GET /billing.
348
+ * @param account The raw account.
349
+ * @returns The account view.
350
+ */
351
+ function toAccountView(account) {
352
+ return {
353
+ currency: account.currency,
354
+ creditBalance: account.credit_balance,
355
+ balanceDue: account.balance_due,
356
+ unusedTimeCredit: account.unused_time_credit
357
+ };
358
+ }
359
+ /**
360
+ * Converts a subscription of GET /billing.
361
+ * @param subscription The raw subscription.
362
+ * @returns The subscription view.
363
+ */
364
+ function toSubscriptionView(subscription) {
365
+ return {
366
+ status: subscription.status,
367
+ monthlyPrice: subscription.monthly_price,
368
+ currentPeriodEnd: subscription.current_period_end,
369
+ cancelAtPeriodEnd: subscription.cancel_at_period_end
370
+ };
371
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The 100 entries of SecLists Passwords/Common-Credentials/10-million-password-list-top-100.txt, lower-cased, plus the
3
+ * product's own names. Most are shorter than MINIMUM_PASSWORD_LENGTH and are refused by length anyway; the list keeps
4
+ * the check honest if the minimum ever changes.
5
+ */
6
+ export declare const COMMON_PASSWORDS: ReadonlySet<string>;
@@ -0,0 +1,19 @@
1
+ // Passwords an admin account may not use (game-server-admin-console D8). Compared lower-cased.
2
+ /**
3
+ * The 100 entries of SecLists Passwords/Common-Credentials/10-million-password-list-top-100.txt, lower-cased, plus the
4
+ * product's own names. Most are shorter than MINIMUM_PASSWORD_LENGTH and are refused by length anyway; the list keeps
5
+ * the check honest if the minimum ever changes.
6
+ */
7
+ export const COMMON_PASSWORDS = new Set([
8
+ "123456", "password", "12345678", "qwerty", "123456789", "12345", "1234", "111111", "1234567", "dragon",
9
+ "123123", "baseball", "abc123", "football", "monkey", "letmein", "696969", "shadow", "master", "666666",
10
+ "qwertyuiop", "123321", "mustang", "1234567890", "michael", "654321", "pussy", "superman", "1qaz2wsx", "7777777",
11
+ "fuckyou", "121212", "000000", "qazwsx", "123qwe", "killer", "trustno1", "jordan", "jennifer", "zxcvbnm",
12
+ "asdfgh", "hunter", "buster", "soccer", "harley", "batman", "andrew", "tigger", "sunshine", "iloveyou",
13
+ "fuckme", "2000", "charlie", "robert", "thomas", "hockey", "ranger", "daniel", "starwars", "klaster",
14
+ "112233", "george", "asshole", "computer", "michelle", "jessica", "pepper", "1111", "zxcvbn", "555555",
15
+ "11111111", "131313", "freedom", "777777", "pass", "fuck", "maggie", "159753", "aaaaaa", "ginger",
16
+ "princess", "joshua", "cheese", "amanda", "summer", "love", "ashley", "6969", "nicole", "chelsea",
17
+ "biteme", "matthew", "access", "yankees", "987654321", "dallas", "austin", "thunder", "taylor", "matrix",
18
+ "babylongameserver", "babylon-game-server", "administrator", "changeme1234"
19
+ ]);