Skip to content
Permalink
Browse files

CSM fixes: load mods after flavours & add flavour to block mod loading (

#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 308bb69eefdfb2ff3b893c124ccf0321d99a1bfd
@@ -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.
@@ -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.
@@ -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";
@@ -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
*/
@@ -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
@@ -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");
@@ -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()) {

@@ -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();
}

/*
@@ -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.
You can’t perform that action at this time.