aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-rw-r--r--src/script/cpp_api/s_player.cpp19
-rw-r--r--src/script/cpp_api/s_player.h4
-rw-r--r--src/script/cpp_api/s_server.cpp14
-rw-r--r--src/script/cpp_api/s_server.h3
4 files changed, 27 insertions, 13 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(
diff --git a/src/script/cpp_api/s_player.h b/src/script/cpp_api/s_player.h
index 7ca3d8f30..a337f975b 100644
--- a/src/script/cpp_api/s_player.h
+++ b/src/script/cpp_api/s_player.h
@@ -41,7 +41,7 @@ public:
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_joinplayer(ServerActiveObject *player, s64 last_login);
void on_leaveplayer(ServerActiveObject *player, bool timeout);
void on_cheat(ServerActiveObject *player, const std::string &cheat_type);
bool on_punchplayer(ServerActiveObject *player, ServerActiveObject *hitter,
@@ -51,7 +51,7 @@ public:
const PlayerHPChangeReason &reason);
void on_playerReceiveFields(ServerActiveObject *player,
const std::string &formname, const StringMap &fields);
- void on_auth_failure(const std::string &name, const std::string &ip);
+ void on_authplayer(const std::string &name, const std::string &ip, bool is_success);
// Player inventory callbacks
// Return number of accepted items to be moved
diff --git a/src/script/cpp_api/s_server.cpp b/src/script/cpp_api/s_server.cpp
index 1ce2f9d45..96cb28b28 100644
--- a/src/script/cpp_api/s_server.cpp
+++ b/src/script/cpp_api/s_server.cpp
@@ -23,7 +23,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
bool ScriptApiServer::getAuth(const std::string &playername,
std::string *dst_password,
- std::set<std::string> *dst_privs)
+ std::set<std::string> *dst_privs,
+ s64 *dst_last_login)
{
SCRIPTAPI_PRECHECKHEADER
@@ -43,8 +44,7 @@ bool ScriptApiServer::getAuth(const std::string &playername,
luaL_checktype(L, -1, LUA_TTABLE);
std::string password;
- bool found = getstringfield(L, -1, "password", password);
- if (!found)
+ if (!getstringfield(L, -1, "password", password))
throw LuaError("Authentication handler didn't return password");
if (dst_password)
*dst_password = password;
@@ -54,7 +54,13 @@ bool ScriptApiServer::getAuth(const std::string &playername,
throw LuaError("Authentication handler didn't return privilege table");
if (dst_privs)
readPrivileges(-1, *dst_privs);
- lua_pop(L, 1);
+ lua_pop(L, 1); // Remove key from privs table
+
+ s64 last_login;
+ if(!getintfield(L, -1, "last_login", last_login))
+ throw LuaError("Authentication handler didn't return last_login");
+ if (dst_last_login)
+ *dst_last_login = (s64)last_login;
return true;
}
diff --git a/src/script/cpp_api/s_server.h b/src/script/cpp_api/s_server.h
index a4cede84d..d8639cba7 100644
--- a/src/script/cpp_api/s_server.h
+++ b/src/script/cpp_api/s_server.h
@@ -43,7 +43,8 @@ public:
/* auth */
bool getAuth(const std::string &playername,
std::string *dst_password,
- std::set<std::string> *dst_privs);
+ std::set<std::string> *dst_privs,
+ s64 *dst_last_login = nullptr);
void createAuth(const std::string &playername,
const std::string &password);
bool setPassword(const std::string &playername,