pastebin

Paste #HcT -- näytä pelkkänä tekstinä -- uusi tämän pohjalta

Värjäys: Tyyli: ensimmäinen rivinumero: Tabin korvaus:

  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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
From 567dcb81c6882363dac35ae55ff4dd40b04d3029 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_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<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_visitor_players"))
+		{
+			actionstream<<"Server: "<<playername<<" tried to join, but there"
+					<<" are already max_visitor_players="
+					<<g_settings->getU16("max_visitor_players")
+					<<" players."<<std::endl;
+			DenyAccess(peer_id, L"Too many visitor players.");
+			return;
+		}
+		if(!is_some_kind_of_admin &&
+				num_valid_clients >= g_settings->getU16("max_players"))
 		{
 			actionstream<<"Server: "<<playername<<" tried to join, but there"
-					<<" are already max_users="
-					<<g_settings->getU16("max_users")<<" players."<<std::endl;
-			DenyAccess(peer_id, L"Too many users.");
+					<<" are already max_players="
+					<<g_settings->getU16("max_players")<<" players."<<std::endl;
+			DenyAccess(peer_id, L"Too many players.");
 			return;
 		}
 
@@ -4643,7 +4668,7 @@ void Server::DenyAccess(u16 peer_id, const std::wstring &reason)
 		client->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