How to distribute game info

Started by
7 comments, last by hplus0603 12 years, 9 months ago
Hello

I'm working on a network game that runs without a master server. The one who starts a game hosts it. Of course he has to distribute some info to the other computers, before they can log on, like his external ip or the type of game (free for all, capture the flag etc.).... How is this done best? For testing purposes I've done it with simple ftp upload and download, but this is somehow very slow and not very elegant when there are lots of games running.

What would be a good way to do it? With PHP and/or MySQL? If you know some links or key words to search for it would be great!

thanks
Advertisement
So what you want is something like a list of all currently active servers?

I'd just write a simple program that accepts a connection from a server, validates it, tracks the IP/gametype/etc., and then hands that data back out on demand. When a server comes online, it connects to your master centralized box, registers itself, and downloads a list of other available servers (if applicable). When the server disconnects, the master tracker automatically unregisters it and removes it from the list, so the next time someone asks for a list of available servers/games, the recently shut-down machine doesn't appear.

Should be pretty easy to build; couple of days, tops. No need for a back-end database or anything else, you can just hold the list of active servers in RAM.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]



How is this done best?


By using UDK.
You say your work on a network game without a master server. If by network, you may LAN and not the internet, I would suggest using UDP.

The host who created the game will periodically use broadcast UDP packets to all computers in the network with information about the game. The computers that care (where your client program is running) will intercept these packets and show the server in a list. Try searching "UDP broadcast" or "UDP Socket" and add the name of your programming language. Once again, this does not work for the internet, only for LAN.

Otherwise, you will need a master server, even if only to store this data. In that case, ApochPiQ's suggestion is best, provided that you have a computer with public IP at your disposal. If you are stuck with FTP/HTTP hosting, PHP/MySQL is a good choice. That half second difference of connection to the database isn't important when you look only for a list of servers.

I'm working on a network game that runs without a master server. The one who starts a game hosts it. Of course he has to distribute some info to the other computers, before they can log on, like his external ip or the type of game (free for all, capture the flag etc.).... How is this done best? For testing purposes I've done it with simple ftp upload and download, but this is somehow very slow and not very elegant when there are lots of games running.


In this case, your "FTP" server is your "master" server.

If you only support networking on a LAN, then any broadcast-based discovery protocol will work. Look at mDNS/Bonjour for example. (Used by iTunes et al)

If you want to support the Internet, you need to start a lobby server that each server instance can connect to to register availability, and each client can connect to to get a list of running servers.
enum Bool { True, False, FileNotFound };

[quote name='domok' timestamp='1310068369' post='4832462']
I'm working on a network game that runs without a master server. The one who starts a game hosts it. Of course he has to distribute some info to the other computers, before they can log on, like his external ip or the type of game (free for all, capture the flag etc.).... How is this done best? For testing purposes I've done it with simple ftp upload and download, but this is somehow very slow and not very elegant when there are lots of games running.


In this case, your "FTP" server is your "master" server.

If you only support networking on a LAN, then any broadcast-based discovery protocol will work. Look at mDNS/Bonjour for example. (Used by iTunes et al)

If you want to support the Internet, you need to start a lobby server that each server instance can connect to to register availability, and each client can connect to to get a list of running servers.
[/quote]

Something which at first seems a little goofy but works quite well, is to pull in a little XMPP library and do all of this with the jabber protocol. I thought it was rather insane at first but in practice I'm a convert because of all the other things it lets you do when you get time to implement them. You still have to run a jabber server somewhere for this to work, or get permission to use someone elses (or be rude and don't "ask" since this is low bandwidth just for testing) but the jabber servers are fairly easy to setup and run locally for testing. Anyway, for advertising a game server things are very simple, the server logs in a bot XMPP client with presence information describing the game, ip address etc and it joins a specifically named channel. That's all, just update the presence information and you don't need anything else on the server side. The client side lists the channel and queries the presence information of each occupant, thus getting all the data required to see the status and join a game.

Anyway, that's the easy stuff. The more interesting items to me are that you can use the same library for in game chat, friend list/block list, online/offline/busy status etc. Extensions allow video chat (say put your buddies face on an in game toon), voice chat without central server bandwidth, etc etc. I'm still playing with such items and not convinced it is all going to work out, but as something that should take all of a day to setup for your initial problem, it comes with a lot of bells and whistles to play with later when you have time.
Thanks for your replies. I have now made a php program that creates a list of all the servers so you can call something.com/p.php?ip=255.12.24.22&mode=freeforall or something like that... The php program appends this new server to a file (say List.txt)

Now I have another question: How can you do such a http request (something.com/p.php?ip=255.12.24.22&mode=freeforall) from your C++ program? Is there the possibility to do it with raknet (so I don't have to get another library)? And if yes, how? Or how do I have to google for it?
And what is the best way to get the List (List.txt) from the internet to the C++ program? Just download the file and open it from the program?
The HTTP protocol is pretty easy; just look up any HTTP tutorial on the web and it should tell you how to format the requests. A simple GET should be all you need to implement in your model.

Note that your approach has a weakness: if a server crashes, it won't be able to update the master list and tell it to stop listing that server. As a result, you may want to implement some kind of timeout where servers are pruned from the master list every few minutes, and have to re-register periodically to stay active.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]


Thanks for your replies. I have now made a php program that creates a list of all the servers so you can call something.com/p.php?ip=255.12.24.22&mode=freeforall or something like that... The php program appends this new server to a file (say List.txt)

Now I have another question: How can you do such a http request (something.com/p.php?ip=255.12.24.22&mode=freeforall) from your C++ program? Is there the possibility to do it with raknet (so I don't have to get another library)? And if yes, how? Or how do I have to google for it?
And what is the best way to get the List (List.txt) from the internet to the C++ program? Just download the file and open it from the program?



1) Don't send the IP address as a query parameter. That would mean that a) the registering server has to discover its own external IP before registering and b) anyone can register any server address, which can be used for griefing. Use the IP address of the remote host of the request as the IP that's registered, instead.

2) Appending a server to a file means that, if multiple servers register at the same time, you'll probably screw up the file. Use a database; that's what it's for!

3) Getting a list of servers should typically be a service request -- you query for certain parameters (mode, player count, name-contains, latest-registration-time, ...) and out comes a list of servers matching those parameters (limited to some maximum number). Again, a database is fine for this.


To make a C++ HTTP request, use libcurl. If you don't want a large library, some C++ source code to make a HTTP GET request (without actually following the letter of the HTTP spec) is available, too.
enum Bool { True, False, FileNotFound };

The HTTP protocol is pretty easy; just look up any HTTP tutorial on the web and it should tell you how to format the requests. A simple GET should be all you need to implement in your model.


I disagree with your statements here.

First, proper HTTP clients support tags, Accept headers, Encodings, Expire dates, etc. Doing all of that right is non-trivial.

Second, trying to WRITE to a database using a GET request is a violation of the HTTP spec. GET is supposed to be idempotent -- multiple GET requests should not change the behavior of the server on the other end. However, other things may change the result of a subsequent GET, which is why Etags and cache/validation/expires headers are important.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement