From 2aa69bb240d507682293f5225c146a300933b3ad Mon Sep 17 00:00:00 2001 From: I-Have-An-Issue <34550332+I-Have-An-Issue@users.noreply.github.com> Date: Fri, 20 Jan 2023 18:15:54 -0500 Subject: [PATCH] Ok --- src/index.js | 2 -- src/lib/classes/RCCService.js | 10 ++++----- src/routes/game/execute.js | 2 +- src/routes/game/start.js | 2 +- src/routes/game/stop.js | 2 +- src/routes/index.js | 42 ++--------------------------------- src/routes/render/asset.js | 42 ++++++++++++++++++++++++++++++++++- src/routes/render/avatar.js | 42 ++++++++++++++++++++++++++++++++++- src/routes/render/game.js | 2 +- start.bat | 2 ++ start.sh | 2 ++ 11 files changed, 97 insertions(+), 53 deletions(-) create mode 100644 start.bat create mode 100644 start.sh diff --git a/src/index.js b/src/index.js index 64472a4..426e423 100644 --- a/src/index.js +++ b/src/index.js @@ -2,8 +2,6 @@ const logger = require("./lib/logger.js") const express = require("express") const app = express() -process.env.RCCSERVICE_PATH = "D:\\Projects\\Roblox\\Source\\UploadBits\\Win32-Release-RCCService\\" - app.use("/game/start", require("./routes/game/start.js")) app.use("/game/stop", require("./routes/game/stop.js")) app.use("/game/execute", require("./routes/game/execute.js")) diff --git a/src/lib/classes/RCCService.js b/src/lib/classes/RCCService.js index a70b2e8..e45da9f 100644 --- a/src/lib/classes/RCCService.js +++ b/src/lib/classes/RCCService.js @@ -1,6 +1,6 @@ const EventEmitter = require("events") const child_process = require("child_process") -const logger = require(`${__dirname}\\..\\logger.js`) +const logger = require("../../lib/logger.js") class RCCService extends EventEmitter { constructor(port, path = process.env.RCCSERVICE_PATH) { @@ -12,21 +12,21 @@ class RCCService extends EventEmitter { Start(options = { cwd: this.path }) { return new Promise((resolve, reject) => { try { - if(process.platform == "win32") { + if (process.platform == "win32") { this.proc = child_process.spawn("RCCService.exe", ["-Console", "-PlaceId:-1", `-Port`, this.port], options) } else { this.proc = child_process.spawn("wine", ["RCCService.exe", "-Console", "-PlaceId:-1", `-Port`, this.port], options) } this.proc.once("spawn", () => { - logger.info(`Spawned RCCService instance on port ${this.port}`); + logger.info(`Spawned RCCService instance on port ${this.port}`) resolve(this.proc) }) this.proc.once("exit", () => { - this.proc = null; + this.proc = null logger.info(`An RCCService instance has closed on port ${this.port}`) }) } catch (_) { - logger.error(_); + logger.error(_) reject(_) } }) diff --git a/src/routes/game/execute.js b/src/routes/game/execute.js index 12697bd..88822f0 100644 --- a/src/routes/game/execute.js +++ b/src/routes/game/execute.js @@ -1,6 +1,6 @@ const express = require("express") const app = express.Router() -app.all("*", (request, response) => response.status(404).end()) +app.all("*", (request, response) => response.status(404).json({ status: 404 })) module.exports = app diff --git a/src/routes/game/start.js b/src/routes/game/start.js index 12697bd..88822f0 100644 --- a/src/routes/game/start.js +++ b/src/routes/game/start.js @@ -1,6 +1,6 @@ const express = require("express") const app = express.Router() -app.all("*", (request, response) => response.status(404).end()) +app.all("*", (request, response) => response.status(404).json({ status: 404 })) module.exports = app diff --git a/src/routes/game/stop.js b/src/routes/game/stop.js index 12697bd..88822f0 100644 --- a/src/routes/game/stop.js +++ b/src/routes/game/stop.js @@ -1,6 +1,6 @@ const express = require("express") const app = express.Router() -app.all("*", (request, response) => response.status(404).end()) +app.all("*", (request, response) => response.status(404).json({ status: 404 })) module.exports = app diff --git a/src/routes/index.js b/src/routes/index.js index 2a45b29..7ccedee 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -1,46 +1,8 @@ -const waitPort = require("wait-port") -const logger = require(`${__dirname}\\..\\lib\\logger.js`) -const { readFileSync, read } = require("fs") const express = require("express") -const Job = require("../lib/classes/Job.js") -const { randomUUID } = require("crypto") const app = express.Router() -let tempPort = 64990 +app.get("/", (request, response) => response.status(200).json()) -app.all("*", async (request, response) => { - const job = new Job(randomUUID(), tempPort) - await job.Start() - - const { open } = await waitPort({ host: "127.0.0.1", port: tempPort, timeout: 5000, output: "silent" }) - if (!open) { - logger.warn("Job could not be started because port is already taken. Closing job.."); - job.Close() - return response.json(false) - } - - await job.CreateClient() - const result = await job.Open({ - name: job.id, - script: readFileSync(__dirname + "/../lua/headshot.lua", { encoding: "utf-8" }), - arguments: { - LuaValue: [ - { type: "LUA_TSTRING", value: job.id }, - { type: "LUA_TSTRING", value: "Headshot" }, - { type: "LUA_TSTRING", value: "PNG" }, - - // change this to 1920x when we finish the arbiter - { type: "LUA_TNUMBER", value: "420" }, - { type: "LUA_TNUMBER", value: "420" }, - - { type: "LUA_TSTRING", value: "https://sitetest.unexp.xyz" }, - { type: "LUA_TNUMBER", value: "1" }, - ], - }, - }) - await job.Stop() - - return response.end(Buffer.from(result[0].OpenJobExResult.LuaValue[0].value, "base64")) -}) +app.all("*", (request, response) => response.status(404).json({ status: 404 })) module.exports = app diff --git a/src/routes/render/asset.js b/src/routes/render/asset.js index 12697bd..263b50f 100644 --- a/src/routes/render/asset.js +++ b/src/routes/render/asset.js @@ -1,6 +1,46 @@ +const waitPort = require("wait-port") +const { readFileSync } = require("fs") +const { randomUUID } = require("crypto") +const logger = require("../../lib/logger.js") +const Job = require("../../lib/classes/Job.js") + const express = require("express") const app = express.Router() -app.all("*", (request, response) => response.status(404).end()) +app.get("/", async (request, response) => { + let tempPort = 64990 + const job = new Job(randomUUID(), tempPort) + await job.Start() + + const { open } = await waitPort({ host: "127.0.0.1", port: tempPort, timeout: 5000, output: "silent" }) + if (!open) { + logger.warn("Job could not be started because port is already taken. Closing job..") + job.Close() + return response.json(false) + } + + await job.CreateClient() + const result = await job.Open({ + name: job.id, + script: readFileSync(__dirname + "/../lua/xml.lua", { encoding: "utf-8" }), + arguments: { + LuaValue: [ + { type: "LUA_TSTRING", value: job.id }, + { type: "LUA_TSTRING", value: "XML" }, + { type: "LUA_TSTRING", value: "PNG" }, + + // change this to 1920x when we finish the arbiter + { type: "LUA_TNUMBER", value: "420" }, + { type: "LUA_TNUMBER", value: "420" }, + + { type: "LUA_TSTRING", value: "https://economy.ittblox.gay" }, + { type: "LUA_TNUMBER", value: "2555" }, + ], + }, + }) + + await job.Stop() + return response.end(Buffer.from(result[0].OpenJobExResult.LuaValue[0].value, "base64")) +}) module.exports = app diff --git a/src/routes/render/avatar.js b/src/routes/render/avatar.js index 12697bd..44c9b1d 100644 --- a/src/routes/render/avatar.js +++ b/src/routes/render/avatar.js @@ -1,6 +1,46 @@ +const waitPort = require("wait-port") +const { readFileSync } = require("fs") +const { randomUUID } = require("crypto") +const logger = require("../../lib/logger.js") +const Job = require("../../lib/classes/Job.js") + const express = require("express") const app = express.Router() -app.all("*", (request, response) => response.status(404).end()) +app.get("/", async (request, response) => { + let tempPort = 64990 + const job = new Job(randomUUID(), tempPort) + await job.Start() + + const { open } = await waitPort({ host: "127.0.0.1", port: tempPort, timeout: 5000, output: "silent" }) + if (!open) { + logger.warn("Job could not be started because port is already taken. Closing job..") + job.Close() + return response.json(false) + } + + await job.CreateClient() + const result = await job.Open({ + name: job.id, + script: readFileSync(__dirname + "/../lua/headshot.lua", { encoding: "utf-8" }), + arguments: { + LuaValue: [ + { type: "LUA_TSTRING", value: job.id }, + { type: "LUA_TSTRING", value: "Headshot" }, + { type: "LUA_TSTRING", value: "PNG" }, + + // change this to 1920x when we finish the arbiter + { type: "LUA_TNUMBER", value: "420" }, + { type: "LUA_TNUMBER", value: "420" }, + + { type: "LUA_TSTRING", value: "https://economy.ittblox.gay" }, + { type: "LUA_TNUMBER", value: "1" }, + ], + }, + }) + + await job.Stop() + return response.end(Buffer.from(result[0].OpenJobExResult.LuaValue[0].value, "base64")) +}) module.exports = app diff --git a/src/routes/render/game.js b/src/routes/render/game.js index 12697bd..88822f0 100644 --- a/src/routes/render/game.js +++ b/src/routes/render/game.js @@ -1,6 +1,6 @@ const express = require("express") const app = express.Router() -app.all("*", (request, response) => response.status(404).end()) +app.all("*", (request, response) => response.status(404).json({ status: 404 })) module.exports = app diff --git a/start.bat b/start.bat new file mode 100644 index 0000000..940ff1b --- /dev/null +++ b/start.bat @@ -0,0 +1,2 @@ +set RCCSERVICE_PATH=D:\\Projects\\Roblox\\Source\\UploadBits\\Win32-Release-RCCService\\ +npm run dev \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..38dd7f5 --- /dev/null +++ b/start.sh @@ -0,0 +1,2 @@ +export RCCSERVICE_PATH=/run/media/calones/32531f99-d721-4297-90c7-f91e56851060/ICCService/ +npm run dev \ No newline at end of file