From 1a55b0b11f1d1a0f3d3226bf37a8ac09ad3345ef Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 20 Apr 2023 00:44:22 +0200 Subject: Parse game options before passing to "roles" callback. --- server.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'server.js') 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 } -- cgit v1.2.3