Possible to kick players and/or set player limit?

As the title states I’m looking for how I can limit the amount of players on a networked server. I would assume that you’re able to set the player limit somewhere but I haven’t managed to find anything like that yet. And also is it possible to kick a player that’s currently connected to the server (disconnect them from the server)? I’m solely using Blueprints currently.

Thanks

I Have the exact same question, did you find a solution?

Nope, not yet

Hey, have a look at this:

Though i think it is not yet blueprintcallable. Try call it from the GameSession. There is also a BanPlayer function in the GameSession class. Check Github to see more.

GameSession also has a variable called “MaxPlayers” which should be available in blueprints (:

Wow, thantks!

Is there still no way of kicking players from a server from blueprints? Anyone ever made a plugin or something to add this function call?

It could be that the AdvancedSession plugin supports it.
The other way, which I follow when I have BP only projects, is to simply identify the Player (via PlayerState and PlayerController) on the Server and then call a ClientRPC on his PlayerController “Client_KickPlayer” which simply lets the client perform a travel to the MainMenu, while destroying his session.

Means you simply force him to leave.

The ClientRPC must be created by yourself of course.

It would seem a temporary solution tho, if you get problems with hackers in your game for example, asking the hacking client to leave is a bad idea and the server should close the connection.

Im going to try and research some better solution. AdvancedSession does not expose this functionality unfortunately.

The GameSession “KickPlayer” method is doing the same thing.
It destroys the Pawn of the Player and calls “ClientWasKicked(const FText& KickReason)” on the passed PlayerController, which is also a ClientRPC.
Then it also destroys the passed PlayerController itself.

“ClientWasKicked” does actually nothing though. It’s implementation in the PlayerController is empty.

The KickPlayer function of the GameSession does this here:

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;
}

So you should be good to go by just copying this with Blueprint Nodes the way I told you.

1 Like

Thanks for your reply! Interesting that their kick function would rely on the client complying with that command.

It seems like the only way to accomplish this in UE4 at the moment though without modifications to the source. I’ll probably post a feature request later and keep looking for a better solution in the future.

Thanks for helping out investigating this.
Best Regards

Kick Function in Game session does not rely on the client, Game session only exit on Server. U can expose the Function Kick Player to Blueprint, and then, in Game mode Class, make an array of player controller when post login and check when u want to kick that player, call that function and pass the controller u want to kick out of your server. Thats simple.

Or you just do the same via Blueprint, as the GameSession version, as already explained, calls ClientWasKicked, which in the end does nothing. A simple ClientRPC on the PlayerController that connects which disconnects him is enough. Together with destroying Pawn and PlayerController of the Player (like it’s done in the GameSession function) and you have your Blueprint only solution.