help learning about unity master server

hi i have a project in which is ready for a multiplayer game in this case i’m thinking of using the builting unity networking in which i have used before. this will be a game of 4 players coop with some enemies to fight against.

now one of the problems i see is that normally users can’t really host their own games because of port forwarding.
and the whole nat punchthrough. now some people mention about using the masterserver for this thing.

the unity networking tutorial doesn’t seems to work well with some users and at the same time i need a c# form of it.

other thing is that i see people doing things such as hosting this on a web server and so on.

so my question would be is there anyone that could guide me on the right direction?

first i’m new about the whole hosting, i don’t know much about how people do about using the master server through php in which i heard nor i know php. and the other thing would be what about using a database and so on? is it going to be through unity too?

Do you know how to set up Peer-to-peer networking? If so, it’s pretty much done the same way except there’s no player on the server machine. If you don’t know how to do p2p, I suggest GTGDs tutorials which can be found on these forums.

i’m able to do the whole direct connection and so on like if you type someone else’s ip.
where im really trying to get to is, of what i know if i for example use the default master server that comes with the unity networking tutorial in which i have no idea how it works lol. it wouldn’t be good since it’s more like for testing and so on.

now what i’m actually trying to acomplish here is people to be able to host their own games and no unity it’s not a p2p that’s not how unity networking works. it’s a server to client network. one person becomes the server and the other becomes the client.

anyhow i’m trying to do a hybrid connection using unity networking for things like AI and so on since it’s not easy to set up and do with smartfox and the regular multiplayer in there lol.

Unity’s Master Server helps with matchmaking and NAT traversal (but only if you use it for matchmaking too).

When a user starts a game session, they register it on the master server and generally initialise as a server in the usual way. When another user wants to join a session, they ask the master server for a list of sessions, which it provides along with some details about each session (provided by the game server). The client picks a session to join, passing it into Network.Connect instead of using an IP address. Unity then performs NAT negotiation if necessary to connect to the game server, and once that is done the Master Server is no longer involved. The game server can update the Master Server with new information about the session, but that’s only used to allow clients to see information about the various servers before joining them. It’s purely matchmaking.

In the example I gave, the game is still using a server hosted by one of the players - it’s just also using a Master Server to help users find each other. But you could equally well have dedicated servers in a datacenter, which can register themselves in exactly the same way with the Master Server.

Hi,
George Foot your answer was clear, but I’ve 3 questions now:

1- If one player initialize server and host a game then some others connect to that host for playing together, what will happen if the host player suddenly disconnect? I mean all the connected players will be disconnected also? Is there a way to switch those players in another host room without problems or resetting stuffs?

2- If we want to have a dedicated server I found out that simply we can pass true to MasterServer.dedicatedServer, so after this done, what will happen if a player run Network.Initialize?

3- In dedicated mode, if we want to have some maps (city, jungle, warehouse, …) and in witch of them some rooms with limited max players, how can we structure our game? I mean we can only register a host game on the server with just unique GameTypeName, so then for calling RequestHostList we have to tell what GameTypeName we want to fetch. So it will return only one host because of using dedicated server. I’m a little bit confused here between concepts.

Thank you for your help.

I got your PM but I don’t have access to the old account any more so can’t reply.

  1. Unity will notify the clients that the host has disconnected, then it’s up to you what you do with that notification. I don’t think Unity has built-in support for host migration. You can build something on top, but it’s a complex task. Host migration is a messy business - you might not be able to pick a client that everybody can connect to, for example, for NAT reasons.

If you want to go down this route then you should probably start with just getting the players to quit the active level and reform the session around a new host. Even that is hard to do smoothly, and almost impossible to do reliably given the intricacies of NAT.

Once you’ve got that working you could look at trying to migrate without quitting the level, which involves more work on top - migrating ownership of game objects, in particular. In any case, you’re probably looking at a gameplay break of 10-20 seconds, and a high chance that some clients will not be able to join the new session.

  1. I think that just affects the number of clients connected field that the master server reports to prospective new clients - if the server is not dedicated, it counts as a client, and adds one to the connection count, while if the server is dedicated it does not add to the connection count.

  2. I’m not sure what you mean here. You can add whatever you like to your game type string, so the master server does filtering by level for you, but it will only report exact matches. If you need a mixture of searches, you have to do the filtering on the client, which kind of sucks, but Unity’s master server is really rather poor. You can use something like Gamespy, or other middleware, instead, though its integration with Unity’s networking is not as good. Also, anything other than Unity’s masterserver API would require a pro license for mobile, which might be significant for you or not.

You can extend the master server though, and treat the game type string passed by the client as a query string in whatever format you like. Then you make the master server interpret that and filter the server list properly. You’re stuck with a pretty lame API for the client to use, but the string format is at least flexible enough that you can embed something structured inside it.

Thank you so much gfoot!

So I think it’s better to explain a little more about what is in my mind.
Because I want to run my online game on a normal web server with low traffic, I decided to not use authoritative server instead whenever needed using one of my best clients ( low ping etc.) as a server to others. But a normal client may leave the game anytime and that breaks the game of others connected!
But now with your complete response I realized that handling host migrations is expensive and risky to do, somehow impossible, So I have to run one single instance of game and all the others connect to it. But now i’m facing more questions:

1- With online game ( There’s no standalone version) how can I keep my game running? I mean the InitializeServer just works without any IP in auruments so it will always run on the visitor machine ! How’s that for having an eternal running server?

2- I must play with gameTypeName string as a key to any specific level that I want? the below C# declaration is what you are saying ???

List gameTypes = new List {
“JUNGLE_DEFENCE_ROOM01”, //jungle with gameplay type #1
“JUNGLE_DEFENCE_ROOM02”, //jungle with gameplay type #1
“JUNGLE_ESCAPE_ROOM01”, //same jungle with other gameplay
“JUNGLE_ESCAPE_ROOM02”, //same jungle with other gameplay
“CITY_DEFENCE_ROOM01”,
“CITY_DEFENCE_ROOM02”,
“CITY_ESCAPE_ROOM01”,
“CITY_ESCAPE_ROOM02”
,“etc”
};

In this manner all hosts (game rooms) will have exact maxplayers (max connection) because it is defined in InitializeServer. That’s not very acceptable for me. Can we have different maxplayer for every host?