[GameLift][FlexMatch] Add client side change for match acceptance (#4634)

* [GameLift][FlexMatch] Add client side change for match acceptance required

Signed-off-by: Junbo Liang <junbo@amazon.com>
This commit is contained in:
Junbo Liang
2021-10-13 11:34:13 -07:00
committed by GitHub
parent 150060441e
commit 26d53690b9
17 changed files with 409 additions and 8 deletions
@@ -10,6 +10,7 @@
#include <AzCore/std/bind/bind.h>
#include <AzCore/std/smart_ptr/shared_ptr.h>
#include <AzFramework/Session/ISessionHandlingRequests.h>
#include <AzFramework/Matchmaking/MatchmakingNotifications.h>
#include <AWSGameLiftClientLocalTicketTracker.h>
#include <AWSGameLiftSessionConstants.h>
@@ -109,6 +110,7 @@ namespace AWSGameLift
else if (ticket.GetStatus() == Aws::GameLift::Model::MatchmakingConfigurationStatus::REQUIRES_ACCEPTANCE)
{
// broadcast acceptance requires to player
AzFramework::MatchAcceptanceNotificationBus::Broadcast(&AzFramework::MatchAcceptanceNotifications::OnMatchAcceptance);
}
else
{
@@ -18,6 +18,7 @@
#include <AWSGameLiftClientManager.h>
#include <AWSGameLiftSessionConstants.h>
#include <Activity/AWSGameLiftAcceptMatchActivity.h>
#include <Activity/AWSGameLiftCreateSessionActivity.h>
#include <Activity/AWSGameLiftCreateSessionOnQueueActivity.h>
#include <Activity/AWSGameLiftJoinSessionActivity.h>
@@ -125,12 +126,53 @@ namespace AWSGameLift
void AWSGameLiftClientManager::AcceptMatch(const AzFramework::AcceptMatchRequest& acceptMatchRequest)
{
AZ_UNUSED(acceptMatchRequest);
if (AcceptMatchActivity::ValidateAcceptMatchRequest(acceptMatchRequest))
{
const AWSGameLiftAcceptMatchRequest& gameliftStartMatchmakingRequest =
static_cast<const AWSGameLiftAcceptMatchRequest&>(acceptMatchRequest);
AcceptMatchHelper(gameliftStartMatchmakingRequest);
}
}
void AWSGameLiftClientManager::AcceptMatchAsync(const AzFramework::AcceptMatchRequest& acceptMatchRequest)
{
AZ_UNUSED(acceptMatchRequest);
if (!AcceptMatchActivity::ValidateAcceptMatchRequest(acceptMatchRequest))
{
AzFramework::MatchmakingAsyncRequestNotificationBus::Broadcast(
&AzFramework::MatchmakingAsyncRequestNotifications::OnAcceptMatchAsyncComplete);
return;
}
const AWSGameLiftAcceptMatchRequest& gameliftStartMatchmakingRequest = static_cast<const AWSGameLiftAcceptMatchRequest&>(acceptMatchRequest);
AZ::JobContext* jobContext = nullptr;
AWSCore::AWSCoreRequestBus::BroadcastResult(jobContext, &AWSCore::AWSCoreRequests::GetDefaultJobContext);
AZ::Job* acceptMatchJob = AZ::CreateJobFunction(
[this, gameliftStartMatchmakingRequest]()
{
AcceptMatchHelper(gameliftStartMatchmakingRequest);
AzFramework::MatchmakingAsyncRequestNotificationBus::Broadcast(
&AzFramework::MatchmakingAsyncRequestNotifications::OnAcceptMatchAsyncComplete);
},
true, jobContext);
acceptMatchJob->Start();
}
void AWSGameLiftClientManager::AcceptMatchHelper(const AWSGameLiftAcceptMatchRequest& acceptMatchRequest)
{
auto gameliftClient = AZ::Interface<IAWSGameLiftInternalRequests>::Get()->GetGameLiftClient();
AZStd::string response;
if (!gameliftClient)
{
AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftClientMissingErrorMessage);
}
else
{
AcceptMatchActivity::AcceptMatch(*gameliftClient, acceptMatchRequest);
}
}
AZStd::string AWSGameLiftClientManager::CreateSession(const AzFramework::CreateSessionRequest& createSessionRequest)
@@ -15,6 +15,7 @@
namespace AWSGameLift
{
struct AWSGameLiftAcceptMatchRequest;
struct AWSGameLiftCreateSessionRequest;
struct AWSGameLiftCreateSessionOnQueueRequest;
struct AWSGameLiftJoinSessionRequest;
@@ -158,6 +159,7 @@ namespace AWSGameLift
void LeaveSession() override;
private:
void AcceptMatchHelper(const AWSGameLiftAcceptMatchRequest& createSessionRequest);
AZStd::string CreateSessionHelper(const AWSGameLiftCreateSessionRequest& createSessionRequest);
AZStd::string CreateSessionOnQueueHelper(const AWSGameLiftCreateSessionOnQueueRequest& createSessionOnQueueRequest);
bool JoinSessionHelper(const AWSGameLiftJoinSessionRequest& joinSessionRequest);
@@ -0,0 +1,76 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.AcceptMatch
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <AzCore/Interface/Interface.h>
#include <Activity/AWSGameLiftAcceptMatchActivity.h>
#include <AWSGameLiftSessionConstants.h>
#include <aws/core/utils/Outcome.h>
#include <aws/gamelift/model/AcceptMatchRequest.h>
namespace AWSGameLift
{
namespace AcceptMatchActivity
{
Aws::GameLift::Model::AcceptMatchRequest BuildAWSGameLiftAcceptMatchRequest(
const AWSGameLiftAcceptMatchRequest& acceptMatchRequest)
{
Aws::GameLift::Model::AcceptMatchRequest request;
request.SetAcceptanceType(acceptMatchRequest.m_acceptMatch ?
Aws::GameLift::Model::AcceptanceType::ACCEPT : Aws::GameLift::Model::AcceptanceType::REJECT);
Aws::Vector<Aws::String> playerIds;
for (const AZStd::string& playerId : acceptMatchRequest.m_playerIds)
{
playerIds.emplace_back(playerId.c_str());
}
request.SetPlayerIds(playerIds);
if (!acceptMatchRequest.m_ticketId.empty())
{
request.SetTicketId(acceptMatchRequest.m_ticketId.c_str());
}
AZ_TracePrintf(AWSGameLiftAcceptMatchActivityName, "Built AcceptMatchRequest with TicketId=%s", request.GetTicketId().c_str());
return request;
}
void AcceptMatch(const Aws::GameLift::GameLiftClient& gameliftClient,
const AWSGameLiftAcceptMatchRequest& AcceptMatchRequest)
{
AZ_TracePrintf(AWSGameLiftAcceptMatchActivityName, "Requesting AcceptMatch against Amazon GameLift service ...");
Aws::GameLift::Model::AcceptMatchRequest request = BuildAWSGameLiftAcceptMatchRequest(AcceptMatchRequest);
auto AcceptMatchOutcome = gameliftClient.AcceptMatch(request);
if (AcceptMatchOutcome.IsSuccess())
{
AZ_TracePrintf(AWSGameLiftAcceptMatchActivityName, "AcceptMatch request against Amazon GameLift service is complete");
}
else
{
AZ_Error(AWSGameLiftAcceptMatchActivityName, false, AWSGameLiftErrorMessageTemplate,
AcceptMatchOutcome.GetError().GetExceptionName().c_str(), AcceptMatchOutcome.GetError().GetMessage().c_str());
}
}
bool ValidateAcceptMatchRequest(const AzFramework::AcceptMatchRequest& AcceptMatchRequest)
{
auto gameliftAcceptMatchRequest = azrtti_cast<const AWSGameLiftAcceptMatchRequest*>(&AcceptMatchRequest);
bool isValid = gameliftAcceptMatchRequest &&
(gameliftAcceptMatchRequest->m_playerIds.size() > 0) &&
(!gameliftAcceptMatchRequest->m_ticketId.empty());
AZ_Error(AWSGameLiftAcceptMatchActivityName, isValid, AWSGameLiftAcceptMatchRequestInvalidErrorMessage);
return isValid;
}
} // namespace AcceptMatchActivity
} // namespace AWSGameLift
@@ -0,0 +1,31 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <Request/AWSGameLiftAcceptMatchRequest.h>
#include <aws/gamelift/GameLiftClient.h>
namespace AWSGameLift
{
namespace AcceptMatchActivity
{
static constexpr const char AWSGameLiftAcceptMatchActivityName[] = "AWSGameLiftAcceptMatchActivity";
static constexpr const char AWSGameLiftAcceptMatchRequestInvalidErrorMessage[] = "Invalid GameLift AcceptMatch request.";
// Build AWS GameLift AcceptMatchRequest by using AWSGameLiftAcceptMatchRequest
Aws::GameLift::Model::AcceptMatchRequest BuildAWSGameLiftAcceptMatchRequest(const AWSGameLiftAcceptMatchRequest& AcceptMatchRequest);
// Create AcceptMatchRequest and make a AcceptMatch call through GameLift client
void AcceptMatch(const Aws::GameLift::GameLiftClient& gameliftClient, const AWSGameLiftAcceptMatchRequest& AcceptMatchRequest);
// Validate AcceptMatchRequest and check required request parameters
bool ValidateAcceptMatchRequest(const AzFramework::AcceptMatchRequest& AcceptMatchRequest);
} // namespace AcceptMatchActivity
} // namespace AWSGameLift
@@ -5,12 +5,16 @@
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <AzCore/Interface/Interface.h>
#include <Activity/AWSGameLiftActivityUtils.h>
#include <Activity/AWSGameLiftStartMatchmakingActivity.h>
#include <AWSGameLiftSessionConstants.h>
#include <aws/core/utils/Outcome.h>
#include <aws/gamelift/model/StartMatchmakingRequest.h>
namespace AWSGameLift
{
namespace StartMatchmakingActivity
@@ -10,9 +10,7 @@
#include <Request/AWSGameLiftStartMatchmakingRequest.h>
#include <aws/core/utils/Outcome.h>
#include <aws/gamelift/GameLiftClient.h>
#include <aws/gamelift/model/StartMatchmakingRequest.h>
namespace AWSGameLift
{
@@ -25,7 +23,6 @@ namespace AWSGameLift
Aws::GameLift::Model::StartMatchmakingRequest BuildAWSGameLiftStartMatchmakingRequest(const AWSGameLiftStartMatchmakingRequest& startMatchmakingRequest);
// Create StartMatchmakingRequest and make a StartMatchmaking call through GameLift client
// Will also start polling the matchmaking ticket when get success outcome from GameLift client
AZStd::string StartMatchmaking(const Aws::GameLift::GameLiftClient& gameliftClient, const AWSGameLiftStartMatchmakingRequest& startMatchmakingRequest);
// Validate StartMatchmakingRequest and check required request parameters
@@ -11,6 +11,9 @@
#include <Activity/AWSGameLiftStopMatchmakingActivity.h>
#include <AWSGameLiftSessionConstants.h>
#include <aws/core/utils/Outcome.h>
#include <aws/gamelift/model/StopMatchmakingRequest.h>
namespace AWSGameLift
{
namespace StopMatchmakingActivity
@@ -10,9 +10,7 @@
#include <Request/AWSGameLiftStopMatchmakingRequest.h>
#include <aws/core/utils/Outcome.h>
#include <aws/gamelift/GameLiftClient.h>
#include <aws/gamelift/model/StopMatchmakingRequest.h>
namespace AWSGameLift
{
@@ -25,7 +23,6 @@ namespace AWSGameLift
Aws::GameLift::Model::StopMatchmakingRequest BuildAWSGameLiftStopMatchmakingRequest(const AWSGameLiftStopMatchmakingRequest& stopMatchmakingRequest);
// Create StopMatchmakingRequest and make a StopMatchmaking call through GameLift client
// Will also stop polling the matchmaking ticket when get success outcome from GameLift client
void StopMatchmaking(const Aws::GameLift::GameLiftClient& gameliftClient, const AWSGameLiftStopMatchmakingRequest& stopMatchmakingRequest);
// Validate StopMatchmakingRequest and check required request parameters