How to react to server rejecting client(reading the server error message client side)

My client is connecting to the server by using APlayerController::ClientTravel(TEXT(“IP:PORT”), TRAVEL_Absolute);

On the server, I reject the client in AGameMode::PreLogin() by setting the ErrorMessage.
How can I access this ErrorMessage on the client side to give the info about the rejection reason to the user? How is the client notified that it was rejected (APlayerController::ClientTravel does not return anything and seems to be asynchronous)?

After a bit of digging through the source I found it, here is the delegate declared in Engine.h:

/** 
	 * Error message event relating to network failures 
	 * 
	 * @param Type type of network failure
	 * @param Name name of netdriver that generated the failure
	 * @param ErrorString additional error message
	 */
	DECLARE_EVENT_FourParams(UEngine, FOnNetworkFailure, UWorld*, UNetDriver*, ENetworkFailure::Type, const FString&);

	FOnNetworkFailure NetworkFailureEvent;

Now to listen for the event you have to bind it somewhere, for example in your custom game instance class:

	GEngine->NetworkFailureEvent.AddUObject(this, &UBrickGameInstance::OnNetworkFailure);

There are also other useful events, like TravelFailureEvent and NetworkLagStateChangedEvent that you can bind.

1 Like