Skip to content

Commit

Permalink
CSM fixes: load mods after flavours & add flavour to block mod loading (
Browse files Browse the repository at this point in the history
#6738)

* 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
  • Loading branch information
nerzhul committed Dec 11, 2017
1 parent 02cc257 commit 308bb69
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 31 deletions.
5 changes: 3 additions & 2 deletions builtin/settingtypes.txt
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions minetest.conf.example
Expand Up @@ -1346,13 +1346,13 @@

# 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.
Expand Down
52 changes: 35 additions & 17 deletions src/client.cpp
Expand Up @@ -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();
Expand All @@ -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,
Expand All @@ -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";
Expand Down
8 changes: 4 additions & 4 deletions src/client.h
Expand Up @@ -140,17 +140,14 @@ 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)
{
scanModSubfolder(mod_name, mod_path, "");
}

// Initizle the mods
void initMods();

/*
request all threads managed by client to be stopped
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/defaultsettings.cpp
Expand Up @@ -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");
Expand Down
5 changes: 2 additions & 3 deletions src/game.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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()) {

Expand Down
4 changes: 4 additions & 0 deletions src/network/clientpackethandler.cpp
Expand Up @@ -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();
}

/*
Expand Down
3 changes: 2 additions & 1 deletion src/network/networkprotocol.h
Expand Up @@ -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,
};

0 comments on commit 308bb69

Please sign in to comment.