summaryrefslogtreecommitdiff
path: root/server.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-02-24 13:30:27 +0100
committerTor Andersson <tor@ccxvii.net>2023-02-24 13:39:07 +0100
commitd097e2db5862177d1c30cbf7df0e8143e67d901d (patch)
tree26f7e7c3985fb5428a961ea417cf76b4ac6318f8 /server.js
parent8efbcdda8d35d0bccda1303623c36bb495a6e82d (diff)
downloadserver-d097e2db5862177d1c30cbf7df0e8143e67d901d.tar.gz
Optimize replay.
Send raw array rather than objects over the wire.
Diffstat (limited to 'server.js')
-rw-r--r--server.js27
1 files changed, 3 insertions, 24 deletions
diff --git a/server.js b/server.js
index 2a07e8e..1bf38fe 100644
--- a/server.js
+++ b/server.js
@@ -1070,7 +1070,7 @@ const SQL_UPDATE_GAME_STATE = SQL("INSERT OR REPLACE INTO game_state (game_id,st
const SQL_UPDATE_GAME_RESULT = SQL("UPDATE games SET status=?, result=? WHERE game_id=?")
const SQL_UPDATE_GAME_PRIVATE = SQL("UPDATE games SET is_private=1 WHERE game_id=?")
const SQL_INSERT_REPLAY = SQL("INSERT INTO game_replay (game_id,role,action,arguments) VALUES (?,?,?,?)")
-const SQL_SELECT_REPLAY = SQL("SELECT role,action,arguments FROM game_replay WHERE game_id=?")
+const SQL_SELECT_REPLAY = SQL("SELECT role,action,arguments FROM game_replay WHERE game_id=?").raw()
const SQL_SELECT_GAME = SQL("SELECT * FROM games WHERE game_id=?")
const SQL_SELECT_GAME_VIEW = SQL("SELECT * FROM game_view WHERE game_id=?")
@@ -1670,34 +1670,13 @@ app.get('/:title_id/replay\::game_id', function (req, res) {
return res.sendFile(__dirname + '/public/' + title_id + '/play.html')
})
-app.get('/:title_id/debug\::game_id', function (req, res) {
- if (!req.user || req.user.user_id !== 1)
- return res.status(401).send("Not authorized to debug.")
- let title_id = req.params.title_id
+app.get('/api/replay/:game_id', function (req, res) {
let game_id = req.params.game_id
let game = SQL_SELECT_GAME.get(game_id)
if (!game)
return res.status(404).send("Invalid game ID.")
- if (game.title_id !== title_id)
- return res.status(404).send("Invalid game ID.")
- return res.sendFile(__dirname + '/public/' + title_id + '/play.html')
-})
-
-app.get('/replay/:game_id', function (req, res) {
- let game_id = req.params.game_id
- let game = SQL_SELECT_GAME.get(game_id)
- if (game.status < 2)
- return res.status(404).send("Invalid game ID.")
- let players = SQL_SELECT_PLAYERS_JOIN.all(game_id)
- let state = SQL_SELECT_GAME_STATE.get(game_id)
- let replay = SQL_SELECT_REPLAY.all(game_id)
- return res.json({players, state, replay})
-})
-
-app.get('/replay-debug/:game_id', function (req, res) {
- if (!req.user || req.user.user_id !== 1)
+ if (game.status < 2 && (!req.user || req.user.user_id !== 1))
return res.status(401).send("Not authorized to debug.")
- let game_id = req.params.game_id
let players = SQL_SELECT_PLAYERS_JOIN.all(game_id)
let state = SQL_SELECT_GAME_STATE.get(game_id)
let replay = SQL_SELECT_REPLAY.all(game_id)