From 39878d9edf3b54486d77712621642359004687bf Mon Sep 17 00:00:00 2001 From: I-Have-An-Issue <34550332+I-Have-An-Issue@users.noreply.github.com> Date: Sun, 19 Feb 2023 03:07:51 -0500 Subject: [PATCH] Clean up exmaple.env, add authentication to endpoints --- example.env | 6 +++--- src/index.js | 30 +++++++++++++++--------------- src/lib/classes/RenderJob.js | 12 ++++++------ 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/example.env b/example.env index b757a14..1f72db2 100644 --- a/example.env +++ b/example.env @@ -1,10 +1,10 @@ +PORT= RCCSERVICE= -ARBITER_TOKEN= -ARBITER_PASSWORD= BASE_URL=https://sitetest.unexp.xyz -RENDER_FORMAT=PNG +ARBITER_TOKEN= +ARBITER_KEY= RENDER_USER_WIDTH=720 RENDER_USER_HEIGHT=720 diff --git a/src/index.js b/src/index.js index eff1167..b9d6f0b 100644 --- a/src/index.js +++ b/src/index.js @@ -6,13 +6,11 @@ const logger = require("./lib/logger.js") if (process.platform == "linux") logger.warn("Game hosting might not be fully compatible with Linux") -global.games = new Map() - -setInterval(() => { - global.games.forEach(async (value, key) => { - if (!(await value.Running())) value.Stop() - }) -}, 15000) +app.use(({ query }, response, next) => { + if (!query.key) return response.status(400).json({ error: "Missing key in query" }) + if (query.key !== process.env.ARBITER_KEY) return response.status(403).json({ error: "Incorrect key in query" }) + next() +}) app.use("/game/start", require("./routes/game/start.js")) app.use("/game/stop", require("./routes/game/stop.js")) @@ -22,17 +20,19 @@ app.use("/game/status", require("./routes/game/status.js")) app.use("/game/execute", require("./routes/game/execute.js")) app.use("/render/asset", require("./routes/render/asset.js")) -//app.use("/render/game", require("./routes/render/game.js")) -//app.use("/render/texture", require("./routes/render/texture.js")) +app.use("/render/game", require("./routes/render/game.js")) +app.use("/render/texture", require("./routes/render/texture.js")) app.use("/render/user", require("./routes/render/user.js")) app.use("/render/texture", require("./routes/render/texture.js")) app.use("*", require("./routes/index.js")) -app.listen(process.env.PORT || 64989, () => { - logger.boot(`Listening on http://127.0.0.1:${process.env.PORT || 64989}/`) -}) +process.on("uncaughtException", (err) => logger.error(err.message)) +global.games = new Map() +setInterval(() => { + global.games.forEach(async (value, key) => { + if (!(await value.Running())) value.Stop() + }) +}, 15000) -process.on("uncaughtException", (err) => { - logger.error(err.message) -}) +app.listen(process.env.PORT, () => logger.boot(`Listening on http://127.0.0.1:${process.env.PORT}/`)) diff --git a/src/lib/classes/RenderJob.js b/src/lib/classes/RenderJob.js index 4da4cf9..0439098 100644 --- a/src/lib/classes/RenderJob.js +++ b/src/lib/classes/RenderJob.js @@ -1,5 +1,5 @@ const { readFile } = require("fs/promises") -const chalk = require('chalk') +const chalk = require("chalk") const Job = require("./Job.js") const logger = require("../logger.js") @@ -31,7 +31,7 @@ class RenderJob extends Job { { type: "LUA_TSTRING", value: this.id }, { type: "LUA_TSTRING", value: "Headshot" }, - { type: "LUA_TSTRING", value: process.env.RENDER_FORMAT }, + { type: "LUA_TSTRING", value: "PNG" }, { type: "LUA_TNUMBER", value: process.env.RENDER_USER_WIDTH }, { type: "LUA_TNUMBER", value: process.env.RENDER_USER_HEIGHT }, @@ -70,7 +70,7 @@ class RenderJob extends Job { { type: "LUA_TSTRING", value: this.id }, { type: "LUA_TSTRING", value: "Bodyshot" }, - { type: "LUA_TSTRING", value: three_d ? "OBJ" : process.env.RENDER_FORMAT }, + { type: "LUA_TSTRING", value: three_d ? "OBJ" : "PNG" }, { type: "LUA_TNUMBER", value: process.env.RENDER_USER_WIDTH }, { type: "LUA_TNUMBER", value: process.env.RENDER_USER_HEIGHT }, @@ -110,7 +110,7 @@ class RenderJob extends Job { { type: "LUA_TSTRING", value: this.id }, { type: "LUA_TSTRING", value: "Asset" }, - { type: "LUA_TSTRING", value: three_d ? "OBJ" : process.env.RENDER_FORMAT }, + { type: "LUA_TSTRING", value: three_d ? "OBJ" : "PNG" }, { type: "LUA_TNUMBER", value: process.env.RENDER_ASSET_WIDTH }, { type: "LUA_TNUMBER", value: process.env.RENDER_ASSET_HEIGHT }, @@ -153,7 +153,7 @@ class RenderJob extends Job { { type: "LUA_TSTRING", value: this.id }, { type: "LUA_TSTRING", value: "Place" }, - { type: "LUA_TSTRING", value: process.env.RENDER_FORMAT }, + { type: "LUA_TSTRING", value: "PNG" }, { type: "LUA_TNUMBER", value: process.env.RENDER_PLACE_WIDTH }, { type: "LUA_TNUMBER", value: process.env.RENDER_PLACE_HEIGHT }, @@ -191,7 +191,7 @@ class RenderJob extends Job { { type: "LUA_TSTRING", value: this.id }, { type: "LUA_TSTRING", value: "Texture" }, - { type: "LUA_TSTRING", value: process.env.RENDER_FORMAT }, + { type: "LUA_TSTRING", value: "PNG" }, { type: "LUA_TNUMBER", value: process.env.RENDER_USER_WIDTH }, { type: "LUA_TNUMBER", value: process.env.RENDER_USER_HEIGHT },