ID 转换
1. 概述
游戏可能提供添加平台好友或账号提供商好友的功能。这就需要在不同系统之间转换ID。完成本教程后,开发者将了解:
- 如何将账号提供商侧的一组openID转换为PGOS中的玩家信息。- 如何将账号平台侧的一组账号ID转换为PGOS中的玩家ID。
2. 关键词定义
- account open ID: 账号服务提供商提供的用户身份标识。
- Account ID: 这是玩家所拥有的账号平台用户 ID,而不是账号提供商用户 ID。当游戏集成支持多个账号平台的账号提供商时,此字段可以是 Steam 的 SteamID、XBox 的 XUID 等。最大长度为 64 个字符。
account ID 是为了使用 BatchAccountIDToPlayerID API 而设置的,该 API 可以将账号平台的用户 ID 转换为 PGOS 的玩家 ID。在某些场景下,例如为了满足 PSN/XBox 的合规要求,必须将 PSN/XBox 的黑名单同步到 PGOS,这时 BatchAccountIDToPlayerID API 将非常有用。
account_id
也是PlayerInfo
结构的一个字段,因此其他玩家客户端也可以读取它。
3. 使用玩家资料服务
3.1 将open ID 转换为平台玩家信息
将账号提供方的一组open ID 转换为 PGOS 中的玩家信息。
从 PlayerProfile 模块调用 BatchOpenIDToPlatformPlayerInfo
方法,如下所示:
#include "PgosSDKCpp.h"
void SomeUObjectClass::SomeFunction()
{
auto PlayerProfile = IPgosSDKCpp::Get().GetClientPlayerProfileAPI();
if (PlayerProfile)
{
TArray<FString> AccountOpenIds;
AccountOpenIds.Add("1926974186468553003");
AccountOpenIds.Add("1926974186468586187");
PlayerProfile->BatchOpenIDToPlatformPlayerInfo(AccountOpenIds, [](const FPgosResult& Ret, const FClientPlatformPlayerInfoMap* Data) {
if (Ret.err_code == (int32)Pgos::PgosErrCode::kSuccess)
{
UE_LOG(LogTemp, Log, TEXT("BatchOpenIDToPlatformPlayerInfo Success"));
}
else
{
UE_LOG(LogTemp, Log, TEXT("BatchOpenIDToPlatformPlayerInfo Failed: err_code=%d, err_msg=%s"), Ret.err_code, *Ret.msg);
}
});
}
}
3.2 Account ID转换为玩家Player ID
将账号平台侧的一组account ID转换为PGOS中的player ID。请按以下方式调用PlayerProfile模块中的BatchAccountIDToPlayerID
:
#include "PgosSDKCpp.h"
void SomeUObjectClass::SomeFunction()
{
auto PlayerProfile = IPgosSDKCpp::Get().GetClientPlayerProfileAPI();
if (PlayerProfile)
{
TArray<FString> AccountIds;
AccountIds.Add("2814657160907135");
AccountIds.Add("1345081161635083484");
PlayerProfile->BatchAccountIDToPlayerID(AccountIds, [](const FPgosResult& Ret, const FClientBatchAccountIDToPlayerIDResult* Data) {
if (Ret.err_code == (int32)Pgos::PgosErrCode::kSuccess)
{
UE_LOG(LogTemp, Log, TEXT("BatchAccountIDToPlayerID Success"));
}
else
{
UE_LOG(LogTemp, Log, TEXT("BatchAccountIDToPlayerID Failed: err_code=%d, err_msg=%s"), Ret.err_code, *Ret.msg);
}
});
}
}