From 4fca601e0cf74ce642e4e49ca7d4fe3e59915846 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 5 Oct 2021 12:35:55 +0000 Subject: [PATCH] Add get_server_max_lag() (#11671) --- doc/lua_api.txt | 2 ++ src/script/lua_api/l_server.cpp | 12 ++++++++++++ src/script/lua_api/l_server.h | 3 +++ 3 files changed, 17 insertions(+) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 9efe1afe7..e6cabb68e 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -5647,6 +5647,8 @@ Server a player joined. * This function may be overwritten by mods to customize the status message. * `minetest.get_server_uptime()`: returns the server uptime in seconds +* `minetest.get_server_max_lag()`: returns the current maximum lag + of the server in seconds or nil if server is not fully loaded yet * `minetest.remove_player(name)`: remove player from database (if they are not connected). * As auth data is not removed, minetest.player_exists will continue to diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index 473faaa14..6438fa6fd 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -57,6 +57,17 @@ int ModApiServer::l_get_server_uptime(lua_State *L) return 1; } +// get_server_max_lag() +int ModApiServer::l_get_server_max_lag(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + ServerEnvironment *s_env = dynamic_cast(getEnv(L)); + if (!s_env) + lua_pushnil(L); + else + lua_pushnumber(L, s_env->getMaxLagEstimate()); + return 1; +} // print(text) int ModApiServer::l_print(lua_State *L) @@ -512,6 +523,7 @@ void ModApiServer::Initialize(lua_State *L, int top) API_FCT(request_shutdown); API_FCT(get_server_status); API_FCT(get_server_uptime); + API_FCT(get_server_max_lag); API_FCT(get_worldpath); API_FCT(is_singleplayer); diff --git a/src/script/lua_api/l_server.h b/src/script/lua_api/l_server.h index c688e494b..a6f709787 100644 --- a/src/script/lua_api/l_server.h +++ b/src/script/lua_api/l_server.h @@ -33,6 +33,9 @@ private: // get_server_uptime() static int l_get_server_uptime(lua_State *L); + // get_server_max_lag() + static int l_get_server_max_lag(lua_State *L); + // get_worldpath() static int l_get_worldpath(lua_State *L);