diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client.cpp | 52 | ||||
-rw-r--r-- | src/client.h | 8 | ||||
-rw-r--r-- | src/defaultsettings.cpp | 2 | ||||
-rw-r--r-- | src/game.cpp | 5 | ||||
-rw-r--r-- | src/network/clientpackethandler.cpp | 4 | ||||
-rw-r--r-- | src/network/networkprotocol.h | 3 |
6 files changed, 48 insertions, 26 deletions
diff --git a/src/client.cpp b/src/client.cpp index c04bf055a..6e29607ca 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -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"; diff --git a/src/client.h b/src/client.h index 06c67105f..6093d6a6f 100644 --- a/src/client.h +++ b/src/client.h @@ -140,7 +140,7 @@ public: 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 @@ public: scanModSubfolder(mod_name, mod_path, ""); } - // Initizle the mods - void initMods(); - /* request all threads managed by client to be stopped */ @@ -433,6 +430,8 @@ public: 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 @@ private: 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 diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index cc113c6f6..d4dbb5481 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -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"); diff --git a/src/game.cpp b/src/game.cpp index fca9c5e68..ee2b19933 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -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()) { diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 5de99418e..0ec46049e 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -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(); } /* diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index fe68f39b2..1f10822e1 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -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, }; |