MultiplayerSampleSystemComponent.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #pragma once
  13. #include <AzCore/Component/Component.h>
  14. #include <AzCore/Component/TickBus.h>
  15. #include <AzNetworking/ConnectionLayer/IConnectionListener.h>
  16. #include "Source/AutoGen/MultiplayerSample.AutoPacketDispatcher.h"
  17. namespace AzNetworking
  18. {
  19. class INetworkInterface;
  20. }
  21. namespace MultiplayerSample
  22. {
  23. class MultiplayerSampleSystemComponent
  24. : public AZ::Component
  25. , public AZ::TickBus::Handler
  26. , public AzNetworking::IConnectionListener
  27. {
  28. public:
  29. AZ_COMPONENT(MultiplayerSampleSystemComponent, "{7BF68D79-E870-44B5-853A-BA68FF4F0B90}");
  30. static void Reflect(AZ::ReflectContext* context);
  31. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  32. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  33. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  34. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  35. bool HandleRequest(AzNetworking::IConnection* connection, const AzNetworking::IPacketHeader& packetHeader, const MultiplayerSamplePackets::Sample& packet);
  36. protected:
  37. ////////////////////////////////////////////////////////////////////////
  38. // AZ::Component interface implementation
  39. void Init() override;
  40. void Activate() override;
  41. void Deactivate() override;
  42. ////////////////////////////////////////////////////////////////////////
  43. // AZ::TickBus::Handler overrides
  44. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  45. int GetTickOrder() override;
  46. ////////////////////////////////////////////////////////////////////////
  47. ////////////////////////////////////////////////////////////////////////
  48. // IConnectionListener interface
  49. AzNetworking::ConnectResult ValidateConnect(const AzNetworking::IpAddress& remoteAddress, const AzNetworking::IPacketHeader& packetHeader, AzNetworking::ISerializer& serializer) override;
  50. void OnConnect(AzNetworking::IConnection* connection) override;
  51. bool OnPacketReceived(AzNetworking::IConnection* connection, const AzNetworking::IPacketHeader& packetHeader, AzNetworking::ISerializer& serializer) override;
  52. void OnPacketLost(AzNetworking::IConnection* connection, AzNetworking::PacketId packetId) override;
  53. void OnDisconnect(AzNetworking::IConnection* connection, AzNetworking::DisconnectReason reason, AzNetworking::TerminationEndpoint endpoint) override;
  54. ////////////////////////////////////////////////////////////////////////
  55. private:
  56. AzNetworking::INetworkInterface* m_networkInterface = nullptr;
  57. };
  58. }