--- deliantra/server/lib/cf.pm 2007/09/12 11:10:11 1.367 +++ deliantra/server/lib/cf.pm 2007/09/13 16:16:01 1.371 @@ -82,6 +82,7 @@ our $USE_FSYNC = 1; # use fsync to write maps - default off our $BDB_POLL_WATCHER; +our $BDB_DEADLOCK_WATCHER; our $BDB_CHECKPOINT_WATCHER; our $BDB_TRICKLE_WATCHER; our $DB_ENV; @@ -2466,21 +2467,27 @@ my $ob = $obs[rand @obs]; # see if we actually can go there - # todo: use ob_blocked to check all tiles of the destination "object" - # for suitability. + if (@obs = grep !$self->blocked ($_->map, $_->x, $_->y), $ob, $ob->tail) { + $ob = $obs[rand @obs]; + } else { + $self->message ("Wow, it's pretty crowded in there.", cf::NDI_UNIQUE | cf::NDI_RED); + } + # else put us there anyways for now #d# ($path, $x, $y) = ($ob->map, $ob->x, $ob->y); + } else { + ($path, $x, $y) = (undef, undef, undef); } } my $map = eval { - my $map = cf::map::find $path; + my $map = defined $path ? cf::map::find $path : undef; if ($map) { $map = $map->customise_for ($self); $map = $check->($map) if $check && $map; } else { - $self->message ("The exit to '$path' is closed", cf::NDI_UNIQUE | cf::NDI_RED); + $self->message ("The exit to '$path' is closed.", cf::NDI_UNIQUE | cf::NDI_RED); } $map @@ -3460,9 +3467,6 @@ $signal->wait; } -our $stat_fh; -sysopen $stat_fh, "/tmp/cfstats", Fcntl::O_APPEND | Fcntl::O_CREAT | Fcntl::O_WRONLY, 0600;#d# - $TICK_WATCHER = Event->timer ( reentrant => 0, parked => 1, @@ -3476,8 +3480,6 @@ return; } - my @pl = cf::player::list; my $stats = sprintf "%.2f %d %d %d", $RUNTIME, (scalar @pl), cf::object::actives_size, cf::object::objects_size; #d# - $NOW = $tick_start = Event::time; cf::server_tick; # one server iteration @@ -3493,9 +3495,6 @@ }; } -# my $AFTER = Event::time; -# warn $AFTER - $NOW;#d# - if (my $sig = shift @WAIT_FOR_TICK_BEGIN) { $sig->send; } @@ -3515,10 +3514,6 @@ $LOADAVG = $LOADAVG * 0.75 + $LOAD * 0.25; _post_tick; - - # gather some statistics#d# - $stats .= sprintf " %d\n", 10000 * ($NOW - $tick_start);#d# - IO::AIO::aio_write $stat_fh, undef, undef, $stats, 0;#d# }, ); @@ -3551,6 +3546,10 @@ unless ($DB_ENV) { $DB_ENV = BDB::db_env_create; + $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC + | BDB::LOG_AUTOREMOVE, 1); + $DB_ENV->set_timeout (30, BDB::SET_TXN_TIMEOUT); + $DB_ENV->set_timeout (30, BDB::SET_LOCK_TIMEOUT); cf::sync_job { eval { @@ -3562,16 +3561,22 @@ 0666; cf::cleanup "db_env_open($BDBDIR): $!" if $!; - - $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC - | BDB::LOG_AUTOREMOVE, 1); - $DB_ENV->set_lk_detect; }; cf::cleanup "db_env_open(db): $@" if $@; }; } + $BDB_DEADLOCK_WATCHER = Event->timer ( + after => 3, + interval => 1, + hard => 1, + prio => 0, + data => WF_AUTOCANCEL, + cb => sub { + BDB::db_env_lock_detect $DB_ENV, 0, BDB::LOCK_DEFAULT, 0, sub { }; + }, + ); $BDB_CHECKPOINT_WATCHER = Event->timer ( after => 11, interval => 60,