Mirror icon indicating copy to clipboard operation
Mirror copied to clipboard

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.

Open RyanAllem opened this issue 3 years ago • 3 comments

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/

RyanAllem avatar Sep 11 '22 22:09 RyanAllem

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 avatar Sep 13 '22 14:09 adamgryu

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.

adamgryu avatar Sep 13 '22 15:09 adamgryu

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!

SteffTek avatar Sep 21 '22 16:09 SteffTek

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

Viktor-MaD avatar Sep 30 '22 12:09 Viktor-MaD

@vis2k See comment above about RemoveTransportHandlers not being called.

MrGadget1024 avatar Nov 24 '22 10:11 MrGadget1024

checking

miwarnec avatar Dec 03 '22 17:12 miwarnec

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

  • I'll check Telepathy, but couldn't reproduce it with the Tanks demo so far
  • Might be good to clear old client state on connect, or at least show a warning if transport forgot to clear

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

miwarnec avatar Dec 03 '22 17:12 miwarnec

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 avatar Dec 03 '22 18:12 miwarnec

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

miwarnec avatar Dec 03 '22 18:12 miwarnec

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

  • This only happen with FizzyTransport. Note to @vis2k this will not happen with Telepathy, I have tested both transport in same scenario.

  • The problem came from FizzyTransport NextClient will not call its own OnDisconnected if disconnection is run via FizzyTransport.Shutdown which does not call NextClient.InternalDisconnect, result in transport.OnClientDisconnected never called, result in NetworkClient.RemoveTransportHandlers never called.

  • FizzyTransport.Shutdown (bad route) will be called when client is voluntary disconnect from server/lobby. Strange enough, the required NextClient.InternalDisconnect will be called if client disconnect by error (timeout, etc).

  • As everyone had guessed, tranport.OnClientConnected delegate will pile up because it is never cleared by NetworkClient.RemoveTransportHandlers, and if client is configured to NetworkManager.autoCreatePlayer = true client will send double/triple AddPlayerMessage to server, thus the said error message on server side. image (image: delegate piles up after 2 cycles of disconnect-rejoin, making triple AddPlayerMessage to server)

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.

wappenull avatar Jan 10 '23 08:01 wappenull

  • This only happen with FizzyTransport.

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

MrGadget1024 avatar Jan 10 '23 12:01 MrGadget1024

@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

wappenull avatar Jan 12 '23 02:01 wappenull