ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.209 by root, Mon Feb 12 01:25:55 2007 UTC vs.
Revision 1.211 by root, Tue Feb 13 16:23:32 2007 UTC

356 356
357 $coro 357 $coro
358} 358}
359 359
360sub write_runtime { 360sub write_runtime {
361 $TICK_WATCHER->is_active or cf::cleanup "mainloop frozen but runtime active", 1;
362
361 my $runtime = cf::localdir . "/runtime"; 363 my $runtime = cf::localdir . "/runtime";
362 364
363 my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644 365 my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644
364 or return; 366 or return;
365 367
1609 return if $self->players; 1611 return if $self->players;
1610 return if $self->isa ("ext::map_per_player");#d# 1612 return if $self->isa ("ext::map_per_player");#d#
1611 1613
1612 warn "resetting map ", $self->path;#d# 1614 warn "resetting map ", $self->path;#d#
1613 1615
1616 $self->in_memory (cf::MAP_SWAPPED);
1617
1618 # need to save uniques path
1619 unless ($self->{deny_save}) {
1620 my $uniq = $self->uniq_path; utf8::encode $uniq;
1621
1622 $self->_save_objects ($uniq, cf::IO_UNIQUES)
1623 if $uniq;
1624 }
1625
1614 delete $cf::MAP{$self->path}; 1626 delete $cf::MAP{$self->path};
1615 1627
1616 $self->in_memory (cf::MAP_SWAPPED);
1617 $self->clear; 1628 $self->clear;
1618 1629
1619 $_->clear_links_to ($self) for values %cf::MAP; 1630 $_->clear_links_to ($self) for values %cf::MAP;
1620 1631
1621 $self->unlink_save; 1632 $self->unlink_save;
2197 2208
2198=cut 2209=cut
2199 2210
2200our $DB; 2211our $DB;
2201 2212
2213sub db_init {
2202unless ($DB) { 2214 unless ($DB) {
2203 $DB = BDB::db_create $DB_ENV; 2215 $DB = BDB::db_create $DB_ENV;
2204 2216
2205 cf::sync_job { 2217 cf::sync_job {
2206 eval { 2218 eval {
2207 $DB->set_flags (BDB::CHKSUM); 2219 $DB->set_flags (BDB::CHKSUM);
2208 2220
2209 BDB::db_open $DB, undef, "db", undef, BDB::BTREE, 2221 BDB::db_open $DB, undef, "db", undef, BDB::BTREE,
2210 BDB::CREATE | BDB::AUTO_COMMIT, 0666; 2222 BDB::CREATE | BDB::AUTO_COMMIT, 0666;
2211 cf::cleanup "db_open(db): $!" if $!; 2223 cf::cleanup "db_open(db): $!" if $!;
2224 };
2225 cf::cleanup "db_open(db): $@" if $@;
2212 }; 2226 };
2213 cf::cleanup "db_open(db): $@" if $@;
2214 };
2215 2227
2216 my $path = cf::localdir . "/database.pst"; 2228 my $path = cf::localdir . "/database.pst";
2217 if (stat $path) { 2229 if (stat $path) {
2218 cf::sync_job { 2230 cf::sync_job {
2219 my $pst = Storable::retrieve $path; 2231 my $pst = Storable::retrieve $path;
2220 2232
2221 cf::db_put (board => data => $pst->{board}); 2233 cf::db_put (board => data => $pst->{board});
2222 cf::db_put (guildrules => data => $pst->{guildrules}); 2234 cf::db_put (guildrules => data => $pst->{guildrules});
2223 cf::db_put (rent => balance => $pst->{rent}{balance}); 2235 cf::db_put (rent => balance => $pst->{rent}{balance});
2224 BDB::db_env_txn_checkpoint $DB_ENV; 2236 BDB::db_env_txn_checkpoint $DB_ENV;
2225 2237
2226 unlink $path; 2238 unlink $path;
2239 };
2227 }; 2240 }
2228 } 2241 }
2229} 2242}
2230 2243
2231sub db_get($$) { 2244sub db_get($$) {
2232 my $key = "$_[0]/$_[1]"; 2245 my $key = "$_[0]/$_[1]";
2285 Event::one_event; 2298 Event::one_event;
2286 })->prio (Coro::PRIO_MAX); 2299 })->prio (Coro::PRIO_MAX);
2287 }; 2300 };
2288 2301
2289 cfg_load; 2302 cfg_load;
2303 db_init;
2290 load_extensions; 2304 load_extensions;
2291 2305
2292 $TICK_WATCHER->start; 2306 $TICK_WATCHER->start;
2293 Event::loop; 2307 Event::loop;
2294} 2308}
2340 BDB::db_env_txn_checkpoint $DB_ENV; 2354 BDB::db_env_txn_checkpoint $DB_ENV;
2341 warn "end emergency database checkpoint\n"; 2355 warn "end emergency database checkpoint\n";
2342 }; 2356 };
2343 2357
2344 warn "leave emergency perl save\n"; 2358 warn "leave emergency perl save\n";
2359}
2360
2361sub post_cleanup {
2362 my ($make_core) = @_;
2363
2364 warn Carp::longmess "post_cleanup backtrace"
2365 if $make_core;
2345} 2366}
2346 2367
2347sub reload() { 2368sub reload() {
2348 # can/must only be called in main 2369 # can/must only be called in main
2349 if ($Coro::current != $Coro::main) { 2370 if ($Coro::current != $Coro::main) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines