Search Unity

Unity RPC host migration.

Discussion in 'Multiplayer' started by Christian-Tucker, Jan 24, 2015.

  1. Christian-Tucker

    Christian-Tucker

    Joined:
    Aug 18, 2013
    Posts:
    376
    I'm not very experienced when it comes to the Unity3D Networking implementation, as I've always used my own custom implementations, however for my current hobbyist project I feel like using the built-in networking will serve a good purpose.

    The over-all idea of the game is going to be 2~16 players in an on-line match, similar to how most FPS games are played, but this will be an action-combat game-style, in which all logic is going to be handled by the host. This of-course will create the "unfair-advantage" that the host will get, because of faster reactions, and always being on-point.. but what can you do.

    The thing is, I don't want to just "end the game" when the host decides their done, instead I'd like to migrate hosts, but I have no idea how to go about doing this, honestly I don't have a clue how to go about ANY of this while using the Unity networking, but I'm about to dive in head-first into all of that. The concept from the last few things I've read seems very simple, the only thing that bothers me is not having the server/client separated. I enjoy being able to know that all data is going in/out of the server, instead of having to distinguish on the spot. Guess I'll have to make some dedicated servers, eh?

    Anyway, host migration, how?

    I understand the concept of creating a collection of connection data, but I have no idea how to go about transferring the hosts, making sure everyone gets transfered to the correct host, etc. The last thing I'd want is for a game to get split into 3 different games because the host got disconnected.
     
  2. AustinRichards

    AustinRichards

    Joined:
    Apr 4, 2013
    Posts:
    321
    So one method you could do, is when everyone's playing the game, ensure every player is receiving all the host's data. If the host disconnects, one of the other players steps up and uses the data received from the old host to continue the game. You will have to manually decide what variables to send to the clients relating to the host, and figure out how to use them to set up the game from the information to "unpause" it on the new host.
     
  3. Christian-Tucker

    Christian-Tucker

    Joined:
    Aug 18, 2013
    Posts:
    376
    The problems with this is handling host reconnection, all players will not have the availability to host. Some routers do not support NAT Punchthrough, or have it disabled by default. Some players will not have the proper ports forwarded to host the server.

    Once you bypass this, you must think about how to ensure that everyone either A) Connects to the same host, or B) Gets dropped from the game.

    Typically when you can't connect to the new host after a few times, You'll attempt to either A) Connect to another host, or B) host it yourself. A might not be that big of a problem, but what about B? Now there's two games going with the same information. Now what if Player C can't connect to player A, and instead connects to player B, but player D does connect to player A?

    Now we have duplicated games
     
  4. AustinRichards

    AustinRichards

    Joined:
    Apr 4, 2013
    Posts:
    321
    You're going to need some server that keeps track of the games. You might be able to also have it where, you Host it yourself. Then try to connect to the other IPs (in the same order on every client somehow) and if it can connect to one of them, the 1st one it connects to will be the new host, and it'll turn off the server you started on your client. So when a host disconnects, every1 starts a new server if they can, then iterates through the other client IP list for open servers (in the same order hopefully) and connects to the 1st open server, and turns off their local servers they just started.

    Idk, just some idea you could play with. I strongly prefer have 1 central authoritative server, rather than having clients host their own games.
     
  5. Moonstorm

    Moonstorm

    Joined:
    Jul 26, 2012
    Posts:
    23
    This is a very hard problem to solve using Unity's built-in networking, as it was not designed for this kind of use-case. I would think very hard about your game and whether people dropping-in and out will happen a lot. If so, you might have to bite the bullet and go for a central authoritative dedicated server approach.
     
  6. Christian-Tucker

    Christian-Tucker

    Joined:
    Aug 18, 2013
    Posts:
    376
    Typically that's a good solution, which I use in my other projects, but for this one it's completely designed around player-hosting. (Obviously with a dedicated customized master-server)