MultiplayerSampleSystemComponent.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #include <AzCore/Serialization/SerializeContext.h>
  13. #include <AzCore/Serialization/EditContext.h>
  14. #include <AzCore/Serialization/EditContextConstants.inl>
  15. #include <AzNetworking/Framework/INetworking.h>
  16. #include "MultiplayerSampleSystemComponent.h"
  17. #include <Source/AutoGen/AutoComponentTypes.h>
  18. namespace MultiplayerSample
  19. {
  20. using namespace AzNetworking;
  21. static const AZStd::string_view s_networkInterfaceName("MultiplayerSampleInterface");
  22. void MultiplayerSampleSystemComponent::Reflect(AZ::ReflectContext* context)
  23. {
  24. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  25. {
  26. serialize->Class<MultiplayerSampleSystemComponent, AZ::Component>()
  27. ->Version(0)
  28. ;
  29. if (AZ::EditContext* ec = serialize->GetEditContext())
  30. {
  31. ec->Class<MultiplayerSampleSystemComponent>("MultiplayerSample", "[Description of functionality provided by this System Component]")
  32. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  33. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System"))
  34. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  35. ;
  36. }
  37. }
  38. }
  39. void MultiplayerSampleSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  40. {
  41. provided.push_back(AZ_CRC_CE("MultiplayerSampleService"));
  42. }
  43. void MultiplayerSampleSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  44. {
  45. incompatible.push_back(AZ_CRC_CE("MultiplayerSampleService"));
  46. }
  47. void MultiplayerSampleSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  48. {
  49. required.push_back(AZ_CRC_CE("NetworkingService"));
  50. required.push_back(AZ_CRC_CE("MultiplayerService"));
  51. }
  52. void MultiplayerSampleSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  53. {
  54. AZ_UNUSED(dependent);
  55. }
  56. void MultiplayerSampleSystemComponent::Init()
  57. {
  58. ;
  59. }
  60. void MultiplayerSampleSystemComponent::Activate()
  61. {
  62. AZ::TickBus::Handler::BusConnect();
  63. //! Register our gems multiplayer components to assign NetComponentIds
  64. RegisterMultiplayerComponents();
  65. }
  66. void MultiplayerSampleSystemComponent::Deactivate()
  67. {
  68. AZ::TickBus::Handler::BusDisconnect();
  69. }
  70. void MultiplayerSampleSystemComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
  71. {
  72. ;
  73. }
  74. int MultiplayerSampleSystemComponent::GetTickOrder()
  75. {
  76. // Tick immediately after the multiplayer system component
  77. return AZ::TICK_PLACEMENT + 2;
  78. }
  79. bool MultiplayerSampleSystemComponent::HandleRequest([[maybe_unused]] IConnection* connection,
  80. [[maybe_unused]] const IPacketHeader& packetHeader, [[maybe_unused]] const MultiplayerSamplePackets::Sample& packet)
  81. {
  82. return true;
  83. }
  84. ConnectResult MultiplayerSampleSystemComponent::ValidateConnect([[maybe_unused]] const IpAddress& remoteAddress,
  85. [[maybe_unused]] const IPacketHeader& packetHeader, [[maybe_unused]] ISerializer& serializer)
  86. {
  87. return ConnectResult::Accepted;
  88. }
  89. void MultiplayerSampleSystemComponent::OnConnect([[maybe_unused]] IConnection* connection)
  90. {
  91. ;
  92. }
  93. bool MultiplayerSampleSystemComponent::OnPacketReceived([[maybe_unused]] IConnection* connection, [[maybe_unused]] const IPacketHeader& packetHeader, [[maybe_unused]] ISerializer& serializer)
  94. {
  95. return true;
  96. }
  97. void MultiplayerSampleSystemComponent::OnPacketLost([[maybe_unused]] IConnection* connection, [[maybe_unused]] PacketId packetId)
  98. {
  99. ;
  100. }
  101. void MultiplayerSampleSystemComponent::OnDisconnect(IConnection* connection, [[maybe_unused]] DisconnectReason reason, [[maybe_unused]] AzNetworking::TerminationEndpoint endpoint)
  102. {
  103. AZLOG_INFO("Disconnected from remote address: %s", connection->GetRemoteAddress().GetString().c_str());
  104. }
  105. }