0
\$\begingroup\$

In a multiplayer client-server Unity project using Mirror networking, I have a matchmaking system where the server matches two players and gives them a MatchID.

The game is server-side authenticated, each player has a unique ID, each match has its own MatchID, and everything is available on the server.

Everything works fine, except when someone gets disconnected.

I can't find any tutorial or documentation on how to reconnect a client to a match with a MatchID. All the shared GameObjects need to be recreated on the client with the correct netIdentity and authorities

How can I go about reconnecting, or setting up NetworkIdentity components in the ways above?

\$\endgroup\$
3
  • \$\begingroup\$ The server is still holding the actual logic/ data or is only responsible for matching the two clients? \$\endgroup\$
    – Zibelas
    Commented Sep 22, 2022 at 7:08
  • \$\begingroup\$ @Zibelas , yes the game is fully server-side authenticated \$\endgroup\$ Commented Sep 22, 2022 at 15:13
  • \$\begingroup\$ @Zibelas players also have unique IDs and there are matchIDs all available on server. Seems like I have everything I need, logically, but I don't know the right way to set things up. \$\endgroup\$ Commented Sep 22, 2022 at 15:29

1 Answer 1

1
\$\begingroup\$

It is a while since I made a reconnect with Mirror, here is roughly what I did:

  1. The server is storing a map of the players authetication as key, the value is everything that was tied to the player (matchId, roomId, NetworkConnection, etc), is basically just identifing that the reconnected player is the same one as a previous one. Docu
  2. In the Networkmanager you usually overwrite the OnServerAddPlayer(NetworkConnection conn). You can grab authentication and compare if it is a new player or reconnected from 1)
  3. You call the NetworkServer.ReplacePlayerForConnection with your needed parameters. This replaces the player object for a connection with a different player object. The old player object is not destroyed. If a connection already has a player object, this can be used to replace that object with a different player object.

I can't find my old code currently, not sure if that was all that was needed or if I had to clean up some duplicated objects. Once I found it or recoded it, I will add some proof of work. Feel free to add your own answer if you get it working before that

\$\endgroup\$
2
  • \$\begingroup\$ Thanks, 1. is player authentication just some uniqueID or is it something inside Mirror? 2. I don't understand step "2", I can detect if the client is reconnecting or not anyway (is that what it's doing?) 3. does "ReplacePlayerConnection" restore all the NetworkIdentities? \$\endgroup\$ Commented Sep 23, 2022 at 11:10
  • \$\begingroup\$ Did you find your codes? cuz it seems like I can't make it work. Thanks \$\endgroup\$ Commented Oct 6, 2022 at 11:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .