summaryrefslogtreecommitdiff
path: root/src/script/common
diff options
context:
space:
mode:
authorHybridDog <ovvv@web.de>2019-03-07 08:31:25 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2019-03-07 08:31:25 +0100
commit431d8a9b83be858193328fe59e75026fa023393f (patch)
treeb5773cb8dd581f4e65ff4977e148483b23ad4d0b /src/script/common
parent3066d76e33070f0ec598b522b519fd6c1ddaf10e (diff)
downloadminetest-431d8a9b83be858193328fe59e75026fa023393f.tar.gz
minetest-431d8a9b83be858193328fe59e75026fa023393f.tar.bz2
minetest-431d8a9b83be858193328fe59e75026fa023393f.zip
Abort when trying to set a not registered node (#7011)
I removed the MapNode constructor which takes a nodename and gives the node's id or CONTENT_IGNORE The code which used this constructor (two places) now handles the situation of not registered nodes correctly: * minetest.set_node and similar functions make minetest crash when a not registered node is passed * reverting a node with rollback aborts if the node is not registered
Diffstat (limited to 'src/script/common')
-rw-r--r--src/script/common/c_content.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 793485e25..361db226e 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -1093,7 +1093,7 @@ MapNode readnode(lua_State *L, int index, const NodeDefManager *ndef)
lua_getfield(L, index, "name");
if (!lua_isstring(L, -1))
throw LuaError("Node name is not set or is not a string!");
- const char *name = lua_tostring(L, -1);
+ std::string name = lua_tostring(L, -1);
lua_pop(L, 1);
u8 param1 = 0;
@@ -1108,7 +1108,11 @@ MapNode readnode(lua_State *L, int index, const NodeDefManager *ndef)
param2 = lua_tonumber(L, -1);
lua_pop(L, 1);
- return {ndef, name, param1, param2};
+ content_t id = CONTENT_IGNORE;
+ if (!ndef->getId(name, id))
+ throw LuaError("\"" + name + "\" is not a registered node!");
+
+ return {id, param1, param2};
}
/******************************************************************************/