From 33de69a173a3646d8f5b9bf91b3e48d76cd40ae6 Mon Sep 17 00:00:00 2001 From: kaeza Date: Thu, 12 Dec 2013 04:51:35 -0200 Subject: Add 'on_prejoinplayer' callback --- src/script/cpp_api/s_player.cpp | 18 ++++++++++++++++++ src/script/cpp_api/s_player.h | 1 + 2 files changed, 19 insertions(+) (limited to 'src/script/cpp_api') diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp index 215a34d53..d357689f2 100644 --- a/src/script/cpp_api/s_player.cpp +++ b/src/script/cpp_api/s_player.cpp @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "cpp_api/s_player.h" #include "cpp_api/s_internal.h" +#include "util/string.h" void ScriptApiPlayer::on_newplayer(ServerActiveObject *player) { @@ -58,6 +59,23 @@ bool ScriptApiPlayer::on_respawnplayer(ServerActiveObject *player) return positioning_handled_by_some; } +bool ScriptApiPlayer::on_prejoinplayer(std::string name, std::string ip, std::string &reason) +{ + SCRIPTAPI_PRECHECKHEADER + + // Get minetest.registered_on_prejoinplayers + lua_getglobal(L, "minetest"); + lua_getfield(L, -1, "registered_on_prejoinplayers"); + lua_pushstring(L, name.c_str()); + lua_pushstring(L, ip.c_str()); + script_run_callbacks(L, 2, RUN_CALLBACKS_MODE_OR); + if (lua_isstring(L, -1)) { + reason.assign(lua_tostring(L, -1)); + return true; + } + return false; +} + 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 88221f486..c77d397c4 100644 --- a/src/script/cpp_api/s_player.h +++ b/src/script/cpp_api/s_player.h @@ -34,6 +34,7 @@ public: void on_newplayer(ServerActiveObject *player); void on_dieplayer(ServerActiveObject *player); bool on_respawnplayer(ServerActiveObject *player); + bool on_prejoinplayer(std::string name, std::string ip, std::string &reason); void on_joinplayer(ServerActiveObject *player); void on_leaveplayer(ServerActiveObject *player); void on_cheat(ServerActiveObject *player, const std::string &cheat_type); -- cgit v1.2.3