Skip to content

Commit ceacff1

Browse files
paramatnerzhul
authored andcommitted
CSM restrictions: Make 'LOAD_CLIENT_MODS' disable loading of 'builtin' (#8000)
Previously, when the CSM restriction 'LOAD_CLIENT_MODS' was used a client was still able to add CSM code to 'builtin' to bypass that restriction, because 'builtin' is not yet verified. Until server-sent CSM and verifying of 'builtin' are complete, make 'LOAD_CLIENT_MODS' disable the loading of builtin. Clarify code comments and messages to distinguish between client-side modding and client-side scripting. 'Scripting' includes 'builtin', 'modding' does not.
1 parent c26eab6 commit ceacff1

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

builtin/settingtypes.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -1189,14 +1189,16 @@ block_send_optimize_distance (Block send optimize distance) int 4 2
11891189
# so that the utility of noclip mode is reduced.
11901190
server_side_occlusion_culling (Server side occlusion culling) bool true
11911191

1192-
# Restricts the access of certain client-side functions on servers
1193-
# Combine these byteflags below to restrict client-side features:
1194-
# LOAD_CLIENT_MODS: 1 (disable client mods loading)
1192+
# Restricts the access of certain client-side functions on servers.
1193+
# Combine the byteflags below to restrict client-side features, or set to 0
1194+
# for no restrictions:
1195+
# LOAD_CLIENT_MODS: 1 (disable loading client-provided mods)
11951196
# CHAT_MESSAGES: 2 (disable send_chat_message call client-side)
11961197
# READ_ITEMDEFS: 4 (disable get_item_def call client-side)
11971198
# READ_NODEDEFS: 8 (disable get_node_def call client-side)
11981199
# LOOKUP_NODES_LIMIT: 16 (limits get_node call client-side to
11991200
# csm_restriction_noderange)
1201+
# READ_PLAYERINFO: 32 (disable get_player_names call client-side)
12001202
csm_restriction_flags (Client side modding restrictions) int 62
12011203

12021204
# If the CSM restriction for node range is enabled, get_node calls are limited

src/client/client.cpp

+26-10
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ Client::Client(
110110
m_cache_save_interval = g_settings->getU16("server_map_save_interval");
111111

112112
m_modding_enabled = g_settings->getBool("enable_client_modding");
113-
// Only create the client script environment if client modding is enabled
113+
// Only create the client script environment if client scripting is enabled by the
114+
// client.
114115
if (m_modding_enabled) {
115116
m_script = new ClientScripting(this);
116117
m_env.setScript(m_script);
@@ -125,27 +126,42 @@ void Client::loadMods()
125126
return;
126127
}
127128

128-
// If client modding is not enabled, don't load client-provided CSM mods or
129-
// builtin.
129+
// If client scripting is disabled by the client, don't load builtin or
130+
// client-provided mods.
130131
if (!m_modding_enabled) {
131-
warningstream << "Client side mods are disabled by configuration." << std::endl;
132+
warningstream << "Client side scripting is disabled by client." << std::endl;
133+
return;
134+
}
135+
136+
// If client scripting is disabled by the server, don't load builtin or
137+
// client-provided mods.
138+
// TODO Delete this code block when server-sent CSM and verifying of builtin are
139+
// complete.
140+
if (checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOAD_CLIENT_MODS)) {
141+
warningstream << "Client-provided mod loading is disabled by server." <<
142+
std::endl;
143+
// This line is needed because builtin is not loaded
144+
m_modding_enabled = false;
132145
return;
133146
}
134147

135148
// Load builtin
136149
scanModIntoMemory(BUILTIN_MOD_NAME, getBuiltinLuaPath());
137150
m_script->loadModFromMemory(BUILTIN_MOD_NAME);
138151

139-
// If the server has disabled client-provided CSM mod loading, don't load
140-
// client-provided CSM mods. Builtin is loaded so needs verfying.
152+
// TODO Uncomment when server-sent CSM and verifying of builtin are complete
153+
/*
154+
// Don't load client-provided mods if disabled by server
141155
if (checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOAD_CLIENT_MODS)) {
142-
warningstream << "Client side mods are disabled by server." << std::endl;
156+
warningstream << "Client-provided mod loading is disabled by server." <<
157+
std::endl;
143158
// If builtin integrity is wrong, disconnect user
144159
if (!checkBuiltinIntegrity()) {
145-
// @TODO disconnect user
160+
// TODO disconnect user
146161
}
147162
return;
148163
}
164+
*/
149165

150166
ClientModConfiguration modconf(getClientModsLuaPath());
151167
m_mods = modconf.getMods();
@@ -155,7 +171,7 @@ void Client::loadMods()
155171
}
156172

157173
// Print mods
158-
infostream << "Client Loading mods: ";
174+
infostream << "Client loading mods: ";
159175
for (const ModSpec &mod : m_mods)
160176
infostream << mod.name << " ";
161177
infostream << std::endl;
@@ -181,7 +197,7 @@ void Client::loadMods()
181197

182198
bool Client::checkBuiltinIntegrity()
183199
{
184-
// @TODO
200+
// TODO
185201
return true;
186202
}
187203

src/client/game.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,7 @@ void Game::processKeyInput()
18911891
if (client->moddingEnabled())
18921892
openConsole(0.2, L".");
18931893
else
1894-
m_game_ui->showStatusText(wgettext("CSM is disabled"));
1894+
m_game_ui->showStatusText(wgettext("Client side scripting is disabled"));
18951895
} else if (wasKeyDown(KeyType::CONSOLE)) {
18961896
openConsole(core::clamp(g_settings->getFloat("console_height"), 0.1f, 1.0f));
18971897
} else if (wasKeyDown(KeyType::FREEMOVE)) {
@@ -2554,7 +2554,7 @@ void Game::handleClientEvent_PlayerForceMove(ClientEvent *event, CameraOrientati
25542554

25552555
void Game::handleClientEvent_Deathscreen(ClientEvent *event, CameraOrientation *cam)
25562556
{
2557-
// If CSM enabled, deathscreen is handled by CSM code in
2557+
// If client scripting is enabled, deathscreen is handled by CSM code in
25582558
// builtin/client/init.lua
25592559
if (client->moddingEnabled())
25602560
client->getScript()->on_death();

src/network/networkprotocol.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,11 @@ enum PlayerListModifer: u8
947947

948948
enum CSMRestrictionFlags : u64 {
949949
CSM_RF_NONE = 0x00000000,
950-
CSM_RF_LOAD_CLIENT_MODS = 0x00000001, // Disable mods provided by clients
950+
// Until server-sent CSM and verifying of builtin are complete,
951+
// 'CSM_RF_LOAD_CLIENT_MODS' also disables loading 'builtin'.
952+
// When those are complete, this should return to only being a restriction on the
953+
// loading of client mods.
954+
CSM_RF_LOAD_CLIENT_MODS = 0x00000001, // Don't load client-provided mods or 'builtin'
951955
CSM_RF_CHAT_MESSAGES = 0x00000002, // Disable chat message sending from CSM
952956
CSM_RF_READ_ITEMDEFS = 0x00000004, // Disable itemdef lookups
953957
CSM_RF_READ_NODEDEFS = 0x00000008, // Disable nodedef lookups

0 commit comments

Comments
 (0)