From b20bb5717c683c546a91b506caaa07cb2bf08ebc Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sun, 1 Jul 2018 12:31:28 +0200 Subject: [PATCH] Make the server status message customizable (#7357) Remove now redundant setting show_statusline_on_connect Improve documentation of `minetest.get_server_status` --- builtin/game/chatcommands.lua | 6 +++++- builtin/game/misc.lua | 6 ++++++ builtin/settingtypes.txt | 3 --- doc/lua_api.txt | 8 +++++++- minetest.conf.example | 4 ---- src/defaultsettings.cpp | 1 - src/server.cpp | 5 ----- 7 files changed, 18 insertions(+), 15 deletions(-) diff --git a/builtin/game/chatcommands.lua b/builtin/game/chatcommands.lua index 8121c6b17..ab73e4c5e 100644 --- a/builtin/game/chatcommands.lua +++ b/builtin/game/chatcommands.lua @@ -791,7 +791,11 @@ core.register_chatcommand("rollback", { core.register_chatcommand("status", { description = "Print server status", func = function(name, param) - return true, core.get_server_status() + local status = core.get_server_status(name, false) + if status and status ~= "" then + return true, status + end + return false, "This command was disabled by a mod or game" end, }) diff --git a/builtin/game/misc.lua b/builtin/game/misc.lua index d479cdd3a..f0b0a387e 100644 --- a/builtin/game/misc.lua +++ b/builtin/game/misc.lua @@ -62,6 +62,12 @@ end core.register_on_joinplayer(function(player) local player_name = player:get_player_name() player_list[player_name] = player + if not minetest.is_singleplayer() then + local status = core.get_server_status(player_name, true) + if status and status ~= "" then + core.chat_send_player(player_name, status) + end + end core.send_join_message(player_name) end) diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 517ee70c5..052e842f7 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -808,9 +808,6 @@ map-dir (Map directory) path # Setting it to -1 disables the feature. item_entity_ttl (Item entity TTL) int 900 -# If enabled, show the server status message on player connection. -show_statusline_on_connect (Status message on connection) bool true - # Enable players getting damage and dying. enable_damage (Damage) bool false diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 08be10f1c..c3b05bb8c 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -3029,7 +3029,13 @@ These functions return the leftover itemstack. negative delay cancels the current active shutdown zero delay triggers an immediate shutdown. * `minetest.cancel_shutdown_requests()`: cancel current delayed shutdown -* `minetest.get_server_status()`: returns server status string +* `minetest.get_server_status(name, joined)` + * Returns the server status string when a player joins or when the command + `/status` is called. Returns `nil` or an empty string when the message is + disabled. + * `joined`: Boolean value, indicates whether the function was called when + a player joined. + * This function may be overwritten by mods to customize the status message. * `minetest.get_server_uptime()`: returns the server uptime in seconds * `minetest.remove_player(name)`: remove player from database (if he is not connected). * Does not remove player authentication data, minetest.player_exists will continue to return true. diff --git a/minetest.conf.example b/minetest.conf.example index 0e9ccfb86..3d5e5cb1b 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -975,10 +975,6 @@ # type: int # item_entity_ttl = 900 -# If enabled, show the server status message on player connection. -# type: bool -# show_statusline_on_connect = true - # Enable players getting damage and dying. # type: bool # enable_damage = false diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index c30da8c33..0ec969e93 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -285,7 +285,6 @@ void set_default_settings(Settings *settings) settings->setDefault("motd", ""); settings->setDefault("max_users", "15"); settings->setDefault("creative_mode", "false"); - settings->setDefault("show_statusline_on_connect", "true"); settings->setDefault("enable_damage", "true"); settings->setDefault("default_password", ""); settings->setDefault("default_privs", "interact, shout"); diff --git a/src/server.cpp b/src/server.cpp index 89aed90c8..6cc4fe79f 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1136,11 +1136,6 @@ PlayerSAO* Server::StageTwoClientInit(u16 peer_id) // Send Breath SendPlayerBreath(playersao); - // Note things in chat if not in simple singleplayer mode - if (!m_simple_singleplayer_mode && g_settings->getBool("show_statusline_on_connect")) { - // Send information about server to player in chat - SendChatMessage(peer_id, getStatusString()); - } Address addr = getPeerAddress(player->peer_id); std::string ip_str = addr.serializeString(); actionstream<getName() <<" [" << ip_str << "] joins game. " << std::endl;