diff options
author | ANAND ツ <ClobberXD@gmail.com> | 2019-05-21 23:07:58 +0530 |
---|---|---|
committer | SmallJoker <SmallJoker@users.noreply.github.com> | 2019-05-21 19:37:58 +0200 |
commit | a90f2efb12b5131436d22a3627403736e2d326b2 (patch) | |
tree | 80f8deb02c75618236281a0b1269fe3cc43485a1 | |
parent | 920bd3b16fd0aaafd9eeb6d8e40310664d1a06dc (diff) | |
download | minetest-a90f2efb12b5131436d22a3627403736e2d326b2.tar.gz minetest-a90f2efb12b5131436d22a3627403736e2d326b2.tar.bz2 minetest-a90f2efb12b5131436d22a3627403736e2d326b2.zip |
Check for out-of-bounds breath when setting breath_max (#8493)
-rw-r--r-- | src/script/lua_api/l_object.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index b1f4e3da5..b7924ddb8 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -750,17 +750,26 @@ int ObjectRef::l_set_properties(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; + ObjectProperties *prop = co->accessObjectProperties(); if (!prop) return 0; + read_object_properties(L, 2, prop, getServer(L)->idef()); + if (prop->hp_max < co->getHP()) { PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP); co->setHP(prop->hp_max, reason); if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER) getServer(L)->SendPlayerHPOrDie((PlayerSAO *)co, reason); } + + if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER && + prop->breath_max < co->getBreath()) + co->setBreath(prop->breath_max); + co->notifyObjectPropertiesModified(); return 0; } |