Merge branch 'master' into crapblox

This commit is contained in:
I-Have-An-Issue 2023-02-17 21:05:56 -05:00
commit 9542096bc6
No known key found for this signature in database
GPG Key ID: E55435DEA0825091
2 changed files with 61 additions and 44 deletions

View File

@ -32,6 +32,7 @@ class RCCService extends EventEmitter {
return resolve(false) return resolve(false)
} }
this.started = true
return resolve(true) return resolve(true)
}) })

View File

@ -1,19 +1,23 @@
const { readFile } = require("fs/promises"); const { readFile } = require("fs/promises")
const Job = require("./Job.js"); const Job = require("./Job.js")
const logger = require("../logger.js"); const logger = require("../logger.js")
class RenderJob extends Job { class RenderJob extends Job {
constructor() { constructor() {
super(); super()
} }
async RenderHeadshot(id) { async RenderHeadshot(id) {
const started = await this.Start(); const running = this.started
if (!started) throw new Error("RCCService failed to start"); if (!running) {
if (!this.client) await this.CreateClient(); const started = await this.Start()
if (!started) throw new Error("RCCService failed to start")
}
logger.info(`[${this.id}] Headshot RenderJob started for ${id}`); if (!this.client) await this.CreateClient()
logger.info(`[${this.id}] Headshot RenderJob started for ${id}`)
const result = await this.OpenJobEx({ const result = await this.OpenJobEx({
name: this.id, name: this.id,
@ -32,21 +36,25 @@ class RenderJob extends Job {
{ type: "LUA_TNUMBER", value: id }, { type: "LUA_TNUMBER", value: id },
], ],
}, },
}).catch((e) => false); }).catch((e) => false)
logger.info(`[${this.id}] Headshot RenderJob finished for ${id}`); logger.info(`[${this.id}] Headshot RenderJob finished for ${id}`)
if (!result) return false; if (!result) return false
return result[0]?.OpenJobExResult?.LuaValue[0]?.value; return result[0]?.OpenJobExResult?.LuaValue[0]?.value
} }
async RenderBodyshot(id, three_d = false) { async RenderBodyshot(id, three_d = false) {
const started = await this.Start(); const running = this.started
if (!started) throw new Error("RCCService failed to start"); if (!running) {
if (!this.client) await this.CreateClient(); const started = await this.Start()
if (!started) throw new Error("RCCService failed to start")
}
if (three_d) logger.info(`[${this.id}] 3D Bodyshot RenderJob started for ${id}`); if (!this.client) await this.CreateClient()
else logger.info(`[${this.id}] Bodyshot RenderJob started for ${id}`);
if (three_d) logger.info(`[${this.id}] 3D Bodyshot RenderJob started for ${id}`)
else logger.info(`[${this.id}] Bodyshot RenderJob started for ${id}`)
const result = await this.OpenJobEx({ const result = await this.OpenJobEx({
name: this.id, name: this.id,
@ -65,22 +73,26 @@ class RenderJob extends Job {
{ type: "LUA_TNUMBER", value: id }, { type: "LUA_TNUMBER", value: id },
], ],
}, },
}).catch((e) => false); }).catch((e) => false)
if (three_d) logger.info(`[${this.id}] 3D Bodyshot RenderJob finished for ${id}`); if (three_d) logger.info(`[${this.id}] 3D Bodyshot RenderJob finished for ${id}`)
else logger.info(`[${this.id}] Bodyshot RenderJob finished for ${id}`); else logger.info(`[${this.id}] Bodyshot RenderJob finished for ${id}`)
if (!result) return false; if (!result) return false
return result[0]?.OpenJobExResult?.LuaValue[0]?.value; return result[0]?.OpenJobExResult?.LuaValue[0]?.value
} }
async RenderAsset(id, three_d = false) { async RenderAsset(id, three_d = false) {
const started = await this.Start(); const running = this.started
if (!started) throw new Error("RCCService failed to start"); if (!running) {
if (!this.client) await this.CreateClient(); const started = await this.Start()
if (!started) throw new Error("RCCService failed to start")
}
if (three_d) logger.info(`[${this.id}] 3D Asset RenderJob started for ${id}`); if (!this.client) await this.CreateClient()
else logger.info(`[${this.id}] Asset RenderJob started for ${id}`);
if (three_d) logger.info(`[${this.id}] 3D Asset RenderJob started for ${id}`)
else logger.info(`[${this.id}] Asset RenderJob started for ${id}`)
const result = await this.OpenJobEx({ const result = await this.OpenJobEx({
name: this.id, name: this.id,
@ -100,26 +112,30 @@ class RenderJob extends Job {
{ type: "LUA_TBOOLEAN", value: "true" }, { type: "LUA_TBOOLEAN", value: "true" },
], ],
}, },
}).catch((e) => false); }).catch((e) => false)
if (three_d) logger.info(`[${this.id}] 3D Asset RenderJob finished for ${id}`); if (three_d) logger.info(`[${this.id}] 3D Asset RenderJob finished for ${id}`)
else logger.info(`[${this.id}] Asset RenderJob finished for ${id}`); else logger.info(`[${this.id}] Asset RenderJob finished for ${id}`)
if (!result) return false; if (!result) return false
return result[0]?.OpenJobExResult?.LuaValue[0]?.value; return result[0]?.OpenJobExResult?.LuaValue[0]?.value
} }
async RenderPlace(id) { async RenderPlace(id) {
const response = await axios(`${process.env.BASE_URL}/API/Game/${id}?t=${process.env.ARBITER_TOKEN}`).catch((_) => reject(_)); 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; const { server_token, server_port, server_owner_id } = response.data
this.id = server_token; this.id = server_token
const started = await this.Start(); const running = this.started
if (!started) throw new Error("RCCService failed to start"); if (!running) {
if (!this.client) await this.CreateClient(); const started = await this.Start()
if (!started) throw new Error("RCCService failed to start")
}
logger.info(`[${this.id}] Place RenderJob started for ${id}`); if (!this.client) await this.CreateClient()
logger.info(`[${this.id}] Place RenderJob started for ${id}`)
const result = await this.OpenJobEx({ const result = await this.OpenJobEx({
name: this.id, name: this.id,
@ -138,13 +154,13 @@ class RenderJob extends Job {
{ type: "LUA_TNUMBER", value: id }, { type: "LUA_TNUMBER", value: id },
], ],
}, },
}).catch((e) => false); }).catch((e) => false)
logger.info(`[${this.id}] Place RenderJob finished for ${id}`); logger.info(`[${this.id}] Place RenderJob finished for ${id}`)
if (!result) return false; if (!result) return false
return result[0]?.OpenJobExResult?.LuaValue[0]?.value; return result[0]?.OpenJobExResult?.LuaValue[0]?.value
} }
} }
module.exports = RenderJob; module.exports = RenderJob