パーティをゲームに統合する
Overview
AccelByte Gaming Services (AGS) Session includes AGS Party, a service which handles parties for multiplayer play. Players can interact with parties in several ways, including:
- User Party Info: shows players information about their party, including the Party ID, Leader ID, and the list of party members.
- Create Party: allows players to create a new party that other players can join.
- Invite to Party: allows players to invite their friends to join their party. Both the inviter and invitee will receive a notification when the invitation is sent.
- Join Party: allows players to join a party that they've been invited to join. When the player joins the party, the inviter and other party members will be notified.
- Cancel Party Invitation allows players to cancel a party invitation. Both invitees and inviters will receive a notification that the invitation has been canceled. Invitees can't join the previous invitation after it is canceled.
- Reject Party Invitation: allows players to reject a party invitation. The inviter will be notified that their invitation was rejected.
- Promote a Member as a Party Leader: allows players to set another player as the party leader.
- Kick from Party: allows party leaders to remove (kick) another player from their party.
- Leave Party: allows players to leave a party that they have already joined. The other party members will be notified when a player leaves their party.
This article will cover integrating player parties using AGS Party.
Permissions
Permissions are used to grant access to specific resources within AGS. Make sure your account has the following permissions before you attempt to manage Party Session V2.
Usage | Permissions | Action |
---|---|---|
To add, edit, and delete a Session Template | ADMIN:NAMESPACE:*:SESSION:CONFIGURATION | CREATE, READ, UPDATE, DELETE |
To view a session in Session and Parties | NAMESPACE:*:SESSION:GAME | CREATE, READ, UPDATE, DELETE |
Prerequisites
- OSS
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
Include the following files to use Session Interface V2:
#include "OnlineSubsystem.h"
#include "OnlineSubsystemUtils.h"
#include "Interfaces/OnlineSessionInterface.h"
#include "Engine/World.h"
#include "Engine/GameEngine.h"
#include "OnlineSessionInterfaceV2AccelByte.h"
#include "OnlineSubsystemAccelByteSessionSettings.h"
#include "OnlineSubsystemSessionSettings.h"
Use the function below to get FOnlineSessionV2AccelByte
and LocalPlayerId
from the game.
The rest of the tutorial will not include this code snippet to focus on each functionality of the interface.
// Get FOnlineSessionV2AccelByte from the game
const UWorld* World = GEngine->GetCurrentPlayWorld();
const IOnlineSubsystem* Subsystem = Online::GetSubsystem(World, ACCELBYTE_SUBSYSTEM);
const auto SessionInterface = StaticCastSharedPtr<FOnlineSessionV2AccelByte>(Subsystem->GetSessionInterface());
// Get LocalPlayerId from the game
const int PlayerIndex = 0;
const ULocalPlayer* LocalPlayer = GEngine->GetLocalPlayerFromControllerId(GEngine->GetCurrentPlayWorld(), PlayerIndex );
const FUniqueNetIdPtr LocalPlayerId = LocalPlayer->GetPreferredUniqueNetId().GetUniqueNetId();
using AccelByte.Api;
using AccelByte.Core;
Use the function below to get the API client to interact with AGS.
The rest of the tutorial will not include this code snippet to focus on each functionality. Party is part of the Session API in V2 and AGS Lobby is used to send and receive notifications about the party.
var apiClient = AccelByteSDK.GetClientRegistry().GetApi();
var lobby = apiClient.GetLobby();
var session = apiClient.GetSession();
partyService := &session.PartyService{
Client: factory.NewSessionClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
Refer to getting started with Extend SDK on how to create Go Extend SDK object.
import accelbyte_py_sdk.api.session as session_service
import accelbyte_py_sdk.api.session.models as session_models
Refer to Get application access token using AGS SDKs on how to create Python Extend SDK object.
Refer to [getting started with Extend SDK](../../10-extend/11-extend-sdk/01-getting-started-with-the-extend-sdk.md) on how to create JavaExtend SDK object.
using AccelByte.Sdk.Api;
using AccelByte.Sdk.Api.Session.Model;
Refer to getting started with Extend SDK on how to create C# Extend SDK object.
Create a party
Players can create a party that can be used for matchmaking. A player can only create one party at a time, and they will become the leader of the party they create.
- OSS
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
SessionInterface->AddOnCreateSessionCompleteDelegate_Handle(
FOnCreateSessionCompleteDelegate::CreateLambda([](const FName SessionName, const bool bWasSuccessful)
{
if (SessionName == NAME_PartySession)
{
if(!bWasSuccessful)
{
// Create party error handling
}
// Party created handling
}
}));
FOnlineSessionSettings NewSessionSettings;
NewSessionSettings.NumPrivateConnections = 4;
NewSessionSettings.Set(SETTING_SESSION_JOIN_TYPE, TEXT("INVITE_ONLY"));
NewSessionSettings.Set(SETTING_SESSION_TYPE, SETTING_SESSION_TYPE_PARTY_SESSION);
NewSessionSettings.Set(SETTING_SESSION_TEMPLATE_NAME, TEXT("TemplateNameFromAP"));
SessionInterface->CreateSession(LocalPlayerId.ToSharedRef().Get(), NAME_PartySession, NewSessionSettings);
var request = new SessionV2PartySessionCreateRequest
{
attributes = new Dictionary<string, object>(), // Add custom attributes if needed
configurationName = "config-name-from-admin-portal",
joinability = SessionV2Joinability.INVITE_ONLY,
members = Array.Empty<SessionV2MemberData>(), // Optional if you want to invite other users when the party is created
textChat = true // Enable to automatically create a chat party topic
};
session.CreateParty(request, result =>
{
if (result.IsError)
{
// Do something if CreateParty has an error
Debug.Log($"Error CreateParty, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if CreateParty succeeds
});
body := sessionclientmodels.ApimodelsCreatePartyRequest {
ConfigurationName: "config-name-from-admin-portal",
Joinability: "INVITE_ONLY",
TextChat: true, // Enable to automatically create chat party topic
Attributes:map[string]interface{}, // Add custom attributes if needed
Members: []*sessionclientmodels.ApimodelsRequestMember{} // Optional if you want to invite other user when party created
}
namespace := "mygame"
input := &party.PublicCreatePartyParams{
Body: &body,
Namespace: namespace,
}
result, err := partyService.PublicCreatePartyShort(input)
result, error = session_service.public_create_party(
body=session_models.ApimodelsCreatePartyRequest()
.with_configuration_name("config-name-from-admin-portal")
.with_joinability("INVITE_ONLY")
.with_text_chat(True)
)
if error:
exit(error)
final Party player1PartyWrapper = new Party(sdk);
ApimodelsCreatePartyRequest body = ApimodelsCreatePartyRequest.builder()
.configurationName("config-name-from-admin-portal")
.joinability("INVITE_ONLY")
.textChat(true) // Enable to automatically create chat party topic
.attributes(new HashMap<>()) // Add custom attributes if needed
.members(
Collections.singletonList(ApimodelsRequestMember.builder().id("<player2UserId>").build()))// Optional if you want to invite other user when party created
.build();
ApimodelsPartySessionResponse response;
try {
response = player1PartyWrapper.publicCreateParty(PublicCreateParty.builder()
.namespace("<namespace>")
.body(body)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
// Do something when successful
}
ApimodelsCreatePartyRequest createPartyRequest = new ApimodelsCreatePartyRequest()
{
ConfigurationName = "config-name-from-admin-portal",
Joinability = "INVITE_ONLY",
TextChat = true, // Enable to automatically create chat party topic
Attributes = new Dictionary<string, object>(), // Add custom attributes if needed
Members = new List<ApimodelsRequestMember>() // Optional if you want to invite other user when party created
};
var response = sdk.Session.Party.PublicCreatePartyOp
.Execute(createPartyRequest, sdk.Namespace);
if (response != null)
{
//do something if after party is created
}
Invite to party
Players can invite other players to their party. Invitees will receive a notification that they have been invited to join a party and current party members will also receive a notification that someone has been invited to the party.
- OSS
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
// Listen for party invitations
SessionInterface->AddOnV2SessionInviteReceivedDelegate_Handle(FOnV2SessionInviteReceivedDelegate::CreateLambda(
[](const FUniqueNetId& UserId, const FUniqueNetId&, const FOnlineSessionInviteAccelByte& InviteResult)
{
if (InviteResult.SessionType == EAccelByteV2SessionType::PartySession)
{
// Handle party session invite notifications
// InviteResult contains the party details
}
}));
// Send invitation to other user
SessionInterface->SendSessionInviteToFriend(LocalPlayerId.ToSharedRef().Get(), NAME_PartySession, OtherUserPlayerId.ToSharedRef().Get());
// Listen for party invitation notification
lobby.SessionV2InvitedUserToParty += result =>
{
if (result.IsError)
{
// Do something if SessionV2InvitedUserToParty has an error
Debug.Log($"Error SessionV2InvitedUserToParty, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if SessionV2InvitedUserToParty is received
};
// Send an invitation to other user
string partyId = "current-party-id";
string otherUserId = "other-user-id";
session.InviteUserToParty(
partyId,
otherUserId,
result =>
{
if (result.IsError)
{
// Do something if InviteUserToParty has an error
Debug.Log($"Error InviteUserToParty, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if InviteUserToParty succeeds
}
);
otherUserId := "otheruserid"
body := sessionclientmodels.ApimodelsSessionInviteRequest {
UserID: &otherUserId,
}
namespace := "mygame"
partyId := "mypartyid"
input := &party.PublicPartyInviteParams{
Body: &body,
Namespace: namespace,
PartyID: partyId,
}
result, err := partyService.PublicPartyInviteShort(input)
result, error = session_service.public_party_invite(
body=session_models.ApimodelsSessionInviteRequest()
.with_platform_id("PlatformId")
.with_user_id("OtherUserId"),
party_id="PartyId",
)
if error:
exit(error)
final Party player1PartyWrapper = new Party(sdk);
String partyId = "<party id>";
String otherUserId = "<user id>";
ApimodelsSessionInviteResponse response;
try {
response = player1PartyWrapper.publicPartyInvite(PublicPartyInvite.builder()
.namespace("<namespace>")
.partyId(partyId)
.body(ApimodelsSessionInviteRequest.builder().userID(otherUserId).build())
.build());
} catch (Exception e) {
// Do something when failed
return;
}
// Do something if after invitation
string partyId = "<party id>";
string otherUserId = "<user id>";
var response = sdk.Session.Party.PublicPartyInviteOp
.Execute(new ApimodelsSessionInviteRequest()
{
UserID = otherUserId
}, sdk.Namespace, partyId);
if (response != null)
{
//do something if after invitation
}
Cancel outgoing party invitation
Players can cancel outgoing invitations. Invitees and inviters will receive a notification that the invitation has been canceled. Invitees can't accept the previous invitation after it is canceled.
- OSS
// Invitee and inviter listen for session invite canceled notification.
auto OnSessionInviteCanceledDelegate = SessionInterface->AddOnSessionInviteCanceledDelegate_Handle(
FOnSessionInviteCanceledDelegate::CreateLambda([](const FString& SessionID) // ID of canceled party.
{
// Received invitation canceled.
}));
// Party leader (inviter) cancel invitation.
FName PartyName = NAME_PartySession;
auto OnCancelSessionInviteCompleteDelegate = SessionInterface->AddOnCancelSessionInviteCompleteDelegate_Handle(FOnCancelSessionInviteCompleteDelegate::CreateLambda(
[&](const FUniqueNetId& LocalUserId, FName SessionName, const FUniqueNetId& Invitee, const FOnlineError& ErrorInfo)
{
bool bInvitationCanceled = ErrorInfo.bSucceeded;
// Cancel session invitation complete.
}));
SessionInterface->CancelSessionInvite(PlayerIndex, PartyName, *InviteeUniqueNetId);
Join a party
Players that are invited to a party can accept the invitation and join the party. Party invitees will receive a notification that they've joined the party and current party members will also receive a notification that someone is joining the party.
- OSS
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
// Listen for party invitations
SessionInterface->AddOnV2SessionInviteReceivedDelegate_Handle(FOnV2SessionInviteReceivedDelegate::CreateLambda(
[](const FUniqueNetId& UserId, const FUniqueNetId&, const FOnlineSessionInviteAccelByte& InviteResult)
{
if (InviteResult.SessionType == EAccelByteV2SessionType::PartySession)
{
// Handle party session invite notifications
// InviteResult contains the party details
}
}));
// Add delegate for joining a party session completing
SessionInterface->AddOnJoinSessionCompleteDelegate_Handle(
FOnJoinSessionCompleteDelegate::CreateLambda([](FName SessionName, EOnJoinSessionCompleteResult::Type Result){
if (SessionName == NAME_PartySession)
{
// Join party session completed, check the result
}
}));
// Join the party session
FOnlineSessionInviteAccelByte Invitation; // The invitation from the notification
SessionInterface->JoinSession(*LocalPlayerId.Get(), NAME_PartySession, Invitation.Session);
// Listen for party joined notifications
lobby.SessionV2UserJoinedParty += result =>
{
if (result.IsError)
{
// Do something if SessionV2UserJoinedParty has an error
Debug.Log($"Error SessionV2UserJoinedParty, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if SessionV2UserJoinedParty is received
};
// Join the party session
string partyId = "invited-party-id";
session.JoinParty(partyId, result =>
{
if (!result.IsError)
{
if (result.IsError)
{
// Do something if JoinParty has an error
Debug.Log($"Error JoinParty, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if JoinParty succeeds
}
});
namespace := "namespace"
partyId := "mypartyid"
input := &party.PublicPartyJoinParams{
Namespace: namespace,
PartyID: partyId,
}
result, err := partyService.PublicPartyJoinShort(input)
result, error = session_service.public_party_join(
party_id="PartyId",
)
if error:
exit(error)
final Party player1PartyWrapper = new Party(sdk);
String partyId = "<party id>";
ApimodelsPartySessionResponse response;
try {
response = player1PartyWrapper.publicPartyJoin(PublicPartyJoin.builder()
.namespace("<namespace>")
.partyId(partyId)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
// Do something if after join
string partyId = "<party id>";
var response = sdk.Session.Party.PublicPartyJoinOp
.Execute(sdk.Namespace, partyId);
if (response != null)
{
//do something if after join
}
Reject a party invitation
When a player has been invited to a party, they can choose to reject the invitation. Party invitees and current party members will receive a notification that they've rejected the invitation.
- OSS
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FOnRejectSessionInviteComplete OnRejectSessionInviteComplete = FOnRejectSessionInviteComplete::CreateLambda([](const bool bWasSuccessful)
{
if (bWasSuccessful)
{
// Successfully rejected party invitation
}
});
// Join the party session
FOnlineSessionInviteAccelByte Invitation; // The invitation from the notification
SessionInterface->RejectInvite(LocalPlayerId.ToSharedRef().Get(), Invitation, OnRejectSessionInviteComplete);
// Listen for party rejected notifications
lobby.SessionV2UserRejectedPartyInvitation += result =>
{
if (result.IsError)
{
// Do something if SessionV2UserRejectedPartyInvitation has an error
Debug.Log($"Error SessionV2UserRejectedPartyInvitation, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if SessionV2UserRejectedPartyInvitation is received
};
// Reject party invitation
string partyId = "invited-party-id";
session.RejectPartyInvitation(partyId, result =>
{
if (result.IsError)
{
// Do something if RejectPartyInvitation has an error
Debug.Log($"Error RejectPartyInvitation, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if RejectPartyInvitation succeeds
});
namespace := "namespace"
partyId := "mypartyid"
input := &party.PublicPartyRejectParams{
Namespace: namespace,
PartyID: partyId,
}
err := partyService.PublicPartyRejectShort(input)
result, error = session_service.public_party_reject(
party_id="PartyId",
)
if error:
exit(error)
final Party player1PartyWrapper = new Party(sdk);
String partyId = "<party id>";
try {
player1PartyWrapper.publicPartyReject(PublicPartyReject.builder()
.namespace("<namespace>")
.partyId(partyId)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
// Do something after party reject success
string partyId = "<party id>";
sdk.Session.Party.PublicPartyRejectOp
.Execute(sdk.Namespace, partyId);
Promote a member to party leader
The party leader can promote another party member to become the new party leader. All party members will be notified of the new party leader. This is how the party leader can promote another party member to become a new party leader. The new party leader is identified by a specific user ID from a party member.
- OSS
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
// Listen for party session updates
SessionInterface->AddOnSessionUpdateReceivedDelegate_Handle(FOnSessionUpdateReceivedDelegate::CreateLambda([SessionInterface](FName SessionName)
{
if (SessionName == NAME_PartySession)
{
// There is an update notification for the party
auto LatestPartySession = SessionInterface->GetNamedSession(NAME_PartySession);
}
}));
// Promote another party member to party leader
FOnPromotePartySessionLeaderComplete OnPromotePartySessionLeaderComplete =
FOnPromotePartySessionLeaderComplete::CreateLambda([](const FUniqueNetId& PromotedUserId, const FOnlineError& Result)
{
if (Result.bSucceeded)
{
// Successfully promoted new party leader
}
});
SessionInterface->PromotePartySessionLeader(LocalPlayerId.ToSharedRef().Get(), NAME_PartySession, OtherUserPlayerId.ToSharedRef().Get(), OnPromotePartySessionLeaderComplete);
// Listen for party session update notifications
lobby.SessionV2PartyUpdated += result =>
{
if (result.IsError)
{
// Do something if SessionV2PartyUpdated has an error
Debug.Log($"Error SessionV2PartyUpdated, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if SessionV2PartyUpdated is received
};
lobby.SessionV2PartyMemberChanged += result =>
{
if (result.IsError)
{
// Do something if SessionV2PartyMemberChanged has an error
Debug.Log($"Error SessionV2PartyMemberChanged, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if SessionV2PartyMemberChanged is received
};
// Promote another party member to party leader
string partyId = "current-party-id";
string leaderId = "current-party-leader-id";
session.PromoteUserToPartyLeader(
partyId,
leaderId,
result =>
{
if (result.IsError)
{
// Do something if PromoteUserToPartyLeader has an error
Debug.Log($"Error PromoteUserToPartyLeader, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if PromoteUserToPartyLeader succeeds
}
);
leaderId := "myleaderid"
body := sessionclientmodels.ApimodelsPromoteLeaderRequest {
LeaderID: &leaderId,
}
namespace := "mygame"
partyId := "mypartyid"
input := &party.PublicPromotePartyLeaderParams{
Body: &body,
Namespace: namespace,
PartyID: partyId,
}
result, err := partyService.PublicPromotePartyLeaderShort(input)
result, error = session_service.public_promote_party_leader(
body=session_models.ApimodelsPromoteLeaderRequest()
.with_leader_id("LeaderId"),
party_id="PartyId",
)
if error:
exit(error)
final Party player1PartyWrapper = new Party(sdk);
try {
player1PartyWrapper.publicPromotePartyLeader(PublicPromotePartyLeader.builder()
.namespace("<namespace>")
.partyId("<party id>")
.body(ApimodelsPromoteLeaderRequest.builder().leaderID("<leaderId>").build())
.build());
} catch (Exception e) {
// Do something when failed
return;
}
// Do something after promote party leader success
var response = sdk.Session.Party.PublicPromotePartyLeaderOp
.Execute(new ApimodelsPromoteLeaderRequest()
{
LeaderID = leaderId
}, sdk.Namespace, partyId);
if (response != null)
{
// Do something if promote has been successful
}
Kick a player from a party
The party leader has the ability to remove a party member from their party by kicking them out of the party. The kicked party member will receive a notification that they've been kicked out of the party, and current party members will also receive a notification that someone has been kicked from the party.
- OSS
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
// Listen for notifications for kicking players from a party session
SessionInterface->AddOnKickedFromSessionDelegate_Handle(FOnKickedFromSessionDelegate::CreateLambda([](FName SessionName)
{
if (SessionName == NAME_PartySession)
{
// Player kicked from party
}
}));
// Kick player from party session
FOnKickPlayerComplete OnKickPlayerComplete =
FOnKickPlayerComplete::CreateLambda([](const bool bWasSuccessful, const FUniqueNetId& KickedPlayerId)
{
if (bWasSuccessful)
{
// Player successfully kicked from the party
}
});
SessionInterface->KickPlayer(LocalPlayerId.ToSharedRef().Get(), NAME_PartySession, PlayerIdToKick.ToSharedRef().Get());
// Listen for notifications for kicking players from a party session
lobby.SessionV2UserKickedFromParty += result =>
{
if (result.IsError)
{
// Do something if SessionV2UserKickedFromPart has an error
Debug.Log($"Error SessionV2UserKickedFromPart, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if SessionV2UserKickedFromPart is received
};
// Kick player from the party session
string partyId = "current-party-id";
string otherUserId = "user-id-to-be-kicked";
session.KickUserFromParty(
partyId,
otherUserId,
result =>
{
if (result.IsError)
{
// Do something if KickUserFromParty has an error
Debug.Log($"Error KickUserFromParty, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if KickUserFromParty succeeds
}
);
namespace := "namespace"
partyId := "mypartyid"
userId := "myuserid"
input := &party.PublicPartyKickParams{
Namespace: namespace,
PartyID: partyId,
UserID: userId,
}
result, err := partyService.PublicPartyKickShort(input)
result, error = session_service.public_party_kick(
party_id="PartyId",
user_id="OtherUserId",
)
if error:
exit(error)
final Party player1PartyWrapper = new Party(sdk);
String partyId = "<party id>";
String otherUserId = "<user id>";
ApimodelsKickResponse response;
try {
response = player1PartyWrapper.publicPartyKick(PublicPartyKick.builder()
.namespace("<namespace>")
.partyId(partyId)
.userId(otherUserId)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
// Do something if player successfully kicked from the party
string partyId = "<party id>";
string otherUserId = "<user id>";
var response = sdk.Session.Party.PublicPartyKickOp
.Execute(sdk.Namespace, partyId, otherUserId);
if (response != null)
{
//do something if player successfully kicked from the party
}
Leave a party
Party members can choose to leave their party. If the party leader leaves the party, party leadership will be passed to another party member automatically. Party members that leave the party will receive a notification that they've left the party and current party members will also receive a notification that someone is leaving the party.
- OSS
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
// Listen for party session update
SessionInterface->AddOnSessionUpdateReceivedDelegate_Handle(FOnSessionUpdateReceivedDelegate::CreateLambda([SessionInterface](FName SessionName)
{
if (SessionName == NAME_PartySession)
{
// There is an update notification for party
auto LatestPartySession = SessionInterface->GetNamedSession(NAME_PartySession);
}
}));
// Leave a party
PartySession = SessionInterface->GetNamedSession(NAME_PartySession);
auto PartySessionInfo = StaticCastSharedPtr<FOnlineSessionInfoAccelByteV2>(PartySession->SessionInfo);
FString PartyId = PartySessionInfo->GetBackendSessionDataAsPartySession()->ID;
FOnLeaveSessionComplete OnLeavePartyComplete =
FOnLeaveSessionComplete::CreateLambda([](const bool bWasSuccessful, FString SessionId)
{
if (bWasSuccessful)
{
// Successfully left a party
}
});
SessionInterface->LeaveSession(LocalPlayerId.ToSharedRef().Get(), EAccelByteV2SessionType::PartySession, PartyId, OnLeavePartyComplete);
// Listen for party session update notifications
lobby.SessionV2PartyUpdated += result =>
{
if (result.IsError)
{
// Do something if SessionV2PartyUpdated has an error
Debug.Log($"Error SessionV2PartyUpdated, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if SessionV2PartyUpdated is received
};
// Leave a party
string partyId = "current-party-id";
session.LeaveParty(partyId, result =>
{
if (result.IsError)
{
// Do something if LeaveParty has an error
Debug.Log($"Error LeaveParty, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if LeaveParty succeeds
});
namespace := "mygame"
partyId := "mypartyid"
input := &party.PublicPartyLeaveParams{
Namespace: namespace,
PartyID: partyId,
}
err := partyService.PublicPartyLeaveShort(input)
result, error = session_service.public_party_leave(
party_id="PartyId",
)
if error:
exit(error)
final Party player1PartyWrapper = new Party(sdk);
String partyId = "<party id>";
try {
player1PartyWrapper.publicPartyLeave(PublicPartyLeave.builder()
.namespace("<namespace>")
.partyId(partyId)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
// Do something after leaving the party
string partyId = "<party id>";
sdk.Session.Party.PublicPartyLeaveOp
.Execute(sdk.Namespace, partyId);
Party codes
Party leaders can send party codes to players so that those players can join their party. Only party leaders can refresh or revoke a party code.
Get a party code
Once a code is generated, party leaders can get the code and share it to other players. This function allows party leaders to get the party code.
- OSS
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FString Code;
auto PartySession = SessionInterface->GetNamedSession(NAME_PartySession);
auto PartySessionInfo = StaticCastSharedPtr<FOnlineSessionInfoAccelByteV2>(PartySession->SessionInfo);
FString PartyCode = PartySessionInfo->GetBackendSessionDataAsPartySession()->Code;
PartySession->SessionSettings.Get(SETTING_PARTYSESSION_CODE, PartyCode);
var partyId = "current-party-id";
session.GetPartyDetails(partyId, result =>
{
if (result.IsError)
{
// Do something if GetPartyDetails has an error
Debug.Log($"Error GetPartyDetails, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if GetPartyDetails succeeds
var code = result.Value.Code;
});
namespace := "mygame"
partyId := "mypartyid"
input := &party.PublicGetPartyParams{
Namespace: namespace,
PartyID: partyId,
}
result, err := partyService.PublicGetPartyShort(input)
result, error = session_service.public_get_party(
party_id="PartyId",
)
if error:
exit(error)
String partyId = "<party id>";
final Party player1PartyWrapper = new Party(sdk);
ApimodelsPartySessionResponse response;
try {
response = player1PartyWrapper.publicGetParty(PublicGetParty.builder()
.namespace("<namespace>")
.partyId(partyId)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
// Get party code and send to other player
string partyId = "<party id>";
var response = sdk.Session.Party.PublicGetPartyOp
.Execute(sdk.Namespace, partyId);
if (response != null)
{
string partyCode = response.Code!;
//get party code and send to other player
}
Generate or refresh a party code
Use the following function to generate or refresh a party code.
- OSS
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
const FOnGenerateNewPartyCodeComplete OnGenerateNewPartyCodeCompleteDelegate =
FOnGenerateNewPartyCodeComplete::CreateLambda([](const bool bWasSuccessful, FString NewPartyCode)
{
if (bWasSuccessful)
{
// successfully generate new party code
}
});
var partyId = "current-party-id";
session.GenerateNewPartyCode(partyId, result =>
{
if (result.IsError)
{
// Do something if GenerateNewPartyCode has an error
Debug.Log($"Error GenerateNewPartyCode, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if GenerateNewPartyCode succeeds
});
namespace := "mygame"
partyId := "mypartyid"
input := &party.PublicGeneratePartyCodeParams{
Namespace: namespace,
PartyID: partyId,
}
result, err := partyService.PublicGeneratePartyCodeShort(input)
result, error = session_service.public_generate_party_code(
party_id="PartyId",
)
if error:
exit(error)
String partyId = "<party id>";
final Party player1PartyWrapper = new Party(sdk);
ApimodelsPartySessionResponse response;
try {
response = player1PartyWrapper.publicGeneratePartyCode(PublicGeneratePartyCode.builder()
.namespace("<namespace>")
.partyId(partyId)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
// Get party code and send to other player
string partyId = "<party id>";
var response = _Sdk.Session.Party.PublicGeneratePartyCodeOp.
Execute(_Sdk.Namespace, partyId);
if (response != null)
{
string partyCode = response.Code!;
//get party code and send to other player
}
Revoke a party code
Party leaders can revoke a party code. If a party code is revoked, players will no longer be able to use it to join the party. This function allows party leaders to revoke the party code.
- OSS
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
const FOnRevokePartyCodeComplete OnRevokePartyCodeComplete =
FOnRevokePartyCodeComplete::CreateLambda([](const bool bWasSuccessful)
{
if (bWasSuccessful)
{
// Successfully revoked party code
}
});
SessionInterface->RevokePartyCode(LocalPlayerId.ToSharedRef().Get(), NAME_PartySession, OnRevokePartyCodeComplete);
var partyId = "current-party-id";
session.RevokePartyCode(partyId, result =>
{
if (result.IsError)
{
// Do something if RevokePartyCode has an error
Debug.Log($"Error RevokePartyCode, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if RevokePartyCode succeeds
});
namespace := "mygame"
partyId := "mypartyid"
input := &party.PublicRevokePartyCodeParams{
Namespace: namespace,
PartyID: partyId,
}
err := partyService.PublicRevokePartyCodeShort(input)
result, error = session_service.public_revoke_party_code(
party_id="PartyId",
)
if error:
exit(error)
String partyId = "<party id>";
final Party player1PartyWrapper = new Party(sdk);
try {
player1PartyWrapper.publicRevokePartyCode(PublicRevokePartyCode.builder()
.namespace("<namespace>")
.partyId(partyId)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
// Do something after revocation success
string partyId = "<party id>";
sdk.Session.Party.PublicRevokePartyCodeOp
.Execute(sdk.Namespace, partyId);
Join a party with a party code
Players that have been sent a party code can use it to join a party. This function allows players to join a party using a party code.
- OSS
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
// Add delegate for the completion of joining a party session
SessionInterface->AddOnJoinSessionCompleteDelegate_Handle(
FOnJoinSessionCompleteDelegate::CreateLambda([](FName SessionName, EOnJoinSessionCompleteResult::Type Result){
if (SessionName == NAME_PartySession)
{
// Join party session completed, check the result
}
}));
// Party code from party leader
FString PartyCode = TEXT("PARTY_CODE");
SessionInterface->JoinSession(LocalPlayerId.ToSharedRef().Get(), NAME_PartySession, PartyCode);
var partyCode = "targeted-party-code";
session.JoinPartyByCode(partyCode, result =>
{
if (result.IsError)
{
// Do something if JoinPartyByCode has an error
Debug.Log($"Error JoinPartyByCode, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if JoinPartyByCode succeeds
});
code := "mypartycode"
body := sessionclientmodels.ApimodelsJoinByCodeRequest {
Code: &code,
}
namespace := "mygame"
input := &party.PublicPartyJoinCodeParams{
Body: &body,
Namespace: namespace,
}
result, err := partyService.PublicPartyJoinCodeShort(input)
result, error = session_service.public_party_join_code(
body=session_models.ApimodelsJoinByCodeRequest()
.with_code("PartyCode"),
)
if error:
exit(error)
final Party player1PartyWrapper = new Party(sdk);
ApimodelsPartySessionResponse response;
try {
response = player1PartyWrapper.publicPartyJoinCode(PublicPartyJoinCode.builder()
.namespace("<namespace>")
.body(ApimodelsJoinByCodeRequest.builder().code("<targeted party code>").build())
.build());
} catch (Exception e) {
// Do something when failed
return;
}
// Do something if join party is success
var response = _Sdk.Session.Party.PublicPartyJoinCodeOp
.Execute(new ApimodelsJoinByCodeRequest()
{
Code = "<targeted party code>"
}, _Sdk.Namespace);
if (response != null)
{
//do something if join party is success
}
Refresh party session
The game session can be refreshed to synchronize with the backend using the Refresh Session
method. The provided SessionName
parameter may correspond to NAME_PartySession
.
- OSS Unreal
SessionInterface->RefreshSession(SessionName, FOnRefreshSessionComplete::CreateLambda([]()
{
// On refresh session complete
}));
Refresh active sessions
To prevent issues and ensure proper synchronization with the backend, use the following function to refresh all active sessions cached locally on the client:
- OSS Unreal
SessionInterface->RefreshActiveSessions(FOnRefreshActiveSessionsComplete::CreateLambda(
[&](bool bWasSuccessful)
{
// On refresh active sessions complete
}));