From 567dcb81c6882363dac35ae55ff4dd40b04d3029 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 4 Aug 2013 11:45:55 +0300 Subject: [PATCH] Setting max_visitor_players sets limit for players with no privilege "regular"; also rename setting max_users -> max_players --- builtin/deprecated.lua | 8 ++++++++ builtin/privileges.lua | 1 + minetest.conf.example | 6 ++++-- src/defaultsettings.cpp | 3 ++- src/server.cpp | 49 +++++++++++++++++++++++++++++++++++++------------ src/serverlist.cpp | 2 +- 6 files changed, 53 insertions(+), 16 deletions(-) diff --git a/builtin/deprecated.lua b/builtin/deprecated.lua index 23ab386..e96c356 100644 --- a/builtin/deprecated.lua +++ b/builtin/deprecated.lua @@ -16,6 +16,10 @@ minetest.digprop_woodlike = digprop_err minetest.digprop_leaveslike = digprop_err minetest.digprop_glasslike = digprop_err +-- +-- Random stuff +-- + minetest.node_metadata_inventory_move_allow_all = function() minetest.log("info", "WARNING: minetest.node_metadata_inventory_move_allow_all is obsolete and does nothing.") end @@ -24,6 +28,10 @@ minetest.add_to_creative_inventory = function(itemstring) minetest.log('info', "WARNING: minetest.add_to_creative_inventory: This function is deprecated and does nothing.") end +if minetest.setting_get("max_users") then + minetest.log("error", "WARNING: max_users setting is deprecated; name changed to max_players") +end + -- -- EnvRef -- diff --git a/builtin/privileges.lua b/builtin/privileges.lua index 8dd06b2..4bec350 100644 --- a/builtin/privileges.lua +++ b/builtin/privileges.lua @@ -49,4 +49,5 @@ minetest.register_privilege("noclip", { give_to_singleplayer = false, }) minetest.register_privilege("rollback", "Can use the rollback functionality") +minetest.register_privilege("regular", "Can join when player count is above max_visitor_players") diff --git a/minetest.conf.example b/minetest.conf.example index 29900b9..2fab1b0 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -216,8 +216,10 @@ #map-dir = /custom/world # Message of the Day #motd = Welcome to this awesome Minetest server! -# Maximum number of players connected simultaneously -#max_users = 100 +# Maximum number of non-admin players connected simultaneously +#max_players = 100 +# Maximum number of non-admin players without the "regular" privilege +#max_visitor_players = 50 # Set to true to disallow old clients from connecting #strict_protocol_version_checking = false # Set to true to enable creative mode (unlimited inventory) diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 33adf10..12cd4f0 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -150,7 +150,8 @@ void set_default_settings(Settings *settings) // "map-dir" doesn't exist by default. settings->setDefault("default_game", "minetest"); settings->setDefault("motd", ""); - settings->setDefault("max_users", "100"); + settings->setDefault("max_players", "100"); + settings->setDefault("max_visitor_players", "50"); settings->setDefault("strict_protocol_version_checking", "false"); settings->setDefault("creative_mode", "false"); settings->setDefault("enable_damage", "true"); diff --git a/src/server.cpp b/src/server.cpp index f5f6645..ffc63cf 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1989,19 +1989,44 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) return; } - // Enforce user limit. - // Don't enforce for users that have some admin right - if(m_clients.size() >= g_settings->getU16("max_users") && - !checkPriv(playername, "server") && - !checkPriv(playername, "ban") && - !checkPriv(playername, "privs") && - !checkPriv(playername, "password") && - playername != g_settings->get("name")) + // Enforce player limit. + // Don't enforce for players that have some admin right + bool is_some_kind_of_admin = ( + checkPriv(playername, "server") || + checkPriv(playername, "ban") || + checkPriv(playername, "privs") || + checkPriv(playername, "password") || + playername == g_settings->get("name") + ); + bool is_regular = ( + is_some_kind_of_admin || + checkPriv(playername, "regular") + ); + u32 num_valid_clients = 0; + for(std::map::iterator + i = m_clients.begin(); i != m_clients.end(); ++i) + { + RemoteClient *client = i->second; + if(!client->denied) + num_valid_clients++; + } + if(!is_regular && + num_valid_clients >= g_settings->getU16("max_visitor_players")) + { + actionstream<<"Server: "<= g_settings->getU16("max_players")) { actionstream<<"Server: "<denied = true; // If there are way too many clients, get rid of denied new ones immediately - if(m_clients.size() > 2 * g_settings->getU16("max_users")){ + if(m_clients.size() > 2 * g_settings->getU16("max_players")){ // Delete peer to stop sending it data m_con.DeletePeer(peer_id); // Delete client also to stop block sends and other stuff diff --git a/src/serverlist.cpp b/src/serverlist.cpp index bc09f6c..6c8a406 100644 --- a/src/serverlist.cpp +++ b/src/serverlist.cpp @@ -213,7 +213,7 @@ void sendAnnounce(std::string action, u16 clients, double uptime, std::string ga server["password"] = g_settings->getBool("disallow_empty_password"); server["pvp"] = g_settings->getBool("enable_pvp"); server["clients"] = clients; - server["clients_max"] = g_settings->get("max_users"); + server["clients_max"] = g_settings->get("max_players"); if (uptime >=1) server["uptime"] = (int)uptime; if (gameid!="") server["gameid"] = gameid; } -- 1.8.3.1