Skip to main content

Client P2PBattle API Reference

Unlike online battle sessions, PGOS manages P2P battle sessions through game clients instead of dedicated servers or local dedicated servers.

API List

APIDescription
ActivateP2PBattleSessionNOTE: This interface can only called by HOST client. Activate a P2P battle session. Signal PGOS that the host is ready for clients to connect.
TerminateP2PBattleSessionNOTE: This interface can only called by HOST client. Terminate a P2P battle session. This method should be called when a P2P game is(or will) end.
AcceptP2PPlayerBattleSessionNOTE: This interface can only called by HOST client. Validates a player session, and signal PGOS to update player session's status to Active. This method should be called when a client requests a connection to the server.
DisconnectP2PPlayerBattleSessionNOTE: This interface can only called by HOST client. Turn a player session status to Disconnected.You can call this interface when the player disconnects from DS non-permanently. The player session can be resumed to Active at any time by calling the AcceptPlayerBattleSession interface again.
RemoveP2PPlayerBattleSessionNOTE: This interface can only called by HOST client. Turn a player session status to Completed.You should call this interface when a player. This interface will set the player session to a final state and cannot be restored.
DescribeP2PPlayerBattleSessionsNOTE: This interface can only called by HOST client. Query players session for a battle session.
DescribeP2PBattleSessionsGet a list of the P2P battle sessions that the player is participating in.
TerminateP2PPlayerBattleSessionTry to terminate the player session in a P2P battle. The player session status will turn to Completed after interface is called. This interface should be called when the player wants to leave the battle session.
ReportHostHealthP2P clients can use this interface to report the health status of a host to PGOS. Note that calls originating from the host itself will be ignored.
RejectHostMigratingThe client elected as the new host calls this interface to reject the host identity. The current battle session will terminate after this call.

Event List

EventDescription
OnStartP2PBattleSessionNOTE: This event is for HOST client only. The event will be triggered when a new P2P battle session is assigned to this client.
OnP2PBattleSessionTerminateNOTE: This event is for HOST client only. The event will be triggered once the P2P battle session being terminated from admin portal. Game server should call TerminateP2PBattleSession. Otherwise, the session will be reclaimed by PGOS after 5 minutes.
OnP2PPlayerBattleSessionsTerminatedThis event will be triggered in the following two situations: 1. The game client calls the TerminateP2PPlayerBattleSession interface, and the event is triggered in the host. 2. The host calls the TerminateP2PBattleSession interface, and the event is triggered in the game client.
OnP2PBattleSessionUpdatedThe event will be triggered when battle session status or player battle session of current player status updated.

API Details

ActivateP2PBattleSession

NOTE: This interface can only called by HOST client. Activate a P2P battle session. Signal PGOS that the host is ready for clients to connect.

/**
* NOTE: This interface can only called by HOST client.
* Activate a P2P battle session. Signal PGOS that the host is ready for clients to connect.
*
* @param ResultCallback The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.
*/
void ActivateP2PBattleSession(
const FPgosClientActivateP2PBattleSessionParams& Params,
TFunction<void(const FPgosResult& Ret)> ResultCallback) const;

Parameters:

ParamTypeDescription
Paramsconst FPgosClientActivateP2PBattleSessionParams&
ResultCallbackTFunction<void(const FPgosResult& Ret)>The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.

Return: void

TerminateP2PBattleSession

NOTE: This interface can only called by HOST client. Terminate a P2P battle session. This method should be called when a P2P game is(or will) end.

/**
* NOTE: This interface can only called by HOST client.
* Terminate a P2P battle session.
* This method should be called when a P2P game is(or will) end.
*
* @param ResultCallback The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.
*/
void TerminateP2PBattleSession(
const FPgosClientTerminateP2PBattleSessionParams& Params,
TFunction<void(const FPgosResult& Ret)> ResultCallback) const;

Parameters:

ParamTypeDescription
Paramsconst FPgosClientTerminateP2PBattleSessionParams&
ResultCallbackTFunction<void(const FPgosResult& Ret)>The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.

Return: void

AcceptP2PPlayerBattleSession

NOTE: This interface can only called by HOST client. Validates a player session, and signal PGOS to update player session's status to Active. This method should be called when a client requests a connection to the server.

/**
* NOTE: This interface can only called by HOST client.
* Validates a player session, and signal PGOS to update player session's status to Active.
* This method should be called when a client requests a connection to the server.
*
* @param ResultCallback The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.
*/
void AcceptP2PPlayerBattleSession(
const FPgosClientAcceptP2PPlayerBattleSessionParams& Params,
TFunction<void(const FPgosResult& Ret)> ResultCallback) const;

Parameters:

ParamTypeDescription
Paramsconst FPgosClientAcceptP2PPlayerBattleSessionParams&
ResultCallbackTFunction<void(const FPgosResult& Ret)>The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.

Return: void

DisconnectP2PPlayerBattleSession

NOTE: This interface can only called by HOST client. Turn a player session status to Disconnected.You can call this interface when the player disconnects from DS non-permanently. The player session can be resumed to Active at any time by calling the AcceptPlayerBattleSession interface again.

/**
* NOTE: This interface can only called by HOST client.
* Turn a player session status to Disconnected.You can call this interface when the player disconnects from DS non-permanently.
* The player session can be resumed to Active at any time by calling the AcceptPlayerBattleSession interface again.
*
* @param ResultCallback The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.
*/
void DisconnectP2PPlayerBattleSession(
const FPgosClientDisconnectP2PPlayerBattleSessionParams& Params,
TFunction<void(const FPgosResult& Ret)> ResultCallback) const;

Parameters:

ParamTypeDescription
Paramsconst FPgosClientDisconnectP2PPlayerBattleSessionParams&
ResultCallbackTFunction<void(const FPgosResult& Ret)>The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.

Return: void

RemoveP2PPlayerBattleSession

NOTE: This interface can only called by HOST client. Turn a player session status to Completed.You should call this interface when a player. This interface will set the player session to a final state and cannot be restored.

/**
* NOTE: This interface can only called by HOST client.
* Turn a player session status to Completed.You should call this interface when a player.
* This interface will set the player session to a final state and cannot be restored.
*
* @param ResultCallback The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.
*/
void RemoveP2PPlayerBattleSession(
const FPgosClientRemoveP2PPlayerBattleSessionParams& Params,
TFunction<void(const FPgosResult& Ret)> ResultCallback) const;

Parameters:

ParamTypeDescription
Paramsconst FPgosClientRemoveP2PPlayerBattleSessionParams&
ResultCallbackTFunction<void(const FPgosResult& Ret)>The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.

Return: void

DescribeP2PPlayerBattleSessions

NOTE: This interface can only called by HOST client. Query players session for a battle session.

/**
* NOTE: This interface can only called by HOST client.
* Query players session for a battle session.
*
* @param ResultCallback The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.
*/
void DescribeP2PPlayerBattleSessions(
const FPgosClientDescribeP2PPlayerBattleSessionsParams& Params,
TFunction<void(const FPgosResult& Ret, const FPgosClientDescribeP2PPlayerBattleSessionsResult* Data)> ResultCallback) const;

Parameters:

ParamTypeDescription
Paramsconst FPgosClientDescribeP2PPlayerBattleSessionsParams&
ResultCallbackTFunction<void(const FPgosResult& Ret, const FPgosClientDescribeP2PPlayerBattleSessionsResult* Data)>The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.

Return: void

DescribeP2PBattleSessions

Get a list of the P2P battle sessions that the player is participating in.

/**
* Get a list of the P2P battle sessions that the player is participating in.
*
* @param ResultCallback The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.
*/
void DescribeP2PBattleSessions(
TFunction<void(const FPgosResult& Ret, const FPgosClientDescribeP2PBattleSessionsResult* Data)> ResultCallback) const;

Parameters:

ParamTypeDescription
ResultCallbackTFunction<void(const FPgosResult& Ret, const FPgosClientDescribeP2PBattleSessionsResult* Data)>The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.

Return: void

TerminateP2PPlayerBattleSession

Try to terminate the player session in a P2P battle. The player session status will turn to Completed after interface is called. This interface should be called when the player wants to leave the battle session.

/**
* Try to terminate the player session in a P2P battle. The player session status will turn to Completed after interface is called.
* This interface should be called when the player wants to leave the battle session.
*
* @param ResultCallback The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.
*/
void TerminateP2PPlayerBattleSession(
const FPgosClientTerminateP2PPlayerBattleSessionParams& Params,
TFunction<void(const FPgosResult& Ret)> ResultCallback) const;

Parameters:

ParamTypeDescription
Paramsconst FPgosClientTerminateP2PPlayerBattleSessionParams&
ResultCallbackTFunction<void(const FPgosResult& Ret)>The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.

Return: void

ReportHostHealth

P2P clients can use this interface to report the health status of a host to PGOS. Note that calls originating from the host itself will be ignored.

/**
* P2P clients can use this interface to report the health status of a host to PGOS. Note that calls originating from the host itself will be ignored.
*
* @param ResultCallback The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.
*/
void ReportHostHealth(
const FPgosClientReportHostHealthParams& Params,
TFunction<void(const FPgosResult& Ret)> ResultCallback) const;

Parameters:

ParamTypeDescription
Paramsconst FPgosClientReportHostHealthParams&
ResultCallbackTFunction<void(const FPgosResult& Ret)>The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.

Return: void

RejectHostMigrating

The client elected as the new host calls this interface to reject the host identity. The current battle session will terminate after this call.

/**
* The client elected as the new host calls this interface to reject the host identity. The current battle session will terminate after this call.
*
* @param ResultCallback The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.
*/
void RejectHostMigrating(
const FString& BattleSessionId,
TFunction<void(const FPgosResult& Ret)> ResultCallback) const;

Parameters:

ParamTypeDescription
BattleSessionIdconst FString&
ResultCallbackTFunction<void(const FPgosResult& Ret)>The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.

Return: void

Event Details

OnStartP2PBattleSession

NOTE: This event is for HOST client only. The event will be triggered when a new P2P battle session is assigned to this client.

/**
* OnStartP2PBattleSession:
* NOTE: This event is for HOST client only.
* The event will be triggered when a new P2P battle session is assigned to this client.
*
* @param Event Event result.
*/
DECLARE_MULTICAST_DELEGATE_OneParam(FOnStartP2PBattleSession, const FPgosClientStartP2PBattleSessionEvt& /*Event*/);
FOnStartP2PBattleSession& OnStartP2PBattleSession() { return StartP2PBattleSessionDelegate; }

Type Reference:

OnP2PBattleSessionTerminate

NOTE: This event is for HOST client only. The event will be triggered once the P2P battle session being terminated from admin portal. Game server should call TerminateP2PBattleSession. Otherwise, the session will be reclaimed by PGOS after 5 minutes.

/**
* OnP2PBattleSessionTerminate:
* NOTE: This event is for HOST client only.
* The event will be triggered once the P2P battle session being terminated from admin portal.
* Game server should call TerminateP2PBattleSession. Otherwise, the session will be reclaimed by PGOS after 5 minutes.
*
* @param Event Event result.
*/
DECLARE_MULTICAST_DELEGATE_OneParam(FOnP2PBattleSessionTerminate, const FPgosClientP2PBattleSessionTerminateEvt& /*Event*/);
FOnP2PBattleSessionTerminate& OnP2PBattleSessionTerminate() { return P2PBattleSessionTerminateDelegate; }

Type Reference:

OnP2PPlayerBattleSessionsTerminated

This event will be triggered in the following two situations: 1. The game client calls the TerminateP2PPlayerBattleSession interface, and the event is triggered in the host. 2. The host calls the TerminateP2PBattleSession interface, and the event is triggered in the game client.

/**
* OnP2PPlayerBattleSessionsTerminated:
* This event will be triggered in the following two situations:
* 1. The game client calls the TerminateP2PPlayerBattleSession interface, and the event is triggered in the host.
* 2. The host calls the TerminateP2PBattleSession interface, and the event is triggered in the game client.
*
* @param Event Event result.
*/
DECLARE_MULTICAST_DELEGATE_OneParam(FOnP2PPlayerBattleSessionsTerminated, const FPgosClientP2PPlayerBattleSessionsTerminatedEvt& /*Event*/);
FOnP2PPlayerBattleSessionsTerminated& OnP2PPlayerBattleSessionsTerminated() { return P2PPlayerBattleSessionsTerminatedDelegate; }

Type Reference:

OnP2PBattleSessionUpdated

The event will be triggered when battle session status or player battle session of current player status updated.

/**
* OnP2PBattleSessionUpdated:
* The event will be triggered when battle session status or player battle session of current player status updated.
*
* @param Event Event result.
*/
DECLARE_MULTICAST_DELEGATE_OneParam(FOnP2PBattleSessionUpdated, const FPgosClientP2PBattleSessionUpdatedEvt& /*Event*/);
FOnP2PBattleSessionUpdated& OnP2PBattleSessionUpdated() { return P2PBattleSessionUpdatedDelegate; }

Type Reference: