MPSGameLiftClientSystemComponent.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. m_playerId = AZ::Uuid::Create().ToString<AZStd::string>();
  41. }
  42. void MPSGameLiftClientSystemComponent::Activate()
  43. {
  44. AWSGameLift::AWSGameLiftRequestBus::Broadcast(&AWSGameLift::AWSGameLiftRequestBus::Events::ConfigureGameLiftClient, "");
  45. }
  46. void MPSGameLiftClientSystemComponent::Deactivate()
  47. {
  48. }
  49. void MPSGameLiftClientSystemComponent::JoinSession(const AZ::ConsoleCommandContainer& consoleFunctionParameters)
  50. {
  51. if (consoleFunctionParameters.size() != 1)
  52. {
  53. AZ_Error("MPSGameLiftClientSystemComponent", false, "Invalid console command. Use JoinSession <game-session-id>");
  54. return;
  55. }
  56. JoinSessionInternal(consoleFunctionParameters[0], m_playerId);
  57. }
  58. void MPSGameLiftClientSystemComponent::JoinSessionInternal(AZStd::string_view sessionId, AZStd::string_view playerId)
  59. {
  60. AWSGameLift::AWSGameLiftJoinSessionRequest request;
  61. request.m_sessionId = sessionId;
  62. request.m_playerId = playerId;
  63. AWSGameLift::AWSGameLiftSessionAsyncRequestBus::Broadcast(
  64. &AWSGameLift::AWSGameLiftSessionAsyncRequestBus::Events::JoinSessionAsync, request);
  65. }
  66. }