1
0

Add CSM restriction flag to block third party CSMs (#162)

This commit is contained in:
mckaygerhard 2024-06-02 05:13:31 -04:00
parent bc3f43705c
commit 8eb09a5aa1
5 changed files with 31 additions and 25 deletions

View File

@ -1352,6 +1352,7 @@ server_side_occlusion_culling (Server side occlusion culling) bool true
# LOOKUP_NODES_LIMIT: 16 (limits get_node call client-side to # LOOKUP_NODES_LIMIT: 16 (limits get_node call client-side to
# csm_restriction_noderange) # csm_restriction_noderange)
# READ_PLAYERINFO: 32 (disable get_player_names call client-side) # READ_PLAYERINFO: 32 (disable get_player_names call client-side)
# THIRD_PARTY_MODS: 256 (disable loading third-party CSMs)
csm_restriction_flags (Client side modding restrictions) int 62 csm_restriction_flags (Client side modding restrictions) int 62
# If the CSM restriction for node range is enabled, get_node calls are limited # If the CSM restriction for node range is enabled, get_node calls are limited

View File

@ -1611,6 +1611,7 @@
# LOOKUP_NODES_LIMIT: 16 (limits get_node call client-side to # LOOKUP_NODES_LIMIT: 16 (limits get_node call client-side to
# csm_restriction_noderange) # csm_restriction_noderange)
# READ_PLAYERINFO: 32 (disable get_player_names call client-side) # READ_PLAYERINFO: 32 (disable get_player_names call client-side)
# THIRD_PARTY_MODS: 256 (disable loading third-party client-provided mods)
# type: int # type: int
# csm_restriction_flags = 60 # csm_restriction_flags = 60

View File

@ -164,33 +164,35 @@ void Client::loadMods()
scanModIntoMemory(BUILTIN_MOD_NAME, getBuiltinLuaPath()); scanModIntoMemory(BUILTIN_MOD_NAME, getBuiltinLuaPath());
m_script->loadModFromMemory(BUILTIN_MOD_NAME); m_script->loadModFromMemory(BUILTIN_MOD_NAME);
ClientModConfiguration modconf(getClientModsLuaPath()); if (!checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_THIRD_PARTY_MODS)) {
m_mods = modconf.getMods(); ClientModConfiguration modconf(getClientModsLuaPath());
// complain about mods with unsatisfied dependencies m_mods = modconf.getMods();
if (!modconf.isConsistent()) { // complain about mods with unsatisfied dependencies
modconf.printUnsatisfiedModsError(); if (!modconf.isConsistent()) {
return; modconf.printUnsatisfiedModsError();
} return;
// Print mods
infostream << "Client loading mods: ";
for (const ModSpec &mod : m_mods)
infostream << mod.name << " ";
infostream << std::endl;
// Load "mod" scripts
for (const ModSpec &mod : m_mods) {
if (!string_allowed(mod.name, MODNAME_ALLOWED_CHARS)) {
throw ModError("Error loading mod \"" + mod.name +
"\": Mod name does not follow naming conventions: "
"Only characters [a-z0-9_] are allowed.");
} }
scanModIntoMemory(mod.name, mod.path);
}
// Run them // Print mods
for (const ModSpec &mod : m_mods) infostream << "Client loading mods: ";
m_script->loadModFromMemory(mod.name); for (const ModSpec &mod : m_mods)
infostream << mod.name << " ";
infostream << std::endl;
// Load "mod" scripts
for (const ModSpec &mod : m_mods) {
if (!string_allowed(mod.name, MODNAME_ALLOWED_CHARS)) {
throw ModError("Error loading mod \"" + mod.name +
"\": Mod name does not follow naming conventions: "
"Only characters [a-z0-9_] are allowed.");
}
scanModIntoMemory(mod.name, mod.path);
}
// Run them
for (const ModSpec &mod : m_mods)
m_script->loadModFromMemory(mod.name);
}
// Mods are done loading. Unlock callbacks // Mods are done loading. Unlock callbacks
m_mods_loaded = true; m_mods_loaded = true;

View File

@ -1051,6 +1051,7 @@ enum CSMRestrictionFlags : u64 {
CSM_RF_READ_NODEDEFS = 0x00000008, // Disable nodedef lookups CSM_RF_READ_NODEDEFS = 0x00000008, // Disable nodedef lookups
CSM_RF_LOOKUP_NODES = 0x00000010, // Limit node lookups CSM_RF_LOOKUP_NODES = 0x00000010, // Limit node lookups
CSM_RF_READ_PLAYERINFO = 0x00000020, // Disable player info lookups CSM_RF_READ_PLAYERINFO = 0x00000020, // Disable player info lookups
CSM_RF_THIRD_PARTY_MODS = 0x00000100, // Don't load third-party CSMs
CSM_RF_ALL = 0xFFFFFFFF, CSM_RF_ALL = 0xFFFFFFFF,
}; };

View File

@ -56,6 +56,7 @@ const static CSMFlagDesc flagdesc_csm_restriction[] = {
{"read_nodedefs", CSM_RF_READ_NODEDEFS}, {"read_nodedefs", CSM_RF_READ_NODEDEFS},
{"lookup_nodes", CSM_RF_LOOKUP_NODES}, {"lookup_nodes", CSM_RF_LOOKUP_NODES},
{"read_playerinfo", CSM_RF_READ_PLAYERINFO}, {"read_playerinfo", CSM_RF_READ_PLAYERINFO},
{"third_party_mods", CSM_RF_THIRD_PARTY_MODS},
{NULL, 0} {NULL, 0}
}; };