--- deliantra/server/lib/cf.pm 2007/01/29 14:46:01 1.199 +++ deliantra/server/lib/cf.pm 2007/02/02 19:59:22 1.204 @@ -50,6 +50,7 @@ our $WRITE_RUNTIME_WATCHER; our $NEXT_TICK; our $NOW; +our $USE_FSYNC; # use fsync to write maps - default off our %CFG; @@ -360,6 +361,7 @@ (aio_write $fh, 0, (length $value), $value, 0) <= 0 and return; + # always fsync - this file is important aio_fsync $fh and return; @@ -754,7 +756,7 @@ if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { chmod SAVE_MODE, $fh; aio_write $fh, 0, (length $$rdata), $$rdata, 0; - aio_fsync $fh; + aio_fsync $fh if $cf::USE_FSYNC; close $fh; if (@$objs) { @@ -762,7 +764,7 @@ chmod SAVE_MODE, $fh; my $data = Storable::nfreeze { version => 1, objs => $objs }; aio_write $fh, 0, (length $data), $data, 0; - aio_fsync $fh; + aio_fsync $fh if $cf::USE_FSYNC; close $fh; aio_rename "$filename.pst~", "$filename.pst"; } @@ -778,6 +780,12 @@ aio_unlink $filename; aio_unlink "$filename.pst"; } + + #d##TODO# nuke non .map-files if exist + if ($filename =~ s/\.map$//) { + aio_unlink $filename; + aio_unlink "$filename.pst"; + } } } @@ -794,6 +802,9 @@ my ($data, $av); + #d#TODO remove .map if file does not exist + aio_stat $filename and $filename =~ s/\.map$//; + (aio_load $filename, $data) >= 0 or return; @@ -1072,6 +1083,8 @@ sub maps($) { my ($pl) = @_; + $pl = ref $pl ? $pl->ob->name : $pl; + my $files = aio_readdir playerdir $pl or return; @@ -1082,7 +1095,7 @@ next if /\.(?:pl|pst)$/; next unless /^$PATH_SEP/o; - push @paths, cf::map::normalise "~" . $pl->ob->name . "/" . $_; + push @paths, cf::map::normalise "~$pl/$_"; } \@paths @@ -1253,7 +1266,7 @@ sub load_path { my ($self) = @_; - sprintf "%s/%s/%s", cf::datadir, cf::mapdir, $self->{path} + sprintf "%s/%s/%s.map", cf::datadir, cf::mapdir, $self->{path} } # the temporary/swap location @@ -1261,7 +1274,7 @@ my ($self) = @_; (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/g; - sprintf "%s/%s/%s", cf::localdir, cf::tmpdir, $path + sprintf "%s/%s/%s.map", cf::localdir, cf::tmpdir, $path } # the unique path, undef == no special unique path @@ -1287,14 +1300,19 @@ utf8::encode (my $save = $self->save_path); IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink $save; IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink "$save.pst"; + + #d#TODO remove .map and also nuke + $save =~ s/\.map// or return;#d# + IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink $save;#d# + IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink "$save.pst";#d# } sub load_header_from($) { my ($self, $path) = @_; utf8::encode $path; - aio_open $path, O_RDONLY, 0 - or return; + #aio_open $path, O_RDONLY, 0 + # or return; $self->_load_header ($path) or return; @@ -1989,6 +2007,7 @@ or return; # be conservative, not sure how that can happen, but we saw a crash here (shift @$queue)->[1]->($msg); + return unless $ns->valid; # temporary(?) workaround for callback destroying socket push @{ $ns->{query_queue} }, @$queue; @@ -2255,7 +2274,12 @@ } ############################################################################# -# the server's main() +# the server's init and main functions + +sub load_resources { + load_regions sprintf "%s/%s/regions", cf::datadir, cf::mapdir + or die "unable to load regions file\n";#d# +} sub cfg_load { open my $fh, "<:utf8", cf::confdir . "/config" @@ -2278,6 +2302,10 @@ } } +sub init { + load_resources; +} + sub main { # we must not ever block the main coroutine local $Coro::idle = sub { @@ -2446,6 +2474,9 @@ warn "reattaching attachments to maps"; reattach $_ for values %MAP; + warn "loading reloadable resources"; + load_resources; + warn "restarting server ticker"; $TICK_WATCHER->start;