Hi. I’ve set a maximum number of clients that I check in my GameMode’s PreLogin(), returning a non-empty error string if I reached the maximum number of players.
void ABelvedereGameModeBase::PreLogin(const FString& Options, const FString& Address, const FUniqueNetIdRepl& UniqueId, FString& ErrorMessage)
{
Super::PreLogin(Options, Address, UniqueId, ErrorMessage);
if (PlayerControllerList.Num() == MaxNumPlayers)
ErrorMessage = TEXT("Maximum number of players reached. Please try again later.");
}
The client connects to the server on BeginPlay() with OpenLevel(). If the client passes PreLogin() successfully, it will go into PostLogin() step.
My problem is that when I reach MaxNumPlayers, the client spams the server continuously until I forcibly shutdown the client.
One approach that I tried is that I can trap OnNetworkFailure() on my GameInstance.
void UBelvedereGameInstance::Init()
{
Super::Init();
GEngine->OnNetworkFailure().AddUObject(this, &UBelvedereGameInstance::HandleNetworkFailure);
}
void UBelvedereGameInstance::HandleNetworkFailure(UWorld* World, UNetDriver* NetDriver, ENetworkFailure::Type FailureType, const FString& ErrorString)
{
UE_LOG(LogTemp, Warning, ErrorString);
// Kill app here ???
}
but it still spams the server unless I explicitly call RequestExit() or exit(0) to make it quit, which is still not what I really want.
Any way of stopping it to loop this way ?