aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2019-11-09 11:00:19 +0100
committersfan5 <sfan5@live.de>2019-11-11 14:06:48 +0100
commit2c4cf508a9b94a76ce2ca7c7317258471a41c51d (patch)
treedb024e8374e7e74809410b9b998d38042b187811 /src/script/lua_api
parent3f271564e08716cfeb4a966f4291524b0fac05d3 (diff)
downloadminetest-2c4cf508a9b94a76ce2ca7c7317258471a41c51d.tar.gz
minetest-2c4cf508a9b94a76ce2ca7c7317258471a41c51d.tar.bz2
minetest-2c4cf508a9b94a76ce2ca7c7317258471a41c51d.zip
[CSM] Implement minetest.get_csm_restrictions()
fixes #8068
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_client.cpp35
-rw-r--r--src/script/lua_api/l_client.h3
2 files changed, 38 insertions, 0 deletions
diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp
index 08976ee11..fa369a360 100644
--- a/src/script/lua_api/l_client.cpp
+++ b/src/script/lua_api/l_client.cpp
@@ -39,6 +39,27 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define checkCSMRestrictionFlag(flag) \
( getClient(L)->checkCSMRestrictionFlag(CSMRestrictionFlags::flag) )
+// Not the same as FlagDesc, which contains an `u32 flag`
+struct CSMFlagDesc {
+ const char *name;
+ u64 flag;
+};
+
+/*
+ FIXME: This should eventually be moved somewhere else
+ It also needs to be kept in sync with the definition of CSMRestrictionFlags
+ in network/networkprotocol.h
+*/
+const static CSMFlagDesc flagdesc_csm_restriction[] = {
+ {"load_client_mods", CSM_RF_LOAD_CLIENT_MODS},
+ {"chat_messages", CSM_RF_CHAT_MESSAGES},
+ {"read_itemdefs", CSM_RF_READ_ITEMDEFS},
+ {"read_nodedefs", CSM_RF_READ_NODEDEFS},
+ {"lookup_nodes", CSM_RF_LOOKUP_NODES},
+ {"read_playerinfo", CSM_RF_READ_PLAYERINFO},
+ {NULL, 0}
+};
+
// get_current_modname()
int ModApiClient::l_get_current_modname(lua_State *L)
{
@@ -363,6 +384,19 @@ int ModApiClient::l_get_builtin_path(lua_State *L)
return 1;
}
+// get_csm_restrictions()
+int ModApiClient::l_get_csm_restrictions(lua_State *L)
+{
+ u64 flags = getClient(L)->getCSMRestrictionFlags();
+ const CSMFlagDesc *flagdesc = flagdesc_csm_restriction;
+
+ lua_newtable(L);
+ for (int i = 0; flagdesc[i].name; i++) {
+ setboolfield(L, -1, flagdesc[i].name, !!(flags & flagdesc[i].flag));
+ }
+ return 1;
+}
+
void ModApiClient::Initialize(lua_State *L, int top)
{
API_FCT(get_current_modname);
@@ -389,4 +423,5 @@ void ModApiClient::Initialize(lua_State *L, int top)
API_FCT(get_privilege_list);
API_FCT(get_builtin_path);
API_FCT(get_language);
+ API_FCT(get_csm_restrictions);
}
diff --git a/src/script/lua_api/l_client.h b/src/script/lua_api/l_client.h
index 0a68eeff0..6d1f70b1d 100644
--- a/src/script/lua_api/l_client.h
+++ b/src/script/lua_api/l_client.h
@@ -96,6 +96,9 @@ private:
// get_builtin_path()
static int l_get_builtin_path(lua_State *L);
+ // get_csm_restrictions()
+ static int l_get_csm_restrictions(lua_State *L);
+
public:
static void Initialize(lua_State *L, int top);
};