#!/usr/bin/perl ## ## qwlog - parses output from quakeworld client ## ## usage: ## $ qwcl | qwlog [-q] [-c] [-s] [name] ## $ cat qw_logfile | qwlog [-q] [-c] [-s] [name] ## ## name ## ## switches: ## -q : quiet - don't output speech ## -c : chat - only output speech ## -s : score - only output scores # check for switches { if (@ARGV[0] =~ /^-/) { $sw = @ARGV[0]; shift; if ($sw =~ /q/) { if ($chat) { die "qwlog: can't use both 'c' and 'q' flags\n"; } $quiet = 1; } elsif ($sw =~ /c/) { if ($quiet) { die "qwlog: can't use both 'c' and 'q' flags\n"; } $chat = 1; } elsif ($sw =~ /s/) { if ($chat) { die "qwlog: can't use both 'c' and 's' flags\n"; } $score = 1; } redo; } } # get search regexp $name = @ARGV[0]; # set scores to zero so they don't print blank strings $frags = 0; $fragged = 0; $suicide = 0; $bestrun = 0; # parse output while () { # non frag messages if (/:\s/) { # catch speech but not prog output print unless (($quiet) || ($score) || (/^(PackFile|FindFile| Downloading|Checking|Exe|Sound|CDAudio)/)); } elsif (!$chat) { # catch $name's frags if ((/$name/) && (!/(dropped|entered|got.the.rune)/)) { print unless ($score); if (/^$name/) { # $name threw a seven :-( if ((/bored.with.life/) || (/pin.back.in/) || (/was.squished/) || (/visits.the.Volcano/) || (/was.spiked/) || (/burst.into.flames/) || (/discharges.into.the/) || (/into.hot.slag/)) { $suicide++; $fragged++; if ($run > $bestrun) { $bestrun = $run; } $run = 0; } # $name fragged someone :-) elsif (/(squishes|rips.*a.new.one)/) { $frags++; $run++; } # $name was fragged elsif ((!/entered/) && (!/dropped$/) && (!/left.the.game/)) { $fragged++; if ($run > $bestrun) { $bestrun = $run; } $run = 0; } } # $name was fragged elsif (/(squishes|rips.*$name.*a.new.one)/) { $fragged++; if ($run > $bestrun) { $bestrun = $run; } $run = 0; } # $name fragged someone :-) else { $frags++; $run++; } } } } if ($run > $bestrun) { $bestrun = $run; } if ($fragged) { $fragrate = int((100 * $frags) / $fragged); } print "\n" unless ($score); # print the scores if (!$chat) { print "$name scored $frags frags\n"; print "$name was fragged $fragged times\n"; print "... of which $suicide were suicides\n"; print "best run was $bestrun frags\n"; print "fragrate was $fragrate percent\n" if ($fragrate); } print "\n";