MultiplayerSampleSystemComponent.cpp 4.5 KB

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