MirrorNetworking / Mirror

#1 Open Source Unity Networking Library
https://mirror-networking.com
MIT License
5.18k stars 767 forks source link

I get "there is already a player for this connection" if players connect to a new game after ending and disconnecting a game, without restarting the application. #3213

Closed DirtyBeastAfterTheToad closed 1 year ago

DirtyBeastAfterTheToad commented 2 years ago

I get the same error if players connect to a new game after ending and disconnecting a game, without restarting the application. The error also prevents the game from starting entirely.

From what I understand I don't need to set online and offline scene because I'm not switching scenes before everyone has connected, the lobby is in the main menu and the host only switches to the play scene once everyone has connected and is ready. Which all works until the game ends and players disconnect, after that I get the same error when the same players try to start a new game again without restarting the app. Interestingly, the error is spammed exactly 31 times before it gives up.

Regardless of not having to set these scenes I tried it anyways, splitting up my lobby and main menu, but now the client refuses to switch to the lobby scene (online scene) after connecting to the host, so it's even worse.

I would prefer to not set these scenes though, I want to manage scenes manually.

I'm on the latest version of mirror and am using playfab party as transport.

Originally posted by @TheMadDodger in https://github.com/vis2k/Mirror/issues/1701#issuecomment-1141308870


I'd add that after many, many, MANY tries, i think the problem resides in the fact that when someone leaves, the connection doesn't close between the server and the client, even though i've tried to put NetworkServer.RemovePlayerForConnection(conn, true); NetworkServer.DestroyPlayerForConnection(conn); conn.Disconnect(); in OnServerDisconnect(). Is this a bug or have i done it all wrong? More information about my problem here: https://forum.unity.com/threads/mirror-and-fizzysteamworks-leavelobby-there-is-already-a-player-for-this-connection.1333179/

adamgryu commented 2 years ago

I think I've noticed the same issue. NetworkClient.RemoveTransportHandlers() doesn't seem to be called during StopClient(), which causes duplicate OnClientConnect() calls when connecting again.

adamgryu commented 2 years ago

I think this is a problem with Telepathy transport - I was upgrading an old project when this error occurred. Switching to KCP seems to fix the issue.

SteffTek commented 2 years ago

Oh my ~fucking~ god!

I had this bug for MONTHS! using FizzySteamworks, and I just COULD NOT get it to work. Everytime I reconnected, it got worse with more and more connection attempts.

Thanks @adamgryu!

I fixed the bug by adding

// Try to fix bug
RemoveTransportHandlers();

at line 1545 in the NetworkClient.cs file in the Shutdown(); method.

There is now an error on startup of my game, but at least reconnecting to the same lobby works!

Viktor-MaD commented 2 years ago

Got the same error, this bug started occurring in a live game after upgrading from Mirror version 6.3.0 to version 66.0.9

MrGadget1024 commented 1 year ago

@vis2k See comment above about RemoveTransportHandlers not being called.

miwarnec commented 1 year ago

checking

miwarnec commented 1 year ago

NetworkClient.OnTransportDisconnected calls RemoveTransportHandlers. So as long as the Transport calls OnClientDisconnected, it should work.

note that someone had the same issue here: https://github.com/vis2k/Mirror/issues/3152

miwarnec commented 1 year ago

NetworkClient.AddTransportHandlers now removes old handlers first. However, I could not reproduce your original issue on the server. Could someone please add detailed steps how to reproduce it?

This would only happen if a Transport forgot to call OnServerDisconnect.

miwarnec commented 1 year ago

yep, can't reproduce it. if anyone still encounters this, please reopen with steps how to reproduce.

wappenull commented 1 year ago

Hi, I'm just hitting this bug our side and conquered it today. Here is the detail:

Solution:

Add following line to your "FizzySteamworks\NextClient.cs" at location in this screen shot.

if( Connected )
    InternalDisconnect( );

image

Note that next time if you decide to update the FizzySteamworks later, it could overwrite your custom code here so beware.

MrGadget1024 commented 1 year ago
  • This only happen with FizzyTransport.

This information needs to be copied to the Fizzy Steamworks repo and perhaps mentioned in the Discord channel.

wappenull commented 1 year ago

@MrGadget1024 I raise this issue to Fizzy repo just in case. But not sure how fast dev would adress or how to reach him. So I will just cross my finger. 🤞 https://github.com/Chykary/FizzySteamworks/issues/46