Integrating latest 47acbe8
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 <Source/NetworkEntity/INetworkEntityManager.h>
|
||||
#include <Source/NetworkEntity/EntityReplication/EntityReplicationManager.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
enum class ConnectionDataType
|
||||
{
|
||||
ServerToClient,
|
||||
ServerToServer
|
||||
};
|
||||
|
||||
class IConnectionData
|
||||
{
|
||||
public:
|
||||
virtual ~IConnectionData() = default;
|
||||
|
||||
//! Returns whether or not this is a ServerToClient or ServerToServer connection data instance.
|
||||
//! @return ConnectionDataType::ServerToClient or ConnectionDataType::ServerToServer
|
||||
virtual ConnectionDataType GetConnectionDataType() const = 0;
|
||||
|
||||
//! Returns the connection bound to this connection data instance.
|
||||
//! @return pointer to the connection bound to this connection data instance
|
||||
virtual AzNetworking::IConnection* GetConnection() const = 0;
|
||||
|
||||
//! Returns the EntityReplicationManager for this connection data instance.
|
||||
//! @return reference to the EntityReplicationManager for this connection data instance
|
||||
virtual EntityReplicationManager& GetReplicationManager() = 0;
|
||||
|
||||
//! Creates and manages sending updates to the remote endpoint.
|
||||
//! @param serverGameTimeMs current server game time in milliseconds
|
||||
virtual void Update(AZ::TimeMs serverGameTimeMs) = 0;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* 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 <Source/ConnectionData/ServerToClientConnectionData.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
static constexpr uint32_t Uint32Max = AZStd::numeric_limits<uint32_t>::max();
|
||||
|
||||
// This can be used to help mitigate client side performance when large numbers of entities are created off the network
|
||||
AZ_CVAR(uint32_t, sv_ClientMaxRemoteEntitiesPendingCreationCount, Uint32Max, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Maximum number of entities that we have sent to the client, but have not had a confirmation back from the client");
|
||||
AZ_CVAR(uint32_t, sv_ClientMaxRemoteEntitiesPendingCreationCountPostInit, Uint32Max, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Maximum number of entities that we will send to clients after gameplay has begun");
|
||||
AZ_CVAR(AZ::TimeMs, sv_ClientEntityReplicatorPendingRemovalTimeMs, AZ::TimeMs{ 10000 }, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "How long should wait prior to removing an entity for the client through a change in the replication window, entity deletes are still immediate");
|
||||
|
||||
ServerToClientConnectionData::ServerToClientConnectionData
|
||||
(
|
||||
AzNetworking::IConnection* connection,
|
||||
AzNetworking::IConnectionListener& connectionListener,
|
||||
NetworkEntityHandle controlledEntity
|
||||
)
|
||||
: m_connection(connection)
|
||||
, m_controlledEntityRemovedHandler([this](const ConstNetworkEntityHandle&) { OnControlledEntityRemove(); })
|
||||
, m_controlledEntityMigrationHandler([this](const ConstNetworkEntityHandle& entityHandle, HostId remoteHostId, AzNetworking::ConnectionId connectionId) { OnControlledEntityMigration(entityHandle, remoteHostId, connectionId); })
|
||||
, m_controlledEntity(controlledEntity)
|
||||
, m_entityReplicationManager(*connection, connectionListener, EntityReplicationManager::Mode::LocalServerToRemoteClient)
|
||||
{
|
||||
NetBindComponent* netBindComponent = m_controlledEntity.GetNetBindComponent();
|
||||
if (netBindComponent != nullptr)
|
||||
{
|
||||
netBindComponent->AddEntityStopEventHandler(m_controlledEntityRemovedHandler);
|
||||
netBindComponent->AddEntityMigrationEventHandler(m_controlledEntityMigrationHandler);
|
||||
}
|
||||
|
||||
m_entityReplicationManager.SetMaxRemoteEntitiesPendingCreationCount(sv_ClientMaxRemoteEntitiesPendingCreationCount);
|
||||
m_entityReplicationManager.SetEntityPendingRemovalMs(sv_ClientEntityReplicatorPendingRemovalTimeMs);
|
||||
}
|
||||
|
||||
ServerToClientConnectionData::~ServerToClientConnectionData()
|
||||
{
|
||||
m_entityReplicationManager.Clear(false);
|
||||
m_controlledEntityRemovedHandler.Disconnect();
|
||||
}
|
||||
|
||||
ConnectionDataType ServerToClientConnectionData::GetConnectionDataType() const
|
||||
{
|
||||
return ConnectionDataType::ServerToClient;
|
||||
}
|
||||
|
||||
AzNetworking::IConnection* ServerToClientConnectionData::GetConnection() const
|
||||
{
|
||||
return m_connection;
|
||||
}
|
||||
|
||||
EntityReplicationManager& ServerToClientConnectionData::GetReplicationManager()
|
||||
{
|
||||
return m_entityReplicationManager;
|
||||
}
|
||||
|
||||
void ServerToClientConnectionData::Update(AZ::TimeMs serverGameTimeMs)
|
||||
{
|
||||
if (CanSendUpdates())
|
||||
{
|
||||
NetBindComponent* netBindComponent = m_controlledEntity.GetNetBindComponent();
|
||||
// potentially false if we just migrated the player, if that is the case, don't send any more updates
|
||||
if (netBindComponent != nullptr && (netBindComponent->GetNetEntityRole() == NetEntityRole::ServerAuthority))
|
||||
{
|
||||
m_entityReplicationManager.SendUpdates(serverGameTimeMs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ServerToClientConnectionData::OnControlledEntityRemove()
|
||||
{
|
||||
m_connection->Disconnect(AzNetworking::DisconnectReason::TerminatedByServer, AzNetworking::TerminationEndpoint::Local);
|
||||
m_entityReplicationManager.Clear(false);
|
||||
m_controlledEntity.Reset();
|
||||
}
|
||||
|
||||
void ServerToClientConnectionData::OnControlledEntityMigration
|
||||
(
|
||||
[[maybe_unused]] const ConstNetworkEntityHandle& entityHandle,
|
||||
[[maybe_unused]] HostId remoteHostId,
|
||||
[[maybe_unused]] AzNetworking::ConnectionId connectionId
|
||||
)
|
||||
{
|
||||
//Multiplayer::ServerAddrInfo serverAddr;
|
||||
//if (gNovaGame->GetMultiplayerworkAgent().GetServerToServerNetwork().GetServerAddrInfoFromConnectionId(newConnectionId, serverAddr) == false)
|
||||
//{
|
||||
// AZLOG_WARN("MigrateClient::Failed to find servershard address, userID:%d", static_cast<uint32_t>(GetUserId()));
|
||||
// return;
|
||||
//}
|
||||
//
|
||||
//Multiplayer::GameTimePoint migratedClientGameTimePoint;
|
||||
//
|
||||
//if (m_ControlledEntity != nullptr)
|
||||
//{
|
||||
// if (const PlayerNetworkInputComponent::Authority* pComponent = Multiplayer::FindController<PlayerNetworkInputComponent::Authority>(m_ControlledEntity))
|
||||
// {
|
||||
// migratedClientGameTimePoint = pComponent->GetLastInputId().GetServerGameTimePoint();
|
||||
// }
|
||||
//}
|
||||
//
|
||||
// generate crypto-rand user identifier, send to both server and client so they can negotiate the autonomous entity to assume predictive control over after migration
|
||||
//const uint64_t randomUserIdentifier = 0;
|
||||
//
|
||||
//// Tell the server a new client is about to join
|
||||
//MultiplayerPackets::NotifyClientMigration notifyClientMigration(randomUserIdentifier);
|
||||
//gNovaGame->GetMultiplayerworkAgent().GetServerToServerNetwork().SendReliablePacket(newConnectionId, notifyClientMigration);
|
||||
//
|
||||
//// Tell the client who to join
|
||||
//MultiplayerPackets::ClientMigration clientMigration(randomUserIdentifier, serverAddr, migratedClientGameTimePoint);
|
||||
//GetConnection()->SendReliablePacket(clientMigration);
|
||||
//
|
||||
//m_controlledEntity = nullptr;
|
||||
//m_canSendUpdates = false;
|
||||
}
|
||||
|
||||
void ServerToClientConnectionData::OnGameplayStarted()
|
||||
{
|
||||
m_entityReplicationManager.SetMaxRemoteEntitiesPendingCreationCount(sv_ClientMaxRemoteEntitiesPendingCreationCountPostInit);
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Source/ConnectionData/IConnectionData.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
class ServerToClientConnectionData final
|
||||
: public IConnectionData
|
||||
{
|
||||
public:
|
||||
ServerToClientConnectionData
|
||||
(
|
||||
AzNetworking::IConnection* connection,
|
||||
AzNetworking::IConnectionListener& connectionListener,
|
||||
NetworkEntityHandle controlledEntity
|
||||
);
|
||||
~ServerToClientConnectionData() override;
|
||||
|
||||
//! IConnectionData interface
|
||||
//! @{
|
||||
ConnectionDataType GetConnectionDataType() const override;
|
||||
AzNetworking::IConnection* GetConnection() const override;
|
||||
EntityReplicationManager& GetReplicationManager() override;
|
||||
void Update(AZ::TimeMs serverGameTimeMs) override;
|
||||
//! @}
|
||||
|
||||
bool CanSendUpdates();
|
||||
|
||||
NetworkEntityHandle GetPrimaryPlayerEntity();
|
||||
const NetworkEntityHandle& GetPrimaryPlayerEntity() const;
|
||||
|
||||
private:
|
||||
void OnControlledEntityRemove();
|
||||
void OnControlledEntityMigration(const ConstNetworkEntityHandle& entityHandle, HostId remoteHostId, AzNetworking::ConnectionId connectionId);
|
||||
void OnGameplayStarted();
|
||||
|
||||
EntityReplicationManager m_entityReplicationManager;
|
||||
NetworkEntityHandle m_controlledEntity;
|
||||
EntityStopEvent::Handler m_controlledEntityRemovedHandler;
|
||||
EntityMigrationEvent::Handler m_controlledEntityMigrationHandler;
|
||||
AzNetworking::IConnection* m_connection = nullptr;
|
||||
bool m_canSendUpdates = true;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Source/ConnectionData/ServerToClientConnectionData.inl>
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
inline bool ServerToClientConnectionData::CanSendUpdates()
|
||||
{
|
||||
return m_canSendUpdates;
|
||||
}
|
||||
|
||||
inline NetworkEntityHandle ServerToClientConnectionData::GetPrimaryPlayerEntity()
|
||||
{
|
||||
return m_controlledEntity;
|
||||
}
|
||||
|
||||
inline const NetworkEntityHandle& ServerToClientConnectionData::GetPrimaryPlayerEntity() const
|
||||
{
|
||||
return m_controlledEntity;
|
||||
}
|
||||
}
|
||||
@@ -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 <Source/ConnectionData/ServerToServerConnectionData.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
AZ_CVAR(AZ::TimeMs, sv_DefaultNetworkEntityActivationTimeSliceMs, AZ::TimeMs{ 0 }, nullptr, AZ::ConsoleFunctorFlags::Null, "Max Ms to use to activate entities coming from the network, 0 means instantiate everything");
|
||||
AZ_CVAR(AZ::TimeMs, sv_ServerToServerReconnectDelayMs, AZ::TimeMs{ 1000 }, nullptr, AZ::ConsoleFunctorFlags::Null, "Number of milliseconds for delaying reconnecting that is based on sv_ServerNonceTimeoutMs");
|
||||
AZ_CVAR(uint32_t, sv_ServerMaxRemoteEntitiesPendingCreationCount, 512, nullptr, AZ::ConsoleFunctorFlags::Null, "Maximum number of entities that we have sent to the remote server, but have not had a confirmation back from the remote server");
|
||||
|
||||
ServerToServerConnectionData::ServerToServerConnectionData
|
||||
(
|
||||
AzNetworking::IConnection* connection,
|
||||
AzNetworking::IConnectionListener& connectionListener,
|
||||
const AzNetworking::IpAddress& serverAddress
|
||||
)
|
||||
: m_connection(connection)
|
||||
, m_serverAddress(serverAddress)
|
||||
, m_entityReplicationManager(*connection, connectionListener, EntityReplicationManager::Mode::LocalServerToRemoteServer)
|
||||
, m_connectEvent([this]() { OnConnectTimeout(); }, AZ::Name("Server to server connection timeout event"))
|
||||
{
|
||||
m_entityReplicationManager.SetRemoteHostId(InvalidHostId);// a_ServerAddrInfo.GetServerAddrInfo().GetShardId());
|
||||
m_entityReplicationManager.SetEntityActivationTimeSliceMs(sv_DefaultNetworkEntityActivationTimeSliceMs);
|
||||
m_entityReplicationManager.SetMaxRemoteEntitiesPendingCreationCount(sv_ServerMaxRemoteEntitiesPendingCreationCount);
|
||||
|
||||
if (connection->GetConnectionRole() == AzNetworking::ConnectionRole::Connector)
|
||||
{
|
||||
m_connectEvent.Enqueue(sv_ServerToServerReconnectDelayMs);
|
||||
}
|
||||
}
|
||||
|
||||
ServerToServerConnectionData::~ServerToServerConnectionData()
|
||||
{
|
||||
m_entityReplicationManager.Clear(false);
|
||||
}
|
||||
|
||||
ConnectionDataType ServerToServerConnectionData::GetConnectionDataType() const
|
||||
{
|
||||
return ConnectionDataType::ServerToServer;
|
||||
}
|
||||
|
||||
AzNetworking::IConnection* ServerToServerConnectionData::GetConnection() const
|
||||
{
|
||||
return m_connection;
|
||||
}
|
||||
|
||||
EntityReplicationManager& ServerToServerConnectionData::GetReplicationManager()
|
||||
{
|
||||
return m_entityReplicationManager;
|
||||
}
|
||||
|
||||
void ServerToServerConnectionData::Update(AZ::TimeMs serverGameTimeMs)
|
||||
{
|
||||
if (IsReady())
|
||||
{
|
||||
m_entityReplicationManager.SendUpdates(serverGameTimeMs);
|
||||
}
|
||||
}
|
||||
|
||||
HostId ServerToServerConnectionData::GetHostId() const
|
||||
{
|
||||
return InvalidHostId; // GetServerToServerAddrInfo().GetServerAddrInfo().GetShardId();
|
||||
}
|
||||
|
||||
void ServerToServerConnectionData::OnConnectTimeout()
|
||||
{
|
||||
AZ_Assert(m_connection->GetConnectionRole() == AzNetworking::ConnectionRole::Connector, "Timeout should only be queued for connectors");
|
||||
|
||||
if (m_connection->GetConnectionState() == AzNetworking::ConnectionState::Connecting)
|
||||
{
|
||||
//NovaGameHubServer::RequestNewNoncesToReconnect::Request request;
|
||||
//request.SetReconnectingServerShardId(GetShardId());
|
||||
//gNovaGame->GetNovaServiceAgent().DispatchRequest(request, 0, &gNovaGame->GetNovaServiceAgent());
|
||||
//AZLOG(Debug_UdpServerConnect, "Sent RequestNewNoncesToReconnect shardId:%u", static_cast<uint32_t>(GetShardId()));
|
||||
//
|
||||
//// Requeue in case we need to request additional nonces
|
||||
//m_ConnectTimedEvent.Enqueue(TimeMs(sv_ServerToServerReconnectDelayMs + sv_ServerNonceTimeoutMs));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 <Source/ConnectionData/IConnectionData.h>
|
||||
#include <Source/NetworkEntity/INetworkEntityManager.h>
|
||||
#include <Source/NetworkEntity/EntityReplication/EntityReplicationManager.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
class ServerToServerConnectionData
|
||||
: public IConnectionData
|
||||
{
|
||||
public:
|
||||
|
||||
//! Constructor
|
||||
//! @param connection connection to other server
|
||||
//! @param connectionListener the connection listener interface for handling packets
|
||||
//! @param serverAddress the address for the remote server
|
||||
ServerToServerConnectionData
|
||||
(
|
||||
AzNetworking::IConnection* connection,
|
||||
AzNetworking::IConnectionListener& connectionListener,
|
||||
const AzNetworking::IpAddress& serverAddress
|
||||
);
|
||||
~ServerToServerConnectionData() override;
|
||||
|
||||
//! IConnectionData interface
|
||||
//! @{
|
||||
ConnectionDataType GetConnectionDataType() const override;
|
||||
AzNetworking::IConnection* GetConnection() const override;
|
||||
EntityReplicationManager& GetReplicationManager() override;
|
||||
void Update(AZ::TimeMs serverGameTimeMs) override;
|
||||
//! @}
|
||||
|
||||
const AzNetworking::IpAddress& GetServerAddress() const;
|
||||
|
||||
bool IsReady();
|
||||
void SetIsReady(bool isReady);
|
||||
|
||||
//! Get my server shard Id
|
||||
//! @return return shard Id
|
||||
HostId GetHostId() const;
|
||||
|
||||
private:
|
||||
void OnConnectTimeout();
|
||||
|
||||
AzNetworking::IpAddress m_serverAddress;
|
||||
AzNetworking::IConnection* m_connection = nullptr;
|
||||
EntityReplicationManager m_entityReplicationManager;
|
||||
AZ::ScheduledEvent m_connectEvent; //< Connection timeout handler
|
||||
bool m_isReady = false;
|
||||
|
||||
AZ_DISABLE_COPY_MOVE(ServerToServerConnectionData);
|
||||
};
|
||||
}
|
||||
|
||||
#include <Source/ConnectionData/ServerToServerConnectionData.inl>
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
inline const AzNetworking::IpAddress& ServerToServerConnectionData::GetServerAddress() const
|
||||
{
|
||||
return m_serverAddress;
|
||||
}
|
||||
|
||||
inline bool ServerToServerConnectionData::IsReady()
|
||||
{
|
||||
return m_isReady;
|
||||
}
|
||||
|
||||
inline void ServerToServerConnectionData::SetIsReady(bool isReady)
|
||||
{
|
||||
m_isReady = isReady;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user