[O3DE][GameLift] Add client side change for starting and stopping matchmaking (#4536)
* [O3DE][GameLift] Add client side change for starting and stopping matchmaking Signed-off-by: Junbo Liang <junbo@amazon.com>
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/RTTI/RTTI.h>
|
||||
#include <AzCore/std/containers/vector.h>
|
||||
#include <AzCore/std/string/string.h>
|
||||
|
||||
namespace AZ
|
||||
|
||||
+3
@@ -8,6 +8,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/std/containers/unordered_map.h>
|
||||
#include <AzCore/std/string/string.h>
|
||||
|
||||
#include <AzFramework/Matchmaking/MatchmakingRequests.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include <Activity/AWSGameLiftLeaveSessionActivity.h>
|
||||
#include <Activity/AWSGameLiftSearchSessionsActivity.h>
|
||||
#include <Request/IAWSGameLiftInternalRequests.h>
|
||||
#include <Activity/AWSGameLiftStartMatchmakingActivity.h>
|
||||
#include <Activity/AWSGameLiftStopMatchmakingActivity.h>
|
||||
|
||||
#include <aws/core/auth/AWSCredentialsProvider.h>
|
||||
|
||||
@@ -43,10 +45,22 @@ namespace AWSGameLift
|
||||
|
||||
AZ::Interface<AzFramework::ISessionRequests>::Register(this);
|
||||
AWSGameLiftSessionRequestBus::Handler::BusConnect();
|
||||
|
||||
AZ::Interface<AzFramework::IMatchmakingAsyncRequests>::Register(this);
|
||||
AWSGameLiftMatchmakingAsyncRequestBus::Handler::BusConnect();
|
||||
|
||||
AZ::Interface<AzFramework::IMatchmakingRequests>::Register(this);
|
||||
AWSGameLiftMatchmakingRequestBus::Handler::BusConnect();
|
||||
}
|
||||
|
||||
void AWSGameLiftClientManager::DeactivateManager()
|
||||
{
|
||||
AWSGameLiftMatchmakingRequestBus::Handler::BusDisconnect();
|
||||
AZ::Interface<AzFramework::IMatchmakingRequests>::Unregister(this);
|
||||
|
||||
AWSGameLiftMatchmakingAsyncRequestBus::Handler::BusDisconnect();
|
||||
AZ::Interface<AzFramework::IMatchmakingAsyncRequests>::Unregister(this);
|
||||
|
||||
AWSGameLiftSessionRequestBus::Handler::BusDisconnect();
|
||||
AZ::Interface<AzFramework::ISessionRequests>::Unregister(this);
|
||||
|
||||
@@ -357,23 +371,108 @@ namespace AWSGameLift
|
||||
|
||||
AZStd::string AWSGameLiftClientManager::StartMatchmaking(const AzFramework::StartMatchmakingRequest& startMatchmakingRequest)
|
||||
{
|
||||
AZ_UNUSED(startMatchmakingRequest);
|
||||
AZStd::string response;
|
||||
if (StartMatchmakingActivity::ValidateStartMatchmakingRequest(startMatchmakingRequest))
|
||||
{
|
||||
const AWSGameLiftStartMatchmakingRequest& gameliftStartMatchmakingRequest =
|
||||
static_cast<const AWSGameLiftStartMatchmakingRequest&>(startMatchmakingRequest);
|
||||
response = StartMatchmakingHelper(gameliftStartMatchmakingRequest);
|
||||
}
|
||||
|
||||
return AZStd::string{};
|
||||
return response;
|
||||
}
|
||||
|
||||
void AWSGameLiftClientManager::StartMatchmakingAsync(const AzFramework::StartMatchmakingRequest& startMatchmakingRequest)
|
||||
{
|
||||
AZ_UNUSED(startMatchmakingRequest);
|
||||
if (!StartMatchmakingActivity::ValidateStartMatchmakingRequest(startMatchmakingRequest))
|
||||
{
|
||||
AzFramework::MatchmakingAsyncRequestNotificationBus::Broadcast(
|
||||
&AzFramework::MatchmakingAsyncRequestNotifications::OnStartMatchmakingAsyncComplete, AZStd::string{});
|
||||
return;
|
||||
}
|
||||
|
||||
const AWSGameLiftStartMatchmakingRequest& gameliftStartMatchmakingRequest =
|
||||
static_cast<const AWSGameLiftStartMatchmakingRequest&>(startMatchmakingRequest);
|
||||
|
||||
AZ::JobContext* jobContext = nullptr;
|
||||
AWSCore::AWSCoreRequestBus::BroadcastResult(jobContext, &AWSCore::AWSCoreRequests::GetDefaultJobContext);
|
||||
AZ::Job* startMatchmakingJob = AZ::CreateJobFunction(
|
||||
[this, gameliftStartMatchmakingRequest]()
|
||||
{
|
||||
AZStd::string response = StartMatchmakingHelper(gameliftStartMatchmakingRequest);
|
||||
|
||||
AzFramework::MatchmakingAsyncRequestNotificationBus::Broadcast(
|
||||
&AzFramework::MatchmakingAsyncRequestNotifications::OnStartMatchmakingAsyncComplete, response);
|
||||
},
|
||||
true, jobContext);
|
||||
|
||||
startMatchmakingJob->Start();
|
||||
}
|
||||
|
||||
AZStd::string AWSGameLiftClientManager::StartMatchmakingHelper(const AWSGameLiftStartMatchmakingRequest& startMatchmakingRequest)
|
||||
{
|
||||
auto gameliftClient = AZ::Interface<IAWSGameLiftInternalRequests>::Get()->GetGameLiftClient();
|
||||
|
||||
AZStd::string response;
|
||||
if (!gameliftClient)
|
||||
{
|
||||
AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftClientMissingErrorMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = StartMatchmakingActivity::StartMatchmaking(*gameliftClient, startMatchmakingRequest);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
void AWSGameLiftClientManager::StopMatchmaking(const AzFramework::StopMatchmakingRequest& stopMatchmakingRequest)
|
||||
{
|
||||
AZ_UNUSED(stopMatchmakingRequest);
|
||||
if (StopMatchmakingActivity::ValidateStopMatchmakingRequest(stopMatchmakingRequest))
|
||||
{
|
||||
const AWSGameLiftStopMatchmakingRequest& gameliftStopMatchmakingRequest =
|
||||
static_cast<const AWSGameLiftStopMatchmakingRequest&>(stopMatchmakingRequest);
|
||||
StopMatchmakingHelper(gameliftStopMatchmakingRequest);
|
||||
}
|
||||
}
|
||||
|
||||
void AWSGameLiftClientManager::StopMatchmakingAsync(const AzFramework::StopMatchmakingRequest& stopMatchmakingRequest)
|
||||
{
|
||||
AZ_UNUSED(stopMatchmakingRequest);
|
||||
if (!StopMatchmakingActivity::ValidateStopMatchmakingRequest(stopMatchmakingRequest))
|
||||
{
|
||||
AzFramework::MatchmakingAsyncRequestNotificationBus::Broadcast(
|
||||
&AzFramework::MatchmakingAsyncRequestNotifications::OnStopMatchmakingAsyncComplete);
|
||||
return;
|
||||
}
|
||||
|
||||
const AWSGameLiftStopMatchmakingRequest& gameliftStopMatchmakingRequest =
|
||||
static_cast<const AWSGameLiftStopMatchmakingRequest&>(stopMatchmakingRequest);
|
||||
|
||||
AZ::JobContext* jobContext = nullptr;
|
||||
AWSCore::AWSCoreRequestBus::BroadcastResult(jobContext, &AWSCore::AWSCoreRequests::GetDefaultJobContext);
|
||||
AZ::Job* stopMatchmakingJob = AZ::CreateJobFunction(
|
||||
[this, gameliftStopMatchmakingRequest]()
|
||||
{
|
||||
StopMatchmakingHelper(gameliftStopMatchmakingRequest);
|
||||
|
||||
AzFramework::MatchmakingAsyncRequestNotificationBus::Broadcast(
|
||||
&AzFramework::MatchmakingAsyncRequestNotifications::OnStopMatchmakingAsyncComplete);
|
||||
},
|
||||
true, jobContext);
|
||||
|
||||
stopMatchmakingJob->Start();
|
||||
}
|
||||
|
||||
void AWSGameLiftClientManager::StopMatchmakingHelper(const AWSGameLiftStopMatchmakingRequest& stopMatchmakingRequest)
|
||||
{
|
||||
auto gameliftClient = AZ::Interface<IAWSGameLiftInternalRequests>::Get()->GetGameLiftClient();
|
||||
|
||||
if (!gameliftClient)
|
||||
{
|
||||
AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftClientMissingErrorMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
StopMatchmakingActivity::StopMatchmaking(*gameliftClient, stopMatchmakingRequest);
|
||||
}
|
||||
}
|
||||
} // namespace AWSGameLift
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace AWSGameLift
|
||||
struct AWSGameLiftCreateSessionOnQueueRequest;
|
||||
struct AWSGameLiftJoinSessionRequest;
|
||||
struct AWSGameLiftSearchSessionsRequest;
|
||||
struct AWSGameLiftStartMatchmakingRequest;
|
||||
struct AWSGameLiftStopMatchmakingRequest;
|
||||
|
||||
// MatchAcceptanceNotificationBus EBus handler for scripting
|
||||
class AWSGameLiftMatchAcceptanceNotificationBusHandler
|
||||
@@ -160,5 +162,7 @@ namespace AWSGameLift
|
||||
AZStd::string CreateSessionOnQueueHelper(const AWSGameLiftCreateSessionOnQueueRequest& createSessionOnQueueRequest);
|
||||
bool JoinSessionHelper(const AWSGameLiftJoinSessionRequest& joinSessionRequest);
|
||||
AzFramework::SearchSessionsResponse SearchSessionsHelper(const AWSGameLiftSearchSessionsRequest& searchSessionsRequest) const;
|
||||
AZStd::string StartMatchmakingHelper(const AWSGameLiftStartMatchmakingRequest& startMatchmakingRequest);
|
||||
void StopMatchmakingHelper(const AWSGameLiftStopMatchmakingRequest& stopMatchmakingRequest);
|
||||
};
|
||||
} // namespace AWSGameLift
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <aws/core/utils/json/JsonSerializer.h>
|
||||
#include <Activity/AWSGameLiftActivityUtils.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
@@ -31,5 +32,53 @@ namespace AWSGameLift
|
||||
outGamePropertiesOutput.substr(0, outGamePropertiesOutput.size() - 1); // Trim last comma to fit array format
|
||||
}
|
||||
}
|
||||
|
||||
void ConvertPlayerAttributes(
|
||||
const AZStd::unordered_map<AZStd::string, AZStd::string>& playerAttributes,
|
||||
Aws::Map<Aws::String, Aws::GameLift::Model::AttributeValue>& outPlayerAttributes)
|
||||
{
|
||||
outPlayerAttributes.clear();
|
||||
for (auto& playerAttribute : playerAttributes)
|
||||
{
|
||||
Aws::Utils::Json::JsonValue keyJsonValue(playerAttribute.second.c_str());
|
||||
Aws::GameLift::Model::AttributeValue attribute(keyJsonValue);
|
||||
outPlayerAttributes[playerAttribute.first.c_str()] = attribute;
|
||||
}
|
||||
}
|
||||
|
||||
void ConvertRegionToLatencyMap(
|
||||
const AZStd::unordered_map<AZStd::string, int>& regionToLatencyMap,
|
||||
Aws::Map<Aws::String, int>& outRegionToLatencyMap)
|
||||
{
|
||||
outRegionToLatencyMap.clear();
|
||||
for (auto& regionToLatencyPair : regionToLatencyMap)
|
||||
{
|
||||
outRegionToLatencyMap[regionToLatencyPair.first.c_str()] = regionToLatencyPair.second;
|
||||
}
|
||||
}
|
||||
|
||||
bool ValidatePlayerAttributes(
|
||||
const AZStd::unordered_map<AZStd::string, AZStd::string>& playerAttributes)
|
||||
{
|
||||
for (auto& playerAttribute : playerAttributes)
|
||||
{
|
||||
Aws::Utils::Json::JsonValue keyJsonValue(playerAttribute.second.c_str());
|
||||
Aws::GameLift::Model::AttributeValue attribute(keyJsonValue);
|
||||
|
||||
// Each AttributeValue object can use only one of the available properties:
|
||||
// 1) number values (N)
|
||||
// 2) single string values (S)
|
||||
// 3) string to double map (SDM)
|
||||
// 4) array of strings (SL)
|
||||
if (!attribute.SHasBeenSet() &&
|
||||
!attribute.NHasBeenSet() &&
|
||||
!attribute.SDMHasBeenSet() &&
|
||||
!attribute.SLHasBeenSet())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace AWSGameLiftActivityUtils
|
||||
} // namespace AWSGameLift
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <AzCore/std/string/string.h>
|
||||
#include <aws/core/utils/memory/stl/AWSVector.h>
|
||||
#include <aws/gamelift/model/GameProperty.h>
|
||||
#include <aws/gamelift/model/AttributeValue.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
@@ -21,5 +22,17 @@ namespace AWSGameLift
|
||||
const AZStd::unordered_map<AZStd::string, AZStd::string>& sessionProperties,
|
||||
Aws::Vector<Aws::GameLift::Model::GameProperty>& outGameProperties,
|
||||
AZStd::string& outGamePropertiesOutput);
|
||||
|
||||
void ConvertPlayerAttributes(
|
||||
const AZStd::unordered_map<AZStd::string, AZStd::string>& playerAttributes,
|
||||
Aws::Map<Aws::String, Aws::GameLift::Model::AttributeValue>& outPlayerAttributes);
|
||||
|
||||
void ConvertRegionToLatencyMap(
|
||||
const AZStd::unordered_map<AZStd::string, int>& regionToLatencyMap,
|
||||
Aws::Map<Aws::String, int>& outRegionToLatencyMap);
|
||||
|
||||
bool ValidatePlayerAttributes(
|
||||
const AZStd::unordered_map<AZStd::string, AZStd::string>& playerAttributes);
|
||||
|
||||
} // namespace AWSGameLiftActivityUtils
|
||||
} // namespace AWSGameLift
|
||||
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
|
||||
#include <Activity/AWSGameLiftActivityUtils.h>
|
||||
#include <Activity/AWSGameLiftStartMatchmakingActivity.h>
|
||||
#include <AWSGameLiftSessionConstants.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
namespace StartMatchmakingActivity
|
||||
{
|
||||
Aws::GameLift::Model::StartMatchmakingRequest BuildAWSGameLiftStartMatchmakingRequest(
|
||||
const AWSGameLiftStartMatchmakingRequest& startMatchmakingRequest)
|
||||
{
|
||||
Aws::GameLift::Model::StartMatchmakingRequest request;
|
||||
if (!startMatchmakingRequest.m_configurationName.empty())
|
||||
{
|
||||
request.SetConfigurationName(startMatchmakingRequest.m_configurationName.c_str());
|
||||
}
|
||||
|
||||
Aws::Vector<Aws::GameLift::Model::Player> players;
|
||||
for (const AWSGameLiftPlayerInformation& playerInfo : startMatchmakingRequest.m_players)
|
||||
{
|
||||
Aws::GameLift::Model::Player player;
|
||||
if (!playerInfo.m_playerId.empty())
|
||||
{
|
||||
player.SetPlayerId(playerInfo.m_playerId.c_str());
|
||||
}
|
||||
|
||||
// Optional attributes
|
||||
if (!playerInfo.m_team.empty())
|
||||
{
|
||||
player.SetTeam(playerInfo.m_team.c_str());
|
||||
}
|
||||
if (playerInfo.m_latencyInMs.size() > 0)
|
||||
{
|
||||
Aws::Map<Aws::String, int> regionToLatencyMap;
|
||||
AWSGameLiftActivityUtils::ConvertRegionToLatencyMap(playerInfo.m_latencyInMs, regionToLatencyMap);
|
||||
player.SetLatencyInMs(AZStd::move(regionToLatencyMap));
|
||||
}
|
||||
if (playerInfo.m_playerAttributes.size() > 0)
|
||||
{
|
||||
Aws::Map<Aws::String, Aws::GameLift::Model::AttributeValue> playerAttributes;
|
||||
AWSGameLiftActivityUtils::ConvertPlayerAttributes(playerInfo.m_playerAttributes, playerAttributes);
|
||||
player.SetPlayerAttributes(AZStd::move(playerAttributes));
|
||||
}
|
||||
players.emplace_back(player);
|
||||
}
|
||||
if (startMatchmakingRequest.m_players.size() > 0)
|
||||
{
|
||||
request.SetPlayers(players);
|
||||
}
|
||||
|
||||
// Optional attributes
|
||||
if (!startMatchmakingRequest.m_ticketId.empty())
|
||||
{
|
||||
request.SetTicketId(startMatchmakingRequest.m_ticketId.c_str());
|
||||
}
|
||||
|
||||
AZ_TracePrintf(AWSGameLiftStartMatchmakingActivityName,
|
||||
"Built StartMatchmakingRequest with TicketId=%s, ConfigurationName=%s and PlayersCount=%d",
|
||||
request.GetTicketId().c_str(),
|
||||
request.GetConfigurationName().c_str(),
|
||||
request.GetPlayers().size());
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
AZStd::string StartMatchmaking(
|
||||
const Aws::GameLift::GameLiftClient& gameliftClient,
|
||||
const AWSGameLiftStartMatchmakingRequest& startMatchmakingRequest)
|
||||
{
|
||||
AZ_TracePrintf(AWSGameLiftStartMatchmakingActivityName, "Requesting StartMatchmaking against Amazon GameLift service ...");
|
||||
|
||||
AZStd::string result = "";
|
||||
Aws::GameLift::Model::StartMatchmakingRequest request = BuildAWSGameLiftStartMatchmakingRequest(startMatchmakingRequest);
|
||||
auto startMatchmakingOutcome = gameliftClient.StartMatchmaking(request);
|
||||
if (startMatchmakingOutcome.IsSuccess())
|
||||
{
|
||||
result = AZStd::string(startMatchmakingOutcome.GetResult().GetMatchmakingTicket().GetTicketId().c_str());
|
||||
|
||||
AZ_TracePrintf(AWSGameLiftStartMatchmakingActivityName, "StartMatchmaking request against Amazon GameLift service is complete");
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Error(AWSGameLiftStartMatchmakingActivityName, false, AWSGameLiftErrorMessageTemplate,
|
||||
startMatchmakingOutcome.GetError().GetExceptionName().c_str(), startMatchmakingOutcome.GetError().GetMessage().c_str());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ValidateStartMatchmakingRequest(const AzFramework::StartMatchmakingRequest& startMatchmakingRequest)
|
||||
{
|
||||
auto gameliftStartMatchmakingRequest = azrtti_cast<const AWSGameLiftStartMatchmakingRequest*>(&startMatchmakingRequest);
|
||||
bool isValid = gameliftStartMatchmakingRequest &&
|
||||
(!gameliftStartMatchmakingRequest->m_configurationName.empty()) &&
|
||||
gameliftStartMatchmakingRequest->m_players.size() > 0;
|
||||
|
||||
if (isValid)
|
||||
{
|
||||
for (const AWSGameLiftPlayerInformation& playerInfo : gameliftStartMatchmakingRequest->m_players)
|
||||
{
|
||||
isValid &= !playerInfo.m_playerId.empty();
|
||||
isValid &= AWSGameLiftActivityUtils::ValidatePlayerAttributes(playerInfo.m_playerAttributes);
|
||||
}
|
||||
}
|
||||
|
||||
AZ_Error(AWSGameLiftStartMatchmakingActivityName, isValid, AWSGameLiftStartMatchmakingRequestInvalidErrorMessage);
|
||||
|
||||
return isValid;
|
||||
}
|
||||
} // namespace StartMatchmakingActivity
|
||||
} // namespace AWSGameLift
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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/AWSGameLiftStartMatchmakingRequest.h>
|
||||
|
||||
#include <aws/core/utils/Outcome.h>
|
||||
#include <aws/gamelift/GameLiftClient.h>
|
||||
#include <aws/gamelift/model/StartMatchmakingRequest.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
namespace StartMatchmakingActivity
|
||||
{
|
||||
static constexpr const char AWSGameLiftStartMatchmakingActivityName[] = "AWSGameLiftStartMatchmakingActivity";
|
||||
static constexpr const char AWSGameLiftStartMatchmakingRequestInvalidErrorMessage[] = "Invalid GameLift StartMatchmaking request.";
|
||||
|
||||
// Build AWS GameLift StartMatchmakingRequest by using AWSGameLiftStartMatchmakingRequest
|
||||
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
|
||||
bool ValidateStartMatchmakingRequest(const AzFramework::StartMatchmakingRequest& startMatchmakingRequest);
|
||||
} // namespace StartMatchmakingActivity
|
||||
} // namespace AWSGameLift
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.StopMatchmaking
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
|
||||
#include <Activity/AWSGameLiftStopMatchmakingActivity.h>
|
||||
#include <AWSGameLiftSessionConstants.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
namespace StopMatchmakingActivity
|
||||
{
|
||||
Aws::GameLift::Model::StopMatchmakingRequest BuildAWSGameLiftStopMatchmakingRequest(
|
||||
const AWSGameLiftStopMatchmakingRequest& stopMatchmakingRequest)
|
||||
{
|
||||
Aws::GameLift::Model::StopMatchmakingRequest request;
|
||||
if (!stopMatchmakingRequest.m_ticketId.empty())
|
||||
{
|
||||
request.SetTicketId(stopMatchmakingRequest.m_ticketId.c_str());
|
||||
}
|
||||
|
||||
AZ_TracePrintf(AWSGameLiftStopMatchmakingActivityName, "Built StopMatchmakingRequest with TicketId=%s", request.GetTicketId().c_str());
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
void StopMatchmaking(const Aws::GameLift::GameLiftClient& gameliftClient,
|
||||
const AWSGameLiftStopMatchmakingRequest& stopMatchmakingRequest)
|
||||
{
|
||||
AZ_TracePrintf(AWSGameLiftStopMatchmakingActivityName, "Requesting StopMatchmaking against Amazon GameLift service ...");
|
||||
|
||||
Aws::GameLift::Model::StopMatchmakingRequest request = BuildAWSGameLiftStopMatchmakingRequest(stopMatchmakingRequest);
|
||||
auto stopMatchmakingOutcome = gameliftClient.StopMatchmaking(request);
|
||||
|
||||
if (stopMatchmakingOutcome.IsSuccess())
|
||||
{
|
||||
AZ_TracePrintf(AWSGameLiftStopMatchmakingActivityName, "StopMatchmaking request against Amazon GameLift service is complete");
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Error(AWSGameLiftStopMatchmakingActivityName, false, AWSGameLiftErrorMessageTemplate,
|
||||
stopMatchmakingOutcome.GetError().GetExceptionName().c_str(), stopMatchmakingOutcome.GetError().GetMessage().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool ValidateStopMatchmakingRequest(const AzFramework::StopMatchmakingRequest& StopMatchmakingRequest)
|
||||
{
|
||||
auto gameliftStopMatchmakingRequest = azrtti_cast<const AWSGameLiftStopMatchmakingRequest*>(&StopMatchmakingRequest);
|
||||
bool isValid = gameliftStopMatchmakingRequest && (!gameliftStopMatchmakingRequest->m_ticketId.empty());
|
||||
|
||||
AZ_Error(AWSGameLiftStopMatchmakingActivityName, isValid, AWSGameLiftStopMatchmakingRequestInvalidErrorMessage);
|
||||
|
||||
return isValid;
|
||||
}
|
||||
} // namespace StopMatchmakingActivity
|
||||
} // namespace AWSGameLift
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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/AWSGameLiftStopMatchmakingRequest.h>
|
||||
|
||||
#include <aws/core/utils/Outcome.h>
|
||||
#include <aws/gamelift/GameLiftClient.h>
|
||||
#include <aws/gamelift/model/StopMatchmakingRequest.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
namespace StopMatchmakingActivity
|
||||
{
|
||||
static constexpr const char AWSGameLiftStopMatchmakingActivityName[] = "AWSGameLiftStopMatchmakingActivity";
|
||||
static constexpr const char AWSGameLiftStopMatchmakingRequestInvalidErrorMessage[] = "Invalid GameLift StopMatchmaking request.";
|
||||
|
||||
// Build AWS GameLift StopMatchmakingRequest by using AWSGameLiftStopMatchmakingRequest
|
||||
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
|
||||
bool ValidateStopMatchmakingRequest(const AzFramework::StopMatchmakingRequest& stopMatchmakingRequest);
|
||||
} // namespace StopMatchmakingActivity
|
||||
} // namespace AWSGameLift
|
||||
@@ -24,6 +24,8 @@
|
||||
#include <Request/AWSGameLiftJoinSessionRequest.h>
|
||||
#include <Request/AWSGameLiftSearchSessionsRequest.h>
|
||||
#include <Request/IAWSGameLiftInternalRequests.h>
|
||||
#include <Request/AWSGameLiftStartMatchmakingRequest.h>
|
||||
#include <Request/AWSGameLiftStopMatchmakingRequest.h>
|
||||
|
||||
using namespace AWSGameLift;
|
||||
|
||||
@@ -223,11 +225,43 @@ protected:
|
||||
return response;
|
||||
}
|
||||
|
||||
AWSGameLiftStartMatchmakingRequest GetValidStartMatchmakingRequest()
|
||||
{
|
||||
AWSGameLiftStartMatchmakingRequest request;
|
||||
request.m_configurationName = "dummyConfiguration";
|
||||
request.m_ticketId = DummyMatchmakingTicketId;
|
||||
|
||||
AWSGameLiftPlayerInformation player;
|
||||
player.m_playerAttributes["dummy"] = "{\"N\": \"1\"}";
|
||||
player.m_playerId = DummyPlayerId;
|
||||
player.m_latencyInMs["us-east-1"] = 10;
|
||||
request.m_players.emplace_back(player);
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
Aws::GameLift::Model::StartMatchmakingOutcome GetValidStartMatchmakingResponse()
|
||||
{
|
||||
Aws::GameLift::Model::MatchmakingTicket ticket;
|
||||
ticket.SetTicketId(DummyMatchmakingTicketId);
|
||||
Aws::GameLift::Model::StartMatchmakingResult result;
|
||||
result.SetMatchmakingTicket(ticket);
|
||||
Aws::GameLift::Model::StartMatchmakingOutcome outcome(result);
|
||||
|
||||
return outcome;
|
||||
}
|
||||
|
||||
static const char* const DummyMatchmakingTicketId;
|
||||
static const char* const DummyPlayerId;
|
||||
|
||||
public:
|
||||
AZStd::unique_ptr<AWSGameLiftClientManager> m_gameliftClientManager;
|
||||
AZStd::shared_ptr<GameLiftClientMock> m_gameliftClientMockPtr;
|
||||
};
|
||||
|
||||
const char* const AWSGameLiftClientManagerTest::DummyMatchmakingTicketId = "dummyTicketId";
|
||||
const char* const AWSGameLiftClientManagerTest::DummyPlayerId = "dummyPlayerId";
|
||||
|
||||
TEST_F(AWSGameLiftClientManagerTest, ConfigureGameLiftClient_CallWithoutRegion_GetFalseAsResult)
|
||||
{
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
@@ -762,3 +796,212 @@ TEST_F(AWSGameLiftClientManagerTest, LeaveSessionAsync_CallWithInterfaceRegister
|
||||
|
||||
m_gameliftClientManager->LeaveSessionAsync();
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftClientManagerTest, StartMatchmaking_CallWithoutClientSetup_GetFalseResponse)
|
||||
{
|
||||
AWSGameLiftStartMatchmakingRequest request = GetValidStartMatchmakingRequest();
|
||||
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
m_gameliftClientManager->ConfigureGameLiftClient("");
|
||||
AZStd::string response = m_gameliftClientManager->StartMatchmaking(request);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(2); // capture 2 error message
|
||||
EXPECT_TRUE(response.empty());
|
||||
|
||||
}
|
||||
TEST_F(AWSGameLiftClientManagerTest, StartMatchmaking_CallWithInvalidRequest_GetErrorWithEmptyResponse)
|
||||
{
|
||||
AWSGameLiftStartMatchmakingRequest request;
|
||||
request.m_configurationName = "dummyConfiguration";
|
||||
AWSGameLiftPlayerInformation player;
|
||||
player.m_playerAttributes["dummy"] = "{\"A\": \"1\"}";
|
||||
request.m_players.emplace_back(player);
|
||||
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
AZStd::string response = m_gameliftClientManager->StartMatchmaking(request);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
|
||||
EXPECT_TRUE(response.empty());
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftClientManagerTest, StartMatchmaking_CallWithValidRequest_GetSuccessOutcome)
|
||||
{
|
||||
AWSGameLiftStartMatchmakingRequest request = GetValidStartMatchmakingRequest();
|
||||
Aws::GameLift::Model::StartMatchmakingOutcome outcome = GetValidStartMatchmakingResponse();
|
||||
|
||||
EXPECT_CALL(*m_gameliftClientMockPtr, StartMatchmaking(::testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(::testing::Return(outcome));
|
||||
|
||||
AZStd::string response = m_gameliftClientManager->StartMatchmaking(request);
|
||||
EXPECT_EQ(response, DummyMatchmakingTicketId);
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftClientManagerTest, StartMatchmaking_CallWithValidRequest_GetErrorOutcome)
|
||||
{
|
||||
AWSGameLiftStartMatchmakingRequest request = GetValidStartMatchmakingRequest();
|
||||
|
||||
Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
|
||||
Aws::GameLift::Model::StartMatchmakingOutcome outcome(error);
|
||||
|
||||
EXPECT_CALL(*m_gameliftClientMockPtr, StartMatchmaking(::testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(::testing::Return(outcome));
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
m_gameliftClientManager->StartMatchmaking(request);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftClientManagerTest, StartMatchmakingAsync_CallWithInvalidRequest_GetNotificationWithErrorOutcome)
|
||||
{
|
||||
AWSGameLiftStartMatchmakingRequest request;
|
||||
request.m_configurationName = "dummyConfiguration";
|
||||
AWSGameLiftPlayerInformation player;
|
||||
player.m_playerAttributes["dummy"] = "{\"A\": \"1\"}";
|
||||
request.m_players.emplace_back(player);
|
||||
|
||||
MatchmakingAsyncRequestNotificationsHandlerMock matchmakingHandlerMock;
|
||||
EXPECT_CALL(matchmakingHandlerMock, OnStartMatchmakingAsyncComplete(AZStd::string{})).Times(1);
|
||||
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
m_gameliftClientManager->StartMatchmakingAsync(request);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftClientManagerTest, StartMatchmakingAsync_CallWithValidRequest_GetNotificationWithSuccessOutcome)
|
||||
{
|
||||
AWSCoreRequestsHandlerMock handlerMock;
|
||||
EXPECT_CALL(handlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
|
||||
|
||||
AWSGameLiftStartMatchmakingRequest request = GetValidStartMatchmakingRequest();
|
||||
Aws::GameLift::Model::StartMatchmakingOutcome outcome = GetValidStartMatchmakingResponse();
|
||||
|
||||
EXPECT_CALL(*m_gameliftClientMockPtr, StartMatchmaking(::testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(::testing::Return(outcome));
|
||||
|
||||
MatchmakingAsyncRequestNotificationsHandlerMock matchmakingHandlerMock;
|
||||
EXPECT_CALL(matchmakingHandlerMock, OnStartMatchmakingAsyncComplete(AZStd::string(DummyMatchmakingTicketId))).Times(1);
|
||||
|
||||
m_gameliftClientManager->StartMatchmakingAsync(request);
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftClientManagerTest, StartMatchmakingAsync_CallWithValidRequest_GetNotificationWithErrorOutcome)
|
||||
{
|
||||
AWSCoreRequestsHandlerMock handlerMock;
|
||||
EXPECT_CALL(handlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
|
||||
|
||||
AWSGameLiftStartMatchmakingRequest request = GetValidStartMatchmakingRequest();
|
||||
|
||||
Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
|
||||
Aws::GameLift::Model::StartMatchmakingOutcome outcome(error);
|
||||
EXPECT_CALL(*m_gameliftClientMockPtr, StartMatchmaking(::testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(::testing::Return(outcome));
|
||||
|
||||
MatchmakingAsyncRequestNotificationsHandlerMock matchmakingHandlerMock;
|
||||
EXPECT_CALL(matchmakingHandlerMock, OnStartMatchmakingAsyncComplete(AZStd::string{})).Times(1);
|
||||
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
m_gameliftClientManager->StartMatchmakingAsync(request);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftClientManagerTest, StopMatchmaking_CallWithoutClientSetup_GetError)
|
||||
{
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
m_gameliftClientManager->ConfigureGameLiftClient("");
|
||||
AWSGameLiftStopMatchmakingRequest request;
|
||||
request.m_ticketId = DummyMatchmakingTicketId;
|
||||
|
||||
m_gameliftClientManager->StopMatchmaking(request);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(2); // capture 2 error message
|
||||
}
|
||||
TEST_F(AWSGameLiftClientManagerTest, StopMatchmaking_CallWithInvalidRequest_GetError)
|
||||
{
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
m_gameliftClientManager->StopMatchmaking(AzFramework::StopMatchmakingRequest());
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftClientManagerTest, StopMatchmaking_CallWithValidRequest_Success)
|
||||
{
|
||||
AWSGameLiftStopMatchmakingRequest request;
|
||||
request.m_ticketId = DummyMatchmakingTicketId;
|
||||
|
||||
Aws::GameLift::Model::StopMatchmakingResult result;
|
||||
Aws::GameLift::Model::StopMatchmakingResult outcome(result);
|
||||
EXPECT_CALL(*m_gameliftClientMockPtr, StopMatchmaking(::testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(::testing::Return(outcome));
|
||||
|
||||
m_gameliftClientManager->StopMatchmaking(request);
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftClientManagerTest, StopMatchmaking_CallWithValidRequest_GetError)
|
||||
{
|
||||
AWSGameLiftStopMatchmakingRequest request;
|
||||
request.m_ticketId = DummyMatchmakingTicketId;
|
||||
|
||||
Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
|
||||
Aws::GameLift::Model::StopMatchmakingOutcome outcome(error);
|
||||
|
||||
EXPECT_CALL(*m_gameliftClientMockPtr, StopMatchmaking(::testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(::testing::Return(outcome));
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
m_gameliftClientManager->StopMatchmaking(request);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftClientManagerTest, StopMatchmakingAsync_CallWithInvalidRequest_GetNotificationWithError)
|
||||
{
|
||||
AWSGameLiftStopMatchmakingRequest request;
|
||||
|
||||
MatchmakingAsyncRequestNotificationsHandlerMock matchmakingHandlerMock;
|
||||
EXPECT_CALL(matchmakingHandlerMock, OnStopMatchmakingAsyncComplete()).Times(1);
|
||||
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
m_gameliftClientManager->StopMatchmakingAsync(request);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftClientManagerTest, StopMatchmakingAsync_CallWithValidRequest_GetNotification)
|
||||
{
|
||||
AWSCoreRequestsHandlerMock handlerMock;
|
||||
EXPECT_CALL(handlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
|
||||
|
||||
AWSGameLiftStopMatchmakingRequest request;
|
||||
request.m_ticketId = DummyMatchmakingTicketId;
|
||||
|
||||
Aws::GameLift::Model::StopMatchmakingResult result;
|
||||
Aws::GameLift::Model::StopMatchmakingOutcome outcome(result);
|
||||
EXPECT_CALL(*m_gameliftClientMockPtr, StopMatchmaking(::testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(::testing::Return(outcome));
|
||||
|
||||
MatchmakingAsyncRequestNotificationsHandlerMock matchmakingHandlerMock;
|
||||
EXPECT_CALL(matchmakingHandlerMock, OnStopMatchmakingAsyncComplete()).Times(1);
|
||||
|
||||
m_gameliftClientManager->StopMatchmakingAsync(request);
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftClientManagerTest, StopMatchmakingAsync_CallWithValidRequest_GetNotificationWithError)
|
||||
{
|
||||
AWSCoreRequestsHandlerMock handlerMock;
|
||||
EXPECT_CALL(handlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
|
||||
|
||||
AWSGameLiftStopMatchmakingRequest request;
|
||||
request.m_ticketId = DummyMatchmakingTicketId;
|
||||
|
||||
Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
|
||||
Aws::GameLift::Model::StopMatchmakingOutcome outcome(error);
|
||||
EXPECT_CALL(*m_gameliftClientMockPtr, StopMatchmaking(::testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(::testing::Return(outcome));
|
||||
|
||||
MatchmakingAsyncRequestNotificationsHandlerMock matchmakingHandlerMock;
|
||||
EXPECT_CALL(matchmakingHandlerMock, OnStopMatchmakingAsyncComplete()).Times(1);
|
||||
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
m_gameliftClientManager->StopMatchmakingAsync(request);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
#include <AzFramework/Session/ISessionRequests.h>
|
||||
#include <AzFramework/Session/ISessionHandlingRequests.h>
|
||||
#include <AzFramework/Matchmaking/MatchmakingNotifications.h>
|
||||
#include <AzTest/AzTest.h>
|
||||
|
||||
#include <aws/core/auth/AWSCredentialsProvider.h>
|
||||
@@ -27,6 +28,12 @@
|
||||
#include <aws/gamelift/model/SearchGameSessionsResult.h>
|
||||
#include <aws/gamelift/model/StartGameSessionPlacementRequest.h>
|
||||
#include <aws/gamelift/model/StartGameSessionPlacementResult.h>
|
||||
#include <aws/gamelift/model/StartMatchmakingRequest.h>
|
||||
#include <aws/gamelift/model/StartMatchmakingResult.h>
|
||||
#include <aws/gamelift/model/StopMatchmakingRequest.h>
|
||||
#include <aws/gamelift/model/StopMatchmakingResult.h>
|
||||
|
||||
#include <Request/IAWSGameLiftMatchmakingInternalRequests.h>
|
||||
|
||||
using namespace Aws::GameLift;
|
||||
|
||||
@@ -44,6 +51,27 @@ public:
|
||||
MOCK_CONST_METHOD1(DescribeMatchmaking, Model::DescribeMatchmakingOutcome(const Model::DescribeMatchmakingRequest&));
|
||||
MOCK_CONST_METHOD1(SearchGameSessions, Model::SearchGameSessionsOutcome(const Model::SearchGameSessionsRequest&));
|
||||
MOCK_CONST_METHOD1(StartGameSessionPlacement, Model::StartGameSessionPlacementOutcome(const Model::StartGameSessionPlacementRequest&));
|
||||
MOCK_CONST_METHOD1(StartMatchmaking, Model::StartMatchmakingOutcome(const Model::StartMatchmakingRequest&));
|
||||
MOCK_CONST_METHOD1(StopMatchmaking, Model::StopMatchmakingOutcome(const Model::StopMatchmakingRequest&));
|
||||
};
|
||||
|
||||
class MatchmakingAsyncRequestNotificationsHandlerMock
|
||||
: public AzFramework::MatchmakingAsyncRequestNotificationBus::Handler
|
||||
{
|
||||
public:
|
||||
MatchmakingAsyncRequestNotificationsHandlerMock()
|
||||
{
|
||||
AzFramework::MatchmakingAsyncRequestNotificationBus::Handler::BusConnect();
|
||||
}
|
||||
|
||||
~MatchmakingAsyncRequestNotificationsHandlerMock()
|
||||
{
|
||||
AzFramework::MatchmakingAsyncRequestNotificationBus::Handler::BusDisconnect();
|
||||
}
|
||||
|
||||
MOCK_METHOD0(OnAcceptMatchAsyncComplete, void());
|
||||
MOCK_METHOD1(OnStartMatchmakingAsyncComplete, void(const AZStd::string&));
|
||||
MOCK_METHOD0(OnStopMatchmakingAsyncComplete, void());
|
||||
};
|
||||
|
||||
class SessionAsyncRequestNotificationsHandlerMock
|
||||
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Activity/AWSGameLiftStartMatchmakingActivity.h>
|
||||
#include <AWSGameLiftClientFixture.h>
|
||||
|
||||
using namespace AWSGameLift;
|
||||
|
||||
using AWSGameLiftStartMatchmakingActivityTest = AWSGameLiftClientFixture;
|
||||
|
||||
TEST_F(AWSGameLiftStartMatchmakingActivityTest, BuildAWSGameLiftStartMatchmakingRequest_Call_GetExpectedResult)
|
||||
{
|
||||
AWSGameLiftStartMatchmakingRequest request;
|
||||
request.m_configurationName = "dummyConfiguration";
|
||||
request.m_ticketId = "dummyTicketId";
|
||||
|
||||
AWSGameLiftPlayerInformation player;
|
||||
player.m_playerAttributes["dummy"] = "{\"S\": \"test\"}";
|
||||
player.m_playerId = "dummyPlayerId";
|
||||
player.m_team = "dummyTeam";
|
||||
player.m_latencyInMs["us-east-1"] = 10;
|
||||
request.m_players.emplace_back(player);
|
||||
auto awsRequest = StartMatchmakingActivity::BuildAWSGameLiftStartMatchmakingRequest(request);
|
||||
|
||||
EXPECT_TRUE(strcmp(awsRequest.GetConfigurationName().c_str(), request.m_configurationName.c_str()) == 0);
|
||||
EXPECT_TRUE(strcmp(awsRequest.GetTicketId().c_str(), request.m_ticketId.c_str()) == 0);
|
||||
|
||||
EXPECT_TRUE(awsRequest.GetPlayers().size() == request.m_players.size());
|
||||
EXPECT_TRUE(strcmp(awsRequest.GetPlayers()[0].GetPlayerId().c_str(), request.m_players[0].m_playerId.c_str()) == 0);
|
||||
EXPECT_TRUE(strcmp(awsRequest.GetPlayers()[0].GetTeam().c_str(), request.m_players[0].m_team.c_str()) == 0);
|
||||
|
||||
EXPECT_TRUE(awsRequest.GetPlayers()[0].GetLatencyInMs().size() == request.m_players[0].m_latencyInMs.size());
|
||||
EXPECT_TRUE(strcmp(awsRequest.GetPlayers()[0].GetLatencyInMs().begin()->first.c_str(), request.m_players[0].m_latencyInMs.begin()->first.c_str()) == 0);
|
||||
EXPECT_TRUE(awsRequest.GetPlayers()[0].GetLatencyInMs().begin()->second == request.m_players[0].m_latencyInMs.begin()->second);
|
||||
|
||||
EXPECT_TRUE(awsRequest.GetPlayers()[0].GetPlayerAttributes().size() == request.m_players[0].m_playerAttributes.size());
|
||||
EXPECT_TRUE(strcmp(awsRequest.GetPlayers()[0].GetPlayerAttributes().begin()->first.c_str(), request.m_players[0].m_playerAttributes.begin()->first.c_str()) == 0);
|
||||
EXPECT_TRUE(strcmp(awsRequest.GetPlayers()[0].GetPlayerAttributes().begin()->second.GetS().c_str(), "test") == 0);
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftStartMatchmakingActivityTest, ValidateStartMatchmakingRequest_CallWithBaseType_GetFalseResult)
|
||||
{
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
auto result = StartMatchmakingActivity::ValidateStartMatchmakingRequest(AzFramework::StartMatchmakingRequest());
|
||||
EXPECT_FALSE(result);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftStartMatchmakingActivityTest, ValidateStartMatchmakingRequest_CallWithoutConfigurationName_GetFalseResult)
|
||||
{
|
||||
AWSGameLiftStartMatchmakingRequest request;
|
||||
request.m_ticketId = "dummyTicketId";
|
||||
|
||||
AWSGameLiftPlayerInformation player;
|
||||
player.m_playerAttributes["dummy"] = "{\"S\": \"test\"}";
|
||||
player.m_playerId = "dummyPlayerId";
|
||||
player.m_team = "dummyTeam";
|
||||
player.m_latencyInMs["us-east-1"] = 10;
|
||||
request.m_players.emplace_back(player);
|
||||
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
auto result = StartMatchmakingActivity::ValidateStartMatchmakingRequest(request);
|
||||
EXPECT_FALSE(result);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftStartMatchmakingActivityTest, ValidateStartMatchmakingRequest_CallWithoutPlayers_GetFalseResult)
|
||||
{
|
||||
AWSGameLiftStartMatchmakingRequest request;
|
||||
request.m_configurationName = "dummyConfiguration";
|
||||
request.m_ticketId = "dummyTicketId";
|
||||
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
auto result = StartMatchmakingActivity::ValidateStartMatchmakingRequest(request);
|
||||
EXPECT_FALSE(result);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftStartMatchmakingActivityTest, ValidateStartMatchmakingRequest_CallWithoutPlayerId_GetFalseResult)
|
||||
{
|
||||
AWSGameLiftStartMatchmakingRequest request;
|
||||
request.m_configurationName = "dummyConfiguration";
|
||||
request.m_ticketId = "dummyTicketId";
|
||||
|
||||
AWSGameLiftPlayerInformation player;
|
||||
player.m_playerAttributes["dummy"] = "{\"S\": \"test\"}";
|
||||
player.m_team = "dummyTeam";
|
||||
player.m_latencyInMs["us-east-1"] = 10;
|
||||
request.m_players.emplace_back(player);
|
||||
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
auto result = StartMatchmakingActivity::ValidateStartMatchmakingRequest(request);
|
||||
EXPECT_FALSE(result);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftStartMatchmakingActivityTest, ValidateStartMatchmakingRequest_CallWithInvalidPlayerAttribute_GetFalseResult)
|
||||
{
|
||||
AWSGameLiftStartMatchmakingRequest request;
|
||||
request.m_configurationName = "dummyConfiguration";
|
||||
request.m_ticketId = "dummyTicketId";
|
||||
|
||||
AWSGameLiftPlayerInformation player;
|
||||
player.m_playerAttributes["dummy"] = "{\"A\": \"test\"}";
|
||||
player.m_playerId = "dummyPlayerId";
|
||||
player.m_team = "dummyTeam";
|
||||
player.m_latencyInMs["us-east-1"] = 10;
|
||||
request.m_players.emplace_back(player);
|
||||
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
auto result = StartMatchmakingActivity::ValidateStartMatchmakingRequest(request);
|
||||
EXPECT_FALSE(result);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftStartMatchmakingActivityTest, ValidateStartMatchmakingRequest_CallWithoutTicketId_GetTrueResult)
|
||||
{
|
||||
AWSGameLiftStartMatchmakingRequest request;
|
||||
request.m_configurationName = "dummyConfiguration";
|
||||
|
||||
AWSGameLiftPlayerInformation player;
|
||||
player.m_playerAttributes["dummy"] = "{\"S\": \"test\"}";
|
||||
player.m_playerId = "dummyPlayerId";
|
||||
player.m_team = "dummyTeam";
|
||||
player.m_latencyInMs["us-east-1"] = 10;
|
||||
request.m_players.emplace_back(player);
|
||||
|
||||
auto result = StartMatchmakingActivity::ValidateStartMatchmakingRequest(request);
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftStartMatchmakingActivityTest, ValidateStartMatchmakingRequest_CallWithValidParameters_GetTrueResult)
|
||||
{
|
||||
AWSGameLiftStartMatchmakingRequest request;
|
||||
request.m_ticketId = "dummyTicketId";
|
||||
request.m_configurationName = "dummyConfiguration";
|
||||
|
||||
AWSGameLiftPlayerInformation player;
|
||||
player.m_playerAttributes["dummy"] = "{\"S\": \"test\"}";
|
||||
player.m_playerId = "dummyPlayerId";
|
||||
player.m_team = "dummyTeam";
|
||||
player.m_latencyInMs["us-east-1"] = 10;
|
||||
request.m_players.emplace_back(player);
|
||||
|
||||
auto result = StartMatchmakingActivity::ValidateStartMatchmakingRequest(request);
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Activity/AWSGameLiftStopMatchmakingActivity.h>
|
||||
#include <AWSGameLiftClientFixture.h>
|
||||
|
||||
using namespace AWSGameLift;
|
||||
|
||||
using AWSGameLiftStopMatchmakingActivityTest = AWSGameLiftClientFixture;
|
||||
|
||||
TEST_F(AWSGameLiftStopMatchmakingActivityTest, BuildAWSGameLiftStopMatchmakingRequest_Call_GetExpectedResult)
|
||||
{
|
||||
AWSGameLiftStopMatchmakingRequest request;
|
||||
request.m_ticketId = "dummyTicketId";
|
||||
auto awsRequest = StopMatchmakingActivity::BuildAWSGameLiftStopMatchmakingRequest(request);
|
||||
EXPECT_TRUE(strcmp(awsRequest.GetTicketId().c_str(), request.m_ticketId.c_str()) == 0);
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftStopMatchmakingActivityTest, ValidateStopMatchmakingRequest_CallWithoutTicketId_GetFalseResult)
|
||||
{
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
auto result = StopMatchmakingActivity::ValidateStopMatchmakingRequest(AzFramework::StopMatchmakingRequest());
|
||||
EXPECT_FALSE(result);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
|
||||
}
|
||||
|
||||
TEST_F(AWSGameLiftStopMatchmakingActivityTest, ValidateStopMatchmakingRequest_CallWithTicketId_GetTrueResult)
|
||||
{
|
||||
AWSGameLiftStopMatchmakingRequest request;
|
||||
request.m_ticketId = "dummyTicketId";
|
||||
auto result = StopMatchmakingActivity::ValidateStopMatchmakingRequest(request);
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
@@ -30,6 +30,10 @@ set(FILES
|
||||
Source/Activity/AWSGameLiftSearchSessionsActivity.h
|
||||
Source/AWSGameLiftClientLocalTicketTracker.cpp
|
||||
Source/AWSGameLiftClientLocalTicketTracker.h
|
||||
Source/Activity/AWSGameLiftStartMatchmakingActivity.cpp
|
||||
Source/Activity/AWSGameLiftStartMatchmakingActivity.h
|
||||
Source/Activity/AWSGameLiftStopMatchmakingActivity.cpp
|
||||
Source/Activity/AWSGameLiftStopMatchmakingActivity.h
|
||||
Source/AWSGameLiftClientManager.cpp
|
||||
Source/AWSGameLiftClientManager.h
|
||||
Source/AWSGameLiftClientSystemComponent.cpp
|
||||
|
||||
@@ -11,6 +11,8 @@ set(FILES
|
||||
Tests/Activity/AWSGameLiftCreateSessionOnQueueActivityTest.cpp
|
||||
Tests/Activity/AWSGameLiftJoinSessionActivityTest.cpp
|
||||
Tests/Activity/AWSGameLiftSearchSessionsActivityTest.cpp
|
||||
Tests/Activity/AWSGameLiftStartMatchmakingActivityTest.cpp
|
||||
Tests/Activity/AWSGameLiftStopMatchmakingActivityTest.cpp
|
||||
Tests/AWSGameLiftClientFixture.h
|
||||
Tests/AWSGameLiftClientLocalTicketTrackerTest.cpp
|
||||
Tests/AWSGameLiftClientManagerTest.cpp
|
||||
|
||||
Reference in New Issue
Block a user