Template Workshop 3: Internetlist Template
In this Workshop you will learn how you can create a list of internet
servers of your game. For using this template you need a server that
supports PHP and MYSQL (you can also use servers from free hosters or
install a local server).
The theory behind
The serverlist is stored in a MYSQL database that can be reached through a web server.
If a new game server goes online he sends his informations via http (the protocol that is used by the world wide web) to the web server. The web server executes a small php script that passes the data to a MYSQL server (which is running on the same machine). Then the MYSQL server adds the entry to the database.
If players search for game servers they contact the web server. The web server again executes a php script that contacts the MYSQL server which forwards the whole content of the database to the web server. Then the web server sends back the result to the client.
Let's see how the table in the database looks like:
For those who have already some experience with database development:
The primary key is a combination of Ip and Port. Ip is a number that
represents the 4 Byte of the Ip address.
The Ip is automatically detected by the php script.
Port is the port number that was used when the game server was started.
Name is the name of the game server.
If Password is 1, the server is password protectet. Otherwise it is 0.
NumPlayers is the number of players that are currently playing on the server and MaxPlayers is the
maximum number of players allowed on the server.
Map is the name of the map that is currently played.
The most interesting field is UpdateTimestamp. This is the time, when
the server entry was updated last. If an online game server was added
to the server list he has to update his entry from time to time.
Otherwise it will be deleted automtically if the serverlist is
requested by a player. This way servers that crashed or lost their
internet connection won't be in the list forever.
The update interval can be set as required. But keep in mind: The
higher the update rate, the higher the produced traffic. --> a better
server with a better internet connection is required.
The database and the php scripts are ready to use. They only have to
be imported into your server. Also the connection to the web server
via http_post() is already implented in a ready to use lite-c file. It
can be controlled through an easy interface.
Configuring the server
As example configuration we will set up a local test server:
For local testing I advice you to use XAMPP. XAMPP is a free bundle
that provides a web server (apache) and a MYSQL server. Just download
the latest XAMPP version from the official homepage:
Download the windows installer and follow the steps of the
After a successful installation, open the Control Panel and start the
Apache server (this is the web server) and the MYSQL server:
Contgratulations, now you have a web server and a MYSQL server running
on your system. In the next step we will setup everything so that the
template can work with the servers:
First of all we have to create our database. Therefore open your
browser and type in or click on the following link: http://localhost
If your Apache server is running you should see the following picture:
Now click on phpMyAdmin to open the configuration interface of the MYSQL server.
Now click on Import. Select the db_server.sql file which is in the folder of the template under "ServerInstallation/mysqlServer". Then click on GO.
Now db_server(1) should be on the left like in the following picture. Click on it so that we can config this database:
If there would be a server in our table we could show the content of the whole table by clicking the button next to tb_server:
Just keep that in mind, we will need that later.
In the last step we have to copy the .php files which allow us to get access to the database over the internet into the correct folder.
Therefore open the "webServer" folder (that comes with the template) and copy the whole folder named "serverlist" into C://xampp/htdocs/.
And that's it. The server is now ready to use. Let's check out if we can do something with the list:
The example project
The template comes with an example project which is in the "Example" folder. Start the application "ITemp_Example.exe" on the same machine as your server is running.
Press [A] to add a server into the list. Now open the phpMyAdmin again, click on db_server (on the left side) and press the "show" button next to tb_server.
If everything worked fine, you should see your server there.
If you press [G] you should see the content of the table in the test project.
If you press [I] the number of players of the server will be increased. After around 30 seconds the change will be visible in the table because the entry is only updated every 30 seconds (this can be changed though).
After the 30 seconds, press refresh in the phpMyAdmin window and you should see that the number of current playing people has increased by 1. Also if you press [G] you should get the new value.
If you press [R] the server will be removed. But if you look into the table through phpMyAdmin you will notice that the server will be still there?! Even if you have waited a few minutes! If you press [G] to get the new list you will notice
that the entry has been removed now. That's because GetList.php runs through the whole table and deletes all entries that wheren't updated since a certain timeout (3 minutes by default). Pressing [R] only stops updating the server entry.
How to include the template into a project?
First of all you have to copy the script files into your project main folder. The script files are located in the "Lite-C" folder.
Then add this line #include "Serverlist.h" after this line #include "anet.h".
Now you have full access to the template's functions.
A short overview
At first the template always has to be initialized by using this function:
The ServerListEntry struct:
This struct represents an entry in the server list. If you want to open
a server that is added to the list, fill the struct with the informations about your
server and share it through the function LanTemp_AddServer() (lan template) or ITemp_AddServer() (internet template).
The ServerList struct:
This struct represents the whole server list and is filled by
LanTemp_GetList() or ITemp_GetList().
If you need an example code look into ITemp_Example.c. For more
informations about the template functions look into Serverlist.h.
There are a few important settings that can't be set through the ITemp_Init() function:
This is the time that should pass between the server list entry
updates of a server that is listed in the serverlist. It is defined in
If a server update wasn't sent until this time has passed it will be
removed from the list. This setting is defined in GetList.php.
Please make sure that ITEMP_UPDATERATE is less than a half of TIMEOUT.
The username that should be used to connect to the mysql server.
(GetList.php and AddServer.php)
The password that should be used to connect to the mysql server.
(GetList.php and AddServer.php)