ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/map-tags.ext
(Generate patch)

Comparing deliantra/server/ext/map-tags.ext (file contents):
Revision 1.4 by root, Tue Sep 11 15:40:01 2007 UTC vs.
Revision 1.7 by root, Thu Sep 13 16:16:36 2007 UTC

77 add_tag_target $txn, $tag, $key; 77 add_tag_target $txn, $tag, $key;
78 } 78 }
79 79
80 # we don't actually care if it succeeds or not, as we 80 # we don't actually care if it succeeds or not, as we
81 # will just retry an hour later 81 # will just retry an hour later
82 BDB::db_txn_commit $txn; 82 BDB::db_txn_finish $txn;
83 83
84# warn "tag-updated $file (= $key) $hash\n";#d# 84# warn "tag-updated $file (= $key) $hash\n";#d#
85} 85}
86 86
87sub scan_static { 87sub scan_static {
100 100
101 &scan_static ("$dir/$_", "$map$_/") 101 &scan_static ("$dir/$_", "$map$_/")
102 for @$dirs; 102 for @$dirs;
103} 103}
104 104
105cf::async_ext { 105sub reload {
106 $Coro::current->prio (Coro::PRIO_MIN); 106 my $start = Event::time;
107 107
108 while () { 108 # 1. check for maps no longer existing
109 my $start = Event::time; 109 {
110 my @delkeys;
110 111
111 # 1. check for maps no longer existing 112 my $cursor = $db_mapinfo->cursor;
113 for (;;) {
114 BDB::db_c_get $cursor, my $key, my $data, BDB::NEXT;
115 last if $!;
112 116
113 # 2. scan all static maps 117 my $data = JSON::XS::from_json $data;
114 scan_static $cf::MAPDIR, "/"; 118 my ($ver, undef, undef, $path) = split /,/, $data->{hash}, 4;
119 push @delkeys, [$key, $data->{tags}]
120 if $ver != 1 || Coro::AIO::aio_stat $path;
121 }
122 BDB::db_c_close $cursor;
115 123
124 for (@delkeys) {
125 my ($key, $tags) = @$_;
126 my $txn = $cf::DB_ENV->txn_begin;
127 BDB::db_del $db_mapinfo, $txn, $key;
128 for my $tag (@{ $tags || [] }) {
129 remove_tag_target $txn, $tag, $key;
130 }
131 BDB::db_txn_finish $txn;
132 }
133 }
134
135 # 2. scan all static maps
136 scan_static $cf::MAPDIR, "/";
137
116 # 3. scan all dynamic maps 138 # 3. scan all dynamic maps
117 for my $path (@{ cf::map::tmp_maps or [] }, @{ cf::map::random_maps or [] }) { 139 for my $path (@{ cf::map::tmp_maps or [] }, @{ cf::map::random_maps or [] }) {
118# my $map = cf::map::find $path; 140# my $map = cf::map::find $path;
119# extract_map_tags "t/$map", $path; 141# extract_map_tags "t/$map", $path;
120 } 142 }
121 143
122 # now hunt for all per-player maps 144 # now hunt for all per-player maps
123# scan_dir $cf::PLAYERDIR 145# scan_dir $cf::PLAYERDIR
124# for my $login (@{ cf::player::list_logins or [] }) { 146# for my $login (@{ cf::player::list_logins or [] }) {
125# for my $path (@{ cf::player::maps $login or [] }) { 147# for my $path (@{ cf::player::maps $login or [] }) {
126# cf::cede_to_tick; 148# cf::cede_to_tick;
144# delete $map->{deny_reset}; 166# delete $map->{deny_reset};
145# } 167# }
146# } 168# }
147# } 169# }
148 170
149 warn sprintf "map-tag scan (%fs)", Event::time - $start; 171 warn sprintf "map-tag scan (%fs)", Event::time - $start;
150 Coro::Timer::sleep $SCHEDULE_INTERVAL; 172}
151 }
152};
153 173
174our $RELOAD_SCHEDULER = Event->timer (
175 after => 0,
176 interval => $SCHEDULE_INTERVAL,
177 data => cf::WF_AUTOCANCEL,
178 cb => Coro::unblock_sub {
179 $Coro::current->prio (Coro::PRIO_MIN);
180 reload;
181 },
182);
183
184# find all objects with the given tag, or at least try to
154sub find($) { 185sub find($) {
155 my ($tag) = @_; 186 my ($tag) = @_;
156 187
157 utf8::encode (my $key = $tag); 188 utf8::encode (my $key = $tag);
158 BDB::db_get $db_target, undef, $key, my $data; 189 BDB::db_get $db_target, undef, $key, my $data;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines