|
@@ -20,7 +20,9 @@
|
|
|
|
|
|
#include <Multiplayer/Session/SessionRequests.h>
|
|
|
#include <Request/AWSGameLiftSessionRequestBus.h>
|
|
|
-
|
|
|
+#include <AzCore/Jobs/JobContext.h>
|
|
|
+#include <AzCore/Jobs/JobFunction.h>
|
|
|
+#include <Multiplayer/Session/ISessionHandlingRequests.h>
|
|
|
|
|
|
namespace MPSGameLift
|
|
|
{
|
|
@@ -59,7 +61,6 @@ namespace MPSGameLift
|
|
|
|
|
|
void UiGameLiftConnectWithPlayerSessionData::Activate()
|
|
|
{
|
|
|
- Multiplayer::SessionAsyncRequestNotificationBus::Handler::BusConnect();
|
|
|
UiCursorBus::Broadcast(&UiCursorInterface::IncrementVisibleCounter);
|
|
|
|
|
|
// Listen for button presses
|
|
@@ -84,8 +85,6 @@ namespace MPSGameLift
|
|
|
{
|
|
|
m_onConnectToHostFailed.Disconnect();
|
|
|
UiCursorBus::Broadcast(&UiCursorInterface::DecrementVisibleCounter);
|
|
|
-
|
|
|
- Multiplayer::SessionAsyncRequestNotificationBus::Handler::BusDisconnect();
|
|
|
}
|
|
|
|
|
|
void UiGameLiftConnectWithPlayerSessionData::OnJSONChanged(const AZStd::string& gameLiftJsonString)
|
|
@@ -95,12 +94,12 @@ namespace MPSGameLift
|
|
|
|
|
|
if (gameLiftJsonString.empty())
|
|
|
{
|
|
|
- UiTextBus::Event(m_jsonParseFailTextUi, &UiTextInterface::SetText, "Please provide GameLift GameSessionId and PlayerSessionId in JSON format!");
|
|
|
+ UiTextBus::Event(m_jsonParseFailTextUi, &UiTextInterface::SetText, "Please provide GameLift player connection information in JSON format!");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// Parse GameLift JSON
|
|
|
- m_request = {};
|
|
|
+ m_sessionConnectionConfig = {};
|
|
|
rapidjson::Document document;
|
|
|
document.Parse(gameLiftJsonString.c_str());
|
|
|
|
|
@@ -110,35 +109,51 @@ namespace MPSGameLift
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (!document.HasMember("GameSessionId"))
|
|
|
+ // Alert the user if any information is missing from the JSON they provided
|
|
|
+ if (!document.HasMember("PlayerSessionId"))
|
|
|
{
|
|
|
- UiTextBus::Event(m_jsonParseFailTextUi, &UiTextInterface::SetText, "Missing GameSessionId!");
|
|
|
+ UiTextBus::Event(m_jsonParseFailTextUi, &UiTextInterface::SetText, "Missing PlayerSessionId!");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (!document.HasMember("PlayerSessionId"))
|
|
|
+ if (!document.HasMember("IpAddress") && !document.HasMember("DnsName"))
|
|
|
{
|
|
|
- UiTextBus::Event(m_jsonParseFailTextUi, &UiTextInterface::SetText, "Missing PlayerSessionId!");
|
|
|
+ UiTextBus::Event(m_jsonParseFailTextUi, &UiTextInterface::SetText, "Must provide either an IpAddress or DnsName!");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const rapidjson::Value& gameSessionId = document["GameSessionId"];
|
|
|
- if (!gameSessionId.IsString())
|
|
|
+ if (!document.HasMember("Port"))
|
|
|
{
|
|
|
- UiTextBus::Event(m_jsonParseFailTextUi, &UiTextInterface::SetText, "Invalid GameSessionId!");
|
|
|
+ UiTextBus::Event(m_jsonParseFailTextUi, &UiTextInterface::SetText, "Missing Port!");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const rapidjson::Value& playerSessionId = document["PlayerSessionId"];
|
|
|
- if (!playerSessionId.IsString())
|
|
|
+ const rapidjson::Value& port = document["Port"];
|
|
|
+ if (!port.IsUint())
|
|
|
{
|
|
|
- UiTextBus::Event(m_jsonParseFailTextUi, &UiTextInterface::SetText, "Invalid PlayerSessionId!");
|
|
|
+ UiTextBus::Event(m_jsonParseFailTextUi, &UiTextInterface::SetText, "Invalid Port!");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // Fill out SessionConnectionConfig and try connecting to host
|
|
|
+ if (document.HasMember("IpAddress"))
|
|
|
+ {
|
|
|
+ const rapidjson::Value& ipAddress = document["IpAddress"];
|
|
|
+ m_sessionConnectionConfig.m_ipAddress = ipAddress.GetString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (document.HasMember("DnsName"))
|
|
|
+ {
|
|
|
+ const rapidjson::Value& dnsName = document["DnsName"];
|
|
|
+ m_sessionConnectionConfig.m_dnsName = dnsName.GetString();
|
|
|
+ }
|
|
|
+
|
|
|
+ const rapidjson::Value& playerSessionId = document["PlayerSessionId"];
|
|
|
+
|
|
|
+ m_sessionConnectionConfig.m_port = aznumeric_cast<uint16_t>(port.GetUint());
|
|
|
+ m_sessionConnectionConfig.m_playerSessionId = playerSessionId.GetString();
|
|
|
+
|
|
|
UiTextBus::Event(m_jsonParseFailTextUi, &UiTextInterface::SetText, "");
|
|
|
- m_request.m_sessionId = gameSessionId.GetString();
|
|
|
- m_request.m_playerId = playerSessionId.GetString();
|
|
|
UiInteractableBus::Event(m_connectButtonUi, &UiInteractableInterface::SetIsHandlingEvents, true);
|
|
|
}
|
|
|
|
|
@@ -162,9 +177,16 @@ namespace MPSGameLift
|
|
|
// Enable blocker ui while we attempt connection
|
|
|
UiElementBus::Event(m_attemptConnectionBlockerUi, &UiElementInterface::SetIsEnabled, true);
|
|
|
|
|
|
- AWSGameLift::AWSGameLiftSessionAsyncRequestBus::Broadcast(
|
|
|
- &AWSGameLift::AWSGameLiftSessionAsyncRequestBus::Events::JoinSessionAsync, m_request);
|
|
|
- return;
|
|
|
+ if (auto clientRequestHandler = AZ::Interface<Multiplayer::ISessionHandlingClientRequests>::Get())
|
|
|
+ {
|
|
|
+ clientRequestHandler->RequestPlayerJoinSession(m_sessionConnectionConfig);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ AZ_Assert(false, "UiGameLiftConnectWithPlayerSessionData failed to connect because there's no ISessionHandlingClientRequests registered. "
|
|
|
+ "Please update code to ensure an ISessionHandlingClientRequests has been created before trying to connect this client to a host!");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
if (buttonEntityId == m_connectToHostFailedUi)
|
|
@@ -178,17 +200,5 @@ namespace MPSGameLift
|
|
|
{
|
|
|
UiElementBus::Event(m_attemptConnectionBlockerUi, &UiElementInterface::SetIsEnabled, false);
|
|
|
UiElementBus::Event(m_connectToHostFailedUi, &UiElementInterface::SetIsEnabled, true);
|
|
|
- }
|
|
|
-
|
|
|
- void UiGameLiftConnectWithPlayerSessionData::OnJoinSessionAsyncComplete(bool joinSessionsResponse)
|
|
|
- {
|
|
|
- UiElementBus::Event(m_attemptConnectionBlockerUi, &UiElementInterface::SetIsEnabled, false);
|
|
|
-
|
|
|
- if (!joinSessionsResponse)
|
|
|
- {
|
|
|
- UiElementBus::Event(m_connectToHostFailedUi, &UiElementInterface::SetIsEnabled, true);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ }
|
|
|
} // namespace MultiplayerSample
|