Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm making a c++ multiplayer game, and I'm trying to implement a server list, where everyone can host his own server. But I don't know how to start, I've google'd for a while and I didn't find anything about this. I tried to search for a master server specially designed to handle with the server list, so if I refresh it, it will ask the master how many servers it has, and tell the client the servers' informations, and I don't have any idea on how I could make it.

Could you just show me an example, or tell me how could I begin?

Any help is really appreciated.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Building a master server so people can host their own dedicated servers is not a hard task. Once you have setup a tcp/ip or udp server / client structure, you will need 2 basic things:

Heartbeat system: The idea of a heartbeat system is easy. A dedicated server hosted by players sends a heartbeat (just a packet with information) to the master server every x seconds, with basic information about the server (server ip, server port, server version, current amount of players, maximum amount of players, server-side variables such as game speed, game mode etc). The server will save this information in the server structure, for example a List of Server(class) objects.

Request list of servers: Once a player opens the client, it will send a packet to the server containing a command to request the server list. The master server then sends back a serialized list of all the servers that have sent a heartbeat in the last x seconds. This way you always have a up-to date list of all the player-hosted servers.

Also you should have a timer which deletes servers from the master server which have not sent a heartbeat for for example a minute.

share|improve this answer
    
I have build one such "master server" in PHP that can be installed on basically any web server. It's open source: bitbucket.org/jcpmcdonald/matchmaker/wiki/Home If not for the code, for the ideas. –  John McDonald Sep 5 '13 at 20:02
    
Yes, using a webserver is an option too. It's much simpler than the tcp/ip option, but the system will be alot more exposed to very easy hacks, simply because you don't have to be a professional hacker to visit a website. –  Basaa Sep 5 '13 at 20:23
    
Thank you so much! –  user2696223 Sep 5 '13 at 21:35
    
If you are satisfied with the answer, please accept the answer. (the check icon on the left of the answer) –  Basaa Sep 5 '13 at 21:39
    
Done, thank you so much again! –  user2696223 Sep 7 '13 at 17:48
add comment

Unless you're intending your players to all share a LAN or VPN, trying to implement a purely peer to peer game is very difficult; there are just too many firewalls and other obstacles to transparent routing. Plan to keep a public server with a stable IP address as the hub for all communications, and make any idea of a private server a virtual entity mediated by that hub.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.