Integrate parts of Session Server API
This commit is contained in:
@@ -29,6 +29,8 @@
|
||||
#include <AzCore/Asset/AssetCommon.h>
|
||||
#include <AzCore/Asset/AssetManagerBus.h>
|
||||
#include <AzCore/Utils/Utils.h>
|
||||
#include <AzFramework/Session/ISessionRequests.h>
|
||||
#include <AzFramework/Session/SessionConfig.h>
|
||||
#include <AzFramework/Spawnable/Spawnable.h>
|
||||
#include <AzNetworking/Framework/INetworking.h>
|
||||
|
||||
@@ -142,6 +144,7 @@ namespace Multiplayer
|
||||
void MultiplayerSystemComponent::Activate()
|
||||
{
|
||||
AZ::TickBus::Handler::BusConnect();
|
||||
AzFramework::SessionNotificationBus::Handler::BusConnect();
|
||||
m_networkInterface = AZ::Interface<INetworking>::Get()->CreateNetworkInterface(AZ::Name(MPNetworkInterfaceName), sv_protocol, TrustZone::ExternalClientToServer, *this);
|
||||
m_consoleCommandHandler.Connect(AZ::Interface<AZ::IConsole>::Get()->GetConsoleCommandInvokedEvent());
|
||||
AZ::Interface<IMultiplayer>::Register(this);
|
||||
@@ -153,9 +156,34 @@ namespace Multiplayer
|
||||
void MultiplayerSystemComponent::Deactivate()
|
||||
{
|
||||
AZ::Interface<IMultiplayer>::Unregister(this);
|
||||
AzFramework::SessionNotificationBus::Handler::BusDisconnect();
|
||||
AZ::TickBus::Handler::BusDisconnect();
|
||||
}
|
||||
|
||||
bool MultiplayerSystemComponent::OnSessionHealthCheck()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MultiplayerSystemComponent::OnCreateSessionBegin(const AzFramework::SessionConfig& sessionConfig)
|
||||
{
|
||||
Multiplayer::MultiplayerAgentType serverType = sv_isDedicated ? MultiplayerAgentType::DedicatedServer : MultiplayerAgentType::ClientServer;
|
||||
AZ::Interface<IMultiplayer>::Get()->InitializeMultiplayer(serverType);
|
||||
return m_networkInterface->Listen(sessionConfig.m_port);
|
||||
}
|
||||
|
||||
bool MultiplayerSystemComponent::OnDestroySessionBegin()
|
||||
{
|
||||
bool disconnectSuccessful = true;
|
||||
IConnectionSet& connectionSet = m_networkInterface->GetConnectionSet();
|
||||
connectionSet.VisitConnections([&disconnectSuccessful](IConnection& connection)
|
||||
{
|
||||
bool didDisconnect = connection.Disconnect(DisconnectReason::TerminatedByServer, TerminationEndpoint::Remote);
|
||||
disconnectSuccessful = disconnectSuccessful && didDisconnect;
|
||||
});
|
||||
return disconnectSuccessful;
|
||||
}
|
||||
|
||||
void MultiplayerSystemComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
|
||||
{
|
||||
AZ::TimeMs deltaTimeMs = aznumeric_cast<AZ::TimeMs>(static_cast<int32_t>(deltaTime * 1000.0f));
|
||||
|
||||
@@ -25,8 +25,14 @@
|
||||
#include <AzCore/IO/ByteContainerStream.h>
|
||||
#include <AzCore/Threading/ThreadSafeDeque.h>
|
||||
#include <AzCore/std/string/string.h>
|
||||
#include <AzFramework/Session/SessionNotifications.h>
|
||||
#include <AzNetworking/ConnectionLayer/IConnectionListener.h>
|
||||
|
||||
namespace AzFramework
|
||||
{
|
||||
struct SessionConfig;
|
||||
}
|
||||
|
||||
namespace AzNetworking
|
||||
{
|
||||
class INetworkInterface;
|
||||
@@ -38,6 +44,7 @@ namespace Multiplayer
|
||||
class MultiplayerSystemComponent final
|
||||
: public AZ::Component
|
||||
, public AZ::TickBus::Handler
|
||||
, public AzFramework::SessionNotificationBus::Handler
|
||||
, public AzNetworking::IConnectionListener
|
||||
, public IMultiplayer
|
||||
{
|
||||
@@ -58,6 +65,13 @@ namespace Multiplayer
|
||||
void Deactivate() override;
|
||||
//! @}
|
||||
|
||||
//! AzFramework::SessionNotificationBus::Handler overrides.
|
||||
//! @{
|
||||
bool OnSessionHealthCheck() override;
|
||||
bool OnCreateSessionBegin(const AzFramework::SessionConfig& sessionConfig) override;
|
||||
bool OnDestroySessionBegin() override;
|
||||
//! @}
|
||||
|
||||
//! AZ::TickBus::Handler overrides.
|
||||
//! @{
|
||||
void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
|
||||
|
||||
Reference in New Issue
Block a user