Adding logs to dedicated-server start up (unable to use for automated testing just yet since remote console cant be connected that early). Adding pytest check to make sure AutomatedTesting.ServerLauncher is running. Moved sveditor_port to MultiplayerEditorConnection since it was never actually getting used when it was in EditorSystemComponent (dedicated servers dont know about editor)

Signed-off-by: Gene Walters <genewalt@amazon.com>
This commit is contained in:
Gene Walters
2021-11-01 13:01:59 -07:00
parent 2f38873e03
commit fa32940205
4 changed files with 42 additions and 30 deletions
@@ -26,6 +26,7 @@ namespace Multiplayer
using namespace AzNetworking;
AZ_CVAR(bool, editorsv_isDedicated, false, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Whether to init as a server expecting data from an Editor. Do not modify unless you're sure of what you're doing.");
AZ_CVAR(uint16_t, editorsv_port, DefaultServerEditorPort, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "The port that the multiplayer editor gem will bind to for traffic.");
MultiplayerEditorConnection::MultiplayerEditorConnection()
: m_byteStream(&m_buffer)
@@ -33,33 +34,37 @@ namespace Multiplayer
m_networkEditorInterface = AZ::Interface<INetworking>::Get()->CreateNetworkInterface(
AZ::Name(MpEditorInterfaceName), ProtocolType::Tcp, TrustZone::ExternalClientToServer, *this);
m_networkEditorInterface->SetTimeoutMs(AZ::TimeMs{ 0 }); // Disable timeouts on this network interface
if (editorsv_isDedicated)
ActivateDedicatedEditorServer();
}
void MultiplayerEditorConnection::ActivateDedicatedEditorServer() const
{
if (m_isActivated || !editorsv_isDedicated)
{
uint16_t editorsv_port = DefaultServerEditorPort;
const auto console = AZ::Interface<AZ::IConsole>::Get();
if (console->GetCvarValue("editorsv_port", editorsv_port) != AZ::GetValueResult::Success)
{
AZ_Assert( false,
"MultiplayerEditorConnection failed! Could not find the editorsv_port cvar; we may not be able to connect to the editor's port! Please update this code to use a valid cvar!")
}
return;
}
m_isActivated = true;
AZ_Assert(m_networkEditorInterface, "MP Editor Network Interface was unregistered before Editor Server could start listening.")
AZ_Assert(m_networkEditorInterface, "MP Editor Network Interface was unregistered before Editor Server could start listening.")
// Check if there's already an Editor out there waiting to connect
const ConnectionId editorServerToEditorConnectionId =
m_networkEditorInterface->Connect(IpAddress(LocalHost.data(), editorsv_port, ProtocolType::Tcp));
// Check if there's already an Editor out there waiting to connect
const ConnectionId editorServerToEditorConnectionId = m_networkEditorInterface->Connect(IpAddress(LocalHost.data(), editorsv_port, ProtocolType::Tcp));
// If there wasn't an Editor waiting for this server to start, then assume this is an editor-server launched by hand... listen and wait for the editor to request a connection
if (editorServerToEditorConnectionId == InvalidConnectionId)
{
m_networkEditorInterface->Listen(editorsv_port);
}
else
{
m_networkEditorInterface->SendReliablePacket(editorServerToEditorConnectionId, MultiplayerEditorPackets::EditorServerReadyForLevelData());
}
// If there wasn't an Editor waiting for this server to start, then assume this is an editor-server launched by hand... listen
// and wait for the editor to request a connection
if (editorServerToEditorConnectionId == InvalidConnectionId)
{
m_networkEditorInterface->Listen(editorsv_port);
AZ_Printf("MultiplayerEditorConnection", "Editor-server activation did not find an editor in game-mode willing to connect; we'll instead wait and listen for an editor trying to connect to us.")
}
else
{
m_networkEditorInterface->SendReliablePacket(editorServerToEditorConnectionId, MultiplayerEditorPackets::EditorServerReadyForLevelData());
AZ_Printf("MultiplayerEditorConnection", "Editor-server activation has found and connected to the editor.")
}
}
bool MultiplayerEditorConnection::HandleRequest
(
[[maybe_unused]] AzNetworking::IConnection* connection,
@@ -136,7 +141,7 @@ namespace Multiplayer
networkInterface->Listen(sv_port);
AZLOG_INFO("Editor Server completed asset receive, responding to Editor...");
AZLOG_INFO("Editor Server completed receiving the editor's level assets, responding to Editor...");
return connection->SendReliablePacket(MultiplayerEditorPackets::EditorServerReady());
}
@@ -45,9 +45,11 @@ namespace Multiplayer
//! @}
private:
void ActivateDedicatedEditorServer() const;
AzNetworking::INetworkInterface* m_networkEditorInterface = nullptr;
AZStd::vector<uint8_t> m_buffer;
AZ::IO::ByteContainerStream<AZStd::vector<uint8_t>> m_byteStream;
mutable bool m_isActivated = false;
};
}
@@ -37,10 +37,10 @@ namespace Multiplayer
AZ_CVAR(AZ::CVarFixedString, editorsv_process, "", nullptr, AZ::ConsoleFunctorFlags::DontReplicate,
"The server executable that should be run. Empty to use the current project's ServerLauncher");
AZ_CVAR(AZ::CVarFixedString, editorsv_serveraddr, AZ::CVarFixedString(LocalHost), nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "The address of the server to connect to");
AZ_CVAR(uint16_t, editorsv_port, DefaultServerEditorPort, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "The port that the multiplayer editor gem will bind to for traffic");
AZ_CVAR(AZ::CVarFixedString, editorsv_rhi_override, "", nullptr, AZ::ConsoleFunctorFlags::DontReplicate,
"Override the default rendering hardware interface (rhi) when launching the Editor server. For example, you may be running an Editor using 'dx12', but want to launch a headless server using 'null'. If empty the server will launch using the same rhi as the Editor.");
AZ_CVAR_EXTERNED(uint16_t, editorsv_port);
//////////////////////////////////////////////////////////////////////////
void PyEnterGameMode()
{
@@ -298,7 +298,7 @@ namespace Multiplayer
"Editor multiplayer game-mode failed! Could not connect to an editor-server. editorsv_launch is false so we're assuming you're running your own editor-server at editorsv_serveraddr(%s) on editorsv_port(%i). "
"Either set editorsv_launch=true so the editor launches an editor-server for you, or launch your own editor-server by hand before entering game-mode. Remember editor-servers must use editorsv_isDedicated=true.",
remoteAddress.c_str(),
static_cast < uint16_t>(editorsv_port))
static_cast<uint16_t>(editorsv_port))
return;
}