Michael Thomas 656f3c8
##########################################################################
Michael Thomas 656f3c8
##########################################################################
Michael Thomas 656f3c8
Michael Thomas 656f3c8
use strict;
Michael Thomas 656f3c8
Michael Thomas 656f3c8
my ($pilot, $user, $ip, $version, $reason, $Msg, $total);
Michael Thomas 656f3c8
my %Start = ();
Michael Thomas 656f3c8
my %Login = ();
Michael Thomas 656f3c8
my %TakeChar = ();
Michael Thomas 656f3c8
my %Ping = ();
Michael Thomas 656f3c8
my %Logout = ();
Michael Thomas 656f3c8
Michael Thomas 656f3c8
my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;
Michael Thomas 656f3c8
Michael Thomas 656f3c8
# Interesting events:
Michael Thomas 656f3c8
#19 Feb 17:11:10 Server runs at 50 frames per second
Michael Thomas 656f3c8
#21 Feb 05:54:27 Welcome Man=Tiago@UR| (217.129.39.100/3086) (version 4501)
Michael Thomas 656f3c8
#21 Feb 05:54:28 Man (6) starts at startpos 0.
Michael Thomas 656f3c8
#21 Feb 05:54:46 Checking Address:(217.129.39.100)
Michael Thomas 656f3c8
#21 Feb 05:54:47 Checking Address:(217.129.39.100)
Michael Thomas 656f3c8
#21 Feb 05:54:50 Checking Address:(217.129.39.100)
Michael Thomas 656f3c8
#21 Feb 05:54:50 Checking Address:(217.129.39.100)
Michael Thomas 656f3c8
#21 Feb 05:55:18 Goodbye Man=Tiago@UR| ("timeout 08")
Michael Thomas 656f3c8
Michael Thomas 656f3c8
Michael Thomas 656f3c8
Michael Thomas 656f3c8
while (defined(my $ThisLine = <STDIN>)) {
Michael Thomas 656f3c8
   chomp($ThisLine);
Michael Thomas 656f3c8
   if ( ($Msg) = ($ThisLine =~ /Server runs at .*$/)) {
Michael Thomas 656f3c8
      $Start{$Msg}++;
Michael Thomas 9519add
   } elsif ( ($pilot,$user,$ip,$version) = ($ThisLine =~ /Welcome ([^=]+)=([^|]+)\|.* \(([^\)]+)\) \(([^\)]+)\)$/)) {
Michael Thomas 656f3c8
      $Login{$pilot}{$user}{$ip}{$version}++;
Michael Thomas 656f3c8
   } elsif ( ($pilot) = ($ThisLine =~ /([^ ]+) \(\d+\) starts at startpos/)) {
Michael Thomas 656f3c8
      $TakeChar{$pilot}++;
Michael Thomas 656f3c8
   } elsif ( ($ip) = ($ThisLine =~ /Checking Address:\((.*)\)$/)) {
Michael Thomas 656f3c8
      $Ping{$ip}++;
Michael Thomas 9519add
   } elsif ( ($pilot,$user,$reason) = ($ThisLine =~ /Goodbye ([^=]+)=([^|]+)\|.* \((.*)\)$/)) {
Michael Thomas 656f3c8
      $Logout{$pilot}{$user}{$reason}++;
Michael Thomas 656f3c8
   }  
Michael Thomas 656f3c8
}
Michael Thomas 656f3c8
Michael Thomas 656f3c8
if (keys %Start) {
Michael Thomas 656f3c8
   if ($Detail >= 5) {
Michael Thomas 656f3c8
      foreach my $Msg (sort keys %Start) {
Michael Thomas 656f3c8
         if ($Start{$Msg} > 1) {
Michael Thomas 656f3c8
            print "Server started ($Start{$Msg} times)\n";
Michael Thomas 656f3c8
         } else {
Michael Thomas 656f3c8
            print "Server started once\n";
Michael Thomas 656f3c8
         }
Michael Thomas 656f3c8
      }
Michael Thomas 656f3c8
   } else {
Michael Thomas 656f3c8
      my $total;
Michael Thomas 656f3c8
      foreach my $Msg (keys %Start) {
Michael Thomas 656f3c8
         $total += $Start{$Msg};
Michael Thomas 656f3c8
      }
Michael Thomas 656f3c8
      print "Server started $total times\n";
Michael Thomas 656f3c8
   }
Michael Thomas 656f3c8
}
Michael Thomas 656f3c8
Michael Thomas 656f3c8
if (keys %Login) {
Michael Thomas 656f3c8
   print "\n";
Michael Thomas 656f3c8
   if ($Detail >= 5) {
Michael Thomas 656f3c8
      foreach my $pilot (sort keys %Login) {
Michael Thomas 656f3c8
         foreach my $user (sort keys %{ $Login{$pilot} }) {
Michael Thomas 656f3c8
            my $total=0;
Michael Thomas 656f3c8
            foreach my $ip (keys %{ $Login{$pilot}{$user} }) {
Michael Thomas 656f3c8
               foreach my $version (keys %{ $Login{$pilot}{$user}{$ip} }) {
Michael Thomas 656f3c8
                  $total += $Login{$pilot}{$user}{$ip}{$version};
Michael Thomas 656f3c8
               }
Michael Thomas 656f3c8
            }
Michael Thomas 656f3c8
            print "Pilot $pilot ($user) logged in $total times\n";
Michael Thomas 656f3c8
         }
Michael Thomas 656f3c8
      }
Michael Thomas 656f3c8
   } else {
Michael Thomas 656f3c8
      my $total;
Michael Thomas 656f3c8
      foreach my $pilot (keys %Login) {
Michael Thomas 656f3c8
         foreach my $user (keys %{ $Login{$pilot} }) {
Michael Thomas 656f3c8
            foreach my $ip (keys %{ $Login{$pilot}{$user} }) {
Michael Thomas 656f3c8
               foreach my $version (keys %{ $Login{$pilot}{$user}{$ip} }) {
Michael Thomas 656f3c8
                  $total += $Login{$pilot}{$user}{$ip}{$version};
Michael Thomas 656f3c8
               }
Michael Thomas 656f3c8
            }
Michael Thomas 656f3c8
         }
Michael Thomas 656f3c8
      }
Michael Thomas 656f3c8
      print "$total users logged in\n";
Michael Thomas 656f3c8
   }
Michael Thomas 656f3c8
}
Michael Thomas 656f3c8
Michael Thomas 656f3c8
if (keys %TakeChar) {
Michael Thomas 656f3c8
   print "\n";
Michael Thomas 656f3c8
   if ($Detail >= 5) {
Michael Thomas 656f3c8
      foreach my $pilot (sort keys %TakeChar) {
Michael Thomas 656f3c8
         if ($TakeChar{$pilot} > 1) {
Michael Thomas 656f3c8
            print "Player $pilot joined $TakeChar{$pilot} times\n"
Michael Thomas 656f3c8
         } else {
Michael Thomas 656f3c8
            print "Player $pilot joined once\n"
Michael Thomas 656f3c8
         }
Michael Thomas 656f3c8
      }
Michael Thomas 656f3c8
   } else {
Michael Thomas 656f3c8
      my $total=0;
Michael Thomas 656f3c8
      foreach my $pilot (keys %TakeChar) {
Michael Thomas 656f3c8
         $total += $TakeChar{$pilot};
Michael Thomas 656f3c8
      }
Michael Thomas 656f3c8
      print "$total players entered the world\n";
Michael Thomas 656f3c8
   }
Michael Thomas 656f3c8
}
Michael Thomas 656f3c8
Michael Thomas 656f3c8
if (keys %Logout) {
Michael Thomas 656f3c8
   print "\n";
Michael Thomas 656f3c8
   if ($Detail >= 5) {
Michael Thomas 656f3c8
      foreach my $pilot (sort keys %Logout) {
Michael Thomas 656f3c8
         foreach my $user (sort keys %{ $Logout{$pilot} }) {
Michael Thomas 656f3c8
            foreach my $reason (keys %{ $Logout{$pilot}{$user} }) {
Michael Thomas 656f3c8
               print "Pilot $pilot ($user) logged out $Logout{$pilot}{$user}{$reason} times ($reason)\n";
Michael Thomas 656f3c8
            }
Michael Thomas 656f3c8
         }
Michael Thomas 656f3c8
      }
Michael Thomas 656f3c8
   } else {
Michael Thomas 656f3c8
      my $total=0;
Michael Thomas 656f3c8
      foreach my $pilot (keys %Logout) {
Michael Thomas 656f3c8
         foreach my $user (keys %{ $Logout{$pilot} }) {
Michael Thomas 656f3c8
            foreach my $reason (keys %{ $Logout{$pilot}{$user} }) {
Michael Thomas 656f3c8
               $total += $Logout{$pilot}{$user}{$reason};
Michael Thomas 656f3c8
            }
Michael Thomas 656f3c8
         }
Michael Thomas 656f3c8
      }
Michael Thomas 656f3c8
      print "$total users logged out\n";
Michael Thomas 656f3c8
   }
Michael Thomas 656f3c8
}
Michael Thomas 656f3c8
Michael Thomas 656f3c8
if (keys %Ping) {
Michael Thomas 656f3c8
   print "\n";
Michael Thomas 656f3c8
   if ($Detail >= 5) {
Michael Thomas 656f3c8
      foreach my $ip (sort keys %Ping) {
Michael Thomas 656f3c8
         if ($Ping{$ip} > 1) {
Michael Thomas 656f3c8
            printf "Pinged %-16s %3d times\n", ($ip,$Ping{$ip})
Michael Thomas 656f3c8
         } else {
Michael Thomas 656f3c8
            printf "Pinged %-16s once\n", ($ip)
Michael Thomas 656f3c8
         }
Michael Thomas 656f3c8
      }
Michael Thomas 656f3c8
   } else {
Michael Thomas 656f3c8
      my $total=0;
Michael Thomas 656f3c8
      foreach my $ip (keys %Ping) {
Michael Thomas 656f3c8
         $total += $Ping{$ip};
Michael Thomas 656f3c8
      }
Michael Thomas 656f3c8
      print "Pinged " . keys(%Ping) . " hosts $total times\n";
Michael Thomas 656f3c8
   }
Michael Thomas 656f3c8
}
Michael Thomas 656f3c8
Michael Thomas 656f3c8
Michael Thomas 656f3c8
exit(0);
Michael Thomas 656f3c8
Michael Thomas 656f3c8
# vi: shiftwidth=3 tabstop=3 syntax=perl et
Michael Thomas 656f3c8