Integrate Party into your game
Overview
The AccelByte Gaming Service (AGS) Session service includes a Party 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.
- 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 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.
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 |
Implement party interaction
Follow the steps below to implement party interaction into your game. Select the tab in each section for the game engine you are using (Unreal with AccelByte OnlineSubsystem (OSS) or Unity SDK) and follow the steps for that engine.
Prerequisites
- Unreal with AccelByte OSS
- Unity 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 following method 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 following method 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 Session API in V2 and the lobby is used to send and receive notifications about the party.
var apiClient = MultiRegistry.GetApiClient();
var lobby = apiClient.GetLobby();
var session = apiClient.GetSession();
Create a party
- Unreal with AccelByte OSS
- Unity 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 user when party created
textChat = true // enable to automatically create chat party topic
};
session.CreateParty(
request,
result =>
{
if (!result.IsError)
{
// party successfully created
SessionV2PartySession partySession = result.Value;
}
}
);
Invite to party
- Unreal with AccelByte OSS
- Unity SDK
// Listen to party invitation
SessionInterface->AddOnV2SessionInviteReceivedDelegate_Handle(FOnV2SessionInviteReceivedDelegate::CreateLambda(
[](const FUniqueNetId& UserId, const FUniqueNetId&, const FOnlineSessionInviteAccelByte& InviteResult)
{
if (InviteResult.SessionType == EAccelByteV2SessionType::PartySession)
{
// Handler on party session invite notification
// InviteResult contain the party details
}
}));
// Send invitation to other user
SessionInterface->SendSessionInviteToFriend(LocalPlayerId.ToSharedRef().Get(), NAME_PartySession, OtherUserPlayerId.ToSharedRef().Get());
// Listen to party invitation
lobby.SessionV2InvitedUserToParty += result =>
{
// Receive invitation to a party
SessionV2PartyInvitationNotification invitation = result.Value;
var partyId = invitation.partyId;
var senderId = invitation.senderId;
};
// Send invitation to other user
string partyId = "current-party-id";
string otherUserId = "other-user-id";
session.InviteUserToParty(
partyId,
otherUserId,
result =>
{
if (!result.IsError)
{
// successfully sent invitation to join a party
}
}
);
Party codes
- Unreal with AccelByte OSS
- Unity SDK
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.
Party codes are not currently supported in AccelByte Unity SDK.
Get a party code
- Unreal with AccelByte OSS
- Unity SDK
Once a code is generated, party leaders can get the code and share it from other players. This function allows party leaders to get the party code.
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);
Party codes are not currently supported in AccelByte Unity SDK.
Generate or refresh a party code
- Unreal with AccelByte OSS
- Unity SDK
Use the following function to generate or refresh a party code.
const FOnGenerateNewPartyCodeComplete OnGenerateNewPartyCodeCompleteDelegate =
FOnGenerateNewPartyCodeComplete::CreateLambda([](const bool bWasSuccessful, FString NewPartyCode)
{
if (bWasSuccessful)
{
// successfully generate new party code
}
});
Party codes are not currently supported in AccelByte Unity SDK.
Revoke a party code
- Unreal with AccelByte OSS
- Unity SDK
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.
const FOnRevokePartyCodeComplete OnRevokePartyCodeComplete =
FOnRevokePartyCodeComplete::CreateLambda([](const bool bWasSuccessful)
{
if (bWasSuccessful)
{
// successfully revoked party code
}
});
SessionInterface->RevokePartyCode(LocalPlayerId.ToSharedRef().Get(), NAME_PartySession, OnRevokePartyCodeComplete);
Party codes are not currently supported in AccelByte Unity SDK.
Join a party with a party code
- Unreal with AccelByte OSS
- Unity SDK
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.
// Add delegate on join party session completed
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);
Party codes are not currently supported in AccelByte Unity SDK.
Join a party
- Unreal with AccelByte OSS
- Unity SDK
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.
// Listen to party invitation
SessionInterface->AddOnV2SessionInviteReceivedDelegate_Handle(FOnV2SessionInviteReceivedDelegate::CreateLambda(
[](const FUniqueNetId& UserId, const FUniqueNetId&, const FOnlineSessionInviteAccelByte& InviteResult)
{
if (InviteResult.SessionType == EAccelByteV2SessionType::PartySession)
{
// Handler on party session invite notification
// InviteResult contain the party details
}
}));
// Add delegate on join party session completed
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 notification
SessionInterface->JoinSession(*LocalPlayerId.Get(), NAME_PartySession, Invitation.Session);
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.
// Listen to party invitation
lobby.SessionV2InvitedUserToParty += result =>
{
// Receive invitation to a party
SessionV2PartyInvitationNotification invitation = result.Value;
var partyId = invitation.partyId;
var senderId = invitation.senderId;
};
// Join the party session
string partyId = "invited-party-id";
session.JoinParty(
partyId,
result =>
{
if (!result.IsError)
{
// successfully sent invitation to join a party
SessionV2PartySession partySession = result.Value;
SessionV2MemberData[] members = partySession.members;
}
}
);
Reject a party invitation
- Unreal with AccelByte OSS
- Unity SDK
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.
FOnRejectSessionInviteComplete OnRejectSessionInviteComplete = FOnRejectSessionInviteComplete::CreateLambda([](const bool bWasSuccessful)
{
if (bWasSuccessful)
{
// successfully reject party invitation
}
});
// Join the party session
FOnlineSessionInviteAccelByte Invitation; // The invitation from notification
SessionInterface->RejectInvite(LocalPlayerId.ToSharedRef().Get(), Invitation, OnRejectSessionInviteComplete);
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.
string partyId = "invited-party-id";
session.RejectPartyInvitation(
partyId,
result =>
{
if (!result.IsError)
{
// successfully sent invitation to join a party
}
}
);
Promote a member to party leader
- Unreal with AccelByte OSS
- Unity SDK
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.
// Listen for party session update
SessionInterface->AddOnSessionUpdateReceivedDelegate_Handle(FOnSessionUpdateReceivedDelegate::CreateLambda([SessionInterface](FName SessionName)
{
if (SessionName == NAME_PartySession)
{
// there is update notification for 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);
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.
// Listen for party session update
lobby.SessionV2PartyUpdated += result =>
{
SessionV2PartySessionUpdatedNotification notification = result.Value;
var members = notification.members;
};
lobby.SessionV2PartyMemberChanged += result =>
{
SessionV2PartyMembersChangedNotification notification = result.Value;
var newJoinedMember = notification.joinerId;
var newLeaderId = notification.leaderId;
};
// 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)
{
// successfully promoted party member to party leader
SessionV2PartySession partySession = result.Value;
string newLeaderId = partySession.leaderId;
}
}
);
Kick a player from a party
- Unreal with AccelByte OSS
- Unity SDK
The party leader has the privilege 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.
// Listen for kicked from party session notification
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());
The party leader has the privilege 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.
// Listen for kicked from party session notification
lobby.SessionV2UserKickedFromParty += result =>
{
// kicked from a party
string partyId = result.Value.partyId;
};
// Kick player from party session
string partyId = "current-party-id";
string otherUserId = "user-id-to-be-kicked";
session.KickUserFromParty(
partyId,
otherUserId,
result =>
{
if (!result.IsError)
{
// successfully kicked user from a party
SessionV2PartySessionKickResponse response = result.Value;
var currentMembers = response.members;
}
}
);
Leave a party
- Unreal with AccelByte OSS
- Unity SDK
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.
// Listen for party session update
SessionInterface->AddOnSessionUpdateReceivedDelegate_Handle(FOnSessionUpdateReceivedDelegate::CreateLambda([SessionInterface](FName SessionName)
{
if (SessionName == NAME_PartySession)
{
// there is 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);
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.
// Listen for party session update
lobby.SessionV2PartyUpdated += result =>
{
SessionV2PartySessionUpdatedNotification notification = result.Value;
var members = notification.members;
};
// Leave a party
session.LeaveParty(
partyId,
result =>
{
if (!result.IsError)
{
// successfully left party
}
}
);