How to block GameInit() on HTTP response

I haven’t figured out how to do this in InitGame()

Discord recommended setting a spectator pawn before the data arrives, then once the data arrived re-initializing everyone.

I considered rejecting connections on PreLogin() until the data arrived, but didn’t know how that would work.

My plan now is to add the configuration via the file system and use the synchronous File API. That way I can skip the complexity of the solutions above.

Hi there, happy Wednesday.

When my game server starts, it needs config data about players requested from a REST API. Without this config data, the game server’s best contribution is to terminate ASAP.

I can start the HTTP request in GameMode::InitGame() but how do I block until the response arrives? I need this data for GameMode::PreLogin() and GameMode::InitNewPlayer().

In JavaScript, I’d use async/await or promises. What’s the best way in UE4 and C++? Thank you in advance!

ADramaGameMode::ADramaGameMode()
{
	//When the object is constructed, Get the HTTP module
	Http = &FHttpModule::Get();
}

void ADramaGameMode::InitGame(const FString & MapName, const FString & Options, FString & ErrorMessage)
{

	TSharedRef<IHttpRequest, ESPMode::ThreadSafe> Request = Http->CreateRequest();
	Request->OnProcessRequestComplete().BindUObject(this, &ADramaGameMode::OnResponseReceived);
	//This is the url on which to process the request
	Request->SetURL("http://localhost:8081/WebApi/getint.php");
	Request->SetVerb("GET");
	Request->SetHeader(TEXT("User-Agent"), "X-UnrealEngine-Agent");
	Request->SetHeader("Content-Type", TEXT("application/json"));
	Request->ProcessRequest();

	// How do I wait here until OnResponseReceived is bWasSuccessful?  
}

void ADramaGameMode::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
	if (bWasSuccessful)
	{
		// parse response 
            // unblock InitGame()
	}
	else
	{
		// retry or quit
	}
}

Thank you!

I solved this by having the data already present in a file, and loading the file synchronously.

Please post how you did it. I have been suffering for 2 weeks with this task. I suffer)