--- deliantra/server/ext/map-tags.ext 2007/09/10 18:30:30 1.1 +++ deliantra/server/ext/map-tags.ext 2007/09/13 08:35:24 1.5 @@ -1,6 +1,6 @@ #! perl # mandatory -our $SCHEDULE_INTERVAL = $cf::CFG{extractor_schedule_interval} || 3600; +our $SCHEDULE_INTERVAL = $cf::CFG{extractor_schedule_interval} || 3600; use JSON::XS; @@ -102,23 +102,20 @@ for @$dirs; } -cf::async_ext { - $Coro::current->prio (Coro::PRIO_MIN); +sub reload { + my $start = Event::time; - while () { - my $start = Event::time; + # 1. check for maps no longer existing - # 1. check for maps no longer existing + # 2. scan all static maps + scan_static $cf::MAPDIR, "/"; - # 2. scan all static maps - scan_static $cf::MAPDIR, "/"; - - # 3. scan all dynamic maps - for my $path (@{ cf::map::tmp_maps or [] }, @{ cf::map::random_maps or [] }) { + # 3. scan all dynamic maps + for my $path (@{ cf::map::tmp_maps or [] }, @{ cf::map::random_maps or [] }) { # my $map = cf::map::find $path; # extract_map_tags "t/$map", $path; - } - + } + # now hunt for all per-player maps # scan_dir $cf::PLAYERDIR # for my $login (@{ cf::player::list_logins or [] }) { @@ -146,9 +143,30 @@ # } # } - warn sprintf "map-tag scan (%fs)", Event::time - $start; - Coro::Timer::sleep $SCHEDULE_INTERVAL; - } -}; - + warn sprintf "map-tag scan (%fs)", Event::time - $start; +} +our $RELOAD_SCHEDULER = Event->timer ( + after => 0, + interval => $SCHEDULE_INTERVAL, + data => cf::WF_AUTOCANCEL, + cb => Coro::unblock_sub { + $Coro::current->prio (Coro::PRIO_MIN); + reload; + }, +); + +# find all objects with the given tag, or at least try to +sub find($) { + my ($tag) = @_; + + utf8::encode (my $key = $tag); + BDB::db_get $db_target, undef, $key, my $data; + utf8::decode $data; + + map { $_->load; $_->find_tagged_objects ($tag) } + grep $_, + map { cf::map::find $_ } + grep s/^s//, + split /\x00/, $data +}