aaaa
This commit is contained in:
parent
2aa69bb240
commit
5af16cc48b
|
|
@ -1,5 +1,6 @@
|
|||
const EventEmitter = require("events")
|
||||
const child_process = require("child_process")
|
||||
const waitPort = require("wait-port")
|
||||
const logger = require("../../lib/logger.js")
|
||||
|
||||
class RCCService extends EventEmitter {
|
||||
|
|
@ -17,23 +18,31 @@ class RCCService extends EventEmitter {
|
|||
} 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}`)
|
||||
resolve(this.proc)
|
||||
|
||||
this.proc.once("spawn", async () => {
|
||||
logger.info(`[${this.port}] RCCService instance spawned`)
|
||||
const { open } = await waitPort({ host: "127.0.0.1", port: this.port, timeout: 5000, output: "silent" }).catch((e) => console.log(e))
|
||||
if (!open || this.proc.exitCode !== null) {
|
||||
logger.error(`[${this.port}] RCCService could not listen, exiting`)
|
||||
this.Close()
|
||||
return resolve(false)
|
||||
}
|
||||
|
||||
return resolve(true)
|
||||
})
|
||||
|
||||
this.proc.once("exit", () => {
|
||||
this.proc = null
|
||||
logger.info(`An RCCService instance has closed on port ${this.port}`)
|
||||
logger.info(`[${this.port}] RCCService instance exited`)
|
||||
})
|
||||
} catch (_) {
|
||||
logger.error(_)
|
||||
reject(_)
|
||||
resolve(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Stop(signal = "SIGTERM") {
|
||||
if (!this.proc) throw new Error("Process is not running")
|
||||
if (!this.proc) return
|
||||
return this.proc.kill(signal)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
const waitPort = require("wait-port")
|
||||
const { readFileSync } = require("fs")
|
||||
const { randomUUID } = require("crypto")
|
||||
const logger = require("../../lib/logger.js")
|
||||
|
|
@ -7,40 +6,40 @@ const Job = require("../../lib/classes/Job.js")
|
|||
const express = require("express")
|
||||
const app = express.Router()
|
||||
|
||||
app.get("/", async (request, response) => {
|
||||
app.get("/:id", 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)
|
||||
}
|
||||
const started = await job.Start()
|
||||
if (!started) return response.status(500).json({ error: "RCCService failed to start" })
|
||||
|
||||
logger.info(`[${job.id}] Job opened`)
|
||||
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" },
|
||||
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" },
|
||||
// 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" },
|
||||
],
|
||||
},
|
||||
})
|
||||
{ type: "LUA_TSTRING", value: "https://economy.ittblox.gay" },
|
||||
{ type: "LUA_TNUMBER", value: request.params.id },
|
||||
],
|
||||
},
|
||||
})
|
||||
.catch((e) => false)
|
||||
|
||||
logger.info(`[${job.id}] Job closed`)
|
||||
await job.Stop()
|
||||
return response.end(Buffer.from(result[0].OpenJobExResult.LuaValue[0].value, "base64"))
|
||||
|
||||
if (result) return response.end(Buffer.from(result[0]?.OpenJobExResult?.LuaValue[0]?.value, "base64"))
|
||||
else return response.status(500).end()
|
||||
})
|
||||
|
||||
module.exports = app
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
const waitPort = require("wait-port")
|
||||
const { readFileSync } = require("fs")
|
||||
const { randomUUID } = require("crypto")
|
||||
const logger = require("../../lib/logger.js")
|
||||
|
|
@ -7,40 +6,40 @@ const Job = require("../../lib/classes/Job.js")
|
|||
const express = require("express")
|
||||
const app = express.Router()
|
||||
|
||||
app.get("/", async (request, response) => {
|
||||
app.get("/:id", 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)
|
||||
}
|
||||
const started = await job.Start()
|
||||
if (!started) return response.status(500).json({ error: "RCCService failed to start" })
|
||||
|
||||
logger.info(`[${job.id}] Job opened`)
|
||||
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" },
|
||||
const result = await job
|
||||
.Open({
|
||||
name: job.id,
|
||||
script: readFileSync(__dirname + "/../../lua/bodyshot.lua", { encoding: "utf-8" }),
|
||||
arguments: {
|
||||
LuaValue: [
|
||||
{ type: "LUA_TSTRING", value: job.id },
|
||||
{ type: "LUA_TSTRING", value: "Bodyshot" },
|
||||
{ type: "LUA_TSTRING", value: "PNG" },
|
||||
|
||||
// change this to 1920x when we finish the arbiter
|
||||
{ type: "LUA_TNUMBER", value: "420" },
|
||||
{ type: "LUA_TNUMBER", value: "420" },
|
||||
// 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" },
|
||||
],
|
||||
},
|
||||
})
|
||||
{ type: "LUA_TSTRING", value: "https://economy.ittblox.gay" },
|
||||
{ type: "LUA_TNUMBER", value: request.params.id },
|
||||
],
|
||||
},
|
||||
})
|
||||
.catch((e) => false)
|
||||
|
||||
logger.info(`[${job.id}] Job closed`)
|
||||
await job.Stop()
|
||||
return response.end(Buffer.from(result[0].OpenJobExResult.LuaValue[0].value, "base64"))
|
||||
|
||||
if (result) return response.end(Buffer.from(result[0]?.OpenJobExResult?.LuaValue[0]?.value, "base64"))
|
||||
else return response.status(500).end()
|
||||
})
|
||||
|
||||
module.exports = app
|
||||
|
|
|
|||
Loading…
Reference in New Issue