1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-13 00:25:19 +02:00

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
This commit is contained in:
SmallJoker
2021-08-21 20:04:04 +02:00
committed by GitHub
parent a72d13064f
commit 0c1e9603db
7 changed files with 86 additions and 44 deletions

View File

@@ -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;
}
/******************************************************************************/