Games should be queried by ids, not 'tokens'

This commit is contained in:
I-Have-An-Issue 2023-02-20 05:06:30 -05:00
parent 884406416f
commit 0ac8928024
No known key found for this signature in database
GPG Key ID: E55435DEA0825091
6 changed files with 13 additions and 23 deletions

View File

@ -6,8 +6,8 @@ const GameJob = require("../../lib/classes/GameJob.js")
app.use(express.json())
app.post("/:token", async (request, response) => {
const game = global.games.get(request.params.token)
app.post("/:id", async (request, response) => {
const game = global.games.get(request.params.id)
if (!game) return response.status(404).json({ error: "Game is not running" })
const { script } = request.body

View File

@ -3,8 +3,8 @@ const app = express.Router()
const GameJob = require("../../lib/classes/GameJob.js")
app.get("/:token/:expire", async (request, response) => {
const game = global.games.get(request.params.token)
app.get("/:id/:expire", async (request, response) => {
const game = global.games.get(request.params.id)
if (!game) return response.status(404).json({ error: "Game is not running" })
await game.RenewLease(request.params.expire)

View File

@ -3,8 +3,8 @@ 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)
app.get("/:id", async (request, response) => {
const game = global.games.get(request.params.id)
if (!game) return response.json(false)
const running = await game.Running()

View File

@ -3,26 +3,16 @@ const app = express.Router()
const GameJob = require("../../lib/classes/GameJob.js")
function getGameById(id) {
let game
global.games.forEach((value, key) => {
if (value.placeId == id) game = value
})
return game
}
app.get("/:id", async (request, response) => {
const game = global.games.get(getGameById(request.params.id)?.id)
const game = global.games.get(request.params.id)
if (game) return response.status(400).json({ error: "Game is running" })
const job = new GameJob()
const result = await job.StartGame(request.params.id).catch((_) => _)
global.games.set(job.id, job)
global.games.set(request.params.id, job)
job.proc.once("exit", () => {
global.games.delete(job.id)
global.games.delete(request.params.id)
})
return response.json({ success: true })

View File

@ -3,8 +3,8 @@ 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)
app.get("/:id", async (request, response) => {
const game = global.games.get(request.params.id)
if (!game) return response.status(404).json({ error: "Game is not running" })
const status = await game.GetStatus()

View File

@ -3,8 +3,8 @@ 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)
app.get("/:id", async (request, response) => {
const game = global.games.get(request.params.id)
if (!game) return response.status(404).json({ error: "Game is not running" })
game.Stop()