1
\$\begingroup\$

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.

\$\endgroup\$
0

2 Answers 2

4
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ 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. \$\endgroup\$ Sep 5, 2013 at 20:02
  • \$\begingroup\$ 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. \$\endgroup\$
    – Basaa
    Sep 5, 2013 at 20:23
  • \$\begingroup\$ If you are satisfied with the answer, please accept the answer. (the check icon on the left of the answer) \$\endgroup\$
    – Basaa
    Sep 5, 2013 at 21:39
0
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .