Kombat Teams Log Parser

A PHP script that parses client's console logs from matches in KTX mods and extracts player stats from them into PHP array structures (XML or JSON supported too). It's suitable for leagues to offer rich detailed match statistics on their webpages, much more than just frag amounts.

Benefits:

Examples

Visit this page to see .log files and the results of their parsing

Live demo

Upload your console log here and the script will produce a HTML page with stats preview.

Requirements

Clients need to set following settings:



	match_auto_logconsole 2
	

That will make client automatically log console text during the match, which is exactly what this script parses. If user forgot to enable console logging, he can create the log later from the demo! Launch the demo playback and then write following into the console:



	log mylog; demo_jump 30:00; log stop
	

You don't have to start logging from the exact start of the demo, so no need to rush :).
FuhQuake users reported issues with the demo_jump command. If you have such problems too, use demo_setspeed 10000000 instead of demo_jump and do the log stop after the demo is over

A .log file like this or this will get saved in users quake/log dir, from where it can be uploaded to your website. Then is the time for this script to take some action - you use it to read the contents of the log. It's up to you which stats you'll print in what form, this script just gives you the raw data.

Server side usage

How to actually use this script.

First of all, let your visitors upload the log files to some directory on your web server.
This is up to you to handle, the script will not help you with that.

Then you need to create a page page where you will call this script to display contents of the logs in nice structured HTML.

  1. Put a line to include the script in your page:
    
    	
    	require_once "ktlogpsr.php";
    	
  2. Create a parser object and call the parse function:
    
    
    	$logParser = new KTLogParser;
    	$logData = $logParser->Parse("a.log", "fragfile.dat");
    	

    Replace "a.log" with the log that you want to parse. fragfile.dat is a file describing the format of frag messages in QuakeWorld. You can find this file in our source code repository too.

  3. To display the data in HTML format create the KTLP_Visualizer object and call its main GetHtml() function:
    
    
    	$logVisualiser = new KTLP_Visualizer;
    	echo $logVisualiser->GetHtml($logData);
    	
  4. Optionally, you may want to display only brief stats on some of your web pages, to do so you can instead call:
    
    	
    	echo $logVisualiser->GetMiniHtml($logData);
    	
  5. Optionally, you may want to rename some of the acquired statistics to something with better readability. To do so, call this function:
    
    
    	$logVisualiser->setRenameStats(true);
    	
  6. Optionally, you may want to produce your own HTML from the data. The script offers you the data in any of PHP array, XML and JSON formats:
    
    
    	$logParser->GetArray(); // this is the same as the result of $logParser->Parse(..) call
    	$logParser->GetXML();
    	$logParser->GetJSON();
    	

Server side efficiency

Parsing of the log file is an expensive process. You may want to cache the results of parsing to increase the load time of the pages with stats and to decrease your web server CPU usage.

It is recommended to cache the result of $logParser->Parse(..) call using e.g. PHP inbuilt function serialize(). You can take benefit of other existing PHP functions too, so you get something like:



	$logData = unserialize(file_get_contents("logs/cached_{$log_id}.dat"));
	

This is all up to you to handle on your site. When testing effects of caching, load time of a single page with stats got reduced from ~500 ms down to ~90 ms.

Download

KT Log Parser Project - repository

gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.