--- deliantra/Deliantra-Client/DC/Protocol.pm 2006/06/12 14:06:27 1.33 +++ deliantra/Deliantra-Client/DC/Protocol.pm 2006/06/13 14:35:17 1.34 @@ -10,6 +10,8 @@ use base 'Crossfire::Protocol::Base'; +our %open_logs; + sub new { my $class = shift; @@ -61,6 +63,30 @@ $self } +sub logprint { + my ($self, @a) = @_; + my $filename = "$Crossfire::VARDIR/log.$self->{host}"; + + my $fh = $open_logs{$filename}; + unless ($fh) { + # FIXME: handle this more gracefully? + open $fh, ">>", $filename + or die "Couldn't open logfile: log.$self->{host}: $!"; + + $open_logs{$filename} = $fh; + } + + my ($sec, $min, $hour, $mday, $mon, $year) = localtime (time); + + my $ts = sprintf "%04d-%02d-%02d %02d:%02d:%02d", + $year + 1900, $mon + 1, $mday, $hour, $min, $sec; + + print $fh "$ts ", @a, "\n"; + $fh->flush; +} + + + sub stats_update { my ($self, $stats) = @_; @@ -81,6 +107,7 @@ push @{$self->{record}}, $command; } + $self->logprint ("send: ", $command); $self->send_command ($command); ::status $command; } @@ -371,6 +398,8 @@ [0.74, 0.65, 0.41], ); + $self->logprint ("info: ", $text); + my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; # try to create single paragraphs of multiple lines sent by the server