AWSGameLiftClientManager.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/RTTI/BehaviorContext.h>
  10. #include <AzCore/std/smart_ptr/shared_ptr.h>
  11. #include <Multiplayer/Session/MatchmakingNotifications.h>
  12. #include <Request/AWSGameLiftRequestBus.h>
  13. #include <Request/AWSGameLiftSessionRequestBus.h>
  14. #include <Request/AWSGameLiftMatchmakingRequestBus.h>
  15. namespace AWSGameLift
  16. {
  17. struct AWSGameLiftAcceptMatchRequest;
  18. struct AWSGameLiftCreateSessionRequest;
  19. struct AWSGameLiftCreateSessionOnQueueRequest;
  20. struct AWSGameLiftJoinSessionRequest;
  21. struct AWSGameLiftSearchSessionsRequest;
  22. struct AWSGameLiftStartMatchmakingRequest;
  23. struct AWSGameLiftStopMatchmakingRequest;
  24. // MatchmakingNotificationBus EBus handler for scripting
  25. class AWSGameLiftMatchmakingNotificationBusHandler
  26. : public Multiplayer::MatchmakingNotificationBus::Handler
  27. , public AZ::BehaviorEBusHandler
  28. {
  29. public:
  30. AZ_EBUS_BEHAVIOR_BINDER(
  31. AWSGameLiftMatchmakingNotificationBusHandler,
  32. "{CBE057D3-F5CE-46D3-B02D-8A6A1446B169}",
  33. AZ::SystemAllocator,
  34. OnMatchAcceptance, OnMatchComplete, OnMatchError, OnMatchFailure);
  35. void OnMatchAcceptance() override
  36. {
  37. Call(FN_OnMatchAcceptance);
  38. }
  39. void OnMatchComplete() override
  40. {
  41. Call(FN_OnMatchComplete);
  42. }
  43. void OnMatchError() override
  44. {
  45. Call(FN_OnMatchError);
  46. }
  47. void OnMatchFailure() override
  48. {
  49. Call(FN_OnMatchFailure);
  50. }
  51. };
  52. // MatchmakingAsyncRequestNotificationBus EBus handler for scripting
  53. class AWSGameLiftMatchmakingAsyncRequestNotificationBusHandler
  54. : public Multiplayer::MatchmakingAsyncRequestNotificationBus::Handler
  55. , public AZ::BehaviorEBusHandler
  56. {
  57. public:
  58. AZ_EBUS_BEHAVIOR_BINDER(
  59. AWSGameLiftMatchmakingAsyncRequestNotificationBusHandler,
  60. "{2045EE8F-2AB7-4ED0-9614-3496A1A43677}",
  61. AZ::SystemAllocator,
  62. OnAcceptMatchAsyncComplete,
  63. OnStartMatchmakingAsyncComplete,
  64. OnStopMatchmakingAsyncComplete);
  65. void OnAcceptMatchAsyncComplete() override
  66. {
  67. Call(FN_OnAcceptMatchAsyncComplete);
  68. }
  69. void OnStartMatchmakingAsyncComplete(const AZStd::string& matchmakingTicketId) override
  70. {
  71. Call(FN_OnStartMatchmakingAsyncComplete, matchmakingTicketId);
  72. }
  73. void OnStopMatchmakingAsyncComplete() override
  74. {
  75. Call(FN_OnStopMatchmakingAsyncComplete);
  76. }
  77. };
  78. // SessionAsyncRequestNotificationBus EBus handler for scripting
  79. class AWSGameLiftSessionAsyncRequestNotificationBusHandler
  80. : public Multiplayer::SessionAsyncRequestNotificationBus::Handler
  81. , public AZ::BehaviorEBusHandler
  82. {
  83. public:
  84. AZ_EBUS_BEHAVIOR_BINDER(
  85. AWSGameLiftSessionAsyncRequestNotificationBusHandler,
  86. "{6E13FC73-53DC-4B6B-AEA7-9038DE4C9635}",
  87. AZ::SystemAllocator,
  88. OnCreateSessionAsyncComplete,
  89. OnSearchSessionsAsyncComplete,
  90. OnJoinSessionAsyncComplete,
  91. OnLeaveSessionAsyncComplete);
  92. void OnCreateSessionAsyncComplete(const AZStd::string& createSessionReponse) override
  93. {
  94. Call(FN_OnCreateSessionAsyncComplete, createSessionReponse);
  95. }
  96. void OnSearchSessionsAsyncComplete(const Multiplayer::SearchSessionsResponse& searchSessionsResponse) override
  97. {
  98. Call(FN_OnSearchSessionsAsyncComplete, searchSessionsResponse);
  99. }
  100. void OnJoinSessionAsyncComplete(bool joinSessionsResponse) override
  101. {
  102. Call(FN_OnJoinSessionAsyncComplete, joinSessionsResponse);
  103. }
  104. void OnLeaveSessionAsyncComplete() override
  105. {
  106. Call(FN_OnLeaveSessionAsyncComplete);
  107. }
  108. };
  109. //! AWSGameLiftClientManager
  110. //! GameLift client manager to support game and player session related client requests
  111. class AWSGameLiftClientManager
  112. : public AWSGameLiftRequestBus::Handler
  113. , public AWSGameLiftMatchmakingAsyncRequestBus::Handler
  114. , public AWSGameLiftMatchmakingRequestBus::Handler
  115. , public AWSGameLiftSessionAsyncRequestBus::Handler
  116. , public AWSGameLiftSessionRequestBus::Handler
  117. {
  118. public:
  119. static constexpr const char AWSGameLiftClientManagerName[] = "AWSGameLiftClientManager";
  120. static constexpr const char AWSGameLiftClientRegionMissingErrorMessage[] =
  121. "Missing AWS region for GameLift client.";
  122. static constexpr const char AWSGameLiftClientCredentialMissingErrorMessage[] =
  123. "Missing AWS credential for GameLift client.";
  124. static constexpr const char AWSGameLiftCreateSessionRequestInvalidErrorMessage[] =
  125. "Invalid GameLift CreateSession or CreateSessionOnQueue request.";
  126. AWSGameLiftClientManager() = default;
  127. virtual ~AWSGameLiftClientManager() = default;
  128. virtual void ActivateManager();
  129. virtual void DeactivateManager();
  130. // AWSGameLiftRequestBus interface implementation
  131. bool ConfigureGameLiftClient(const AZStd::string& region) override;
  132. AZStd::string CreatePlayerId(bool includeBrackets, bool includeDashes) override;
  133. // AWSGameLiftMatchmakingAsyncRequestBus interface implementation
  134. void AcceptMatchAsync(const Multiplayer::AcceptMatchRequest& acceptMatchRequest) override;
  135. void StartMatchmakingAsync(const Multiplayer::StartMatchmakingRequest& startMatchmakingRequest) override;
  136. void StopMatchmakingAsync(const Multiplayer::StopMatchmakingRequest& stopMatchmakingRequest) override;
  137. // AWSGameLiftSessionAsyncRequestBus interface implementation
  138. void CreateSessionAsync(const Multiplayer::CreateSessionRequest& createSessionRequest) override;
  139. void JoinSessionAsync(const Multiplayer::JoinSessionRequest& joinSessionRequest) override;
  140. void SearchSessionsAsync(const Multiplayer::SearchSessionsRequest& searchSessionsRequest) const override;
  141. void LeaveSessionAsync() override;
  142. // AWSGameLiftMatchmakingRequestBus interface implementation
  143. void AcceptMatch(const Multiplayer::AcceptMatchRequest& acceptMatchRequest) override;
  144. AZStd::string StartMatchmaking(const Multiplayer::StartMatchmakingRequest& startMatchmakingRequest) override;
  145. void StopMatchmaking(const Multiplayer::StopMatchmakingRequest& stopMatchmakingRequest) override;
  146. // AWSGameLiftSessionRequestBus interface implementation
  147. AZStd::string CreateSession(const Multiplayer::CreateSessionRequest& createSessionRequest) override;
  148. bool JoinSession(const Multiplayer::JoinSessionRequest& joinSessionRequest) override;
  149. Multiplayer::SearchSessionsResponse SearchSessions(const Multiplayer::SearchSessionsRequest& searchSessionsRequest) const override;
  150. void LeaveSession() override;
  151. };
  152. } // namespace AWSGameLift