… | |
… | |
124 | our $BDB_DEADLOCK_WATCHER; |
124 | our $BDB_DEADLOCK_WATCHER; |
125 | our $BDB_CHECKPOINT_WATCHER; |
125 | our $BDB_CHECKPOINT_WATCHER; |
126 | our $BDB_TRICKLE_WATCHER; |
126 | our $BDB_TRICKLE_WATCHER; |
127 | our $DB_ENV; |
127 | our $DB_ENV; |
128 | |
128 | |
129 | our @EXTRA_MODULES = qw(pod match mapscript); |
129 | our @EXTRA_MODULES = qw(pod match mapscript incloader); |
130 | |
130 | |
131 | our %CFG; |
131 | our %CFG; |
132 | |
132 | |
133 | our $UPTIME; $UPTIME ||= time; |
133 | our $UPTIME; $UPTIME ||= time; |
134 | our $RUNTIME; |
134 | our $RUNTIME; |
… | |
… | |
1451 | |
1451 | |
1452 | my $active = eval $v->{source}; |
1452 | my $active = eval $v->{source}; |
1453 | |
1453 | |
1454 | if (length $@) { |
1454 | if (length $@) { |
1455 | error "$v->{path}: $@\n"; |
1455 | error "$v->{path}: $@\n"; |
1456 | undef $@; # work around perl 5.10.0 utf-8 caching bug |
|
|
1457 | |
1456 | |
1458 | cf::cleanup "mandatory extension '$k' failed to load, exiting." |
1457 | cf::cleanup "mandatory extension '$k' failed to load, exiting." |
1459 | if exists $v->{meta}{mandatory}; |
1458 | if exists $v->{meta}{mandatory}; |
1460 | |
1459 | |
1461 | warn "$v->{base}: optional extension cannot be loaded, skipping.\n"; |
1460 | warn "$v->{base}: optional extension cannot be loaded, skipping.\n"; |
… | |
… | |
1870 | } |
1869 | } |
1871 | |
1870 | |
1872 | sub normalise { |
1871 | sub normalise { |
1873 | my ($path, $base) = @_; |
1872 | my ($path, $base) = @_; |
1874 | |
1873 | |
1875 | $path = "$path"; # make sure its a string |
1874 | $path = "$path"; # make sure it's a string |
1876 | |
1875 | |
1877 | $path =~ s/\.map$//; |
1876 | $path =~ s/\.map$//; |
1878 | |
1877 | |
1879 | # map plan: |
1878 | # map plan: |
1880 | # |
1879 | # |
… | |
… | |
1919 | $self->init; # pass $1 etc. |
1918 | $self->init; # pass $1 etc. |
1920 | return $self; |
1919 | return $self; |
1921 | } |
1920 | } |
1922 | } |
1921 | } |
1923 | |
1922 | |
1924 | Carp::cluck "unable to resolve path '$path' (base '$base')."; |
1923 | Carp::cluck "unable to resolve path '$path' (base '$base')"; |
1925 | () |
1924 | () |
1926 | } |
1925 | } |
1927 | |
1926 | |
1928 | sub init { |
1927 | sub init { |
1929 | my ($self) = @_; |
1928 | my ($self) = @_; |
… | |
… | |
2051 | } |
2050 | } |
2052 | |
2051 | |
2053 | sub find; |
2052 | sub find; |
2054 | sub find { |
2053 | sub find { |
2055 | my ($path, $origin) = @_; |
2054 | my ($path, $origin) = @_; |
|
|
2055 | |
|
|
2056 | cf::cede_to_tick; |
2056 | |
2057 | |
2057 | $path = normalise $path, $origin && $origin->path; |
2058 | $path = normalise $path, $origin && $origin->path; |
2058 | |
2059 | |
2059 | my $guard1 = cf::lock_acquire "map_data:$path";#d#remove |
2060 | my $guard1 = cf::lock_acquire "map_data:$path";#d#remove |
2060 | my $guard2 = cf::lock_acquire "map_find:$path"; |
2061 | my $guard2 = cf::lock_acquire "map_find:$path"; |
… | |
… | |
3358 | =cut |
3359 | =cut |
3359 | |
3360 | |
3360 | ############################################################################# |
3361 | ############################################################################# |
3361 | # the server's init and main functions |
3362 | # the server's init and main functions |
3362 | |
3363 | |
3363 | # async inc loader. yay. |
|
|
3364 | sub inc_loader { |
|
|
3365 | my $mod = $_[1]; |
|
|
3366 | |
|
|
3367 | if (in_main && !tick_inhibit) { |
|
|
3368 | Carp::cluck "ERROR: attempted synchronous perl module load ($mod)"; |
|
|
3369 | } else { |
|
|
3370 | debug "loading perl module $mod\n"; |
|
|
3371 | } |
|
|
3372 | |
|
|
3373 | # 1. find real file |
|
|
3374 | for my $dir (@ORIG_INC) { |
|
|
3375 | warn "$dir/$mod\n";#d# |
|
|
3376 | ref $dir and next; |
|
|
3377 | 0 <= Coro::AIO::aio_load "$dir/$mod", my $data |
|
|
3378 | or next; |
|
|
3379 | |
|
|
3380 | $data = "#line 1 $dir/$mod\n$data"; |
|
|
3381 | |
|
|
3382 | open my $fh, "<", \$data or die; |
|
|
3383 | |
|
|
3384 | return $fh; |
|
|
3385 | } |
|
|
3386 | |
|
|
3387 | () |
|
|
3388 | } |
|
|
3389 | |
|
|
3390 | sub init_inc { |
|
|
3391 | # save original @INC |
|
|
3392 | @ORIG_INC = ($LIBDIR, @INC) unless @ORIG_INC; |
|
|
3393 | |
|
|
3394 | # make sure we can do scalar-opens |
|
|
3395 | open my $dummy, "<", \my $dummy2; |
|
|
3396 | |
|
|
3397 | # execute some stuff so perl load's some of the core modules |
|
|
3398 | /Ü/ =~ /ü/i; |
|
|
3399 | eval { &Storable::nstore_fd }; |
|
|
3400 | |
|
|
3401 | @INC = (\&inc_loader, @ORIG_INC); # @ORIG_INC is needed for DynaLoader, AutoLoad etc. |
|
|
3402 | |
|
|
3403 | debug "module loading will be asynchronous from this point on."; |
|
|
3404 | } |
|
|
3405 | |
|
|
3406 | sub load_facedata($) { |
3364 | sub load_facedata($) { |
3407 | my ($path) = @_; |
3365 | my ($path) = @_; |
3408 | |
3366 | |
3409 | # HACK to clear player env face cache, we need some signal framework |
3367 | # HACK to clear player env face cache, we need some signal framework |
3410 | # for this (global event?) |
3368 | # for this (global event?) |
… | |
… | |
3651 | }; |
3609 | }; |
3652 | |
3610 | |
3653 | evthread_start IO::AIO::poll_fileno; |
3611 | evthread_start IO::AIO::poll_fileno; |
3654 | |
3612 | |
3655 | cf::sync_job { |
3613 | cf::sync_job { |
3656 | init_inc; |
3614 | cf::incloader::init (); |
3657 | |
3615 | |
3658 | cf::init_experience; |
3616 | cf::init_experience; |
3659 | cf::init_anim; |
3617 | cf::init_anim; |
3660 | cf::init_attackmess; |
3618 | cf::init_attackmess; |
3661 | cf::init_dynamic; |
3619 | cf::init_dynamic; |
… | |
… | |
3903 | } |
3861 | } |
3904 | } |
3862 | } |
3905 | |
3863 | |
3906 | sub do_reload_perl() { |
3864 | sub do_reload_perl() { |
3907 | # can/must only be called in main |
3865 | # can/must only be called in main |
3908 | if (in_main) { |
3866 | unless (in_main) { |
3909 | error "can only reload from main coroutine"; |
3867 | error "can only reload from main coroutine"; |
3910 | return; |
3868 | return; |
3911 | } |
3869 | } |
3912 | |
3870 | |
3913 | return if $RELOAD++; |
3871 | return if $RELOAD++; |
3914 | |
3872 | |
3915 | my $t1 = AE::time; |
3873 | my $t1 = AE::time; |
3916 | |
3874 | |
3917 | while ($RELOAD) { |
3875 | while ($RELOAD) { |
|
|
3876 | cf::get_slot 0.1, -1, "reload_perl"; |
3918 | info "reloading..."; |
3877 | info "reloading..."; |
3919 | |
3878 | |
3920 | trace "entering sync_job"; |
3879 | trace "entering sync_job"; |
3921 | |
3880 | |
3922 | cf::sync_job { |
3881 | cf::sync_job { |
3923 | cf::emergency_save; |
3882 | #cf::emergency_save; |
3924 | |
3883 | |
3925 | trace "cancelling all extension coros"; |
3884 | trace "cancelling all extension coros"; |
3926 | $_->cancel for values %EXT_CORO; |
3885 | $_->cancel for values %EXT_CORO; |
3927 | %EXT_CORO = (); |
3886 | %EXT_CORO = (); |
3928 | |
3887 | |