This commit is contained in:
parent
1659d0b5d1
commit
2956e9152a
|
|
@ -5,12 +5,21 @@ const app = express()
|
|||
const logger = require("./lib/logger.js")
|
||||
|
||||
if (process.platform == "linux") logger.warn("Game hosting might not be fully compatible with Linux")
|
||||
|
||||
global.games = new Map()
|
||||
|
||||
setInterval(() => {
|
||||
logger.info("Killing jobless RCCService instances...")
|
||||
global.games.forEach(async (value, key) => {
|
||||
if (!(await game.Running())) game.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("/render/asset", require("./routes/render/asset.js"))
|
||||
app.use("/render/game", require("./routes/render/game.js"))
|
||||
|
|
|
|||
|
|
@ -43,6 +43,11 @@ class GameJob extends Job {
|
|||
resolve()
|
||||
})
|
||||
}
|
||||
|
||||
async Running() {
|
||||
const result = await game.Execute("IsRunning", "return true").catch((_) => _)
|
||||
return !result?.message
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GameJob
|
||||
|
|
|
|||
|
|
@ -46,6 +46,11 @@ class Job extends RCCService {
|
|||
if (!this.client) throw new Error("There is no client")
|
||||
return await this.client.ExecuteAsync({ jobID: this.id, script: { name, script, arguments: {} } })
|
||||
}
|
||||
|
||||
async GetStatus() {
|
||||
if (!this.client) throw new Error("There is no client")
|
||||
return await this.client.GetStatusAsync({})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Job
|
||||
|
|
|
|||
|
|
@ -5,7 +5,15 @@ const GameJob = require("../../lib/classes/GameJob.js")
|
|||
|
||||
app.get("/:token", async (request, response) => {
|
||||
const game = global.games.get(request.params.token)
|
||||
return response.json(!!game)
|
||||
if (!game) return response.json(false)
|
||||
|
||||
const running = await game.Running()
|
||||
if (!running && game) {
|
||||
game.Close()
|
||||
return response.json(false)
|
||||
}
|
||||
|
||||
return response.json(true)
|
||||
})
|
||||
|
||||
module.exports = app
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
const express = require("express")
|
||||
const app = express.Router()
|
||||
|
||||
const GameJob = require("../../lib/classes/GameJob.js")
|
||||
|
||||
app.get("/:token", async (request, response) => {
|
||||
const game = global.games.get(request.params.token)
|
||||
if (!game) return response.status(404).json({ error: "Game is not running" })
|
||||
|
||||
const status = await game.GetStatus()
|
||||
return response.json(status[0]?.GetStatusResult)
|
||||
})
|
||||
|
||||
module.exports = app
|
||||
Loading…
Reference in New Issue