mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
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
This commit is contained in:
parent
037422fdba
commit
15ba75e4cf
10 changed files with 81 additions and 46 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue