Guest User

Untitled

a guest
Nov 13th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # Copyleft 2013 systemv
  3. # GPL'd, etc..
  4. # Use/reuse/hack/edit to suit.
  5.  
  6. # Edited by Francis Baster to calculate total accrued online time
  7. # Designed for an MCPC+ 1.5.2 server
  8.  
  9. #usage:
  10. # Parse server.log and produce a sorted list, players with most accrued online time at the top.
  11. # perl onlineTime < server.log | sort -r -n -k2 > results.txt
  12.  
  13. use Time::Local;
  14.  
  15. my $playerName;
  16. my $onlineTimeHours;
  17.  
  18. format STDOUT=
  19. @<<<<<<<<<<<<<<<< @#######
  20. $playerName, $onlineTimeHours
  21. .
  22.  
  23. sub makeTimeInSeconds {
  24. my ($d, $t) = @_;
  25. my $time = 0;
  26. if ($d =~ /(\d\d\d\d)\-(\d\d)\-(\d\d)/) {
  27. my ($year, $month, $day) = ($1, $2, $3);
  28. $month -= 1;
  29. if ($t =~ /(\d\d):(\d\d):(\d\d)/) {
  30. my ($hour, $min, $sec) = ($1, $2, $3);
  31. $time = timelocal($sec, $min, $hour, $day, $month, $year - 1900);
  32. }
  33. }
  34. return $time;
  35. }
  36.  
  37. my %runningTotal;
  38. my %logonTime;
  39.  
  40. while ($x = <STDIN>) {
  41. chomp $x;
  42.  
  43. if ($x =~ /\[INFO\] ([^\s]+)\[.+\] logged in with entity id/) {
  44. my $playerName = $1;
  45. if ($x =~ /^(\d\d\d\d\-\d\d\-\d\d) (\d\d:\d\d:\d\d) \[INFO\]/) {
  46. my $date = $1;
  47. my $time = $2;
  48. $logonTime{$playerName} = &makeTimeInSeconds($date, $time);
  49. next;
  50. }
  51. }
  52.  
  53. if (($x =~ /\[INFO\] ([^\s]+) lost connection/) || ($x =~ /\[INFO\] Unloading Player: ([^\s]+)/)) {
  54. my $playerName = $1;
  55. if ((exists $logonTime{$playerName}) && ($x =~ /^(\d\d\d\d\-\d\d\-\d\d) (\d\d:\d\d:\d\d) \[INFO\]/)) {
  56. my $date = $1;
  57. my $time = $2;
  58. my $logoffTime = &makeTimeInSeconds($date, $time);
  59. if (!exists $runningTotal{$playerName}) {
  60. $runningTotal{$playerName} = 0;
  61. }
  62. $runningTotal{$playerName} = $runningTotal{$playerName} + $logoffTime - $logonTime{$playerName};
  63. delete $logonTime{$playerName};
  64. next;
  65. }
  66. }
  67.  
  68. if ($x =~ /\[INFO\] Starting minecraft server/) {
  69. %logonTime = ();
  70. next;
  71. }
  72. }
  73.  
  74. foreach $playerName (keys %runningTotal) {
  75. $onlineTimeHours = $runningTotal{$playerName} / (60 * 60);
  76. write;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment