Basic Server Multiplayer Functions (Kick/Ban/Etc)

I’m sorry, but that’s a really simplistic and not terribly helpful answer. Game session isn’t gotten and casted to the same way many of the other core parts like game state, game mode, etc are. There isn’t much information on this, but I managed to work it out last night. This can only be accessed in a meaningful manner via C++. While you can “get game session class” in blueprints you can’t do anything with it.

You need to do this to cast to the game session properly so that you can use it.


CurrentGameSessionRef = GetGameSessionClass();
CurrentGameSession = Cast<AGameSession>(CurrentGameSessionRef->GetDefaultObject());


if you want to kick, especially via blueprints create a header like this:


UFUNCTION(BlueprintCallable, meta = (DisplayName = "KickPlayer"))
bool BP_Kickplayer(APlayerController * KickedPlayer, const FText & KickReason);

with the following code in CPP:


 if (CurrentGameSession)
{
return CurrentGameSession->KickPlayer(KickedPlayer, KickReason);
}
else
{
return false;
}

Be aware that using ban player currently is pointless since all ban player does is call kick directly. Despite the description on the unreal documents ban player does not in any way ban the player from the server permanently. You need you to create a way to reliably identify the player and check if they’re banned during pre-login on the game mode to prevent them from rejoining the server.

2 Likes