aboutsummaryrefslogtreecommitdiff
path: root/src/script/common/c_content.cpp
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2021-08-21 20:04:04 +0200
committerGitHub <noreply@github.com>2021-08-21 20:04:04 +0200
commit0c1e9603db32b4281974fdd8b8e3b505148be47e (patch)
tree376b6f04d1c27388fbb453694827976a9a6d39a0 /src/script/common/c_content.cpp
parenta72d13064fcbddaf332c7d53e6f34b74d8781586 (diff)
downloadhax-minetest-server-0c1e9603db32b4281974fdd8b8e3b505148be47e.tar.gz
hax-minetest-server-0c1e9603db32b4281974fdd8b8e3b505148be47e.zip
HUD: Reject and warn on invalid stat types (#11548)
This comes into play on older servers which do not know the "stat" type. Warnings are only logged once to avoid spam within globalstep callbacks
Diffstat (limited to 'src/script/common/c_content.cpp')
-rw-r--r--src/script/common/c_content.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 235016be0..f13287375 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -1989,15 +1989,17 @@ void push_hud_element(lua_State *L, HudElement *elem)
lua_setfield(L, -2, "style");
}
-HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value)
+bool read_hud_change(lua_State *L, HudElementStat &stat, HudElement *elem, void **value)
{
- HudElementStat stat = HUD_STAT_NUMBER;
- std::string statstr;
- if (lua_isstring(L, 3)) {
+ std::string statstr = lua_tostring(L, 3);
+ {
int statint;
- statstr = lua_tostring(L, 3);
- stat = string_to_enum(es_HudElementStat, statint, statstr) ?
- (HudElementStat)statint : stat;
+ if (!string_to_enum(es_HudElementStat, statint, statstr)) {
+ script_log_unique(L, "Unknown HUD stat type: " + statstr, warningstream);
+ return false;
+ }
+
+ stat = (HudElementStat)statint;
}
switch (stat) {
@@ -2060,7 +2062,8 @@ HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value)
*value = &elem->style;
break;
}
- return stat;
+
+ return true;
}
/******************************************************************************/