Move multiplayer session interface out of AzFramework library (#7338)

Signed-off-by: onecent1101 <liug@amazon.com>
This commit is contained in:
Vincent Liu
2022-02-03 11:53:00 -08:00
committed by GitHub
parent 58f4a5259a
commit 74a876ae3b
65 changed files with 368 additions and 368 deletions
@@ -17,6 +17,8 @@
#include <ReplicationWindows/NullReplicationWindow.h>
#include <ReplicationWindows/ServerToClientReplicationWindow.h>
#include <Source/AutoGen/AutoComponentTypes.h>
#include <Multiplayer/Session/ISessionRequests.h>
#include <Multiplayer/Session/SessionConfig.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/Utils.h>
@@ -30,8 +32,6 @@
#include <AzCore/Utils/Utils.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzFramework/Components/CameraBus.h>
#include <AzFramework/Session/ISessionRequests.h>
#include <AzFramework/Session/SessionConfig.h>
#include <AzFramework/Spawnable/Spawnable.h>
#include <AzFramework/Visibility/IVisibilitySystem.h>
#include <AzFramework/Visibility/EntityBoundsUnionBus.h>
@@ -184,13 +184,13 @@ namespace Multiplayer
void MultiplayerSystemComponent::Activate()
{
AZ::TickBus::Handler::BusConnect();
AzFramework::SessionNotificationBus::Handler::BusConnect();
SessionNotificationBus::Handler::BusConnect();
m_networkInterface = AZ::Interface<INetworking>::Get()->CreateNetworkInterface(AZ::Name(MpNetworkInterfaceName), sv_protocol, TrustZone::ExternalClientToServer, *this);
if (AZ::Interface<AZ::IConsole>::Get())
{
m_consoleCommandHandler.Connect(AZ::Interface<AZ::IConsole>::Get()->GetConsoleCommandInvokedEvent());
}
AZ::Interface<AzFramework::ISessionHandlingClientRequests>::Register(this);
AZ::Interface<ISessionHandlingClientRequests>::Register(this);
//! Register our gems multiplayer components to assign NetComponentIds
RegisterMultiplayerComponents();
@@ -198,10 +198,10 @@ namespace Multiplayer
void MultiplayerSystemComponent::Deactivate()
{
AZ::Interface<AzFramework::ISessionHandlingClientRequests>::Unregister(this);
AZ::Interface<ISessionHandlingClientRequests>::Unregister(this);
m_consoleCommandHandler.Disconnect();
AZ::Interface<INetworking>::Get()->DestroyNetworkInterface(AZ::Name(MpNetworkInterfaceName));
AzFramework::SessionNotificationBus::Handler::BusDisconnect();
SessionNotificationBus::Handler::BusDisconnect();
AZ::TickBus::Handler::BusDisconnect();
m_networkEntityManager.Reset();
@@ -251,14 +251,14 @@ namespace Multiplayer
// Signal session management, do this after uninitializing state
if (agentType == MultiplayerAgentType::DedicatedServer || agentType == MultiplayerAgentType::ClientServer)
{
if (AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get() != nullptr)
if (AZ::Interface<ISessionHandlingProviderRequests>::Get() != nullptr)
{
AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get()->HandleDestroySession();
AZ::Interface<ISessionHandlingProviderRequests>::Get()->HandleDestroySession();
}
}
}
bool MultiplayerSystemComponent::RequestPlayerJoinSession(const AzFramework::SessionConnectionConfig& config)
bool MultiplayerSystemComponent::RequestPlayerJoinSession(const SessionConnectionConfig& config)
{
m_pendingConnectionTickets.push(config.m_playerSessionId);
AZStd::string hostname = config.m_dnsName.empty() ? config.m_ipAddress : config.m_dnsName;
@@ -280,13 +280,13 @@ namespace Multiplayer
return true;
}
bool MultiplayerSystemComponent::OnCreateSessionBegin(const AzFramework::SessionConfig& sessionConfig)
bool MultiplayerSystemComponent::OnCreateSessionBegin(const SessionConfig& sessionConfig)
{
// Check if session manager has a certificate for us and pass it along if so
if (AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get() != nullptr)
if (AZ::Interface<ISessionHandlingProviderRequests>::Get() != nullptr)
{
AZ::CVarFixedString externalCertPath = AZ::CVarFixedString(
AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get()->GetExternalSessionCertificate().c_str());
AZ::Interface<ISessionHandlingProviderRequests>::Get()->GetExternalSessionCertificate().c_str());
if (!externalCertPath.empty())
{
AZ::CVarFixedString commandString = "net_SslExternalCertificateFile " + externalCertPath;
@@ -294,7 +294,7 @@ namespace Multiplayer
}
AZ::CVarFixedString internalCertPath = AZ::CVarFixedString(
AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get()->GetInternalSessionCertificate().c_str());
AZ::Interface<ISessionHandlingProviderRequests>::Get()->GetInternalSessionCertificate().c_str());
if (!internalCertPath.empty())
{
AZ::CVarFixedString commandString = "net_SslInternalCertificateFile " + internalCertPath;
@@ -335,7 +335,7 @@ namespace Multiplayer
{
}
void MultiplayerSystemComponent::OnUpdateSessionBegin(const AzFramework::SessionConfig& sessionConfig, const AZStd::string& updateReason)
void MultiplayerSystemComponent::OnUpdateSessionBegin(const SessionConfig& sessionConfig, const AZStd::string& updateReason)
{
AZ_UNUSED(sessionConfig);
AZ_UNUSED(updateReason);
@@ -496,12 +496,12 @@ namespace Multiplayer
)
{
// Validate our session with the provider if any
if (AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get() != nullptr)
if (AZ::Interface<ISessionHandlingProviderRequests>::Get() != nullptr)
{
AzFramework::PlayerConnectionConfig config;
PlayerConnectionConfig config;
config.m_playerConnectionId = aznumeric_cast<uint32_t>(connection->GetConnectionId());
config.m_playerSessionId = packet.GetTicket();
if (!AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get()->ValidatePlayerJoinSession(config))
if (!AZ::Interface<ISessionHandlingProviderRequests>::Get()->ValidatePlayerJoinSession(config))
{
auto visitor = [](IConnection& connection) { connection.Disconnect(DisconnectReason::TerminatedByUser, TerminationEndpoint::Local); };
m_networkInterface->GetConnectionSet().VisitConnections(visitor);
@@ -780,13 +780,13 @@ namespace Multiplayer
else if (m_agentType == MultiplayerAgentType::DedicatedServer || m_agentType == MultiplayerAgentType::ClientServer)
{
// Signal to session management that a user has left the server
if (AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get() != nullptr &&
if (AZ::Interface<ISessionHandlingProviderRequests>::Get() != nullptr &&
connection->GetConnectionRole() == ConnectionRole::Acceptor)
{
AzFramework::PlayerConnectionConfig config;
PlayerConnectionConfig config;
config.m_playerConnectionId = aznumeric_cast<uint32_t>(connection->GetConnectionId());
config.m_playerSessionId = reinterpret_cast<ServerToClientConnectionData*>(connection->GetUserData())->GetProviderTicket();
AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get()->HandlePlayerLeaveSession(config);
AZ::Interface<ISessionHandlingProviderRequests>::Get()->HandlePlayerLeaveSession(config);
}
}
@@ -9,6 +9,8 @@
#pragma once
#include <Multiplayer/IMultiplayer.h>
#include <Multiplayer/Session/ISessionHandlingRequests.h>
#include <Multiplayer/Session/SessionNotifications.h>
#include <Editor/MultiplayerEditorConnection.h>
#include <NetworkTime/NetworkTime.h>
#include <NetworkEntity/NetworkEntityManager.h>
@@ -21,8 +23,6 @@
#include <AzCore/IO/ByteContainerStream.h>
#include <AzCore/Threading/ThreadSafeDeque.h>
#include <AzCore/std/string/string.h>
#include <AzFramework/Session/ISessionHandlingRequests.h>
#include <AzFramework/Session/SessionNotifications.h>
#include <AzNetworking/ConnectionLayer/IConnectionListener.h>
namespace AzFramework
@@ -41,8 +41,8 @@ namespace Multiplayer
class MultiplayerSystemComponent final
: public AZ::Component
, public AZ::TickBus::Handler
, public AzFramework::SessionNotificationBus::Handler
, public AzFramework::ISessionHandlingClientRequests
, public SessionNotificationBus::Handler
, public ISessionHandlingClientRequests
, public AzNetworking::IConnectionListener
, public IMultiplayer
{
@@ -63,14 +63,14 @@ namespace Multiplayer
void Deactivate() override;
//! @}
//! AzFramework::SessionNotificationBus::Handler overrides.
//! SessionNotificationBus::Handler overrides.
//! @{
bool OnSessionHealthCheck() override;
bool OnCreateSessionBegin(const AzFramework::SessionConfig& sessionConfig) override;
bool OnCreateSessionBegin(const SessionConfig& sessionConfig) override;
void OnCreateSessionEnd() override;
bool OnDestroySessionBegin() override;
void OnDestroySessionEnd() override;
void OnUpdateSessionBegin(const AzFramework::SessionConfig& sessionConfig, const AZStd::string& updateReason) override;
void OnUpdateSessionBegin(const SessionConfig& sessionConfig, const AZStd::string& updateReason) override;
void OnUpdateSessionEnd() override;
//! @}
@@ -101,7 +101,7 @@ namespace Multiplayer
//! ISessionHandlingClientRequests interface
//! @{
bool RequestPlayerJoinSession(const AzFramework::SessionConnectionConfig& sessionConnectionConfig) override;
bool RequestPlayerJoinSession(const SessionConnectionConfig& sessionConnectionConfig) override;
void RequestPlayerLeaveSession() override;
//! @}
@@ -0,0 +1,78 @@
/*
* 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/RTTI/ReflectContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <Multiplayer/Session/MatchmakingRequests.h>
namespace Multiplayer
{
void AcceptMatchRequest::Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<AcceptMatchRequest>()
->Version(0)
->Field("acceptMatch", &AcceptMatchRequest::m_acceptMatch)
->Field("playerIds", &AcceptMatchRequest::m_playerIds)
->Field("ticketId", &AcceptMatchRequest::m_ticketId);
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
{
editContext->Class<AcceptMatchRequest>("AcceptMatchRequest", "The container for AcceptMatch request parameters")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
->DataElement(AZ::Edit::UIHandlers::Default, &AcceptMatchRequest::m_acceptMatch, "AcceptMatch",
"Player response to accept or reject match")
->DataElement(AZ::Edit::UIHandlers::Default, &AcceptMatchRequest::m_playerIds, "PlayerIds",
"A list of unique identifiers for players delivering the response")
->DataElement(AZ::Edit::UIHandlers::Default, &AcceptMatchRequest::m_ticketId, "TicketId",
"A unique identifier for a matchmaking ticket");
}
}
}
void StartMatchmakingRequest::Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<StartMatchmakingRequest>()
->Version(0)
->Field("ticketId", &StartMatchmakingRequest::m_ticketId);
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
{
editContext->Class<StartMatchmakingRequest>("StartMatchmakingRequest", "The container for StartMatchmaking request parameters")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
->DataElement(AZ::Edit::UIHandlers::Default, &StartMatchmakingRequest::m_ticketId, "TicketId",
"A unique identifier for a matchmaking ticket");
}
}
}
void StopMatchmakingRequest::Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<StopMatchmakingRequest>()
->Version(0)
->Field("ticketId", &StopMatchmakingRequest::m_ticketId);
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
{
editContext->Class<StopMatchmakingRequest>("StopMatchmakingRequest", "The container for StopMatchmaking request parameters")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
->DataElement(AZ::Edit::UIHandlers::Default, &StopMatchmakingRequest::m_ticketId, "TicketId",
"A unique identifier for a matchmaking ticket");
}
}
}
} // namespace Multiplayer
@@ -0,0 +1,73 @@
/*
* 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/Serialization/EditContext.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <Multiplayer/Session/SessionConfig.h>
namespace Multiplayer
{
void SessionConfig::Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<SessionConfig>()
->Version(0)
->Field("creationTime", &SessionConfig::m_creationTime)
->Field("terminationTime", &SessionConfig::m_terminationTime)
->Field("creatorId", &SessionConfig::m_creatorId)
->Field("sessionProperties", &SessionConfig::m_sessionProperties)
->Field("matchmakingData", &SessionConfig::m_matchmakingData)
->Field("sessionId", &SessionConfig::m_sessionId)
->Field("sessionName", &SessionConfig::m_sessionName)
->Field("dnsName", &SessionConfig::m_dnsName)
->Field("ipAddress", &SessionConfig::m_ipAddress)
->Field("port", &SessionConfig::m_port)
->Field("maxPlayer", &SessionConfig::m_maxPlayer)
->Field("currentPlayer", &SessionConfig::m_currentPlayer)
->Field("status", &SessionConfig::m_status)
->Field("statusReason", &SessionConfig::m_statusReason)
;
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
{
editContext->Class<SessionConfig>("SessionConfig", "Properties describing a session")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
->DataElement(AZ::Edit::UIHandlers::Default, &Multiplayer::SessionConfig::m_creationTime,
"CreationTime", "A time stamp indicating when this session was created. Format is a number expressed in Unix time as milliseconds.")
->DataElement(AZ::Edit::UIHandlers::Default, &Multiplayer::SessionConfig::m_terminationTime,
"TerminationTime", "A time stamp indicating when this data object was terminated. Same format as creation time.")
->DataElement(AZ::Edit::UIHandlers::Default, &Multiplayer::SessionConfig::m_creatorId,
"CreatorId", "A unique identifier for a player or entity creating the session.")
->DataElement(AZ::Edit::UIHandlers::Default, &Multiplayer::SessionConfig::m_sessionProperties,
"SessionProperties", "A collection of custom properties for a session.")
->DataElement(AZ::Edit::UIHandlers::Default, &Multiplayer::SessionConfig::m_matchmakingData,
"MatchmakingData", "The matchmaking process information that was used to create the session.")
->DataElement(AZ::Edit::UIHandlers::Default, &Multiplayer::SessionConfig::m_sessionId,
"SessionId", "A unique identifier for the session.")
->DataElement(AZ::Edit::UIHandlers::Default, &Multiplayer::SessionConfig::m_sessionName,
"SessionName", "A descriptive label that is associated with a session.")
->DataElement(AZ::Edit::UIHandlers::Default, &Multiplayer::SessionConfig::m_dnsName,
"DnsName", "The DNS identifier assigned to the instance that is running the session.")
->DataElement(AZ::Edit::UIHandlers::Default, &Multiplayer::SessionConfig::m_ipAddress,
"IpAddress", "The IP address of the session.")
->DataElement(AZ::Edit::UIHandlers::Default, &Multiplayer::SessionConfig::m_port,
"Port", "The port number for the session.")
->DataElement(AZ::Edit::UIHandlers::Default, &Multiplayer::SessionConfig::m_maxPlayer,
"MaxPlayer", "The maximum number of players that can be connected simultaneously to the session.")
->DataElement(AZ::Edit::UIHandlers::Default, &Multiplayer::SessionConfig::m_currentPlayer,
"CurrentPlayer", "Number of players currently in the session.")
->DataElement(AZ::Edit::UIHandlers::Default, &Multiplayer::SessionConfig::m_status,
"Status", "Current status of the session.")
->DataElement(AZ::Edit::UIHandlers::Default, &Multiplayer::SessionConfig::m_statusReason,
"StatusReason", "Provides additional information about session status.");
}
}
}
} // namespace Multiplayer
@@ -0,0 +1,127 @@
/*
* 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/RTTI/ReflectContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <Multiplayer/Session/SessionRequests.h>
#include <Multiplayer/Session/SessionConfig.h>
namespace Multiplayer
{
void CreateSessionRequest::Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<CreateSessionRequest>()
->Version(0)
->Field("creatorId", &CreateSessionRequest::m_creatorId)
->Field("sessionProperties", &CreateSessionRequest::m_sessionProperties)
->Field("sessionName", &CreateSessionRequest::m_sessionName)
->Field("maxPlayer", &CreateSessionRequest::m_maxPlayer)
;
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
{
editContext->Class<CreateSessionRequest>("CreateSessionRequest", "The container for CreateSession request parameters")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
->DataElement(AZ::Edit::UIHandlers::Default, &CreateSessionRequest::m_creatorId,
"CreatorId", "A unique identifier for a player or entity creating the session")
->DataElement(AZ::Edit::UIHandlers::Default, &CreateSessionRequest::m_sessionProperties,
"SessionProperties", "A collection of custom properties for a session")
->DataElement(AZ::Edit::UIHandlers::Default, &CreateSessionRequest::m_sessionName,
"SessionName", "A descriptive label that is associated with a session")
->DataElement(AZ::Edit::UIHandlers::Default, &CreateSessionRequest::m_maxPlayer,
"MaxPlayer", "The maximum number of players that can be connected simultaneously to the session")
;
}
}
}
void SearchSessionsRequest::Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<SearchSessionsRequest>()
->Version(0)
->Field("filterExpression", &SearchSessionsRequest::m_filterExpression)
->Field("sortExpression", &SearchSessionsRequest::m_sortExpression)
->Field("maxResult", &SearchSessionsRequest::m_maxResult)
->Field("nextToken", &SearchSessionsRequest::m_nextToken)
;
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
{
editContext->Class<SearchSessionsRequest>("SearchSessionsRequest", "The container for SearchSessions request parameters")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
->DataElement(AZ::Edit::UIHandlers::Default, &SearchSessionsRequest::m_filterExpression,
"FilterExpression", "String containing the search criteria for the session search")
->DataElement(AZ::Edit::UIHandlers::Default, &SearchSessionsRequest::m_sortExpression,
"SortExpression", "Instructions on how to sort the search results")
->DataElement(AZ::Edit::UIHandlers::Default, &SearchSessionsRequest::m_maxResult,
"MaxResult", "The maximum number of results to return")
->DataElement(AZ::Edit::UIHandlers::Default, &SearchSessionsRequest::m_nextToken,
"NextToken", "A token that indicates the start of the next sequential page of results")
;
}
}
}
void SearchSessionsResponse::Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<SearchSessionsResponse>()
->Version(0)
->Field("sessionConfigs", &SearchSessionsResponse::m_sessionConfigs)
->Field("nextToken", &SearchSessionsResponse::m_nextToken)
;
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
{
editContext->Class<SearchSessionsResponse>("SearchSessionsResponse", "The container for SearchSession request results")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
->DataElement(AZ::Edit::UIHandlers::Default, &SearchSessionsResponse::m_sessionConfigs,
"SessionConfigs", "A collection of sessions that match the search criteria and sorted in specific order")
->DataElement(AZ::Edit::UIHandlers::Default, &SearchSessionsResponse::m_nextToken,
"NextToken", "A token that indicates the start of the next sequential page of results")
;
}
}
}
void JoinSessionRequest::Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<JoinSessionRequest>()
->Version(0)
->Field("sessionId", &JoinSessionRequest::m_sessionId)
->Field("playerId", &JoinSessionRequest::m_playerId)
->Field("playerData", &JoinSessionRequest::m_playerData)
;
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
{
editContext->Class<JoinSessionRequest>("JoinSessionRequest", "The container for JoinSession request parameters")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
->DataElement(AZ::Edit::UIHandlers::Default, &JoinSessionRequest::m_sessionId,
"SessionId", "A unique identifier for the session")
->DataElement(AZ::Edit::UIHandlers::Default, &JoinSessionRequest::m_playerId,
"PlayerId", "A unique identifier for a player. Player IDs are developer-defined")
->DataElement(AZ::Edit::UIHandlers::Default, &JoinSessionRequest::m_playerData,
"PlayerData", "Developer-defined information related to a player")
;
}
}
}
} // namespace Multiplayer