MPSGameLiftClientSystemComponent.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #include "MPSGameLiftClientSystemComponent.h"
  8. #include <AzCore/Serialization/SerializeContext.h>
  9. #include <Request/AWSGameLiftRequestBus.h>
  10. #include <Request/AWSGameLiftSessionRequestBus.h>
  11. #include <Request/AWSGameLiftJoinSessionRequest.h>
  12. namespace MPSGameLift
  13. {
  14. void MPSGameLiftClientSystemComponent::Reflect(AZ::ReflectContext* context)
  15. {
  16. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  17. {
  18. serialize->Class<MPSGameLiftClientSystemComponent, AZ::Component>()
  19. ->Version(0)
  20. ;
  21. }
  22. }
  23. void MPSGameLiftClientSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  24. {
  25. provided.push_back(AZ_CRC_CE("MPSGameLiftClientService"));
  26. }
  27. void MPSGameLiftClientSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  28. {
  29. incompatible.push_back(AZ_CRC_CE("MPSGameLiftClientService"));
  30. }
  31. void MPSGameLiftClientSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  32. {
  33. required.push_back(AZ_CRC_CE("AWSGameLiftClientService"));
  34. }
  35. void MPSGameLiftClientSystemComponent::GetDependentServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& dependent)
  36. {
  37. }
  38. void MPSGameLiftClientSystemComponent::Init()
  39. {
  40. }
  41. void MPSGameLiftClientSystemComponent::Activate()
  42. {
  43. AWSGameLift::AWSGameLiftRequestBus::Broadcast(&AWSGameLift::AWSGameLiftRequestBus::Events::ConfigureGameLiftClient, "");
  44. }
  45. void MPSGameLiftClientSystemComponent::Deactivate()
  46. {
  47. }
  48. void MPSGameLiftClientSystemComponent::JoinSession(const AZ::ConsoleCommandContainer& consoleFunctionParameters)
  49. {
  50. if (consoleFunctionParameters.size() != 1)
  51. {
  52. AZ_Error("MPSGameLiftClientSystemComponent", false, "Invalid console command. Use JoinSession <game-session-id>");
  53. return;
  54. }
  55. JoinSessionInternal(consoleFunctionParameters[0], m_playerId);
  56. }
  57. void MPSGameLiftClientSystemComponent::JoinSessionInternal(AZStd::string_view sessionId, const AZ::Uuid& playerId)
  58. {
  59. AWSGameLift::AWSGameLiftJoinSessionRequest request;
  60. request.m_sessionId = sessionId;
  61. request.m_playerId = playerId.ToString<AZStd::string>();
  62. AWSGameLift::AWSGameLiftSessionAsyncRequestBus::Broadcast(
  63. &AWSGameLift::AWSGameLiftSessionAsyncRequestBus::Events::JoinSessionAsync, request);
  64. }
  65. }