]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
CSM fixes: load mods after flavours & add flavour to block mod loading (#6738)
authorLoïc Blot <nerzhul@users.noreply.github.com>
Mon, 11 Dec 2017 16:33:44 +0000 (17:33 +0100)
committerGitHub <noreply@github.com>
Mon, 11 Dec 2017 16:33:44 +0000 (17:33 +0100)
* CSM fixes: load mods after flavours & add flavour to block mod loading

* Don't permit to load mods twice

* Prepare builtin integrity global algorithm

* Add missing doc & use a nicer byteflag for LOAD_CLIENT_MODS flavour

* flag typo fix

* Invert CSM_FL_LOOKUP_NODES & CSM_FL_LOAD_CLIENT_MODS ids

builtin/settingtypes.txt
minetest.conf.example
src/client.cpp
src/client.h
src/defaultsettings.cpp
src/game.cpp
src/network/clientpackethandler.cpp
src/network/networkprotocol.h

index fc628c88f40f2473e664ad4afcce521292b4e4fe..695c0b1d6178357ba4147d9b26af733900ac292a 100644 (file)
@@ -1121,12 +1121,13 @@ server_side_occlusion_culling (Server side occlusion culling) bool true
 
 #    Restricts the access of certain client-side functions on servers
 #    Combine these byteflags below to restrict more client-side features:
-#    LOOKUP_NODES_LIMIT: 1 (limits get_node call client-side to csm_flavour_noderange_limit)
+#    LOAD_CLIENT_MODS: 1 (disable client mods loading)
 #    CHAT_MESSAGES: 2 (disable send_chat_message call client-side)
 #    READ_ITEMDEFS: 4 (disable get_item_def call client-side)
 #    READ_NODEDEFS: 8 (disable get_node_def call client-side)
+#    LOOKUP_NODES_LIMIT: 16 (limits get_node call client-side to csm_flavour_noderange_limit)
 #    type: int
-csm_flavour_limits (Client side modding flavour limits) int 3
+csm_flavour_limits (Client side modding flavour limits) int 18
 
 #   If the CSM flavour for node range is enabled, get_node is limited to
 #   this many nodes from the player.
index 9ca6efb05b63fefa3a5865648bfcbc1c9b4a7120..357d677f41eed5db14ed5188f1503bff346bc918 100644 (file)
 
 #    Restricts the access of certain client-side functions on servers
 #    Combine these byteflags below to restrict more client-side features:
-#    LOOKUP_NODES_LIMIT: 1 (limits get_node call client-side to csm_flavour_noderange_limit)
+#    LOAD_CLIENT_MODS: 1 (disable client mods loading)
 #    CHAT_MESSAGES: 2 (disable send_chat_message call client-side)
 #    READ_ITEMDEFS: 4 (disable get_item_def call client-side)
 #    READ_NODEDEFS: 8 (disable get_node_def call client-side)
 #    type: int
-#    type: int
-# csm_flavour_limits = 3
+#    LOOKUP_NODES_LIMIT: 16 (limits get_node call client-side to csm_flavour_noderange_limit)
+# csm_flavour_limits = 18
 
 #    If the CSM flavour for node range is enabled, get_node is limited to
 #    this many nodes from the player.
index c04bf055a1c609e8c3a93f4477aec80a4d700272..6e29607ca5aa7123c83be1496afccd70c987cf8b 100644 (file)
@@ -113,18 +113,38 @@ Client::Client(
        m_script->setEnv(&m_env);
 }
 
-void Client::loadMods()
+void Client::loadBuiltin()
 {
        // Load builtin
        scanModIntoMemory(BUILTIN_MOD_NAME, getBuiltinLuaPath());
 
-       // If modding is not enabled, don't load mods, just builtin
+       m_script->loadModFromMemory(BUILTIN_MOD_NAME);
+}
+
+void Client::loadMods()
+{
+       // Don't permit to load mods twice
+       if (m_mods_loaded) {
+               return;
+       }
+
+       // If modding is not enabled or flavour disable it, don't load mods, just builtin
        if (!m_modding_enabled) {
+               warningstream << "Client side mods are disabled by configuration." << std::endl;
                return;
        }
+
+       if (checkCSMFlavourLimit(CSMFlavourLimit::CSM_FL_LOAD_CLIENT_MODS)) {
+               warningstream << "Client side mods are disabled by server." << std::endl;
+               // If mods loading is disabled and builtin integrity is wrong, disconnect user.
+               if (!checkBuiltinIntegrity()) {
+                       // @TODO disconnect user
+               }
+               return;
+       }
+
        ClientModConfiguration modconf(getClientModsLuaPath());
        m_mods = modconf.getMods();
-       std::vector<ModSpec> unsatisfied_mods = modconf.getUnsatisfiedMods();
        // complain about mods with unsatisfied dependencies
        if (!modconf.isConsistent()) {
                modconf.printUnsatisfiedModsError();
@@ -145,6 +165,18 @@ void Client::loadMods()
                }
                scanModIntoMemory(mod.name, mod.path);
        }
+
+       // Load and run "mod" scripts
+       for (const ModSpec &mod : m_mods)
+               m_script->loadModFromMemory(mod.name);
+
+       m_mods_loaded = true;
+}
+
+bool Client::checkBuiltinIntegrity()
+{
+       // @TODO
+       return true;
 }
 
 void Client::scanModSubfolder(const std::string &mod_name, const std::string &mod_path,
@@ -164,20 +196,6 @@ void Client::scanModSubfolder(const std::string &mod_name, const std::string &mo
        }
 }
 
-void Client::initMods()
-{
-       m_script->loadModFromMemory(BUILTIN_MOD_NAME);
-
-       // If modding is not enabled, don't load mods, just builtin
-       if (!m_modding_enabled) {
-               return;
-       }
-
-       // Load and run "mod" scripts
-       for (const ModSpec &mod : m_mods)
-               m_script->loadModFromMemory(mod.name);
-}
-
 const std::string &Client::getBuiltinLuaPath()
 {
        static const std::string builtin_dir = porting::path_share + DIR_DELIM + "builtin";
index 06c67105f72420c90d8afbfb23b4eb1fd412f732..6093d6a6ffc7467ddec20611b8ea18e5ea74e5d8 100644 (file)
@@ -140,7 +140,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        DISABLE_CLASS_COPY(Client);
 
        // Load local mods into memory
-       void loadMods();
+       void loadBuiltin();
        void scanModSubfolder(const std::string &mod_name, const std::string &mod_path,
                                std::string mod_subpath);
        inline void scanModIntoMemory(const std::string &mod_name, const std::string &mod_path)
@@ -148,9 +148,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
                scanModSubfolder(mod_name, mod_path, "");
        }
 
-       // Initizle the mods
-       void initMods();
-
        /*
         request all threads managed by client to be stopped
         */
@@ -433,6 +430,8 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        ModChannel *getModChannel(const std::string &channel);
 
 private:
+       void loadMods();
+       bool checkBuiltinIntegrity();
 
        // Virtual methods from con::PeerHandler
        void peerAdded(con::Peer *peer);
@@ -536,6 +535,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        std::queue<ClientEvent *> m_client_event_queue;
        bool m_itemdef_received = false;
        bool m_nodedef_received = false;
+       bool m_mods_loaded = false;
        ClientMediaDownloader *m_media_downloader;
 
        // time_of_day speed approximation for old protocol
index cc113c6f6ddd624d926f8f5e0c88797f65a6d126..d4dbb5481758503078c85e62a4d92e177bb75c49 100644 (file)
@@ -329,7 +329,7 @@ void set_default_settings(Settings *settings)
        settings->setDefault("max_block_send_distance", "9");
        settings->setDefault("block_send_optimize_distance", "4");
        settings->setDefault("server_side_occlusion_culling", "true");
-       settings->setDefault("csm_flavour_limits", "3");
+       settings->setDefault("csm_flavour_limits", "18");
        settings->setDefault("csm_flavour_noderange_limit", "8");
        settings->setDefault("max_clearobjects_extra_loaded_blocks", "4096");
        settings->setDefault("time_speed", "72");
index fca9c5e68f28b6161e143b6f70d6512a5be134db..ee2b19933698bda28e01622ddcd2b2104044f482 100644 (file)
@@ -2049,7 +2049,7 @@ bool Game::initGui()
 
        // Make sure the size of the recent messages buffer is right
        chat_backend->applySettings();
-    
+
        // Chat backend and console
        gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(),
                        -1, chat_backend, client, &g_menumgr);
@@ -2146,8 +2146,7 @@ bool Game::connectToServer(const std::string &playername,
 
                fps_control.last_time = RenderingEngine::get_timer_time();
 
-               client->loadMods();
-               client->initMods();
+               client->loadBuiltin();
 
                while (RenderingEngine::run()) {
 
index 5de99418e5c183def4cfb9683de5de3df5fd7df9..0ec46049e485db54380b8445a2e801fb3cad1092 100644 (file)
@@ -1326,6 +1326,10 @@ void Client::handleCommand_SrpBytesSandB(NetworkPacket* pkt)
 void Client::handleCommand_CSMFlavourLimits(NetworkPacket *pkt)
 {
        *pkt >> m_csm_flavour_limits >> m_csm_noderange_limit;
+
+       // Now we have flavours, load mods if it's enabled
+       // Note: this should be moved after mods receptions from server instead
+       loadMods();
 }
 
 /*
index fe68f39b290c8d1025e3d46b7763fb18c1bd1795..1f10822e17a2d7ab5759981f462550e884b1b3ef 100644 (file)
@@ -921,10 +921,11 @@ enum PlayerListModifer: u8
 
 enum CSMFlavourLimit : u64 {
        CSM_FL_NONE = 0x00000000,
-       CSM_FL_LOOKUP_NODES = 0x00000001, // Limit node lookups
+       CSM_FL_LOAD_CLIENT_MODS = 0x00000001, // Disable mods provided by clients
        CSM_FL_CHAT_MESSAGES = 0x00000002, // Disable chat message sending from CSM
        CSM_FL_READ_ITEMDEFS = 0x00000004, // Disable itemdef lookups
        CSM_FL_READ_NODEDEFS = 0x00000008, // Disable nodedef lookups
+       CSM_FL_LOOKUP_NODES = 0x00000010, // Limit node lookups
        CSM_FL_ALL = 0xFFFFFFFF,
 };