diff --git a/api.json b/api.json index 86f6b1d..ad4eab3 100644 --- a/api.json +++ b/api.json @@ -1267,6 +1267,22 @@ ], "summary": "Get image in RGBA format.", "usage": null + }, + { + "description": "", + "has_params": false, + "has_returns": true, + "name": "utils_get_server_real_time", + "params": [], + "returns": [ + { + "description": "Time", + "name": "Server", + "type": "number" + } + ], + "summary": "Returns the Steam server time in Unix epoch format. (Number of seconds since Jan 1, 1970 UTC)", + "usage": null } ], "filename": "steam/src/steam_utils.cpp", diff --git a/api.md b/api.md index 9ef21a4..f08c6be 100644 --- a/api.md +++ b/api.md @@ -607,5 +607,13 @@ RETURNS * `Image` [`String`] - +### utils_get_server_real_time() +Returns the Steam server time in Unix epoch format. (Number of seconds since Jan 1, 1970 UTC) + + +RETURNS +* `Server` [`number`] - Time + + --- diff --git a/examples/utils/utils.gui_script b/examples/utils/utils.gui_script index 530b840..56eb20f 100644 --- a/examples/utils/utils.gui_script +++ b/examples/utils/utils.gui_script @@ -6,6 +6,7 @@ TEXT = [[INFO App active: %d seconds App id: %d Steam Deck: %s +Server Real Time: %d ]] function init(self) @@ -17,7 +18,8 @@ function init(self) local seconds = steam.utils_get_seconds_since_app_active() local app_id = steam.utils_get_app_id() local steam_deck = steam.utils_is_steam_running_on_steam_deck() and "true" or "false" - gui.set_text(gui.get_node("info"), TEXT:format(seconds, app_id, steam_deck)) + local server_real_time = steam.utils_get_server_real_time() + gui.set_text(gui.get_node("info"), TEXT:format(seconds, app_id, steam_deck, server_real_time)) end function final(self) diff --git a/steam/api/steam.script_api b/steam/api/steam.script_api index 0ddcd4c..44d3cea 100644 --- a/steam/api/steam.script_api +++ b/steam/api/steam.script_api @@ -585,3 +585,11 @@ type: String + - name: utils_get_server_real_time + type: function + desc: Returns the Steam server time in Unix epoch format. (Number of seconds since Jan 1, 1970 UTC) + returns: + - name: Server + type: number + desc: Time + diff --git a/steam/src/steam.cpp b/steam/src/steam.cpp index 4626901..3acad8e 100644 --- a/steam/src/steam.cpp +++ b/steam/src/steam.cpp @@ -177,6 +177,8 @@ static const luaL_reg Module_methods[] = { { "utils_is_steam_running_on_steam_deck", SteamUtils_IsSteamRunningOnSteamDeck }, { "utils_get_image_size", SteamUtils_GetImageSize }, { "utils_get_image_rgba", SteamUtils_GetImageRGBA }, + { "utils_get_server_real_time", SteamUtils_GetServerRealTime }, + // USERSTATS - stats { "user_stats_get_stat_int", SteamUserStats_GetStatInt }, diff --git a/steam/src/steam_utils.cpp b/steam/src/steam_utils.cpp index be62c7e..8895aba 100644 --- a/steam/src/steam_utils.cpp +++ b/steam/src/steam_utils.cpp @@ -125,5 +125,18 @@ int SteamUtils_GetImageRGBA(lua_State* L) } +/** Returns the Steam server time in Unix epoch format. (Number of seconds since Jan 1, 1970 UTC) + * @name utils_get_server_real_time + * @treturn number Server time + */ +int SteamUtils_GetServerRealTime(lua_State* L) +{ + if (!g_SteamUtils) return 0; + DM_LUA_STACK_CHECK(L, 1); + uint32 time = g_SteamUtils->GetServerRealTime(); + lua_pushnumber(L, time); + return 1; +} + #endif \ No newline at end of file diff --git a/steam/src/steam_utils.h b/steam/src/steam_utils.h index 6cdb0e9..956c88a 100644 --- a/steam/src/steam_utils.h +++ b/steam/src/steam_utils.h @@ -11,6 +11,7 @@ int SteamUtils_GetSecondsSinceAppActive(lua_State* L); int SteamUtils_IsSteamRunningOnSteamDeck(lua_State* L); int SteamUtils_GetImageSize(lua_State* L); int SteamUtils_GetImageRGBA(lua_State* L); +int SteamUtils_GetServerRealTime(lua_State* L); #endif