Merge branch 'master' of calones.xyz:Bingle/arbiter

This commit is contained in:
unexp 2023-02-17 23:14:07 -03:00
commit 1dc50c7cc5
No known key found for this signature in database
GPG Key ID: BF66F09641C584C8
11 changed files with 137 additions and 118 deletions

16
example.env Normal file
View File

@ -0,0 +1,16 @@
RCCSERVICE=
ARBITER_TOKEN=
ARBITER_PASSWORD=
BASE_URL=https://sitetest.unexp.xyz
RENDER_FORMAT=PNG
RENDER_USER_WIDTH=720
RENDER_USER_HEIGHT=720
RENDER_ASSET_WIDTH=720
RENDER_ASSET_HEIGHT=720
RENDER_PLACE_WIDTH=854
RENDER_PLACE_HEIGHT=480

View File

@ -1,40 +1,37 @@
require("dotenv").config()
const express = require("express")
const app = express()
require("dotenv").config();
const express = require("express");
const app = express();
const logger = require("./lib/logger.js")
const logger = require("./lib/logger.js");
if (process.platform == "linux") logger.warn("Game hosting might not be fully compatible with Linux")
if (process.platform == "linux") logger.warn("Game hosting might not be fully compatible with Linux");
global.games = new Map()
global.games = new Map();
setInterval(() => {
global.games.forEach(async (value, key) => {
if (!(await value.Running())) value.Stop()
})
}, 15000)
if (!(await value.Running())) value.Stop();
});
}, 15000);
app.use("/game/start", require("./routes/game/start.js"))
app.use("/game/stop", require("./routes/game/stop.js"))
app.use("/game/running", require("./routes/game/running.js"))
app.use("/game/renew", require("./routes/game/renew.js"))
app.use("/game/status", require("./routes/game/status.js"))
app.use("/game/execute", require("./routes/game/execute.js"))
app.use("/game/start", require("./routes/game/start.js"));
app.use("/game/stop", require("./routes/game/stop.js"));
app.use("/game/running", require("./routes/game/running.js"));
app.use("/game/renew", require("./routes/game/renew.js"));
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/headshot", require("./routes/render/headshot.js"))
app.use("/render/bodyshot", require("./routes/render/bodyshot.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/user", require("./routes/render/user.js"));
app.use("/render/3d/asset", require("./routes/render/3d/asset.js"))
app.use("/render/3d/user", require("./routes/render/3d/user.js"))
app.use("*", require("./routes/index.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}/`)
})
logger.boot(`Listening on http://127.0.0.1:${process.env.PORT || 64989}/`);
});
process.on("uncaughtException", (err) => {
logger.error(err.message)
})
logger.error(err.message);
});

View File

@ -5,7 +5,7 @@ const waitPort = require("wait-port")
const logger = require("../../lib/logger.js")
const randport = require("../../lib/randport.js")
const chalk = require('chalk')
const chalk = require("chalk")
class RCCService extends EventEmitter {
constructor() {
@ -18,9 +18,9 @@ class RCCService extends EventEmitter {
this.port = await randport.tcp()
if (process.platform == "win32") {
this.proc = child_process.spawn("RCCService.exe", ["-Console", "-PlaceId:-1", `-Port`, this.port], { cwd: process.env.RCCSERVICE })
this.proc = child_process.spawn("RCCService.exe", ["-Console", "-PlaceId:-1", `-Port`, this.port], { cwd: process.env.RCCSERVICE, stdio: "inherit" })
} else {
this.proc = child_process.spawn("wine", ["RCCService.exe", "-Console", "-PlaceId:-1", `-Port`, this.port], { cwd: process.env.RCCSERVICE })
this.proc = child_process.spawn("wine", ["RCCService.exe", "-Console", "-PlaceId:-1", `-Port`, this.port], { cwd: process.env.RCCSERVICE, stdio: "inherit" })
}
this.proc.once("spawn", async () => {
@ -32,6 +32,7 @@ class RCCService extends EventEmitter {
return resolve(false)
}
this.started = true
return resolve(true)
})
@ -51,4 +52,4 @@ class RCCService extends EventEmitter {
}
}
module.exports = RCCService
module.exports = RCCService

View File

@ -9,9 +9,13 @@ class RenderJob extends Job {
super()
}
async RenderHeadshot(id, base64 = false) {
const started = await this.Start()
if (!started) throw new Error("RCCService failed to start")
async RenderHeadshot(id) {
const running = this.started
if (!running) {
const started = await this.Start()
if (!started) throw new Error("RCCService failed to start")
}
if (!this.client) await this.CreateClient()
logger.info(`${chalk.gray(`[${this.id}]`)} Headshot RenderJob started for ${id}`)
@ -37,16 +41,17 @@ class RenderJob extends Job {
logger.info(`${chalk.gray(`[${this.id}]`)} Headshot RenderJob finished for ${id}`)
await this.Stop()
if (!result) return false
if (base64) return result[0].OpenJobExResult.LuaValue[0].value
return Buffer.from(result[0]?.OpenJobExResult?.LuaValue[0]?.value, "base64")
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
}
async RenderBodyshot(id, base64 = false, three_d = false) {
const started = await this.Start()
if (!started) throw new Error("RCCService failed to start")
async RenderBodyshot(id, three_d = false) {
const running = this.started
if (!running) {
const started = await this.Start()
if (!started) throw new Error("RCCService failed to start")
}
if (!this.client) await this.CreateClient()
if (three_d) logger.info(`${chalk.gray(`[${this.id}]`)} 3D Bodyshot RenderJob started for ${id}`)
@ -74,16 +79,17 @@ class RenderJob extends Job {
if (three_d) logger.info(`${chalk.gray(`[${this.id}]`)} 3D Bodyshot RenderJob finished for ${id}`)
else logger.info(`${chalk.gray(`[${this.id}]`)} Bodyshot RenderJob finished for ${id}`)
await this.Stop()
if (!result) return false
if (base64 || three_d) return result[0].OpenJobExResult.LuaValue[0].value
return Buffer.from(result[0]?.OpenJobExResult?.LuaValue[0]?.value, "base64")
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
}
async RenderAsset(id, base64 = false, three_d = false) {
const started = await this.Start()
if (!started) throw new Error("RCCService failed to start")
async RenderAsset(id, three_d = false) {
const running = this.started
if (!running) {
const started = await this.Start()
if (!started) throw new Error("RCCService failed to start")
}
if (!this.client) await this.CreateClient()
if (three_d) logger.info(`${chalk.gray(`[${this.id}]`)} 3D Asset RenderJob started for ${id}`)
@ -112,21 +118,22 @@ class RenderJob extends Job {
if (three_d) logger.info(`${chalk.gray(`[${this.id}]`)} 3D Asset RenderJob finished for ${id}`)
else logger.info(`${chalk.gray(`[${this.id}]`)} Asset RenderJob finished for ${id}`)
await this.Stop()
if (!result) return false
if (base64 || three_d) return result[0].OpenJobExResult.LuaValue[0].value
return Buffer.from(result[0]?.OpenJobExResult?.LuaValue[0]?.value, "base64")
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
}
async RenderPlace(id, base64 = false) {
async RenderPlace(id) {
const response = await axios(`${process.env.BASE_URL}/API/Game/${id}?t=${process.env.ARBITER_TOKEN}`).catch((_) => reject(_))
const { server_token, server_port, server_owner_id } = response.data
this.id = server_token
const started = await this.Start()
if (!started) throw new Error("RCCService failed to start")
const running = this.started
if (!running) {
const started = await this.Start()
if (!started) throw new Error("RCCService failed to start")
}
if (!this.client) await this.CreateClient()
logger.info(`${chalk.gray(`[${this.id}]`)} Place RenderJob started for ${id}`)
@ -152,11 +159,8 @@ class RenderJob extends Job {
logger.info(`${chalk.gray(`[${this.id}]`)} Place RenderJob finished for ${id}`)
await this.Stop()
if (!result) return false
if (base64) return result[0].OpenJobExResult.LuaValue[0].value
return Buffer.from(result[0]?.OpenJobExResult?.LuaValue[0]?.value, "base64")
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
}
}

View File

@ -1,14 +0,0 @@
const express = require("express")
const app = express.Router()
const RenderJob = require("../../../lib/classes/RenderJob.js")
app.get("/:id", async (request, response) => {
const job = new RenderJob()
const result = await job.RenderAsset(request.params.id, process.env.RENDER_BASE64, true).catch((_) => _)
if (result?.message) return response.status(500).json({ error: result.message })
else return response.end(result)
})
module.exports = app

View File

@ -1,14 +0,0 @@
const express = require("express")
const app = express.Router()
const RenderJob = require("../../../lib/classes/RenderJob.js")
app.get("/:id", async (request, response) => {
const job = new RenderJob()
const result = await job.RenderBodyshot(request.params.id, process.env.RENDER_BASE64, true).catch((_) => _)
if (result?.message) return response.status(500).json({ error: result.message })
else return response.end(result)
})
module.exports = app

View File

@ -4,11 +4,29 @@ const app = express.Router()
const RenderJob = require("../../lib/classes/RenderJob.js")
app.get("/:id", async (request, response) => {
const { params, query } = request
const job = new RenderJob()
const result = await job.RenderAsset(request.params.id, process.env.RENDER_BASE64).catch((_) => _)
let body = {}
if (result?.message) return response.status(500).json({ error: result.message })
else return response.end(result)
const asset = await job.RenderAsset(params.id).catch((_) => _)
if (asset?.message) {
job.Stop()
return response.status(500).json({ error: asset.message })
}
body.asset = asset
if (query.three_d) {
const three_d = await job.RenderAsset(params.id, true).catch((_) => _)
if (three_d?.message) {
job.Stop()
return response.status(500).json({ error: three_d.message })
}
body.three_d = three_d
}
job.Stop()
return response.json(body)
})
module.exports = app

View File

@ -1,14 +0,0 @@
const express = require("express")
const app = express.Router()
const RenderJob = require("../../lib/classes/RenderJob.js")
app.get("/:id", async (request, response) => {
const job = new RenderJob()
const result = await job.RenderBodyshot(request.params.id, process.env.RENDER_BASE64).catch((_) => _)
if (result?.message) return response.status(500).json({ error: result.message })
else return response.end(result)
})
module.exports = app

View File

@ -1,14 +0,0 @@
const express = require("express")
const app = express.Router()
const RenderJob = require("../../lib/classes/RenderJob.js")
app.get("/:id", async (request, response) => {
const job = new RenderJob()
const result = await job.RenderHeadshot(request.params.id, process.env.RENDER_BASE64).catch((_) => _)
if (result?.message) return response.status(500).json({ error: result.message })
else return response.end(result)
})
module.exports = app

View File

39
src/routes/render/user.js Normal file
View File

@ -0,0 +1,39 @@
const express = require("express");
const app = express.Router();
const RenderJob = require("../../lib/classes/RenderJob.js");
app.get("/:id", async (request, response) => {
const { params, query } = request;
const job = new RenderJob();
let body = {};
const headshot = await job.RenderHeadshot(params.id).catch((_) => _);
if (headshot?.message) {
job.Stop();
return response.status(500).json({ error: headshot.message });
}
body.headshot = headshot;
const bodyshot = await job.RenderBodyshot(params.id).catch((_) => _);
if (bodyshot?.message) {
job.Stop();
return response.status(500).json({ error: bodyshot.message });
}
body.bodyshot = bodyshot;
if (query.three_d) {
const three_d = await job.RenderBodyshot(params.id, true).catch((_) => _);
if (three_d?.message) {
job.Stop();
return response.status(500).json({ error: three_d.message });
}
body.three_d = three_d;
}
job.Stop();
return response.json(body);
});
module.exports = app;