Player Presence
1. Overview
Player Presence is a non-persistent data designed to express the status of a player in a game and it is visible to other players. Player presence will be cleared once the player goes offline.
2. Data Structure
In the data structure, player presence contains two parts:
status: It includes two states, online and offline, which are automatically assigned by PGOS based on the player's actual situation.
presence: It is a custom string assigned by the game, which will be automatically cleared when the player is offline.
enum class EClientOnlineStatus
{
OnlineStatus_Offline = 0,
OnlineStatus_Online = 1
};
struct FClientPlayerPresence
{
EClientOnlineStatus status;
FString presence;
};
3. Set My Presence
Set the presence of the current player.
For game client
Call SetMyPresence
from PlayerProfile module.
#include "PgosSDKCpp.h"
// for my player
void SomeUObjectClass::SetMyPresence()
{
auto playerProfile = IPgosSDKCpp::Get().GetClientPlayerProfileAPI();
if (playerProfile)
{
FString presence = "Matchmaking";
playerProfile->SetMyPresence(presence, [](const FPgosResult& Ret) {
if (Ret.err_code == (int32)Pgos::PgosErrCode::kSuccess)
{
UE_LOG(LogTemp, Log, TEXT("SetMyPresence Success"))
}
else
{
UE_LOG(LogTemp, Log, TEXT("SetMyPresence Failed: err_code=%d, err_msg=%s"), Ret.err_code, *Ret.msg);
}
});
}
}
4. Get My Presence
Get the presence of the current player.
For game client
Call GetMyPresence
from PlayerProfile module.
#include "PgosSDKCpp.h"
// for my player
void SomeUObjectClass::GetMyPresence()
{
auto playerProfile = IPgosSDKCpp::Get().GetClientPlayerProfileAPI();
if (playerProfile)
{
playerProfile->GetMyPresence([](const FPgosResult& Ret, const FClientPlayerPresence* Data) {
if (Ret.err_code == (int32)Pgos::PgosErrCode::kSuccess)
{
UE_LOG(LogTemp, Log, TEXT("GetMyPresence Success"))
}
else
{
UE_LOG(LogTemp, Log, TEXT("GetMyPresenceFailed: err_code=%d, err_msg=%s"), Ret.err_code, *Ret.msg);
}
});
}
}
5. Get Player Presence
The game can query player presence of one or more players.
For game client
- One player: call
GetPlayerPresence
from PlayerProfile module. - Multiple players (batch): call
BatchGetPlayerPresence
from PlayerProfile module.
#include "PgosSDKCpp.h"
// for one player
void SomeUObjectClass::GetPlayerPresence()
{
auto playerProfile = IPgosSDKCpp::Get().GetClientPlayerProfileAPI();
if (playerProfile)
{
FString PlayerID = "11223344";
playerProfile->GetPlayerPresence(PlayerID, [](const FPgosResult& Ret, const FClientPlayerPresence* Data) {
if (Ret.err_code == (int32)Pgos::PgosErrCode::kSuccess)
{
UE_LOG(LogTemp, Log, TEXT("GetPlayerPresence Success"))
}
else
{
UE_LOG(LogTemp, Log, TEXT("GetPlayerPresence Failed: err_code=%d, err_msg=%s"), Ret.err_code, *Ret.msg);
}
});
}
}
// for a batch of players
void SomeUObjectClass::BatchGetPlayerPresence()
{
auto playerProfile = IPgosSDKCpp::Get().GetClientPlayerProfileAPI();
if (playerProfile)
{
TArray<FString> PlayerIDs = {"11223344", "55667788"};
playerProfile->BatchGetPlayerPresence(PlayerIDs, [](const FPgosResult& Ret, const FClientBatchGetPlayerPresenceResult* Data) {
if (Ret.err_code == (int32)Pgos::PgosErrCode::kSuccess)
{
UE_LOG(LogTemp, Log, TEXT("BatchGetPlayerPresence Success"))
}
else
{
UE_LOG(LogTemp, Log, TEXT("BatchGetPlayerPresence Failed: err_code=%d, err_msg=%s"), Ret.err_code, *Ret.msg);
}
});
}
}
6. Friend Presence
The game can obtain a friend's player presence in the following ways:
By fetching the friend list using GetFriendList API, its callback data including the player presence information.
struct FClientPlayerInfoWithStatus : public FPlayerInfo
{
EClientOnlineStatus status;
FString presence;
};
struct FClientFriendListInfo
{
TArray<FClientPlayerInfoWithStatus> friend_info_list;
};Although it is possible to retrieve the player presence of any player using the GetPlayerPresence API, however, monitoring the OnFriendPresenceChanged event is a more efficient way to get the player presence of a friend. Note that the
OnFriendPresenceChanged
event requires the game to Subscribe to Friends' Presence first.
7. View Player Status
The game can also query the status of the specified player.
/Tabs>