Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ And it's also a good idea to upload a demo build of YaGames to your game's draft
| `player.getUniqueID()` | `yagames.player_get_unique_id()` |
| `player.getIDsPerGame()` | `yagames.player_get_ids_per_game(callback)` |
| `player.getMode()` | `yagames.player_get_mode()`<br>[(more info)](https://yandex.ru/blog/gamesfordevelopers/novye-vozmozhnosti-dlya-neavtorizovannykh-polzovateley) |
| `player.isAuthorized()` | `yagames.player_is_authorized()` |
| `player.getName()` | `yagames.player_get_name()` |
| `player.getPhoto(size)` | `yagames.player_get_photo(size)` |
| `player.getPayingStatus()` | `yagames.player_get_paying_status()` |
Expand Down
2 changes: 1 addition & 1 deletion example/ysdkdebug/pg_player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ local function init_handler(self, options)
self.button_player_set_stats:set_enabled(true)

print("yagames.player_get_signature():", yagames.player_get_signature() or "nil")
print("yagames.player_get_mode():", "'" .. yagames.player_get_mode() .. "'")
print("yagames.player_is_authorized():", yagames.player_is_authorized() and "true" or "false")
print("yagames.player_get_personal_info():", table_util.tostring(yagames.player_get_personal_info()))
print("yagames.player_get_paying_status():", "'" .. yagames.player_get_paying_status() .. "'")
end
Expand Down
22 changes: 20 additions & 2 deletions yagames/helpers/mock.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
local rxi_json = require("yagames.helpers.json")

local M = {listeners = {}}
local M = {
listeners = {},
_warned = {}
}

local GLOBAL_CALLBACK_ID = 0
local NO_ERR = nil
Expand Down Expand Up @@ -61,6 +64,13 @@ local function sequence_calls(...)
end)
end

local function warn_once(message)
if not M._warned[message] then
M._warned[message] = true
print("<!>", message)
end
end

--
-- Yandex Games SDK
--
Expand Down Expand Up @@ -469,12 +479,13 @@ end

function M.player_get_id()
assert(M._player)
warn_once("yagames.player_get_id() is deprecated and will be removed from the interface in the future.")

return M._player._personalInfo.uniqueID
end

function M.player_get_ids_per_game(cb_id)
if M.player_get_mode() == "lite" then
if not M.player_is_authorized() then
M.send(cb_id, "FetchError: Unauthorized")
else
M.send(cb_id, NO_ERR, '[{"appID":100,"userID":"9c/GxA5IUaaavN2KPdtTxTlKh/ayLzrVhNj90Ka8oPA="}]')
Expand All @@ -483,10 +494,17 @@ end

function M.player_get_mode()
assert(M._player)
warn_once("yagames.player_get_mode() is deprecated and will be removed from the interface in the future.")

return M._player._personalInfo.mode
end

function M.player_is_authorized()
assert(M._player)

return M._player._personalInfo.mode ~= "lite"
end

function M.player_get_name()
assert(M._player)

Expand Down
6 changes: 6 additions & 0 deletions yagames/lib/web/lib_yagames.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,12 @@ var LibYaGamesPrivate = {
return cmode;
},

YaGamesPrivate_Player_IsAuthorized: function () {
var self = YaGamesPrivate;
var isAuthorized = self._player.isAuthorized();
return isAuthorized;
},

YaGamesPrivate_Player_GetName: function () {
var self = YaGamesPrivate;
var cname = stringToNewUTF8(self._player.getName());
Expand Down
8 changes: 8 additions & 0 deletions yagames/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ extern "C"
void YaGamesPrivate_Player_GetIDsPerGame(const int cb_id);
const char* YaGamesPrivate_Player_GetID();
const char* YaGamesPrivate_Player_GetMode();
const bool YaGamesPrivate_Player_IsAuthorized();
const char* YaGamesPrivate_Player_GetName();
const char* YaGamesPrivate_Player_GetPhoto(const char* size);
const char* YaGamesPrivate_Player_GetUniqueID();
Expand Down Expand Up @@ -668,6 +669,12 @@ static int Player_GetMode(lua_State* L)
return 1;
}

static int Player_IsAuthorized(lua_State* L)
{
lua_pushboolean(L, YaGamesPrivate_Player_IsAuthorized());
return 1;
}

static int Player_GetName(lua_State* L)
{
const char* name = YaGamesPrivate_Player_GetName();
Expand Down Expand Up @@ -924,6 +931,7 @@ static const luaL_reg Module_methods[] = {
{ "player_get_id", Player_GetID },
{ "player_get_ids_per_game", Player_GetIDsPerGame },
{ "player_get_mode", Player_GetMode },
{ "player_is_authorized", Player_IsAuthorized },
{ "player_get_name", Player_GetName },
{ "player_get_photo", Player_GetPhoto },
{ "player_get_unique_id", Player_GetUniqueID },
Expand Down
14 changes: 12 additions & 2 deletions yagames/yagames.lua
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ function M.player_get_signature()
return yagames_private.player_get_signature()
end

--- DEPRECATED: Use player_get_unique_id()
--- Return the user's ID.
-- @deprecated Use player_get_unique_id() instead.
-- @treturn string
function M.player_get_id()
assert_player_ready()
Expand All @@ -548,7 +549,7 @@ function M.player_get_ids_per_game(callback)
assert(type(callback) == "function", "`callback` function is required")

yagames_private.player_get_ids_per_game(helper.wrap_for_promise(
function(self, err, arr)
function(self, err, arr)
if arr then
arr = rxi_json.decode(arr)
end
Expand All @@ -557,13 +558,22 @@ function M.player_get_ids_per_game(callback)
end

--- Return the user's auth mode.
-- @deprecated Use player_is_authorized() instead.
-- @treturn string
function M.player_get_mode()
assert_player_ready()

return yagames_private.player_get_mode()
end

--- Return the user's auth mode.
-- @treturn boolean
function M.player_is_authorized()
assert_player_ready()

return yagames_private.player_is_authorized()
end

--- Return the user's name.
-- @treturn string
function M.player_get_name()
Expand Down