ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/DB.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/DB.pm (file contents):
Revision 1.32 by root, Sat Jan 19 04:49:37 2008 UTC vs.
Revision 1.33 by root, Tue Mar 25 21:11:51 2008 UTC

43 43
44our $DB_ENV; 44our $DB_ENV;
45our $DB_STATE; 45our $DB_STATE;
46our %DB_TABLE; 46our %DB_TABLE;
47 47
48sub open_db { 48sub try_open_db {
49 mkdir $DB_HOME, 0777; 49 mkdir $DB_HOME, 0777;
50 50
51 $DB_ENV = db_env_create; 51 $DB_ENV = db_env_create;
52 52
53 $DB_ENV->set_errfile (\*STDERR); 53 $DB_ENV->set_errfile (\*STDERR);
84 } 84 }
85} 85}
86 86
87############################################################################# 87#############################################################################
88 88
89unless (eval { open_db }) { 89our $WATCHER;
90 warn "$@";#d# 90our $SYNC;
91 eval { File::Path::rmtree $DB_HOME };
92 open_db;
93}
94
95our $WATCHER = EV::io BDB::poll_fileno, EV::READ, \&BDB::poll_cb;
96
97our $SYNC = EV::timer_ns 0, 60, sub {
98 $_[0]->stop;
99 db_env_txn_checkpoint $DB_ENV, 0, 0, 0, sub { };
100};
101
102our $tilemap; 91our $tilemap;
103 92
104sub exists($$$) { 93sub exists($$$) {
105 my ($db, $key, $cb) = @_; 94 my ($db, $key, $cb) = @_;
106 95
220sub logprint($$$) { 209sub logprint($$$) {
221 DC::DB::Server::req (logprint => @_); 210 DC::DB::Server::req (logprint => @_);
222} 211}
223 212
224############################################################################# 213#############################################################################
225
226# fetch the full face table first
227unless ($tilemap) {
228 do_table facemap => sub {
229 $tilemap = $_[0];
230 delete $tilemap->{id};
231 my %maptile = reverse %$tilemap;#d#
232 if ((scalar keys %$tilemap) != (scalar keys %maptile)) {#d#
233 $tilemap = { };#d#
234 DC::error "FATAL: facemap is not a 1:1 mapping, please report this and delete your $DB_HOME directory!\n";#d#
235 }#d#
236 };
237}
238 214
239package DC::DB::Server; 215package DC::DB::Server;
240 216
241use strict; 217use strict;
242 218
422 398
423sub stop { 399sub stop {
424 close $FH; 400 close $FH;
425} 401}
426 402
403package DC::DB;
404
405sub open_db {
406 unless (eval { try_open_db }) {
407 warn "$@";#d#
408 eval { File::Path::rmtree $DB_HOME };
409 try_open_db;
410 }
411
412 # fetch the full face table first
413 unless ($tilemap) {
414 do_table facemap => sub {
415 $tilemap = $_[0];
416 delete $tilemap->{id};
417 my %maptile = reverse %$tilemap;#d#
418 if ((scalar keys %$tilemap) != (scalar keys %maptile)) {#d#
419 $tilemap = { };#d#
420 DC::error "FATAL: facemap is not a 1:1 mapping, please report this and delete your $DB_HOME directory!\n";#d#
421 }#d#
422 };
423 }
424
425 $WATCHER = EV::io BDB::poll_fileno, EV::READ, \&BDB::poll_cb;
426 $SYNC = EV::timer_ns 0, 60, sub {
427 $_[0]->stop;
428 db_env_txn_checkpoint $DB_ENV, 0, 0, 0, sub { };
429 };
430}
431
432END {
433 %DB_TABLE = ();
434 undef $DB_ENV;
435}
436
4271; 4371;
428 438
429=back 439=back
430 440
431=head1 AUTHOR 441=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines