Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # Copyleft 2013 systemv
- # GPL'd, etc..
- # Use/reuse/hack/edit to suit.
- # Edited by Francis Baster to calculate total accrued online time
- # Designed for an MCPC+ 1.5.2 server
- #usage:
- # Parse server.log and produce a sorted list, players with most accrued online time at the top.
- # perl onlineTime < server.log | sort -r -n -k2 > results.txt
- use Time::Local;
- my $playerName;
- my $onlineTimeHours;
- format STDOUT=
- @<<<<<<<<<<<<<<<< @#######
- $playerName, $onlineTimeHours
- .
- sub makeTimeInSeconds {
- my ($d, $t) = @_;
- my $time = 0;
- if ($d =~ /(\d\d\d\d)\-(\d\d)\-(\d\d)/) {
- my ($year, $month, $day) = ($1, $2, $3);
- $month -= 1;
- if ($t =~ /(\d\d):(\d\d):(\d\d)/) {
- my ($hour, $min, $sec) = ($1, $2, $3);
- $time = timelocal($sec, $min, $hour, $day, $month, $year - 1900);
- }
- }
- return $time;
- }
- my %runningTotal;
- my %logonTime;
- while ($x = <STDIN>) {
- chomp $x;
- if ($x =~ /\[INFO\] ([^\s]+)\[.+\] logged in with entity id/) {
- my $playerName = $1;
- if ($x =~ /^(\d\d\d\d\-\d\d\-\d\d) (\d\d:\d\d:\d\d) \[INFO\]/) {
- my $date = $1;
- my $time = $2;
- $logonTime{$playerName} = &makeTimeInSeconds($date, $time);
- next;
- }
- }
- if (($x =~ /\[INFO\] ([^\s]+) lost connection/) || ($x =~ /\[INFO\] Unloading Player: ([^\s]+)/)) {
- my $playerName = $1;
- if ((exists $logonTime{$playerName}) && ($x =~ /^(\d\d\d\d\-\d\d\-\d\d) (\d\d:\d\d:\d\d) \[INFO\]/)) {
- my $date = $1;
- my $time = $2;
- my $logoffTime = &makeTimeInSeconds($date, $time);
- if (!exists $runningTotal{$playerName}) {
- $runningTotal{$playerName} = 0;
- }
- $runningTotal{$playerName} = $runningTotal{$playerName} + $logoffTime - $logonTime{$playerName};
- delete $logonTime{$playerName};
- next;
- }
- }
- if ($x =~ /\[INFO\] Starting minecraft server/) {
- %logonTime = ();
- next;
- }
- }
- foreach $playerName (keys %runningTotal) {
- $onlineTimeHours = $runningTotal{$playerName} / (60 * 60);
- write;
- }
Advertisement
Add Comment
Please, Sign In to add comment