Piglet's UT2004 Server Monitor

Contact Information:
====================

Find me (Piglet) on the forums at http://ut2004.titaninternet.co.uk/vbb
or irc://irc.quakenet.org/titanonslaught


Script Information:
===================

The script retrieves information about the server from four sources:

1. The Gamespy Port on the server (for the majority of the information)
2. The UT2004 proprietory format port on the server (for mutator information)
3. The server Webadmin console panel (for chat)
4. Epic Stats Site (for recently played maps stats information)

The script buffers the retrieved information to that the server load is reduced. However many client 
requests you get the script only queries the server a maximum of the interval you set. Each of the four 
different queries is controlled separately so that you can can decide how often you want the query to happen.

The script uses the current game type and map name to pick up an image from a the correct directory name. 
It will pick a random image from the directory relating to the game type and map. Where a map directory does not 
exist the script will pick a random map from the root of the gametype directory.

Script useage:
==============

By Default the script produces a complete web page. Example: http://ut2004.titaninternet.co.uk/cgi-bin/titan.pl?server=0

If the query string "&forceRefresh=true" is added to the URL it will override the buffering in the script.
If I were you I'd so a global search and replace of this to something else so that you can refresh when you want
but nobody else can!

If the query string "&forceSpectators=true" is added to the URL the chat will include spectator to spectator
chat. By default this is excluded. You may wish to change this to something else.

You can also use the script to embed information into a web page by getting it to output javascript.

Here is a little proof of concept - never taken further than this:

<html><head><title> Test </title><body>
You can embed it </ br>
<script type="text/javascript" src="http://ut2004.titaninternet.co.uk/cgi-bin/titan.pl?server=0&type=js" />
In a page </ br></body></html>


Thanks to:
==========

Dogsbody for publishing some initial code which got me going and served as the basis for the script
Fiz at Cains Lair for his .net server monitor from which I got a few ideas, and basis for the nice page layout.


Prerequisites
==============

A PERL cgi-enabled web server with access through the local firewall to the IP addresses and ports 
you're trying to reach.

Setup
=====

Edit your server details into the script. Most of the things you can change are already commented:

Set up Server Query Intervals and Buffered info locations
----------------------------------------------------------

1. Create a directory within your script path (preferably) to hold buffered data. In the example the 
directory is at path ".\saved_data" in relation to the perl script.

2. Edit the file names and query intervals for each of the queries in the script if you want to.
The "#" is used by the script to maintain a distinct set of files for each server. You may not want
to change these:


#saved server gamespy results
$serverfile = 'saved_data\\serverfile#.txt';
#Minimum time (seconds) before the server will be queried again by gamespy protocol
# regardless of number of clients asking for it
$serverqueryinterval = 25;

#saved mutators info from ut2004 query
$mutsfile = 'saved_data\\mutsfile#.txt';
#Minimum time (seconds) before the server will be queried again by ut2004 protocol 
# regardless of number of clients asking for it
$mutqueryinterval = 240;

#saved chat from webadmin
$chatfile = 'saved_data\\chatfile#.txt';
#Minimum time (seconds) before the webadmin chat will be queried again
# regardless of number of clients asking for it
$chatqueryinterval = 35;

#saved epic stats from their site
$epicfile = 'saved_data\\statsfile#.txt';
#Minimum time (seconds) before the Epic stats site will be queried again
# regardless of number of clients asking for it
$epicqueryinterval = 240;


Internal server path to map images: 
------------------------------------

1. Edit the script. Example
$path='..\\htdocs\\servermonitor\\maps';

Edit the web external relative URL path to map images - web path relative to the perl script:
$urlpath='/servermonitor/maps';

2. Create a directory for the server monitor images to match the path you set up:

\htdocs\servermonitor\maps

3. Create Gametype Specific Directories for each gametype being run

If you do not know what they should be called, come back to this after you have the script running.
When you run it the directory name it will expect is shown against the title "Game Type"

Example Game Type Directory Names:

For TDM: xTeamGame
For TAM: TDM_Game_3SPN
For ONS: onsonslaughtgame
For Jailbreak: Jailbreak

4. Create at least one, preferably more 'default' images at size 495*248, into each of the gametype dirs
(yeh - I know it's a strange size - blame Fiz) and put them in the game directory.
The script will find them and pick one at random where no map specific directory is found.

5. If you want to have images per map (best), create a directory per map per gametype named exactly as the
map name (less the .ut2 - eg. "ONS-Primeval") and put map specific images in it. The script will find them and pick one at random to send the client.

Script Setup Continued:
========================

Edit the following settings as required for your setup:

The url to link to when a server is passworded (we use the same thread for all servers)
$passurl = 'http://ut2004.titaninternet.co.uk/vbb/showthread.php?t=2261';

Array of server names you want to to monitor:
@servername = ("Titan 32 Player Onslaught", "Titan Chillout Server");

External IP addresses (for display purposes on the page)
@server = ("217.77.176.198","217.77.176.199");

The Ip address the script will actually use to query the server If the HTTP server is on a lan with the game server you should use the internal address (often 192.169.n.n) , not the external address
@intserver = ("217.77.176.198","217.77.176.199");

Array of Webadmin userids and passwords, webadmin port - one for each web server you're monitoring
@webadmin=("removedloginname","removedloginname");
@webadminpass=("removedpassword","removedpassword");
@intserverwebport=("1234","1234");

Array of Epic stats server IDs for the servers
@serverstats = (8582195,11999163);

The Port the game is running on at the IP addresses detailed above
@gameport = (7777,7777);

How often to refresh the page:
$refreshtime = "30";

The Gameport increment to the game port on the server. This will always be 10. Do not change it!
$queryport = 10;

Timeout time to wait on the gamespy port before giving up. Probably leave this unchanged:
$timeout = 5;

Page Title:
$title = "Titan UT2004 Server Query";


Good luck. I hope that this is useful to you. Come to the Titan forum to chat about anything UT related (or not).

Stephen (Piglet) C-E