--- deliantra/server/lib/cf.pm 2006/09/12 22:18:55 1.65 +++ deliantra/server/lib/cf.pm 2006/09/18 01:10:35 1.69 @@ -810,6 +810,21 @@ wantarray ? @res : $res[0] } +=item cf::register_script_function $function => $cb + +Register a function that can be called from within map/npc scripts. The +function should be reasonably secure and should be put into a package name +like the extension. + +Example: register a function that gets called whenever a map script calls +C, as used by the C extension. + + cf::register_script_function "rent::overview" => sub { + ... + }; + +=cut + sub register_script_function { my ($fun, $cb) = @_; @@ -862,7 +877,7 @@ { my $db; - my $path = cf::datadir . "/database.pst"; + my $path = cf::localdir . "/database.pst"; sub db_load() { warn "loading database $path\n";#d# remove later @@ -874,7 +889,7 @@ sub db_save() { warn "saving database $path\n";#d# remove later waitpid $pid, 0 if $pid; - unless ($pid = fork) { + if (0 == ($pid = fork)) { $db->{_meta}{version} = 1; Storable::nstore $db, "$path~"; rename "$path~", $path; @@ -912,6 +927,13 @@ } db_dirty; } + + attach_global + prio => 10000, + on_cleanup => sub { + db_sync; + }, + ; } #############################################################################