Configuring Session Templates with the SDK
Last updated on November 21, 2023
概要
このセクションでは、ゲーム SDK を介してセッションを作成、更新、およびその他の方法で管理する方法を示します。
セッションテンプレートを使用すると、ゲーム開発者はセッションの動作を設定できます。このトピックの目標
は、次の方法を示すコードスニペットを提供することです。
- ゲームセッションを作成する
- ゲームセッションを取得する
- ゲームセッション
- の詳細を取得する
- ゲームセッションを更新する
- ゲームセッションを削除する-プレイヤーをゲームセッションに招待する
- -ゲームセッションに参加する
- ゲームセッションの招待を拒否する
- ゲームセッションを終了する
- ゲームセッションの通知を聞く
ゲーム SDK を使用してゲームセッションを管理する
ゲームセッションを作成する
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FAccelByteModelsV2GameSessionCreateRequest Request;
Request.ConfigurationName = ConfigurationName; // MANDATORY
Request.Joinability = EAccelByteV2SessionJoinability::INVITE_ONLY; // Optional
Request.Type = EAccelByteV2SessionConfigurationServerType::DS; // Optional
Request.ClientVersion = GameServerVersion; // Optional
Request.ServerName = LocalServerName; // Optional
Request.Deployment = Deployment; // Optional
Request.RequestedRegions = {"us-west-1", "us-west2"}; // Optional
// Optional
TArray<FString> TeamA = {TeamAUserId1, TeamAUserId2};
TArray<FString> TeamB = {TeamBUserId1, TeamBUserId2};
TArray<FAccelByteModelsV2GameSessionTeam> Teams;
Teams.Add({TeamA});
Request.Teams = Teams;
// Optional
Request.Attributes.JsonObject = MakeShared<FJsonObject>();
Request.Attributes.JsonObject->SetStringField("PartyAttribute", "Attribute1");
Request.MaxPlayers = 10; // Optional
Request.MinPlayers = 1; // Optional
Request.InactiveTimeout = 30; // Optional
Request.InviteTimeout = 86400; // Optional
ApiClient->Session.CreateGameSession(Request,
THandler<FAccelByteModelsV2GameSession>::CreateLambda(
[&](const FAccelByteModelsV2GameSession& Result)
{
// Do something when operation success
}),
FErrorHandler::CreateLambda(
[&](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something when operation error / failed
}));
SessionV2GameSessionCreateRequest createGameSessionRequest = new SessionV2GameSessionCreateRequest
{
joinability = SessionV2Joinability.OPEN,
configurationName = _configurationTemplateName
};
AccelBytePlugin.GetSession()
.CreateGameSession(createGameSessionRequest, result =>
{
if (!result.IsError)
{
// Creating game session success
}
});
ゲームセッションを取得する
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
ApiClient->Session.GetMyGameSessions(
THandler<FAccelByteModelsV2PaginatedGameSessionQueryResult>::CreateLambda(
[&](const FAccelByteModelsV2PaginatedGameSessionQueryResult& Result)
{
// Do something when operation success
}),
FErrorHandler::CreateLambda(
[&](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something when operation error / failed
}));
AccelBytePlugin.GetSession()
.GetUserGameSessions(null, null, null, result =>
{
if (!result.IsError)
{
// success get game session details
}
});
ゲームセッションの詳細を取得する
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
ApiClient->Session.GetGameSessionDetails( SessionId,
THandler<FAccelByteModelsV2GameSession>::CreateLambda(
[&](const FAccelByteModelsV2GameSession& Result)
{
// Do something when operation success
}),
FErrorHandler::CreateLambda(
[&](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something when operation error / failed
}));
AccelBytePlugin.GetSession()
.GetGameSessionDetailsBySessionId(sessionId, result =>
{
if (!result.IsError)
{
// success get Game Session details
}
});
ゲームセッションを更新する
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FAccelByteModelsV2GameSessionUpdateRequest Request;
Request.Version = PartyDataVersion; // Mandatory, must be the same version as current data in the backend
Request.Joinability = EAccelByteV2SessionJoinability::INVITE_ONLY; // Optional
Request.Attributes.JsonObject = MakeShared<FJsonObject>(); // Optional
Request.Attributes.JsonObject->SetStringField("AttributeName", "Attribute1"); // Optional
Request.MaxPlayers = 10; // Optional
Request.MinPlayers = 1; // Optional
Request.InactiveTimeout = 30; // Optional
Request.InviteTimeout = 86400; // Optional
ApiClient->Session.UpdateGameSession(GameSessionID, Request, THandler<FAccelByteModelsV2GameSession>::CreateLambda(
[&](const FAccelByteModelsV2GameSession& Result)
{
// do something when success
}),
FErrorHandler::CreateLambda([&](int32 ErrorCode, const FString& Message)
{
// do something when failed / error
}));
SessionV2GameSessionUpdateRequest updateRequest = new SessionV2GameSessionUpdateRequest()
{
joinability = SessionV2Joinability.OPEN
};
AccelBytePlugin.GetSession()
.PatchGameSession(sessionId, updateRequest, result =>
{
if (!result.IsError)
{
// Update game session success
}
});
ゲームセッションを削除する
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
ApiClient->Session.DeleteGameSession(SessionId, FVoidHandler::CreateLambda([]
{
// successfully deleted game session
}),
FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& Message)
{
// error deleting game session
}));
AccelBytePlugin.GetSession()
.DeleteGameSession(sessionId, result =>
{
if (!result.IsError)
{
// delete Game Session success
}
});
プレイヤーをゲームセッションに招待する
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
ApiClient->Session.SendGameSessionInvite(SessionId, UserIdToInvite, FVoidHandler::CreateLambda(
[&]
{
// do something when success
}),
FErrorHandler::CreateLambda([&](int32 ErrorCode, const FString& Message)
{
// do something when failed / error
}));
AccelBytePlugin.GetSession()
.InviteUserToGameSession(sessionId, userIdToInvite, result =>
{
if (!result.IsError)
{
// invite to game session success
}
});
ゲームセッションに参加する
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
ApiClient->Session.JoinGameSession(SessionId, THandler<FAccelByteModelsV2GameSession>::CreateLambda(
[&](const FAccelByteModelsV2GameSession& Result)
{
// do something when success
}),
FErrorHandler::CreateLambda([&](int32 ErrorCode, const FString& Message)
{
// do something when failed / error
}));
AccelBytePlugin.GetSession()
.JoinGameSession(sessionId, result =>
{
if (!result.IsError)
{
// join to game session success
}
});
ゲームセッションの招待を拒否する
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
ApiClient->Session.RejectGameSessionInvite(GameSessionID, FVoidHandler::CreateLambda(
[&]
{
// do something when success
}),
FErrorHandler::CreateLambda([&](int32 ErrorCode, const FString& Message)
{
// do something when failed / error
}));
AccelBytePlugin.GetSession()
.RejectGameSessionInvitation(sessionId, result =>
{
if (!result.IsError)
{
// reject to game session success
}
});
ゲームセッションを終了する
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
ApiClient->Session.LeaveGameSession(SessionId, FVoidHandler::CreateLambda(
[&]
{
// do something when success
}),
FErrorHandler::CreateLambda([&](int32 ErrorCode, const FString& Message)
{
// do something when failed / error
}));
AccelBytePlugin.GetSession()
.LeaveGameSession(sessionId, result =>
{
if (!result.IsError)
{
// leave to game session success
}
});
ゲームセッションの通知を聞く
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
ApiClient->Lobby.SetV2GameSessionInvitedNotifDelegate(Api::Lobby::FV2GameSessionInvitedNotif::CreateLambda(
[&](const FAccelByteModelsV2GameSessionUserInvitedEvent& Notif)
{
// Do something when receive notification
}));
ApiClient->Lobby.SetV2GameSessionMembersChangedNotifDelegate(Api::Lobby::FV2GameSessionMembersChangedNotif::CreateLambda(
[&](const FAccelByteModelsV2GameSessionMembersChangedEvent& Notif)
{
// Do something when receive notification
}));
ApiClient->Lobby.SetV2GameSessionJoinedNotifDelegate(Api::Lobby::FV2GameSessionJoinedNotif::CreateLambda(
[&](const FAccelByteModelsV2GameSessionUserJoinedEvent& Notif)
{
// Do something when receive notification
}));
ApiClient->Lobby.SetV2GameSessionRejectedNotifDelegate(Api::Lobby::FV2GameSessionRejectedNotif::CreateLambda(
[&](const FAccelByteModelsV2GameSessionUserRejectedEvent& Notif)
{
// Do something when receive notification
}));
ApiClient->Lobby.SetV2GameSessionKickedNotifDelegate(Api::Lobby::FV2GameSessionKickedNotif::CreateLambda(
[&](const FAccelByteModelsV2GameSessionUserKickedEvent& Notif)
{
// Do something when receive notification
}));
ApiClient->Lobby.SetV2GameSessionUpdatedNotifDelegate(Api::Lobby::FV2GameSessionUpdatedNotif::CreateLambda(
[&](const FAccelByteModelsV2GameSession& Notif)
{
// Do something when receive notification
}));
ApiClient->Lobby.SetV2DSStatusChangedNotifDelegate(Api::Lobby::FV2DSStatusChangedNotif::CreateLambda(
[&](const FAccelByteModelsV2DSStatusChangedNotif& Notif)
{
// Do something when receive notification
}));
AccelBytePlugin.GetLobby().SessionV2GameSessionUpdated += (Result<SessionV2GameSessionUpdatedNotification> notif) =>
{
// do something when a game session is updated
};
AccelBytePlugin.GetLobby().SessionV2GameSessionMemberChanged += (Result<SessionV2GameMembersChangedNotification> notif) =>
{
// do something when a game session member has change
};
AccelBytePlugin.GetLobby().SessionV2UserJoinedGameSession += (Result<SessionV2GameJoinedNotification> notif) =>
{
// do something when a user joined the game session
};
AccelBytePlugin.GetLobby().SessionV2UserKickedFromGameSession += (Result<SessionV2GameUserKickedNotification> notif) =>
{
// do something when kicked from a game session
};
AccelBytePlugin.GetLobby().SessionV2UserRejectedGameSessionInvitation += (Result<SessionV2GameInvitationRejectedNotification> notif) =>
{
// do something when a game session invite is rejected
};
AccelBytePlugin.GetLobby().SessionV2InvitedUserToGameSession += (Result<SessionV2GameInvitationNotification> notif) =>
{
// do something when invited to a game session
};