Add handling for session provider ticket
This commit is contained in:
@@ -46,7 +46,7 @@ namespace AzFramework
|
||||
};
|
||||
|
||||
//! ISessionHandlingClientRequests
|
||||
//! Requests made to the client to manage their connection to a session
|
||||
//! Requests made to the client to manage their membership in a session
|
||||
class ISessionHandlingClientRequests
|
||||
{
|
||||
public:
|
||||
@@ -87,11 +87,11 @@ namespace AzFramework
|
||||
// Retrieves the file location of a pem-encoded TLS certificate for Client to Server communication
|
||||
// @return If successful, returns the file location of TLS certificate file; if not successful, returns
|
||||
// empty string.
|
||||
virtual AZStd::string GetExternalSessionCertificate() = 0;
|
||||
virtual AZ::IO::Path GetExternalSessionCertificate() = 0;
|
||||
|
||||
// Retrieves the file location of a pem-encoded TLS certificate for Server to Server communication
|
||||
// @return If successful, returns the file location of TLS certificate file; if not successful, returns
|
||||
// empty string.
|
||||
virtual AZStd::string GetInternalSessionCertificate() = 0;
|
||||
virtual AZ::IO::Path GetInternalSessionCertificate() = 0;
|
||||
};
|
||||
} // namespace AzFramework
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
<Packet Name="Connect" Desc="Client connection packet, on success the server will reply with an Accept">
|
||||
<Member Type="uint16_t" Name="networkProtocolVersion" Init="0" />
|
||||
<Member Type="Multiplayer::LongNetworkString" Name="ticket" />
|
||||
</Packet>
|
||||
|
||||
<Packet Name="Accept" Desc="Server accept packet">
|
||||
|
||||
@@ -21,10 +21,12 @@ namespace Multiplayer
|
||||
ClientToServerConnectionData::ClientToServerConnectionData
|
||||
(
|
||||
AzNetworking::IConnection* connection,
|
||||
AzNetworking::IConnectionListener& connectionListener
|
||||
AzNetworking::IConnectionListener& connectionListener,
|
||||
AZStd::string providerTicket
|
||||
)
|
||||
: m_connection(connection)
|
||||
, m_entityReplicationManager(*connection, connectionListener, EntityReplicationManager::Mode::LocalClientToRemoteServer)
|
||||
, m_providerTicket(providerTicket)
|
||||
{
|
||||
m_entityReplicationManager.SetMaxRemoteEntitiesPendingCreationCount(cl_ClientMaxRemoteEntitiesPendingCreationCount);
|
||||
m_entityReplicationManager.SetEntityPendingRemovalMs(cl_ClientEntityReplicatorPendingRemovalTimeMs);
|
||||
|
||||
@@ -24,7 +24,8 @@ namespace Multiplayer
|
||||
ClientToServerConnectionData
|
||||
(
|
||||
AzNetworking::IConnection* connection,
|
||||
AzNetworking::IConnectionListener& connectionListener
|
||||
AzNetworking::IConnectionListener& connectionListener,
|
||||
AZStd::string providerTicket = ""
|
||||
);
|
||||
~ClientToServerConnectionData() override;
|
||||
|
||||
@@ -38,8 +39,11 @@ namespace Multiplayer
|
||||
void SetCanSendUpdates(bool canSendUpdates) override;
|
||||
//! @}
|
||||
|
||||
AZStd::string GetProviderTicket() const;
|
||||
|
||||
private:
|
||||
EntityReplicationManager m_entityReplicationManager;
|
||||
AZStd::string m_providerTicket;
|
||||
AzNetworking::IConnection* m_connection = nullptr;
|
||||
bool m_canSendUpdates = true;
|
||||
};
|
||||
|
||||
@@ -21,4 +21,9 @@ namespace Multiplayer
|
||||
{
|
||||
m_canSendUpdates = canSendUpdates;
|
||||
}
|
||||
|
||||
inline AZStd::string ClientToServerConnectionData::GetProviderTicket() const
|
||||
{
|
||||
return m_providerTicket;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ namespace Multiplayer
|
||||
|
||||
NetworkEntityHandle GetPrimaryPlayerEntity();
|
||||
const NetworkEntityHandle& GetPrimaryPlayerEntity() const;
|
||||
AZStd::string GetProviderTicket() const;
|
||||
void SetProviderTicket(AZStd::string);
|
||||
|
||||
private:
|
||||
void OnControlledEntityRemove();
|
||||
@@ -51,6 +53,7 @@ namespace Multiplayer
|
||||
NetworkEntityHandle m_controlledEntity;
|
||||
EntityStopEvent::Handler m_controlledEntityRemovedHandler;
|
||||
EntityServerMigrationEvent::Handler m_controlledEntityMigrationHandler;
|
||||
AZStd::string m_ticket;
|
||||
AzNetworking::IConnection* m_connection = nullptr;
|
||||
bool m_canSendUpdates = false;
|
||||
};
|
||||
|
||||
@@ -32,4 +32,14 @@ namespace Multiplayer
|
||||
{
|
||||
return m_controlledEntity;
|
||||
}
|
||||
|
||||
inline AZStd::string ServerToClientConnectionData::GetProviderTicket() const
|
||||
{
|
||||
return m_ticket;
|
||||
}
|
||||
|
||||
inline void ServerToClientConnectionData::SetProviderTicket(AZStd::string ticket)
|
||||
{
|
||||
m_ticket = ticket;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +176,13 @@ namespace Multiplayer
|
||||
INetworkInterface* networkInterface = AZ::Interface<INetworking>::Get()->RetrieveNetworkInterface(AZ::Name(MPNetworkInterfaceName));
|
||||
|
||||
const IpAddress ipAddress(config.m_ipAddress.c_str(), config.m_port, networkInterface->GetType());
|
||||
networkInterface->Connect(ipAddress);
|
||||
ConnectionId connectionId = networkInterface->Connect(ipAddress);
|
||||
|
||||
AzNetworking::IConnection* connection = networkInterface->GetConnectionSet().GetConnection(connectionId);
|
||||
if (connection->GetUserData() == nullptr) // Only add user data if the connect event handler has not already done so
|
||||
{
|
||||
connection->SetUserData(new ClientToServerConnectionData(connection, *this, config.m_playerSessionId));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -196,18 +202,23 @@ namespace Multiplayer
|
||||
bool MultiplayerSystemComponent::OnCreateSessionBegin(const AzFramework::SessionConfig& sessionConfig)
|
||||
{
|
||||
// Check if session manager has a certificate for us and pass it along if so
|
||||
AZ::CVarFixedString externalCertPath = AZ::CVarFixedString(AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get()->GetExternalSessionCertificate());
|
||||
if (!externalCertPath.empty())
|
||||
if (AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get() != nullptr)
|
||||
{
|
||||
AZ::CVarFixedString commandString = "net_SslExternalCertificateFile " + externalCertPath;
|
||||
AZ::Interface<AZ::IConsole>::Get()->PerformCommand(commandString.c_str());
|
||||
}
|
||||
AZ::CVarFixedString externalCertPath = AZ::CVarFixedString(
|
||||
AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get()->GetExternalSessionCertificate().c_str());
|
||||
if (!externalCertPath.empty())
|
||||
{
|
||||
AZ::CVarFixedString commandString = "net_SslExternalCertificateFile " + externalCertPath;
|
||||
AZ::Interface<AZ::IConsole>::Get()->PerformCommand(commandString.c_str());
|
||||
}
|
||||
|
||||
AZ::CVarFixedString internalCertPath = AZ::CVarFixedString(AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get()->GetInternalSessionCertificate());
|
||||
if (!internalCertPath.empty())
|
||||
{
|
||||
AZ::CVarFixedString commandString = "net_SslInternalCertificateFile " + internalCertPath;
|
||||
AZ::Interface<AZ::IConsole>::Get()->PerformCommand(commandString.c_str());
|
||||
AZ::CVarFixedString internalCertPath = AZ::CVarFixedString(
|
||||
AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get()->GetInternalSessionCertificate().c_str());
|
||||
if (!internalCertPath.empty())
|
||||
{
|
||||
AZ::CVarFixedString commandString = "net_SslInternalCertificateFile " + internalCertPath;
|
||||
AZ::Interface<AZ::IConsole>::Get()->PerformCommand(commandString.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
Multiplayer::MultiplayerAgentType serverType = sv_isDedicated ? MultiplayerAgentType::DedicatedServer : MultiplayerAgentType::ClientServer;
|
||||
@@ -370,6 +381,17 @@ namespace Multiplayer
|
||||
{
|
||||
if (connection->SendReliablePacket(MultiplayerPackets::Accept(InvalidHostId, sv_map)))
|
||||
{
|
||||
// Validate our session with the provider if any
|
||||
if (AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get() != nullptr)
|
||||
{
|
||||
AzFramework::PlayerConnectionConfig config;
|
||||
config.m_playerConnectionId = aznumeric_cast<uint32_t>(connection->GetConnectionId());
|
||||
config.m_playerSessionId = packet.GetTicket();
|
||||
AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get()->ValidatePlayerJoinSession(config);
|
||||
|
||||
reinterpret_cast<ServerToClientConnectionData*>(connection->GetUserData())->SetProviderTicket(packet.GetTicket().c_str());
|
||||
}
|
||||
|
||||
// Sync our console
|
||||
ConsoleReplicator consoleReplicator(connection);
|
||||
AZ::Interface<AZ::IConsole>::Get()->VisitRegisteredFunctors([&consoleReplicator](AZ::ConsoleFunctorBase* functor) { consoleReplicator.Visit(functor); });
|
||||
@@ -525,16 +547,17 @@ namespace Multiplayer
|
||||
if (connection->GetConnectionRole() == ConnectionRole::Connector)
|
||||
{
|
||||
AZLOG_INFO("New outgoing connection to remote address: %s", connection->GetRemoteAddress().GetString().c_str());
|
||||
connection->SendReliablePacket(MultiplayerPackets::Connect(0));
|
||||
AZ::CVarFixedString providerTicket;
|
||||
if (connection->GetUserData() != nullptr)
|
||||
{
|
||||
providerTicket = reinterpret_cast<ClientToServerConnectionData*>(connection->GetUserData())->GetProviderTicket();
|
||||
}
|
||||
connection->SendReliablePacket(MultiplayerPackets::Connect(0, providerTicket));
|
||||
}
|
||||
else
|
||||
{
|
||||
AZLOG_INFO("New incoming connection from remote address: %s", connection->GetRemoteAddress().GetString().c_str());
|
||||
m_connAcquiredEvent.Signal(datum);
|
||||
AzFramework::PlayerConnectionConfig config;
|
||||
config.m_playerConnectionId = aznumeric_cast<uint32_t>(connection->GetConnectionId());
|
||||
config.m_playerSessionId = AZStd::to_string(config.m_playerConnectionId);
|
||||
AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get()->ValidatePlayerJoinSession(config);
|
||||
}
|
||||
|
||||
// Hosts will spawn a new default player prefab for the user that just connected
|
||||
@@ -600,20 +623,22 @@ namespace Multiplayer
|
||||
// Signal to session management that a user has left the server
|
||||
if (m_agentType == MultiplayerAgentType::DedicatedServer || m_agentType == MultiplayerAgentType::ClientServer)
|
||||
{
|
||||
if (connection->GetConnectionRole() == ConnectionRole::Connector)
|
||||
if (AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get() != nullptr &&
|
||||
connection->GetConnectionRole() == ConnectionRole::Connector)
|
||||
{
|
||||
AzFramework::PlayerConnectionConfig config;
|
||||
config.m_playerConnectionId = aznumeric_cast<uint32_t>(connection->GetConnectionId());
|
||||
config.m_playerSessionId = AZStd::to_string(config.m_playerConnectionId);
|
||||
config.m_playerSessionId = reinterpret_cast<ServerToClientConnectionData*>(connection->GetUserData())->GetProviderTicket();
|
||||
AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get()->HandlePlayerLeaveSession(config);
|
||||
}
|
||||
}
|
||||
|
||||
// Signal to session management when there are no remaining players in a dedicated server for potential cleanup
|
||||
// We avoid this for client server as the host itself is a user
|
||||
if (m_agentType == MultiplayerAgentType::DedicatedServer)
|
||||
if (m_agentType == MultiplayerAgentType::DedicatedServer && connection->GetConnectionRole() == ConnectionRole::Connector)
|
||||
{
|
||||
if (m_networkInterface->GetConnectionSet().GetConnectionCount() == 0)
|
||||
if (AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get() != nullptr
|
||||
&& m_networkInterface->GetConnectionSet().GetConnectionCount() == 0)
|
||||
{
|
||||
AZ::Interface<AzFramework::ISessionHandlingProviderRequests>::Get()->HandleDestroySession();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user