Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Mirror and FizzySteamworks leavelobby "There is already a player for this connection."

Discussion in 'Multiplayer' started by RyanAllemProd, Sep 7, 2022.

  1. RyanAllemProd

    RyanAllemProd

    Joined:
    Feb 25, 2022
    Posts:
    4
    Hello everyone!
    First post here so I apologize for the lack of style.
    So I'm making a multiplayer game with mirror and fizzysteamworks, and I got everything to work just fine, except for a thing:
    Whenever I leave a lobby and try to rejoin it, it throws an error "There is already a player for this connection." on host side.
    More precisely, on client side, I get no error message.
    The thing is that I actually receive the disconnection message on server side, and the playerobject, which is spawned when the client connects, does get destroyed.

    I must precise: I haven't set an offline scene nor an online scene in my networkmanager. I'm wondering if that could explain my problem but well... I don't know. Basically I have 2 scenes that are both "online" . What I mean by that is that my first scene, which is the lobby, is the scene where I initially connect people together, then transporting them in the other scene works just fine.

    So to summarize : The first game session works fine, you don't get any error from either sides. But if you end the game, try to reconnect to a player you've already played with (as a host) will just throw that error ! Same goes if you simply disconnect from the lobby and reconnect to it (before the other scene is launched).

    So when i want to leave the game i call
    Code (CSharp):
    1. public void LeaveGame()
    2.     {
    3.         if (SteamMatchmaking.GetLobbyOwner((CSteamID)CurrentLobbyID) == (CSteamID)GameObject.Find("LocalGamePlayer").GetComponent<PlayerObjectController>().playerSteamID && manager.GamePlayers.Count > 1)
    4.             SteamMatchmaking.SetLobbyOwner((CSteamID)CurrentLobbyID, (CSteamID)manager.GamePlayers[1].playerSteamID);
    5.         LeaveLobby((CSteamID)(CurrentLobbyID));
    6.  
    7.     }
    that calls this:
    Code (CSharp):
    1.     public void LeaveLobby(CSteamID steamID)
    2.     {
    3.         SteamMatchmaking.LeaveLobby(steamID);
    4.  
    5.         if (NetworkClient.isHostClient)
    6.             GetComponent<CustomNetworkManager>().StopHost();      
    7.         else
    8.             GetComponent<CustomNetworkManager>().StopClient();
    9.  
    10.         Destroy(GameObject.Find("LocalGamePlayer"));
    11.         SceneManager.LoadScene(0);
    12.         StartCoroutine(WaitAndSet());
    13.     }
    I've tried adding NetworkServer.RemovePlayerForConnection(conn, true);
    in OnServerDisconnect(NetworkConnectionToClient conn) but it didn't work either.
    Anyone has any ideas?
    Sorry if I'm not clear enough, if you want more details, I can provide!

    Ryan
     
  2. RyanAllemProd

    RyanAllemProd

    Joined:
    Feb 25, 2022
    Posts:
    4
    If that can ring a bell, i also noticed that if someone hosts a lobby (we'll call him A) and someone joins him (B), then if B Hosts another game, he will get the lobby id from the previous lobby (lobby made by A), and the same lobby name (which is the name of player A).
     
  3. RyanAllemProd

    RyanAllemProd

    Joined:
    Feb 25, 2022
    Posts:
    4
    Turns out my solution was to add a new scene which i've set to "offline" in the network manager. It deletes the current networkmanager and makes a new one. Now if you reconnect to a lobby you've already been in, it will count you as a new player (the id still goes up in the host's networkmanager, but it doesn't matter since it's with a fresh connection). I have a Gameplayers list which manages the game players so the connection id problem isn't one actually ^^.
     
    Last edited: Sep 14, 2022
  4. Wappenull

    Wappenull

    Joined:
    Oct 29, 2013
    Posts:
    51