omegga 1.2.8 → 1.3.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 (255) hide show
  1. package/README.md +20 -1
  2. package/dist/brickadia/config.js +26 -90
  3. package/dist/brickadia/config.js.map +1 -1
  4. package/dist/brickadia/server.js +294 -293
  5. package/dist/brickadia/server.js.map +1 -1
  6. package/dist/cli/auth.js +149 -177
  7. package/dist/cli/auth.js.map +1 -1
  8. package/dist/cli/config.js +64 -66
  9. package/dist/cli/config.js.map +1 -1
  10. package/dist/cli/index.js +14 -14
  11. package/dist/cli/index.js.map +1 -1
  12. package/dist/cli/installer.js +37 -43
  13. package/dist/cli/installer.js.map +1 -1
  14. package/dist/cli/plugin.js +651 -682
  15. package/dist/cli/plugin.js.map +1 -1
  16. package/dist/cli/terminal.js +811 -733
  17. package/dist/cli/terminal.js.map +1 -1
  18. package/dist/config/formats/format_js.js +6 -6
  19. package/dist/config/formats/format_js.js.map +1 -1
  20. package/dist/config/formats/format_yml.js +7 -10
  21. package/dist/config/formats/format_yml.js.map +1 -1
  22. package/dist/config/index.js +46 -68
  23. package/dist/config/index.js.map +1 -1
  24. package/dist/config/reader.js +16 -27
  25. package/dist/config/reader.js.map +1 -1
  26. package/dist/config/validator.js +23 -25
  27. package/dist/config/validator.js.map +1 -1
  28. package/dist/config/writer.js +11 -21
  29. package/dist/config/writer.js.map +1 -1
  30. package/dist/index.js +18 -64
  31. package/dist/index.js.map +1 -1
  32. package/dist/info/default_commands.json.js +39 -0
  33. package/dist/info/default_commands.json.js.map +1 -0
  34. package/dist/logger.js +61 -60
  35. package/dist/logger.js.map +1 -1
  36. package/dist/main.js +424 -471
  37. package/dist/main.js.map +1 -1
  38. package/dist/omegga/auth.js +101 -148
  39. package/dist/omegga/auth.js.map +1 -1
  40. package/dist/omegga/commandInjector.js +261 -251
  41. package/dist/omegga/commandInjector.js.map +1 -1
  42. package/dist/omegga/index.js +14 -52
  43. package/dist/omegga/index.js.map +1 -1
  44. package/dist/omegga/logWrangler.js +224 -275
  45. package/dist/omegga/logWrangler.js.map +1 -1
  46. package/dist/omegga/matchers/auth.js +36 -50
  47. package/dist/omegga/matchers/auth.js.map +1 -1
  48. package/dist/omegga/matchers/chat.js +49 -71
  49. package/dist/omegga/matchers/chat.js.map +1 -1
  50. package/dist/omegga/matchers/command.js +25 -36
  51. package/dist/omegga/matchers/command.js.map +1 -1
  52. package/dist/omegga/matchers/exit.js +15 -18
  53. package/dist/omegga/matchers/exit.js.map +1 -1
  54. package/dist/omegga/matchers/index.js +26 -40
  55. package/dist/omegga/matchers/index.js.map +1 -1
  56. package/dist/omegga/matchers/init.js +20 -23
  57. package/dist/omegga/matchers/init.js.map +1 -1
  58. package/dist/omegga/matchers/interact.js +58 -64
  59. package/dist/omegga/matchers/interact.js.map +1 -1
  60. package/dist/omegga/matchers/join.js +74 -95
  61. package/dist/omegga/matchers/join.js.map +1 -1
  62. package/dist/omegga/matchers/leave.js +43 -56
  63. package/dist/omegga/matchers/leave.js.map +1 -1
  64. package/dist/omegga/matchers/mapChange.js +26 -35
  65. package/dist/omegga/matchers/mapChange.js.map +1 -1
  66. package/dist/omegga/matchers/minigameJoin.js +24 -31
  67. package/dist/omegga/matchers/minigameJoin.js.map +1 -1
  68. package/dist/omegga/matchers/version.js +42 -49
  69. package/dist/omegga/matchers/version.js.map +1 -1
  70. package/dist/omegga/player.js +527 -527
  71. package/dist/omegga/player.js.map +1 -1
  72. package/dist/omegga/plugin/interface.js +91 -98
  73. package/dist/omegga/plugin/interface.js.map +1 -1
  74. package/dist/omegga/plugin/plugin_jsonrpc_stdio.js +524 -429
  75. package/dist/omegga/plugin/plugin_jsonrpc_stdio.js.map +1 -1
  76. package/dist/omegga/plugin/plugin_node_safe/proxyOmegga.js +282 -294
  77. package/dist/omegga/plugin/plugin_node_safe/proxyOmegga.js.map +1 -1
  78. package/dist/omegga/plugin/plugin_node_safe.js +365 -393
  79. package/dist/omegga/plugin/plugin_node_safe.js.map +1 -1
  80. package/dist/omegga/plugin/plugin_node_unsafe.js +119 -179
  81. package/dist/omegga/plugin/plugin_node_unsafe.js.map +1 -1
  82. package/dist/omegga/plugin.js +402 -347
  83. package/dist/omegga/plugin.js.map +1 -1
  84. package/dist/omegga/server.js +742 -774
  85. package/dist/omegga/server.js.map +1 -1
  86. package/dist/omegga/wrapper.js +64 -91
  87. package/dist/omegga/wrapper.js.map +1 -1
  88. package/dist/plugin.js +11 -31
  89. package/dist/plugin.js.map +1 -1
  90. package/dist/softconfig.js +121 -100
  91. package/dist/softconfig.js.map +1 -1
  92. package/dist/updater/steam.js +97 -112
  93. package/dist/updater/steam.js.map +1 -1
  94. package/dist/util/brdb.js +496 -528
  95. package/dist/util/brdb.js.map +1 -1
  96. package/dist/util/brick/checkBounds.js +11 -15
  97. package/dist/util/brick/checkBounds.js.map +1 -1
  98. package/dist/util/brick/constants.js +723 -174
  99. package/dist/util/brick/constants.js.map +1 -1
  100. package/dist/util/brick/displayName.js +204 -211
  101. package/dist/util/brick/displayName.js.map +1 -1
  102. package/dist/util/brick/getBounds.js +29 -41
  103. package/dist/util/brick/getBounds.js.map +1 -1
  104. package/dist/util/brick/getBrickSize.js +6 -7
  105. package/dist/util/brick/getBrickSize.js.map +1 -1
  106. package/dist/util/brick/getScaleAxis.js +24 -30
  107. package/dist/util/brick/getScaleAxis.js.map +1 -1
  108. package/dist/util/brick/index.js +8 -29
  109. package/dist/util/brick/index.js.map +1 -1
  110. package/dist/util/brick/rotate.js +29 -34
  111. package/dist/util/brick/rotate.js.map +1 -1
  112. package/dist/util/brick/setOwnership.js +13 -19
  113. package/dist/util/brick/setOwnership.js.map +1 -1
  114. package/dist/util/chat.js +53 -44
  115. package/dist/util/chat.js.map +1 -1
  116. package/dist/util/color.js +112 -124
  117. package/dist/util/color.js.map +1 -1
  118. package/dist/util/file.js +54 -98
  119. package/dist/util/file.js.map +1 -1
  120. package/dist/util/index.js +84 -106
  121. package/dist/util/index.js.map +1 -1
  122. package/dist/util/map.js +18 -20
  123. package/dist/util/map.js.map +1 -1
  124. package/dist/util/pattern.js +6 -9
  125. package/dist/util/pattern.js.map +1 -1
  126. package/dist/util/time.js +31 -34
  127. package/dist/util/time.js.map +1 -1
  128. package/dist/util/uuid.js +10 -8
  129. package/dist/util/uuid.js.map +1 -1
  130. package/dist/util/wsl.js +19 -25
  131. package/dist/util/wsl.js.map +1 -1
  132. package/dist/version.js +7 -9
  133. package/dist/version.js.map +1 -1
  134. package/dist/webserver/backend/api.js +784 -874
  135. package/dist/webserver/backend/api.js.map +1 -1
  136. package/dist/webserver/backend/calendar.js +14 -17
  137. package/dist/webserver/backend/calendar.js.map +1 -1
  138. package/dist/webserver/backend/database.js +563 -613
  139. package/dist/webserver/backend/database.js.map +1 -1
  140. package/dist/webserver/backend/index.js +153 -191
  141. package/dist/webserver/backend/index.js.map +1 -1
  142. package/dist/webserver/backend/metrics.js +219 -248
  143. package/dist/webserver/backend/metrics.js.map +1 -1
  144. package/dist/webserver/backend/util.js +47 -68
  145. package/dist/webserver/backend/util.js.map +1 -1
  146. package/dist/worker.js +322 -0
  147. package/dist/worker.js.map +1 -0
  148. package/package.json +14 -10
  149. package/templates/safe-ts/omegga.d.ts +2 -2
  150. package/vite.backend.config.mts +46 -0
  151. package/vite.frontend.config.mts +58 -0
  152. package/vitest.backend.config.mts +7 -0
  153. package/dist/brickadia/config.d.ts +0 -3
  154. package/dist/brickadia/presets.d.ts +0 -65
  155. package/dist/brickadia/presets.js +0 -3
  156. package/dist/brickadia/presets.js.map +0 -1
  157. package/dist/brickadia/server.d.ts +0 -36
  158. package/dist/brickadia/types.d.ts +0 -45
  159. package/dist/brickadia/types.js +0 -3
  160. package/dist/brickadia/types.js.map +0 -1
  161. package/dist/cli/auth.d.ts +0 -26
  162. package/dist/cli/config.d.ts +0 -10
  163. package/dist/cli/index.d.ts +0 -30
  164. package/dist/cli/installer.d.ts +0 -1
  165. package/dist/cli/plugin.d.ts +0 -22
  166. package/dist/cli/terminal.d.ts +0 -25
  167. package/dist/config/authorizer.d.ts +0 -2
  168. package/dist/config/authorizer.js +0 -38
  169. package/dist/config/authorizer.js.map +0 -1
  170. package/dist/config/formats/format_js.d.ts +0 -3
  171. package/dist/config/formats/format_yml.d.ts +0 -3
  172. package/dist/config/index.d.ts +0 -18
  173. package/dist/config/reader.d.ts +0 -3
  174. package/dist/config/types.d.ts +0 -50
  175. package/dist/config/types.js +0 -3
  176. package/dist/config/types.js.map +0 -1
  177. package/dist/config/validator.d.ts +0 -6
  178. package/dist/config/writer.d.ts +0 -3
  179. package/dist/index.d.ts +0 -22
  180. package/dist/info/default_commands.json +0 -29
  181. package/dist/logger.d.ts +0 -41
  182. package/dist/main.d.ts +0 -1
  183. package/dist/omegga/auth.d.ts +0 -9
  184. package/dist/omegga/commandInjector.d.ts +0 -35
  185. package/dist/omegga/index.d.ts +0 -7
  186. package/dist/omegga/logWrangler.d.ts +0 -32
  187. package/dist/omegga/matchers/auth.d.ts +0 -10
  188. package/dist/omegga/matchers/chat.d.ts +0 -10
  189. package/dist/omegga/matchers/command.d.ts +0 -7
  190. package/dist/omegga/matchers/exit.d.ts +0 -3
  191. package/dist/omegga/matchers/index.d.ts +0 -3
  192. package/dist/omegga/matchers/init.d.ts +0 -3
  193. package/dist/omegga/matchers/interact.d.ts +0 -4
  194. package/dist/omegga/matchers/join.d.ts +0 -4
  195. package/dist/omegga/matchers/leave.d.ts +0 -4
  196. package/dist/omegga/matchers/mapChange.d.ts +0 -3
  197. package/dist/omegga/matchers/minigameJoin.d.ts +0 -9
  198. package/dist/omegga/matchers/types.d.ts +0 -5
  199. package/dist/omegga/matchers/types.js +0 -3
  200. package/dist/omegga/matchers/types.js.map +0 -1
  201. package/dist/omegga/matchers/version.d.ts +0 -3
  202. package/dist/omegga/player.d.ts +0 -81
  203. package/dist/omegga/plugin/interface.d.ts +0 -30
  204. package/dist/omegga/plugin/plugin_jsonrpc_stdio.d.ts +0 -23
  205. package/dist/omegga/plugin/plugin_node_safe/proxyOmegga.d.ts +0 -145
  206. package/dist/omegga/plugin/plugin_node_safe/worker.d.ts +0 -1
  207. package/dist/omegga/plugin/plugin_node_safe/worker.js +0 -367
  208. package/dist/omegga/plugin/plugin_node_safe/worker.js.map +0 -1
  209. package/dist/omegga/plugin/plugin_node_safe.d.ts +0 -23
  210. package/dist/omegga/plugin/plugin_node_unsafe.d.ts +0 -13
  211. package/dist/omegga/plugin.d.ts +0 -63
  212. package/dist/omegga/server.d.ts +0 -166
  213. package/dist/omegga/types.d.ts +0 -49
  214. package/dist/omegga/types.js +0 -3
  215. package/dist/omegga/types.js.map +0 -1
  216. package/dist/omegga/wrapper.d.ts +0 -32
  217. package/dist/plugin.d.ts +0 -916
  218. package/dist/softconfig.d.ts +0 -67
  219. package/dist/tsconfig.tsbuildinfo +0 -1
  220. package/dist/updater/index.d.ts +0 -1
  221. package/dist/updater/index.js +0 -10
  222. package/dist/updater/index.js.map +0 -1
  223. package/dist/updater/steam.d.ts +0 -52
  224. package/dist/util/brdb.d.ts +0 -31
  225. package/dist/util/brick/checkBounds.d.ts +0 -8
  226. package/dist/util/brick/constants.d.ts +0 -18
  227. package/dist/util/brick/displayName.d.ts +0 -7
  228. package/dist/util/brick/getBounds.d.ts +0 -5
  229. package/dist/util/brick/getBrickSize.d.ts +0 -3
  230. package/dist/util/brick/getScaleAxis.d.ts +0 -3
  231. package/dist/util/brick/index.d.ts +0 -14
  232. package/dist/util/brick/rotate.d.ts +0 -16
  233. package/dist/util/brick/setOwnership.d.ts +0 -12
  234. package/dist/util/chat.d.ts +0 -23
  235. package/dist/util/color.d.ts +0 -13
  236. package/dist/util/file.d.ts +0 -5
  237. package/dist/util/index.d.ts +0 -183
  238. package/dist/util/map.d.ts +0 -6
  239. package/dist/util/pattern.d.ts +0 -1
  240. package/dist/util/time.d.ts +0 -39
  241. package/dist/util/uuid.d.ts +0 -3
  242. package/dist/util/wsl.d.ts +0 -2
  243. package/dist/version.d.ts +0 -2
  244. package/dist/webserver/backend/api.d.ts +0 -115
  245. package/dist/webserver/backend/calendar.d.ts +0 -5
  246. package/dist/webserver/backend/database.d.ts +0 -150
  247. package/dist/webserver/backend/index.d.ts +0 -30
  248. package/dist/webserver/backend/metrics.d.ts +0 -3
  249. package/dist/webserver/backend/types.d.ts +0 -114
  250. package/dist/webserver/backend/types.js +0 -3
  251. package/dist/webserver/backend/types.js.map +0 -1
  252. package/dist/webserver/backend/util.d.ts +0 -2
  253. package/dist/webserver/index.d.ts +0 -2
  254. package/dist/webserver/index.js +0 -9
  255. package/dist/webserver/index.js.map +0 -1
@@ -1,311 +1,312 @@
1
1
  "use strict";
2
- /*
3
- Brickadia Server Wrapper
4
- Manages IO with the game server
5
- */
6
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
- if (kind === "m") throw new TypeError("Private method is not writable");
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
- };
12
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
13
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
14
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
15
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
16
- };
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- var _BrickadiaServer_child, _BrickadiaServer_errInterface, _BrickadiaServer_outInterface;
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- const logger_1 = __importDefault(require("../logger"));
23
- const softconfig_1 = require("../softconfig");
24
- const auth_1 = require("../cli/auth");
25
- const wsl_1 = require("../util/wsl");
26
- const child_process_1 = require("child_process");
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const logger = require("../logger.js");
4
+ const softconfig = require("../softconfig.js");
5
+ const auth = require("../cli/auth.js");
6
+ const wsl = require("../util/wsl.js");
27
7
  require("colors");
28
- const events_1 = __importDefault(require("events"));
29
- const fs_1 = require("fs");
30
- const path_1 = __importDefault(require("path"));
31
- const process_1 = require("process");
32
- const readline_1 = __importDefault(require("readline"));
33
- const strip_ansi_1 = __importDefault(require("strip-ansi"));
34
- // list of errors that can be solved by yelling at the user
8
+ const fs = require("node:fs");
9
+ const node_child_process = require("node:child_process");
10
+ const EventEmitter = require("node:events");
11
+ const path = require("node:path");
12
+ const node_process = require("node:process");
13
+ const readline = require("readline");
14
+ const stripAnsi = require("strip-ansi");
35
15
  const knownErrors = [
36
- {
37
- name: 'MISSING_LIBGL',
38
- solution: 'apt-get install libgl1-mesa-glx libglib2.0-0',
39
- match: /error while loading shared libraries: libGL\.so\.1: cannot open shared object file/,
40
- },
41
- {
42
- name: 'MISSING_GLIB',
43
- solution: 'apt-get install libgl1-mesa-glx libglib2.0-0',
44
- match: /error while loading shared libraries: libgthread-2\.0\.so\.0: cannot open shared object file/,
45
- },
16
+ {
17
+ name: "MISSING_LIBGL",
18
+ solution: "apt-get install libgl1-mesa-glx libglib2.0-0",
19
+ match: /error while loading shared libraries: libGL\.so\.1: cannot open shared object file/
20
+ },
21
+ {
22
+ name: "MISSING_GLIB",
23
+ solution: "apt-get install libgl1-mesa-glx libglib2.0-0",
24
+ match: /error while loading shared libraries: libgthread-2\.0\.so\.0: cannot open shared object file/
25
+ }
46
26
  ];
47
- /** Start a brickadia server */
48
- class BrickadiaServer extends events_1.default {
49
- constructor(dataPath, config) {
50
- super();
51
- _BrickadiaServer_child.set(this, null);
52
- _BrickadiaServer_errInterface.set(this, null);
53
- _BrickadiaServer_outInterface.set(this, null);
54
- this.config = config;
55
- // use the data path if it's absolute, otherwise build an absolute path
56
- this.path =
57
- path_1.default.isAbsolute(dataPath) || dataPath.startsWith('/')
58
- ? dataPath
59
- : path_1.default.join(process.cwd(), dataPath);
60
- this.lineListener = this.lineListener.bind(this);
61
- this.errorListener = this.errorListener.bind(this);
62
- this.exitListener = this.exitListener.bind(this);
63
- }
64
- getActiveWorldFile() {
65
- return path_1.default.join(this.path, softconfig_1.ACTIVE_WORLD_FILE);
66
- }
67
- /** A world specified by the active world file */
68
- getActiveWorld() {
69
- const activeWorldFile = this.getActiveWorldFile();
70
- if ((0, fs_1.existsSync)(activeWorldFile)) {
71
- try {
72
- return (0, fs_1.readFileSync)(activeWorldFile, 'utf8').trim();
73
- }
74
- catch (err) {
75
- logger_1.default.errorp('Failed to read active world file', activeWorldFile.yellow, err);
76
- return null;
77
- }
78
- }
27
+ class BrickadiaServer extends EventEmitter {
28
+ #child = null;
29
+ #errInterface = null;
30
+ #outInterface = null;
31
+ constructor(dataPath, config) {
32
+ super();
33
+ this.config = config;
34
+ this.path = path.isAbsolute(dataPath) || dataPath.startsWith("/") ? dataPath : path.join(process.cwd(), dataPath);
35
+ this.lineListener = this.lineListener.bind(this);
36
+ this.errorListener = this.errorListener.bind(this);
37
+ this.exitListener = this.exitListener.bind(this);
38
+ }
39
+ getActiveWorldFile() {
40
+ return path.join(this.path, softconfig.ACTIVE_WORLD_FILE);
41
+ }
42
+ /** A world specified by the active world file */
43
+ getActiveWorld() {
44
+ const activeWorldFile = this.getActiveWorldFile();
45
+ if (fs.existsSync(activeWorldFile)) {
46
+ try {
47
+ return fs.readFileSync(activeWorldFile, "utf8").trim();
48
+ } catch (err) {
49
+ logger.default.errorp(
50
+ "Failed to read active world file",
51
+ activeWorldFile.yellow,
52
+ err
53
+ );
79
54
  return null;
55
+ }
80
56
  }
81
- /** Set the world to use next startup */
82
- setActiveWorld(world) {
83
- const activeWorldFile = this.getActiveWorldFile();
84
- if (!world || world === null) {
85
- if ((0, fs_1.existsSync)(activeWorldFile)) {
86
- logger_1.default.verbose('Removing active world file', activeWorldFile.yellow);
87
- (0, fs_1.unlinkSync)(activeWorldFile);
88
- }
89
- return true;
90
- }
91
- if (!this.worldExists(world)) {
92
- logger_1.default.verbose('Cannot set active world to', world.yellow, 'as it does not exist');
93
- return false;
94
- }
95
- logger_1.default.verbose('Setting active world to', world.yellow);
96
- try {
97
- (0, fs_1.writeFileSync)(activeWorldFile, world, 'utf8');
98
- return true;
99
- }
100
- catch (err) {
101
- logger_1.default.errorp('Failed to write active world file', activeWorldFile.yellow, err);
102
- return false;
103
- }
104
- }
105
- /** A world specified by the config */
106
- getConfigWorld() {
107
- var _a, _b, _c;
108
- return (_c = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.server) === null || _b === void 0 ? void 0 : _b.world) !== null && _c !== void 0 ? _c : null;
109
- }
110
- /** A world specified by the BRICKADIA_WORLD env variable */
111
- getEnvWorld() {
112
- return process_1.env.BRICKADIA_WORLD || null;
113
- }
114
- /** Check if a world exists */
115
- worldExists(world) {
116
- var _a, _b, _c;
117
- const savedDir = (_c = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.server) === null || _b === void 0 ? void 0 : _b.savedDir) !== null && _c !== void 0 ? _c : softconfig_1.CONFIG_SAVED_DIR;
118
- const worldPath = path_1.default.join(this.path, savedDir, 'Worlds', world + '.brdb');
119
- return (0, fs_1.existsSync)(worldPath);
120
- }
121
- /** Get the world that will be used next startup */
122
- getNextWorld() {
123
- var _a;
124
- const candidates = [
125
- { source: 'file', file: this.getActiveWorld() },
126
- { source: 'config', file: this.getConfigWorld() },
127
- { source: 'env', file: this.getEnvWorld() },
128
- ];
129
- return ((_a = candidates.find(({ file }) => file && this.worldExists(file))) !== null && _a !== void 0 ? _a : null);
130
- }
131
- // start the server child process
132
- start() {
133
- var _a;
134
- const { email, password, token: confToken, } = this.config
135
- .credentials || {};
136
- const token = confToken || process.env.BRICKADIA_TOKEN || (0, auth_1.getGlobalToken)();
137
- if (token) {
138
- logger_1.default.verbose('Starting server with hosting token');
139
- }
140
- else {
141
- logger_1.default.verbose('Starting server', (!email && !password ? 'without' : 'with').yellow, 'credentials');
142
- }
143
- const isSteam = !this.config.server.branch;
144
- const steamBeta = (_a = this.config.server.steambeta) !== null && _a !== void 0 ? _a : 'main';
145
- const overrideBinary = softconfig_1.OVERRIDE_GAME_DIR &&
146
- path_1.default.join(softconfig_1.OVERRIDE_GAME_DIR, // from BRICKADIA_DIR env
147
- softconfig_1.GAME_BIN_PATH);
148
- const steamBinary = path_1.default.join(softconfig_1.GAME_INSTALL_DIR, // steam install directory
149
- steamBeta, // steam beta branch (or main)
150
- softconfig_1.GAME_DIRNAME, // Brickadia
151
- softconfig_1.GAME_BIN_PATH);
152
- let gameBinary = steamBinary;
153
- if (overrideBinary) {
154
- if (!(0, fs_1.existsSync)(overrideBinary)) {
155
- logger_1.default.error('Override binary', overrideBinary.yellow, 'does not exist!');
156
- throw new Error(`Override binary ${overrideBinary} does not exist!`);
157
- }
158
- logger_1.default.verbose('Using override binary', overrideBinary.yellow, 'instead of', steamBinary.yellow);
159
- gameBinary = overrideBinary;
160
- }
161
- else if (isSteam) {
162
- logger_1.default.verbose('Using steam binary', steamBeta.yellow);
163
- }
164
- else {
165
- logger_1.default.verbose('Running', (this.config.server.__LOCAL
166
- ? path_1.default.join(__dirname, '../../tools/brickadia.sh')
167
- : 'brickadia launcher').yellow);
168
- if (typeof this.config.server.branch === 'string')
169
- logger_1.default.verbose('Using branch', this.config.server.branch.yellow);
170
- }
171
- // handle local launcher support
172
- const launchArgs = isSteam
173
- ? [gameBinary]
174
- : [
175
- this.config.server.__LOCAL
176
- ? path_1.default.join(__dirname, '../../tools/brickadia.sh')
177
- : 'brickadia',
178
- this.config.server.branch && `--branch=${this.config.server.branch}`,
179
- '--server',
180
- '--',
181
- ];
182
- const world = this.getNextWorld();
183
- if (world) {
184
- logger_1.default.verbose('Using world', world.file.yellow, 'from', world.source.yellow);
185
- }
186
- else if (this.config.server.map) {
187
- logger_1.default.verbose('Using map', this.config.server.map.yellow, 'from config');
188
- }
189
- const params = [
190
- '--output=L',
191
- '--',
192
- ...launchArgs,
193
- !world &&
194
- this.config.server.map &&
195
- `-Environment="${this.config.server.map}"`,
196
- world && `-World="${world.file}"`,
197
- '-NotInstalled',
198
- '-log',
199
- (0, wsl_1.checkWsl)() === 1 ? '-OneThread' : null,
200
- this.path ? `-UserDir="${this.path}"` : null,
201
- token ? `-Token="${token}"` : null, // remove token argument if not provided
202
- !token && email ? `-User="${email}"` : null, // remove email argument if not provided or token is provided
203
- !token && password ? `-Password="${password}"` : null, // remove password argument if not provided or token is provided
204
- `-port="${this.config.server.port}"`,
205
- this.config.server.launchArgs,
206
- ].filter(Boolean); // remove unused arguments
207
- logger_1.default.verbose('Params for spawn', params
208
- .join(' ')
209
- .replace(/-User=".*?"/, '-User="<hidden>"')
210
- .replace(/-Password=".*?"/, '-Password="<hidden>"')
211
- .replace(/-Token=".*?"/, '-Token="<hidden>"'));
212
- // Either unbuffer or stdbuf must be used because brickadia's output is buffered
213
- // this means that multiple lines can be bundled together if the output buffer is not full
214
- // unfortunately without stdbuf or unbuffer, the output would not happen immediately
215
- __classPrivateFieldSet(this, _BrickadiaServer_child, (0, child_process_1.spawn)('stdbuf', params), "f");
216
- logger_1.default.verbose('Spawn process', __classPrivateFieldGet(this, _BrickadiaServer_child, "f") ? __classPrivateFieldGet(this, _BrickadiaServer_child, "f").pid : 'failed'.red);
217
- __classPrivateFieldGet(this, _BrickadiaServer_child, "f").stdin.setDefaultEncoding('utf8');
218
- __classPrivateFieldSet(this, _BrickadiaServer_outInterface, readline_1.default.createInterface({
219
- input: __classPrivateFieldGet(this, _BrickadiaServer_child, "f").stdout,
220
- terminal: false,
221
- }), "f");
222
- __classPrivateFieldSet(this, _BrickadiaServer_errInterface, readline_1.default.createInterface({
223
- input: __classPrivateFieldGet(this, _BrickadiaServer_child, "f").stderr,
224
- terminal: false,
225
- }), "f");
226
- this.attachListeners();
227
- logger_1.default.verbose('Attached listeners');
57
+ return null;
58
+ }
59
+ /** Set the world to use next startup */
60
+ setActiveWorld(world) {
61
+ const activeWorldFile = this.getActiveWorldFile();
62
+ if (!world || world === null) {
63
+ if (fs.existsSync(activeWorldFile)) {
64
+ logger.default.verbose("Removing active world file", activeWorldFile.yellow);
65
+ fs.unlinkSync(activeWorldFile);
66
+ }
67
+ return true;
228
68
  }
229
- // write a string to the child process
230
- write(line) {
231
- if (line.length >= 512) {
232
- // show a warning
233
- logger_1.default.warn('WARNING'.yellow, 'The following line was called and is', 'longer than allowed limit'.red);
234
- logger_1.default.warn(line.replace(/\n$/, ''));
235
- // throw a fake error to get the line number
236
- try {
237
- throw new Error('Console Line Too Long');
238
- }
239
- catch (err) {
240
- logger_1.default.warn(err);
241
- }
242
- return;
243
- }
244
- if (__classPrivateFieldGet(this, _BrickadiaServer_child, "f")) {
245
- logger_1.default.verbose('WRITE'.green, line.replace(/\n$/, ''));
246
- __classPrivateFieldGet(this, _BrickadiaServer_child, "f").stdin.write(line);
247
- }
69
+ if (!this.worldExists(world)) {
70
+ logger.default.verbose(
71
+ "Cannot set active world to",
72
+ world.yellow,
73
+ "as it does not exist"
74
+ );
75
+ return false;
248
76
  }
249
- // write a line to the child process
250
- writeln(line) {
251
- this.write(line + '\n');
77
+ logger.default.verbose("Setting active world to", world.yellow);
78
+ try {
79
+ fs.writeFileSync(activeWorldFile, world, "utf8");
80
+ return true;
81
+ } catch (err) {
82
+ logger.default.errorp(
83
+ "Failed to write active world file",
84
+ activeWorldFile.yellow,
85
+ err
86
+ );
87
+ return false;
252
88
  }
253
- // forcibly kills the server
254
- stop() {
255
- if (!__classPrivateFieldGet(this, _BrickadiaServer_child, "f")) {
256
- logger_1.default.verbose('Cannot stop server as no subprocess exists');
257
- return;
258
- }
259
- logger_1.default.verbose('Forcibly stopping server');
260
- // kill the process
261
- __classPrivateFieldGet(this, _BrickadiaServer_child, "f").kill('SIGINT');
262
- // ...kill it again just to make sure it's dead
263
- (0, child_process_1.spawn)('kill', ['-9', __classPrivateFieldGet(this, _BrickadiaServer_child, "f").pid + '']);
89
+ }
90
+ /** A world specified by the config */
91
+ getConfigWorld() {
92
+ return this.config?.server?.world ?? null;
93
+ }
94
+ /** A world specified by the BRICKADIA_WORLD env variable */
95
+ getEnvWorld() {
96
+ return node_process.env.BRICKADIA_WORLD || null;
97
+ }
98
+ /** Check if a world exists */
99
+ worldExists(world) {
100
+ const savedDir = this.config?.server?.savedDir ?? softconfig.CONFIG_SAVED_DIR;
101
+ const worldPath = path.join(this.path, savedDir, "Worlds", world + ".brdb");
102
+ return fs.existsSync(worldPath);
103
+ }
104
+ /** Get the world that will be used next startup */
105
+ getNextWorld() {
106
+ const candidates = [
107
+ { source: "file", file: this.getActiveWorld() },
108
+ { source: "config", file: this.getConfigWorld() },
109
+ { source: "env", file: this.getEnvWorld() }
110
+ ];
111
+ return candidates.find(({ file }) => file && this.worldExists(file)) ?? null;
112
+ }
113
+ // start the server child process
114
+ start() {
115
+ const {
116
+ email,
117
+ password,
118
+ token: confToken
119
+ } = this.config.credentials || {};
120
+ const token = confToken || process.env.BRICKADIA_TOKEN || auth.getGlobalToken();
121
+ if (token) {
122
+ logger.default.verbose("Starting server with hosting token");
123
+ } else {
124
+ logger.default.verbose(
125
+ "Starting server",
126
+ (!email && !password ? "without" : "with").yellow,
127
+ "credentials"
128
+ );
264
129
  }
265
- // detaches listeners
266
- cleanup() {
267
- if (!__classPrivateFieldGet(this, _BrickadiaServer_child, "f"))
268
- return;
269
- logger_1.default.verbose('Cleaning up brickadia server');
270
- // detach listener
271
- this.detachListeners();
272
- __classPrivateFieldSet(this, _BrickadiaServer_child, null, "f");
273
- __classPrivateFieldSet(this, _BrickadiaServer_outInterface, null, "f");
274
- __classPrivateFieldSet(this, _BrickadiaServer_errInterface, null, "f");
130
+ const isSteam = !this.config.server.branch;
131
+ const steamBeta = this.config.server.steambeta ?? "main";
132
+ const overrideBinary = softconfig.OVERRIDE_GAME_DIR && path.join(
133
+ softconfig.OVERRIDE_GAME_DIR,
134
+ // from BRICKADIA_DIR env
135
+ softconfig.GAME_BIN_PATH
136
+ );
137
+ const steamBinary = path.join(
138
+ softconfig.GAME_INSTALL_DIR,
139
+ // steam install directory
140
+ steamBeta,
141
+ // steam beta branch (or main)
142
+ softconfig.GAME_DIRNAME,
143
+ // Brickadia
144
+ softconfig.GAME_BIN_PATH
145
+ // path to binary
146
+ );
147
+ let gameBinary = steamBinary;
148
+ if (overrideBinary) {
149
+ if (!fs.existsSync(overrideBinary)) {
150
+ logger.default.error(
151
+ "Override binary",
152
+ overrideBinary.yellow,
153
+ "does not exist!"
154
+ );
155
+ throw new Error(`Override binary ${overrideBinary} does not exist!`);
156
+ }
157
+ logger.default.verbose(
158
+ "Using override binary",
159
+ overrideBinary.yellow,
160
+ "instead of",
161
+ steamBinary.yellow
162
+ );
163
+ gameBinary = overrideBinary;
164
+ } else if (isSteam) {
165
+ logger.default.verbose("Using steam binary", steamBeta.yellow);
166
+ } else {
167
+ logger.default.verbose(
168
+ "Running",
169
+ (this.config.server.__LOCAL ? path.join(__dirname, "../../tools/brickadia.sh") : "brickadia launcher").yellow
170
+ );
171
+ if (typeof this.config.server.branch === "string")
172
+ logger.default.verbose("Using branch", this.config.server.branch.yellow);
275
173
  }
276
- // attaches proxy event listeners
277
- attachListeners() {
278
- __classPrivateFieldGet(this, _BrickadiaServer_outInterface, "f").on('line', this.lineListener);
279
- __classPrivateFieldGet(this, _BrickadiaServer_errInterface, "f").on('line', this.errorListener);
280
- __classPrivateFieldGet(this, _BrickadiaServer_child, "f").on('exit', this.exitListener);
281
- __classPrivateFieldGet(this, _BrickadiaServer_child, "f").on('close', () => { });
174
+ const launchArgs = isSteam ? [gameBinary] : [
175
+ this.config.server.__LOCAL ? path.join(__dirname, "../../tools/brickadia.sh") : "brickadia",
176
+ this.config.server.branch && `--branch=${this.config.server.branch}`,
177
+ "--server",
178
+ "--"
179
+ ];
180
+ const world = this.getNextWorld();
181
+ if (world) {
182
+ logger.default.verbose(
183
+ "Using world",
184
+ world.file.yellow,
185
+ "from",
186
+ world.source.yellow
187
+ );
188
+ } else if (this.config.server.map) {
189
+ logger.default.verbose("Using map", this.config.server.map.yellow, "from config");
282
190
  }
283
- // removes previously attached proxy event listeners
284
- detachListeners() {
285
- __classPrivateFieldGet(this, _BrickadiaServer_outInterface, "f").off('line', this.lineListener);
286
- __classPrivateFieldGet(this, _BrickadiaServer_errInterface, "f").off('line', this.errorListener);
287
- __classPrivateFieldGet(this, _BrickadiaServer_child, "f").off('exit', this.exitListener);
288
- __classPrivateFieldGet(this, _BrickadiaServer_child, "f").removeAllListeners('close');
191
+ const params = [
192
+ "--output=L",
193
+ "--",
194
+ ...launchArgs,
195
+ !world && this.config.server.map && `-Environment="${this.config.server.map}"`,
196
+ world && `-World="${world.file}"`,
197
+ "-NotInstalled",
198
+ "-log",
199
+ wsl.checkWsl() === 1 ? "-OneThread" : null,
200
+ this.path ? `-UserDir="${this.path}"` : null,
201
+ token ? `-Token="${token}"` : null,
202
+ // remove token argument if not provided
203
+ !token && email ? `-User="${email}"` : null,
204
+ // remove email argument if not provided or token is provided
205
+ !token && password ? `-Password="${password}"` : null,
206
+ // remove password argument if not provided or token is provided
207
+ `-port="${this.config.server.port}"`,
208
+ this.config.server.launchArgs
209
+ ].filter(Boolean);
210
+ logger.default.verbose(
211
+ "Params for spawn",
212
+ params.join(" ").replace(/-User=".*?"/, '-User="<hidden>"').replace(/-Password=".*?"/, '-Password="<hidden>"').replace(/-Token=".*?"/, '-Token="<hidden>"')
213
+ );
214
+ this.#child = node_child_process.spawn("stdbuf", params);
215
+ logger.default.verbose(
216
+ "Spawn process",
217
+ this.#child ? this.#child.pid : "failed".red
218
+ );
219
+ this.#child.stdin.setDefaultEncoding("utf8");
220
+ this.#outInterface = readline.createInterface({
221
+ input: this.#child.stdout,
222
+ terminal: false
223
+ });
224
+ this.#errInterface = readline.createInterface({
225
+ input: this.#child.stderr,
226
+ terminal: false
227
+ });
228
+ this.attachListeners();
229
+ logger.default.verbose("Attached listeners");
230
+ }
231
+ // write a string to the child process
232
+ write(line) {
233
+ if (line.length >= 512) {
234
+ logger.default.warn(
235
+ "WARNING".yellow,
236
+ "The following line was called and is",
237
+ "longer than allowed limit".red
238
+ );
239
+ logger.default.warn(line.replace(/\n$/, ""));
240
+ try {
241
+ throw new Error("Console Line Too Long");
242
+ } catch (err) {
243
+ logger.default.warn(err);
244
+ }
245
+ return;
289
246
  }
290
- // -- listeners for basic events (line, err, exit)
291
- errorListener(line) {
292
- logger_1.default.verbose('ERROR'.red, line);
293
- this.emit('err', line);
294
- for (const { match, solution, name, message } of knownErrors) {
295
- if (line.match(match)) {
296
- logger_1.default.error(`Encountered ${name.red}. ${solution ? 'Known fix:\n ' + solution : message || 'Unknown error.'}`);
297
- }
298
- }
247
+ if (this.#child) {
248
+ logger.default.verbose("WRITE".green, line.replace(/\n$/, ""));
249
+ this.#child.stdin.write(line);
299
250
  }
300
- exitListener(...args) {
301
- logger_1.default.verbose('Exit listener fired');
302
- this.emit('closed', ...args);
303
- this.cleanup();
251
+ }
252
+ // write a line to the child process
253
+ writeln(line) {
254
+ this.write(line + "\n");
255
+ }
256
+ // forcibly kills the server
257
+ stop() {
258
+ if (!this.#child) {
259
+ logger.default.verbose("Cannot stop server as no subprocess exists");
260
+ return;
304
261
  }
305
- lineListener(line) {
306
- this.emit('line', (0, strip_ansi_1.default)(line));
262
+ logger.default.verbose("Forcibly stopping server");
263
+ this.#child.kill("SIGINT");
264
+ node_child_process.spawn("kill", ["-9", this.#child.pid + ""]);
265
+ }
266
+ // detaches listeners
267
+ cleanup() {
268
+ if (!this.#child) return;
269
+ logger.default.verbose("Cleaning up brickadia server");
270
+ this.detachListeners();
271
+ this.#child = null;
272
+ this.#outInterface = null;
273
+ this.#errInterface = null;
274
+ }
275
+ // attaches proxy event listeners
276
+ attachListeners() {
277
+ this.#outInterface.on("line", this.lineListener);
278
+ this.#errInterface.on("line", this.errorListener);
279
+ this.#child.on("exit", this.exitListener);
280
+ this.#child.on("close", () => {
281
+ });
282
+ }
283
+ // removes previously attached proxy event listeners
284
+ detachListeners() {
285
+ this.#outInterface.off("line", this.lineListener);
286
+ this.#errInterface.off("line", this.errorListener);
287
+ this.#child.off("exit", this.exitListener);
288
+ this.#child.removeAllListeners("close");
289
+ }
290
+ // -- listeners for basic events (line, err, exit)
291
+ errorListener(line) {
292
+ logger.default.verbose("ERROR".red, line);
293
+ this.emit("err", line);
294
+ for (const { match, solution, name, message } of knownErrors) {
295
+ if (line.match(match)) {
296
+ logger.default.error(
297
+ `Encountered ${name.red}. ${solution ? "Known fix:\n " + solution : message || "Unknown error."}`
298
+ );
299
+ }
307
300
  }
301
+ }
302
+ exitListener(...args) {
303
+ logger.default.verbose("Exit listener fired");
304
+ this.emit("closed", ...args);
305
+ this.cleanup();
306
+ }
307
+ lineListener(line) {
308
+ this.emit("line", stripAnsi(line));
309
+ }
308
310
  }
309
- _BrickadiaServer_child = new WeakMap(), _BrickadiaServer_errInterface = new WeakMap(), _BrickadiaServer_outInterface = new WeakMap();
310
311
  exports.default = BrickadiaServer;
311
- //# sourceMappingURL=server.js.map
312
+ //# sourceMappingURL=server.js.map