How to make a CLIENT leave the CURRENT session and join the SAME session again? (Listen Server)

I’ve used this WIKI page to get a reference for the C++ code: A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums

When a client decides to leave the session or a lobby, I currently destroy the session for the client and make him go to the Main Menu by using OpenLevel() function. After doing this, if the Client decides to join the SAME session again, the search for sessions doesn’t return that destroyed session in the search results array. So the client is unable to join the SAME session which he had previously left.

After the client destroys the session and leaves the game, if the server tries to end the session by calling the DestroySession() function, the function fails as well. However if the client just returns to Main Menu without destroying the session, the search for sessions functionality from the client fails but the server is successfully able to destroy the session using DestroySession(). This implies that DestroySession() should be called only once for a particular session. But it is mentioned in this link that https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/OnlineNodes/ “Clients also need to call this node(Destroy Session node) when they leave a game.” Even in the Multiplayer tutorial by Wess Bunn, he destroys the session for a client when the client leaves the session. The same is done in the MultiplayerShootout game as well.

I’ve been looking into ShooterGame code now. It calls EndGame() function before destroying a session. But there seems to be no documention about EndGame() or how to properly make the client properly leave the joined session.

There are other functionalities as well, but I’m not sure if I have to use them.

  1. KickPlayer() in AGameSession
  2. RegisterPlayer() and UnregisterPlayer() in IOnlineSession

I’m using STEAM online sub system.

I would really appreciate if someone can help me with this.

Thanks,

The problem was actually at my end.

I was destroying the session in EndPlay() of PlayerController which was causing the session to be destroyed in the server.

My previous code was:

void AYourPlayerController::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
	if (HasAuthority())
	{
		UYourGameInstance* YourGameInstance = Cast<UYourGameInstance>(GetGameInstance());
		if (YourGameInstance )
		{
			YourGameInstance ->DestroySession();			//My own custom function
		}
	}

	Super::EndPlay(EndPlayReason);
}

My current code is:

 void AYourPlayerController::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
	if (IsLocalController())                                //Change was made here
	{
		UYourGameInstance* YourGameInstance = Cast<UYourGameInstance>(GetGameInstance());
		if (YourGameInstance )
		{
			YourGameInstance ->DestroySession();			//My own custom function
		}
	}

	Super::EndPlay(EndPlayReason);
}