]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
[CSM] Implement minetest.get_csm_restrictions()
authorsfan5 <sfan5@live.de>
Sat, 9 Nov 2019 10:00:19 +0000 (11:00 +0100)
committersfan5 <sfan5@live.de>
Mon, 11 Nov 2019 13:06:48 +0000 (14:06 +0100)
fixes #8068

clientmods/preview/init.lua
doc/client_lua_api.txt
src/client/client.h
src/script/lua_api/l_client.cpp
src/script/lua_api/l_client.h

index dd856217f7eff9a82e5c7e93edc48904884033b2..2e679b866175df5f78d10a44cb8d188a1569e4d8 100644 (file)
@@ -14,6 +14,9 @@ print("Server version: " .. server_info.protocol_version)
 print("Server ip: " .. server_info.ip)
 print("Server address: " .. server_info.address)
 print("Server port: " .. server_info.port)
+
+print("CSM restrictions: " .. dump(core.get_csm_restrictions()))
+
 mod_channel = core.mod_channel_join("experimental_preview")
 
 core.after(4, function()
index 78cd2ead28988c92c4ff6b17761932ece4d73fbd..a7e928f566eb6765bbf061688adfe675e77352b1 100644 (file)
@@ -649,6 +649,11 @@ Minetest namespace reference
 * `minetest.sha1(data, [raw])`: returns the sha1 hash of data
     * `data`: string of data to hash
     * `raw`: return raw bytes instead of hex digits, default: false
+* `minetest.get_csm_restrictions()`: returns a table of `Flags` indicating the
+   restrictions applied to the current mod.
+   * If a flag in this table is set to true, the feature is RESTRICTED.
+   * Possible flags: `load_client_mods`, `chat_messages`, `read_itemdefs`,
+                   `read_nodedefs`, `lookup_nodes`, `read_playerinfo`
 
 ### Logging
 * `minetest.debug(...)`
index 5144af69fe7ca4b37903e65af7ce87807429b1f9..0e0765caea109a3136cbd184096c96af8bdfdd0b 100644 (file)
@@ -410,6 +410,11 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
                return m_address_name;
        }
 
+       inline u64 getCSMRestrictionFlags() const
+       {
+               return m_csm_restriction_flags;
+       }
+
        inline bool checkCSMRestrictionFlag(CSMRestrictionFlags flag) const
        {
                return m_csm_restriction_flags & flag;
index 08976ee11a6dfc0e83b8c4166a45e57c192d30be..fa369a360b53a445c65e9081df2deed1ba2f32d8 100644 (file)
@@ -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);
 }
index 0a68eeff0b6efa0a420429799c71648c177d72fe..6d1f70b1d3160cbf6962d30dfd84f5e4e7423dca 100644 (file)
@@ -96,6 +96,9 @@ class ModApiClient : public ModApiBase
        // 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);
 };