Paste #etS -- näytä pelkkänä tekstinä -- uusi tämän pohjalta
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | From 1bce05307601b4e692e374f265186b38e8e6173c Mon Sep 17 00:00:00 2001 From: Perttu Ahola <celeron55@gmail.com> 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<u16, RemoteClient*>::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: "<<playername<<" tried to join, but there" + <<" are already max_nonregular_users=" + <<g_settings->getU16("max_nonregular_users") + <<" players."<<std::endl; + DenyAccess(peer_id, L"Too many users."); + return; + } + if(!is_some_kind_of_admin && + num_valid_clients >= g_settings->getU16("max_users")) { actionstream<<"Server: "<<playername<<" tried to join, but there" <<" are already max_users=" -- 1.8.3.1 |