From a13bdea2eb020ca5446b56a5c7f7699343cbef87 Mon Sep 17 00:00:00 2001 From: I-Have-An-Issue <34550332+I-Have-An-Issue@users.noreply.github.com> Date: Thu, 19 Jan 2023 19:17:01 -0500 Subject: [PATCH] DO NOT RUN ANYTHING FROM THIS COMMIT --- package.json | 3 +- src/index.js | 6 ++++ src/lib/classes/GameJob.js | 7 ++++ src/lib/classes/Job.js | 9 +++++ src/lib/classes/RCCService.js | 30 +++++++++++++++++ src/lib/classes/RenderJob.js | 7 ++++ src/lib/wait.js | 5 +++ src/lua/user.lua | 2 +- src/lua/user_headshot.lua | 2 +- src/routes/index.js | 62 ++++++++++++++++++++++++++++++++++- src/routes/render/avatar.js | 55 +------------------------------ 11 files changed, 130 insertions(+), 58 deletions(-) create mode 100644 src/lib/classes/GameJob.js create mode 100644 src/lib/classes/Job.js create mode 100644 src/lib/classes/RCCService.js create mode 100644 src/lib/classes/RenderJob.js create mode 100644 src/lib/wait.js diff --git a/package.json b/package.json index cf6df7d..fba5f60 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "version": "0.1", "main": "src/index.js", "scripts": { - "start": "node ." + "start": "node .", + "dev": "nodemon ." }, "repository": { "type": "git", diff --git a/src/index.js b/src/index.js index 163ecae..58bf831 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,8 @@ const logger = require("./lib/logger.js") const express = require("express") const app = express() +process.env.RCCSERVICE_PATH = "/tmp/Release" + 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")) @@ -15,3 +17,7 @@ app.use("*", require("./routes/index.js")) app.listen(process.env.PORT || 5173, () => { logger.info(`Listening on http://127.0.0.1:${process.env.PORT || 5173}/`) }) + +process.on("uncaughtException", (err) => { + console.log(err) +}) diff --git a/src/lib/classes/GameJob.js b/src/lib/classes/GameJob.js new file mode 100644 index 0000000..54d678a --- /dev/null +++ b/src/lib/classes/GameJob.js @@ -0,0 +1,7 @@ +const Job = require("./Job.js") + +class GameJob extends Job { + constructor() {} +} + +module.exports = GameJob diff --git a/src/lib/classes/Job.js b/src/lib/classes/Job.js new file mode 100644 index 0000000..c031b11 --- /dev/null +++ b/src/lib/classes/Job.js @@ -0,0 +1,9 @@ +const RCCService = require("./RCCService.js") + +class Job extends RCCService { + constructor(id, expirationInSeconds = 10, category = 0, cores = 1) { + super() + } +} + +module.exports = Job diff --git a/src/lib/classes/RCCService.js b/src/lib/classes/RCCService.js new file mode 100644 index 0000000..cd6101c --- /dev/null +++ b/src/lib/classes/RCCService.js @@ -0,0 +1,30 @@ +const EventEmitter = require("events") +const child_process = require("child_process") + +class RCCService extends EventEmitter { + constructor(path = process.env.RCCSERVICE_PATH) { + super() + this.path = path + } + + start(port, options = { cwd: this.path }) { + return new Promise((resolve, reject) => { + try { + this.proc = child_process.spawn("wine", ["RCCService.exe", "-console", "-placeid:-1", `-port`, port], options) + this.proc.once("spawn", resolve(this.proc)) + this.proc.once("exit", () => { + this.proc = null + }) + } catch (_) { + reject(_) + } + }) + } + + stop(signal = "SIGTERM") { + if (!this.proc) throw new Error("Process is not running") + return this.proc.kill(signal) + } +} + +module.exports = RCCService diff --git a/src/lib/classes/RenderJob.js b/src/lib/classes/RenderJob.js new file mode 100644 index 0000000..62a6e69 --- /dev/null +++ b/src/lib/classes/RenderJob.js @@ -0,0 +1,7 @@ +const Job = require("./Job.js") + +class RenderJob extends Job { + constructor() {} +} + +module.exports = RenderJob diff --git a/src/lib/wait.js b/src/lib/wait.js new file mode 100644 index 0000000..93e4399 --- /dev/null +++ b/src/lib/wait.js @@ -0,0 +1,5 @@ +module.exports = (ms) => { + return new Promise((resolve) => { + setTimeout(resolve, ms) + }) +} diff --git a/src/lua/user.lua b/src/lua/user.lua index b36e7c3..977290d 100644 --- a/src/lua/user.lua +++ b/src/lua/user.lua @@ -8,7 +8,7 @@ game:GetService("ContentProvider"):SetBaseUrl(baseUrl) game:GetService("ScriptContext").ScriptsDisabled = true local Player = game.Players:CreateLocalPlayer(0) -Player.CharacterAppearance = ("%s/users/%d/character"):format(baseUrl, assetId) +Player.CharacterAppearance = ("%s/Users/%d/CharApp"):format(baseUrl, assetId) Player:LoadCharacter(false) game:GetService("RunService"):Run() diff --git a/src/lua/user_headshot.lua b/src/lua/user_headshot.lua index d62f877..e74ea56 100644 --- a/src/lua/user_headshot.lua +++ b/src/lua/user_headshot.lua @@ -9,7 +9,7 @@ game:GetService("ContentProvider"):SetBaseUrl(baseUrl) game:GetService("ScriptContext").ScriptsDisabled = true local Player = game.Players:CreateLocalPlayer(0) -Player.CharacterAppearance = ("%s/users/%d/character"):format(baseUrl, assetId) +Player.CharacterAppearance = ("%s/Users/%d/CharApp"):format(baseUrl, assetId) Player:LoadCharacter(false) game:GetService("RunService"):Run() diff --git a/src/routes/index.js b/src/routes/index.js index e8e1d8e..97227af 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -1,6 +1,66 @@ +const soap = require("soap") +const { readFileSync } = require("fs") const express = require("express") +const RCCService = require("../lib/classes/RCCService") +const wait = require("../lib/wait") const app = express.Router() -app.all("*", (request, response) => response.status(200).end("Hi")) +app.all("*", async (request, response) => { + const rcc = new RCCService() + const proc = await rcc.start(64989) + if (proc.exitCode !== null) return response.json(false) + + await wait(1000) + + const jobId = "RenderTest" + const client = await soap.createClientAsync(__dirname + "/../lib/RCCService.wsdl", {}, "http://127.0.0.1:64989/") + const result = await client.OpenJobExAsync({ + job: { + id: jobId, + expirationInSeconds: 10, + category: 0, + cores: 1, + }, + script: { + name: jobId, + script: readFileSync(__dirname + "/../lua/user_headshot.lua", { encoding: "utf-8" }), + arguments: { + LuaValue: [ + { + type: "LUA_TSTRING", + value: jobId, + }, + { + type: "LUA_TSTRING", + value: "Avatar", + }, + { + type: "LUA_TSTRING", + value: "PNG", + }, + { + type: "LUA_TNUMBER", + value: "1920", + }, + { + type: "LUA_TNUMBER", + value: "1920", + }, + { + type: "LUA_TSTRING", + value: "https://economy.ittblox.gay", + }, + { + type: "LUA_TNUMBER", + value: "1", + }, + ], + }, + }, + }) + + rcc.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 f605917..12697bd 100644 --- a/src/routes/render/avatar.js +++ b/src/routes/render/avatar.js @@ -1,59 +1,6 @@ -const { readFileSync } = require("fs") -const soap = require("soap") -const { randomUUID } = require("crypto") - const express = require("express") const app = express.Router() -app.get("/", async (request, response) => { - let jobId = randomUUID() - const client = await soap.createClientAsync(__dirname + "/../../lib/RCCService.wsdl", {}, "http://127.0.0.1:64989/") - const result = await client.OpenJobExAsync({ - job: { - id: jobId, - expirationInSeconds: 2, - category: 100, - cores: 1, - }, - script: { - name: jobId, - script: readFileSync(__dirname + "/../../lua/user.lua", { encoding: "utf-8" }), - arguments: { - LuaValue: [ - { - type: "LUA_TSTRING", - value: jobId, - }, - { - type: "LUA_TSTRING", - value: "Avatar", - }, - { - type: "LUA_TSTRING", - value: "PNG", - }, - { - type: "LUA_TNUMBER", - value: "1920", - }, - { - type: "LUA_TNUMBER", - value: "1920", - }, - { - type: "LUA_TSTRING", - value: "https://economy.ittblox.gay", - }, - { - type: "LUA_TNUMBER", - value: "-1", - }, - ], - }, - }, - }) - - response.json(result[0]) -}) +app.all("*", (request, response) => response.status(404).end()) module.exports = app