From a5197eaebc61ac6b555a640f36c0b427faef381d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Blot?= Date: Mon, 24 Dec 2018 10:51:10 +0100 Subject: [PATCH] CSM: add requested CSM_RF_READ_PLAYERINFO (#8007) * CSM: add requested CSM_RF_READ_PLAYERINFO This new CSM limit permit to limit PLAYERINFO read from server. It affects get_player_names call --- builtin/client/chatcommands.lua | 9 +++++++-- builtin/settingtypes.txt | 2 +- doc/client_lua_api.txt | 2 +- minetest.conf.example | 3 ++- src/defaultsettings.cpp | 2 +- src/network/networkprotocol.h | 1 + src/script/lua_api/l_client.cpp | 7 +++++++ 7 files changed, 20 insertions(+), 6 deletions(-) diff --git a/builtin/client/chatcommands.lua b/builtin/client/chatcommands.lua index ed43a614..201ca4a9 100644 --- a/builtin/client/chatcommands.lua +++ b/builtin/client/chatcommands.lua @@ -40,8 +40,13 @@ end) core.register_chatcommand("list_players", { description = core.gettext("List online players"), func = function(param) - local players = table.concat(core.get_player_names(), ", ") - core.display_chat_message(core.gettext("Online players: ") .. players) + local player_names = core.get_player_names() + if not player_names then + return false, core.gettext("This command is disabled by server.") + end + + local players = table.concat(player_names, ", ") + return true, core.gettext("Online players: ") .. players end }) diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 40db037e..66d4c324 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -1198,7 +1198,7 @@ server_side_occlusion_culling (Server side occlusion culling) bool true # READ_NODEDEFS: 8 (disable get_node_def call client-side) # LOOKUP_NODES_LIMIT: 16 (limits get_node call client-side to # csm_restriction_noderange) -csm_restriction_flags (Client side modding restrictions) int 30 +csm_restriction_flags (Client side modding restrictions) int 62 # If the CSM restriction for node range is enabled, get_node calls are limited # to this distance from the player to the node. diff --git a/doc/client_lua_api.txt b/doc/client_lua_api.txt index 3b6e1b25..41560b98 100644 --- a/doc/client_lua_api.txt +++ b/doc/client_lua_api.txt @@ -763,7 +763,7 @@ Call these functions only at load time! ### Client Environment * `minetest.get_player_names()` - * Returns list of player names on server + * Returns list of player names on server (nil if CSM_RF_READ_PLAYERINFO is enabled by server) * `minetest.disconnect()` * Disconnect from the server and exit to main menu. * Returns `false` if the client is already disconnecting otherwise returns `true`. diff --git a/minetest.conf.example b/minetest.conf.example index b7647344..0bf0b988 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -1468,8 +1468,9 @@ # READ_NODEDEFS: 8 (disable get_node_def call client-side) # LOOKUP_NODES_LIMIT: 16 (limits get_node call client-side to # csm_restriction_noderange) +# READ_PLAYERINFO: 32 (disable get_player_names call client-side) # type: int -# csm_restriction_flags = 30 +# csm_restriction_flags = 62 # If the CSM restriction for node range is enabled, get_node calls are limited # to this distance from the player to the node. diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 1ae6e046..b061b684 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -346,7 +346,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_restriction_flags", "30"); + settings->setDefault("csm_restriction_flags", "62"); settings->setDefault("csm_restriction_noderange", "0"); settings->setDefault("max_clearobjects_extra_loaded_blocks", "4096"); settings->setDefault("time_speed", "72"); diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index 0cf77b8c..6d670848 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -952,5 +952,6 @@ enum CSMRestrictionFlags : u64 { CSM_RF_READ_ITEMDEFS = 0x00000004, // Disable itemdef lookups CSM_RF_READ_NODEDEFS = 0x00000008, // Disable nodedef lookups CSM_RF_LOOKUP_NODES = 0x00000010, // Limit node lookups + CSM_RF_READ_PLAYERINFO = 0x00000020, // Disable player info lookups CSM_RF_ALL = 0xFFFFFFFF, }; diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp index 8a5867a3..6d9d832b 100644 --- a/src/script/lua_api/l_client.cpp +++ b/src/script/lua_api/l_client.cpp @@ -116,6 +116,13 @@ int ModApiClient::l_clear_out_chat_queue(lua_State *L) // get_player_names() int ModApiClient::l_get_player_names(lua_State *L) { + // clang-format off + if (getClient(L)->checkCSMRestrictionFlag( + CSMRestrictionFlags::CSM_RF_READ_PLAYERINFO)) { + return 0; + } + // clang-format on + const std::list &plist = getClient(L)->getConnectedPlayerNames(); lua_createtable(L, plist.size(), 0); int newTable = lua_gettop(L);