#!/usr/bin/perl

$datetime = `date -u '+%Y%m%d/%H%M'`;
chomp $datetime;

$/ = '';
$sep = '\\\\';

while ($server = <>) {
	chomp $server;
	@data = split /\n/, $server;
	($type, $ip, $name, $map, $maxplayers, $players, $ping, $tries)
							= split /$sep/, $data[0];
	next if $type ne 'T2S';
	next if $name eq 'TIMEOUT' or $name eq 'DOWN';
	next if $map eq '?';
	%detail = ('bot_count' => 0, 'game' => '?', 'mission' => '?');
	foreach $detail (split /$sep/, $data[1]) {
		($key, $value) = split /=/, $detail, 2;
		$detail{$key} = $value;
	}
	$players -= $detail{'bot_count'};

	print "$datetime\t$detail{'game'}\t$detail{'mission'}\t$map\t$maxplayers\t$players\n";
}

