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.431 by elmex, Sun May 4 19:27:27 2008 UTC vs.
Revision 1.438 by elmex, Sun Jul 13 20:15:51 2008 UTC

25use strict; 25use strict;
26 26
27use Symbol; 27use Symbol;
28use List::Util; 28use List::Util;
29use Socket; 29use Socket;
30use EV 3.2; 30use EV;
31use Opcode; 31use Opcode;
32use Safe; 32use Safe;
33use Safe::Hole; 33use Safe::Hole;
34use Storable (); 34use Storable ();
35 35
36use Coro 4.50 (); 36use Coro ();
37use Coro::State; 37use Coro::State;
38use Coro::Handle; 38use Coro::Handle;
39use Coro::EV; 39use Coro::AnyEvent;
40use Coro::Timer; 40use Coro::Timer;
41use Coro::Signal; 41use Coro::Signal;
42use Coro::Semaphore; 42use Coro::Semaphore;
43use Coro::AnyEvent;
43use Coro::AIO; 44use Coro::AIO;
44use Coro::BDB; 45use Coro::BDB 1.6;
45use Coro::Storable; 46use Coro::Storable;
46use Coro::Util (); 47use Coro::Util ();
47 48
48use JSON::XS 2.01 (); 49use JSON::XS 2.01 ();
49use BDB (); 50use BDB ();
50use Data::Dumper; 51use Data::Dumper;
51use Digest::MD5; 52use Digest::MD5;
52use Fcntl; 53use Fcntl;
53use YAML (); 54use YAML ();
54use IO::AIO 2.51 (); 55use IO::AIO ();
55use Time::HiRes; 56use Time::HiRes;
56use Compress::LZF; 57use Compress::LZF;
57use Digest::MD5 (); 58use Digest::MD5 ();
59
60AnyEvent::detect;
58 61
59# configure various modules to our taste 62# configure various modules to our taste
60# 63#
61$Storable::canonical = 1; # reduce rsync transfers 64$Storable::canonical = 1; # reduce rsync transfers
62Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator 65Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator
90our $RANDOMDIR = "$LOCALDIR/random"; 93our $RANDOMDIR = "$LOCALDIR/random";
91our $BDBDIR = "$LOCALDIR/db"; 94our $BDBDIR = "$LOCALDIR/db";
92our %RESOURCE; 95our %RESOURCE;
93 96
94our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) 97our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!)
95our $AIO_POLL_WATCHER;
96our $NEXT_RUNTIME_WRITE; # when should the runtime file be written 98our $NEXT_RUNTIME_WRITE; # when should the runtime file be written
97our $NEXT_TICK; 99our $NEXT_TICK;
98our $USE_FSYNC = 1; # use fsync to write maps - default off 100our $USE_FSYNC = 1; # use fsync to write maps - default off
99 101
100our $BDB_POLL_WATCHER;
101our $BDB_DEADLOCK_WATCHER; 102our $BDB_DEADLOCK_WATCHER;
102our $BDB_CHECKPOINT_WATCHER; 103our $BDB_CHECKPOINT_WATCHER;
103our $BDB_TRICKLE_WATCHER; 104our $BDB_TRICKLE_WATCHER;
104our $DB_ENV; 105our $DB_ENV;
105 106
1523 $pl->{deny_save} = 1; 1524 $pl->{deny_save} = 1;
1524 $pl->password ("*"); # this should lock out the player until we nuked the dir 1525 $pl->password ("*"); # this should lock out the player until we nuked the dir
1525 1526
1526 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active; 1527 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active;
1527 $pl->deactivate; 1528 $pl->deactivate;
1529 my $killer = cf::arch::get "killer_quit"; $pl->killer ($killer); $killer->destroy;
1530 $pl->ob->check_score;
1528 $pl->invoke (cf::EVENT_PLAYER_QUIT); 1531 $pl->invoke (cf::EVENT_PLAYER_QUIT);
1529 $pl->ns->destroy if $pl->ns; 1532 $pl->ns->destroy if $pl->ns;
1530 1533
1531 my $path = playerdir $pl; 1534 my $path = playerdir $pl;
1532 my $temp = "$path~$cf::RUNTIME~deleting~"; 1535 my $temp = "$path~$cf::RUNTIME~deleting~";
2610Moves the player to the given map-path and coordinates by first freezing 2613Moves the player to the given map-path and coordinates by first freezing
2611her, loading and preparing them map, calling the provided $check callback 2614her, loading and preparing them map, calling the provided $check callback
2612that has to return the map if sucecssful, and then unfreezes the player on 2615that has to return the map if sucecssful, and then unfreezes the player on
2613the new (success) or old (failed) map position. In either case, $done will 2616the new (success) or old (failed) map position. In either case, $done will
2614be called at the end of this process. 2617be called at the end of this process.
2618
2619Note that $check will be called with a potentially non-loaded map, so if
2620it needs a loaded map it has to call C<< ->load >>.
2615 2621
2616=cut 2622=cut
2617 2623
2618our $GOTOGEN; 2624our $GOTOGEN;
2619 2625
3122=cut 3128=cut
3123 3129
3124for ( 3130for (
3125 ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y 3131 ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y
3126 insert remove inv nrof name archname title slaying race 3132 insert remove inv nrof name archname title slaying race
3127 decrease split destroy)], 3133 decrease split destroy change_exp)],
3128 ["cf::object::player" => qw(player)], 3134 ["cf::object::player" => qw(player)],
3129 ["cf::player" => qw(peaceful)], 3135 ["cf::player" => qw(peaceful)],
3130 ["cf::map" => qw(trigger)], 3136 ["cf::map" => qw(trigger)],
3131) { 3137) {
3132 no strict 'refs'; 3138 no strict 'refs';
3392 warn "finished reloading resource files\n"; 3398 warn "finished reloading resource files\n";
3393} 3399}
3394 3400
3395sub init { 3401sub init {
3396 my $guard = freeze_mainloop; 3402 my $guard = freeze_mainloop;
3403
3404 evthread_start IO::AIO::poll_fileno;
3397 3405
3398 reload_resources; 3406 reload_resources;
3399} 3407}
3400 3408
3401sub reload_config { 3409sub reload_config {
3434 reload_config; 3442 reload_config;
3435 db_init; 3443 db_init;
3436 load_extensions; 3444 load_extensions;
3437 3445
3438 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority 3446 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority
3439 evthread_start IO::AIO::poll_fileno;
3440 } 3447 }
3441 3448
3442 EV::loop; 3449 EV::loop;
3443} 3450}
3444 3451
3785{ 3792{
3786 # configure BDB 3793 # configure BDB
3787 3794
3788 BDB::min_parallel 8; 3795 BDB::min_parallel 8;
3789 BDB::max_poll_reqs $TICK * 0.1; 3796 BDB::max_poll_reqs $TICK * 0.1;
3790 $Coro::BDB::WATCHER->priority (1); 3797 $AnyEvent::BDB::WATCHER->priority (1);
3791 3798
3792 unless ($DB_ENV) { 3799 unless ($DB_ENV) {
3793 $DB_ENV = BDB::db_env_create; 3800 $DB_ENV = BDB::db_env_create;
3794 $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC 3801 $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT);
3795 | BDB::LOG_AUTOREMOVE, 1); 3802 $DB_ENV->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7;
3803 $DB_ENV->log_set_config (&BDB::LOG_AUTO_REMOVE) if BDB::VERSION v4.7;
3796 $DB_ENV->set_timeout (30, BDB::SET_TXN_TIMEOUT); 3804 $DB_ENV->set_timeout (30, BDB::SET_TXN_TIMEOUT);
3797 $DB_ENV->set_timeout (30, BDB::SET_LOCK_TIMEOUT); 3805 $DB_ENV->set_timeout (30, BDB::SET_LOCK_TIMEOUT);
3798 3806
3799 cf::sync_job { 3807 cf::sync_job {
3800 eval { 3808 eval {
3826{ 3834{
3827 # configure IO::AIO 3835 # configure IO::AIO
3828 3836
3829 IO::AIO::min_parallel 8; 3837 IO::AIO::min_parallel 8;
3830 IO::AIO::max_poll_time $TICK * 0.1; 3838 IO::AIO::max_poll_time $TICK * 0.1;
3831 $Coro::AIO::WATCHER->priority (1); 3839 undef $AnyEvent::AIO::WATCHER;
3832} 3840}
3833 3841
3834my $_log_backtrace; 3842my $_log_backtrace;
3835 3843
3836sub _log_backtrace { 3844sub _log_backtrace {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines