summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--public/common/play.js40
-rw-r--r--server.js11
2 files changed, 38 insertions, 13 deletions
diff --git a/public/common/play.js b/public/common/play.js
index 2059678..02a415d 100644
--- a/public/common/play.js
+++ b/public/common/play.js
@@ -508,7 +508,17 @@ function on_update_log() {
while (to_delete-- > 0)
div.removeChild(div.lastChild)
for (let text of view.log) {
- if (typeof on_log === 'function') {
+ if (params.mode === "debug" && typeof text === "object") {
+ let entry = document.createElement("a")
+ entry.href = "#" + text[0]
+ if (text[3] !== null)
+ entry.textContent = "\u25b6 " + text[1] + " " + text[2] + " " + text[3]
+ else
+ entry.textContent = "\u25b6 " + text[1] + " " + text[2]
+ entry.style.display = "block"
+ entry.style.textDecoration = "none"
+ div.appendChild(entry)
+ } else if (typeof on_log === "function") {
div.appendChild(on_log(text))
} else {
let entry = document.createElement("div")
@@ -754,7 +764,7 @@ async function require(path) {
let replay = null
-async function init_replay(debug) {
+async function init_replay() {
remove_resign_menu()
document.getElementById("prompt").textContent = "Loading replay..."
@@ -763,7 +773,7 @@ async function init_replay(debug) {
let rules = await require("rules.js")
console.log("LOADING REPLAY")
- let response = await fetch((debug ? "/debug/" : "/replay/") + params.game_id)
+ let response = await fetch((params.mode === "debug" ? "/replay-debug/" : "/replay/") + params.game_id)
let body = await response.json()
replay = body.replay
@@ -774,7 +784,7 @@ async function init_replay(debug) {
let p = 0
let s = {}
- function eval_action(item) {
+ function eval_action(item, p) {
switch (item.action) {
case "restore":
s = JSON.parse(item.arguments)
@@ -783,9 +793,13 @@ async function init_replay(debug) {
s = rules.setup(item.arguments[0], item.arguments[1], item.arguments[2])
break
case "resign":
+ if (params.mode === "debug")
+ s.log.push([p, item.role.substring(0,2), item.action, null])
s = rules.resign(s, item.role)
break
default:
+ if (params.mode === "debug")
+ s.log.push([p, item.role.substring(0,2), item.action, item.arguments])
s = rules.action(s, item.role, item.action, item.arguments)
break
}
@@ -806,18 +820,18 @@ async function init_replay(debug) {
}
try {
- eval_action(replay[p])
+ eval_action(replay[p], p)
} catch (err) {
console.log("ERROR IN REPLAY %d %s %s/%s/%s", p, s.state, replay[p].role, replay[p].action, replay[p].arguments)
console.log(err)
- if (debug)
+ if (params.mode === "debug")
replay.length = p
else
replay.length = 0
break
}
- if (!debug) {
+ if (params.mode !== "debug") {
replay[p].digest = adler32(JSON.stringify(s))
for (let k = p-1; k > 0; --k) {
if (replay[k].digest === replay[p].digest && !replay[k].is_undone) {
@@ -879,8 +893,10 @@ async function init_replay(debug) {
set_hash(np)
if (p > np)
p = 0, s = {}
- while (p < np)
- eval_action(replay[p++])
+ while (p < np) {
+ eval_action(replay[p], p)
+ ++p;
+ }
update_replay_view()
}
@@ -900,7 +916,7 @@ async function init_replay(debug) {
body.classList.add(player.replace(/ /g, "_"))
view = rules.view(s, player)
- if (!debug)
+ if (params.mode !== "debug")
view.actions = null
if (viewpoint === "Observer")
@@ -980,9 +996,9 @@ async function init_replay(debug) {
window.addEventListener("load", function () {
zoom_map()
if (params.mode === "debug")
- init_replay(true)
+ init_replay()
if (params.mode === "replay")
- init_replay(false)
+ init_replay()
if (params.mode === "play")
connect_play()
})
diff --git a/server.js b/server.js
index d5ce614..1ca151b 100644
--- a/server.js
+++ b/server.js
@@ -1593,6 +1593,15 @@ app.get('/play/:game_id', function (req, res) {
res.redirect('/'+title+'/play:'+game_id)
})
+app.get('/debug/:game_id', function (req, res) {
+ let game_id = req.params.game_id | 0
+ let user_id = req.user ? req.user.user_id : 0
+ let title = SQL_SELECT_GAME_TITLE.get(game_id)
+ if (!title)
+ return res.status(404).send("Invalid game ID.")
+ res.redirect('/'+title+'/debug:'+game_id)
+})
+
app.get('/:title_id/play\::game_id\::role', must_be_logged_in, function (req, res) {
let user_id = req.user ? req.user.user_id : 0
let title_id = req.params.title_id
@@ -1649,7 +1658,7 @@ app.get('/replay/:game_id', function (req, res) {
return res.json({players, state, replay})
})
-app.get('/debug/:game_id', function (req, res) {
+app.get('/replay-debug/:game_id', function (req, res) {
if (!req.user || req.user.user_id !== 1)
return res.status(401).send("Not authorized to debug.")
let game_id = req.params.game_id