How disconnect a specific PlayerController from server?

When my Match end, inside my GameMode, I need to check for some condition on each PlayerController and if the condition is true, disconnect from server that PlayerController. Later, call ServerTravel in order to move to another map only the PlayerControllers that are connected. But i don’t know how disconnect a specific PlayerController from server.

Someone can help me with this, please ?

Thanks

Well, I found some solution, but don’t know if this is the best way to do this.

In my GameMode, when I found some PlayerController that I need to disconnect, I destroy it (calling Destroy()). So, in my game mode, on server, run a method like this:

for (FConstControllerIterator It = GetWorld()->GetControllerIterator(); It; ++It)
{
	if ((*It)->MyCondition)
	{
		(*It)->Destroy();
	}
} 

… apparently it work correctly, and exactly has I want. This client is disconnected, on gameMode is called the Logout function etc. But, the point is that I don’t know if this is the best way to do it.

Best regards

Regardinging 's answer:

Actually you’re right!

If you look in GameSession.cpp, Epic does the same thing, except they make sure to clean up the Pawn first:

#UnregisterPlayer
Though if you want a more gentile approach you can use

GameSession::UnregisterPlayer

#:heart:

bool AGameSession::KickPlayer(APlayerController* KickedPlayer, const FText& KickReason)
{
	// Do not kick logged admins
	if (KickedPlayer != NULL && Cast<UNetConnection>(KickedPlayer->Player) != NULL)
	{
		if (KickedPlayer->GetPawn() != NULL)
		{
			KickedPlayer->GetPawn()->Destroy();
		}

		KickedPlayer->ClientWasKicked(KickReason);

		if (KickedPlayer != NULL)
		{
			KickedPlayer->Destroy();
		}

		return true;
	}
	return false;
}

Hi , thank you for your answer, this is a old question, but is good to know that I was in a correct direction, thank you.

… and , I will use this opportunity, because you are a UE4 Guru :), maybe you can help me with another two question that I did here more recently, but none one answer me. If is not to mush ask, can you take a look please ?

I will appreciate if you can point me in the right direction at least on one of the two questions.

PD: Are two completely different questions

Again, thanks so much.

Best regards,