Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1401054 Posts in 67847 Topics- by 61382 Members - Latest Member: lolapaluuza

May 27, 2022, 10:41:31 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Master server for an online game
Pages: [1]
Print
Author Topic: Master server for an online game  (Read 4247 times)
NickWaanders
Level 0
**


View Profile
« on: November 01, 2007, 12:29:12 PM »

Hello boys and girls,

I am wondering if there are any people here that have dealt with creating a master server for an online game.

The way I've got it set up now is like this:
- Master server: This server is sitting at a static IP, and all it really does is wait for UDP messages from hosting servers. Hosts are expected to keep sending the master server updates on a regular time interval (updating things such as nr players, current map, etc). When a host does not send updates for a while (currently 10 seconds), the host will be removed from the active list of servers.
- Host server: This would be somebody who wants to host a game. Once the server is started up, it will send the master server updates every (currently) 2 seconds. Other than this, the host will wait for clients to connect to it, and handle them accordingly.
- Client: This would be somebody who wants to join a game. When you press join, it will connect to the master server, which will return a list of active servers. Once you select a host to connect to, communication will be between that host and the client.

So the questions I would have are:
- Am I on the right path?
- What is a good heartbeat period for hosts? Is 2 seconds too much?
- What is a good timeout period for a host to be removed? Is 10 seconds too little?
- Currently the master server just receives host messages, it never sends a message to the host to make sure it's actually available. Do you think this is critical? It would increase the server bandwidth, but it would also increase the reliability of the system.
- When clients request the list of currently active servers, the server needs to somehow send them the info. I'm thinking this could get very big, and if you have lots of clients joining, it could pretty much kill your bandwidth. So I am wondering if there is a smarter way of doing this. For example multicasting current servers, but I am not entirely clear if multicasting actually works 100% in the current internet-world. Should I be sending little packets of servers to clients over time, basically load-balancing between clients? This would make getting the list of servers really slow if there are LOTS of clients, but at least the system was created with this expectation, instead of a system that just blows up when there's lots of clients.. Smiley
- Are there any recommendation about NATs? Should I worry about them, or should I assume that anybody who wants to host has the expertise to open up a port on their router?
- Any other recommendations?

Cheers!
    Nick



Logged
Michaël Samyn
Level 3
***



View Profile WWW
« Reply #1 on: November 02, 2007, 02:22:43 PM »

I don't know much about this type of multiplayer game. Forgive me if what I say is irrelevant.

I like using web-based databases for these kinds of communications. MySQL and PHP, basically. For your list of servers, maybe this could just be a web page somewhere. Could even be hosted on another server. And your game server simply updates that one database rather than sending the data to each client individually.

Please ignore if this makes no sense.  Embarrassed
Logged

Tale of Tales now creating Sunset
NickWaanders
Level 0
**


View Profile
« Reply #2 on: November 02, 2007, 05:44:07 PM »

(warning, long post)
Actually, that does make sense. However, isn't this just introducing another step in the system by adding in a webserver that hosts the webpage? I guess the good thing would be that you can limit your bandwidth to our own game-server and instead route everybody to the web-server.

At first I was thinking of a completely PHP based system, but I couldn't figure out how to keep track of disconnected servers without using big database purges, which could make the whole system slow, and we'd be getting calls from our web host Smiley

Currently I changed my mind a little bit from the original post, now I am thinking of never sending a big list to clients at all, so the bandwidth should be no issue anymore. Instead I give the option to query for a server (for example by name, location, etc.), or simply by quick-matching (no query options, just find one). That way I can just a short list of max 5 possible servers or so. The only thing I would need then is more CPU to process all the queries on the master server side, but that is quite easy to scale up if needed, you just buy more CPU's.. Smiley


As a side-note for people who are interested in this subject, I've found out a bunch more things (some may be obvious, but they weren't to me! Smiley )

- NAT's (network address translation, something that routers do for you so you can have multiple computers on the same external IP address) are a problem, but there are ways around them. UPNP is a way to communicate with your router through udp, and with this you can request certain ports to be opened up. There are several pages with info on this, one of them on codeproject.

- STUN servers are another way to get through a NAT. What a NAT does is basically remember what local IPaddress sent a message through what port. Then if traffic comes in on that same port, the NAT will forward that message to the local machine it remembered. So the problem is that if computer A randomly tries to connect to computer B through a NAT (on B's side), the NAT will get a message with a port that it hasn't recognized before, and therefore doesn't know where to send it. It basically just drops the message. However, if computer B was recently sending data through that port, and now computer A tries to connect, there is a chance (depending on the type of NAT) that the NAT still remembers that traffic on that port needs to go to B, and lets the message through. So how do you get B and A to send messages at the same time to each-other? This is where the STUN server comes in. The STUN server is a separate server with an IP that is known to both A and B. So if B is connected to the STUN server, and A tells the STUN server that it wants to connect to B, then the STUN server will start sending messages to B, after which A will start sending message to B as well, with the hope that the NAT still remembered where the messages went, and in that way will get through the NAT. Again, this depends on the type of NAT through.

- Because there is a master server that keeps track of all the games being played, this server can act as a STUN server in case one of the clients does not have a UPNP compatible router, and in this way a NAT punch-through can be attempted by blasting packets at each-other and hoping that the NAT's have still remembered the routing to the local machine. We'd need to have our master server sit on a static IP for this though, but we were planning this anyway.

- With UPNP and a STUN setup, you still won't get through all NAT's, but you will get through most home-routers. Hey you're not supposed to play games at work anyway Wink


Side note 2: We're NOT trying to make an MMO if this is what you're thinking. We're just trying to make a game that is playable online, much like the quake setup where you can see a list of servers and join one.

Cheers,
  Nick

Logged
Michaël Samyn
Level 3
***



View Profile WWW
« Reply #3 on: November 03, 2007, 01:01:00 AM »

For us, web servers are an integral part of our activity (for portfolio display, promotion, community, etc.). So it's not a big deal to add an extra database and a few scripts. It does add some extra complexity to the game. But it also takes some away (PHP and MySQL are very convenient and fast -at least compared to how our game engine handles databases). Andother advantage is that when the game server is down, the web server can report this to the players. And vice versa.

Come to think of it, though... What do you need a game server for? Once the match is made, one of the client becomes the server, no? If all the game server needs to do is match-making, then it might very well be replaced by some PHP scripts and an online database.
I'm probably missing something...   Embarrassed

Currently I changed my mind a little bit from the original post, now I am thinking of never sending a big list to clients at all, so the bandwidth should be no issue anymore. Instead I give the option to query for a server (for example by name, location, etc.), or simply by quick-matching (no query options, just find one). That way I can just a short list of max 5 possible servers or so. The only thing I would need then is more CPU to process all the queries on the master server side, but that is quite easy to scale up if needed, you just buy more CPU's.. Smiley

That sounds like a smart solution. Then you only need to offer search criteria that can reduce the list sufficiently. Many of these criteria will have to be input by the host players, I guess. But many only need to be filled in once (like location and name, etc) as they apply to all games they host.

By "quick-matching", do you mean a system in the vein of Nintendo's Friend Code system. I'm not familiar with this system but it sounds like a good idea for organising online multiplayer game ("O.M.G."? Shocked).

One more thought. What makes you think the bandwidth usage of sending a list of hosts will be so extreme? It's just text isn't it? And you only need to send it once every x seconds. How demanding can it be (compared to the average web site these days, e.g.)? (and is there not a way to compress/encode it to reduce bandwidth requirements?)
Logged

Tale of Tales now creating Sunset
NickWaanders
Level 0
**


View Profile
« Reply #4 on: November 03, 2007, 01:47:10 PM »

Ah, no, the master server is not the game server. The master server is just a server that keeps track of what games are currently being hosted, and are ready to be joined by clients. Clients would simply connect to the master server, find a hosting server, and then join that hosting server. So basically the master server is intended to be just a central point of access for all games that want to play online.

We were thinking about doing this with php scripts at first, but got a bit worried about scaling. (Maybe we're totally thinking way too big by the way, so please tell me if we are.. Smiley ) What if your game gets 1000 players that are all requesting lists of servers? If you have 100 servers up, then sending a whole list to a client would take up quite a lot of bandwidth. We're planning on sending 4 bytes for the IP, 2 bytes for the port, the name (30 bytes max?), any game settings, map names, etc. So you're quickly talking about 50 bytes per server, times 100 servers is 5000 bytes. And this is to one client asking the list. times 1000 clients, that is about 5mb per second if they ask for the list once per second.. So say for a monthly cost, if it's just for the US/Canada, it would probably be 8 hours per day, 31 days, so 31*8*60*60*5mb = 4.4Tb (that is 4464 gigabytes) bandwidth per month. I think we would get a phone call from our provider really quickly if this would happen, even if we put it on our webserver Smiley

Like I said, I totally may be overestimating here, but it also shows that it adds up *very* quickly. This is why we decided to switch to a simple server instead of a php based system. Again, I'm new at this stuff so I'm just looking at what games like Quake and such did, because that is pretty much all the information I have. Do you have more info the php based system you're mentioning? Things like bandwidth, etc?

With Quickmatching I mean a system where all you have to do is press one button, and it finds a server for you, and you join it. So a very quick way of joining a game, without the hassle of finding a proper server, etc..

Actually the location of somebody can be derived from the ip address. There are a few paid services to do this, and a few are free but less precise. It's kinda neat, you can match people together based on the distance of their home town.. Smiley
Logged
Michaël Samyn
Level 3
***



View Profile WWW
« Reply #5 on: November 03, 2007, 04:02:24 PM »

I don't understand why you need to send the list of servers to every client every second.
They only need the list before they start playing, right? To choose a host? During the game, they don't need to see the list. And I would hope that they spend most of their time playing the game.
Also, an updated list every second seems excessive. Why not update once every 20 or 30 seconds and add a button to manually refresh the list, if they are looking for something specific that just came online, e.g.

I know too little about your project or the technology to be of real use to you. But hopefully the silly things I say trigger some smart thoughts in your head.  Grin
Logged

Tale of Tales now creating Sunset
NickWaanders
Level 0
**


View Profile
« Reply #6 on: November 05, 2007, 12:09:17 PM »

I was mostly thinking of a quicker update rate so that servers which are full get removed from the list. I guess there are other ways of doing it though that don't require such a fast update rate.. See this is what I need to get an idea about I think, and now that you say it, it does sound a bit excessive to send the list that often.

Yes, the main reason I posted this was to get some different ideas on the subject. Thanks for the discussion! Smiley
Logged
Michaël Samyn
Level 3
***



View Profile WWW
« Reply #7 on: November 05, 2007, 04:18:24 PM »

You're welcome.  Smiley
Logged

Tale of Tales now creating Sunset
raigan
Level 5
*****


View Profile
« Reply #8 on: November 07, 2007, 04:47:25 PM »

hey nick Wink

i'd try asking on the indiegamer forums as well: http://forums.indiegamer.com/forumdisplay.php?f=3

Logged
queasy
Quite Possibly Jon Mak
Level 0
*


View Profile
« Reply #9 on: November 17, 2007, 05:27:45 AM »

I guess I'm a little late on this, but I wrote a master server once.  Mine was simple though because it didn't need to handle much load.  Also I don't remember much about it.  Still, I found Valve's article on it to be very useful: http://www.gamasutra.com/features/20000511/bernier_01.htm .

Also, don't take NAT lightly.  Make it your top priority to ensure that your punch-through works!  I've found that 99.9% of my players were behind NAT and therefore could not host a game.  I'm pretty sure this was a significant reason why my game could never sustain an audience: nobody could host games.  Well there were other serious issues too, but that was one of them.

Hope it helps.

-j
Logged
NickWaanders
Level 0
**


View Profile
« Reply #10 on: November 26, 2007, 10:28:53 PM »

Awesome, thanks Jon! That article is awesome! I wonder why I didn't notice it in my google searches..

So you tried to implement punch-through? Do you remember if you used UPNP or another method?

-Nick
« Last Edit: November 26, 2007, 10:59:02 PM by NickWaanders » Logged
queasy
Quite Possibly Jon Mak
Level 0
*


View Profile
« Reply #11 on: December 07, 2007, 07:45:43 PM »

hey, sorry for the late reply again, i gotta turn notify on or something.

anyway no, i never implemented punch-through, so i don't have any good info to give you, sorry!

EDIT: i know, i'm useless...

-j
« Last Edit: December 07, 2007, 08:11:33 PM by queasy » Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic