diff options
author | sorcerykid <rkrause@inbox.com> | 2020-05-23 06:24:06 -0500 |
---|---|---|
committer | SmallJoker <mk939@ymail.com> | 2020-05-23 13:25:29 +0200 |
commit | 15ba75e4cf1d1b8ceaa9d8ce33dcfdd7dbe80741 (patch) | |
tree | 482763407643cd776af9bd2c79e241969bbc644f /src/script/cpp_api/s_player.cpp | |
parent | 037422fdba9a47bd538480988fbf8aad67d66c85 (diff) | |
download | minetest-15ba75e4cf1d1b8ceaa9d8ce33dcfdd7dbe80741.tar.gz minetest-15ba75e4cf1d1b8ceaa9d8ce33dcfdd7dbe80741.tar.bz2 minetest-15ba75e4cf1d1b8ceaa9d8ce33dcfdd7dbe80741.zip |
Add on_authplayer callback and 'last_login' to on_joinplayer (#9574)
Replace on_auth_fail callback with more versatile on_authplayer
Better clarify account login process in Lua API documentation
Change initial timestamp for newly registered accounts to -1
Diffstat (limited to 'src/script/cpp_api/s_player.cpp')
-rw-r--r-- | src/script/cpp_api/s_player.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp index df67ea00c..712120c61 100644 --- a/src/script/cpp_api/s_player.cpp +++ b/src/script/cpp_api/s_player.cpp @@ -147,7 +147,7 @@ bool ScriptApiPlayer::can_bypass_userlimit(const std::string &name, const std::s return lua_toboolean(L, -1); } -void ScriptApiPlayer::on_joinplayer(ServerActiveObject *player) +void ScriptApiPlayer::on_joinplayer(ServerActiveObject *player, s64 last_login) { SCRIPTAPI_PRECHECKHEADER @@ -156,7 +156,11 @@ void ScriptApiPlayer::on_joinplayer(ServerActiveObject *player) lua_getfield(L, -1, "registered_on_joinplayers"); // Call callbacks objectrefGetOrCreate(L, player); - runCallbacks(1, RUN_CALLBACKS_MODE_FIRST); + if (last_login != -1) + lua_pushinteger(L, last_login); + else + lua_pushnil(L); + runCallbacks(2, RUN_CALLBACKS_MODE_FIRST); } void ScriptApiPlayer::on_leaveplayer(ServerActiveObject *player, @@ -216,16 +220,19 @@ void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player, runCallbacks(3, RUN_CALLBACKS_MODE_OR_SC); } -void ScriptApiPlayer::on_auth_failure(const std::string &name, const std::string &ip) +void ScriptApiPlayer::on_authplayer(const std::string &name, const std::string &ip, bool is_success) { SCRIPTAPI_PRECHECKHEADER - // Get core.registered_on_auth_failure + // Get core.registered_on_authplayers lua_getglobal(L, "core"); - lua_getfield(L, -1, "registered_on_auth_fail"); + lua_getfield(L, -1, "registered_on_authplayers"); + + // Call callbacks lua_pushstring(L, name.c_str()); lua_pushstring(L, ip.c_str()); - runCallbacks(2, RUN_CALLBACKS_MODE_FIRST); + lua_pushboolean(L, is_success); + runCallbacks(3, RUN_CALLBACKS_MODE_FIRST); } void ScriptApiPlayer::pushMoveArguments( |