aaaa
This commit is contained in:
parent
2aa69bb240
commit
5af16cc48b
|
|
@ -1,5 +1,6 @@
|
||||||
const EventEmitter = require("events")
|
const EventEmitter = require("events")
|
||||||
const child_process = require("child_process")
|
const child_process = require("child_process")
|
||||||
|
const waitPort = require("wait-port")
|
||||||
const logger = require("../../lib/logger.js")
|
const logger = require("../../lib/logger.js")
|
||||||
|
|
||||||
class RCCService extends EventEmitter {
|
class RCCService extends EventEmitter {
|
||||||
|
|
@ -17,23 +18,31 @@ class RCCService extends EventEmitter {
|
||||||
} else {
|
} else {
|
||||||
this.proc = child_process.spawn("wine", ["RCCService.exe", "-Console", "-PlaceId:-1", `-Port`, this.port], options)
|
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}`)
|
this.proc.once("spawn", async () => {
|
||||||
resolve(this.proc)
|
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.once("exit", () => {
|
||||||
this.proc = null
|
this.proc = null
|
||||||
logger.info(`An RCCService instance has closed on port ${this.port}`)
|
logger.info(`[${this.port}] RCCService instance exited`)
|
||||||
})
|
})
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
logger.error(_)
|
resolve(false)
|
||||||
reject(_)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
Stop(signal = "SIGTERM") {
|
Stop(signal = "SIGTERM") {
|
||||||
if (!this.proc) throw new Error("Process is not running")
|
if (!this.proc) return
|
||||||
return this.proc.kill(signal)
|
return this.proc.kill(signal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
const waitPort = require("wait-port")
|
|
||||||
const { readFileSync } = require("fs")
|
const { readFileSync } = require("fs")
|
||||||
const { randomUUID } = require("crypto")
|
const { randomUUID } = require("crypto")
|
||||||
const logger = require("../../lib/logger.js")
|
const logger = require("../../lib/logger.js")
|
||||||
|
|
@ -7,40 +6,40 @@ const Job = require("../../lib/classes/Job.js")
|
||||||
const express = require("express")
|
const express = require("express")
|
||||||
const app = express.Router()
|
const app = express.Router()
|
||||||
|
|
||||||
app.get("/", async (request, response) => {
|
app.get("/:id", async (request, response) => {
|
||||||
let tempPort = 64990
|
let tempPort = 64990
|
||||||
const job = new Job(randomUUID(), tempPort)
|
const job = new Job(randomUUID(), tempPort)
|
||||||
await job.Start()
|
const started = await job.Start()
|
||||||
|
if (!started) return response.status(500).json({ error: "RCCService failed to 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
logger.info(`[${job.id}] Job opened`)
|
||||||
await job.CreateClient()
|
await job.CreateClient()
|
||||||
const result = await job.Open({
|
const result = await job
|
||||||
name: job.id,
|
.Open({
|
||||||
script: readFileSync(__dirname + "/../lua/xml.lua", { encoding: "utf-8" }),
|
name: job.id,
|
||||||
arguments: {
|
script: readFileSync(__dirname + "/../../lua/xml.lua", { encoding: "utf-8" }),
|
||||||
LuaValue: [
|
arguments: {
|
||||||
{ type: "LUA_TSTRING", value: job.id },
|
LuaValue: [
|
||||||
{ type: "LUA_TSTRING", value: "XML" },
|
{ type: "LUA_TSTRING", value: job.id },
|
||||||
{ type: "LUA_TSTRING", value: "PNG" },
|
{ type: "LUA_TSTRING", value: "XML" },
|
||||||
|
{ type: "LUA_TSTRING", value: "PNG" },
|
||||||
|
|
||||||
// change this to 1920x when we finish the arbiter
|
// change this to 1920x when we finish the arbiter
|
||||||
{ type: "LUA_TNUMBER", value: "420" },
|
{ type: "LUA_TNUMBER", value: "420" },
|
||||||
{ type: "LUA_TNUMBER", value: "420" },
|
{ type: "LUA_TNUMBER", value: "420" },
|
||||||
|
|
||||||
{ type: "LUA_TSTRING", value: "https://economy.ittblox.gay" },
|
{ type: "LUA_TSTRING", value: "https://economy.ittblox.gay" },
|
||||||
{ type: "LUA_TNUMBER", value: "2555" },
|
{ type: "LUA_TNUMBER", value: request.params.id },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
.catch((e) => false)
|
||||||
|
|
||||||
|
logger.info(`[${job.id}] Job closed`)
|
||||||
await job.Stop()
|
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
|
module.exports = app
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
const waitPort = require("wait-port")
|
|
||||||
const { readFileSync } = require("fs")
|
const { readFileSync } = require("fs")
|
||||||
const { randomUUID } = require("crypto")
|
const { randomUUID } = require("crypto")
|
||||||
const logger = require("../../lib/logger.js")
|
const logger = require("../../lib/logger.js")
|
||||||
|
|
@ -7,40 +6,40 @@ const Job = require("../../lib/classes/Job.js")
|
||||||
const express = require("express")
|
const express = require("express")
|
||||||
const app = express.Router()
|
const app = express.Router()
|
||||||
|
|
||||||
app.get("/", async (request, response) => {
|
app.get("/:id", async (request, response) => {
|
||||||
let tempPort = 64990
|
let tempPort = 64990
|
||||||
const job = new Job(randomUUID(), tempPort)
|
const job = new Job(randomUUID(), tempPort)
|
||||||
await job.Start()
|
const started = await job.Start()
|
||||||
|
if (!started) return response.status(500).json({ error: "RCCService failed to 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
logger.info(`[${job.id}] Job opened`)
|
||||||
await job.CreateClient()
|
await job.CreateClient()
|
||||||
const result = await job.Open({
|
const result = await job
|
||||||
name: job.id,
|
.Open({
|
||||||
script: readFileSync(__dirname + "/../lua/headshot.lua", { encoding: "utf-8" }),
|
name: job.id,
|
||||||
arguments: {
|
script: readFileSync(__dirname + "/../../lua/bodyshot.lua", { encoding: "utf-8" }),
|
||||||
LuaValue: [
|
arguments: {
|
||||||
{ type: "LUA_TSTRING", value: job.id },
|
LuaValue: [
|
||||||
{ type: "LUA_TSTRING", value: "Headshot" },
|
{ type: "LUA_TSTRING", value: job.id },
|
||||||
{ type: "LUA_TSTRING", value: "PNG" },
|
{ type: "LUA_TSTRING", value: "Bodyshot" },
|
||||||
|
{ type: "LUA_TSTRING", value: "PNG" },
|
||||||
|
|
||||||
// change this to 1920x when we finish the arbiter
|
// change this to 1920x when we finish the arbiter
|
||||||
{ type: "LUA_TNUMBER", value: "420" },
|
{ type: "LUA_TNUMBER", value: "420" },
|
||||||
{ type: "LUA_TNUMBER", value: "420" },
|
{ type: "LUA_TNUMBER", value: "420" },
|
||||||
|
|
||||||
{ type: "LUA_TSTRING", value: "https://economy.ittblox.gay" },
|
{ type: "LUA_TSTRING", value: "https://economy.ittblox.gay" },
|
||||||
{ type: "LUA_TNUMBER", value: "1" },
|
{ type: "LUA_TNUMBER", value: request.params.id },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
.catch((e) => false)
|
||||||
|
|
||||||
|
logger.info(`[${job.id}] Job closed`)
|
||||||
await job.Stop()
|
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
|
module.exports = app
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue