omegga 0.1.83 → 1.0.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 (463) hide show
  1. package/.vscode/settings.json +20 -0
  2. package/README.md +142 -62
  3. package/bin/omegga +10 -4
  4. package/dist/brickadia/config.d.ts +3 -0
  5. package/dist/brickadia/config.d.ts.map +1 -0
  6. package/dist/brickadia/config.js +61 -0
  7. package/dist/brickadia/config.js.map +1 -0
  8. package/dist/brickadia/presets.d.ts +65 -0
  9. package/dist/brickadia/presets.js +3 -0
  10. package/dist/brickadia/presets.js.map +1 -0
  11. package/dist/brickadia/server.d.ts +20 -0
  12. package/dist/brickadia/server.d.ts.map +1 -0
  13. package/dist/brickadia/server.js +188 -0
  14. package/dist/brickadia/server.js.map +1 -0
  15. package/dist/brickadia/types.d.ts +45 -0
  16. package/dist/brickadia/types.d.ts.map +1 -0
  17. package/dist/brickadia/types.js +3 -0
  18. package/dist/brickadia/types.js.map +1 -0
  19. package/dist/cli/auth.d.ts +20 -0
  20. package/dist/cli/auth.d.ts.map +1 -0
  21. package/dist/cli/auth.js +115 -0
  22. package/dist/cli/auth.js.map +1 -0
  23. package/dist/cli/config.d.ts +10 -0
  24. package/dist/cli/config.d.ts.map +1 -0
  25. package/dist/cli/config.js +72 -0
  26. package/dist/cli/config.js.map +1 -0
  27. package/dist/cli/index.d.ts +20 -0
  28. package/dist/cli/index.d.ts.map +1 -0
  29. package/dist/cli/index.js +15 -0
  30. package/dist/cli/index.js.map +1 -0
  31. package/dist/cli/installer.d.ts +1 -0
  32. package/dist/cli/installer.d.ts.map +1 -0
  33. package/dist/cli/installer.js +55 -0
  34. package/dist/cli/installer.js.map +1 -0
  35. package/dist/cli/plugin.d.ts +11 -0
  36. package/dist/cli/plugin.d.ts.map +1 -0
  37. package/dist/cli/plugin.js +596 -0
  38. package/dist/cli/plugin.js.map +1 -0
  39. package/dist/cli/terminal.d.ts +34 -0
  40. package/dist/cli/terminal.d.ts.map +1 -0
  41. package/dist/cli/terminal.js +395 -0
  42. package/dist/cli/terminal.js.map +1 -0
  43. package/dist/config/authorizer.d.ts +2 -0
  44. package/dist/config/authorizer.d.ts.map +1 -0
  45. package/dist/config/authorizer.js +38 -0
  46. package/dist/config/authorizer.js.map +1 -0
  47. package/dist/config/formats/format_js.d.ts +3 -0
  48. package/dist/config/formats/format_js.d.ts.map +1 -0
  49. package/dist/config/formats/format_js.js +10 -0
  50. package/dist/config/formats/format_js.js.map +1 -0
  51. package/dist/config/formats/format_yml.d.ts +3 -0
  52. package/dist/config/formats/format_yml.d.ts.map +1 -0
  53. package/dist/config/formats/format_yml.js +14 -0
  54. package/dist/config/formats/format_yml.js.map +1 -0
  55. package/dist/config/index.d.ts +18 -0
  56. package/dist/config/index.d.ts.map +1 -0
  57. package/dist/config/index.js +86 -0
  58. package/dist/config/index.js.map +1 -0
  59. package/dist/config/reader.d.ts +3 -0
  60. package/dist/config/reader.d.ts.map +1 -0
  61. package/dist/config/reader.js +30 -0
  62. package/dist/config/reader.js.map +1 -0
  63. package/dist/config/types.d.ts +37 -0
  64. package/dist/config/types.d.ts.map +1 -0
  65. package/dist/config/types.js +3 -0
  66. package/dist/config/types.js.map +1 -0
  67. package/dist/config/validator.d.ts +6 -0
  68. package/dist/config/validator.d.ts.map +1 -0
  69. package/dist/config/validator.js +26 -0
  70. package/dist/config/validator.js.map +1 -0
  71. package/dist/config/writer.d.ts +3 -0
  72. package/dist/config/writer.d.ts.map +1 -0
  73. package/dist/config/writer.js +25 -0
  74. package/dist/config/writer.js.map +1 -0
  75. package/dist/index.d.ts +22 -0
  76. package/dist/index.js +55 -0
  77. package/dist/index.js.map +1 -0
  78. package/dist/info/default_commands.json +28 -0
  79. package/dist/lib.d.ts +21 -0
  80. package/dist/lib.d.ts.map +1 -0
  81. package/dist/lib.js +54 -0
  82. package/dist/lib.js.map +1 -0
  83. package/dist/logger.d.ts +41 -0
  84. package/dist/logger.js +67 -0
  85. package/dist/logger.js.map +1 -0
  86. package/dist/main.d.ts +1 -0
  87. package/dist/main.d.ts.map +1 -0
  88. package/dist/main.js +284 -0
  89. package/dist/main.js.map +1 -0
  90. package/dist/omegga/auth.d.ts +6 -0
  91. package/dist/omegga/auth.d.ts.map +1 -0
  92. package/dist/omegga/auth.js +139 -0
  93. package/dist/omegga/auth.js.map +1 -0
  94. package/dist/omegga/commandInjector.d.ts +35 -0
  95. package/dist/omegga/commandInjector.d.ts.map +1 -0
  96. package/dist/omegga/commandInjector.js +234 -0
  97. package/dist/omegga/commandInjector.js.map +1 -0
  98. package/dist/omegga/index.d.ts +7 -0
  99. package/dist/omegga/index.d.ts.map +1 -0
  100. package/dist/omegga/index.js +43 -0
  101. package/dist/omegga/index.js.map +1 -0
  102. package/dist/omegga/logWrangler.d.ts +32 -0
  103. package/dist/omegga/logWrangler.d.ts.map +1 -0
  104. package/dist/omegga/logWrangler.js +279 -0
  105. package/dist/omegga/logWrangler.js.map +1 -0
  106. package/dist/omegga/matchers/auth.d.ts +9 -0
  107. package/dist/omegga/matchers/auth.d.ts.map +1 -0
  108. package/dist/omegga/matchers/auth.js +53 -0
  109. package/dist/omegga/matchers/auth.js.map +1 -0
  110. package/dist/omegga/matchers/chat.d.ts +9 -0
  111. package/dist/omegga/matchers/chat.d.ts.map +1 -0
  112. package/dist/omegga/matchers/chat.js +68 -0
  113. package/dist/omegga/matchers/chat.js.map +1 -0
  114. package/dist/omegga/matchers/command.d.ts +7 -0
  115. package/dist/omegga/matchers/command.d.ts.map +1 -0
  116. package/dist/omegga/matchers/command.js +39 -0
  117. package/dist/omegga/matchers/command.js.map +1 -0
  118. package/dist/omegga/matchers/exit.d.ts +3 -0
  119. package/dist/omegga/matchers/exit.d.ts.map +1 -0
  120. package/dist/omegga/matchers/exit.js +21 -0
  121. package/dist/omegga/matchers/exit.js.map +1 -0
  122. package/dist/omegga/matchers/index.d.ts +3 -0
  123. package/dist/omegga/matchers/index.d.ts.map +1 -0
  124. package/dist/omegga/matchers/index.js +39 -0
  125. package/dist/omegga/matchers/index.js.map +1 -0
  126. package/dist/omegga/matchers/init.d.ts +3 -0
  127. package/dist/omegga/matchers/init.d.ts.map +1 -0
  128. package/dist/omegga/matchers/init.js +26 -0
  129. package/dist/omegga/matchers/init.js.map +1 -0
  130. package/dist/omegga/matchers/interact.d.ts +4 -0
  131. package/dist/omegga/matchers/interact.js +39 -0
  132. package/dist/omegga/matchers/interact.js.map +1 -0
  133. package/dist/omegga/matchers/join.d.ts +4 -0
  134. package/dist/omegga/matchers/join.d.ts.map +1 -0
  135. package/dist/omegga/matchers/join.js +95 -0
  136. package/dist/omegga/matchers/join.js.map +1 -0
  137. package/dist/omegga/matchers/leave.d.ts +4 -0
  138. package/dist/omegga/matchers/leave.d.ts.map +1 -0
  139. package/dist/omegga/matchers/leave.js +59 -0
  140. package/dist/omegga/matchers/leave.js.map +1 -0
  141. package/dist/omegga/matchers/mapChange.d.ts +3 -0
  142. package/dist/omegga/matchers/mapChange.d.ts.map +1 -0
  143. package/dist/omegga/matchers/mapChange.js +38 -0
  144. package/dist/omegga/matchers/mapChange.js.map +1 -0
  145. package/dist/omegga/matchers/types.d.ts +5 -0
  146. package/dist/omegga/matchers/types.d.ts.map +1 -0
  147. package/dist/omegga/matchers/types.js +7 -0
  148. package/dist/omegga/matchers/types.js.map +1 -0
  149. package/dist/omegga/matchers/version.d.ts +3 -0
  150. package/dist/omegga/matchers/version.d.ts.map +1 -0
  151. package/dist/omegga/matchers/version.js +45 -0
  152. package/dist/omegga/matchers/version.js.map +1 -0
  153. package/dist/omegga/player.d.ts +71 -0
  154. package/dist/omegga/player.d.ts.map +1 -0
  155. package/dist/omegga/player.js +442 -0
  156. package/dist/omegga/player.js.map +1 -0
  157. package/dist/omegga/plugin/plugin_jsonrpc_stdio.d.ts +23 -0
  158. package/dist/omegga/plugin/plugin_jsonrpc_stdio.d.ts.map +1 -0
  159. package/dist/omegga/plugin/plugin_jsonrpc_stdio.js +441 -0
  160. package/dist/omegga/plugin/plugin_jsonrpc_stdio.js.map +1 -0
  161. package/dist/omegga/plugin/plugin_node_safe/proxyOmegga.d.ts +129 -0
  162. package/dist/omegga/plugin/plugin_node_safe/proxyOmegga.d.ts.map +1 -0
  163. package/dist/omegga/plugin/plugin_node_safe/proxyOmegga.js +260 -0
  164. package/dist/omegga/plugin/plugin_node_safe/proxyOmegga.js.map +1 -0
  165. package/dist/omegga/plugin/plugin_node_safe/worker.d.ts +1 -0
  166. package/dist/omegga/plugin/plugin_node_safe/worker.d.ts.map +1 -0
  167. package/dist/omegga/plugin/plugin_node_safe/worker.js +289 -0
  168. package/dist/omegga/plugin/plugin_node_safe/worker.js.map +1 -0
  169. package/dist/omegga/plugin/plugin_node_safe.d.ts +24 -0
  170. package/dist/omegga/plugin/plugin_node_safe.d.ts.map +1 -0
  171. package/dist/omegga/plugin/plugin_node_safe.js +397 -0
  172. package/dist/omegga/plugin/plugin_node_safe.js.map +1 -0
  173. package/dist/omegga/plugin/plugin_node_unsafe.d.ts +13 -0
  174. package/dist/omegga/plugin/plugin_node_unsafe.d.ts.map +1 -0
  175. package/dist/omegga/plugin/plugin_node_unsafe.js +178 -0
  176. package/dist/omegga/plugin/plugin_node_unsafe.js.map +1 -0
  177. package/dist/omegga/plugin.d.ts +86 -0
  178. package/dist/omegga/plugin.d.ts.map +1 -0
  179. package/dist/omegga/plugin.js +458 -0
  180. package/dist/omegga/plugin.js.map +1 -0
  181. package/dist/omegga/server.d.ts +149 -0
  182. package/dist/omegga/server.d.ts.map +1 -0
  183. package/dist/omegga/server.js +601 -0
  184. package/dist/omegga/server.js.map +1 -0
  185. package/dist/omegga/types.d.ts +48 -0
  186. package/dist/omegga/types.d.ts.map +1 -0
  187. package/dist/omegga/types.js +3 -0
  188. package/dist/omegga/types.js.map +1 -0
  189. package/dist/omegga/wrapper.d.ts +22 -0
  190. package/dist/omegga/wrapper.d.ts.map +1 -0
  191. package/dist/omegga/wrapper.js +75 -0
  192. package/dist/omegga/wrapper.js.map +1 -0
  193. package/dist/omeggaplugin.d.ts +1 -0
  194. package/dist/omeggaplugin.js +4 -0
  195. package/dist/omeggaplugin.js.map +1 -0
  196. package/dist/plugin.d.ts +781 -0
  197. package/dist/plugin.js +41 -0
  198. package/dist/plugin.js.map +1 -0
  199. package/dist/softconfig.d.ts +51 -0
  200. package/dist/softconfig.d.ts.map +1 -0
  201. package/dist/softconfig.js +82 -0
  202. package/dist/softconfig.js.map +1 -0
  203. package/dist/util/brick/checkBounds.d.ts +8 -0
  204. package/dist/util/brick/checkBounds.d.ts.map +1 -0
  205. package/dist/util/brick/checkBounds.js +22 -0
  206. package/dist/util/brick/checkBounds.js.map +1 -0
  207. package/dist/util/brick/constants.d.ts +18 -0
  208. package/dist/util/brick/constants.d.ts.map +1 -0
  209. package/dist/util/brick/constants.js +184 -0
  210. package/dist/util/brick/constants.js.map +1 -0
  211. package/dist/util/brick/getBounds.d.ts +4 -0
  212. package/dist/util/brick/getBounds.d.ts.map +1 -0
  213. package/dist/util/brick/getBounds.js +39 -0
  214. package/dist/util/brick/getBounds.js.map +1 -0
  215. package/dist/util/brick/getBrickSize.d.ts +3 -0
  216. package/dist/util/brick/getBrickSize.d.ts.map +1 -0
  217. package/dist/util/brick/getBrickSize.js +12 -0
  218. package/dist/util/brick/getBrickSize.js.map +1 -0
  219. package/dist/util/brick/getScaleAxis.d.ts +3 -0
  220. package/dist/util/brick/getScaleAxis.d.ts.map +1 -0
  221. package/dist/util/brick/getScaleAxis.js +38 -0
  222. package/dist/util/brick/getScaleAxis.js.map +1 -0
  223. package/dist/util/brick/index.d.ts +13 -0
  224. package/dist/util/brick/index.d.ts.map +1 -0
  225. package/dist/util/brick/index.js +29 -0
  226. package/dist/util/brick/index.js.map +1 -0
  227. package/dist/util/brick/rotate.d.ts +17 -0
  228. package/dist/util/brick/rotate.d.ts.map +1 -0
  229. package/dist/util/brick/rotate.js +38 -0
  230. package/dist/util/brick/rotate.js.map +1 -0
  231. package/dist/util/brick/setOwnership.d.ts +12 -0
  232. package/dist/util/brick/setOwnership.d.ts.map +1 -0
  233. package/dist/util/brick/setOwnership.js +21 -0
  234. package/dist/util/brick/setOwnership.js.map +1 -0
  235. package/dist/util/chat.d.ts +23 -0
  236. package/dist/util/chat.d.ts.map +1 -0
  237. package/dist/util/chat.js +50 -0
  238. package/dist/util/chat.js.map +1 -0
  239. package/dist/util/color.d.ts +13 -0
  240. package/dist/util/color.d.ts.map +1 -0
  241. package/dist/util/color.js +130 -0
  242. package/dist/util/color.js.map +1 -0
  243. package/dist/util/file.d.ts +5 -0
  244. package/dist/util/file.d.ts.map +1 -0
  245. package/dist/util/file.js +114 -0
  246. package/dist/util/file.js.map +1 -0
  247. package/dist/util/index.d.ts +162 -0
  248. package/dist/util/index.d.ts.map +1 -0
  249. package/dist/util/index.js +92 -0
  250. package/dist/util/index.js.map +1 -0
  251. package/dist/util/map.d.ts +6 -0
  252. package/dist/util/map.d.ts.map +1 -0
  253. package/dist/util/map.js +26 -0
  254. package/dist/util/map.js.map +1 -0
  255. package/dist/util/pattern.d.ts +1 -0
  256. package/dist/util/pattern.d.ts.map +1 -0
  257. package/dist/util/pattern.js +11 -0
  258. package/dist/util/pattern.js.map +1 -0
  259. package/dist/util/time.d.ts +4 -0
  260. package/dist/util/time.d.ts.map +1 -0
  261. package/dist/util/time.js +41 -0
  262. package/dist/util/time.js.map +1 -0
  263. package/dist/util/uuid.d.ts +2 -0
  264. package/dist/util/uuid.d.ts.map +1 -0
  265. package/dist/util/uuid.js +8 -0
  266. package/dist/util/uuid.js.map +1 -0
  267. package/dist/util/wsl.d.ts +1 -0
  268. package/dist/util/wsl.d.ts.map +1 -0
  269. package/dist/util/wsl.js +14 -0
  270. package/dist/util/wsl.js.map +1 -0
  271. package/dist/webserver/backend/api.d.ts +3 -0
  272. package/dist/webserver/backend/api.d.ts.map +1 -0
  273. package/dist/webserver/backend/api.js +685 -0
  274. package/dist/webserver/backend/api.js.map +1 -0
  275. package/dist/webserver/backend/calendar.d.ts +5 -0
  276. package/dist/webserver/backend/calendar.d.ts.map +1 -0
  277. package/dist/webserver/backend/calendar.js +21 -0
  278. package/dist/webserver/backend/calendar.js.map +1 -0
  279. package/dist/webserver/backend/database.d.ts +149 -0
  280. package/dist/webserver/backend/database.d.ts.map +1 -0
  281. package/dist/webserver/backend/database.js +575 -0
  282. package/dist/webserver/backend/database.js.map +1 -0
  283. package/dist/webserver/backend/index.d.ts +31 -0
  284. package/dist/webserver/backend/index.d.ts.map +1 -0
  285. package/dist/webserver/backend/index.js +189 -0
  286. package/dist/webserver/backend/index.js.map +1 -0
  287. package/dist/webserver/backend/metrics.d.ts +3 -0
  288. package/dist/webserver/backend/metrics.d.ts.map +1 -0
  289. package/dist/webserver/backend/metrics.js +203 -0
  290. package/dist/webserver/backend/metrics.js.map +1 -0
  291. package/dist/webserver/backend/types.d.ts +115 -0
  292. package/dist/webserver/backend/types.d.ts.map +1 -0
  293. package/dist/webserver/backend/types.js +3 -0
  294. package/dist/webserver/backend/types.js.map +1 -0
  295. package/dist/webserver/backend/util.d.ts +2 -0
  296. package/dist/webserver/backend/util.d.ts.map +1 -0
  297. package/dist/webserver/backend/util.js +78 -0
  298. package/dist/webserver/backend/util.js.map +1 -0
  299. package/dist/webserver/index.d.ts +2 -0
  300. package/dist/webserver/index.d.ts.map +1 -0
  301. package/dist/webserver/index.js +9 -0
  302. package/dist/webserver/index.js.map +1 -0
  303. package/{src/webserver/frontend → frontend}/app.html +0 -0
  304. package/{src/webserver/frontend → frontend}/assets/fonts/GlacialIndifferenceBold.ttf +0 -0
  305. package/{src/webserver/frontend → frontend}/assets/fonts/GlacialIndifferenceItalic.otf +0 -0
  306. package/{src/webserver/frontend → frontend}/assets/fonts/GlacialIndifferenceMedium.otf +0 -0
  307. package/{src/webserver/frontend → frontend}/assets/fonts/GlacialIndifferenceRegular.ttf +0 -0
  308. package/{src/webserver/frontend → frontend}/assets/fonts/RobotoBold.ttf +0 -0
  309. package/{src/webserver/frontend → frontend}/assets/fonts/RobotoItalic.ttf +0 -0
  310. package/{src/webserver/frontend → frontend}/assets/fonts/RobotoRegular.ttf +0 -0
  311. package/{src/webserver/frontend → frontend}/assets/img/auth_bg.webp +0 -0
  312. package/{src/webserver/frontend → frontend}/assets/img/dark_bg.webp +0 -0
  313. package/{src/webserver/frontend → frontend}/assets/img/turkey.webp +0 -0
  314. package/{src/webserver/frontend → frontend}/auth.html +0 -0
  315. package/index.js +10 -2
  316. package/package.json +43 -15
  317. package/public/app.bundle.js +537 -73
  318. package/public/app.bundle.js.map +1 -1
  319. package/public/app.css +727 -2
  320. package/public/app.css.map +1 -1
  321. package/public/auth.bundle.js +18 -18
  322. package/public/auth.bundle.js.map +1 -1
  323. package/public/auth.css +364 -2
  324. package/public/auth.css.map +1 -1
  325. package/templates/rpc/README.md +29 -0
  326. package/templates/rpc/doc.json +7 -0
  327. package/templates/rpc/omegga_plugin +0 -0
  328. package/templates/rpc/plugin.json +4 -0
  329. package/templates/rpc/setup.sh +3 -0
  330. package/templates/safe/README.md +29 -0
  331. package/templates/safe/access.json +1 -0
  332. package/templates/safe/doc.json +7 -0
  333. package/templates/safe/omegga.plugin.js +20 -0
  334. package/templates/safe/plugin.json +4 -0
  335. package/templates/safe/setup.sh +4 -0
  336. package/templates/safe-ts/README.md +29 -0
  337. package/templates/safe-ts/access.json +1 -0
  338. package/templates/safe-ts/doc.json +7 -0
  339. package/templates/safe-ts/omegga.plugin.ts +29 -0
  340. package/templates/safe-ts/plugin.json +4 -0
  341. package/templates/safe-ts/setup.sh +4 -0
  342. package/templates/safe-ts/tsconfig.json +10 -0
  343. package/templates/unsafe/README.md +29 -0
  344. package/templates/unsafe/doc.json +7 -0
  345. package/templates/unsafe/omegga.main.js +15 -0
  346. package/templates/unsafe/plugin.json +4 -0
  347. package/templates/unsafe/setup.sh +4 -0
  348. package/.prettierrc +0 -7
  349. package/src/OMEGGA_LEGACY_INSTALL +0 -44
  350. package/src/brickadia/config.js +0 -42
  351. package/src/brickadia/server.js +0 -227
  352. package/src/cli/auth.js +0 -104
  353. package/src/cli/config.js +0 -77
  354. package/src/cli/index.js +0 -6
  355. package/src/cli/installer.js +0 -65
  356. package/src/cli/plugin.js +0 -575
  357. package/src/cli/terminal.js +0 -466
  358. package/src/config/authorizer.js +0 -37
  359. package/src/config/formats/format_js.js +0 -6
  360. package/src/config/formats/format_yml.js +0 -8
  361. package/src/config/index.js +0 -81
  362. package/src/config/reader.js +0 -27
  363. package/src/config/validator.js +0 -32
  364. package/src/config/writer.js +0 -20
  365. package/src/info/default_commands.json +0 -26
  366. package/src/lib.js +0 -23
  367. package/src/main.js +0 -332
  368. package/src/omegga/auth.js +0 -138
  369. package/src/omegga/commandInjector.js +0 -228
  370. package/src/omegga/index.js +0 -22
  371. package/src/omegga/logWrangler.js +0 -323
  372. package/src/omegga/matchers/auth.js +0 -49
  373. package/src/omegga/matchers/chat.js +0 -73
  374. package/src/omegga/matchers/command.js +0 -39
  375. package/src/omegga/matchers/exit.js +0 -19
  376. package/src/omegga/matchers/init.js +0 -23
  377. package/src/omegga/matchers/join.js +0 -115
  378. package/src/omegga/matchers/leave.js +0 -58
  379. package/src/omegga/matchers/mapChange.js +0 -37
  380. package/src/omegga/matchers/version.js +0 -45
  381. package/src/omegga/player.js +0 -585
  382. package/src/omegga/plugin/plugin_jsonrpc_stdio.js +0 -526
  383. package/src/omegga/plugin/plugin_node_safe/proxyOmegga.js +0 -117
  384. package/src/omegga/plugin/plugin_node_safe/worker.js +0 -238
  385. package/src/omegga/plugin/plugin_node_safe.js +0 -473
  386. package/src/omegga/plugin/plugin_node_unsafe.js +0 -177
  387. package/src/omegga/plugin.js +0 -565
  388. package/src/omegga/server.js +0 -658
  389. package/src/omegga/wrapper.js +0 -62
  390. package/src/softconfig.js +0 -64
  391. package/src/util/brick/checkBounds.js +0 -22
  392. package/src/util/brick/constants.js +0 -185
  393. package/src/util/brick/getBounds.js +0 -36
  394. package/src/util/brick/getBrickSize.js +0 -9
  395. package/src/util/brick/getScaleAxis.js +0 -31
  396. package/src/util/brick/index.js +0 -9
  397. package/src/util/brick/rotate.js +0 -43
  398. package/src/util/brick/setOwnership.js +0 -20
  399. package/src/util/chat.js +0 -28
  400. package/src/util/color.js +0 -143
  401. package/src/util/file.js +0 -118
  402. package/src/util/index.js +0 -28
  403. package/src/util/map.js +0 -28
  404. package/src/util/pattern.js +0 -14
  405. package/src/util/time.js +0 -46
  406. package/src/util/uuid.js +0 -8
  407. package/src/util/wsl.js +0 -9
  408. package/src/webserver/backend/api.js +0 -795
  409. package/src/webserver/backend/calendar.js +0 -15
  410. package/src/webserver/backend/database.js +0 -725
  411. package/src/webserver/backend/index.js +0 -206
  412. package/src/webserver/backend/metrics.js +0 -148
  413. package/src/webserver/backend/util.js +0 -75
  414. package/src/webserver/frontend/.eslintrc.yml +0 -26
  415. package/src/webserver/frontend/app.js +0 -78
  416. package/src/webserver/frontend/auth.js +0 -16
  417. package/src/webserver/frontend/components/Background.vue +0 -83
  418. package/src/webserver/frontend/components/Button.vue +0 -105
  419. package/src/webserver/frontend/components/ChatEntry.vue +0 -107
  420. package/src/webserver/frontend/components/ChatTime.vue +0 -40
  421. package/src/webserver/frontend/components/Dimmer.vue +0 -43
  422. package/src/webserver/frontend/components/Dropdown.vue +0 -145
  423. package/src/webserver/frontend/components/Footer.vue +0 -29
  424. package/src/webserver/frontend/components/Header.vue +0 -27
  425. package/src/webserver/frontend/components/InfiniteScroll.vue +0 -51
  426. package/src/webserver/frontend/components/Input.vue +0 -93
  427. package/src/webserver/frontend/components/ListInput.vue +0 -105
  428. package/src/webserver/frontend/components/Loader.vue +0 -98
  429. package/src/webserver/frontend/components/MainMenuButton.vue +0 -83
  430. package/src/webserver/frontend/components/Modal.vue +0 -44
  431. package/src/webserver/frontend/components/NavBar.vue +0 -24
  432. package/src/webserver/frontend/components/PlayerDropdown.vue +0 -210
  433. package/src/webserver/frontend/components/PopoutContent.vue +0 -32
  434. package/src/webserver/frontend/components/RoleDropdown.vue +0 -157
  435. package/src/webserver/frontend/components/Scroll.vue +0 -33
  436. package/src/webserver/frontend/components/Toggle.vue +0 -91
  437. package/src/webserver/frontend/components/index.js +0 -33
  438. package/src/webserver/frontend/css/font.scss +0 -53
  439. package/src/webserver/frontend/css/mixins.scss +0 -49
  440. package/src/webserver/frontend/css/style.scss +0 -166
  441. package/src/webserver/frontend/css/theme.scss +0 -64
  442. package/src/webserver/frontend/partials/NavHeader.vue +0 -55
  443. package/src/webserver/frontend/partials/Page.vue +0 -40
  444. package/src/webserver/frontend/partials/PageContent.vue +0 -31
  445. package/src/webserver/frontend/partials/SideNav.vue +0 -115
  446. package/src/webserver/frontend/partials/index.js +0 -4
  447. package/src/webserver/frontend/router.js +0 -83
  448. package/src/webserver/frontend/views/Auth.vue +0 -190
  449. package/src/webserver/frontend/views/History.vue +0 -462
  450. package/src/webserver/frontend/views/Home.vue +0 -251
  451. package/src/webserver/frontend/views/Main.vue +0 -69
  452. package/src/webserver/frontend/views/NotFound.vue +0 -10
  453. package/src/webserver/frontend/views/Players.vue +0 -425
  454. package/src/webserver/frontend/views/PlayersInspector.vue +0 -538
  455. package/src/webserver/frontend/views/Plugins.vue +0 -217
  456. package/src/webserver/frontend/views/PluginsInspector.vue +0 -418
  457. package/src/webserver/frontend/views/Server.vue +0 -167
  458. package/src/webserver/frontend/views/Users.vue +0 -538
  459. package/src/webserver/frontend/widgets/Chat.vue +0 -124
  460. package/src/webserver/frontend/widgets/Status.vue +0 -91
  461. package/src/webserver/frontend/widgets/index.js +0 -2
  462. package/src/webserver/frontend/widgets/tooltip.js +0 -108
  463. package/src/webserver/index.js +0 -4
@@ -0,0 +1,685 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const logger_1 = __importDefault(require("../../logger"));
30
+ const player_1 = __importDefault(require("../../omegga/player"));
31
+ const chat_1 = require("../../util/chat");
32
+ const color_1 = require("../../util/color");
33
+ const time_1 = require("../../util/time");
34
+ const uuid = __importStar(require("../../util/uuid"));
35
+ const express_1 = __importDefault(require("express"));
36
+ const json_rpc_2_0_1 = require("json-rpc-2.0");
37
+ const lodash_1 = __importDefault(require("lodash"));
38
+ const pkg = require('../../../package.json');
39
+ function default_1(server, io) {
40
+ const { database, omegga } = server;
41
+ // open API is accessible without auth
42
+ const openApi = express_1.default.Router();
43
+ const api = express_1.default.Router();
44
+ // check if this is the first user in the database
45
+ openApi.get('/first', async (req, res) => res.json(await database.isFirstUser()));
46
+ // login / create admin user route
47
+ openApi.post('/auth', async (req, res) => {
48
+ // body is username and password
49
+ if (typeof req.body !== 'object' ||
50
+ typeof req.body.username !== 'string' ||
51
+ typeof req.body.password !== 'string') {
52
+ return res.status(422).json({ message: 'invalid body' });
53
+ }
54
+ const { username, password } = req.body;
55
+ // username regex
56
+ if (!username.match(/^\w{0,32}$/)) {
57
+ return res.status(422).json({ message: 'invalid body' });
58
+ }
59
+ // if this is the first user, create it as the admin user
60
+ const isFirst = await database.isFirstUser();
61
+ let user;
62
+ if (isFirst) {
63
+ user = await database.createAdminUser(username, username === '' ? '' : password);
64
+ }
65
+ else {
66
+ user = await database.authUser(username, password);
67
+ }
68
+ if (user) {
69
+ req.session.userId = user._id;
70
+ req.session.save();
71
+ res.status(200).json({});
72
+ }
73
+ else {
74
+ res.status(404).json({ message: 'no user found' });
75
+ }
76
+ });
77
+ // kill a session
78
+ api.get('/logout', (req, res) => {
79
+ req.session.destroy(e => {
80
+ res.status(e ? 500 : 200).json({});
81
+ });
82
+ });
83
+ // authentication middleware for api
84
+ api.all('*', (req, _res, next) => {
85
+ (async () => {
86
+ const user = await database.findUserById(req.session.userId);
87
+ if (!user || user.isBanned)
88
+ return next(new Error('unauthorized'));
89
+ // req.user = user;
90
+ next();
91
+ })();
92
+ });
93
+ // websocket data
94
+ io.on('connection', socket => {
95
+ // let this user receive messages directed to this user
96
+ socket.join('user:' + socket.data.user._id);
97
+ database.getRoles().then(roles => {
98
+ socket.emit('data', {
99
+ roles,
100
+ version: pkg.version,
101
+ canLogOut: socket.data.user.username !== '',
102
+ now: Date.now(),
103
+ userless: !socket.data.user.username,
104
+ user: {
105
+ username: socket.data.user.username || 'Admin',
106
+ isOwner: socket.data.user.isOwner,
107
+ roles: socket.data.user.roles,
108
+ },
109
+ });
110
+ });
111
+ // logging for this user in the console for web ui actions
112
+ const usernameText = `[${(socket.data.user.username || 'Admin').brightMagenta}]`;
113
+ const log = (...args) => logger_1.default.logp(usernameText, ...args);
114
+ const error = (...args) => logger_1.default.errorp(usernameText, ...args);
115
+ // rpc connection
116
+ const rpcServer = new json_rpc_2_0_1.JSONRPCServer();
117
+ const rpcClient = new json_rpc_2_0_1.JSONRPCClient(async (data) => {
118
+ socket.emit('rpc', data);
119
+ });
120
+ const rpc = new json_rpc_2_0_1.JSONRPCServerAndClient(rpcServer, rpcClient);
121
+ socket.on('rpc', data => {
122
+ if (data && typeof data === 'object') {
123
+ try {
124
+ rpc.receiveAndSend(data);
125
+ }
126
+ catch (e) {
127
+ // silently discard broken rpc requests
128
+ }
129
+ }
130
+ });
131
+ // send chat message from web ui
132
+ // TODO: check if this user has a role with permission to chat
133
+ rpc.addMethod('chat', async ([message]) => {
134
+ if (typeof message !== 'string')
135
+ return;
136
+ if (message.length > 140)
137
+ message = message.slice(0, 140);
138
+ // create fake user
139
+ const user = {
140
+ name: socket.data.user.username || 'Admin',
141
+ id: socket.data.user.playerId,
142
+ color: 'ff00ff',
143
+ web: true,
144
+ };
145
+ // create database entry, send to web ui
146
+ io.to('chat').emit('chat', await database.addChatLog('msg', user, message));
147
+ // broadcast to chat
148
+ server.omegga.broadcast(`"[<b><color=\\"ff00ff\\">${user.name}</></>]: ${(0, chat_1.parseLinks)((0, chat_1.sanitize)(message))}"`);
149
+ // broadcast to terminal
150
+ logger_1.default.log(`[${user.name.brightMagenta.underline}]: ${message}`);
151
+ return 'ok';
152
+ });
153
+ // read recent chat messages
154
+ // TODO: add permission check
155
+ rpc.addMethod('chat.recent', () => {
156
+ return database.getChats({ sameServer: true });
157
+ });
158
+ // find chat messages after a certain time
159
+ // TODO: add permission check
160
+ rpc.addMethod('chat.history', ([{ after, before }]) => {
161
+ return database.getChats({ after, before });
162
+ });
163
+ // see what days chat messages were sent
164
+ // TODO: add permission check
165
+ rpc.addMethod('chat.calendar', () => {
166
+ return database.calendar.years;
167
+ });
168
+ // get the list of plugins
169
+ // TODO: add permission check
170
+ rpc.addMethod('plugins.list', () => {
171
+ return lodash_1.default.sortBy(omegga.pluginLoader.plugins.map(p => ({
172
+ name: p.getName(),
173
+ documentation: p.getDocumentation(),
174
+ path: p.shortPath,
175
+ isLoaded: p.isLoaded(),
176
+ isEnabled: p.isEnabled(),
177
+ })), p => p.name.toLowerCase());
178
+ });
179
+ // get information on a specific plugin
180
+ // TODO: add permission check
181
+ rpc.addMethod('plugin.get', async ([shortPath]) => {
182
+ const plugin = omegga.pluginLoader.plugins.find(p => p.shortPath === shortPath);
183
+ if (!plugin)
184
+ return null;
185
+ // get the plugin configs
186
+ const [defaultConfig, config, objCount] = await Promise.all([
187
+ plugin.storage.getDefaultConfig(),
188
+ plugin.storage.getConfig(),
189
+ plugin.storage.count(),
190
+ ]);
191
+ return {
192
+ name: plugin.getName(),
193
+ format: plugin.constructor.getFormat(),
194
+ info: plugin.getInfo(),
195
+ documentation: plugin.getDocumentation(),
196
+ config,
197
+ defaultConfig,
198
+ objCount,
199
+ path: plugin.shortPath,
200
+ isLoaded: plugin.isLoaded(),
201
+ isEnabled: plugin.isEnabled(),
202
+ };
203
+ });
204
+ // get a paginated list of players
205
+ // TODO: add permission check
206
+ rpc.addMethod('players.list', async ([{ page = 0, search = '', sort = 'name', direction = '1', filter = '', } = {},]) => {
207
+ const banList = (omegga.getBanList() || { banList: {} }).banList;
208
+ // get the ban list
209
+ const now = Date.now();
210
+ let limitId;
211
+ // if the filter is set to banned players only, limit player results by ids in the current ban list
212
+ if (filter === 'banned') {
213
+ limitId = Object.keys(banList).filter(b => banList[b].expires <= banList[b].created ||
214
+ (0, time_1.parseBrickadiaTime)(banList[b].expires) > Date.now());
215
+ }
216
+ const resp = await database.getPlayers({
217
+ page,
218
+ search,
219
+ sort,
220
+ direction,
221
+ limitId,
222
+ });
223
+ for (const player of resp.players) {
224
+ player.seenAgo = now - player.lastSeen;
225
+ player.createdAgo = now - player.created;
226
+ const foundBan = banList[player.id];
227
+ if (foundBan) {
228
+ const created = (0, time_1.parseBrickadiaTime)(foundBan.created);
229
+ const expires = (0, time_1.parseBrickadiaTime)(foundBan.expires);
230
+ // create a clone of the object
231
+ let currentBan = Object.assign(Object.assign({}, foundBan), {
232
+ // parse the times in the current ban
233
+ created,
234
+ expires, duration: expires - created, remainingTime: expires - now,
235
+ // lookup banner name
236
+ bannerName: lodash_1.default.get(omegga.getNameCache(), ['savedPlayerNames', foundBan.bannerId], '') });
237
+ // if the ban is expired, it should not be listed
238
+ if (currentBan.expires < now && currentBan.duration > 0)
239
+ currentBan = null;
240
+ player.ban = currentBan;
241
+ }
242
+ }
243
+ return resp;
244
+ });
245
+ // get a specific player's info
246
+ // TODO: add permission check
247
+ rpc.addMethod('player.get', async ([id]) => {
248
+ const entry = await database.getPlayer(id);
249
+ if (!entry)
250
+ return null;
251
+ const now = Date.now();
252
+ entry.seenAgo = now - entry.lastSeen;
253
+ entry.createdAgo = now - entry.created;
254
+ for (const n of entry.nameHistory)
255
+ n.ago = now - n.date;
256
+ // combine player roles with server roles
257
+ const playerRoles = player_1.default.getRoles(omegga, id) || [];
258
+ const { roles: serverRoles } = omegga.getRoleSetup();
259
+ // Get banner name and duration from list of bans
260
+ for (const b of entry.banHistory) {
261
+ b.duration = b.expires - b.created;
262
+ // lookup banner name
263
+ b.bannerName = lodash_1.default.get(omegga.getNameCache(), ['savedPlayerNames', b.bannerId], '');
264
+ }
265
+ // Get kicker name from list of kicks
266
+ for (const b of entry.kickHistory) {
267
+ // lookup banner name
268
+ b.kickerName = lodash_1.default.get(omegga.getNameCache(), ['savedPlayerNames', b.kickerId], '');
269
+ }
270
+ const foundBan = (omegga.getBanList() || { banList: {} }).banList[id];
271
+ let currentBan = null;
272
+ if (foundBan) {
273
+ // parse the times in the current ban
274
+ const created = (0, time_1.parseBrickadiaTime)(foundBan.created);
275
+ const expires = (0, time_1.parseBrickadiaTime)(foundBan.expires);
276
+ // create a clone of the object
277
+ currentBan = Object.assign(Object.assign({}, foundBan), { created,
278
+ expires, duration: expires - created, remainingTime: expires - now,
279
+ // lookup banner name
280
+ bannerName: lodash_1.default.get(omegga.getNameCache(), ['savedPlayerNames', foundBan.bannerId], '') });
281
+ // if the ban is expired, it should not be listed
282
+ if (currentBan.expires < now && currentBan.duration > 0)
283
+ currentBan = null;
284
+ }
285
+ return Object.assign(Object.assign({}, entry), {
286
+ // player is host
287
+ isHost: omegga.getHostId() === id, isOnline: omegga.players.some(p => p.id === id),
288
+ // player's current ban state
289
+ currentBan,
290
+ // all player's roles w/ colors
291
+ roles: playerRoles.map(r => {
292
+ // default role color is white
293
+ let color = 'ffffff';
294
+ // find the role (if it exists) and get the color
295
+ const role = serverRoles.find(sr => sr.name.toLowerCase() === r.toLowerCase());
296
+ if (role && role.bHasColor)
297
+ color = (0, color_1.rgbToHex)(role.color);
298
+ return {
299
+ name: r,
300
+ color: color,
301
+ };
302
+ }) });
303
+ });
304
+ rpc.addMethod('player.ban', async ([id, duration = -1, reason = 'No Reason']) => {
305
+ var _a, _b, _c;
306
+ // validate inputs
307
+ if (typeof duration !== 'number')
308
+ return false;
309
+ if (typeof id !== 'string' || !uuid.match(id))
310
+ return false;
311
+ if (typeof reason !== 'string' || reason.length > 128)
312
+ return false;
313
+ reason = reason.replace(/\n/g, ' ').replace(/"/g, "'");
314
+ log('Banning player', (_c = (_b = (_a = omegga.getNameCache()) === null || _a === void 0 ? void 0 : _a.savedPlayerNames) === null || _b === void 0 ? void 0 : _b[id].yellow) !== null && _c !== void 0 ? _c : 'with id ' + id.yellow);
315
+ // ban the user
316
+ omegga.writeln(`Chat.Command /Ban "${id}" ${duration} "${reason}"`);
317
+ let listener;
318
+ // wait for the ban to update
319
+ const ok = await Promise.race([
320
+ new Promise(resolve => {
321
+ database.on('update.bans', (listener = () => {
322
+ const banList = (omegga.getBanList() || { banList: {} })
323
+ .banList;
324
+ if (banList[id]) {
325
+ const entry = {
326
+ type: 'banHistory',
327
+ banned: id,
328
+ bannerId: null,
329
+ created: (0, time_1.parseBrickadiaTime)(banList[id].created),
330
+ expires: (0, time_1.parseBrickadiaTime)(banList[id].expires),
331
+ reason: banList[id].reason,
332
+ };
333
+ database.stores.players.update(entry, { $set: entry }, { upsert: true });
334
+ resolve(true);
335
+ }
336
+ }));
337
+ }),
338
+ new Promise(resolve => setTimeout(() => resolve(false), 5000)),
339
+ ]);
340
+ database.off('update.bans', listener);
341
+ return ok;
342
+ });
343
+ rpc.addMethod('player.kick', async ([id, reason = 'No Reason']) => {
344
+ // validate inputs
345
+ if (typeof id !== 'string' || !uuid.match(id))
346
+ return false;
347
+ if (typeof reason !== 'string' || reason.length > 128)
348
+ return false;
349
+ reason = reason.replace(/\n/g, ' ').replace(/"/g, "'");
350
+ // ensure player exists
351
+ const player = omegga.players.find(p => p.id === id);
352
+ if (!player)
353
+ return false;
354
+ log('Kicking player', player.name.yellow);
355
+ // kick the user
356
+ omegga.writeln(`Chat.Command /Kick "${id}" "${reason}"`);
357
+ // wait for the player to disconnect
358
+ const ok = await Promise.race([
359
+ new Promise(resolve => {
360
+ this.omegga.once('leave', async (leavingPlayer) => {
361
+ if (leavingPlayer.id === id) {
362
+ resolve(true);
363
+ // add kick to database
364
+ const entry = {
365
+ type: 'kickHistory',
366
+ kicked: id,
367
+ kickerId: null,
368
+ created: Date.now(),
369
+ reason,
370
+ };
371
+ await database.stores.players.update(entry, { $set: entry }, { upsert: true });
372
+ }
373
+ });
374
+ }),
375
+ new Promise(resolve => setTimeout(() => resolve(false), 5000)),
376
+ ]);
377
+ return ok;
378
+ });
379
+ rpc.addMethod('player.unban', async ([id]) => {
380
+ var _a, _b, _c;
381
+ // validate inputs
382
+ if (typeof id !== 'string' || !uuid.match(id))
383
+ return false;
384
+ // check if user is banned
385
+ const banList = (omegga.getBanList() || { banList: {} }).banList;
386
+ if (!banList[id] || (0, time_1.parseBrickadiaTime)(banList[id].expires) < Date.now())
387
+ return false;
388
+ log('Unbanning player', (_c = (_b = (_a = omegga.getNameCache()) === null || _a === void 0 ? void 0 : _a.savedPlayerNames) === null || _b === void 0 ? void 0 : _b[id].yellow) !== null && _c !== void 0 ? _c : 'with id ' + id.yellow);
389
+ // unban the user
390
+ omegga.writeln(`Chat.Command /Unban "${id}"`);
391
+ let listener;
392
+ // wait for the ban to update
393
+ const ok = await Promise.race([
394
+ new Promise(resolve => {
395
+ database.on('update.bans', (listener = () => {
396
+ const banList = (omegga.getBanList() || { banList: {} }).banList;
397
+ if (!banList[id] ||
398
+ (0, time_1.parseBrickadiaTime)(banList[id].expires) < Date.now())
399
+ resolve(true);
400
+ }));
401
+ }),
402
+ new Promise(resolve => setTimeout(() => resolve(false), 5000)),
403
+ ]);
404
+ database.off('update.bans', listener);
405
+ return ok;
406
+ });
407
+ rpc.addMethod('player.clearbricks', async ([id]) => {
408
+ var _a, _b, _c, _d;
409
+ // validate inputs
410
+ if (typeof id !== 'string' || !uuid.match(id))
411
+ return false;
412
+ log('Clearing bricks for player', (_d = (_c = (_b = (_a = omegga.getNameCache()) === null || _a === void 0 ? void 0 : _a.savedPlayerNames) === null || _b === void 0 ? void 0 : _b[id]) === null || _c === void 0 ? void 0 : _c.yellow) !== null && _d !== void 0 ? _d : 'with id ' + id.yellow);
413
+ // unban the user
414
+ omegga.writeln(`Bricks.Clear "${id}"`);
415
+ return true;
416
+ });
417
+ // set plugin config
418
+ // TODO: add permission check
419
+ rpc.addMethod('plugin.config', async ([shortPath, config]) => {
420
+ const plugin = omegga.pluginLoader.plugins.find(p => p.shortPath === shortPath);
421
+ if (!plugin)
422
+ return null;
423
+ await plugin.storage.setConfig(config);
424
+ // TODO: validate configs
425
+ return true;
426
+ });
427
+ // reload all plugins (and scan for new ones)
428
+ // TODO: add permission check
429
+ rpc.addMethod('plugins.reload', async () => {
430
+ if (!omegga.pluginLoader) {
431
+ error('Omegga is not using plugins');
432
+ return false;
433
+ }
434
+ log('Unloading current plugins');
435
+ let success = await omegga.pluginLoader.unload();
436
+ if (!success) {
437
+ error('Could not unload all plugins');
438
+ return false;
439
+ }
440
+ log('Scanning for new plugins');
441
+ success = await omegga.pluginLoader.scan();
442
+ if (!success) {
443
+ error('Could not scan for plugins');
444
+ return false;
445
+ }
446
+ log('Starting plugins');
447
+ success = await omegga.pluginLoader.reload();
448
+ if (success) {
449
+ const plugins = omegga.pluginLoader.plugins
450
+ .filter(p => p.isLoaded())
451
+ .map(p => p.getName());
452
+ log('Loaded', (plugins.length + '').yellow, 'plugins:', plugins);
453
+ return true;
454
+ }
455
+ else {
456
+ error('Could not load all plugins');
457
+ return false;
458
+ }
459
+ });
460
+ // unload a plugin
461
+ // TODO: add permission check
462
+ rpc.addMethod('plugin.unload', async ([shortPath]) => {
463
+ const plugin = omegga.pluginLoader.plugins.find(p => p.shortPath === shortPath);
464
+ if (!plugin)
465
+ return false;
466
+ if (!plugin.isLoaded())
467
+ return false;
468
+ log('Unloading'.red, 'plugin', plugin.getName().yellow);
469
+ return await plugin.unload();
470
+ });
471
+ // load a plugin
472
+ // TODO: add permission check
473
+ rpc.addMethod('plugin.load', async ([shortPath]) => {
474
+ const plugin = omegga.pluginLoader.plugins.find(p => p.shortPath === shortPath);
475
+ if (!plugin)
476
+ return false;
477
+ if (plugin.isLoaded() || !plugin.isEnabled())
478
+ return false;
479
+ log('Loading'.green, 'plugin', plugin.getName().yellow);
480
+ return await plugin.load();
481
+ });
482
+ // enable/disable a plugin
483
+ // TODO: add permission check
484
+ rpc.addMethod('plugin.toggle', ([shortPath, enabled]) => {
485
+ if (typeof enabled !== 'boolean')
486
+ return;
487
+ const plugin = omegga.pluginLoader.plugins.find(p => p.shortPath === shortPath);
488
+ if (!plugin)
489
+ return false;
490
+ try {
491
+ plugin.setEnabled(enabled);
492
+ log(enabled ? 'Enabled'.green : 'Disabled'.red, 'plugin', plugin.getName().yellow);
493
+ return true;
494
+ }
495
+ catch (e) {
496
+ error('Error', enabled ? 'enabling'.green : 'disabling'.red, 'plugin', plugin.getName().yellow);
497
+ return false;
498
+ }
499
+ });
500
+ // get a list of roles
501
+ // TODO: add permission check
502
+ rpc.addMethod('roles.list', () => {
503
+ return lodash_1.default.sortBy(omegga.getRoleSetup().roles, p => p.name.toLowerCase());
504
+ });
505
+ // get a paginated list of users
506
+ // TODO: add permission check
507
+ rpc.addMethod('users.list', async ([{ page = 0, search = '', sort = 'name', direction = '1' } = {}]) => {
508
+ const resp = await database.getUsers({ page, search, sort, direction });
509
+ const now = Date.now();
510
+ resp.users = resp.users.map(user => (Object.assign(Object.assign({}, user), { seenAgo: user.lastOnline ? now - user.lastOnline : Infinity, createdAgo: now - user.created })));
511
+ return resp;
512
+ });
513
+ // create a new user (host only at the moment)
514
+ // TODO: add permission check
515
+ rpc.addMethod('users.create', async ([username, password]) => {
516
+ if (!socket.data.user.isOwner)
517
+ return 'missing permission';
518
+ // body is username and password
519
+ if (typeof username !== 'string' || typeof password !== 'string')
520
+ return 'username/password not a string';
521
+ // validate username
522
+ if (!username.match(/^\w{0,32}$/))
523
+ return 'username is not allowed';
524
+ // this validation is here for _those_ people
525
+ if (password.length === 0 || password.length > 128)
526
+ return 'invalid password size';
527
+ // set owner's credential as the first user
528
+ if (socket.data.user.isOwner && socket.data.user.username === '') {
529
+ // set the owner's username and password
530
+ try {
531
+ await database.stores.users.update({ _id: socket.data.user._id }, {
532
+ username,
533
+ hash: await database.hash(password),
534
+ });
535
+ }
536
+ catch (e) {
537
+ error('error setting owner password', e);
538
+ return 'error setting owner password';
539
+ }
540
+ log(`created account as "${username.yellow}"`);
541
+ // update
542
+ return '';
543
+ }
544
+ // check if user exists
545
+ if (await database.userExists(username))
546
+ return 'user already exists';
547
+ try {
548
+ await database.createUser(username, password);
549
+ }
550
+ catch (e) {
551
+ error('error creating new user', e);
552
+ return 'error creating new user';
553
+ }
554
+ log(`created new user "${username.yellow}"`);
555
+ return '';
556
+ });
557
+ // change a user's password
558
+ // TODO: add permission check
559
+ rpc.addMethod('users.passwd', async ([username, password]) => {
560
+ // the owner can change names and the user can change their own name
561
+ if (!socket.data.user.isOwner && username !== socket.data.user.username)
562
+ return 'missing permission';
563
+ // body is username and password
564
+ if (typeof username !== 'string' || typeof password !== 'string')
565
+ return 'username/password not a string';
566
+ // validate username
567
+ if (!username.match(/^\w{0,32}$/))
568
+ return 'username is not allowed';
569
+ // check if user exists
570
+ if (!(await database.userExists(username)))
571
+ return 'user does not exist';
572
+ try {
573
+ await database.userPasswd(username, password);
574
+ }
575
+ catch (e) {
576
+ error('error setting user password', e);
577
+ return "error setting user's password";
578
+ }
579
+ log(`changed password for "${username.yellow}"`);
580
+ return '';
581
+ });
582
+ rpc.addMethod('server.autorestart.get', async () => {
583
+ return await database.getAutoRestartConfig();
584
+ });
585
+ const autorestartConfigFields = {
586
+ type: 'string',
587
+ maxUptime: 'number',
588
+ maxUptimeEnabled: 'boolean',
589
+ emptyUptime: 'number',
590
+ emptyUptimeEnabled: 'boolean',
591
+ dailyHour: 'number',
592
+ dailyHourEnabled: 'boolean',
593
+ announcementEnabled: 'boolean',
594
+ bricksEnabled: 'boolean',
595
+ minigamesEnabled: 'boolean',
596
+ environmentEnabled: 'boolean',
597
+ playersEnabled: 'boolean',
598
+ };
599
+ rpc.addMethod('server.autorestart.set', async ([config]) => {
600
+ // validate the autorestart config
601
+ if (typeof config !== 'object' ||
602
+ !Object.entries(autorestartConfigFields).every(([k, v]) => k in config && typeof config[k] === v && !Number.isNaN(v)) ||
603
+ config.type !== 'autoRestartConfig')
604
+ return false;
605
+ await database.setAutoRestartConfig(config);
606
+ return true;
607
+ });
608
+ // send server status at request
609
+ // TODO: server status permission check
610
+ rpc.addMethod('server.status', () => {
611
+ return server.lastReportedStatus;
612
+ });
613
+ // get server run status
614
+ // TODO: server status permission check
615
+ rpc.addMethod('server.started', () => {
616
+ return {
617
+ started: omegga.started,
618
+ starting: omegga.starting,
619
+ stopping: omegga.stopping,
620
+ };
621
+ });
622
+ // start the server if it's not already started
623
+ // TODO: server status permission check
624
+ rpc.addMethod('server.start', async () => {
625
+ if (omegga.starting || omegga.stopping || omegga.started)
626
+ return;
627
+ log('Starting server...');
628
+ await omegga.start();
629
+ });
630
+ // stop the server if it's not already stopped
631
+ // TODO: server status permission check
632
+ rpc.addMethod('server.stop', async () => {
633
+ if (omegga.starting || omegga.stopping || !omegga.started)
634
+ return;
635
+ log('Stopping server...');
636
+ await omegga.stop();
637
+ });
638
+ // restart the server if it's running, start the server if it's stopped
639
+ // TODO: server status permission check
640
+ rpc.addMethod('server.restart', async () => {
641
+ if (omegga.starting || omegga.stopping)
642
+ return;
643
+ try {
644
+ const config = await database.getAutoRestartConfig();
645
+ await omegga.saveServer({
646
+ players: config.playersEnabled,
647
+ bricks: config.bricksEnabled,
648
+ announcement: config.announcementEnabled,
649
+ minigames: config.minigamesEnabled,
650
+ environment: config.environmentEnabled,
651
+ });
652
+ }
653
+ catch (err) {
654
+ error('Error while saving server setup', err);
655
+ }
656
+ database.addChatLog('server', {}, 'Restarting in 5 seconds...');
657
+ logger_1.default.logp('Restarting in 5 seconds...');
658
+ omegga.broadcast(`<size="20">Server restart in <b><color="ffffbb">${5} seconds</></></>`);
659
+ await new Promise(resolve => setTimeout(resolve, 5000));
660
+ omegga.changeMap(omegga.currentMap);
661
+ await new Promise(resolve => setTimeout(resolve, 100));
662
+ if (omegga.started)
663
+ await omegga.stop();
664
+ await new Promise(resolve => setTimeout(resolve, 1000));
665
+ await omegga.start();
666
+ });
667
+ // subscribe and unsubscribe to events
668
+ socket.on('subscribe', room => {
669
+ // TODO: permission check for certain rooms
670
+ if (server.rooms.includes(room)) {
671
+ socket.join(room);
672
+ }
673
+ });
674
+ socket.on('unsubscribe', room => {
675
+ if (server.rooms.includes(room))
676
+ socket.leave(room);
677
+ });
678
+ socket.on('disconnect', () => { });
679
+ });
680
+ // register routes
681
+ server.app.use('/api/v1', openApi);
682
+ server.app.use('/api/v1', api);
683
+ }
684
+ exports.default = default_1;
685
+ //# sourceMappingURL=api.js.map