Please elaborate what is happening and what you expect to happen. Are you trying to drop a connection like kicking a player from the server? Do players whom disconnect still persist in the game?
You should connect peer_disconnected as part of _on_host, that’s for the server to handle clients disconnecting i.e. cleaning up players that left the game.
Then I believe my second paragraph will fix that issue.
func _on_host():
peer.create_server(135)
multiplayer.multiplayer_peer = peer
multiplayer.peer_connected.connect(_add_player)
# server must handle disconnects from startup to shutdown
multiplayer.peer_disconnected.connect(del_player)
_add_player()
And make sure the player calls disconnect_peer when going to main.tscn
if not multiplayer.is_server():
# 1 is always the server
multiplayer.multiplayer_peer.disconnect_peer(1)
Not sure on the null value, any Node should have a multiplayer value. Where are you trying to call it?
Yes disconnect_peer(1) disconnect from the server, it doesn’t remove the server just the connection from said peer. The if statement should confirm we are not the server, if we want to close the server we would call multiplayer.multiplayer_peer.close()
Umm. Idk? This is my first game so I don’t know what to set the port too. I just did what the tutorial did. Also 1 more tiny question: I use peer.close() when the host leaves, but how do I then make the client return to the homescreen? rpc? It’s what I did to reflect kick changes.
Ports are made up but they have to be from 1024 to 65535, anything <1024 is considered reserved for system administrator use. I host a lot of game servers from my house and it’s crazy keeping track of all the ports.
Ok! Your code worked! About the ports. I’m going to a minecraft like thing so that if for some reason someone wants to host a server, they can. It may be switched off ports because I don’t want people to have to be on the same network. I have a raspberry pi in which I hope to use as a server. I also want people to be able to host from their device to people on the same network, also like minecraft. So I don’t even know if ports are the right way to do this.
Ports are simply a requirement to host anything. I believe your are thinking of matchmaking, or a central server (still has a port assigned) to connect players or pass players along to smaller more dispersed servers (also ports). If you are hosting this from your home you will need to port forward, this tells your router when it recieves packets for a certain port to send it to your raspberrypi.
In Godot you would hard-code your public IP address to achieve this, but it’s best to include a manual ip address entry in case someone wants to host their own server or your internet service provider randomly changes your public IP.