Skip to content

Commit

Permalink
Add server time api
Browse files Browse the repository at this point in the history
  • Loading branch information
aglitchman committed Jul 29, 2024
1 parent 967adda commit e01a9ea
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions example/ysdkdebug/playground.gui_script
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ function init(self)
pg_screen.init(self)
pg_shortcut.init(self)

print("yagames.server_time():", yagames.server_time())

event_test(self)

druid_style.make_button(self, "button_environment", environment_handler)
Expand Down
5 changes: 5 additions & 0 deletions yagames/helpers/mock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ end

local available_methods = {
"isAvailableMethod",
"serverTime",
-- Advertisement
"adv.showFullscreenAdv",
"adv.showRewardedVideo",
Expand Down Expand Up @@ -130,6 +131,10 @@ function M.is_available_method(cb_id, name)
M.send(cb_id, NO_ERR, result)
end

function M.server_time()
return math.floor(socket.gettime() * 1000)
end

function M.show_fullscreen_adv(cb_id)
M.send(cb_id, "close", false)
end
Expand Down
6 changes: 5 additions & 1 deletion yagames/lib/web/lib_yagames.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ var LibYaGamesPrivate = {
}
},

YaGamesPrivate_ServerTime: function () {
return YaGamesPrivate._ysdk.serverTime() || 0; // the return value can be null?..
},

YaGamesPrivate_Adv_ShowFullscreenAdv: function (cb_id) {
var self = YaGamesPrivate;
try {
Expand Down Expand Up @@ -260,7 +264,7 @@ var LibYaGamesPrivate = {

YaGamesPrivate_DeviceInfo_Type: function () {
var self = YaGamesPrivate;
var ctype = stringToNewUTF8(self._ysdk.deviceInfo.type || "null");
var ctype = stringToNewUTF8(self._ysdk.deviceInfo.type || "null"); // the return value can be undefined/null if you run the game outside of the YSDK system.
return ctype;
},

Expand Down
8 changes: 8 additions & 0 deletions yagames/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extern "C"
BooleanMessage cb_bool);
void YaGamesPrivate_RemoveCallbacks();
void YaGamesPrivate_IsAvailableMethod(const int cb_id, const char* name);
const double YaGamesPrivate_ServerTime();
void YaGamesPrivate_Adv_ShowFullscreenAdv(const int cb_id);
void YaGamesPrivate_Adv_ShowRewardedVideo(const int cb_id);
void YaGamesPrivate_Adv_GetBannerAdvStatus(const int cb_id);
Expand Down Expand Up @@ -394,6 +395,12 @@ static int IsAvailableMethod(lua_State* L)
return 0;
}

static int ServerTime(lua_State* L)
{
lua_pushnumber(L, YaGamesPrivate_ServerTime());
return 1;
}

static int Adv_ShowFullscreenAdv(lua_State* L)
{
YaGamesPrivate_Adv_ShowFullscreenAdv(luaL_checkint(L, 1));
Expand Down Expand Up @@ -868,6 +875,7 @@ static const luaL_reg Module_methods[] = {
{ "remove_listener", RemoveListener },
// Yandex Games SDK API
{ "is_available_method", IsAvailableMethod },
{ "server_time", ServerTime },
// - Adv
{ "show_fullscreen_adv", Adv_ShowFullscreenAdv },
{ "show_rewarded_video", Adv_ShowRewardedVideo },
Expand Down
8 changes: 8 additions & 0 deletions yagames/yagames.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ function M.is_available_method(name, callback)
end), name)
end

--- Get server time in UNIX format
-- @treturn number
function M.server_time()
assert(M.ysdk_ready, "YaGames is not initialized.")

return yagames_private.server_time()
end

--- Call the fullscreen ad
-- @tparam {open=function,close=function,error=function,offline=function} callbacks Optional callback-functions.
function M.adv_show_fullscreen_adv(callbacks)
Expand Down

0 comments on commit e01a9ea

Please sign in to comment.