+2 votes

I recently became interested in multiplayer games. Apparently, godot 2.2 (and as far as i know godot 3.0) provides no ability to kick/disconnect peer. Let's say i start the server limited to 2 players, with address known to group of people, and i want to disconnect player that sent incorrect password (which is obtained with remote call). The idea of simply not registering player and assigning in-game object to them is not enough, because they gonna stall the available connection slots, so no more players will be able to join. I really, really don't want to code networking logic by myself based on PacketPeer. Is there possibility do disconnect player basing on their peer_id ?

in Engine by (18 points)

2 Answers

0 votes

I'm answering myself because I've found both answer and solution. After looking through code my answer is: no, but... But since Godot uses ENet implementation which provides certain functions, I've written small modification for Godot 2.2 and (hopefully) Godot 3.0. It extends ENet functionality with two functions: one to disconnect player by his id, and another one to obtain peer IP address by his id. The code is here. It has been tested with Godot 2.2 but not with 3.0 (my graphic card does not support OpenGL 3). Here's the sample how it can be used to blacklist/ban certain IPs:


var blacklist = ["", ""]

get_tree().connect("network_peer_connected", self, "_client_connected")
# ...

func _client_connected(id):
var adr = get_tree().get_network_peer_address(id)
assert(not adr.empty())
if adr.ip in blacklist:
rpc_id(id, "kicked", "you have been banned from this server")


remote kicked(reason):
show_info("Kicked from server: " + reason)

by (18 points)
edited by

Does not work. Get the error: "Invalid call. Nonexistent function 'disconect_network_peer' in base 'SceneTree'.

+2 votes

I'm aware this is an old question but I figured I would update the answer as the answer is different now and not always obvious.

# Initialize your peer (peer is declared elsewhere)
peer = NetworkedMultiplayerENet.new()
# Somewhere in your Code where you want to kick, where remote_rpc_id
#  is the ID you get when a player connects 
by (57 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.