Merge 'gameliftfeature' branch into 'development' branch (#1534)
This commit is contained in:
@@ -0,0 +1,360 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Console/IConsole.h>
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
#include <AzCore/Jobs/JobFunction.h>
|
||||
#include <AzCore/std/smart_ptr/make_shared.h>
|
||||
#include <AzFramework/Session/SessionConfig.h>
|
||||
|
||||
#include <AWSCoreBus.h>
|
||||
#include <Credential/AWSCredentialBus.h>
|
||||
#include <ResourceMapping/AWSResourceMappingBus.h>
|
||||
|
||||
#include <AWSGameLiftClientManager.h>
|
||||
#include <Activity/AWSGameLiftCreateSessionActivity.h>
|
||||
#include <Activity/AWSGameLiftCreateSessionOnQueueActivity.h>
|
||||
#include <Activity/AWSGameLiftJoinSessionActivity.h>
|
||||
#include <Activity/AWSGameLiftLeaveSessionActivity.h>
|
||||
#include <Activity/AWSGameLiftSearchSessionsActivity.h>
|
||||
|
||||
#include <aws/core/auth/AWSCredentialsProvider.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
#if defined(AWSGAMELIFT_DEV)
|
||||
AZ_CVAR(AZ::CVarFixedString, cl_gameliftLocalEndpoint, "", nullptr, AZ::ConsoleFunctorFlags::Null, "The local endpoint to test with GameLiftLocal SDK.");
|
||||
#endif
|
||||
|
||||
AWSGameLiftClientManager::AWSGameLiftClientManager()
|
||||
{
|
||||
m_gameliftClient.reset();
|
||||
}
|
||||
|
||||
void AWSGameLiftClientManager::ActivateManager()
|
||||
{
|
||||
AZ::Interface<IAWSGameLiftRequests>::Register(this);
|
||||
AWSGameLiftRequestBus::Handler::BusConnect();
|
||||
|
||||
AZ::Interface<AzFramework::ISessionAsyncRequests>::Register(this);
|
||||
AWSGameLiftSessionAsyncRequestBus::Handler::BusConnect();
|
||||
|
||||
AZ::Interface<AzFramework::ISessionRequests>::Register(this);
|
||||
AWSGameLiftSessionRequestBus::Handler::BusConnect();
|
||||
}
|
||||
|
||||
void AWSGameLiftClientManager::DeactivateManager()
|
||||
{
|
||||
AWSGameLiftSessionRequestBus::Handler::BusDisconnect();
|
||||
AZ::Interface<AzFramework::ISessionRequests>::Unregister(this);
|
||||
|
||||
AWSGameLiftSessionAsyncRequestBus::Handler::BusDisconnect();
|
||||
AZ::Interface<AzFramework::ISessionAsyncRequests>::Unregister(this);
|
||||
|
||||
AWSGameLiftRequestBus::Handler::BusDisconnect();
|
||||
AZ::Interface<IAWSGameLiftRequests>::Unregister(this);
|
||||
}
|
||||
|
||||
bool AWSGameLiftClientManager::ConfigureGameLiftClient(const AZStd::string& region)
|
||||
{
|
||||
m_gameliftClient.reset();
|
||||
|
||||
Aws::Client::ClientConfiguration clientConfig;
|
||||
// Set up client endpoint or region
|
||||
AZStd::string localEndpoint = "";
|
||||
#if defined(AWSGAMELIFT_DEV)
|
||||
localEndpoint = static_cast<AZ::CVarFixedString>(cl_gameliftLocalEndpoint);
|
||||
#endif
|
||||
if (!localEndpoint.empty())
|
||||
{
|
||||
// The attribute needs to override to interact with GameLiftLocal
|
||||
clientConfig.endpointOverride = localEndpoint.c_str();
|
||||
}
|
||||
else if (!region.empty())
|
||||
{
|
||||
clientConfig.region = region.c_str();
|
||||
}
|
||||
else
|
||||
{
|
||||
AZStd::string clientRegion;
|
||||
AWSCore::AWSResourceMappingRequestBus::BroadcastResult(clientRegion, &AWSCore::AWSResourceMappingRequests::GetDefaultRegion);
|
||||
if (clientRegion.empty())
|
||||
{
|
||||
AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftClientRegionMissingErrorMessage);
|
||||
return false;
|
||||
}
|
||||
clientConfig.region = clientRegion.c_str();
|
||||
}
|
||||
|
||||
// Fetch AWS credential for client
|
||||
AWSCore::AWSCredentialResult credentialResult;
|
||||
AWSCore::AWSCredentialRequestBus::BroadcastResult(credentialResult, &AWSCore::AWSCredentialRequests::GetCredentialsProvider);
|
||||
if (!localEndpoint.empty())
|
||||
{
|
||||
credentialResult.result = std::make_shared<Aws::Auth::AnonymousAWSCredentialsProvider>();
|
||||
}
|
||||
else if (!credentialResult.result)
|
||||
{
|
||||
AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftClientCredentialMissingErrorMessage);
|
||||
return false;
|
||||
}
|
||||
m_gameliftClient = AZStd::make_shared<Aws::GameLift::GameLiftClient>(credentialResult.result, clientConfig);
|
||||
return true;
|
||||
}
|
||||
|
||||
AZStd::string AWSGameLiftClientManager::CreatePlayerId(bool includeBrackets, bool includeDashes)
|
||||
{
|
||||
return AZ::Uuid::CreateRandom().ToString<AZStd::string>(includeBrackets, includeDashes);
|
||||
}
|
||||
|
||||
AZStd::string AWSGameLiftClientManager::CreateSession(const AzFramework::CreateSessionRequest& createSessionRequest)
|
||||
{
|
||||
AZStd::string result = "";
|
||||
if (CreateSessionActivity::ValidateCreateSessionRequest(createSessionRequest))
|
||||
{
|
||||
const AWSGameLiftCreateSessionRequest& gameliftCreateSessionRequest =
|
||||
static_cast<const AWSGameLiftCreateSessionRequest&>(createSessionRequest);
|
||||
result = CreateSessionHelper(gameliftCreateSessionRequest);
|
||||
}
|
||||
else if (CreateSessionOnQueueActivity::ValidateCreateSessionOnQueueRequest(createSessionRequest))
|
||||
{
|
||||
const AWSGameLiftCreateSessionOnQueueRequest& gameliftCreateSessionOnQueueRequest =
|
||||
static_cast<const AWSGameLiftCreateSessionOnQueueRequest&>(createSessionRequest);
|
||||
result = CreateSessionOnQueueHelper(gameliftCreateSessionOnQueueRequest);
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftCreateSessionRequestInvalidErrorMessage);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void AWSGameLiftClientManager::CreateSessionAsync(const AzFramework::CreateSessionRequest& createSessionRequest)
|
||||
{
|
||||
if (CreateSessionActivity::ValidateCreateSessionRequest(createSessionRequest))
|
||||
{
|
||||
const AWSGameLiftCreateSessionRequest& gameliftCreateSessionRequest =
|
||||
static_cast<const AWSGameLiftCreateSessionRequest&>(createSessionRequest);
|
||||
|
||||
AZ::JobContext* jobContext = nullptr;
|
||||
AWSCore::AWSCoreRequestBus::BroadcastResult(jobContext, &AWSCore::AWSCoreRequests::GetDefaultJobContext);
|
||||
AZ::Job* createSessionJob = AZ::CreateJobFunction(
|
||||
[this, gameliftCreateSessionRequest]()
|
||||
{
|
||||
AZStd::string result = CreateSessionHelper(gameliftCreateSessionRequest);
|
||||
|
||||
AzFramework::SessionAsyncRequestNotificationBus::Broadcast(
|
||||
&AzFramework::SessionAsyncRequestNotifications::OnCreateSessionAsyncComplete, result);
|
||||
},
|
||||
true, jobContext);
|
||||
createSessionJob->Start();
|
||||
}
|
||||
else if (CreateSessionOnQueueActivity::ValidateCreateSessionOnQueueRequest(createSessionRequest))
|
||||
{
|
||||
const AWSGameLiftCreateSessionOnQueueRequest& gameliftCreateSessionOnQueueRequest =
|
||||
static_cast<const AWSGameLiftCreateSessionOnQueueRequest&>(createSessionRequest);
|
||||
|
||||
AZ::JobContext* jobContext = nullptr;
|
||||
AWSCore::AWSCoreRequestBus::BroadcastResult(jobContext, &AWSCore::AWSCoreRequests::GetDefaultJobContext);
|
||||
AZ::Job* createSessionOnQueueJob = AZ::CreateJobFunction(
|
||||
[this, gameliftCreateSessionOnQueueRequest]()
|
||||
{
|
||||
AZStd::string result = CreateSessionOnQueueHelper(gameliftCreateSessionOnQueueRequest);
|
||||
|
||||
AzFramework::SessionAsyncRequestNotificationBus::Broadcast(
|
||||
&AzFramework::SessionAsyncRequestNotifications::OnCreateSessionAsyncComplete, result);
|
||||
},
|
||||
true, jobContext);
|
||||
createSessionOnQueueJob->Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftCreateSessionRequestInvalidErrorMessage);
|
||||
AzFramework::SessionAsyncRequestNotificationBus::Broadcast(
|
||||
&AzFramework::SessionAsyncRequestNotifications::OnCreateSessionAsyncComplete, "");
|
||||
}
|
||||
}
|
||||
|
||||
AZStd::string AWSGameLiftClientManager::CreateSessionHelper(
|
||||
const AWSGameLiftCreateSessionRequest& createSessionRequest)
|
||||
{
|
||||
AZStd::shared_ptr<Aws::GameLift::GameLiftClient> gameLiftClient = m_gameliftClient;
|
||||
AZStd::string result = "";
|
||||
if (!gameLiftClient)
|
||||
{
|
||||
AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftClientMissingErrorMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = CreateSessionActivity::CreateSession(*gameLiftClient, createSessionRequest);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
AZStd::string AWSGameLiftClientManager::CreateSessionOnQueueHelper(
|
||||
const AWSGameLiftCreateSessionOnQueueRequest& createSessionOnQueueRequest)
|
||||
{
|
||||
AZStd::shared_ptr<Aws::GameLift::GameLiftClient> gameliftClient = m_gameliftClient;
|
||||
AZStd::string result;
|
||||
if (!gameliftClient)
|
||||
{
|
||||
AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftClientMissingErrorMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = CreateSessionOnQueueActivity::CreateSessionOnQueue(*gameliftClient, createSessionOnQueueRequest);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool AWSGameLiftClientManager::JoinSession(const AzFramework::JoinSessionRequest& joinSessionRequest)
|
||||
{
|
||||
bool result = false;
|
||||
if (JoinSessionActivity::ValidateJoinSessionRequest(joinSessionRequest))
|
||||
{
|
||||
const AWSGameLiftJoinSessionRequest& gameliftJoinSessionRequest =
|
||||
static_cast<const AWSGameLiftJoinSessionRequest&>(joinSessionRequest);
|
||||
result = JoinSessionHelper(gameliftJoinSessionRequest);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void AWSGameLiftClientManager::JoinSessionAsync(const AzFramework::JoinSessionRequest& joinSessionRequest)
|
||||
{
|
||||
if (!JoinSessionActivity::ValidateJoinSessionRequest(joinSessionRequest))
|
||||
{
|
||||
AzFramework::SessionAsyncRequestNotificationBus::Broadcast(
|
||||
&AzFramework::SessionAsyncRequestNotifications::OnJoinSessionAsyncComplete, false);
|
||||
return;
|
||||
}
|
||||
|
||||
const AWSGameLiftJoinSessionRequest& gameliftJoinSessionRequest =
|
||||
static_cast<const AWSGameLiftJoinSessionRequest&>(joinSessionRequest);
|
||||
|
||||
AZ::JobContext* jobContext = nullptr;
|
||||
AWSCore::AWSCoreRequestBus::BroadcastResult(jobContext, &AWSCore::AWSCoreRequests::GetDefaultJobContext);
|
||||
AZ::Job* joinSessionJob = AZ::CreateJobFunction(
|
||||
[this, gameliftJoinSessionRequest]()
|
||||
{
|
||||
bool result = JoinSessionHelper(gameliftJoinSessionRequest);
|
||||
|
||||
AzFramework::SessionAsyncRequestNotificationBus::Broadcast(
|
||||
&AzFramework::SessionAsyncRequestNotifications::OnJoinSessionAsyncComplete, result);
|
||||
},
|
||||
true, jobContext);
|
||||
|
||||
joinSessionJob->Start();
|
||||
}
|
||||
|
||||
bool AWSGameLiftClientManager::JoinSessionHelper(const AWSGameLiftJoinSessionRequest& joinSessionRequest)
|
||||
{
|
||||
AZStd::shared_ptr<Aws::GameLift::GameLiftClient> gameliftClient = m_gameliftClient;
|
||||
bool result = false;
|
||||
if (!gameliftClient)
|
||||
{
|
||||
AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftClientMissingErrorMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto createPlayerSessionOutcome = JoinSessionActivity::CreatePlayerSession(*gameliftClient, joinSessionRequest);
|
||||
|
||||
result = JoinSessionActivity::RequestPlayerJoinSession(createPlayerSessionOutcome);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void AWSGameLiftClientManager::LeaveSession()
|
||||
{
|
||||
AWSGameLift::LeaveSessionActivity::LeaveSession();
|
||||
}
|
||||
|
||||
void AWSGameLiftClientManager::LeaveSessionAsync()
|
||||
{
|
||||
AZ::JobContext* jobContext = nullptr;
|
||||
AWSCore::AWSCoreRequestBus::BroadcastResult(jobContext, &AWSCore::AWSCoreRequests::GetDefaultJobContext);
|
||||
AZ::Job* leaveSessionJob = AZ::CreateJobFunction(
|
||||
[this]()
|
||||
{
|
||||
LeaveSession();
|
||||
AzFramework::SessionAsyncRequestNotificationBus::Broadcast(
|
||||
&AzFramework::SessionAsyncRequestNotifications::OnLeaveSessionAsyncComplete);
|
||||
},
|
||||
true, jobContext);
|
||||
|
||||
leaveSessionJob->Start();
|
||||
}
|
||||
|
||||
AzFramework::SearchSessionsResponse AWSGameLiftClientManager::SearchSessions(
|
||||
const AzFramework::SearchSessionsRequest& searchSessionsRequest) const
|
||||
{
|
||||
AzFramework::SearchSessionsResponse response;
|
||||
if (SearchSessionsActivity::ValidateSearchSessionsRequest(searchSessionsRequest))
|
||||
{
|
||||
const AWSGameLiftSearchSessionsRequest& gameliftSearchSessionsRequest =
|
||||
static_cast<const AWSGameLiftSearchSessionsRequest&>(searchSessionsRequest);
|
||||
response = SearchSessionsHelper(gameliftSearchSessionsRequest);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
void AWSGameLiftClientManager::SearchSessionsAsync(const AzFramework::SearchSessionsRequest& searchSessionsRequest) const
|
||||
{
|
||||
if (!SearchSessionsActivity::ValidateSearchSessionsRequest(searchSessionsRequest))
|
||||
{
|
||||
AzFramework::SessionAsyncRequestNotificationBus::Broadcast(
|
||||
&AzFramework::SessionAsyncRequestNotifications::OnSearchSessionsAsyncComplete, AzFramework::SearchSessionsResponse());
|
||||
return;
|
||||
}
|
||||
|
||||
const AWSGameLiftSearchSessionsRequest& gameliftSearchSessionsRequest =
|
||||
static_cast<const AWSGameLiftSearchSessionsRequest&>(searchSessionsRequest);
|
||||
|
||||
AZ::JobContext* jobContext = nullptr;
|
||||
AWSCore::AWSCoreRequestBus::BroadcastResult(jobContext, &AWSCore::AWSCoreRequests::GetDefaultJobContext);
|
||||
AZ::Job* searchSessionsJob = AZ::CreateJobFunction(
|
||||
[this, gameliftSearchSessionsRequest]()
|
||||
{
|
||||
AzFramework::SearchSessionsResponse response = SearchSessionsHelper(gameliftSearchSessionsRequest);
|
||||
|
||||
AzFramework::SessionAsyncRequestNotificationBus::Broadcast(
|
||||
&AzFramework::SessionAsyncRequestNotifications::OnSearchSessionsAsyncComplete, response);
|
||||
},
|
||||
true, jobContext);
|
||||
|
||||
searchSessionsJob->Start();
|
||||
}
|
||||
|
||||
AzFramework::SearchSessionsResponse AWSGameLiftClientManager::SearchSessionsHelper(
|
||||
const AWSGameLiftSearchSessionsRequest& searchSessionsRequest) const
|
||||
{
|
||||
AZStd::shared_ptr<Aws::GameLift::GameLiftClient> gameliftClient = m_gameliftClient;
|
||||
|
||||
AzFramework::SearchSessionsResponse response;
|
||||
if (!gameliftClient)
|
||||
{
|
||||
AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftClientMissingErrorMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = SearchSessionsActivity::SearchSessions(*gameliftClient, searchSessionsRequest);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
void AWSGameLiftClientManager::SetGameLiftClient(AZStd::shared_ptr<Aws::GameLift::GameLiftClient> gameliftClient)
|
||||
{
|
||||
m_gameliftClient.swap(gameliftClient);
|
||||
}
|
||||
} // namespace AWSGameLift
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/std/smart_ptr/shared_ptr.h>
|
||||
#include <Request/IAWSGameLiftRequests.h>
|
||||
|
||||
namespace Aws
|
||||
{
|
||||
namespace GameLift
|
||||
{
|
||||
class GameLiftClient;
|
||||
}
|
||||
}
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
struct AWSGameLiftCreateSessionRequest;
|
||||
struct AWSGameLiftCreateSessionOnQueueRequest;
|
||||
struct AWSGameLiftJoinSessionRequest;
|
||||
struct AWSGameLiftSearchSessionsRequest;
|
||||
|
||||
// SessionAsyncRequestNotificationBus EBus handler for scripting
|
||||
class AWSGameLiftSessionAsyncRequestNotificationBusHandler
|
||||
: public AzFramework::SessionAsyncRequestNotificationBus::Handler
|
||||
, public AZ::BehaviorEBusHandler
|
||||
{
|
||||
public:
|
||||
AZ_EBUS_BEHAVIOR_BINDER(
|
||||
AWSGameLiftSessionAsyncRequestNotificationBusHandler,
|
||||
"{6E13FC73-53DC-4B6B-AEA7-9038DE4C9635}",
|
||||
AZ::SystemAllocator,
|
||||
OnCreateSessionAsyncComplete,
|
||||
OnSearchSessionsAsyncComplete,
|
||||
OnJoinSessionAsyncComplete,
|
||||
OnLeaveSessionAsyncComplete);
|
||||
|
||||
void OnCreateSessionAsyncComplete(const AZStd::string& createSessionReponse) override
|
||||
{
|
||||
Call(FN_OnCreateSessionAsyncComplete, createSessionReponse);
|
||||
}
|
||||
|
||||
void OnSearchSessionsAsyncComplete(const AzFramework::SearchSessionsResponse& searchSessionsResponse) override
|
||||
{
|
||||
Call(FN_OnSearchSessionsAsyncComplete, searchSessionsResponse);
|
||||
}
|
||||
|
||||
void OnJoinSessionAsyncComplete(bool joinSessionsResponse) override
|
||||
{
|
||||
Call(FN_OnJoinSessionAsyncComplete, joinSessionsResponse);
|
||||
}
|
||||
|
||||
void OnLeaveSessionAsyncComplete() override
|
||||
{
|
||||
Call(FN_OnLeaveSessionAsyncComplete);
|
||||
}
|
||||
};
|
||||
|
||||
//! AWSGameLiftClientManager
|
||||
//! GameLift client manager to support game and player session related client requests
|
||||
class AWSGameLiftClientManager
|
||||
: public AWSGameLiftRequestBus::Handler
|
||||
, public AWSGameLiftSessionAsyncRequestBus::Handler
|
||||
, public AWSGameLiftSessionRequestBus::Handler
|
||||
{
|
||||
public:
|
||||
static constexpr const char AWSGameLiftClientManagerName[] = "AWSGameLiftClientManager";
|
||||
static constexpr const char AWSGameLiftClientRegionMissingErrorMessage[] =
|
||||
"Missing AWS region for GameLift client.";
|
||||
static constexpr const char AWSGameLiftClientCredentialMissingErrorMessage[] =
|
||||
"Missing AWS credential for GameLift client.";
|
||||
static constexpr const char AWSGameLiftClientMissingErrorMessage[] =
|
||||
"GameLift client is not configured yet.";
|
||||
|
||||
static constexpr const char AWSGameLiftCreateSessionRequestInvalidErrorMessage[] =
|
||||
"Invalid GameLift CreateSession or CreateSessionOnQueue request.";
|
||||
|
||||
AWSGameLiftClientManager();
|
||||
virtual ~AWSGameLiftClientManager() = default;
|
||||
|
||||
virtual void ActivateManager();
|
||||
virtual void DeactivateManager();
|
||||
|
||||
// AWSGameLiftRequestBus interface implementation
|
||||
bool ConfigureGameLiftClient(const AZStd::string& region) override;
|
||||
AZStd::string CreatePlayerId(bool includeBrackets, bool includeDashes) override;
|
||||
|
||||
// AWSGameLiftSessionAsyncRequestBus interface implementation
|
||||
void CreateSessionAsync(const AzFramework::CreateSessionRequest& createSessionRequest) override;
|
||||
void JoinSessionAsync(const AzFramework::JoinSessionRequest& joinSessionRequest) override;
|
||||
void SearchSessionsAsync(const AzFramework::SearchSessionsRequest& searchSessionsRequest) const override;
|
||||
void LeaveSessionAsync() override;
|
||||
|
||||
// AWSGameLiftSessionRequestBus interface implementation
|
||||
AZStd::string CreateSession(const AzFramework::CreateSessionRequest& createSessionRequest) override;
|
||||
bool JoinSession(const AzFramework::JoinSessionRequest& joinSessionRequest) override;
|
||||
AzFramework::SearchSessionsResponse SearchSessions(const AzFramework::SearchSessionsRequest& searchSessionsRequest) const override;
|
||||
void LeaveSession() override;
|
||||
|
||||
protected:
|
||||
// Use for automation tests only to inject mock objects.
|
||||
void SetGameLiftClient(AZStd::shared_ptr<Aws::GameLift::GameLiftClient> gameliftClient);
|
||||
|
||||
private:
|
||||
AZStd::string CreateSessionHelper(const AWSGameLiftCreateSessionRequest& createSessionRequest);
|
||||
AZStd::string CreateSessionOnQueueHelper(const AWSGameLiftCreateSessionOnQueueRequest& createSessionOnQueueRequest);
|
||||
bool JoinSessionHelper(const AWSGameLiftJoinSessionRequest& joinSessionRequest);
|
||||
AzFramework::SearchSessionsResponse SearchSessionsHelper(const AWSGameLiftSearchSessionsRequest& searchSessionsRequest) const;
|
||||
|
||||
AZStd::shared_ptr<Aws::GameLift::GameLiftClient> m_gameliftClient;
|
||||
};
|
||||
} // namespace AWSGameLift
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Memory/SystemAllocator.h>
|
||||
#include <AzCore/Module/Module.h>
|
||||
|
||||
#include <AWSGameLiftClientSystemComponent.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
//! Provide the entry point for the gem and register the system component.
|
||||
class AWSGameLiftClientModule
|
||||
: public AZ::Module
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(AWSGameLiftClientModule, "{7b920f3e-2b23-482e-a1b6-16bd278d126c}", AZ::Module);
|
||||
AZ_CLASS_ALLOCATOR(AWSGameLiftClientModule, AZ::SystemAllocator, 0);
|
||||
|
||||
AWSGameLiftClientModule()
|
||||
: AZ::Module()
|
||||
{
|
||||
// Push results of [MyComponent]::CreateDescriptor() into m_descriptors here.
|
||||
m_descriptors.insert(m_descriptors.end(), {
|
||||
AWSGameLiftClientSystemComponent::CreateDescriptor(),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add required SystemComponents to the SystemEntity.
|
||||
*/
|
||||
AZ::ComponentTypeList GetRequiredSystemComponents() const override
|
||||
{
|
||||
return AZ::ComponentTypeList {
|
||||
azrtti_typeid<AWSGameLiftClientSystemComponent>(),
|
||||
};
|
||||
}
|
||||
};
|
||||
}// namespace AWSGameLift
|
||||
|
||||
AZ_DECLARE_MODULE_CLASS(Gem_AWSGameLift_Client, AWSGameLift::AWSGameLiftClientModule)
|
||||
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzCore/Serialization/EditContextConstants.inl>
|
||||
#include <AzFramework/Session/SessionConfig.h>
|
||||
|
||||
#include <AWSGameLiftClientManager.h>
|
||||
#include <AWSGameLiftClientSystemComponent.h>
|
||||
#include <Request/AWSGameLiftCreateSessionOnQueueRequest.h>
|
||||
#include <Request/AWSGameLiftCreateSessionRequest.h>
|
||||
#include <Request/AWSGameLiftJoinSessionRequest.h>
|
||||
#include <Request/AWSGameLiftSearchSessionsRequest.h>
|
||||
|
||||
#include <aws/gamelift/GameLiftClient.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
AWSGameLiftClientSystemComponent::AWSGameLiftClientSystemComponent()
|
||||
{
|
||||
m_gameliftClientManager = AZStd::make_unique<AWSGameLiftClientManager>();
|
||||
}
|
||||
|
||||
void AWSGameLiftClientSystemComponent::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
ReflectCreateSessionRequest(context);
|
||||
AWSGameLiftCreateSessionOnQueueRequest::Reflect(context);
|
||||
AWSGameLiftCreateSessionRequest::Reflect(context);
|
||||
AWSGameLiftJoinSessionRequest::Reflect(context);
|
||||
AWSGameLiftSearchSessionsRequest::Reflect(context);
|
||||
ReflectSearchSessionsResponse(context);
|
||||
|
||||
if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
{
|
||||
serialize->Class<AWSGameLiftClientSystemComponent, AZ::Component>()
|
||||
->Version(0)
|
||||
;
|
||||
|
||||
if (AZ::EditContext* editContext = serialize->GetEditContext())
|
||||
{
|
||||
editContext
|
||||
->Class<AWSGameLiftClientSystemComponent>(
|
||||
"AWSGameLiftClient",
|
||||
"Create the GameLift client manager that handles communication between game clients and the GameLift service.")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System"))
|
||||
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->EBus<AWSGameLiftRequestBus>("AWSGameLiftRequestBus")
|
||||
->Attribute(AZ::Script::Attributes::Category, "AWSGameLift")
|
||||
->Event("ConfigureGameLiftClient", &AWSGameLiftRequestBus::Events::ConfigureGameLiftClient,
|
||||
{{{"Region", ""}}})
|
||||
->Event("CreatePlayerId", &AWSGameLiftRequestBus::Events::CreatePlayerId,
|
||||
{{{"IncludeBrackets", ""},
|
||||
{"IncludeDashes", ""}}})
|
||||
;
|
||||
behaviorContext->EBus<AWSGameLiftSessionAsyncRequestBus>("AWSGameLiftSessionAsyncRequestBus")
|
||||
->Attribute(AZ::Script::Attributes::Category, "AWSGameLift")
|
||||
->Event("CreateSessionAsync", &AWSGameLiftSessionAsyncRequestBus::Events::CreateSessionAsync,
|
||||
{{{"CreateSessionRequest", ""}}})
|
||||
->Event("JoinSessionAsync", &AWSGameLiftSessionAsyncRequestBus::Events::JoinSessionAsync,
|
||||
{{{"JoinSessionRequest", ""}}})
|
||||
->Event("SearchSessionsAsync", &AWSGameLiftSessionAsyncRequestBus::Events::SearchSessionsAsync,
|
||||
{{{"SearchSessionsRequest", ""}}})
|
||||
->Event("LeaveSessionAsync", &AWSGameLiftSessionAsyncRequestBus::Events::LeaveSessionAsync)
|
||||
;
|
||||
behaviorContext
|
||||
->EBus<AzFramework::SessionAsyncRequestNotificationBus>("AWSGameLiftSessionAsyncRequestNotificationBus")
|
||||
->Attribute(AZ::Script::Attributes::Category, "AWSGameLift")
|
||||
->Handler<AWSGameLiftSessionAsyncRequestNotificationBusHandler>()
|
||||
;
|
||||
behaviorContext->EBus<AWSGameLiftSessionRequestBus>("AWSGameLiftSessionRequestBus")
|
||||
->Attribute(AZ::Script::Attributes::Category, "AWSGameLift")
|
||||
->Event("CreateSession", &AWSGameLiftSessionRequestBus::Events::CreateSession,
|
||||
{{{"CreateSessionRequest", ""}}})
|
||||
->Event("JoinSession", &AWSGameLiftSessionRequestBus::Events::JoinSession,
|
||||
{{{"JoinSessionRequest", ""}}})
|
||||
->Event("SearchSessions", &AWSGameLiftSessionRequestBus::Events::SearchSessions,
|
||||
{{{"SearchSessionsRequest", ""}}})
|
||||
->Event("LeaveSession", &AWSGameLiftSessionRequestBus::Events::LeaveSession)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void AWSGameLiftClientSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
|
||||
{
|
||||
provided.push_back(AZ_CRC_CE("AWSGameLiftClientService"));
|
||||
}
|
||||
|
||||
void AWSGameLiftClientSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
|
||||
{
|
||||
incompatible.push_back(AZ_CRC_CE("AWSGameLiftClientService"));
|
||||
}
|
||||
|
||||
void AWSGameLiftClientSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
|
||||
{
|
||||
required.push_back(AZ_CRC_CE("AWSCoreService"));
|
||||
}
|
||||
|
||||
void AWSGameLiftClientSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
|
||||
{
|
||||
AZ_UNUSED(dependent);
|
||||
}
|
||||
|
||||
void AWSGameLiftClientSystemComponent::Init()
|
||||
{
|
||||
}
|
||||
|
||||
void AWSGameLiftClientSystemComponent::Activate()
|
||||
{
|
||||
m_gameliftClientManager->ActivateManager();
|
||||
}
|
||||
|
||||
void AWSGameLiftClientSystemComponent::Deactivate()
|
||||
{
|
||||
m_gameliftClientManager->DeactivateManager();
|
||||
}
|
||||
|
||||
void AWSGameLiftClientSystemComponent::ReflectCreateSessionRequest(AZ::ReflectContext* context)
|
||||
{
|
||||
AzFramework::CreateSessionRequest::Reflect(context);
|
||||
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->Class<AzFramework::CreateSessionRequest>("CreateSessionRequest")
|
||||
->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value)
|
||||
// Expose base type to BehaviorContext, but hide it to be used directly
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void AWSGameLiftClientSystemComponent::ReflectSearchSessionsResponse(AZ::ReflectContext* context)
|
||||
{
|
||||
// As it is a common response type, reflection could be moved to AzFramework to avoid duplication
|
||||
AzFramework::SessionConfig::Reflect(context);
|
||||
AzFramework::SearchSessionsResponse::Reflect(context);
|
||||
|
||||
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->Class<AzFramework::SessionConfig>("SessionConfig")
|
||||
->Attribute(AZ::Script::Attributes::Category, "Session")
|
||||
->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value)
|
||||
->Property("CreationTime", BehaviorValueProperty(&AzFramework::SessionConfig::m_creationTime))
|
||||
->Property("CreatorId", BehaviorValueProperty(&AzFramework::SessionConfig::m_creatorId))
|
||||
->Property("CurrentPlayer", BehaviorValueProperty(&AzFramework::SessionConfig::m_currentPlayer))
|
||||
->Property("DnsName", BehaviorValueProperty(&AzFramework::SessionConfig::m_dnsName))
|
||||
->Property("IpAddress", BehaviorValueProperty(&AzFramework::SessionConfig::m_ipAddress))
|
||||
->Property("MaxPlayer", BehaviorValueProperty(&AzFramework::SessionConfig::m_maxPlayer))
|
||||
->Property("Port", BehaviorValueProperty(&AzFramework::SessionConfig::m_port))
|
||||
->Property("SessionId", BehaviorValueProperty(&AzFramework::SessionConfig::m_sessionId))
|
||||
->Property("SessionName", BehaviorValueProperty(&AzFramework::SessionConfig::m_sessionName))
|
||||
->Property("SessionProperties", BehaviorValueProperty(&AzFramework::SessionConfig::m_sessionProperties))
|
||||
->Property("Status", BehaviorValueProperty(&AzFramework::SessionConfig::m_status))
|
||||
->Property("StatusReason", BehaviorValueProperty(&AzFramework::SessionConfig::m_statusReason))
|
||||
->Property("TerminationTime", BehaviorValueProperty(&AzFramework::SessionConfig::m_terminationTime))
|
||||
;
|
||||
behaviorContext->Class<AzFramework::SearchSessionsResponse>("SearchSessionsResponse")
|
||||
->Attribute(AZ::Script::Attributes::Category, "Session")
|
||||
->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value)
|
||||
->Property("NextToken", BehaviorValueProperty(&AzFramework::SearchSessionsResponse::m_nextToken))
|
||||
->Property("SessionConfigs", BehaviorValueProperty(&AzFramework::SearchSessionsResponse::m_sessionConfigs))
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void AWSGameLiftClientSystemComponent::SetGameLiftClientManager(AZStd::unique_ptr<AWSGameLiftClientManager> gameliftClientManager)
|
||||
{
|
||||
m_gameliftClientManager.reset();
|
||||
m_gameliftClientManager = AZStd::move(gameliftClientManager);
|
||||
}
|
||||
} // namespace AWSGameLift
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/Component/Component.h>
|
||||
#include <AzCore/std/smart_ptr/unique_ptr.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
class AWSGameLiftClientManager;
|
||||
|
||||
//! Gem client system component. Responsible for creating the gamelift client manager.
|
||||
class AWSGameLiftClientSystemComponent
|
||||
: public AZ::Component
|
||||
{
|
||||
public:
|
||||
AZ_COMPONENT(AWSGameLiftClientSystemComponent, "{d481c15c-732a-4eea-9853-4965ed1bc2be}");
|
||||
|
||||
AWSGameLiftClientSystemComponent();
|
||||
virtual ~AWSGameLiftClientSystemComponent() = default;
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
|
||||
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
|
||||
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
|
||||
static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
|
||||
|
||||
protected:
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// AZ::Component interface implementation
|
||||
void Init() override;
|
||||
void Activate() override;
|
||||
void Deactivate() override;
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SetGameLiftClientManager(AZStd::unique_ptr<AWSGameLiftClientManager> gameliftClientManager);
|
||||
|
||||
private:
|
||||
static void ReflectCreateSessionRequest(AZ::ReflectContext* context);
|
||||
static void ReflectSearchSessionsResponse(AZ::ReflectContext* context);
|
||||
|
||||
AZStd::unique_ptr<AWSGameLiftClientManager> m_gameliftClientManager;
|
||||
};
|
||||
|
||||
} // namespace AWSGameLift
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Activity/AWSGameLiftCreateSessionActivity.h>
|
||||
#include <AWSGameLiftSessionConstants.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
namespace CreateSessionActivity
|
||||
{
|
||||
Aws::GameLift::Model::CreateGameSessionRequest BuildAWSGameLiftCreateGameSessionRequest(
|
||||
const AWSGameLiftCreateSessionRequest& createSessionRequest)
|
||||
{
|
||||
Aws::GameLift::Model::CreateGameSessionRequest request;
|
||||
// Optional attributes
|
||||
if (!createSessionRequest.m_creatorId.empty())
|
||||
{
|
||||
request.SetCreatorId(createSessionRequest.m_creatorId.c_str());
|
||||
}
|
||||
if (!createSessionRequest.m_sessionName.empty())
|
||||
{
|
||||
request.SetName(createSessionRequest.m_sessionName.c_str());
|
||||
}
|
||||
if (!createSessionRequest.m_idempotencyToken.empty())
|
||||
{
|
||||
request.SetIdempotencyToken(createSessionRequest.m_idempotencyToken.c_str());
|
||||
}
|
||||
for (auto iter = createSessionRequest.m_sessionProperties.begin();
|
||||
iter != createSessionRequest.m_sessionProperties.end(); iter++)
|
||||
{
|
||||
Aws::GameLift::Model::GameProperty sessionProperty;
|
||||
sessionProperty.SetKey(iter->first.c_str());
|
||||
sessionProperty.SetValue(iter->second.c_str());
|
||||
request.AddGameProperties(sessionProperty);
|
||||
}
|
||||
|
||||
// Required attributes
|
||||
if (!createSessionRequest.m_aliasId.empty())
|
||||
{
|
||||
request.SetAliasId(createSessionRequest.m_aliasId.c_str());
|
||||
}
|
||||
if (!createSessionRequest.m_fleetId.empty())
|
||||
{
|
||||
request.SetFleetId(createSessionRequest.m_fleetId.c_str());
|
||||
}
|
||||
request.SetMaximumPlayerSessionCount(createSessionRequest.m_maxPlayer);
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
AZStd::string CreateSession(
|
||||
const Aws::GameLift::GameLiftClient& gameliftClient,
|
||||
const AWSGameLiftCreateSessionRequest& createSessionRequest)
|
||||
{
|
||||
AZ_TracePrintf(AWSGameLiftCreateSessionActivityName, "Requesting CreateGameSession against Amazon GameLift service ...");
|
||||
|
||||
AZStd::string result = "";
|
||||
Aws::GameLift::Model::CreateGameSessionRequest request = BuildAWSGameLiftCreateGameSessionRequest(createSessionRequest);
|
||||
auto createSessionOutcome = gameliftClient.CreateGameSession(request);
|
||||
|
||||
if (createSessionOutcome.IsSuccess())
|
||||
{
|
||||
result = AZStd::string(createSessionOutcome.GetResult().GetGameSession().GetGameSessionId().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Error(AWSGameLiftCreateSessionActivityName, false, AWSGameLiftErrorMessageTemplate,
|
||||
createSessionOutcome.GetError().GetExceptionName().c_str(), createSessionOutcome.GetError().GetMessage().c_str());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ValidateCreateSessionRequest(const AzFramework::CreateSessionRequest& createSessionRequest)
|
||||
{
|
||||
auto gameliftCreateSessionRequest = azrtti_cast<const AWSGameLiftCreateSessionRequest*>(&createSessionRequest);
|
||||
|
||||
return gameliftCreateSessionRequest && gameliftCreateSessionRequest->m_maxPlayer >= 0 &&
|
||||
(!gameliftCreateSessionRequest->m_aliasId.empty() || !gameliftCreateSessionRequest->m_fleetId.empty());
|
||||
}
|
||||
} // namespace CreateSessionActivity
|
||||
} // namespace AWSGameLift
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Request/AWSGameLiftCreateSessionRequest.h>
|
||||
|
||||
#include <aws/core/utils/Outcome.h>
|
||||
#include <aws/gamelift/GameLiftClient.h>
|
||||
#include <aws/gamelift/model/CreateGameSessionRequest.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
namespace CreateSessionActivity
|
||||
{
|
||||
static constexpr const char AWSGameLiftCreateSessionActivityName[] = "AWSGameLiftCreateSessionActivity";
|
||||
|
||||
// Build AWS GameLift CreateGameSessionRequest by using AWSGameLiftCreateSessionRequest
|
||||
Aws::GameLift::Model::CreateGameSessionRequest BuildAWSGameLiftCreateGameSessionRequest(const AWSGameLiftCreateSessionRequest& createSessionRequest);
|
||||
|
||||
// Create CreateGameSessionRequest and make a CreateGameSession call through GameLift client
|
||||
AZStd::string CreateSession(
|
||||
const Aws::GameLift::GameLiftClient& gameliftClient,
|
||||
const AWSGameLiftCreateSessionRequest& createSessionRequest);
|
||||
|
||||
// Validate CreateSessionRequest and check required request parameters
|
||||
bool ValidateCreateSessionRequest(const AzFramework::CreateSessionRequest& createSessionRequest);
|
||||
|
||||
} // namespace CreateSessionActivity
|
||||
} // namespace AWSGameLift
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AWSGameLiftSessionConstants.h>
|
||||
#include <Activity/AWSGameLiftCreateSessionOnQueueActivity.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
namespace CreateSessionOnQueueActivity
|
||||
{
|
||||
Aws::GameLift::Model::StartGameSessionPlacementRequest BuildAWSGameLiftStartGameSessionPlacementRequest(
|
||||
const AWSGameLiftCreateSessionOnQueueRequest& createSessionOnQueueRequest)
|
||||
{
|
||||
Aws::GameLift::Model::StartGameSessionPlacementRequest request;
|
||||
// Optional attributes
|
||||
if (!createSessionOnQueueRequest.m_sessionName.empty())
|
||||
{
|
||||
request.SetGameSessionName(createSessionOnQueueRequest.m_sessionName.c_str());
|
||||
}
|
||||
for (auto iter = createSessionOnQueueRequest.m_sessionProperties.begin();
|
||||
iter != createSessionOnQueueRequest.m_sessionProperties.end(); iter++)
|
||||
{
|
||||
Aws::GameLift::Model::GameProperty sessionProperty;
|
||||
sessionProperty.SetKey(iter->first.c_str());
|
||||
sessionProperty.SetValue(iter->second.c_str());
|
||||
request.AddGameProperties(sessionProperty);
|
||||
}
|
||||
|
||||
// Required attributes
|
||||
request.SetGameSessionQueueName(createSessionOnQueueRequest.m_queueName.c_str());
|
||||
request.SetMaximumPlayerSessionCount(createSessionOnQueueRequest.m_maxPlayer);
|
||||
request.SetPlacementId(createSessionOnQueueRequest.m_placementId.c_str());
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
AZStd::string CreateSessionOnQueue(
|
||||
const Aws::GameLift::GameLiftClient& gameliftClient,
|
||||
const AWSGameLiftCreateSessionOnQueueRequest& createSessionOnQueueRequest)
|
||||
{
|
||||
AZ_TracePrintf(AWSGameLiftCreateSessionOnQueueActivityName,
|
||||
"Requesting StartGameSessionPlacement against Amazon GameLift service ...");
|
||||
|
||||
AZStd::string result = "";
|
||||
Aws::GameLift::Model::StartGameSessionPlacementRequest request =
|
||||
BuildAWSGameLiftStartGameSessionPlacementRequest(createSessionOnQueueRequest);
|
||||
auto createSessionOnQueueOutcome = gameliftClient.StartGameSessionPlacement(request);
|
||||
|
||||
if (createSessionOnQueueOutcome.IsSuccess())
|
||||
{
|
||||
result = AZStd::string(createSessionOnQueueOutcome.GetResult().GetGameSessionPlacement().GetPlacementId().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Error(AWSGameLiftCreateSessionOnQueueActivityName, false, AWSGameLiftErrorMessageTemplate,
|
||||
createSessionOnQueueOutcome.GetError().GetExceptionName().c_str(),
|
||||
createSessionOnQueueOutcome.GetError().GetMessage().c_str());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ValidateCreateSessionOnQueueRequest(const AzFramework::CreateSessionRequest& createSessionRequest)
|
||||
{
|
||||
auto gameliftCreateSessionOnQueueRequest =
|
||||
azrtti_cast<const AWSGameLiftCreateSessionOnQueueRequest*>(&createSessionRequest);
|
||||
|
||||
return gameliftCreateSessionOnQueueRequest && gameliftCreateSessionOnQueueRequest->m_maxPlayer >= 0 &&
|
||||
!gameliftCreateSessionOnQueueRequest->m_queueName.empty() && !gameliftCreateSessionOnQueueRequest->m_placementId.empty();
|
||||
}
|
||||
} // namespace CreateSessionOnQueueActivity
|
||||
} // namespace AWSGameLift
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Request/AWSGameLiftCreateSessionOnQueueRequest.h>
|
||||
|
||||
#include <aws/core/utils/Outcome.h>
|
||||
#include <aws/gamelift/GameLiftClient.h>
|
||||
#include <aws/gamelift/model/StartGameSessionPlacementRequest.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
namespace CreateSessionOnQueueActivity
|
||||
{
|
||||
static constexpr const char AWSGameLiftCreateSessionOnQueueActivityName[] = "AWSGameLiftCreateSessionOnQueueActivity";
|
||||
|
||||
// Build AWS GameLift StartGameSessionPlacementRequest by using AWSGameLiftCreateSessionOnQueueRequest
|
||||
Aws::GameLift::Model::StartGameSessionPlacementRequest BuildAWSGameLiftStartGameSessionPlacementRequest(
|
||||
const AWSGameLiftCreateSessionOnQueueRequest& createSessionOnQueueRequest);
|
||||
|
||||
// Create StartGameSessionPlacementRequest and make a CreateGameSession call through GameLift client
|
||||
AZStd::string CreateSessionOnQueue(
|
||||
const Aws::GameLift::GameLiftClient& gameliftClient,
|
||||
const AWSGameLiftCreateSessionOnQueueRequest& createSessionOnQueueRequest);
|
||||
|
||||
// Validate CreateSessionOnQueueRequest and check required request parameters
|
||||
bool ValidateCreateSessionOnQueueRequest(const AzFramework::CreateSessionRequest& createSessionRequest);
|
||||
|
||||
} // namespace CreateSessionOnQueueActivity
|
||||
} // namespace AWSGameLift
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
#include <AzFramework/Session/ISessionHandlingRequests.h>
|
||||
|
||||
#include <Activity/AWSGameLiftJoinSessionActivity.h>
|
||||
#include <AWSGameLiftSessionConstants.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
namespace JoinSessionActivity
|
||||
{
|
||||
Aws::GameLift::Model::CreatePlayerSessionRequest BuildAWSGameLiftCreatePlayerSessionRequest(
|
||||
const AWSGameLiftJoinSessionRequest& joinSessionRequest)
|
||||
{
|
||||
Aws::GameLift::Model::CreatePlayerSessionRequest request;
|
||||
// Optional attributes
|
||||
if (!joinSessionRequest.m_playerData.empty())
|
||||
{
|
||||
request.SetPlayerData(joinSessionRequest.m_playerData.c_str());
|
||||
}
|
||||
// Required attributes
|
||||
request.SetPlayerId(joinSessionRequest.m_playerId.c_str());
|
||||
request.SetGameSessionId(joinSessionRequest.m_sessionId.c_str());
|
||||
return request;
|
||||
}
|
||||
|
||||
AzFramework::SessionConnectionConfig BuildSessionConnectionConfig(
|
||||
const Aws::GameLift::Model::CreatePlayerSessionOutcome& createPlayerSessionOutcome)
|
||||
{
|
||||
AzFramework::SessionConnectionConfig sessionConnectionConfig;
|
||||
auto createPlayerSessionResult = createPlayerSessionOutcome.GetResult();
|
||||
// TODO: AWSNativeSDK needs to be updated to support this attribute, and it is a must have for TLS certificate enabled fleet
|
||||
//sessionConnectionConfig.m_dnsName = createPlayerSessionResult.GetPlayerSession().GetDnsName().c_str();
|
||||
sessionConnectionConfig.m_ipAddress = createPlayerSessionResult.GetPlayerSession().GetIpAddress().c_str();
|
||||
sessionConnectionConfig.m_playerSessionId = createPlayerSessionResult.GetPlayerSession().GetPlayerSessionId().c_str();
|
||||
sessionConnectionConfig.m_port = createPlayerSessionResult.GetPlayerSession().GetPort();
|
||||
return sessionConnectionConfig;
|
||||
}
|
||||
|
||||
Aws::GameLift::Model::CreatePlayerSessionOutcome CreatePlayerSession(
|
||||
const Aws::GameLift::GameLiftClient& gameliftClient,
|
||||
const AWSGameLiftJoinSessionRequest& joinSessionRequest)
|
||||
{
|
||||
AZ_TracePrintf(AWSGameLiftJoinSessionActivityName,
|
||||
"Requesting CreatePlayerSession for player %s against Amazon GameLift service ...",
|
||||
joinSessionRequest.m_playerId.c_str());
|
||||
|
||||
Aws::GameLift::Model::CreatePlayerSessionRequest request =
|
||||
BuildAWSGameLiftCreatePlayerSessionRequest(joinSessionRequest);
|
||||
auto createPlayerSessionOutcome = gameliftClient.CreatePlayerSession(request);
|
||||
|
||||
if (!createPlayerSessionOutcome.IsSuccess())
|
||||
{
|
||||
AZ_Error(AWSGameLiftJoinSessionActivityName, false, AWSGameLiftErrorMessageTemplate,
|
||||
createPlayerSessionOutcome.GetError().GetExceptionName().c_str(),
|
||||
createPlayerSessionOutcome.GetError().GetMessage().c_str());
|
||||
}
|
||||
return createPlayerSessionOutcome;
|
||||
}
|
||||
|
||||
bool RequestPlayerJoinSession(const Aws::GameLift::Model::CreatePlayerSessionOutcome& createPlayerSessionOutcome)
|
||||
{
|
||||
bool result = false;
|
||||
if (createPlayerSessionOutcome.IsSuccess())
|
||||
{
|
||||
auto clientRequestHandler = AZ::Interface<AzFramework::ISessionHandlingClientRequests>::Get();
|
||||
if (clientRequestHandler)
|
||||
{
|
||||
AZ_TracePrintf(AWSGameLiftJoinSessionActivityName, "Requesting player to connect to game session ...");
|
||||
|
||||
AzFramework::SessionConnectionConfig sessionConnectionConfig =
|
||||
BuildSessionConnectionConfig(createPlayerSessionOutcome);
|
||||
result = clientRequestHandler->RequestPlayerJoinSession(sessionConnectionConfig);
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Error(AWSGameLiftJoinSessionActivityName, false, AWSGameLiftJoinSessionMissingRequestHandlerErrorMessage);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ValidateJoinSessionRequest(const AzFramework::JoinSessionRequest& joinSessionRequest)
|
||||
{
|
||||
auto gameliftJoinSessionRequest = azrtti_cast<const AWSGameLiftJoinSessionRequest*>(&joinSessionRequest);
|
||||
|
||||
if (gameliftJoinSessionRequest &&
|
||||
!gameliftJoinSessionRequest->m_playerId.empty() &&
|
||||
!gameliftJoinSessionRequest->m_sessionId.empty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Error(AWSGameLiftJoinSessionActivityName, false, AWSGameLiftJoinSessionRequestInvalidErrorMessage);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // namespace JoinSessionActivity
|
||||
} // namespace AWSGameLift
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzFramework/Session/ISessionHandlingRequests.h>
|
||||
|
||||
#include <Request/AWSGameLiftJoinSessionRequest.h>
|
||||
|
||||
#include <aws/core/utils/Outcome.h>
|
||||
#include <aws/gamelift/GameLiftClient.h>
|
||||
#include <aws/gamelift/model/CreatePlayerSessionRequest.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
namespace JoinSessionActivity
|
||||
{
|
||||
static constexpr const char AWSGameLiftJoinSessionActivityName[] = "AWSGameLiftJoinSessionActivity";
|
||||
static constexpr const char AWSGameLiftJoinSessionRequestInvalidErrorMessage[] =
|
||||
"Invalid GameLift JoinSession request.";
|
||||
static constexpr const char AWSGameLiftJoinSessionMissingRequestHandlerErrorMessage[] =
|
||||
"Missing GameLift JoinSession request handler, please make sure Multiplayer Gem is enabled and registered as handler.";
|
||||
|
||||
// Build AWS GameLift CreatePlayerSessionRequest by using AWSGameLiftJoinSessionRequest
|
||||
Aws::GameLift::Model::CreatePlayerSessionRequest BuildAWSGameLiftCreatePlayerSessionRequest(
|
||||
const AWSGameLiftJoinSessionRequest& joinSessionRequest);
|
||||
|
||||
// Build session connection config by using CreatePlayerSessionOutcome
|
||||
AzFramework::SessionConnectionConfig BuildSessionConnectionConfig(
|
||||
const Aws::GameLift::Model::CreatePlayerSessionOutcome& createPlayerSessionOutcome);
|
||||
|
||||
// Create CreatePlayerSessionRequest and make a CreatePlayerSession call through GameLift client
|
||||
Aws::GameLift::Model::CreatePlayerSessionOutcome CreatePlayerSession(
|
||||
const Aws::GameLift::GameLiftClient& gameliftClient,
|
||||
const AWSGameLiftJoinSessionRequest& joinSessionRequest);
|
||||
|
||||
// Request to setup networking connection for player
|
||||
bool RequestPlayerJoinSession(
|
||||
const Aws::GameLift::Model::CreatePlayerSessionOutcome& createPlayerSessionOutcome);
|
||||
|
||||
// Validate JoinSessionRequest and check required request parameters
|
||||
bool ValidateJoinSessionRequest(const AzFramework::JoinSessionRequest& joinSessionRequest);
|
||||
|
||||
} // namespace JoinSessionActivity
|
||||
} // namespace AWSGameLift
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Activity/AWSGameLiftLeaveSessionActivity.h>
|
||||
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
#include <AzFramework/Session/ISessionHandlingRequests.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
namespace LeaveSessionActivity
|
||||
{
|
||||
void LeaveSession()
|
||||
{
|
||||
auto clientRequestHandler = AZ::Interface<AzFramework::ISessionHandlingClientRequests>::Get();
|
||||
if (clientRequestHandler)
|
||||
{
|
||||
AZ_TracePrintf(AWSGameLiftLeaveSessionActivityName, "Requesting to leave the current session...");
|
||||
|
||||
clientRequestHandler->RequestPlayerLeaveSession();
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Error(AWSGameLiftLeaveSessionActivityName, false, AWSGameLiftLeaveSessionMissingRequestHandlerErrorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace LeaveSessionActivity
|
||||
} // namespace AWSGameLift
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
namespace LeaveSessionActivity
|
||||
{
|
||||
static constexpr const char AWSGameLiftLeaveSessionActivityName[] = "AWSGameLiftLeaveSessionActivity";
|
||||
static constexpr const char AWSGameLiftLeaveSessionMissingRequestHandlerErrorMessage[] =
|
||||
"Missing GameLift LeaveSession request handler, please make sure Multiplayer Gem is enabled and registered as handler.";
|
||||
|
||||
// Request to leave the current session
|
||||
void LeaveSession();
|
||||
} // namespace LeaveSessionActivity
|
||||
} // namespace AWSGameLift
|
||||
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzFramework/Session/SessionConfig.h>
|
||||
|
||||
#include <Activity/AWSGameLiftSearchSessionsActivity.h>
|
||||
#include <AWSGameLiftSessionConstants.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
namespace SearchSessionsActivity
|
||||
{
|
||||
Aws::GameLift::Model::SearchGameSessionsRequest BuildAWSGameLiftSearchGameSessionsRequest(
|
||||
const AWSGameLiftSearchSessionsRequest& searchSessionsRequest)
|
||||
{
|
||||
Aws::GameLift::Model::SearchGameSessionsRequest request;
|
||||
// Optional attributes
|
||||
if (!searchSessionsRequest.m_filterExpression.empty())
|
||||
{
|
||||
request.SetFilterExpression(searchSessionsRequest.m_filterExpression.c_str());
|
||||
}
|
||||
if (!searchSessionsRequest.m_sortExpression.empty())
|
||||
{
|
||||
request.SetSortExpression(searchSessionsRequest.m_sortExpression.c_str());
|
||||
}
|
||||
if (searchSessionsRequest.m_maxResult > 0)
|
||||
{
|
||||
request.SetLimit(searchSessionsRequest.m_maxResult);
|
||||
}
|
||||
if (!searchSessionsRequest.m_nextToken.empty())
|
||||
{
|
||||
request.SetNextToken(searchSessionsRequest.m_nextToken.c_str());
|
||||
}
|
||||
// Required attributes
|
||||
if (!searchSessionsRequest.m_aliasId.empty())
|
||||
{
|
||||
request.SetAliasId(searchSessionsRequest.m_aliasId.c_str());
|
||||
}
|
||||
if (!searchSessionsRequest.m_fleetId.empty())
|
||||
{
|
||||
request.SetFleetId(searchSessionsRequest.m_fleetId.c_str());
|
||||
}
|
||||
// TODO: Update the AWS Native SDK to accept the new request parameter.
|
||||
//request.SetLocation(searchSessionsRequest.m_location.c_str());
|
||||
return request;
|
||||
}
|
||||
|
||||
AzFramework::SearchSessionsResponse SearchSessions(
|
||||
const Aws::GameLift::GameLiftClient& gameliftClient,
|
||||
const AWSGameLiftSearchSessionsRequest& searchSessionsRequest)
|
||||
{
|
||||
AZ_TracePrintf(AWSGameLiftSearchSessionsActivityName, "Requesting SearchGameSessions against Amazon GameLift service ...");
|
||||
|
||||
AzFramework::SearchSessionsResponse response;
|
||||
Aws::GameLift::Model::SearchGameSessionsRequest request = BuildAWSGameLiftSearchGameSessionsRequest(searchSessionsRequest);
|
||||
Aws::GameLift::Model::SearchGameSessionsOutcome outcome = gameliftClient.SearchGameSessions(request);
|
||||
|
||||
if (outcome.IsSuccess())
|
||||
{
|
||||
response = SearchSessionsActivity::ParseResponse(outcome.GetResult());
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Error(AWSGameLiftSearchSessionsActivityName, false, AWSGameLiftErrorMessageTemplate,
|
||||
outcome.GetError().GetExceptionName().c_str(), outcome.GetError().GetMessage().c_str());
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
AzFramework::SearchSessionsResponse ParseResponse(
|
||||
const Aws::GameLift::Model::SearchGameSessionsResult& gameLiftSearchSessionsResult)
|
||||
{
|
||||
AzFramework::SearchSessionsResponse response;
|
||||
response.m_nextToken = gameLiftSearchSessionsResult.GetNextToken().c_str();
|
||||
|
||||
for (const Aws::GameLift::Model::GameSession& gameSession : gameLiftSearchSessionsResult.GetGameSessions())
|
||||
{
|
||||
AzFramework::SessionConfig session;
|
||||
session.m_creationTime = gameSession.GetCreationTime().Millis();
|
||||
session.m_creatorId = gameSession.GetCreatorId().c_str();
|
||||
session.m_currentPlayer = gameSession.GetCurrentPlayerSessionCount();
|
||||
session.m_ipAddress = gameSession.GetIpAddress().c_str();
|
||||
session.m_maxPlayer = gameSession.GetMaximumPlayerSessionCount();
|
||||
session.m_port = gameSession.GetPort();
|
||||
session.m_sessionId = gameSession.GetGameSessionId().c_str();
|
||||
session.m_sessionName = gameSession.GetName().c_str();
|
||||
session.m_status = AWSGameLiftSessionStatusNames[(int)gameSession.GetStatus()];
|
||||
session.m_statusReason = AWSGameLiftSessionStatusReasons[(int)gameSession.GetStatusReason()];
|
||||
session.m_terminationTime = gameSession.GetTerminationTime().Millis();
|
||||
// TODO: Update the AWS Native SDK to get the new game session attributes.
|
||||
//session.m_dnsName = gameSession.GetDnsName();
|
||||
|
||||
for (const auto& gameProperty : gameSession.GetGameProperties())
|
||||
{
|
||||
session.m_sessionProperties[gameProperty.GetKey().c_str()] = gameProperty.GetValue().c_str();
|
||||
}
|
||||
|
||||
response.m_sessionConfigs.emplace_back(AZStd::move(session));
|
||||
}
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
bool ValidateSearchSessionsRequest(const AzFramework::SearchSessionsRequest& searchSessionsRequest)
|
||||
{
|
||||
auto gameliftSearchSessionsRequest = azrtti_cast<const AWSGameLiftSearchSessionsRequest*>(&searchSessionsRequest);
|
||||
if (gameliftSearchSessionsRequest &&
|
||||
(!gameliftSearchSessionsRequest->m_aliasId.empty() || !gameliftSearchSessionsRequest->m_fleetId.empty()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Error(AWSGameLiftSearchSessionsActivityName, false, AWSGameLiftSearchSessionsRequestInvalidErrorMessage);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace AWSGameLift
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Request/AWSGameLiftSearchSessionsRequest.h>
|
||||
|
||||
#include <aws/core/utils/Outcome.h>
|
||||
#include <aws/gamelift/GameLiftClient.h>
|
||||
#include <aws/gamelift/model/SearchGameSessionsRequest.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
namespace SearchSessionsActivity
|
||||
{
|
||||
static constexpr const char AWSGameLiftSearchSessionsActivityName[] = "AWSGameLiftSearchSessionsActivity";
|
||||
static constexpr const char AWSGameLiftSearchSessionsRequestInvalidErrorMessage[] =
|
||||
"Invalid GameLift SearchSessions request.";
|
||||
|
||||
// Build AWS GameLift SearchGameSessionsRequest by using AWSGameLiftSearchSessionsRequest
|
||||
Aws::GameLift::Model::SearchGameSessionsRequest BuildAWSGameLiftSearchGameSessionsRequest(
|
||||
const AWSGameLiftSearchSessionsRequest& searchSessionsRequest);
|
||||
|
||||
// Create SearchGameSessionsRequest and make a SeachGameSessions call through GameLift client
|
||||
AzFramework::SearchSessionsResponse SearchSessions(
|
||||
const Aws::GameLift::GameLiftClient& gameliftClient,
|
||||
const AWSGameLiftSearchSessionsRequest& searchSessionsRequest);
|
||||
|
||||
// Convert from Aws::GameLift::Model::SearchGameSessionsResult to AzFramework::SearchSessionsResponse.
|
||||
AzFramework::SearchSessionsResponse ParseResponse(
|
||||
const Aws::GameLift::Model::SearchGameSessionsResult& gameLiftSearchSessionsResult);
|
||||
|
||||
// Validate SearchSessionsRequest and check required request parameters
|
||||
bool ValidateSearchSessionsRequest(const AzFramework::SearchSessionsRequest& searchSessionsRequest);
|
||||
} // namespace SearchSessionsActivity
|
||||
} // namespace AWSGameLift
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
|
||||
#include <Request/AWSGameLiftCreateSessionOnQueueRequest.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
void AWSGameLiftCreateSessionOnQueueRequest::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<AWSGameLiftCreateSessionOnQueueRequest, AzFramework::CreateSessionRequest>()
|
||||
->Version(0)
|
||||
->Field("queueName", &AWSGameLiftCreateSessionOnQueueRequest::m_queueName)
|
||||
->Field("placementId", &AWSGameLiftCreateSessionOnQueueRequest::m_placementId)
|
||||
;
|
||||
|
||||
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
|
||||
{
|
||||
editContext->Class<AWSGameLiftCreateSessionOnQueueRequest>("AWSGameLiftCreateSessionOnQueueRequest", "")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||
->DataElement(
|
||||
AZ::Edit::UIHandlers::Default, &AWSGameLiftCreateSessionOnQueueRequest::m_queueName, "QueueName (Required)",
|
||||
"Name of the queue to use to place the new game session")
|
||||
->DataElement(
|
||||
AZ::Edit::UIHandlers::Default, &AWSGameLiftCreateSessionOnQueueRequest::m_placementId, "PlacementId (Required)",
|
||||
"A unique identifier to assign to the new game session placement")
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->Class<AWSGameLiftCreateSessionOnQueueRequest>("AWSGameLiftCreateSessionOnQueueRequest")
|
||||
->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value)
|
||||
->Property("CreatorId", BehaviorValueProperty(&AWSGameLiftCreateSessionOnQueueRequest::m_creatorId))
|
||||
->Property("SessionProperties", BehaviorValueProperty(&AWSGameLiftCreateSessionOnQueueRequest::m_sessionProperties))
|
||||
->Property("SessionName", BehaviorValueProperty(&AWSGameLiftCreateSessionOnQueueRequest::m_sessionName))
|
||||
->Property("MaxPlayer", BehaviorValueProperty(&AWSGameLiftCreateSessionOnQueueRequest::m_maxPlayer))
|
||||
->Property("QueueName", BehaviorValueProperty(&AWSGameLiftCreateSessionOnQueueRequest::m_queueName))
|
||||
->Property("PlacementId", BehaviorValueProperty(&AWSGameLiftCreateSessionOnQueueRequest::m_placementId))
|
||||
;
|
||||
}
|
||||
}
|
||||
} // namespace AWSGameLift
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
|
||||
#include <Request/AWSGameLiftCreateSessionRequest.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
void AWSGameLiftCreateSessionRequest::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<AWSGameLiftCreateSessionRequest, AzFramework::CreateSessionRequest>()
|
||||
->Version(0)
|
||||
->Field("aliasId", &AWSGameLiftCreateSessionRequest::m_aliasId)
|
||||
->Field("fleetId", &AWSGameLiftCreateSessionRequest::m_fleetId)
|
||||
->Field("idempotencyToken", &AWSGameLiftCreateSessionRequest::m_idempotencyToken)
|
||||
;
|
||||
|
||||
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
|
||||
{
|
||||
editContext->Class<AWSGameLiftCreateSessionRequest>("AWSGameLiftCreateSessionRequest", "")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||
->DataElement(
|
||||
AZ::Edit::UIHandlers::Default, &AWSGameLiftCreateSessionRequest::m_aliasId, "AliasId (Required, or FleetId)",
|
||||
"A unique identifier for the alias associated with the fleet to create a game session in")
|
||||
->DataElement(
|
||||
AZ::Edit::UIHandlers::Default, &AWSGameLiftCreateSessionRequest::m_fleetId, "FleetId (Required, or AliasId)",
|
||||
"A unique identifier for the fleet to create a game session in")
|
||||
->DataElement(
|
||||
AZ::Edit::UIHandlers::Default, &AWSGameLiftCreateSessionRequest::m_idempotencyToken, "IdempotencyToken",
|
||||
"Custom string that uniquely identifies the new game session request")
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->Class<AWSGameLiftCreateSessionRequest>("AWSGameLiftCreateSessionRequest")
|
||||
->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value)
|
||||
->Property("CreatorId", BehaviorValueProperty(&AWSGameLiftCreateSessionRequest::m_creatorId))
|
||||
->Property("SessionProperties", BehaviorValueProperty(&AWSGameLiftCreateSessionRequest::m_sessionProperties))
|
||||
->Property("SessionName", BehaviorValueProperty(&AWSGameLiftCreateSessionRequest::m_sessionName))
|
||||
->Property("MaxPlayer", BehaviorValueProperty(&AWSGameLiftCreateSessionRequest::m_maxPlayer))
|
||||
->Property("AliasId", BehaviorValueProperty(&AWSGameLiftCreateSessionRequest::m_aliasId))
|
||||
->Property("FleetId", BehaviorValueProperty(&AWSGameLiftCreateSessionRequest::m_fleetId))
|
||||
->Property("IdempotencyToken", BehaviorValueProperty(&AWSGameLiftCreateSessionRequest::m_idempotencyToken))
|
||||
;
|
||||
}
|
||||
}
|
||||
} // namespace AWSGameLift
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
|
||||
#include <Request/AWSGameLiftJoinSessionRequest.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
void AWSGameLiftJoinSessionRequest::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
AzFramework::JoinSessionRequest::Reflect(context);
|
||||
|
||||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<AWSGameLiftJoinSessionRequest, AzFramework::JoinSessionRequest>()
|
||||
->Version(0)
|
||||
;
|
||||
|
||||
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
|
||||
{
|
||||
editContext->Class<AWSGameLiftJoinSessionRequest>("AWSGameLiftJoinSessionRequest", "")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->Class<AzFramework::JoinSessionRequest>("JoinSessionRequest")
|
||||
->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value)
|
||||
// Expose base type to BehaviorContext, but hide it to be used directly
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
|
||||
;
|
||||
behaviorContext->Class<AWSGameLiftJoinSessionRequest>("AWSGameLiftJoinSessionRequest")
|
||||
->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value)
|
||||
->Property("PlayerData", BehaviorValueProperty(&AWSGameLiftJoinSessionRequest::m_playerData))
|
||||
->Property("PlayerId", BehaviorValueProperty(&AWSGameLiftJoinSessionRequest::m_playerId))
|
||||
->Property("SessionId", BehaviorValueProperty(&AWSGameLiftJoinSessionRequest::m_sessionId))
|
||||
;
|
||||
}
|
||||
}
|
||||
} // namespace AWSGameLift
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzFramework/Session/SessionConfig.h>
|
||||
|
||||
#include <Request/AWSGameLiftSearchSessionsRequest.h>
|
||||
#include <AWSGameLiftSessionConstants.h>
|
||||
|
||||
namespace AWSGameLift
|
||||
{
|
||||
void AWSGameLiftSearchSessionsRequest::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
AzFramework::SearchSessionsRequest::Reflect(context);
|
||||
|
||||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<AWSGameLiftSearchSessionsRequest, AzFramework::SearchSessionsRequest>()
|
||||
->Version(0)
|
||||
->Field("aliasId", &AWSGameLiftSearchSessionsRequest::m_aliasId)
|
||||
->Field("fleetId", &AWSGameLiftSearchSessionsRequest::m_fleetId)
|
||||
->Field("location", &AWSGameLiftSearchSessionsRequest::m_location);
|
||||
|
||||
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
|
||||
{
|
||||
editContext->Class<AWSGameLiftSearchSessionsRequest>("AWSGameLiftSearchSessionsRequest", "")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||
->DataElement(
|
||||
AZ::Edit::UIHandlers::Default, &AWSGameLiftSearchSessionsRequest::m_aliasId, "AliasId (Required, or FleetId)",
|
||||
"A unique identifier for the alias associated with the fleet to search for active game sessions.")
|
||||
->DataElement(
|
||||
AZ::Edit::UIHandlers::Default, &AWSGameLiftSearchSessionsRequest::m_fleetId, "FleetId (Required, or AliasId)",
|
||||
"A unique identifier for the fleet to search for active game sessions.")
|
||||
->DataElement(
|
||||
AZ::Edit::UIHandlers::Default, &AWSGameLiftSearchSessionsRequest::m_location, "Location",
|
||||
"A fleet location to search for game sessions.");
|
||||
}
|
||||
}
|
||||
|
||||
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->Class<AzFramework::SearchSessionsRequest>("SearchSessionsRequest")
|
||||
->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value)
|
||||
// Expose base type to BehaviorContext, but hide it to be used directly
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All);
|
||||
behaviorContext->Class<AWSGameLiftSearchSessionsRequest>("AWSGameLiftSearchSessionsRequest")
|
||||
|
||||
->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value)
|
||||
->Property("FilterExpression", BehaviorValueProperty(&AWSGameLiftSearchSessionsRequest::m_filterExpression))
|
||||
->Property("SortExpression", BehaviorValueProperty(&AWSGameLiftSearchSessionsRequest::m_sortExpression))
|
||||
->Property("MaxResult", BehaviorValueProperty(&AWSGameLiftSearchSessionsRequest::m_maxResult))
|
||||
->Property("NextToken", BehaviorValueProperty(&AWSGameLiftSearchSessionsRequest::m_nextToken))
|
||||
->Property("AliasId", BehaviorValueProperty(&AWSGameLiftSearchSessionsRequest::m_aliasId))
|
||||
->Property("FleetId", BehaviorValueProperty(&AWSGameLiftSearchSessionsRequest::m_fleetId))
|
||||
->Property("Location", BehaviorValueProperty(&AWSGameLiftSearchSessionsRequest::m_location));
|
||||
}
|
||||
}
|
||||
} // namespace AWSGameLift
|
||||
Reference in New Issue
Block a user