Disconnection from ENet Multiplayer

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Vespiria

I’m still new to networking, but I managed to integrate godotsteam with the built in ENet multiplayer api to allow for steam features and lobby matchmaking. I have the necessary information for connection being passed through godotsteam, p2p handshaking etc. Then I create_client or create_server depending on join or create, connect the necessary signals, spawn the necessary bodies via multiplayerspawner and synchronizes them with the multiplayersynchronizer, very simple. I followed a few tutorials in order to set it up but it seems to connect perfectly fine, even through testing it on actual steam across the internet with my testers.
My issue comes with disconnecting from that server then causes a whole slew of issues depending on which version of disconnection I have tried using:

  • The one that seems to work the best so far, or really at all in the way I intended, is multiplayer.multiplayer_peer.close(). Multiplayer_peer being the ENetMultiplayerPeer with the created client/server attached. This seems to completely close the entire network completely and doesn’t allow for any creation of new servers or clients at all. Seems to be how it is intended, but it is the only thing I’ve tried so far that actually removes the disconnecting player’s body.
  • Setting the multiplayer_peer to null, if I use = null it causes my character’s rpc functions to fail, if I use set_multiplayer_peer(null) it spams my console with errors telling me the some condition is true while making my computer a laggy mess. On top of this, the host of the server loses its’ multiplayer peer as well and becomes unable to perform basic things (due to multiplayer authority requirements). On the flip side, it does seem to actually disconnect the connection, just doesn’t call peer_disconnected.
  • The most obvious one, and the one I keep seeing in the docs and trying in various different ways is disconnect_peer(id). I’ve been using multiplayer.get_unique_id() to get the peerid, but I’ve also tried multiplayer.multiplayer_peer.get_unique_id(), I’ve tried getting it from the list of get_peers(), I’ve tried setting my own id’s using set_unique_id(), none of it seems to do anything and it isn’t triggering peer_disconnected on the server.
  • Beyond this I’ve tried a lot of random things, most of the time realizing it was outdated information. I was thinking there might be a way to create a new enet using ENetMultiplayerPeer.new() every time I disconnect by making the old one null, however it just continues telling me there is no multiplayer peer even after setting the new one as so.

Any ideas would be helpful, I can supply any code I have that’s necessary I just don’t know what else to supply that would help with solving with issue.

Edit: After looking at an example multiplayer setup on github, I realized my enet_peer is a global variable I set at the top rather than a temporary one to use in the function itself. So I changed the create and join server function to :

var enet_peer = ENetMultiplayerPeer.new()
enet_peer.create_server(ip, port)
multiplayer.multiplayer_peer = enet_peer

with server being client for the joining function, and connections for peer_disconnect and connect after the last line there. So far I’ve been using multiple instances (2) to test the multiplayer functions, but after I changed this my first instance to load into a server seems to work perfectly fine connecting/disconnecting by itself. My other instance of the game however just goes grey, even though both are hitting the same button to start the game from the main menu (which consequently starts a new friends-only steam lobby + enet_peer setup).
Maybe the issues I’m having are because I’m testing in editor with multiple instances on the same machine?