From f2041ffcf982eb407e986b99e4cabaaaefd6eab9 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Mon, 27 Oct 2025 15:46:24 +0100 Subject: [PATCH] fix: api/game/room-terrain returning encoded terrain data in all cases As rooms generated via the `map.generateRoom` CLI command would never set `type: "terrain"`, the check for decoding those would always fail, leading to encoded terrain being returned whether the `&encoded` param was set or not. Fix the issue by always decoding if a string `terrain` key is found on a single-result return, but for consistency, also fix `generateRoom` to add that `type` property. --- lib/cli/map.js | 2 +- lib/game/api/game.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cli/map.js b/lib/cli/map.js index 6f6a129..cdaeb28 100644 --- a/lib/cli/map.js +++ b/lib/cli/map.js @@ -555,7 +555,7 @@ exports.generateRoom = utils.withHelp([ return q.all([ db.rooms.insert({_id: roomName, status: 'normal', sourceKeepers}), - db['rooms.terrain'].insert({room: roomName, terrain}), + db['rooms.terrain'].insert({room: roomName, terrain, type: "terrain"}), objects.length ? db['rooms.objects'].insert(objects) : q.when() ]); }) diff --git a/lib/game/api/game.js b/lib/game/api/game.js index eaeb643..8170be9 100644 --- a/lib/game/api/game.js +++ b/lib/game/api/game.js @@ -270,7 +270,7 @@ router.get('/room-terrain', jsonResponse((request) => { if(request.query.encoded) { return {terrain}; } - if(terrain.length == 1 && terrain[0].type == 'terrain') { + if(terrain.length == 1 && typeof terrain[0].terrain === 'string') { return {terrain: common.decodeTerrain(terrain[0].terrain, request.query.room)}; } return {terrain};