--- deliantra/server/ext/schmorplog.ext 2007/05/19 11:04:16 1.9 +++ deliantra/server/ext/schmorplog.ext 2008/04/30 10:36:01 1.15 @@ -1,18 +1,44 @@ -#! perl +#! perl # depends=irc -our $UPDATE_LOGINS = Event->idle (repeat => 0, min => 1, data => cf::WF_AUTOCANCEL, cb => Coro::unblock_sub { - my ($status, @pl) = ext::commands::who_listing; +use Fcntl; +use Coro::AIO; - #TODO: write files asynchronously - open my $fh, ">", "$LOCALDIR/usercount"; - print $fh scalar @pl; - - open my $fh, ">", "$LOCALDIR/userlisting.html"; - for ($status, @pl) { - s/[<&]//g; - print $fh "$_
\n"; - } -}); +our $UPDATE_LOGINS = EV::idle sub { + $_[0]->stop; + + cf::async { + my ($status, @pl) = ext::commands::who_listing; + + my $fh = aio_open "$LOCALDIR/usercount", O_WRONLY | O_CREAT | O_TRUNC, 0644 + or return; + aio_write $fh, 0, undef, scalar @pl, 0; + aio_close $fh; + + my $who; + for ($status, @pl) { + s/[<&]//g; + $who .= "$_
\n"; + } + + my $fh = aio_open "$LOCALDIR/userlisting.html", O_WRONLY | O_CREAT | O_TRUNC, 0644 + or return; + aio_write $fh, 0, undef, $who, 0; + aio_close $fh; + }; +}; + +cf::object->attach ( + on_kill => sub { + my ($ob, $hitter) = @_; + + return unless $hitter; + $hitter = $hitter->outer_owner; + my $pl = $hitter->contr + or return; + + ++$hitter->{stats_kill}{$ob->name_pl}; + }, +); cf::player->attach ( on_login => sub { @@ -56,7 +82,9 @@ }, on_death => sub { my ($pl) = @_; - ext::irc::do_notice (sprintf "%s was killed by %s", $pl->ob->name, $pl->killer); + ext::irc::do_notice (sprintf "%s was killed by %s", $pl->ob->name, $pl->killer_name); + + ++$pl->ob->{stats_death}{$pl->killer_name}; $pl->ob->set_ob_key_value (schmorplog_death_count => 1 + $pl->ob->get_ob_key_value ("schmorplog_death_count"));