Lesson 80 - Serializing Content
This commit is contained in:
@@ -46,3 +46,19 @@ void UHTTPRequestManager::DumpMetadata(TSharedPtr<FJsonObject> JsonObject)
|
|||||||
DSMetaData.Dump();
|
DSMetaData.Dump();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FString UHTTPRequestManager::SerializeJsonContent(const TMap<FString, FString>& Params)
|
||||||
|
{
|
||||||
|
TSharedPtr<FJsonObject> ContentJsonObject = MakeShareable(new FJsonObject);
|
||||||
|
|
||||||
|
for (auto Param : Params)
|
||||||
|
{
|
||||||
|
ContentJsonObject->SetStringField(Param.Key, Param.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
FString Content;
|
||||||
|
TSharedRef<TJsonWriter<>> JsonWriter = TJsonWriterFactory<>::Create(&Content);
|
||||||
|
FJsonSerializer::Serialize(ContentJsonObject.ToSharedRef(), JsonWriter);
|
||||||
|
|
||||||
|
return Content;
|
||||||
|
}
|
||||||
|
|||||||
@@ -119,4 +119,29 @@ void UPortalManager::HandleGameSessionStatus(const FString& Status, const FStrin
|
|||||||
|
|
||||||
void UPortalManager::TryCreatePlayerSession(const FString& PlayerId, const FString& GameSessionId)
|
void UPortalManager::TryCreatePlayerSession(const FString& PlayerId, const FString& GameSessionId)
|
||||||
{
|
{
|
||||||
|
BroadcastJoinGameSessionMessage.Broadcast(TEXT("Searching for Game Session..."), false);
|
||||||
|
|
||||||
|
check(APIData);
|
||||||
|
|
||||||
|
TSharedPtr<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
|
||||||
|
Request->OnProcessRequestComplete().BindUObject(this, &UPortalManager::FindPlayerSession_Response);
|
||||||
|
|
||||||
|
const FString APIUrl = APIData->GetAPIEndPoint(DedicatedServersTags::GameSessionsAPI::CreatePlayerSession);
|
||||||
|
|
||||||
|
Request->SetURL(APIUrl);
|
||||||
|
Request->SetVerb("POST");
|
||||||
|
Request->SetHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
|
TMap<FString, FString> Params = {
|
||||||
|
{TEXT("playerId"), PlayerId},
|
||||||
|
{TEXT("sessionId"), GameSessionId}
|
||||||
|
};
|
||||||
|
|
||||||
|
Request->SetContentAsString(SerializeJsonContent(Params));
|
||||||
|
Request->ProcessRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UPortalManager::FindPlayerSession_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,4 +24,6 @@ protected:
|
|||||||
|
|
||||||
bool ContainsErrors(TSharedPtr<FJsonObject> JsonObject, bool bLogErrors = true);
|
bool ContainsErrors(TSharedPtr<FJsonObject> JsonObject, bool bLogErrors = true);
|
||||||
void DumpMetadata(TSharedPtr<FJsonObject> JsonObject);
|
void DumpMetadata(TSharedPtr<FJsonObject> JsonObject);
|
||||||
|
|
||||||
|
FString SerializeJsonContent(const TMap<FString, FString>& Params);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ private:
|
|||||||
FString GetUniquePlayerId() const;
|
FString GetUniquePlayerId() const;
|
||||||
void HandleGameSessionStatus(const FString& Status, const FString& SessionId);
|
void HandleGameSessionStatus(const FString& Status, const FString& SessionId);
|
||||||
void TryCreatePlayerSession(const FString& PlayerId, const FString& GameSessionId);
|
void TryCreatePlayerSession(const FString& PlayerId, const FString& GameSessionId);
|
||||||
|
void FindPlayerSession_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
|
||||||
|
|
||||||
|
|
||||||
FTimerHandle CreateSessionTimer;
|
FTimerHandle CreateSessionTimer;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user