From: octacian Date: Thu, 16 Mar 2017 05:03:52 +0000 (-0700) Subject: Keys: Fix crash when using unconfigured default:key X-Git-Tag: 0.4.16~52 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=07e11427cf86de4554834fe1ebbb72531611774b;p=oweals%2Fminetest_game.git Keys: Fix crash when using unconfigured default:key Since meta secret field is blank on any keys (default:key) obtained using /give, the game will crash if you attempt to use one of these. This follows along the principle that the game should never have any reason to crash. --- diff --git a/mods/default/functions.lua b/mods/default/functions.lua index eeac0c2a..bf3749a8 100644 --- a/mods/default/functions.lua +++ b/mods/default/functions.lua @@ -562,7 +562,12 @@ function default.can_interact_with_node(player, pos) local key_meta = item:get_meta() if key_meta:get_string("secret") == "" then - key_meta:set_string("secret", minetest.parse_json(item:get_metadata()).secret) + local key_oldmeta = item:get_metadata() + if key_oldmeta == "" or not minetest.parse_json(key_oldmeta) then + return false + end + + key_meta:set_string("secret", minetest.parse_json(key_oldmeta).secret) item:set_metadata("") end