How to block public connection in a GamePlay map? (OnlineSubsystem + DedicatedServer)

I think i found a solution… seems to work, but it is completily invented by me

void AGamePlayGameMode::PreLogin(const FString& Options, const FString& Address, const FUniqueNetIdRepl& UniqueId,	FString& ErrorMessage)
{	

	IOnlineSessionPtr SessionPtr = Session::GetInterface();
	if(SessionPtr == nullptr)
	{
		Message::Error("AGamePlayGameMode::PreLogin --> SessionPtr is NULL");
		return;
	}

	if (!UniqueId.IsValid())
	{
		Message::Error("AGamePlayGameMode::PreLogin --> UniqueNetId is NULL");
		return;		
	}

	if(SessionPtr->IsPlayerInSession(NAME_GameSession, *UniqueId))
	{
		ErrorMessage = GameSession->ApproveLogin(Options);
		Message::Warning("PLAYER IS REGISTER WITH SESSION");
		
	}
	else
	{
		ErrorMessage = TEXT("PLAYER IS NOT REGISTER WITH SESSION");
		Message::Warning("PLAYER IS NOT REGISTER WITH SESSION");
	}

	FGameModeEvents::GameModePreLoginEvent.Broadcast(this, UniqueId, ErrorMessage);	
	
}

I got the idea from this post:

if someone know a better solution let know please!!

Thank you so much!!


Edited:


Well, seeing none provide a better solution i wiil acept my own answer as solution…
However feel free to provide a better solution if you know it… even if this post is old in the future.
thx u

1 Like