Improving 24/7

How-To: Put live server stats on your chalkboard MOTD

1. Introduction

The long awaited guide how to put live stats to MOTD is here! Make sure you've read our guide How-To: Create a TF2 chalkboard style MOTD with HTML first.

Here is the screenshot of our current MOTD:

2. Requirements

To get this working you'll need:

  • Webserver with PHP (4 or 5) support
  • GD 2 extension for PHP installed and enabled

And a little programming knowledge will come handy for configuration.

3. Download & installation

You can download the script, config and sample MOTD here (ZIP, 228kB). Extract and copy it to your website.

Important: Make sure that directory cache/ is writable by the webserver. You can do this using your FTP client (search for Properties or Permissions) or you can use the following command:

chmod a+rw cache/

4. Configuration

Same as in live server stats for website, everything you need to edit is the config.php file. However, this time you'll find much more settings there so lets go step by step:

$image
Path to the base image. Live stats will be printed over it so prepare image with empty space for them like this:

$cachedir
Directory where cache files will be saved. Don't forget to set the permissions.

$cachelifetime
Time (in seconds) after which cache expires. After mapchange, when lots of players join at once, caching will greatly reduce server load. Setting to 0 will turn caching off.

$timeout and $retries
Script will wait $timeout seconds for response from the server. If time runs out this will be done $retries more times. If there is still no answer, server will be marked offline / down.
If you often get online servers incorrectly marked as offline, try rising these variables.

$nextmap
Server variable (cvar) that contains the name of next map. For SourceMod use the default value sm_nextmap

$timeleft
This variable is very hard to understand without programming and regular expressions knowledge. If you are using SourceMod you are lucky, because the default value will work for you, so you can skip this part.

If you are using some another server plugin you have 3 options: delete this variable and don't use timeleft in your MOTD, configure it yourself or post info about your plugin and it's timeleft command to comments and wait for answer.

If you are going to configure it yourself here is something you should know:
command is name of the command that returns time remaining for current map. outputs is array of regexp => output pairs. If some regexp matches the output of the command, output will be displayed. If no match is found, default is returned.

$xstart and $ystart
Starting coordinates of the live stats (this will be the top-left corner).

$xstep and $ystep
After each server x and y coordinates will be rised by this values. Unless you wan't your servers to be aligned diagonally one of these variables should be 0.

$templates_default, $templates_active and $templates_down
Templates for normal, active (the server you are currently playing on) and down (offline) servers. active and down templates are optional, if you don't set them the default template will be used.

Each one of these variables is array of templates. Every template looks like this:

                            array ('x' => 0,
                                   'y' => 0,
                                   'color' => '255 255 255',
                                   'font' => './tf2secondary.ttf',
                                   'size' => 12,
                                   'text' => '#name#')

You have to set six variables:

x and y
Relative coordinates from current server base coordinates.
color
Space separated RGB of the color that will be used for this template.
font
Path to the font file that will be used for this template.
size
Size of the font
text
Text to display. You can use following placeholders:
#name#, #ip# and #port#
Name, IP address and port of the server as defined in $servers variable. Always available.
#map#, #players# and #maxplayers
Current map, current / maximal number of players. Available for online servers (don't use these placeholders in $templates_down).
#nextmap#
Name of the next map. Available for online servers if $nextmap is set correctly.
#timeleft#
Time remaining for the current map. Available for online servers if $timeleft is set correctly.

$servers
Array of servers which should be displayed. Each server looks like this:

                  array ('name' => 'Server  1  NL  All maps',
                         'ip' => '85.17.60.96',
                         'port' => 27025,
                         'pass' => '')

You have to set four variables:

name
Name of the server. Used only for the #name# placeholder
ip and port
IP address and port of the server.
pass
RCON password. If you don't set it, nextmap and timeleft won't work.

5. Testing
Open motdpic.php in your browser and check the output. You can also try the active server template by going to motdpic.php?server=ip:port (for example, motdpic.php?server=85.17.60.96:27035). Tweak the settings until you are happy with the result.

Note: While testing, set $cachelifetime to 0 so you will always see tha last version without waiting for cache expiration.

For example, here is our image with live stats:

6. Putting it live

In the zip archive you'll also find file motd.php. It's slightly modified HTML&CSS from out chalkboard MOTD guide. It contains the image on the chalkboard background.

So all you have to do is open the motd.txt in your server's tf directory and put link to your motd.php there.

For example, this is how motd.txt on our server #2 looks loke:

http://content.specialattack.net/motd2/motd.php?server=85.17.60.96:27035

7. Conclusion
Ta-Daa! You have cool MOTD with live stats. Please do not copy this guide, but link to our site, when recommending this guide to others.

If you have any ideas for improvements, questions or problems use the comments.

Comments

try to enter absolute path to

try to enter absolute path to the font

that array (...) is just one

that array (...) is just one server, it must look like this:

$servers = array (array (... server 1 ...), array (... server 2 ...));

you must have the "$servers = array (" before the first one and ");" after the last one

in case u still have some problems post whole config.php to:
http://rafb.net/paste
and post link here, I'll fix it ASAP

looks like you have a typo in

looks like you have a typo in the servers list

please post few lines before and after line 111

are u using SourceMod? what

are u using SourceMod? what version? how does the response look?