パーティをゲームに統合する
注釈:本資料はAI技術を用いて翻訳されています。
Overview
AccelByte Gaming Services (AGS) Session には、マルチプレイヤープレイのパーティを処理するサービスである AGS Party が含まれています。プレイヤーは以下のような複数の方法でパーティを操作できます。
- User Party Info: パーティ ID、リーダー ID、パーティメンバーのリストなど、自分のパーティに関する情報をプレイヤーに表示します。
- Create Party: プレイヤーが他のプレイヤーが参加できる新しいパーティを作成できるようにします。
- Invite to Party: プレイヤーが自分のパーティに友達を招待できるようにします。招待が送信されると、招待者と被招待者の両方に通知が届きます。
- Join Party: プレイヤーが招待されたパーティに参加できるようにします。プレイヤーがパーティに参加すると、招待者と他のパーティメンバーに通知が届きます。
- Cancel Party Invitation: プレイヤーがパーティへの招待を取り消せるようにします。被招待者と招待者の両方に、招待が取り消されたことを通知します。被招待者は取り消し後、以前の招待に参加することはできません。
- Reject Party Invitation: プレイヤーがパーティへの招待を拒否できるようにします。招待者には、招待が拒否されたことが通知されます。
- Promote a Member as a Party Leader: プレイヤーが他のプレイヤーをパーティリーダーに設定できるようにします。
- Kick from Party: パーティリーダーがパーティから他のプレイヤーを削除(キック)できるようにします。
- Leave Party: プレイヤーが既に参加しているパーティから離脱できるようにします。プレイヤーがパーティから離脱すると、他のパーティメンバーに通知が届きます。
この記事では、AGS Party を使用したプレイヤーパーティの統合について説明します。
Permissions
権限は、AGS 内の特定のリソースへのアクセスを許可するために使用されます。Party Session V2 を管理する前に、アカウントに以下の権限があることを確認してください。
| 用途 | 権限 | アクション |
|---|---|---|
| セッションテンプレートを追加、編集、削除する | ADMIN:NAMESPACE:*:SESSION:CONFIGURATION | CREATE, READ, UPDATE, DELETE |
| Session and Parties でセッションを表示する | NAMESPACE:*:SESSION:GAME | CREATE, READ, UPDATE, DELETE |
Prerequisites
- OSS
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python Extend SDK
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"
以下の関数を使用して、ゲームから FOnlineSessionV2AccelByte と LocalPlayerId を取得します。
このチュートリアルの以降の部分では、インターフェースの各機能に焦点を当てるため、このコードスニペットは省略します。
// 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();
Session V2 を使用するには、以下のファイルをインクルードします。
using AccelByte.Api;
using AccelByte.Core;
以下の関数を使用して、AGS と対話するための API クライアントを取得します。
このチュートリアルの以降の部分では、各機能に焦点を当てるため、このコードスニペットは省略します。パーティは V2 の Session API の一部であり、AGS Lobby はパーティに関する通知の送受信に使用されます。
var apiClient = AccelByteSDK.GetClientRegistry().GetApi();
var lobby = apiClient.GetLobby();
var session = apiClient.GetSession();
using AccelByte.Sdk.Api;
using AccelByte.Sdk.Api.Session.Model;
C# Extend SDK オブジェクトの作成方法については、Extend SDK の使用を開始するを参照してください。
partyService := &session.PartyService{
Client: factory.NewSessionClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
Go Extend SDK オブジェクトの作成方法については、Extend SDK の使用を開始するを参照してください。
Refer to [getting started with Extend SDK](../../01-foundations/extend/06-sdk-and-tools/01-extend-sdk/01-get-started-with-extend-sdk.md) on how to create JavaExtend SDK object.
import accelbyte_py_sdk.api.session as session_service
import accelbyte_py_sdk.api.session.models as session_models
Python Extend SDK オブジェクトの作成方法については、AGS SDK を使用してアプリケーションアクセストークンを取得するを参照してください。
Create a party
プレイヤーは、マッチメイキングに使用できるパーティを作成できます。プレイヤーは同時に1つのパーティしか作成できず、作成したパーティのリーダーになります。
- OSS
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python 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
});
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
}
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)
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
}
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),
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
Invite to party
プレイヤーは他のプレイヤーを自分のパーティに招待できます。被招待者にはパーティへの招待を受け取ったことが通知され、現在のパーティメンバーにも誰かがパーティに招待されたことが通知されます。
- OSS
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python 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
}
);
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
}
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)
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
result, error = session_service.public_party_invite(
body=session_models.ApimodelsSessionInviteRequest()
.with_platform_id("PlatformId")
.with_user_id("OtherUserId"),
party_id="PartyId",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
Cancel outgoing party invitation
プレイヤーは送信済みの招待を取り消すことができます。被招待者と招待者には、招待が取り消されたことが通知されます。被招待者は取り消し後、以前の招待を受け入れることはできません。
- 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
パーティに招待されたプレイヤーは、招待を受け入れてパーティに参加できます。パーティの被招待者にはパーティに参加したことが通知され、現在のパーティメンバーにも誰かがパーティに参加していることが通知されます。
- OSS
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python 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
}
});
string partyId = "<party id>";
var response = sdk.Session.Party.PublicPartyJoinOp
.Execute(sdk.Namespace, partyId);
if (response != null)
{
//do something if after join
}
namespace := "namespace"
partyId := "mypartyid"
input := &party.PublicPartyJoinParams{
Namespace: namespace,
PartyID: partyId,
}
result, err := partyService.PublicPartyJoinShort(input)
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
result, error = session_service.public_party_join(
party_id="PartyId",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
Reject a party invitation
プレイヤーがパーティに招待されると、その招待を拒否することを選択できます。パーティの被招待者と現在のパーティメンバーには、招待が拒否されたことが通知されます。
- OSS
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python 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
});
string partyId = "<party id>";
sdk.Session.Party.PublicPartyRejectOp
.Execute(sdk.Namespace, partyId);
namespace := "namespace"
partyId := "mypartyid"
input := &party.PublicPartyRejectParams{
Namespace: namespace,
PartyID: partyId,
}
err := partyService.PublicPartyRejectShort(input)
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
result, error = session_service.public_party_reject(
party_id="PartyId",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
Promote a member to party leader
パーティリーダーは、他のパーティメンバーを新しいパーティリーダーに昇格させることができます。新しいパーティリーダーは、すべてのパーティメンバーに通知されます。昇格させる新しいパーティリーダーは、パーティメンバーの特定のユーザー ID によって指定します。
- OSS
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python 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
}
);
var response = sdk.Session.Party.PublicPromotePartyLeaderOp
.Execute(new ApimodelsPromoteLeaderRequest()
{
LeaderID = leaderId
}, sdk.Namespace, partyId);
if (response != null)
{
// Do something if promote has been successful
}
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)
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
result, error = session_service.public_promote_party_leader(
body=session_models.ApimodelsPromoteLeaderRequest()
.with_leader_id("LeaderId"),
party_id="PartyId",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
Kick a player from a party
パーティリーダーは、パーティメンバーをパーティから削除(キック)する権限を持っています。キックされたパーティメンバーには、パーティからキックされたことが通知され、現在のパーティメンバーにも誰かがパーティからキックされたことが通知されます。
- OSS
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python 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
}
);
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
}
namespace := "namespace"
partyId := "mypartyid"
userId := "myuserid"
input := &party.PublicPartyKickParams{
Namespace: namespace,
PartyID: partyId,
UserID: userId,
}
result, err := partyService.PublicPartyKickShort(input)
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
result, error = session_service.public_party_kick(
party_id="PartyId",
user_id="OtherUserId",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
Leave a party
パーティメンバーは、自分のパーティから離脱することを選択できます。パーティリーダーがパーティを離脱すると、パーティのリーダーシップは自動的に他のパーティメンバーに引き継がれます。パーティを離脱したパーティメンバーには、パーティを離脱したことが通知され、現在のパーティメンバーにも誰かがパーティを離脱していることが通知されます。
- OSS
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python 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
});
string partyId = "<party id>";
sdk.Session.Party.PublicPartyLeaveOp
.Execute(sdk.Namespace, partyId);
namespace := "mygame"
partyId := "mypartyid"
input := &party.PublicPartyLeaveParams{
Namespace: namespace,
PartyID: partyId,
}
err := partyService.PublicPartyLeaveShort(input)
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
result, error = session_service.public_party_leave(
party_id="PartyId",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
Party codes
パーティリーダーは、プレイヤーが自分のパーティに参加できるようにパーティコードを送信できます。パーティコードを更新または取り消せるのはパーティリーダーのみです。
Get a party code
コードが生成されると、パーティリーダーはそのコードを取得して他のプレイヤーに共有できます。この関数は、パーティリーダーがパーティコードを取得できるようにします。
- OSS
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python 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;
});
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
}
namespace := "mygame"
partyId := "mypartyid"
input := &party.PublicGetPartyParams{
Namespace: namespace,
PartyID: partyId,
}
result, err := partyService.PublicGetPartyShort(input)
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
result, error = session_service.public_get_party(
party_id="PartyId",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
Generate or refresh a party code
パーティコードを生成または更新するには、以下の関数を使用します。
- OSS
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python 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
});
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
}
namespace := "mygame"
partyId := "mypartyid"
input := &party.PublicGeneratePartyCodeParams{
Namespace: namespace,
PartyID: partyId,
}
result, err := partyService.PublicGeneratePartyCodeShort(input)
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
result, error = session_service.public_generate_party_code(
party_id="PartyId",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
Revoke a party code
パーティリーダーは、パーティコードを取り消すことができます。パーティコードが取り消されると、プレイヤーはそれを使用してパーティに参加できなくなります。この関数は、パーティリーダーがパーティコードを取り消せるようにします。
- OSS
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python 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
});
string partyId = "<party id>";
sdk.Session.Party.PublicRevokePartyCodeOp
.Execute(sdk.Namespace, partyId);
namespace := "mygame"
partyId := "mypartyid"
input := &party.PublicRevokePartyCodeParams{
Namespace: namespace,
PartyID: partyId,
}
err := partyService.PublicRevokePartyCodeShort(input)
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
result, error = session_service.public_revoke_party_code(
party_id="PartyId",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
Join a party with a party code
パーティコードを送られたプレイヤーは、それを使用してパーティに参加できます。この関数は、プレイヤーがパーティコードを使用してパーティに参加できるようにします。
- OSS
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python 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
});
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
}
code := "mypartycode"
body := sessionclientmodels.ApimodelsJoinByCodeRequest {
Code: &code,
}
namespace := "mygame"
input := &party.PublicPartyJoinCodeParams{
Body: &body,
Namespace: namespace,
}
result, err := partyService.PublicPartyJoinCodeShort(input)
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
result, error = session_service.public_party_join_code(
body=session_models.ApimodelsJoinByCodeRequest()
.with_code("PartyCode"),
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
Refresh party session
ゲームセッションは、Refresh Session メソッドを使用してバックエンドと同期するように更新できます。指定する SessionName パラメータは NAME_PartySession に対応させることができます。
- OSS Unreal
SessionInterface->RefreshSession(SessionName, FOnRefreshSessionComplete::CreateLambda([]()
{
// On refresh session complete
}));
Refresh active sessions
問題を防止し、バックエンドとの適切な同期を確保するために、以下の関数を使用して、クライアント側にローカルにキャッシュされているすべてのアクティブなセッションを更新します。
- OSS Unreal
SessionInterface->RefreshActiveSessions(FOnRefreshActiveSessionsComplete::CreateLambda(
[&](bool bWasSuccessful)
{
// On refresh active sessions complete
}));