Skip to content

Commit

Permalink
Added get_server_real_time()
Browse files Browse the repository at this point in the history
Fixes #11
  • Loading branch information
britzl committed Mar 14, 2024
1 parent 9dd813a commit b519fa7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 1 deletion.
16 changes: 16 additions & 0 deletions api.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


---

4 changes: 3 additions & 1 deletion examples/utils/utils.gui_script
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ TEXT = [[INFO
App active: %d seconds
App id: %d
Steam Deck: %s
Server Real Time: %d
]]

function init(self)
Expand All @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions steam/api/steam.script_api
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 2 additions & 0 deletions steam/src/steam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
13 changes: 13 additions & 0 deletions steam/src/steam_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions steam/src/steam_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b519fa7

Please sign in to comment.