Multi-Gaming Community

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

Server Connection Issues

Hey there,

I can get all the font/layout stuff for the most part (colours don't seem to want to work), but no matter what I put in for server ip/port/password, I cannot get the a response from the server. It always says server timed out. Here's my page:

http://www.agedinoakcasks.com/motd/motdpic.php

Any ideas? I've tried the ips/ports/rcon passes of 4 or 5 different servers.

Setup Difficulty

I had this working flawlessly, but then our host had a hardware failure and we lost everything. When we got a new site, it was running PHP 4.3.11 and I found it would display the background and motd_base.png, but none of the live stats. I asked to have us upgraded to PHP5, which they did (PHP 5.1.6), but now only the background loads. Here is what it looks like with the contents of your zip file uploaded without any changes made: http://allkindsofawesome.darkstargamers.com/tf2/motds/test/motd.php Can I get a little help? :)

#timeleft# not working.

I'm not getting a time left with SourceMod 1.0.4. Is the issue with SourceMod or my config?

me again^^

i am the one who double postet about the timelfeft issue. that isnt solved but in addition we have a new problem. some people get the thing rendered like this: http://img520.imageshack.us/my.php?image=imrewg1.jpg while it should be like this: http://six.gerade.org/skarufue/download/motd.php

cannot get timeleft to work

i got the whole thing working. the only problem is that timeleft doesnt work... i get alot of those in my server logs though (one every time someone views the thing): Unknown command "timeleft" rcon from "78.46.xxx.xxx:60332": command "timeleft" the timeleft function works flawlessy when initiated by a player ingame also "say timeleft" in the server console produces neither error nor visible output i use this version of SM: SourceMod Version Information: SourceMod Version: 1.0.3 JIT Version: JIT (x86), 1.0.3 JIT Settings: Generic i686 Compiled on: Jun 24 2008 22:44:47 http://www.sourcemod.net/

Struggling to get it to

Struggling to get it to work,but the way i see it with out any changes to the downloaded files ie config it should work as soon as you put it on a webserver as your ip and ports are already in there(specialattacks that is) I understand next map and time left will not because recon password is not filled in but the ip and game name should without touching a single thing just uploading the files.I cant seem to get it to work i have gd installed running with php5.the image on the chalkboard shows just fine but nothing shows in the box below. i have set permissions in the right place any help with this please or point in the right place to get a hand with it? There are no files in the catch folder is this right? ps i have also tried with my servers ip and ports and rcon passwords but still nothing. i have tried the (live server stats on your website script) and it works fine so i know the site can accept them and servers are ok. only thing i can say is i run tf2 servers and only have Beatles Mod installed.

Do you guys have a blank of

Do you guys have a blank of that blueprint png file?

Errors on LInes 124 and 137/138

I'm having errors with the true type font when I try to implement this, and don't see a missing package (I do have GD 2.0 at the moment). Could not find/open font

try to enter absolute path to

try to enter absolute path to the font

thanks but ... n°2

this is what i've got before and after : array ('[FR] -=HEROES=- Serveur DoD source tick 100' => 'Serveur DoD Source', 'ip' => '87.98.194.200', 'port' => 27015, 'pass' => '*******'), ?> that's all , got nothing more after the line 111 with the "?>"

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

thanks but ...

Thanks for sharing the "How-to" but don't work with me...got error = Parse error: parse error, unexpected ';', expecting ')' in /data/filer-2/********/*******/home/web/********/config.php on line 111

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

Many thanks!

I'm looking forward to messing around with this later. Thanks for showing those of us with little HTML experience how to help our servers stand out.

Me again.

So I finally got around to playing with it and got almost everything working perfectly. The only snag I had is getting the time left function to work. I haven't messed with it at all, so I'm stumped as to why it's not working. There's just nothing showing up in that spot for the active server.

i cant get timeleft to work

i got the whole thing working. the only problem is that timeleft doesnt work... i get alot of those in my server logs though (one every time someone views the thing): Unknown command "timeleft" rcon from "78.46.xxx.xxx:60332": command "timeleft" the timeleft function works flawlessy when initiated by a player ingame also "say timeleft" in the server console produces neither error nor visible output i use this version of SM: SourceMod Version Information: SourceMod Version: 1.0.3 JIT Version: JIT (x86), 1.0.3 JIT Settings: Generic i686 Compiled on: Jun 24 2008 22:44:47 http://www.sourcemod.net/

are u using SourceMod? what

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

Yeah, we're using SM.

Yeah, we're using SM. I just found we're using a very old version, so I'll get that upgraded and try again.