@v12-engine/engine 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) hide show
  1. package/LICENSE +21 -0
  2. package/dist/abilities/buffs.d.ts +83 -0
  3. package/dist/abilities/castTold.d.ts +12 -0
  4. package/dist/abilities/charges.d.ts +28 -0
  5. package/dist/abilities/dispel.d.ts +9 -0
  6. package/dist/abilities/effectFields.d.ts +10 -0
  7. package/dist/abilities/effects/buff.d.ts +8 -0
  8. package/dist/abilities/effects/core.d.ts +1 -0
  9. package/dist/abilities/effects/damage.d.ts +1 -0
  10. package/dist/abilities/effects/heal.d.ts +2 -0
  11. package/dist/abilities/effects/missile.d.ts +1 -0
  12. package/dist/abilities/effects/moves.d.ts +11 -0
  13. package/dist/abilities/effects/passives.d.ts +15 -0
  14. package/dist/abilities/effects/sight.d.ts +4 -0
  15. package/dist/abilities/effects/spawn.d.ts +2 -0
  16. package/dist/abilities/effects/timed.d.ts +4 -0
  17. package/dist/abilities/effects/trade.d.ts +1 -0
  18. package/dist/abilities/effects.d.ts +122 -0
  19. package/dist/abilities/land.d.ts +21 -0
  20. package/dist/abilities/scaled.d.ts +21 -0
  21. package/dist/abilities/text.d.ts +113 -0
  22. package/dist/ai/area.d.ts +53 -0
  23. package/dist/ai/brain.d.ts +528 -0
  24. package/dist/ai/budget.d.ts +67 -0
  25. package/dist/ai/checks.d.ts +115 -0
  26. package/dist/ai/computer.d.ts +166 -0
  27. package/dist/ai/defence.d.ts +108 -0
  28. package/dist/ai/define.d.ts +21 -0
  29. package/dist/ai/economy.d.ts +129 -0
  30. package/dist/ai/geometry.d.ts +35 -0
  31. package/dist/ai/goals.d.ts +360 -0
  32. package/dist/ai/index.d.ts +38 -0
  33. package/dist/ai/knowledge.d.ts +418 -0
  34. package/dist/ai/lanes.d.ts +232 -0
  35. package/dist/ai/melee/build.d.ts +61 -0
  36. package/dist/ai/melee/goals.d.ts +299 -0
  37. package/dist/ai/melee/heroes.d.ts +27 -0
  38. package/dist/ai/melee/index.d.ts +14 -0
  39. package/dist/ai/melee/production.d.ts +8 -0
  40. package/dist/ai/melee/surrender.d.ts +24 -0
  41. package/dist/ai/micro.d.ts +278 -0
  42. package/dist/ai/mission.d.ts +195 -0
  43. package/dist/ai/missionRules.d.ts +18 -0
  44. package/dist/ai/module.d.ts +116 -0
  45. package/dist/ai/options.d.ts +61 -0
  46. package/dist/ai/plans/build.d.ts +280 -0
  47. package/dist/ai/plans/placement.d.ts +82 -0
  48. package/dist/ai/plans/plans.d.ts +105 -0
  49. package/dist/ai/plans/production.d.ts +210 -0
  50. package/dist/ai/plans/purse.d.ts +73 -0
  51. package/dist/ai/plans/tech.d.ts +37 -0
  52. package/dist/ai/profiles.d.ts +204 -0
  53. package/dist/ai/reach.d.ts +4 -0
  54. package/dist/ai/report.d.ts +203 -0
  55. package/dist/ai/roles.d.ts +133 -0
  56. package/dist/ai/rules.d.ts +288 -0
  57. package/dist/ai/scouting.d.ts +98 -0
  58. package/dist/ai/settings.d.ts +73 -0
  59. package/dist/ai/squads.d.ts +429 -0
  60. package/dist/ai/strength.d.ts +167 -0
  61. package/dist/ai/task.d.ts +118 -0
  62. package/dist/ai/tasks/attack.d.ts +7 -0
  63. package/dist/ai/tasks/capture.d.ts +21 -0
  64. package/dist/ai/tasks/creep.d.ts +16 -0
  65. package/dist/ai/tasks/defend.d.ts +29 -0
  66. package/dist/ai/tasks/drop.d.ts +34 -0
  67. package/dist/ai/tasks/escort.d.ts +16 -0
  68. package/dist/ai/tasks/gather.d.ts +23 -0
  69. package/dist/ai/tasks/harass.d.ts +7 -0
  70. package/dist/ai/tasks/hold.d.ts +20 -0
  71. package/dist/ai/tasks/index.d.ts +32 -0
  72. package/dist/ai/tasks/move.d.ts +19 -0
  73. package/dist/ai/tasks/patrol.d.ts +8 -0
  74. package/dist/ai/tasks/retreat.d.ts +20 -0
  75. package/dist/ai/tasks/scout.d.ts +29 -0
  76. package/dist/ai/tasks/shared.d.ts +74 -0
  77. package/dist/ai/team.d.ts +155 -0
  78. package/dist/ai/threat.d.ts +91 -0
  79. package/dist/ai/view.d.ts +366 -0
  80. package/dist/ai/waves.d.ts +126 -0
  81. package/dist/ai.js +6239 -0
  82. package/dist/ai.js.map +1 -0
  83. package/dist/aiTesting.d.ts +179 -0
  84. package/dist/areas.d.ts +149 -0
  85. package/dist/attacks.d.ts +66 -0
  86. package/dist/attributes.d.ts +66 -0
  87. package/dist/brain-BvVdUhX8.js +7659 -0
  88. package/dist/brain-BvVdUhX8.js.map +1 -0
  89. package/dist/builds-C6LfgvEU.js +460 -0
  90. package/dist/builds-C6LfgvEU.js.map +1 -0
  91. package/dist/bytes.d.ts +6 -0
  92. package/dist/camps.d.ts +95 -0
  93. package/dist/capture.d.ts +131 -0
  94. package/dist/cellLayers.d.ts +75 -0
  95. package/dist/cinematics.d.ts +194 -0
  96. package/dist/clock.d.ts +32 -0
  97. package/dist/commands.d.ts +235 -0
  98. package/dist/components.d.ts +184 -0
  99. package/dist/computers.d.ts +108 -0
  100. package/dist/concealment.d.ts +61 -0
  101. package/dist/coreComponents-syuh2fPG.js +5149 -0
  102. package/dist/coreComponents-syuh2fPG.js.map +1 -0
  103. package/dist/coreComponents.d.ts +1 -0
  104. package/dist/dashing.d.ts +8 -0
  105. package/dist/debug.d.ts +36 -0
  106. package/dist/debug.js +3 -0
  107. package/dist/debugCommands-CzjrSm66.js +14739 -0
  108. package/dist/debugCommands-CzjrSm66.js.map +1 -0
  109. package/dist/debugCommands.d.ts +213 -0
  110. package/dist/debugging.d.ts +10 -0
  111. package/dist/definitions.d.ts +43 -0
  112. package/dist/defs.d.ts +1162 -0
  113. package/dist/denying.d.ts +81 -0
  114. package/dist/destructibles.d.ts +27 -0
  115. package/dist/determinism-BCymQwiE.js +518 -0
  116. package/dist/determinism-BCymQwiE.js.map +1 -0
  117. package/dist/determinism.d.ts +121 -0
  118. package/dist/dialog.d.ts +94 -0
  119. package/dist/effectRefs.d.ts +16 -0
  120. package/dist/effects.d.ts +80 -0
  121. package/dist/endings.d.ts +22 -0
  122. package/dist/engagement.d.ts +108 -0
  123. package/dist/engineEvents.d.ts +710 -0
  124. package/dist/entity.d.ts +409 -0
  125. package/dist/entityIndex.d.ts +50 -0
  126. package/dist/errors.d.ts +85 -0
  127. package/dist/events.d.ts +97 -0
  128. package/dist/exactMath.d.ts +63 -0
  129. package/dist/features.d.ts +10 -0
  130. package/dist/fields.d.ts +114 -0
  131. package/dist/fixture.d.ts +17 -0
  132. package/dist/fog.d.ts +110 -0
  133. package/dist/formation.d.ts +111 -0
  134. package/dist/friendlyFire.d.ts +26 -0
  135. package/dist/game-DiJEN-Ks.js +5800 -0
  136. package/dist/game-DiJEN-Ks.js.map +1 -0
  137. package/dist/game.d.ts +501 -0
  138. package/dist/gameData.d.ts +325 -0
  139. package/dist/gameFiles.d.ts +26 -0
  140. package/dist/gates.d.ts +28 -0
  141. package/dist/generate.d.ts +403 -0
  142. package/dist/generateWorker.d.ts +39 -0
  143. package/dist/grid.d.ts +53 -0
  144. package/dist/ground.d.ts +127 -0
  145. package/dist/groundSpeed.d.ts +22 -0
  146. package/dist/hero.d.ts +177 -0
  147. package/dist/home.d.ts +14 -0
  148. package/dist/hooks.d.ts +780 -0
  149. package/dist/hotReload.d.ts +76 -0
  150. package/dist/ids.d.ts +26 -0
  151. package/dist/index.d.ts +227 -0
  152. package/dist/index.js +4701 -0
  153. package/dist/index.js.map +1 -0
  154. package/dist/inspect-D9dWHmZ0.js +491 -0
  155. package/dist/inspect-D9dWHmZ0.js.map +1 -0
  156. package/dist/inspect.d.ts +176 -0
  157. package/dist/inventory.d.ts +18 -0
  158. package/dist/items.d.ts +91 -0
  159. package/dist/lanes.d.ts +213 -0
  160. package/dist/life.d.ts +53 -0
  161. package/dist/local-Dkovq42k.js +1379 -0
  162. package/dist/local-Dkovq42k.js.map +1 -0
  163. package/dist/log.d.ts +140 -0
  164. package/dist/manaBurn.d.ts +39 -0
  165. package/dist/map/file.d.ts +114 -0
  166. package/dist/map/images.d.ts +18 -0
  167. package/dist/map/look.d.ts +47 -0
  168. package/dist/map/pathProfile.d.ts +13 -0
  169. package/dist/map/resize.d.ts +54 -0
  170. package/dist/map/schema.d.ts +10 -0
  171. package/dist/map/terrain.d.ts +32 -0
  172. package/dist/map/types.d.ts +613 -0
  173. package/dist/map.d.ts +7 -0
  174. package/dist/mapCheck/cells.d.ts +19 -0
  175. package/dist/mapCheck/rule.d.ts +30 -0
  176. package/dist/mapCheck/rules/names.d.ts +3 -0
  177. package/dist/mapCheck/rules/objects.d.ts +3 -0
  178. package/dist/mapCheck/rules/paths.d.ts +3 -0
  179. package/dist/mapCheck/rules/players.d.ts +3 -0
  180. package/dist/mapCheck/rules/races.d.ts +3 -0
  181. package/dist/mapCheck/rules/random.d.ts +3 -0
  182. package/dist/mapCheck/rules/regions.d.ts +3 -0
  183. package/dist/mapCheck/rules/targets.d.ts +3 -0
  184. package/dist/mapCheck/rules/walking.d.ts +3 -0
  185. package/dist/mapCheck.d.ts +23 -0
  186. package/dist/mapFields.d.ts +364 -0
  187. package/dist/mapFile.d.ts +23 -0
  188. package/dist/mapMeasure.d.ts +95 -0
  189. package/dist/mapMerge.d.ts +19 -0
  190. package/dist/mapObjectives.d.ts +82 -0
  191. package/dist/mapObjects.d.ts +1 -0
  192. package/dist/math.d.ts +44 -0
  193. package/dist/messages.d.ts +150 -0
  194. package/dist/missionRules-C-bGxm0Q.js +523 -0
  195. package/dist/missionRules-C-bGxm0Q.js.map +1 -0
  196. package/dist/missionRules.d.ts +179 -0
  197. package/dist/mods.d.ts +146 -0
  198. package/dist/names.d.ts +93 -0
  199. package/dist/navigation/agentParams.d.ts +4 -0
  200. package/dist/navigation/air.d.ts +89 -0
  201. package/dist/navigation/builds.d.ts +140 -0
  202. package/dist/navigation/groundAreas.d.ts +23 -0
  203. package/dist/navigation/navigation.d.ts +127 -0
  204. package/dist/navigation/recast.d.ts +214 -0
  205. package/dist/navigation/sidePaths.d.ts +69 -0
  206. package/dist/navigation/sized.d.ts +1 -0
  207. package/dist/navigation-worker.js +11 -0
  208. package/dist/navigation-worker.js.map +1 -0
  209. package/dist/nearest.d.ts +8 -0
  210. package/dist/noise.d.ts +12 -0
  211. package/dist/objectives.d.ts +93 -0
  212. package/dist/orders/basic.d.ts +96 -0
  213. package/dist/orders/build.d.ts +91 -0
  214. package/dist/orders/cast.d.ts +105 -0
  215. package/dist/orders/facts.d.ts +14 -0
  216. package/dist/orders/harvest.d.ts +94 -0
  217. package/dist/orders/idle.d.ts +7 -0
  218. package/dist/orders/items.d.ts +14 -0
  219. package/dist/orders/queue.d.ts +24 -0
  220. package/dist/pack.schema.json +6621 -0
  221. package/dist/packs/director/index.d.ts +81 -0
  222. package/dist/packs/heroes/campaign.d.ts +137 -0
  223. package/dist/packs/heroes/carry.d.ts +59 -0
  224. package/dist/packs/heroes/commands.d.ts +6 -0
  225. package/dist/packs/heroes/hire.d.ts +9 -0
  226. package/dist/packs/heroes/index.d.ts +12 -0
  227. package/dist/packs/heroes/making.d.ts +16 -0
  228. package/dist/packs/heroes/respawn.d.ts +42 -0
  229. package/dist/packs/moba/index.d.ts +34 -0
  230. package/dist/packs/pack.d.ts +84 -0
  231. package/dist/packs-g5thvmGn.js +3199 -0
  232. package/dist/packs-g5thvmGn.js.map +1 -0
  233. package/dist/packs.d.ts +84 -0
  234. package/dist/paths.d.ts +51 -0
  235. package/dist/plain.d.ts +17 -0
  236. package/dist/player.d.ts +117 -0
  237. package/dist/portals.d.ts +66 -0
  238. package/dist/prefabs.d.ts +139 -0
  239. package/dist/presetBuildings.d.ts +52 -0
  240. package/dist/presetGround.d.ts +22 -0
  241. package/dist/profiles-B3NS9jwk.js +335 -0
  242. package/dist/profiles-B3NS9jwk.js.map +1 -0
  243. package/dist/races.d.ts +136 -0
  244. package/dist/randomGroups.d.ts +2 -0
  245. package/dist/registry.d.ts +464 -0
  246. package/dist/remains.d.ts +119 -0
  247. package/dist/replication.d.ts +103 -0
  248. package/dist/rng.d.ts +17 -0
  249. package/dist/rules.d.ts +395 -0
  250. package/dist/rulesCheck.d.ts +37 -0
  251. package/dist/runes.d.ts +41 -0
  252. package/dist/save.d.ts +277 -0
  253. package/dist/scenario.d.ts +56 -0
  254. package/dist/scheduler.d.ts +67 -0
  255. package/dist/score.d.ts +306 -0
  256. package/dist/sequences.d.ts +132 -0
  257. package/dist/server/doorman.d.ts +21 -0
  258. package/dist/server/gameServer.d.ts +346 -0
  259. package/dist/server/index.d.ts +24 -0
  260. package/dist/server/lobby.d.ts +1 -0
  261. package/dist/server/log.d.ts +13 -0
  262. package/dist/server/match.d.ts +24 -0
  263. package/dist/server/mode.d.ts +168 -0
  264. package/dist/server/navigation-worker.d.ts +1 -0
  265. package/dist/server/navigation.d.ts +11 -0
  266. package/dist/server/ops.d.ts +78 -0
  267. package/dist/server/packs.d.ts +15 -0
  268. package/dist/server/ratings.d.ts +62 -0
  269. package/dist/server/relay.d.ts +34 -0
  270. package/dist/server/rooms.d.ts +162 -0
  271. package/dist/server/seat.d.ts +2 -0
  272. package/dist/server/seatSettings.d.ts +15 -0
  273. package/dist/server/secret.d.ts +5 -0
  274. package/dist/server/start.d.ts +54 -0
  275. package/dist/server/websocket.d.ts +74 -0
  276. package/dist/server.js +2861 -0
  277. package/dist/server.js.map +1 -0
  278. package/dist/session/can.d.ts +20 -0
  279. package/dist/session/commandReplay.d.ts +92 -0
  280. package/dist/session/debug.d.ts +65 -0
  281. package/dist/session/delay.d.ts +15 -0
  282. package/dist/session/delta.d.ts +98 -0
  283. package/dist/session/entityState.d.ts +1 -0
  284. package/dist/session/local.d.ts +214 -0
  285. package/dist/session/memory.d.ts +27 -0
  286. package/dist/session/protocol.d.ts +1155 -0
  287. package/dist/session/remote.d.ts +530 -0
  288. package/dist/session/replay.d.ts +114 -0
  289. package/dist/session/seed.d.ts +7 -0
  290. package/dist/session/share.d.ts +78 -0
  291. package/dist/session/socket.d.ts +8 -0
  292. package/dist/session/wire.d.ts +153 -0
  293. package/dist/session/worker.d.ts +227 -0
  294. package/dist/shared.d.ts +171 -0
  295. package/dist/sides.d.ts +75 -0
  296. package/dist/sight.d.ts +27 -0
  297. package/dist/simulate-oXBiw1Ff.js +167 -0
  298. package/dist/simulate-oXBiw1Ff.js.map +1 -0
  299. package/dist/simulate-worker.d.ts +1 -0
  300. package/dist/simulate-worker.js +28 -0
  301. package/dist/simulate-worker.js.map +1 -0
  302. package/dist/simulate.d.ts +154 -0
  303. package/dist/smart.d.ts +9 -0
  304. package/dist/spatial.d.ts +62 -0
  305. package/dist/spawning.d.ts +33 -0
  306. package/dist/stances.d.ts +76 -0
  307. package/dist/start.d.ts +71 -0
  308. package/dist/stats.d.ts +122 -0
  309. package/dist/summons.d.ts +63 -0
  310. package/dist/systems/abilities.d.ts +3 -0
  311. package/dist/systems/combat.d.ts +71 -0
  312. package/dist/systems/combatTold.d.ts +14 -0
  313. package/dist/systems/construction.d.ts +34 -0
  314. package/dist/systems/economy.d.ts +21 -0
  315. package/dist/systems/fog.d.ts +19 -0
  316. package/dist/systems/life.d.ts +3 -0
  317. package/dist/systems/movement.d.ts +105 -0
  318. package/dist/systems/orders.d.ts +7 -0
  319. package/dist/systems/production.d.ts +49 -0
  320. package/dist/systems/productionQueue.d.ts +40 -0
  321. package/dist/systems/victory.d.ts +14 -0
  322. package/dist/talk.d.ts +65 -0
  323. package/dist/tech.d.ts +62 -0
  324. package/dist/techTree.d.ts +38 -0
  325. package/dist/terrain.d.ts +173 -0
  326. package/dist/terrainSave.d.ts +29 -0
  327. package/dist/testing.d.ts +58 -0
  328. package/dist/testing.js +822 -0
  329. package/dist/testing.js.map +1 -0
  330. package/dist/tiles.d.ts +34 -0
  331. package/dist/timers.d.ts +146 -0
  332. package/dist/tomes.d.ts +48 -0
  333. package/dist/trade.d.ts +28 -0
  334. package/dist/transport.d.ts +76 -0
  335. package/dist/tunables.d.ts +45 -0
  336. package/dist/upkeep.d.ts +16 -0
  337. package/dist/veterancy.d.ts +80 -0
  338. package/dist/walls.d.ts +86 -0
  339. package/dist/world.d.ts +1118 -0
  340. package/package.json +80 -5
  341. package/README.md +0 -3
@@ -0,0 +1,78 @@
1
+ import type { Ratings } from './ratings';
2
+ import type { GameResult } from '#engine/game';
3
+ import { type GameKindListing, type GameListing } from '#engine/session/protocol';
4
+ import type { IncomingMessage, ServerResponse } from 'node:http';
5
+ /**
6
+ * What a game server says of itself: the numbers of `/metrics` (`GameServer.metrics`)
7
+ *
8
+ * @beta
9
+ */
10
+ export interface ServerMetrics {
11
+ /** In its lobby, playing, or showing a game that ended */
12
+ phase: 'lobby' | 'game' | 'ended';
13
+ /** It takes no new games: it is stopping, once the running one is over (`close({ drain })`) */
14
+ draining: boolean;
15
+ /** Seconds since it started */
16
+ uptime: number;
17
+ /** Games running now (0 or 1 for one server), and played to their end since it started */
18
+ games: {
19
+ running: number;
20
+ played: number;
21
+ };
22
+ /** Seats held by someone connected, and those watching */
23
+ players: number;
24
+ watching: number;
25
+ /** Connections open, seated or not */
26
+ connections: number;
27
+ /** Ticks of the simulation stepped since it started, and the seconds they took; how long the last one took */
28
+ ticks: number;
29
+ tickSeconds: number;
30
+ lastTickSeconds: number;
31
+ /** Rounds of sending everyone what changed, and the seconds they took */
32
+ sends: number;
33
+ sendSeconds: number;
34
+ /** Bytes sent to those connected now, over the wire */
35
+ bytesSent: number;
36
+ }
37
+ /**
38
+ * Where the addresses are, and who may read the numbers (`GameServerOptions.http`)
39
+ *
40
+ * @beta
41
+ */
42
+ export interface ServerHttpOptions {
43
+ /** The address that says whether it is well. `/health` when left out; false for none */
44
+ health?: string | false;
45
+ /** The address of its numbers. `/metrics` when left out; false for none */
46
+ metrics?: string | false;
47
+ /**
48
+ * The address of the list of its games, for a page to find one (`GameListing`, JSON, readable from any page). `/games`
49
+ * when left out; false for none
50
+ */
51
+ games?: string | false;
52
+ /**
53
+ * The address of the best of each mode (`/ratings?mode=melee&n=10&player=<rated id>`: the top and the player's own
54
+ * place, JSON, readable from any page), where the server keeps ratings. `/ratings` when left out; false for none @beta
55
+ */
56
+ ratings?: string | false;
57
+ /**
58
+ * What reading the numbers takes (`Authorization: Bearer <key>`): they say how many play, and when. Anyone who can
59
+ * reach the address when left out: keep it behind the proxy then
60
+ */
61
+ metricsKey?: string;
62
+ }
63
+ /**
64
+ * Answers the health and numbers addresses for the rooms of a process; false for any other request, which goes to
65
+ * what answered it before. `draining` is whether the process takes no new games
66
+ */
67
+ export declare function answerOps(request: IncomingMessage, response: ServerResponse, options: ServerHttpOptions | undefined, state: () => {
68
+ draining: boolean;
69
+ rooms: ReadonlyMap<string, ServerMetrics>;
70
+ }, games?: () => {
71
+ games: GameListing[];
72
+ kinds?: GameKindListing[];
73
+ }, ratings?: {
74
+ ratings?: Ratings;
75
+ modes: readonly string[];
76
+ }): boolean;
77
+ /** A game's result as a file of its own in `dir` (`GameServerOptions.resultsDir`): by when it ended and its mode */
78
+ export declare function writeResult(dir: string, result: GameResult): Promise<void>;
@@ -0,0 +1,15 @@
1
+ import type { GameModule } from '#engine/game';
2
+ import { type PackMod } from '#engine/packs';
3
+ /**
4
+ * The packs of content of a server, read from their files (`packs/<id>/pack.json`) in the order named: that order is
5
+ * the game's, as a page's `defineGame({ packs })` is
6
+ *
7
+ * @beta
8
+ */
9
+ export declare function readPacks(files: readonly string[]): PackMod[];
10
+ /**
11
+ * A server's game with its packs of content composed in (`readPacks`, `composeGame`): the game as is with none
12
+ *
13
+ * @beta
14
+ */
15
+ export declare function withPackFiles(game: GameModule, files: readonly string[]): GameModule;
@@ -0,0 +1,62 @@
1
+ import type { GameResult } from '#engine/game';
2
+ /**
3
+ * A player's standing in a mode
4
+ *
5
+ * @beta
6
+ */
7
+ export interface Rating {
8
+ rating: number;
9
+ games: number;
10
+ wins: number;
11
+ /** The name they last played by */
12
+ name: string;
13
+ }
14
+ /**
15
+ * Where a server keeps ratings (`GameServerOptions.ratings`): what it reads to show in the lobby and the list, and
16
+ * what it tells of every game that ended. `createRatings` keeps them in a file, or in memory; a game's own keeps them
17
+ * where it likes (a database)
18
+ *
19
+ * @beta
20
+ */
21
+ export interface Ratings {
22
+ /** A player's standing in a mode, by their rated id (`ratedId`): none for one who never played it */
23
+ get(mode: string, player: string): Rating | undefined;
24
+ /** Takes in a game that ended: the rated seats' ratings move by how it went, against what was expected */
25
+ record(result: GameResult): void | Promise<void>;
26
+ /**
27
+ * The best of a mode, best first, with their rated ids and places (from 1): what `/ratings` lists. A store with none
28
+ * lists nothing @beta
29
+ */
30
+ top?(mode: string, count: number): RatedPlayer[];
31
+ /** A player's place in a mode (from 1), with their standing: none for one who never played it @beta */
32
+ placeOf?(mode: string, player: string): RatedPlayer | undefined;
33
+ }
34
+ /**
35
+ * A player in a list of the best: their standing, their rated id (`ratedId`), and their place, from 1
36
+ *
37
+ * @beta
38
+ */
39
+ export interface RatedPlayer extends Rating {
40
+ id: string;
41
+ place: number;
42
+ }
43
+ /**
44
+ * The id a player is rated by: a hash of their key or login id, safe to show and keep. The same key, the same id
45
+ *
46
+ * @beta
47
+ */
48
+ export declare const ratedId: (key: string) => string;
49
+ /**
50
+ * Ratings kept in a file (`file`, JSON, read once and written after every game) or in memory: Elo, each side's
51
+ * players against the average of the other's, `k` 32, starting at 1500. The computer counts as `start`, and is not
52
+ * rated; a game with no winner, or with players of one side only, changes nothing
53
+ *
54
+ * @beta
55
+ */
56
+ export declare function createRatings(options?: {
57
+ file?: string;
58
+ k?: number;
59
+ start?: number;
60
+ }): Ratings & {
61
+ ready: Promise<void>;
62
+ };
@@ -0,0 +1,34 @@
1
+ import type { Logger } from '#engine/log';
2
+ import { type ServerLog } from './log';
3
+ /** @beta */
4
+ export interface RelayOptions {
5
+ /** Port to listen on: 0 for any free one */
6
+ port: number;
7
+ compress?: boolean;
8
+ /** Where it says what it does, as `GameServerOptions.log` */
9
+ log?: ServerLog;
10
+ }
11
+ /** @beta */
12
+ export declare class WatchRelay {
13
+ private readonly socket;
14
+ private readonly shares;
15
+ private readonly watchers;
16
+ private next;
17
+ /** What the relay says: see `RelayOptions.log` */
18
+ readonly logger: Logger;
19
+ private constructor();
20
+ /** Starts a relay, and resolves once it listens */
21
+ static start(options: RelayOptions): Promise<WatchRelay>;
22
+ get port(): number;
23
+ /** How many watch what is shared under a key */
24
+ watching(key: string): number;
25
+ private accept;
26
+ private tell;
27
+ private share;
28
+ private unshare;
29
+ private watch;
30
+ private fromWatcher;
31
+ private leave;
32
+ /** Stops the relay: every connection closed */
33
+ close(): Promise<void>;
34
+ }
@@ -0,0 +1,162 @@
1
+ import type { GameKindListing, GameListing } from '#engine/session/protocol';
2
+ import { GameServer, type GameServerOptions } from './gameServer';
3
+ import { type ServerLog } from './log';
4
+ import { type ServerHttpOptions, type ServerMetrics } from './ops';
5
+ /**
6
+ * A room's game server: all of `GameServerOptions` but what the port they share says once for all
7
+ *
8
+ * @beta
9
+ */
10
+ export type RoomOptions = Omit<GameServerOptions, 'port' | 'compress' | 'idleTimeout' | 'maxBuffered' | 'maxConnections' | 'http' | 'log'>;
11
+ /**
12
+ * A kind of game a player may make a room of (features-plan H2): what a "New game" makes (`POST /games`), with the
13
+ * settings asked for (the map) where the game offers them
14
+ *
15
+ * @beta
16
+ */
17
+ export interface RoomKind {
18
+ /** What a list calls it */
19
+ name: string;
20
+ /**
21
+ * The room it makes: the same options for each, or a function that makes a room's options each time one is made,
22
+ * with the settings asked for (a random map for each: `generatedMode`). A kind of a function is listed and matched
23
+ * by a room it makes once, at first
24
+ */
25
+ room: RoomOptions | ((settings: Record<string, string>) => RoomOptions);
26
+ }
27
+ /** @beta */
28
+ export interface GameRoomsOptions {
29
+ /** The port they share: 8787 when left out, 0 for any free one */
30
+ port?: number;
31
+ /**
32
+ * The rooms, by name: each a game server of its own (a lobby and its games), reached at its name
33
+ * (`ws://host:8787/arena`). A name is letters, digits, `-` and `_`. They are there for as long as the process is
34
+ */
35
+ rooms: Record<string, RoomOptions>;
36
+ /**
37
+ * What players may make rooms of, by id (`POST /games` with `{ kind, settings }`, a "New game"): each room made is
38
+ * named after its kind and closed once nobody has been in it for `emptyFor`. None when left out
39
+ */
40
+ kinds?: Record<string, RoomKind>;
41
+ /** How many rooms players may have made at once, those matchmaking made with them: 16 when left out */
42
+ maxMade?: number;
43
+ /** Seconds a made room may stay empty before it is closed: 60 when left out. A room nobody came to counts from when it was made */
44
+ emptyFor?: number;
45
+ /**
46
+ * Matchmaking (features-plan H3): players wait in a queue for a kind (`kinds`), at the address `queue`
47
+ * (`ws://host:8787/queue`, `{ type: 'queue', kind, name }`); once as many wait as its seats for players, it makes a
48
+ * room of the kind, which lets in only them, and hands each a ticket to it (`{ type: 'matched', room, ticket }`). On
49
+ * where there are kinds, unless `false`; `path` for another address
50
+ */
51
+ matchmaking?: boolean | {
52
+ path?: string;
53
+ };
54
+ compress?: boolean;
55
+ idleTimeout?: number;
56
+ maxBuffered?: number;
57
+ /**
58
+ * Connections open at once to all the rooms and the queue, at most (`SocketServerOptions.maxConnections`). 1024 when
59
+ * left out
60
+ *
61
+ * @beta
62
+ */
63
+ maxConnections?: number;
64
+ /**
65
+ * Seconds a connection to the queue has to say what it waits for (`queue`) before it is closed. 10 when left out;
66
+ * a room's own connections have their room's (`GameServerOptions.joinWithin`)
67
+ *
68
+ * @beta
69
+ */
70
+ joinWithin?: number;
71
+ /** Where they all say what they do, each line with its room */
72
+ log?: ServerLog;
73
+ /** The health and numbers addresses, for all of them: the numbers of each by its room */
74
+ http?: ServerHttpOptions;
75
+ /** Where ratings are kept, for every room's players (`GameServerOptions.ratings`), where a room says none of its own */
76
+ ratings?: GameServerOptions['ratings'];
77
+ }
78
+ /**
79
+ * Many games in a process (S58): game servers that share a port, each a room reached at its name, as a server of its
80
+ * own would be at its port. One process, one thread: each room's games step in turn, so the rooms of a process are as
81
+ * many as its ticks have time for (`/metrics` says how long they take). A connection to a room there is not is told so
82
+ * and closed. Rooms are added in code (`add`), or made by players of the kinds it offers (`kinds`, `POST /games`) and
83
+ * closed once empty
84
+ *
85
+ * @beta
86
+ */
87
+ export declare class GameRooms {
88
+ private readonly socket;
89
+ private readonly options;
90
+ private readonly logger;
91
+ private readonly servers;
92
+ /** Where each room's connections come from, by its name */
93
+ private readonly doors;
94
+ /** The rooms players made, and since when each has been empty (nobody connected): what closes them */
95
+ private readonly made;
96
+ /** When each address last asked for rooms (`POST /games`): a few a minute each */
97
+ private readonly askedBy;
98
+ private sweeper?;
99
+ private nextMade;
100
+ /** Who waits to be matched, by kind, in the order they came */
101
+ private readonly queues;
102
+ private constructor();
103
+ /** The rooms there are now, by name */
104
+ get rooms(): ReadonlyMap<string, GameServer>;
105
+ /** Starts the rooms, and resolves once they listen */
106
+ static start(options: GameRoomsOptions): Promise<GameRooms>;
107
+ /** A kind it offers, by id: its own, never what every object has (`constructor`), whatever a page sends */
108
+ private kind;
109
+ /** The address of the queue, or none where there is no matchmaking */
110
+ private get queuePath();
111
+ /** A connection to a room: handed to its game server, or told there is no such room. The queue's, to the queue */
112
+ private connect;
113
+ /** Opens a room at a name, as `rooms` does: in code, while the rooms run */
114
+ add(name: string, room: RoomOptions): Promise<GameServer>;
115
+ /** Closes a room and lets go of its name: those in it are let go */
116
+ remove(name: string): Promise<void>;
117
+ /**
118
+ * Makes a room of a kind it offers (`kinds`), with the settings asked for: what `POST /games` does. Its name is the
119
+ * kind's and a number. Refused (with why) for a kind it does not offer, too many made, or while it stops
120
+ */
121
+ make(kind: string, settings?: Record<string, string>, seat?: RoomOptions['seat']): Promise<{
122
+ room: string;
123
+ } | {
124
+ refused: string;
125
+ }>;
126
+ /** A room a kind makes, as its listing and matchmaking read it: the one it makes, or one it made once (a kind of a function) */
127
+ private readonly samples;
128
+ private sampleOf;
129
+ /** How many of a kind's seats are for players: those the computer does not play */
130
+ private seatsFor;
131
+ /** A connection to the queue: it says the kind it waits for, is told how many wait, and its ticket once matched */
132
+ private waitInQueue;
133
+ /**
134
+ * Whether an address has asked for games too often to ask again now: a few a minute each, made (`POST /games`) or
135
+ * waited for in the queue, so that nobody fills every place there is by asking over and over. Counted when it has not
136
+ */
137
+ private askedTooOften;
138
+ /** Tells everyone waiting for a kind how many wait, of how many it takes */
139
+ private tellQueue;
140
+ /** As many wait for a kind as its seats: a room of it for them, which lets in only them, and a ticket each */
141
+ private match;
142
+ /** Closes the rooms players made that have been empty long enough */
143
+ private sweep;
144
+ /** `POST /games`: a room made of a kind it offers, `{ kind, settings }`, answered with its name. And what a page asks first */
145
+ private answerMake;
146
+ /** The port they share */
147
+ get port(): number;
148
+ /** Whether they take no new games: stopping */
149
+ get draining(): boolean;
150
+ /** The modes the rooms play, each once, in their order: what the ratings are kept by (`/ratings`) */
151
+ modes(): string[];
152
+ /** Every room's game, as a list of games says it (`GET /games`) */
153
+ listing(): GameListing[];
154
+ /** The kinds of game players may make a room of (`kinds`), by id, with their names and the settings they offer */
155
+ kinds(): GameKindListing[];
156
+ /** The numbers of each room, by its name */
157
+ metrics(): Map<string, ServerMetrics>;
158
+ /** Stops every room (see `GameServer.close`: with `drain`, each waits for its game, all at once), then the port */
159
+ close(options?: {
160
+ drain?: number;
161
+ }): Promise<void>;
162
+ }
@@ -0,0 +1,2 @@
1
+ /** A token to come back to a seat with: what only who has it knows */
2
+ export declare function randomToken(): string;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * What a lobby offers to choose for each seat (`seatSettingsOf`): a race where the game has races, and for a game that
3
+ * says how its computers play (`GameModule.ai`) a difficulty and a personality, the engine's and the game's own. On the
4
+ * server's side: it reads the computer player's profiles (`@v12-engine/engine/ai`), which the engine's core does not load
5
+ */
6
+ import type { GameModule, ServerHooks } from '#engine/game';
7
+ /**
8
+ * What a game offers to choose for each seat in a lobby (`ServerHooks.seatSettings`), with a race among them where the
9
+ * game has races and does not offer its own choice of one: each race, by its name, and `random` where there are two
10
+ * or more; only those of
11
+ * `races` where given (the races a map offers, `GameMap.races`). The first is chosen until someone does
12
+ *
13
+ * @beta
14
+ */
15
+ export declare function seatSettingsOf(game: GameModule, races?: readonly string[]): NonNullable<ServerHooks['seatSettings']>;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Whether what was brought is the secret (an admin's key, a key to watch, to the numbers), compared in a time that
3
+ * says nothing of how much of it is right (RV37)
4
+ */
5
+ export declare const sameSecret: (brought: string, secret: string) => boolean;
@@ -0,0 +1,54 @@
1
+ import type { Logger } from '#engine/log';
2
+ import type { BrainDef } from '#engine/ai/brain';
3
+ import type { GameModule } from '#engine/game';
4
+ import type { GameMap } from '#engine/map';
5
+ import type { World } from '#engine/world';
6
+ import { GameServer, type GameServerOptions } from './gameServer';
7
+ import { type GameMode, type ModeSeat } from './mode';
8
+ /**
9
+ * What a game server is started with: the game, where its worlds come from, and the server's own options
10
+ *
11
+ * @beta
12
+ */
13
+ export interface StartServerOptions extends Omit<GameServerOptions, 'mode' | 'port'> {
14
+ /** The rules of the game (`GameModule`): of a game defined whole, its `rules`. A server never sees a game's view */
15
+ game: GameModule;
16
+ /** The port to listen on: 8787 when left out, 0 for any free one */
17
+ port?: number;
18
+ /** A map of the game: each game is played on a world made from it, with a seat for each of its players with a start */
19
+ map?: GameMap;
20
+ /** A world made in code for each game, with the lobby's settings: in the place of a map. Says its `seats` too */
21
+ makeWorld?: (settings: Record<string, string>, context?: {
22
+ log?: Logger;
23
+ }) => World | Promise<World>;
24
+ /** The seats a player may take. Those of the map when left out */
25
+ seats?: ModeSeat[];
26
+ /** What the game does once a world is made, before anyone plays: a mission given, the first wave sent */
27
+ start?: (world: World, context: {
28
+ map?: GameMap;
29
+ settings: Record<string, string>;
30
+ }) => void | Promise<void>;
31
+ /**
32
+ * How a computer player in a seat plays (`ai` says which seats, and those nobody took are its too): its options by
33
+ * seat (`GameMode.ai`), or the brain that plays every seat of the computer (`defineBrain`), against everyone else's
34
+ * base; the first brain the game lists, against everyone else's base when left out; `null` for
35
+ * a game the computer does not play. `mode` for a brain by seat (`GameMode.brain`)
36
+ */
37
+ computer?: GameMode['ai'] | BrainDef | null;
38
+ /** A mode put together elsewhere, in the place of all of the above but the game */
39
+ mode?: GameMode;
40
+ /** What the mode is called. The map's name, or the game's */
41
+ name?: string;
42
+ }
43
+ /**
44
+ * Starts a server of a game, and resolves once it listens: a lobby that seats who joins, then games of it, one after
45
+ * the other, each on a world made anew.
46
+ *
47
+ * const server = await startServer({ game: rules, map, start: (world) => startMission(world) })
48
+ * // server.port, server.close()
49
+ *
50
+ * The parts are there on their own: `GameServer.start` with a `GameMode`, `mapMode`, `SessionHost`
51
+ *
52
+ * @beta
53
+ */
54
+ export declare function startServer(options: StartServerOptions): Promise<GameServer>;
@@ -0,0 +1,74 @@
1
+ import { type Logger } from '#engine/log';
2
+ import { createServer, type Server } from 'node:http';
3
+ import type { Transport } from '#engine/session/remote';
4
+ /**
5
+ * A connection, with what it came with: the address it was asked at, and who from
6
+ *
7
+ * @beta
8
+ */
9
+ export interface Connection extends Transport {
10
+ readonly url: string;
11
+ readonly address: string;
12
+ /** Bytes written to it so far, as they go over the wire: compressed, where it is */
13
+ readonly bytesSent: number;
14
+ /** Whether what goes over it is compressed (`permessage-deflate`) */
15
+ readonly compressed: boolean;
16
+ }
17
+ /** @beta */
18
+ export interface SocketServerOptions {
19
+ port: number;
20
+ /** Where it says what goes wrong with a connection. The root logger when left out */
21
+ log?: Logger;
22
+ /** Characters a message may have at most: a longer one closes the connection. 64 KB when left out */
23
+ maxMessage?: number;
24
+ /** Whether to compress what goes over connections whose other end can take it. Yes when left out */
25
+ compress?: boolean;
26
+ /**
27
+ * Seconds a connection may say nothing before it is closed: it is pinged meanwhile, and a browser answers a ping by
28
+ * itself, so only one that is gone (a machine that vanished without closing) goes. 60 when left out
29
+ */
30
+ idleTimeout?: number;
31
+ /**
32
+ * Bytes waiting to go out to a connection, at most: one that takes what it is sent too slowly is closed, where it
33
+ * once queued in the server's memory without end. 16 MB when left out
34
+ */
35
+ maxBuffered?: number;
36
+ /**
37
+ * Connections open at once, at most: one more is answered `503` and never upgraded (RV38). 1024 when left out
38
+ *
39
+ * @beta
40
+ */
41
+ maxConnections?: number;
42
+ /** What answers plain HTTP requests: a page saying what this is, by default */
43
+ onRequest?: Parameters<typeof createServer>[1];
44
+ }
45
+ /**
46
+ * Where a game server's connections come from (`GameServer.attach`): `onConnection` is told of each one made, `close`
47
+ * closes them all. A socket server, or a room of a port that several share (`GameRooms`)
48
+ *
49
+ * @beta
50
+ */
51
+ export interface ConnectionSource {
52
+ /** The port they come in at */
53
+ readonly port: number;
54
+ /** Who is told of each connection made: one handler, the last given */
55
+ onConnection(handler: (connection: Connection) => void): void;
56
+ /** Closes every connection it made */
57
+ close(): Promise<void>;
58
+ }
59
+ /**
60
+ * A WebSocket server: `onConnection` is told of each connection made. `close` stops it, and closes them all
61
+ *
62
+ * @beta
63
+ */
64
+ export interface SocketServer extends ConnectionSource {
65
+ readonly server: Server;
66
+ /** The port it listens on: the one given, or the one it was given for 0 */
67
+ readonly port: number;
68
+ }
69
+ /**
70
+ * Starts a WebSocket server, and resolves once it listens
71
+ *
72
+ * @beta
73
+ */
74
+ export declare function startSocketServer(options: SocketServerOptions): Promise<SocketServer>;