) {
# If we see anything resembling a date, save it as the closest date
# we have to the user who joined.
if (/(\d\d\/\d\d\/\d\d (\d\d):\d\d:\d\d)/) {
$lastdate = $1;
$hour = sprintf("%g", $2);
$startdate = $lastdate unless $startdate;
}
if (/LoadMap: (.*)\.nrf/) {
$lastmap = $1;
}
if (/Join succeeded: (.*)$/) {
chop ($username = $1);
print "$lastdate - $username\n" unless $web;
$userlist{$username}++;
$hours{$hour}++;
$maxplayers = $hours{$hour} if ($hours{$hour} > $maxplayers);
$maplist{$lastmap}++;
$found = 1;
}
if (/GameLogger: (.*) knocked/) {
my $player = $1;
if ( (/ himself /) or (/ herself /) ) {
$kills{$player}-- if (exists $kills{$player})
} else {
$kills{$player}++;# if (exists $userlist{$player});
}
}
}
$enddate = $lastdate;
close NERFLOG;
if ($found) {
print '' if $web;
print '' if $web;
print_header("Totals: ($startdate - $enddate)",
'colspan=3 align="center" valign="top"');
print '' if $web;
print '
' if $web;
print '' if $web;
# User totals
my $subhead = "";
$subhead = " (>=$games played)" if ($games > 1);
print_table(\%userlist, "User Totals$subhead:", 'valign="top"', $games);
# Kill totals
print "\n";
print_table(\%kills, "Knock-out Totals:", 'valign="top"');
print "\n";
# Maps played
print_table(\%maplist, "Maps Played:", 'valign="top"');
print '
' if $web;
print '' if $web;
# Create a multiplier for the histogram to insure the number
# of asterisks is <= some maximum
my $maxstars = 40;
my $multiplier = 1;
$multiplier = ($maxstars / $maxplayers) if ($maxplayers > $maxstars);
print_header("Users by hour:", 'colspan=3 valign="top"');
print '' if $web;
foreach (0..23) {
printf "%02d: (%4d) ", $_, $hours{$_};
for (my $i = 1; $i <= ($hours{$_} * $multiplier); $i++)
{ print '*' };
print "${cr}";
}
print '' if $web;
print "
\n" if $web;
}
sub print_header
{
my $string = shift;
my $modifiers = shift || "";
$modifiers = ' ' . $modifiers if ($modifiers !~ /^ /);
print "" if $web;
print $cr unless $web;
print '' if $web;
print $string;
print '' if $web;
print $cr;
}
sub print_table
{
my ($table, $title, $modifiers, $minvalue) = @_;
$minvalue |= 1;
my $maxlength = 0;
my $total = 0;
foreach (keys %{$table}) {
$maxlength = length $_ if ($maxlength < length $_);
}
print_header($title, $modifiers);
print '' if $web;
foreach (sort {
($table->{$b} <=> $table->{$a})
||
((lc $a) cmp (lc $b))
} keys %{$table}) {
printf "%-${maxlength}s - %d${cr}", $_, $table->{$_}
if ($table->{$_} >= $minvalue);
$total += $table->{$_};
}
print "---${cr}";
printf "%-${maxlength}s - %d${cr}", 'Total:', $total;
print '' if $web;
print ' | ' if $web;
}
sub print_usage
{
print <] []
-h Print this help message
-w Output of statistics suitable for the Web (i.e. HTML)
-g Restrict output of games played to or more
Name of file to report on.
Default is $default_log_file
EOD
}