Skip to content

Commit 308bb69

Browse files
authoredDec 11, 2017
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
1 parent 02cc257 commit 308bb69

8 files changed

+54
-31
lines changed
 

Diff for: ‎builtin/settingtypes.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1121,12 +1121,13 @@ server_side_occlusion_culling (Server side occlusion culling) bool true
11211121

11221122
# Restricts the access of certain client-side functions on servers
11231123
# Combine these byteflags below to restrict more client-side features:
1124-
# LOOKUP_NODES_LIMIT: 1 (limits get_node call client-side to csm_flavour_noderange_limit)
1124+
# LOAD_CLIENT_MODS: 1 (disable client mods loading)
11251125
# CHAT_MESSAGES: 2 (disable send_chat_message call client-side)
11261126
# READ_ITEMDEFS: 4 (disable get_item_def call client-side)
11271127
# READ_NODEDEFS: 8 (disable get_node_def call client-side)
1128+
# LOOKUP_NODES_LIMIT: 16 (limits get_node call client-side to csm_flavour_noderange_limit)
11281129
# type: int
1129-
csm_flavour_limits (Client side modding flavour limits) int 3
1130+
csm_flavour_limits (Client side modding flavour limits) int 18
11301131

11311132
# If the CSM flavour for node range is enabled, get_node is limited to
11321133
# this many nodes from the player.

Diff for: ‎minetest.conf.example

+3-3
Original file line numberDiff line numberDiff line change
@@ -1346,13 +1346,13 @@
13461346

13471347
# Restricts the access of certain client-side functions on servers
13481348
# Combine these byteflags below to restrict more client-side features:
1349-
# LOOKUP_NODES_LIMIT: 1 (limits get_node call client-side to csm_flavour_noderange_limit)
1349+
# LOAD_CLIENT_MODS: 1 (disable client mods loading)
13501350
# CHAT_MESSAGES: 2 (disable send_chat_message call client-side)
13511351
# READ_ITEMDEFS: 4 (disable get_item_def call client-side)
13521352
# READ_NODEDEFS: 8 (disable get_node_def call client-side)
13531353
# type: int
1354-
# type: int
1355-
# csm_flavour_limits = 3
1354+
# LOOKUP_NODES_LIMIT: 16 (limits get_node call client-side to csm_flavour_noderange_limit)
1355+
# csm_flavour_limits = 18
13561356

13571357
# If the CSM flavour for node range is enabled, get_node is limited to
13581358
# this many nodes from the player.

Diff for: ‎src/client.cpp

+35-17
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,38 @@ Client::Client(
113113
m_script->setEnv(&m_env);
114114
}
115115

116-
void Client::loadMods()
116+
void Client::loadBuiltin()
117117
{
118118
// Load builtin
119119
scanModIntoMemory(BUILTIN_MOD_NAME, getBuiltinLuaPath());
120120

121-
// If modding is not enabled, don't load mods, just builtin
121+
m_script->loadModFromMemory(BUILTIN_MOD_NAME);
122+
}
123+
124+
void Client::loadMods()
125+
{
126+
// Don't permit to load mods twice
127+
if (m_mods_loaded) {
128+
return;
129+
}
130+
131+
// If modding is not enabled or flavour disable it, don't load mods, just builtin
122132
if (!m_modding_enabled) {
133+
warningstream << "Client side mods are disabled by configuration." << std::endl;
123134
return;
124135
}
136+
137+
if (checkCSMFlavourLimit(CSMFlavourLimit::CSM_FL_LOAD_CLIENT_MODS)) {
138+
warningstream << "Client side mods are disabled by server." << std::endl;
139+
// If mods loading is disabled and builtin integrity is wrong, disconnect user.
140+
if (!checkBuiltinIntegrity()) {
141+
// @TODO disconnect user
142+
}
143+
return;
144+
}
145+
125146
ClientModConfiguration modconf(getClientModsLuaPath());
126147
m_mods = modconf.getMods();
127-
std::vector<ModSpec> unsatisfied_mods = modconf.getUnsatisfiedMods();
128148
// complain about mods with unsatisfied dependencies
129149
if (!modconf.isConsistent()) {
130150
modconf.printUnsatisfiedModsError();
@@ -145,6 +165,18 @@ void Client::loadMods()
145165
}
146166
scanModIntoMemory(mod.name, mod.path);
147167
}
168+
169+
// Load and run "mod" scripts
170+
for (const ModSpec &mod : m_mods)
171+
m_script->loadModFromMemory(mod.name);
172+
173+
m_mods_loaded = true;
174+
}
175+
176+
bool Client::checkBuiltinIntegrity()
177+
{
178+
// @TODO
179+
return true;
148180
}
149181

150182
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
164196
}
165197
}
166198

167-
void Client::initMods()
168-
{
169-
m_script->loadModFromMemory(BUILTIN_MOD_NAME);
170-
171-
// If modding is not enabled, don't load mods, just builtin
172-
if (!m_modding_enabled) {
173-
return;
174-
}
175-
176-
// Load and run "mod" scripts
177-
for (const ModSpec &mod : m_mods)
178-
m_script->loadModFromMemory(mod.name);
179-
}
180-
181199
const std::string &Client::getBuiltinLuaPath()
182200
{
183201
static const std::string builtin_dir = porting::path_share + DIR_DELIM + "builtin";

Diff for: ‎src/client.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,14 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
140140
DISABLE_CLASS_COPY(Client);
141141

142142
// Load local mods into memory
143-
void loadMods();
143+
void loadBuiltin();
144144
void scanModSubfolder(const std::string &mod_name, const std::string &mod_path,
145145
std::string mod_subpath);
146146
inline void scanModIntoMemory(const std::string &mod_name, const std::string &mod_path)
147147
{
148148
scanModSubfolder(mod_name, mod_path, "");
149149
}
150150

151-
// Initizle the mods
152-
void initMods();
153-
154151
/*
155152
request all threads managed by client to be stopped
156153
*/
@@ -433,6 +430,8 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
433430
ModChannel *getModChannel(const std::string &channel);
434431

435432
private:
433+
void loadMods();
434+
bool checkBuiltinIntegrity();
436435

437436
// Virtual methods from con::PeerHandler
438437
void peerAdded(con::Peer *peer);
@@ -536,6 +535,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
536535
std::queue<ClientEvent *> m_client_event_queue;
537536
bool m_itemdef_received = false;
538537
bool m_nodedef_received = false;
538+
bool m_mods_loaded = false;
539539
ClientMediaDownloader *m_media_downloader;
540540

541541
// time_of_day speed approximation for old protocol

Diff for: ‎src/defaultsettings.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ void set_default_settings(Settings *settings)
329329
settings->setDefault("max_block_send_distance", "9");
330330
settings->setDefault("block_send_optimize_distance", "4");
331331
settings->setDefault("server_side_occlusion_culling", "true");
332-
settings->setDefault("csm_flavour_limits", "3");
332+
settings->setDefault("csm_flavour_limits", "18");
333333
settings->setDefault("csm_flavour_noderange_limit", "8");
334334
settings->setDefault("max_clearobjects_extra_loaded_blocks", "4096");
335335
settings->setDefault("time_speed", "72");

Diff for: ‎src/game.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -2049,7 +2049,7 @@ bool Game::initGui()
20492049

20502050
// Make sure the size of the recent messages buffer is right
20512051
chat_backend->applySettings();
2052-
2052+
20532053
// Chat backend and console
20542054
gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(),
20552055
-1, chat_backend, client, &g_menumgr);
@@ -2146,8 +2146,7 @@ bool Game::connectToServer(const std::string &playername,
21462146

21472147
fps_control.last_time = RenderingEngine::get_timer_time();
21482148

2149-
client->loadMods();
2150-
client->initMods();
2149+
client->loadBuiltin();
21512150

21522151
while (RenderingEngine::run()) {
21532152

Diff for: ‎src/network/clientpackethandler.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,10 @@ void Client::handleCommand_SrpBytesSandB(NetworkPacket* pkt)
13261326
void Client::handleCommand_CSMFlavourLimits(NetworkPacket *pkt)
13271327
{
13281328
*pkt >> m_csm_flavour_limits >> m_csm_noderange_limit;
1329+
1330+
// Now we have flavours, load mods if it's enabled
1331+
// Note: this should be moved after mods receptions from server instead
1332+
loadMods();
13291333
}
13301334

13311335
/*

Diff for: ‎src/network/networkprotocol.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -921,10 +921,11 @@ enum PlayerListModifer: u8
921921

922922
enum CSMFlavourLimit : u64 {
923923
CSM_FL_NONE = 0x00000000,
924-
CSM_FL_LOOKUP_NODES = 0x00000001, // Limit node lookups
924+
CSM_FL_LOAD_CLIENT_MODS = 0x00000001, // Disable mods provided by clients
925925
CSM_FL_CHAT_MESSAGES = 0x00000002, // Disable chat message sending from CSM
926926
CSM_FL_READ_ITEMDEFS = 0x00000004, // Disable itemdef lookups
927927
CSM_FL_READ_NODEDEFS = 0x00000008, // Disable nodedef lookups
928+
CSM_FL_LOOKUP_NODES = 0x00000010, // Limit node lookups
928929
CSM_FL_ALL = 0xFFFFFFFF,
929930
};
930931

0 commit comments

Comments
 (0)
Please sign in to comment.