#!/usr/bin/perl -w

#   Copyright (C) 2001-2002 Fernando Gomes
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
#   USA

use strict;

#Author: Fernando A. P. Gomes
#Email: nocturno@nsk.yi.org

my (%World_Kill, %Suicida, %Killer, %Victim, %Weapon, $type_of_order, %Games);
my %Pontos = ();
my %Jogo = ();
my $quake_log = "/home/serv/gameserver/quake3/baseq3/games.log";
my $outputFile = "top";
my $type = "cgi";
my @link;
my %type_of_weapon;
my $ii = 0;
my ($kr, $kd, $kw);
my $version = "30/10/2000";
my $flag = 1;
#tempo total de jogo de um utilizador
my %Time = ();
#tempo que cada utilizador jogou num jogo
my %time_aux = ();
#nome associado ao numero de cada jogo
my %nome_numero = ();
my $minutos = 0;
my $segundos = 0;
my $segundos_do_jogo = 0;

#definicao das armas existentes
$type_of_weapon{MOD_ROCKET} = "Rocket Luncher";
$type_of_weapon{MOD_ROCKET_SPLASH} = "Rocket Luncher Splash";
$type_of_weapon{MOD_SHOTGUN} = "Shotgun";
$type_of_weapon{MOD_MACHINEGUN} = "Machine Gun";
$type_of_weapon{MOD_GRENADE} = "Grenade Luncher";
$type_of_weapon{MOD_GRENADE_SPLASH} = "Grenade Luncher Splash";
$type_of_weapon{MOD_PLASMA} = "Plasma Gun";
$type_of_weapon{MOD_PLASMA_SPLASH} = "Plasma Gun Splash";
$type_of_weapon{MOD_RAILGUN} = "Railgun";
$type_of_weapon{MOD_LIGHTNING} = "Lightning Gun";
$type_of_weapon{MOD_BFG} = "The BFG";
$type_of_weapon{MOD_BFG_SPLASH} = "The BFG Splash";
$type_of_weapon{MOD_GAUNTLET} = "Humiliation :))";

#link para a mesma pagina e diferentes tabelas
$link[0] = "Top order for points";
$link[1] = "Top order for kills";
$link[2] = "Top order for names";
$link[3] = "Top order for deaths";

##### Inicio do tratamento de parametros
if ($ARGV[0]) {
        if ($ARGV[0] eq "-l") {
                $quake_log = $ARGV[1];
        } elsif ($ARGV[0] eq "-o") {
                $outputFile = $ARGV[1];
        } elsif ($ARGV[0] eq "-t") {
                $type = $ARGV[1];
        } elsif ($ARGV[0] eq "--help") {
                help();
        } else {
                print "invalid option: $ARGV[0]\n";
                help();
        }
}
if ($ARGV[2]) {
        if ($ARGV[2] eq "-l") {
                $quake_log = $ARGV[3];
        } elsif ($ARGV[2] eq "-o") {
                $outputFile = $ARGV[3];
        } elsif ($ARGV[2] eq "-t") {
                $type = $ARGV[3];
	} elsif ($ARGV[2] eq "--help") {
                help();
	} else {
                print "invalid option: $ARGV[2]\n";
                help();
        }
}
if ($ARGV[4]) {
        if ($ARGV[4] eq "-l") {
                $quake_log = $ARGV[5];
        } elsif ($ARGV[4] eq "-o") {
                $outputFile = $ARGV[5];
        } elsif ($ARGV[4] eq "-t") {
                $type = $ARGV[5];
	} elsif ($ARGV[4] eq "--help") {
                help();
	} else {
                print "invalid option: $ARGV[4]\n";
                help();
        }
}
##### Fim do tratamento de parametros

#E' preferivel nem tentar entender :))
#print "QUAKE_LOG: $quake_log\n";

my $linha = 0;

open(Q3_LOG, "< $quake_log") or die "open $quake_log: $!";
while(<Q3_LOG>) {
	$linha++;
	if ($_ =~/^\s*\d+:\d+\s*Warmup:/) {
		my $ficheiro = 0;
		while ($flag && !($ficheiro =~/^\s*\d+:\d+\s*ShutdownGame:/) && !($ficheiro =~/^\s*\d+:\d+\s*InitiGame:/)) {
			$ficheiro = <Q3_LOG>;
	$linha++;

			if (!$ficheiro) {
				$flag = 0;
			}
			
			if ($flag) {
			if ($ficheiro =~/\s*\d+:\d+\s*ClientDisconnect:/) {
				$ficheiro =~/\s*(\d+:\d+)\s*ClientDisconnect:\s*(\d+)/;
				($minutos, $segundos) = split(/:/, $1);
				$segundos_do_jogo = ($minutos * 60 + $segundos) - $time_aux{$nome_numero{$2}};
				$Time{$nome_numero{$2}} = $Time{$nome_numero{$2}} + $segundos_do_jogo;
				delete($time_aux{$nome_numero{$2}});
			} elsif ($ficheiro =~/\s*\d+:\d+\s*ClientConnect:/) {
                		$ficheiro = <Q3_LOG>;
	$linha++;
				if ($ficheiro =~/^\s*\d+:\d+\s*ClientUserinfoChanged:/) {
					$ficheiro =~/\s*(\d+:\d+)\s*ClientUserinfoChanged: (\d+) n\\([\§\.\^\s\<\>\d\w\[\]]+)/; 
					my $dois = $2;
					$kr = $3;
					($minutos, $segundos) = split(/:/, $1);
					$kr =~ s/\^\d//g;

#					my $num = 0;
#			if ($nome_numero{$dois}) {
#			if ($time_aux{$nome_numero{$dois}}) {
#					foreach $num (keys %nome_numero) {
#						if ($num eq $dois) {
#							if (!($nome_numero{$num} eq $kr)) {
#									$segundos_do_jogo = ($minutos * 60 + $segundos) - $time_aux{$nome_numero{$num}};
#									$Time{$nome_numero{$num}} = $Time{$nome_numero{$num}} + $segundos_do_jogo;
#									print "(WARM) NUM: $num - $dois LINE: $linha USER ACTUAL: $kr USER: $nome_numero{$num}  SEGUNDOS: $segundos_do_jogo TEMPO: $Time{$nome_numero{$num}}\n";
#									delete($time_aux{$nome_numero{$num}});
#							}
#						}
#					}
#			}
#			}
					$nome_numero{$dois} = $kr;

					#se ja existir o nome no tempo de jogo nao inicia a zero
					if (!($time_aux{$nome_numero{$dois}})) {
						$time_aux{$nome_numero{$dois}} = ($minutos * 60 + $segundos);
						if (!($Time{$nome_numero{$dois}})) {
							$Time{$nome_numero{$dois}} = 0;
						}
					}
				}
			}
			}
		}
	} elsif ($_ =~/^\s*\d+:\d+\s*Kill/) {

		$_ =~/\s*\d+:\d+\s*Kill: \d+ \d+ \d+: ([\§\.\^\s\<\>\d\w\[\]]+) killed ([\§\.\^\s\<\>\d\w\[\]]+) by (.+)/; 
		$kr = $1;
		$kd = $2;
		$kw = $3;
		$kr =~ s/\^\d//g;
		$kd =~ s/\^\d//g;
		if ($kr eq $kd) {
			$Suicida{$kr}++;
			$Pontos{$kr}--;
			$Pontos{$kr} = $Pontos{$kr} - 2;
		} elsif ($kr eq "<world>") {
			$World_Kill{$kd}++;
			$Pontos{$kd}--;
		} else {
			$Killer{$kr}++;
			$Pontos{$kr}++;
			$Pontos{$kr}++;
			$Victim{$kd}++;
		}
		chomp($kw);
		if ($kw eq "MOD_GAUNTLET") {
			$Pontos{$kr} = $Pontos{$kr} + 3;
		}
		$Weapon{$kr}{$kw}++;
	} elsif ($_ =~/^\s*\d+:\d+\s*InitGame:/) {
		%Jogo = ();
	} elsif ($_ =~/\s*\d+:\d+\s*ClientConnect:/) {
		$_ = <Q3_LOG>;
	$linha++;
		if ($_ =~/^\s*\d+:\d+\s*ClientUserinfoChanged:/) {
			$_ =~/\s*(\d+:\d+)\s*ClientUserinfoChanged: (\d+) n\\([\§\.\^\s\<\>\d\w\[\]]+)/; 
			my $dois = $2;
			($minutos, $segundos) = split(/:/, $1);
			$kr = $3;
			$kr =~ s/\^\d//g;

#			my $num = 0;
#			if ($nome_numero{$dois}) {
#			if ($time_aux{$nome_numero{$dois}}) {
#			foreach $num (keys %nome_numero) {
#				if ($num eq $dois) {
#					if (!($nome_numero{$num} eq $kr)) {
#							$segundos_do_jogo = ($minutos * 60 + $segundos) - $time_aux{$nome_numero{$num}};
#							$Time{$nome_numero{$num}} = $Time{$nome_numero{$num}} + $segundos_do_jogo;
#							delete($time_aux{$nome_numero{$num}});
#							print "NUM: $num - $dois LINE: $linha USER ACTUAL: $kr USER: $nome_numero{$num}  SEGUNDOS: $segundos_do_jogo TEMPO: $Time{$nome_numero{$num}}\n";
#					}
#				}
#			}
#			}
#			}

			$nome_numero{$dois} = $kr;

			#se ja existir o nome no tempo de jogo nao inicia a zero
			if (!($time_aux{$nome_numero{$dois}})) {
				$time_aux{$nome_numero{$dois}} = ($minutos * 60 + $segundos);
				if (!($Time{$nome_numero{$dois}})) {
					$Time{$nome_numero{$dois}} = 0;
				}
			}

			if (!$Jogo{$kr}) {
				$Games{$kr}++;
				$Jogo{$kr} = 1;
				if (!$Pontos{$kr}) {
					$Pontos{$kr} = 0;
				}
				if (!$Killer{$kr}) {
					$Killer{$kr} = 0;
				}
			}
		}
	} elsif ($_ =~/\s*\d+:\d+\s*ClientDisconnect:/) {
		$_ =~/\s*(\d+:\d+)\s*ClientDisconnect:\s*(\d+)/;
		($minutos, $segundos) = split(/:/, $1);
		$segundos_do_jogo = ($minutos * 60 + $segundos) - $time_aux{$nome_numero{$2}};
		$Time{$nome_numero{$2}} = $Time{$nome_numero{$2}} + $segundos_do_jogo; 
		delete($time_aux{$nome_numero{$2}});
	}
}
close(Q3_LOG);

if ($type eq "html") {
	init_html();
	begin_table();
		$type_of_order = "name";
		write_results_html(%World_Kill, %Suicida, %Killer, %Victim, %Weapon, $type_of_order);
		$ii++;
	end_table();
	close_html();
} elsif ($type eq "text") {
	$type_of_order = "name";
	write_results_txt(%World_Kill, %Suicida, %Killer, %Victim, %Weapon, $type_of_order);
} elsif ($type eq "cgi") {
	print "Content-type: text/html\n\n";
	init_cgi();
	begin_table_cgi();
		$type_of_order = "points";
		write_results_cgi(%World_Kill, %Suicida, %Killer, %Victim, %Weapon, $type_of_order);
		$ii++;
	end_table_cgi();
	begin_table_cgi();
		$type_of_order = "kills";
		write_results_cgi(%World_Kill, %Suicida, %Killer, %Victim, %Weapon, $type_of_order);
		$ii++;
	end_table_cgi();
	begin_table_cgi();
		$type_of_order = "name";
		write_results_cgi(%World_Kill, %Suicida, %Killer, %Victim, %Weapon, $type_of_order);
		$ii++;
	end_table_cgi();
	close_cgi();
}

#####################
######## SUBS #######
#####################

#escreve os resultados em texto simples
sub write_results_txt(%World_Kill, %Suicida, %Killer, %Victim, %Weapon, $type_of_order) {

	foreach (keys %Killer) {
		if ($Victim{$_}) {
			print "$_ -> KILLER: $Killer{$_} VICTIM: $Victim{$_}\n";
		} else {
			print "$_ -> KILLER: $Killer{$_} VICTIM: I'M NOT A VICTIM\n";
		}
	}
}

#inicia o formato html
sub init_html {

#indica onde foi criado o log
my $generated_host = `uname -n`;
my $hora_analize = localtime;

open ANALIZE, ">$outputFile.html";

print ANALIZE <<__HTML__;
<HTML>
 <HEAD>
        <TITLE>QUAKE III Logs Analize</TITLE>
	<LINK REV=MADE HREF="mailto:nocturno\@nsk.yi.org">
	<META NAME="copyright" CONTENT="(c) 2000 Group NSK">
 </HEAD>
 <BODY BGCOLOR="#000000" TEXT="#E8E8E8" LINK="#0000FF" VLINK="#FF0000">
	<A NAME="TOP"></A>
	<P ALIGN="center"><img border="0" src="/images/quakearena.gif" lowsrc="/images/quakearenalow.jpg" alt="NSK Quake 3 Arena .. Statistics" width="640" height="130" ></P>
	<BR>
        <H2>Log generated in $generated_host</H2>
        <STRONG>Generated at $hora_analize</STRONG>
        <STRONG>If you had news ideas, or find any bugs, please tel me:</STRONG><A HREF=\"mailto:nocturno\@nsk.yi.org\">nocturno\@nsk.yi.org</A>
        <CENTER>
	<HR>
	<BR>
__HTML__
	for (my $t = 0; $t < $#link; $t++) {
		print ANALIZE "\t<A HREF=\"\#$link[$t]\">[$link[$t]]<A>\n";
	}
	print ANALIZE "\t<BR>\n";
	print ANALIZE "\t<BR>\n";
}
 
#termina o formato html
sub close_html() {

print ANALIZE <<__HTML__;

	</CENTER>
 </BODY>
</HTML>
__HTML__
close ANALIZE;
}

#inicia a formacao de uma tabela
sub begin_table {

print ANALIZE <<__HTML__;
	<A NAME="$link[$ii]"></A>
        <TABLE WIDTH=700 BORDER=2 CELLSPACING=1 CELLPADDING=1>
        <TR><TH HEIGHT=4></TH></TR>
__HTML__
}

#termina a formacao de uma tabela
sub end_table() {

print ANALIZE <<__HTML__;
        </TABLE>
        <P><SMALL>
		<A HREF="#TOP">[Back to Top]</A>
	</P></SMALL>
	<BR><BR><BR>
__HTML__
}
#escreve os ultimos resultados em html
sub write_results_html(%World_Kill, %Suicida, %Killer, %Victim, %Weapon, $type_of_order) {

#	my (%Order_killer, %Order_victim, %Order_Weapon);
	my $temp;

print ANALIZE <<__TABLE__;
                <TR><TH COLSPAN=6 ALIGN=center BGCOLOR=\"RED\">QUAKE III TOP TABLE</TH></TR>
                <TR>
		<TH WIDTH=380 ALIGN=center><FONT SIZE=\"3\"><B>User</B></FONT></TH>
		<TH WIDTH=380 ALIGN=center><FONT SIZE=\"3\"><B>Kills</B></FONT></TH>
		<TH WIDTH=380 ALIGN=center><FONT SIZE=\"3\"><B>Deaths</B></FONT></TH>
		<TH WIDTH=380 ALIGN=center><FONT SIZE=\"3\"><B>Killed himself</B></FONT></TH>
		<TH WIDTH=380 ALIGN=center><FONT SIZE=\"3\"><B>Killed himself(by World)</B></FONT></TH>
		<TH WIDTH=380 ALIGN=center><FONT SIZE=\"3\"><B>Most used Weapon</B></FONT></TH>
      		</TR>
		<TR><TH HEIGHT=4></TH></TR>
__TABLE__

	if ($type_of_order eq "name") {
	foreach (sort keys %Killer) {
		$temp = $_;
		print ANALIZE "\t\t<TR>\n";
               	print ANALIZE "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">$temp</FONT></TD>\n";
                print ANALIZE "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">$Killer{$temp}</FONT></TD>\n";
		if ($Victim{$temp}) {
                	print ANALIZE "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">$Victim{$temp}</FONT></TD>\n";
		} else {
                	print ANALIZE "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">Never was killed</FONT></TD>\n";
		}
		if ($Suicida{$temp}) {
                	print ANALIZE "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">$Suicida{$temp}</FONT></TD>\n";
		} else {
                	print ANALIZE "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">Never killed himself</FONT></TD>\n";
		}
		if ($World_Kill{$temp}) {
                	print ANALIZE "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">$World_Kill{$temp}</FONT></TD>\n";
		} else {
                	print ANALIZE "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">Never fall over the world</FONT></TD>\n";
		}
                print ANALIZE "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">$Weapon{$temp}</FONT></TD>\n";
        	print ANALIZE "\t\t</TR>\n";
		print ANALIZE "\t\t<TR>\n";
	}
	}
}

########################
#### ESCREVE EM CGI
########################

#inicia o formato html
sub init_cgi {

#indica onde foi criado o log
my $generated_host = `uname -n`;
my $hora_analize = localtime;
my $t;

print <<__HTML__;
<HTML>
 <HEAD>
        <TITLE>QUAKE III Logs Analize</TITLE>
	<LINK REV=MADE HREF="mailto:nocturno\@nsk.yi.org">
	<META NAME="copyright" CONTENT="(c) 2000 Group NSK">
 </HEAD>
 <BODY BGCOLOR="#000000" TEXT="#E8E8E8" LINK="#0000FF" VLINK="#FF0000">
	<A NAME="TOP"></A>
	<P ALIGN="center"><img border="0" src="/images/quakearena.gif" lowsrc="/images/quakearenalow.jpg" alt="NSK Quake 3 Arena .. Statistics" width="640" height="130" ></P>
	<BR>
	<BR>
        <H2>Log generated in $generated_host for server nsk.yi.org port 27960</H2>
        <STRONG>Generated at $hora_analize</STRONG><BR>
        <STRONG>If you had news ideas, or find any bugs, please tell us:</STRONG><A HREF=\"mailto:quake3\@nsk.yi.org\"> quake3\@nsk.yi.org</A>
        <CENTER>
	<HR>
	<BR>
__HTML__
	for (my $t = 0; $t < $#link; $t++) {
		print "\t<A HREF=\"\#$link[$t]\">[$link[$t]]<A>\n";
	}
	print "\t<BR>\n";
	print "\t<BR>\n";
}
 
#termina o formato html
sub close_cgi() {

print <<__HTML__;

	</CENTER>
	<FONT COLOR="#990000" SIZE="1">Version: $version</FONT>
 </BODY>
</HTML>
__HTML__
}

#inicia a formacao de uma tabela
sub begin_table_cgi {

print <<__HTML__;
	<A NAME="$link[$ii]"></A>
        <TABLE WIDTH=700 BORDER=2 CELLSPACING=1 CELLPADDING=1>
        <TR><TH HEIGHT=4></TH></TR>
__HTML__
}

#termina a formacao de uma tabela
sub end_table_cgi {

print <<__HTML__;
        </TABLE>
        <P><SMALL>
		<A HREF="#TOP">[Back to Top]</A>
	</P></SMALL>
	<BR><BR><BR>
__HTML__
}
#escreve os ultimos resultados em html
sub write_results_cgi(%Suicida, %Killer, %Victim, %Weapon, $type_of_order) {
	my @temp = ();
	my $temp = 0;
	my $lugar = 0;
	
print <<__TABLE__;
                <TR><TH COLSPAN=9 ALIGN=center BGCOLOR=\"RED\">QUAKE III TOP TABLE - $type_of_order</TH></TR>
                <TR>
		<TH WIDTH=380 ALIGN=center><FONT SIZE=\"3\"><B>User</B></FONT></TH>
		<TH WIDTH=380 ALIGN=center><FONT SIZE=\"3\"><B>Points</B></FONT></TH>
		<TH WIDTH=380 ALIGN=center><FONT SIZE=\"3\"><B>Kills</B></FONT></TH>
		<TH WIDTH=380 ALIGN=center><FONT SIZE=\"3\"><B>Deaths</B></FONT></TH>
		<TH WIDTH=380 ALIGN=center><FONT SIZE=\"3\"><B>Killed himself</B></FONT></TH>
		<TH WIDTH=380 ALIGN=center><FONT SIZE=\"3\"><B>Killed himself (by World)</B></FONT></TH>
		<TH WIDTH=380 ALIGN=center><FONT SIZE=\"3\"><B>Games Played</B></FONT></TH>
		<TH WIDTH=380 ALIGN=center><FONT SIZE=\"3\"><B>UNDER CONSTRUCTION Time Played</B></FONT></TH>
		<TH WIDTH=380 ALIGN=center><FONT SIZE=\"3\"><B>Most used Weapon</B></FONT></TH>
      		</TR>
		<TR><TH HEIGHT=4></TH></TR>
__TABLE__

	if ($type_of_order eq "name") {
		foreach $temp (sort keys %Games) {
			$lugar = "";
			write_aux($temp, $lugar);
		}
	} elsif ($type_of_order eq "points") {
		$lugar = 0;
		@temp = sort {$Pontos{$b} <=> $Pontos{$a}} keys %Pontos;
		for (my $h = 0; $h <= $#temp; $h++) {
			$temp = $temp[$h];
			$lugar++;
			$lugar = "$lugarē - ";
			write_aux($temp, $lugar);
		}
	} elsif ($type_of_order eq "kills") {
		$lugar = 0;
		@temp = sort {$Killer{$b} <=> $Killer{$a}} keys %Killer;
		for (my $h = 0; $h <= $#temp; $h++) {
			$temp = $temp[$h];
			$lugar++;
			$lugar = "$lugarē - ";
			write_aux($temp, $lugar);
		}
	}
}

sub write_aux {
	my $most_used_weapon = 0;
	my $w;
	my $weap = 0;
	my ($temp, $lugar) = @_;

	print "\t\t<TR>\n";
      	print "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\"><A HREF=\"playerQ3stats.pl\?$temp\">$lugar $temp<A></FONT></TD>\n";
	if ($Pontos{$temp}) {
       		print "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">$Pontos{$temp}</FONT></TD>\n";
	} else {
       		print "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">0</FONT></TD>\n";
	}
	if ($Killer{$temp}) {
        	print "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">$Killer{$temp}</FONT></TD>\n";
	} else {
        	print "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">Never killed anyone</FONT></TD>\n";
	}
	if ($Victim{$temp}) {
               	print "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">$Victim{$temp}</FONT></TD>\n";
	} else {
               	print "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">Never was killed</FONT></TD>\n";
	}
	if ($Suicida{$temp}) {
               	print "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">$Suicida{$temp}</FONT></TD>\n";
	} else {
               	print "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">Never killed himself</FONT></TD>\n";
	}
	if ($World_Kill{$temp}) {
               	print "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">$World_Kill{$temp}</FONT></TD>\n";
	} else {
               	print "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">Never fall over the world</FONT></TD>\n";
	}
	print "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">$Games{$temp}</FONT></TD>\n";
	print "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\">";
	$w = $Time{$temp};
	if (int($w / 86400) > 0) {
		print int($w / 86400), "d ";
		$w %= 86400;
	}
	if (int($w / 3600) > 0) {
		print int($w / 3600), "h ";
		$w %= 3600;
	}
	if (int($w / 60) > 0) {
		print int($w / 60), "m ";
		$w %= 60;
	}
	print $w, "s</FONT></TD>\n";
	$most_used_weapon = 0;
	foreach $w (keys %{$Weapon{$temp}}) {
		if ($Weapon{$temp}{$w} > $most_used_weapon) {
			$most_used_weapon = $Weapon{$temp}{$w};
			$weap = $w;
		}
	} 
	if ($type_of_weapon{$weap}) {
        	print "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\"><IMG border=\"0\" SRC=\"/images/weapons/$weap.jpg\" ALT=\"$type_of_weapon{$weap}\"></FONT></TD>\n";
	} else {
        	print "\t\t<TD WIDTH=380 ALIGN=center><FONT SIZE=\"-1\"><IMG border=\"0\" SRC=\"/images/weapons/MOD_UNKNOWN.jpg\" ALT=\"What is a weapon\?\"></FONT></TD>\n";
	}
       	print "\t\t</TR>\n";
	print "\t\t<TR>\n";
}

# mostra o help
sub help {
        print "usage: $0 [-l quake_log] [-o outputFile] [-t type]\n";
        print "types: html text cgi\n";
        exit(0);
}
