--- deliantra/server/ext/map-scheduler.ext 2007/05/11 07:59:59 1.34 +++ deliantra/server/ext/map-scheduler.ext 2007/06/11 21:38:13 1.37 @@ -1,4 +1,4 @@ -#! perl # MANDATORY +#! perl # mandatory # this extension swaps out maps and resets them, in essence managing # the reset/swap policy of the server. @@ -13,21 +13,43 @@ cf::async_ext { $Coro::current->prio (Coro::PRIO_MIN); + # load the header of swapped-out maps. # this is not a correctness issue, it simply saves diskspace # because old files will get cleaned up on reset time - Coro::Timer::sleep 1; - - my $files = Coro::AIO::aio_readdir $cf::TMPDIR; + Coro::Timer::sleep 0.25; - for my $map (@$files) { - utf8::decode $map; - next if $map =~ /\.(?:pst|meta)$/; - cf::map::find $map; - cf::wait_for_tick; + for my $path (@{ cf::map::tmp_maps or [] }, @{ cf::map::random_maps or [] }) { + cf::map::find $path; + cf::wait_for_tick; Coro::cede; } - #TODO: should also preload random maps... + # now hunt for resettable per-player maps + for my $login (@{ cf::player::list_logins or [] }) { + for my $path (@{ cf::player::maps $login or [] }) { + Coro::cede; + + $path =~ /^~[^\/]+(\/.*)$/ + or next; # doh + + my $base = cf::map::find $1; + + # skip maps without base maps on the assumption + # that those are old, unresettable maps + next unless $base; + + # skip unresettable maps, for speed + next if $base->{deny_reset}; + + my $map = cf::map::find $path; + cf::wait_for_tick; + + if ($map->{deny_reset}) { + warn "found noreset map with resettable base map, resetting: $path\n"; + delete $map->{deny_reset}; + } + } + } }; our $SCHEDULER = cf::async_ext {