Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add get_server_max_lag() (#11671)
  • Loading branch information
Wuzzy2 committed Oct 5, 2021
1 parent d7e7ade commit 4fca601
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/lua_api.txt
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/script/lua_api/l_server.cpp
Expand Up @@ -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<ServerEnvironment *>(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)
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions src/script/lua_api/l_server.h
Expand Up @@ -33,6 +33,9 @@ class ModApiServer : public ModApiBase
// 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);

Expand Down

0 comments on commit 4fca601

Please sign in to comment.