Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

networking tournament - best practice

Discussion in 'Multiplayer' started by benblo, Jan 25, 2008.

  1. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    473
    Hi all network-professionals... ahem, Larus?

    I have a quick networking question: right now our game is purely 2-player (one versus one) based.
    We'd like to offer a tournament mode, where like 8 players would subscribe => 4 matches, then we only keep the winners => 2 matches, then a final match.

    My question is... what would be the best architecture to achieve that?
    My first impulse would be to have one player hosts a 8-player game, and let everybody connect. But then what happens for 2 clients that battle each other: do they need to be able to connect to each other directly? Are their RPCs relayed through the host?

    I'm asking because we're having connection difficulties (NAT punchthrough etc), so I'm thinking, if the host is wide open then everybody should have no problem connecting to it, but maybe 2 given clients couldn't connect to each other.
    For example, between my development Mac and my test PC, the PC needs to be the host and the Mac the client. If my Mac is the host then my PC can't connect (NATTargetNotConnected, CreateSocketSomethingError).
    Also, sometimes my Mac receives OnFailedToConnectToMasterServer, so the game isn't even in the list.

    I realize all this won't be an issue when connecting will be 100% failsafe (which I believe is Larus' goal... I really hope you achieve it :)... soon :p !), but in the meantime...
     
  2. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,304
    Hi Ben,

    aside from the potential connection issues, you might want to have a look at this thread, if you haven't done so already. Depending on your game design, you may or may not run into similar issues when having a server for 8 players in 4 games. Basically, I think when you are playing in the same level, it *should* work by using groups. It may require some "housekeeping", though, to make sure the differnet game sessions don't interact in funny ways...

    Concerning the network question, I'm not sure... I think probably, the connection goes via the server. There's a nice example somewhere in the documentation on how to use "TestConnection()" which will make sure, when used correctly, that only hosts register as servers, with which it will work...

    Jashan
     
  3. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Posts:
    274
    One way would be to use a dedicated coordinator type of server. The clients would all connect to him and enroll in the tournament, something with simple RPC functions. The 4 matches are given unique identifiers as well as the clients. Each client does a connection test to see if they are NAT punchthrough capable, if they need that. If they can't connect directly to each other the server needs to spawn a game server instance which they will use. In any case the 8 clients have the information they to connect and play their matches. They disconnect and do their thing. When done all clients report to the coordinator again, sending in the match results using their match identifier (simple RPCs again). Then the process is repeated until all matches are played. The coordination server should be able to manage multiple tournaments with lots of clients, since this is just a bunch of RPCs with small data payloads. You have good control of where you send your RPC so you could easily manager groups of clients yourself.

    This way you can circumvent the need of managing 4 different games with 8 clients on one server instance. Doing it that way is harder (see the thread Jashan pointed to), but its probably less error prone regarding client being unable to start their match because of some connection error or whatever.
     
  4. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    473
    OK, thank you both for your answer, it'll take my mind a while to digest that ;), but I think I got the main points.
    So just to confirm, does that mean that if I connected 7 clients to a central host (who would play too, not a dedicated host), RPCs between clients who be relayed through the host? Or does my question make no sense?

    Your idea of a central server reminds me of something I've be wondering for quite a while: what exactly does the MasterServer do? Is it just a list of games, like a simple database? or does it have to do with the NAT facilitator?
    'cause if it's just a list, it wouldn't impact my architecture to just replace it with some sort of PHP webservice that would give my a list of games, thus allowing me to build my own DB with much more info (like nicknames and stuff)... or would it?
     
  5. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Posts:
    274
    The RPCs are always relayed through the host. The only thing the clients are connected to is the server. So everything a client sends to other clients must go through the server, he knows how to route it. Its a client-server architecture.

    Its just a place to advertise game servers to clients. It does a little more than that in relation to helping set up NAT punchthrough and such, that is a non-trivial matter. It can, however, be replaced with something completely different, its up to you. The source code is available (info in the networking manual) so you can do with it whatever you want. The host info data structure does carry an extra comment field where you could stuff your own data structures with extra info. Your mention of nicknames makes me thing you have might something more/else in mind. Its just a place do distribute server info, its not made for player info.
     
  6. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,304
    Hi Larus,

    Could you give us an approximate "performance penalty" when doing the routing in C# scripts, i.e. when the game server "decides" who gets which messages (remember my other thread about SetSendingEnabled / SetReceivingEnabled?)

    Would that be significantly less efficient, or would it just be "a bit less efficient"? Like, "takes two times longer" or "takes 20 times longer"?

    Jashan