diff options
author | kaeza <kaeza@users.sf.net> | 2013-12-12 04:51:35 -0200 |
---|---|---|
committer | ShadowNinja <shadowninja@minetest.net> | 2013-12-12 13:42:14 -0500 |
commit | 33de69a173a3646d8f5b9bf91b3e48d76cd40ae6 (patch) | |
tree | c5eeb56ed20b435e9fabf52f80bdee893e580df1 /src | |
parent | 76036abdb0d9cb2c971e5a69331c77872d38c56f (diff) | |
download | minetest-33de69a173a3646d8f5b9bf91b3e48d76cd40ae6.tar.gz minetest-33de69a173a3646d8f5b9bf91b3e48d76cd40ae6.tar.bz2 minetest-33de69a173a3646d8f5b9bf91b3e48d76cd40ae6.zip |
Add 'on_prejoinplayer' callback
Diffstat (limited to 'src')
-rw-r--r-- | src/script/cpp_api/s_player.cpp | 18 | ||||
-rw-r--r-- | src/script/cpp_api/s_player.h | 1 | ||||
-rw-r--r-- | src/server.cpp | 13 |
3 files changed, 32 insertions, 0 deletions
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); diff --git a/src/server.cpp b/src/server.cpp index 13b59e7f5..2c38c66d3 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1970,6 +1970,19 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) return; } + { + std::string reason; + if(m_script->on_prejoinplayer(playername, addr_s, reason)) + { + actionstream<<"Server: Player with the name \""<<playername<<"\" " + <<"tried to connect from "<<addr_s<<" " + <<"but it was disallowed for the following reason: " + <<reason<<std::endl; + DenyAccess(peer_id, narrow_to_wide(reason.c_str())); + return; + } + } + infostream<<"Server: New connection: \""<<playername<<"\" from " <<addr_s<<" (peer_id="<<peer_id<<")"<<std::endl; |