玩家管理
21

获取当前玩家

下面我们演示如何获取当前用户。这只有在TrustedPlatformClient通过玩家访问令牌认证时才会有效,因此这个查询在客户端更有意义。如果你需要在服务器上获取一个玩家,你可以显式地定义玩家的id或名称。

GDScript
var _client: TrustedPlatformClient
var _get_current_player_cb: NFTEXCallback

func _init():
_client = TrustedPlatformClient.new()
_get_current_player_cb = NFTEXCallback.new(self, "_get_current_player")

func get_current_player():
_client.user_service().get_user(GetUserInput.new(), { "callback": _get_current_player_cb })

func _get_current_player(udata: Dictionary):
var gql: NFTEXGraphqlResponse = udata.gql
if gql.has_errors() or not gql.has_result():
return
var user: Dictionary = gql.get_result()

获取玩家身份

下面的例子演示了如何在用户查询中包含玩家身份。

GDScript
var _client: TrustedPlatformClient
var _get_player_identities_cb: NFTEXCallback

func _init():
_client = TrustedPlatformClient.new()
_get_player_identities_cb = NFTEXCallback.new(self, "_get_player_identities")

func get_player_identities(name: String):
var input: GetUserInput = GetUserInput.new().name(name)
input.user_i.with_identities(true)
_client.user_service.get_user(input, { "callback": _get_player_identities_cb })

func _get_player_identities(udata: Dictionary):
pass
var gql: NFTEXGraphqlResponse = udata.gql
if gql.has_errors() or not gql.has_result():
return
var user: Dictionary = gql.get_result()
var identities: Array = user.identities

链接一个玩家

虽然可以在SDK中明确地将一个以太币地址链接到一个身份,但我们建议将链接代码或链接代码qr显示给玩家的,这样他们就可以从NFTEX钱包android或iOS应用中进行链接。下面我们演示一下如何获取链接代码和qr网址。

GDScript
var _client: TrustedPlatformClient
var _get_identity_code_cb: NFTEXCallback

func _init():
_client = TrustedPlatformClient.new()
_get_player_identities_cb = NFTEXCallback.new(self, "_get_player_identities")

func get_identity_code():
var input: GetUserInput = GetUserInput.new()
input.user_i.with_identities(true)
input.identity_i.with_linking_code(true)
input.identity_i.with_linking_code_qr(true)
_client.user_service.get_user(input, { "callback": _get_identity_code_cb })

func _get_identity_code_cb(udata: Dictionary):
pass
var gql: NFTEXGraphqlResponse = udata.gql
if gql.has_errors() or not gql.has_result():
return
var user: Dictionary = gql.get_result()
var identity: Dictionary = user.identities[0]
var text_code = identity.linkingCode
var qr_code_url = identity.linkingCodeQr

获取玩家余额

获取玩家余额的方法有很多种。我们强烈建议使用钱包服务来明确获取以太坊地址的余额。通过这样做,您可以限制响应中返回的数据范围,与其他方法相比。为了演示的目的,我们将展示如何在获取玩家时包含余额,以及如何获取特定以太币地址的钱包。

GDScript
var _client: TrustedPlatformClient
var _get_balances_cb: NFTEXCallback
var _get_wallet_cb: NFTEXCallback

func _init():
_client = TrustedPlatformClient.new()
_get_balances_cb = NFTEXCallback.new(self, "_get_balances")
_get_wallet_cb = NFTEXCallback.new(self, "_get_wallet")

func get_balances():
var input: GetUserInput = GetUserInput.new()
input.user_i.with_identities(true)
input.identity_i.with_wallet(true)
input.wallet_input.with_balances(true)
_client.user_service.get_user(input, { "callback": _get_balances_cb })

func get_wallet(eth_addr: String):
var input: GetWalletInput = GetWalletInput.new().eth_addr(eth_addr)
input.wallet_i.with_balances(true)
_client.wallet_service.get_wallet(input, { "callback": _get_wallet_cb })

func _get_balances_cb(udata: Dictionary):
pass
var gql: NFTEXGraphqlResponse = udata.gql
if gql.has_errors() or not gql.has_result():
return
var user: Dictionary = gql.get_result()
var identity: Dictionary = user.identities[0]
var wallet: Dictionary = identity.wallet
var balances: Array = wallet.balances
for balance in balances:
print("id: %s, index: %s, amount: %s" % [balance.id, balance.index, balance.value])

func _get_wallet_cb(udata: Dictionary):
pass
var gql: NFTEXGraphqlResponse = udata.gql
if gql.has_errors() or not gql.has_result():
return
var user: Dictionary = gql.get_result()
var identity: Dictionary = user.identities[0]
var wallet: Dictionary = identity.wallet
var balances: Array = wallet.balances
for balance in balances:
print("id: %s, index: %s, amount: %s" % [balance.id, balance.index, balance.value])

上一页
接下来
本页