--- deliantra/Deliantra-Client/DC/DB.pm 2008/01/19 04:49:37 1.32 +++ deliantra/Deliantra-Client/DC/DB.pm 2008/03/25 21:11:51 1.33 @@ -45,7 +45,7 @@ our $DB_STATE; our %DB_TABLE; -sub open_db { +sub try_open_db { mkdir $DB_HOME, 0777; $DB_ENV = db_env_create; @@ -86,19 +86,8 @@ ############################################################################# -unless (eval { open_db }) { - warn "$@";#d# - eval { File::Path::rmtree $DB_HOME }; - open_db; -} - -our $WATCHER = EV::io BDB::poll_fileno, EV::READ, \&BDB::poll_cb; - -our $SYNC = EV::timer_ns 0, 60, sub { - $_[0]->stop; - db_env_txn_checkpoint $DB_ENV, 0, 0, 0, sub { }; -}; - +our $WATCHER; +our $SYNC; our $tilemap; sub exists($$$) { @@ -223,19 +212,6 @@ ############################################################################# -# fetch the full face table first -unless ($tilemap) { - do_table facemap => sub { - $tilemap = $_[0]; - delete $tilemap->{id}; - my %maptile = reverse %$tilemap;#d# - if ((scalar keys %$tilemap) != (scalar keys %maptile)) {#d# - $tilemap = { };#d# - DC::error "FATAL: facemap is not a 1:1 mapping, please report this and delete your $DB_HOME directory!\n";#d# - }#d# - }; -} - package DC::DB::Server; use strict; @@ -424,6 +400,40 @@ close $FH; } +package DC::DB; + +sub open_db { + unless (eval { try_open_db }) { + warn "$@";#d# + eval { File::Path::rmtree $DB_HOME }; + try_open_db; + } + + # fetch the full face table first + unless ($tilemap) { + do_table facemap => sub { + $tilemap = $_[0]; + delete $tilemap->{id}; + my %maptile = reverse %$tilemap;#d# + if ((scalar keys %$tilemap) != (scalar keys %maptile)) {#d# + $tilemap = { };#d# + DC::error "FATAL: facemap is not a 1:1 mapping, please report this and delete your $DB_HOME directory!\n";#d# + }#d# + }; + } + + $WATCHER = EV::io BDB::poll_fileno, EV::READ, \&BDB::poll_cb; + $SYNC = EV::timer_ns 0, 60, sub { + $_[0]->stop; + db_env_txn_checkpoint $DB_ENV, 0, 0, 0, sub { }; + }; +} + +END { + %DB_TABLE = (); + undef $DB_ENV; +} + 1; =back