MultiplayerEditorConnection.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <Source/AutoGen/MultiplayerEditor.AutoPacketDispatcher.h>
  10. #include <AzCore/IO/ByteContainerStream.h>
  11. #include <AzCore/Settings/SettingsRegistry.h>
  12. #include <AzFramework/Spawnable/InMemorySpawnableAssetContainer.h>
  13. #include <AzNetworking/ConnectionLayer/IConnectionListener.h>
  14. namespace AzNetworking
  15. {
  16. class INetworkInterface;
  17. }
  18. namespace Multiplayer
  19. {
  20. //! MultiplayerEditorConnection is a connection listener to synchronize the Editor and a local server it launches
  21. class MultiplayerEditorConnection final
  22. : public AzNetworking::IConnectionListener
  23. {
  24. public:
  25. MultiplayerEditorConnection();
  26. ~MultiplayerEditorConnection();
  27. bool HandleRequest(AzNetworking::IConnection* connection, const AzNetworking::IPacketHeader& packetHeader, MultiplayerEditorPackets::EditorServerReadyForLevelData& packet);
  28. bool HandleRequest(AzNetworking::IConnection* connection, const AzNetworking::IPacketHeader& packetHeader, MultiplayerEditorPackets::EditorServerLevelData& packet);
  29. bool HandleRequest(AzNetworking::IConnection* connection, const AzNetworking::IPacketHeader& packetHeader, MultiplayerEditorPackets::EditorServerReady& packet);
  30. //! IConnectionListener interface
  31. //! @{
  32. AzNetworking::ConnectResult ValidateConnect(const AzNetworking::IpAddress& remoteAddress, const AzNetworking::IPacketHeader& packetHeader, AzNetworking::ISerializer& serializer) override;
  33. void OnConnect(AzNetworking::IConnection* connection) override;
  34. AzNetworking::PacketDispatchResult OnPacketReceived(AzNetworking::IConnection* connection, const AzNetworking::IPacketHeader& packetHeader, AzNetworking::ISerializer& serializer) override;
  35. void OnPacketLost([[maybe_unused]]AzNetworking::IConnection* connection, [[maybe_unused]]AzNetworking::PacketId packetId) override {}
  36. void OnDisconnect([[maybe_unused]]AzNetworking::IConnection* connection, [[maybe_unused]]AzNetworking::DisconnectReason reason, [[maybe_unused]]AzNetworking::TerminationEndpoint endpoint) override {}
  37. //! @}
  38. private:
  39. void ActivateDedicatedEditorServer() const;
  40. AzNetworking::INetworkInterface* m_networkEditorInterface = nullptr;
  41. AZStd::vector<uint8_t> m_buffer;
  42. AZ::IO::ByteContainerStream<AZStd::vector<uint8_t>> m_byteStream;
  43. mutable bool m_isActivated = false;
  44. AZ::SettingsRegistryInterface::NotifyEventHandler m_componentApplicationLifecycleHandler;
  45. AZStd::unique_ptr<AzFramework::InMemorySpawnableAssetContainer> m_inMemorySpawnableAssetContainer = nullptr;
  46. };
  47. }