--- deliantra/server/ext/highscore.ext 2010/01/31 04:20:36 1.2 +++ deliantra/server/ext/highscore.ext 2010/05/09 22:51:13 1.7 @@ -44,14 +44,14 @@ aio_pathsync "$cf::LOCALDIR"; - warn "saved highscore file.\n"; + cf::trace "saved highscore file.\n"; 1 } -our $HEADER = " | rank | name | experience | killer | HP |mana |grace|\n"; -our $SEP = " +------+-------------|--------------------|----------------------+-----+-----+-----+\n"; -our $FORMAT = " | %4s | %-11.11s | %18s | %-20.20s | %3s | %3s | %3s |\n"; +our $HEADER = " | rank | name | experience | reason | HP |mana |grace|\n"; +our $SEP = " +------+--------------------|--------------|----------------------+-----+-----+-----+\n"; +our $FORMAT = " | %4s | %-18.18s | %12s | %-20.20s | %3s | %3s | %3s |\n"; our $SCORE_CHANNEL = { id => "highscore", @@ -80,85 +80,82 @@ $ob->stats->maxsp, $ob->stats->maxgrace, $ob->uuid, - int EV::now, + int AE::now, ]; - cf::async { - my $guard = cf::lock_acquire "highscore:check"; + my $guard = cf::lock_acquire "highscore:check"; - # load hiscore, patch, save hiscore - my $hiscore = load_hiscore; + # load hiscore, patch, save hiscore + my $hiscore = load_hiscore; - cf::get_slot 0.01, 0, "highscore check"; + cf::get_slot 0.01, 0, "highscore check"; - my ($pre, $ins, $save); + my ($pre, $ins, $save); - pop @$hiscore while @$hiscore > $HIGHSCORE_ENTRIES; + pop @$hiscore while @$hiscore > $HIGHSCORE_ENTRIES; - # find previous entry, and new position + # find previous entry, and new position - for (0 .. $#$hiscore) { - $pre //= $_ if $hiscore->[$_][0] eq $score->[0]; - $ins //= $_ if $hiscore->[$_][2] < $score->[2]; - } - cf::cede_to_tick; # we need an "interruptible" block... - - my $msg; + for (0 .. $#$hiscore) { + $pre //= $_ if $hiscore->[$_][0] eq $score->[0]; + $ins //= $_ if $hiscore->[$_][2] < $score->[2]; + } + cf::cede_to_tick; # we need an "interruptible" block... - if (defined $pre) { - # we are already in the list - if ($hiscore->[$pre][2] < $score->[2]) { - $msg = "T\n\n" - . $SEP - . $HEADER - . $SEP - . (fmt $ins, $score) - . (fmt $pre, $hiscore->[$pre]) - . $SEP; - - splice @$hiscore, $pre, 1; - splice @$hiscore, $ins, 0, $score; - $save = 1; - } else { - $msg = "T\n\n" - . $SEP - . $HEADER - . $SEP - . (fmt $pre , $hiscore->[$pre]) - . (fmt undef, $score) - . $SEP; - } - } elsif (defined $ins or @$hiscore < $HIGHSCORE_ENTRIES) { - $ins //= @$hiscore; + my $msg; - $msg = "T\n\n" + if (defined $pre) { + # we are already in the list + if ($hiscore->[$pre][2] < $score->[2]) { + $msg = "T\n\n" . $SEP . $HEADER . $SEP . (fmt $ins, $score) + . (fmt $pre, $hiscore->[$pre]) . $SEP; + splice @$hiscore, $pre, 1; splice @$hiscore, $ins, 0, $score; $save = 1; } else { - $msg = "T\n\n" + $msg = "T\n\n" . $SEP . $HEADER . $SEP - . (fmt -1 + (scalar @$hiscore), $hiscore->[-1]) + . (fmt $pre , $hiscore->[$pre]) . (fmt undef, $score) . $SEP; } + } elsif (defined $ins or @$hiscore < $HIGHSCORE_ENTRIES) { + $ins //= @$hiscore; - warn $msg;#d# remove once working stable - - $ob->send_msg ($SCORE_CHANNEL => $msg, cf::NDI_CLEAR); - - if ($save) { - save_hiscore $hiscore - or die "unable to write highscore file: $!"; - } - }; + $msg = "T\n\n" + . $SEP + . $HEADER + . $SEP + . (fmt $ins, $score) + . $SEP; + + splice @$hiscore, $ins, 0, $score; + $save = 1; + } else { + $msg = "T\n\n" + . $SEP + . $HEADER + . $SEP + . (fmt -1 + (scalar @$hiscore), $hiscore->[-1]) + . (fmt undef, $score) + . $SEP; + } + + cf::info $msg;#d# remove once working stable + + $ob->send_msg ($SCORE_CHANNEL => $msg, cf::NDI_CLEAR); + + if ($save) { + save_hiscore $hiscore + or die "unable to write highscore file: $!"; + } } -