summaryrefslogtreecommitdiff
path: root/server.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-04-20 00:44:22 +0200
committerTor Andersson <tor@ccxvii.net>2023-04-28 23:36:11 +0200
commit1a55b0b11f1d1a0f3d3226bf37a8ac09ad3345ef (patch)
treee6e4c94e89c63f30641ecd8ed364dff75ef528da /server.js
parent7c0eb693a50dbd2890a5ad1b27516a0a829bbf7c (diff)
downloadserver-1a55b0b11f1d1a0f3d3226bf37a8ac09ad3345ef.tar.gz
Parse game options before passing to "roles" callback.
Diffstat (limited to 'server.js')
-rw-r--r--server.js15
1 files changed, 13 insertions, 2 deletions
diff --git a/server.js b/server.js
index 163c0f6..af2fc65 100644
--- a/server.js
+++ b/server.js
@@ -1056,6 +1056,8 @@ function load_rules() {
}
function get_game_roles(title_id, scenario, options) {
+ if (typeof options === "string")
+ options = JSON.parse(options)
let roles = RULES[title_id].roles
if (typeof roles === 'function')
return roles(scenario, options)
@@ -1218,7 +1220,13 @@ function format_options(options) {
if (k === false) return 'no'
return k.replace(/_/g, " ").replace(/^\w/, c => c.toUpperCase())
}
- return Object.entries(options||{}).map(([k,v]) => (v === true || v === 1) ? to_english(k) : `${to_english(k)}=${to_english(v)}`).join(", ")
+ return Object.entries(options||{}).map(([k,v]) => {
+ if (v === true || v === 1)
+ return to_english(k)
+ if (k === "players")
+ return v + " Player"
+ return to_english(k) + "=" + to_english(v)
+ }).join(", ")
}
function annotate_game(game, user_id, unread) {
@@ -1407,7 +1415,10 @@ function options_json_replacer(key, value) {
if (key === 'is_private') return undefined
if (value === 'true') return true
if (value === 'false') return false
- if (value === '') return undefined
+ if (value === '')
+ return undefined
+ if (typeof value === "string" && String(parseInt(value)) === value)
+ return parseInt(value)
return value
}