Code: Select all
Index: src/Log.pm
===================================================================
--- src/Log.pm (revision 6344)
+++ src/Log.pm (working copy)
@@ -112,9 +112,9 @@
use base qw(Exporter);
use Modules 'register';
-use Globals qw(%config $interface %consoleColors %field %cities_lut);
+use Globals qw(%config $interface %consoleColors %field %cities_lut %maps_lut $char);
use Utils::DataStructures qw(binAdd existsInList);
-use Utils qw(binAdd existsInList getFormattedDate);
+use Utils qw(binAdd existsInList getFormattedDate calcPosition);
our @EXPORT_OK = qw(message warning error debug);
@@ -131,6 +131,7 @@
# If you set the current verbosity higher, you will see more messages.
our $warningVerbosity;
our $errorVerbosity;
+our @messages=();
# Enable/disable printing certain domains to console.
# Usage: $messageConsole{$domain} = $enabled
@@ -237,6 +238,36 @@
}
}
}
+
+ if($config{logDeath}) {
+ if ($level <= $currentVerbosity) {
+ my (undef, $microseconds) = Time::HiRes::gettimeofday;
+ $microseconds = substr($microseconds, 0, 2);
+ my $message2 = "[".getFormattedDate(int(time)).".$microseconds] ".$message;
+ my $logfile;
+ push(@messages, $message2);
+ if ($#messages == $config{'logDeathSize'} + 1) {
+ shift(@messages);
+ }
+ if ($config{logAppendUsername}) {
+ $logfile = "$Settings::logs_folder/deathlog_$config{username}_$config{char}.txt";
+ } else {
+ $logfile = "$Settings::logs_folder/deathlog.txt";
+ }
+ my $deathmsg = $config{'deathMessage'};
+ if ($message =~ /$deathmsg/) {
+ my $pos = calcPosition($char);
+ my $location = "\nYou died at $maps_lut{$field{name}.'.rsw'} ($field{name}) : $pos->{x}, $pos->{y}\n";
+ use encoding 'utf8';
+ open(DFILE, ">>:utf8", "$logfile");
+ print DFILE "\n*** Start of console death log ***\n\n";
+ print DFILE @messages;
+ print DFILE $location;
+ print DFILE "\n*** End of console death log ***\n\n";
+ close(DFILE);
+ }
+ }
+ }
# Print to files
foreach my $file (@{$files->{$domain}}) {