aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-09-04 22:08:59 +0200
committerGitHub <noreply@github.com>2017-09-04 22:08:59 +0200
commit40dd03e328ff0ae36338615114cb38879752756e (patch)
tree0ffe5ded06cce82f2b528284c1b5f5aba73f203e /src
parentc05228fa6d446022cdf675865f9a420c95619313 (diff)
downloadminetest-40dd03e328ff0ae36338615114cb38879752756e.tar.gz
minetest-40dd03e328ff0ae36338615114cb38879752756e.tar.bz2
minetest-40dd03e328ff0ae36338615114cb38879752756e.zip
Implement minetest.register_can_bypass_userlimit (#6369)
* Implement minetest.register_on_userlimit_check This new callback permits to bypass the max_users parameter with new mods condition, based on player name or IP Only one mod needs to permit it. Move core part for builtin privileges checks to builtin
Diffstat (limited to 'src')
-rw-r--r--src/network/serverpackethandler.cpp9
-rw-r--r--src/script/cpp_api/s_player.cpp15
-rw-r--r--src/script/cpp_api/s_player.h1
3 files changed, 19 insertions, 6 deletions
diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp
index 62da136ad..ecf4306c8 100644
--- a/src/network/serverpackethandler.cpp
+++ b/src/network/serverpackethandler.cpp
@@ -209,13 +209,10 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
<< addr_s << " (peer_id=" << pkt->getPeerId() << ")" << std::endl;
// Enforce user limit.
- // Don't enforce for users that have some admin right
+ // Don't enforce for users that have some admin right or mod permits it.
if (m_clients.isUserLimitReached() &&
- !checkPriv(playername, "server") &&
- !checkPriv(playername, "ban") &&
- !checkPriv(playername, "privs") &&
- !checkPriv(playername, "password") &&
- playername != g_settings->get("name")) {
+ playername != g_settings->get("name") &&
+ !m_script->can_bypass_userlimit(playername, addr_s)) {
actionstream << "Server: " << playername << " tried to join from "
<< addr_s << ", but there" << " are already max_users="
<< g_settings->getU16("max_users") << " players." << std::endl;
diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp
index b7f2f10f9..578c26184 100644
--- a/src/script/cpp_api/s_player.cpp
+++ b/src/script/cpp_api/s_player.cpp
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "cpp_api/s_internal.h"
#include "common/c_converter.h"
#include "common/c_content.h"
+#include "debug.h"
#include "util/string.h"
void ScriptApiPlayer::on_newplayer(ServerActiveObject *player)
@@ -123,6 +124,20 @@ bool ScriptApiPlayer::on_prejoinplayer(
return false;
}
+bool ScriptApiPlayer::can_bypass_userlimit(const std::string &name, const std::string &ip)
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ // Get core.registered_on_prejoinplayers
+ lua_getglobal(L, "core");
+ lua_getfield(L, -1, "registered_can_bypass_userlimit");
+ lua_pushstring(L, name.c_str());
+ lua_pushstring(L, ip.c_str());
+ runCallbacks(2, RUN_CALLBACKS_MODE_OR);
+ FATAL_ERROR_IF(!lua_isboolean(L, -1), "on_user_limitcheck must return a boolean");
+ return lua_toboolean(L, -1);
+}
+
void ScriptApiPlayer::on_joinplayer(ServerActiveObject *player)
{
SCRIPTAPI_PRECHECKHEADER
diff --git a/src/script/cpp_api/s_player.h b/src/script/cpp_api/s_player.h
index faf394de5..6b752eb69 100644
--- a/src/script/cpp_api/s_player.h
+++ b/src/script/cpp_api/s_player.h
@@ -35,6 +35,7 @@ public:
bool on_respawnplayer(ServerActiveObject *player);
bool on_prejoinplayer(const std::string &name, const std::string &ip,
std::string *reason);
+ bool can_bypass_userlimit(const std::string &name, const std::string &ip);
void on_joinplayer(ServerActiveObject *player);
void on_leaveplayer(ServerActiveObject *player, bool timeout);
void on_cheat(ServerActiveObject *player, const std::string &cheat_type);