From 1bce05307601b4e692e374f265186b38e8e6173c Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 4 Aug 2013 11:45:55 +0300 Subject: [PATCH] Setting max_nonregular_users sets limit for users with no privilege "regular" --- builtin/privileges.lua | 1 + minetest.conf.example | 4 +++- src/defaultsettings.cpp | 1 + src/server.cpp | 37 +++++++++++++++++++++++++++++++------ 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/builtin/privileges.lua b/builtin/privileges.lua index 8dd06b2..6d2d0d5 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_nonregular_users") diff --git a/minetest.conf.example b/minetest.conf.example index 4c049f8..3eb5427 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 +# Maximum number of non-admin players connected simultaneously #max_users = 100 +# Maximum number of non-admin players without the "regular" privilege +#max_nonregular_users = 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 326e11b..c94e2c6 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -151,6 +151,7 @@ void set_default_settings(Settings *settings) settings->setDefault("default_game", "minetest"); settings->setDefault("motd", ""); settings->setDefault("max_users", "100"); + settings->setDefault("max_nonregular_users", "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 4099d99..4a2389c 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1991,12 +1991,37 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) // 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")) + 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_nonregular_users")) + { + actionstream<<"Server: "<= g_settings->getU16("max_users")) { actionstream<<"Server: "<