Games should be queried by ids, not 'tokens'
This commit is contained in:
parent
6d1e6401e3
commit
24e97e5e21
|
|
@ -6,8 +6,8 @@ const GameJob = require("../../lib/classes/GameJob.js")
|
||||||
|
|
||||||
app.use(express.json())
|
app.use(express.json())
|
||||||
|
|
||||||
app.post("/:token", async (request, response) => {
|
app.post("/:id", async (request, response) => {
|
||||||
const game = global.games.get(request.params.token)
|
const game = global.games.get(request.params.id)
|
||||||
if (!game) return response.status(404).json({ error: "Game is not running" })
|
if (!game) return response.status(404).json({ error: "Game is not running" })
|
||||||
|
|
||||||
const { script } = request.body
|
const { script } = request.body
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ const app = express.Router()
|
||||||
|
|
||||||
const GameJob = require("../../lib/classes/GameJob.js")
|
const GameJob = require("../../lib/classes/GameJob.js")
|
||||||
|
|
||||||
app.get("/:token/:expire", async (request, response) => {
|
app.get("/:id/:expire", async (request, response) => {
|
||||||
const game = global.games.get(request.params.token)
|
const game = global.games.get(request.params.id)
|
||||||
if (!game) return response.status(404).json({ error: "Game is not running" })
|
if (!game) return response.status(404).json({ error: "Game is not running" })
|
||||||
|
|
||||||
await game.RenewLease(request.params.expire)
|
await game.RenewLease(request.params.expire)
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ const app = express.Router()
|
||||||
|
|
||||||
const GameJob = require("../../lib/classes/GameJob.js")
|
const GameJob = require("../../lib/classes/GameJob.js")
|
||||||
|
|
||||||
app.get("/:token", async (request, response) => {
|
app.get("/:id", async (request, response) => {
|
||||||
const game = global.games.get(request.params.token)
|
const game = global.games.get(request.params.id)
|
||||||
if (!game) return response.json(false)
|
if (!game) return response.json(false)
|
||||||
|
|
||||||
const running = await game.Running()
|
const running = await game.Running()
|
||||||
|
|
|
||||||
|
|
@ -3,26 +3,16 @@ const app = express.Router()
|
||||||
|
|
||||||
const GameJob = require("../../lib/classes/GameJob.js")
|
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) => {
|
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" })
|
if (game) return response.status(400).json({ error: "Game is running" })
|
||||||
|
|
||||||
const job = new GameJob()
|
const job = new GameJob()
|
||||||
const result = await job.StartGame(request.params.id).catch((_) => _)
|
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", () => {
|
job.proc.once("exit", () => {
|
||||||
global.games.delete(job.id)
|
global.games.delete(request.params.id)
|
||||||
})
|
})
|
||||||
|
|
||||||
return response.json({ success: true })
|
return response.json({ success: true })
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ const app = express.Router()
|
||||||
|
|
||||||
const GameJob = require("../../lib/classes/GameJob.js")
|
const GameJob = require("../../lib/classes/GameJob.js")
|
||||||
|
|
||||||
app.get("/:token", async (request, response) => {
|
app.get("/:id", async (request, response) => {
|
||||||
const game = global.games.get(request.params.token)
|
const game = global.games.get(request.params.id)
|
||||||
if (!game) return response.status(404).json({ error: "Game is not running" })
|
if (!game) return response.status(404).json({ error: "Game is not running" })
|
||||||
|
|
||||||
const status = await game.GetStatus()
|
const status = await game.GetStatus()
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ const app = express.Router()
|
||||||
|
|
||||||
const GameJob = require("../../lib/classes/GameJob.js")
|
const GameJob = require("../../lib/classes/GameJob.js")
|
||||||
|
|
||||||
app.get("/:token", async (request, response) => {
|
app.get("/:id", async (request, response) => {
|
||||||
const game = global.games.get(request.params.token)
|
const game = global.games.get(request.params.id)
|
||||||
if (!game) return response.status(404).json({ error: "Game is not running" })
|
if (!game) return response.status(404).json({ error: "Game is not running" })
|
||||||
|
|
||||||
game.Stop()
|
game.Stop()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue