Blob Blame Raw
##########################################################################
##########################################################################

use strict;

my ($junk, $Msg, $total);
my %Action = ();
my %Start = ();
my %Login = ();
my %TakeChar = ();
my %DropChar = ();
my %Logout = ();

my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;

# Interesting events:
#2007-02-17 12:45:22 START - - - Standalone server startup
#2007-02-17 12:56:58 LOGIN 2158 2159 - Create account wart
#2007-02-17 12:57:03 TAKE_CHAR 2158 2159 2160 Created character wart(settler) by account wart
#2007-02-17 12:57:43 DROP_CHAR 2158 - 2160 Logout character wart(settler)
#2007-02-17 12:57:43 LOGOUT 2158 2159 - Logout account wart


while (defined(my $ThisLine = <STDIN>)) {
   chomp($ThisLine);
   if ( ($Msg) = ($ThisLine =~ /START - - - (.*)$/)) {
      $Start{$Msg}++;
   }
   if ( ($Msg) = ($ThisLine =~ /LOGIN [-0-9]+ [-0-9]+ [-0-9]+ (.*)$/)) {
      $Login{$Msg}++;
   }
   if ( ($Msg) = ($ThisLine =~ /TAKE_CHAR [-0-9]+ [-0-9]+ [-0-9]+ (.*)$/)) {
      $TakeChar{$Msg}++;
   }
   if ( ($Msg) = ($ThisLine =~ /DROP_CHAR [-0-9]+ [-0-9]+ [-0-9]+ (.*)$/)) {
      $DropChar{$Msg}++;
   }
   if ( ($Msg) = ($ThisLine =~ /LOGOUT [-0-9]+ [-0-9]+ [-0-9]+ (.*)$/)) {
      $Logout{$Msg}++;
   }
}

if (keys %Start) {
   if ($Detail >= 5) {
      foreach my $Msg (sort keys %Start) {
         if ($Start{$Msg} > 1) {
            print "$Msg ($Start{$Msg} times)\n"
         } else {
            print "$Msg\n"
         }
      }
   } else {
      my $total;
      foreach my $Msg (sort keys %Start) {
         $total += $Start{$Msg};
      }
      print "Server started $total times\n";
   }
}

if (keys %Login) {
   if ($Detail >= 5) {
      foreach my $Msg (sort keys %Login) {
         if ($Login{$Msg} > 1) {
            print "$Msg ($Login{$Msg} times)\n"
         } else {
            print "$Msg\n"
         }
      }
   } else {
      my $total;
      foreach my $Msg (sort keys %Login) {
         $total += $Login{$Msg};
      }
      print "$total Users logged in\n";
   }
}

if (keys %TakeChar) {
   if ($Detail >= 5) {
      foreach my $Msg (sort keys %TakeChar) {
         if ($TakeChar{$Msg} > 1) {
            print "$Msg ($TakeChar{$Msg} times)\n"
         } else {
            print "$Msg\n"
         }
      }
   } else {
      my $total;
      foreach my $Msg (sort keys %TakeChar) {
         $total += $TakeChar{$Msg};
      }
      print "$total characters entered the world\n";
   }
}

if (keys %DropChar) {
   if ($Detail >= 5) {
      foreach my $Msg (sort keys %DropChar) {
         if ($DropChar{$Msg} > 1) {
            print "$Msg ($DropChar{$Msg} times)\n"
         } else {
            print "$Msg\n"
         }
      }
   } else {
      my $total;
      foreach my $Msg (sort keys %DropChar) {
         $total += $DropChar{$Msg};
      }
      print "$total characters left the world\n";
   }
}

if (keys %Logout) {
   if ($Detail >= 5) {
      foreach my $Msg (sort keys %Logout) {
         if ($Logout{$Msg} > 1) {
            print "$Msg ($Logout{$Msg} times)\n"
         } else {
            print "$Msg\n"
         }
      }
   } else {
      my $total;
      foreach my $Msg (sort keys %Logout) {
         $total += $Logout{$Msg};
      }
      print "$total players logged out\n";
   }
}

exit(0);

# vi: shiftwidth=3 tabstop=3 syntax=perl et