… | |
… | |
383 | |
383 | |
384 | sub post_init(&) { |
384 | sub post_init(&) { |
385 | push @POST_INIT, shift; |
385 | push @POST_INIT, shift; |
386 | } |
386 | } |
387 | |
387 | |
|
|
388 | sub _post_init { |
|
|
389 | trace "running post_init jobs"; |
|
|
390 | |
|
|
391 | # run them in parallel... |
|
|
392 | |
|
|
393 | my @join; |
|
|
394 | |
|
|
395 | while () { |
|
|
396 | push @join, map &Coro::async ($_, 0), @POST_INIT; |
|
|
397 | @POST_INIT = (); |
|
|
398 | |
|
|
399 | @join or last; |
|
|
400 | |
|
|
401 | (pop @join)->join; |
|
|
402 | } |
|
|
403 | } |
|
|
404 | |
388 | =item cf::lock_wait $string |
405 | =item cf::lock_wait $string |
389 | |
406 | |
390 | Wait until the given lock is available. See cf::lock_acquire. |
407 | Wait until the given lock is available. See cf::lock_acquire. |
391 | |
408 | |
392 | =item my $lock = cf::lock_acquire $string |
409 | =item my $lock = cf::lock_acquire $string |
… | |
… | |
1662 | my $name = $pl->ob->name; |
1679 | my $name = $pl->ob->name; |
1663 | |
1680 | |
1664 | $pl->{deny_save} = 1; |
1681 | $pl->{deny_save} = 1; |
1665 | $pl->password ("*"); # this should lock out the player until we have nuked the dir |
1682 | $pl->password ("*"); # this should lock out the player until we have nuked the dir |
1666 | |
1683 | |
1667 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active; |
1684 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->ns; |
1668 | $pl->deactivate; |
1685 | $pl->deactivate; |
1669 | |
1686 | |
1670 | my $killer = cf::arch::get "killer_quit"; $pl->killer ($killer); $killer->destroy; |
1687 | my $killer = cf::arch::get "killer_quit"; $pl->killer ($killer); $killer->destroy; |
|
|
1688 | $pl->invoke (cf::EVENT_PLAYER_QUIT) if $pl->ns; |
1671 | ext::highscore::check ($pl->ob); |
1689 | ext::highscore::check ($pl->ob); |
1672 | |
1690 | |
1673 | $pl->invoke (cf::EVENT_PLAYER_QUIT); |
|
|
1674 | $pl->ns->destroy if $pl->ns; |
1691 | $pl->ns->destroy if $pl->ns; |
1675 | |
1692 | |
1676 | my $path = playerdir $pl; |
1693 | my $path = playerdir $pl; |
1677 | my $temp = "$path~$cf::RUNTIME~deleting~"; |
1694 | my $temp = "$path~$cf::RUNTIME~deleting~"; |
1678 | aio_rename $path, $temp; |
1695 | aio_rename $path, $temp; |
… | |
… | |
1844 | sub generate_random_map { |
1861 | sub generate_random_map { |
1845 | my ($self, $rmp) = @_; |
1862 | my ($self, $rmp) = @_; |
1846 | |
1863 | |
1847 | my $lock = cf::lock_acquire "generate_random_map"; # the random map generator is NOT reentrant ATM |
1864 | my $lock = cf::lock_acquire "generate_random_map"; # the random map generator is NOT reentrant ATM |
1848 | |
1865 | |
1849 | # mit "rum" bekleckern, nicht |
|
|
1850 | $self->_create_random_map ( |
1866 | $self->_create_random_map ($rmp); |
1851 | $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle}, |
|
|
1852 | $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle}, $rmp->{miningstyle}, |
|
|
1853 | $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map}, |
|
|
1854 | $rmp->{exit_on_final_map}, |
|
|
1855 | $rmp->{xsize}, $rmp->{ysize}, |
|
|
1856 | $rmp->{expand2x}, $rmp->{layoutoptions1}, $rmp->{layoutoptions2}, $rmp->{layoutoptions3}, |
|
|
1857 | $rmp->{symmetry}, $rmp->{difficulty}, $rmp->{difficulty_given}, $rmp->{difficulty_increase}, |
|
|
1858 | $rmp->{dungeon_level}, $rmp->{dungeon_depth}, $rmp->{decoroptions}, $rmp->{orientation}, |
|
|
1859 | $rmp->{origin_y}, $rmp->{origin_x}, $rmp->{random_seed}, $rmp->{total_map_hp}, |
|
|
1860 | $rmp->{map_layout_style}, $rmp->{treasureoptions}, $rmp->{symmetry_used}, |
|
|
1861 | (cf::region::find $rmp->{region}), $rmp->{custom} |
|
|
1862 | ) |
|
|
1863 | } |
1867 | } |
1864 | |
1868 | |
1865 | =item cf::map->register ($regex, $prio) |
1869 | =item cf::map->register ($regex, $prio) |
1866 | |
1870 | |
1867 | Register a handler for the map path matching the given regex at the |
1871 | Register a handler for the map path matching the given regex at the |
… | |
… | |
1918 | $base =~ s{[^/]+/?$}{}; |
1922 | $base =~ s{[^/]+/?$}{}; |
1919 | $path = "$base/$path"; |
1923 | $path = "$base/$path"; |
1920 | } |
1924 | } |
1921 | |
1925 | |
1922 | for ($path) { |
1926 | for ($path) { |
1923 | redo if s{//}{/}; |
|
|
1924 | redo if s{/\.?/}{/}; |
1927 | redo if s{/\.?/}{/}; |
1925 | redo if s{/[^/]+/\.\./}{/}; |
1928 | redo if s{/[^/]+/\.\./}{/}; |
1926 | } |
1929 | } |
1927 | |
1930 | |
1928 | $path |
1931 | $path |
… | |
… | |
2170 | |
2173 | |
2171 | $self->in_memory (cf::MAP_ACTIVE); |
2174 | $self->in_memory (cf::MAP_ACTIVE); |
2172 | } |
2175 | } |
2173 | |
2176 | |
2174 | $self->post_load; |
2177 | $self->post_load; |
|
|
2178 | |
|
|
2179 | 1 |
2175 | } |
2180 | } |
2176 | |
2181 | |
2177 | # customize the map for a given player, i.e. |
2182 | # customize the map for a given player, i.e. |
2178 | # return the _real_ map. used by e.g. per-player |
2183 | # return the _real_ map. used by e.g. per-player |
2179 | # maps to change the path to ~playername/mappath |
2184 | # maps to change the path to ~playername/mappath |
… | |
… | |
3421 | |
3426 | |
3422 | cf::face::set_visibility $idx, $info->{visibility}; |
3427 | cf::face::set_visibility $idx, $info->{visibility}; |
3423 | cf::face::set_magicmap $idx, $info->{magicmap}; |
3428 | cf::face::set_magicmap $idx, $info->{magicmap}; |
3424 | cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32}; |
3429 | cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32}; |
3425 | cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64}; |
3430 | cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64}; |
|
|
3431 | cf::face::set_data $idx, 2, $info->{glyph} , $info->{glyph} ; |
3426 | |
3432 | |
3427 | cf::cede_to_tick; |
3433 | cf::cede_to_tick; |
3428 | } |
3434 | } |
3429 | |
3435 | |
3430 | while (my ($face, $info) = each %$faces) { |
3436 | while (my ($face, $info) = each %$faces) { |
… | |
… | |
3660 | |
3666 | |
3661 | # no (long-running) fork's whatsoever before this point(!) |
3667 | # no (long-running) fork's whatsoever before this point(!) |
3662 | use POSIX (); |
3668 | use POSIX (); |
3663 | POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; |
3669 | POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; |
3664 | |
3670 | |
3665 | (pop @POST_INIT)->(0) while @POST_INIT; |
3671 | cf::_post_init 0; |
3666 | }; |
3672 | }; |
3667 | |
3673 | |
3668 | cf::object::thawer::errors_are_fatal 0; |
3674 | cf::object::thawer::errors_are_fatal 0; |
3669 | info "parse errors in files are no longer fatal from this point on.\n"; |
3675 | info "parse errors in files are no longer fatal from this point on.\n"; |
3670 | |
3676 | |
… | |
… | |
3893 | |
3899 | |
3894 | my $t1 = AE::time; |
3900 | my $t1 = AE::time; |
3895 | |
3901 | |
3896 | while ($RELOAD) { |
3902 | while ($RELOAD) { |
3897 | cf::get_slot 0.1, -1, "reload_perl"; |
3903 | cf::get_slot 0.1, -1, "reload_perl"; |
3898 | info "reloading..."; |
3904 | info "perl_reload: reloading..."; |
3899 | |
3905 | |
3900 | trace "entering sync_job"; |
3906 | trace "perl_reload: entering sync_job"; |
3901 | |
3907 | |
3902 | cf::sync_job { |
3908 | cf::sync_job { |
3903 | #cf::emergency_save; |
3909 | #cf::emergency_save; |
3904 | |
3910 | |
3905 | trace "cancelling all extension coros"; |
3911 | trace "perl_reload: cancelling all extension coros"; |
3906 | $_->cancel for values %EXT_CORO; |
3912 | $_->cancel for values %EXT_CORO; |
3907 | %EXT_CORO = (); |
3913 | %EXT_CORO = (); |
3908 | |
3914 | |
3909 | trace "removing commands"; |
3915 | trace "perl_reload: removing commands"; |
3910 | %COMMAND = (); |
3916 | %COMMAND = (); |
3911 | |
3917 | |
3912 | trace "removing ext/exti commands"; |
3918 | trace "perl_reload: removing ext/exti commands"; |
3913 | %EXTCMD = (); |
3919 | %EXTCMD = (); |
3914 | %EXTICMD = (); |
3920 | %EXTICMD = (); |
3915 | |
3921 | |
3916 | trace "unloading/nuking all extensions"; |
3922 | trace "perl_reload: unloading/nuking all extensions"; |
3917 | for my $pkg (@EXTS) { |
3923 | for my $pkg (@EXTS) { |
3918 | trace "... unloading $pkg"; |
3924 | trace "... unloading $pkg"; |
3919 | |
3925 | |
3920 | if (my $cb = $pkg->can ("unload")) { |
3926 | if (my $cb = $pkg->can ("unload")) { |
3921 | eval { |
3927 | eval { |
… | |
… | |
3926 | |
3932 | |
3927 | trace "... clearing $pkg"; |
3933 | trace "... clearing $pkg"; |
3928 | clear_package $pkg; |
3934 | clear_package $pkg; |
3929 | } |
3935 | } |
3930 | |
3936 | |
3931 | trace "unloading all perl modules loaded from $LIBDIR"; |
3937 | trace "perl_reload: unloading all perl modules loaded from $LIBDIR"; |
3932 | while (my ($k, $v) = each %INC) { |
3938 | while (my ($k, $v) = each %INC) { |
3933 | next unless $v =~ /^\Q$LIBDIR\E\/.*\.pm$/; |
3939 | next unless $v =~ /^\Q$LIBDIR\E\/.*\.pm$/; |
3934 | |
3940 | |
3935 | trace "... unloading $k"; |
3941 | trace "... unloading $k"; |
3936 | delete $INC{$k}; |
3942 | delete $INC{$k}; |
… | |
… | |
3943 | } |
3949 | } |
3944 | |
3950 | |
3945 | clear_package $k; |
3951 | clear_package $k; |
3946 | } |
3952 | } |
3947 | |
3953 | |
3948 | trace "getting rid of safe::, as good as possible"; |
3954 | trace "perl_reload: getting rid of safe::, as good as possible"; |
3949 | clear_package "safe::$_" |
3955 | clear_package "safe::$_" |
3950 | for qw(cf::attachable cf::object cf::object::player cf::client cf::player cf::map cf::party cf::region); |
3956 | for qw(cf::attachable cf::object cf::object::player cf::client cf::player cf::map cf::party cf::region); |
3951 | |
3957 | |
3952 | trace "unloading cf.pm \"a bit\""; |
3958 | trace "perl_reload: unloading cf.pm \"a bit\""; |
3953 | delete $INC{"cf.pm"}; |
3959 | delete $INC{"cf.pm"}; |
3954 | delete $INC{"cf/$_.pm"} for @EXTRA_MODULES; |
3960 | delete $INC{"cf/$_.pm"} for @EXTRA_MODULES; |
3955 | |
3961 | |
3956 | # don't, removes xs symbols, too, |
3962 | # don't, removes xs symbols, too, |
3957 | # and global variables created in xs |
3963 | # and global variables created in xs |
3958 | #clear_package __PACKAGE__; |
3964 | #clear_package __PACKAGE__; |
3959 | |
3965 | |
3960 | info "unload completed, starting to reload now"; |
3966 | info "perl_reload: unload completed, starting to reload now"; |
3961 | |
3967 | |
3962 | trace "reloading cf.pm"; |
3968 | trace "perl_reload: reloading cf.pm"; |
3963 | require cf; |
3969 | require cf; |
3964 | cf::_connect_to_perl_1; |
3970 | cf::_connect_to_perl_1; |
3965 | |
3971 | |
3966 | trace "loading config and database again"; |
3972 | trace "perl_reload: loading config and database again"; |
3967 | cf::reload_config; |
3973 | cf::reload_config; |
3968 | |
3974 | |
3969 | trace "loading extensions"; |
3975 | trace "perl_reload: loading extensions"; |
3970 | cf::load_extensions; |
3976 | cf::load_extensions; |
3971 | |
3977 | |
3972 | if ($REATTACH_ON_RELOAD) { |
3978 | if ($REATTACH_ON_RELOAD) { |
3973 | trace "reattaching attachments to objects/players"; |
3979 | trace "perl_reload: reattaching attachments to objects/players"; |
3974 | _global_reattach; # objects, sockets |
3980 | _global_reattach; # objects, sockets |
3975 | trace "reattaching attachments to maps"; |
3981 | trace "perl_reload: reattaching attachments to maps"; |
3976 | reattach $_ for values %MAP; |
3982 | reattach $_ for values %MAP; |
3977 | trace "reattaching attachments to players"; |
3983 | trace "perl_reload: reattaching attachments to players"; |
3978 | reattach $_ for values %PLAYER; |
3984 | reattach $_ for values %PLAYER; |
3979 | } |
3985 | } |
3980 | |
3986 | |
3981 | trace "running post_init jobs"; |
3987 | cf::_post_init 1; |
3982 | (pop @POST_INIT)->(1) while @POST_INIT; |
|
|
3983 | |
3988 | |
3984 | trace "leaving sync_job"; |
3989 | trace "perl_reload: leaving sync_job"; |
3985 | |
3990 | |
3986 | 1 |
3991 | 1 |
3987 | } or do { |
3992 | } or do { |
3988 | error $@; |
3993 | error $@; |
3989 | cf::cleanup "error while reloading, exiting."; |
3994 | cf::cleanup "perl_reload: error, exiting."; |
3990 | }; |
3995 | }; |
3991 | |
3996 | |
3992 | info "reloaded"; |
|
|
3993 | --$RELOAD; |
3997 | --$RELOAD; |
3994 | } |
3998 | } |
3995 | |
3999 | |
3996 | $t1 = AE::time - $t1; |
4000 | $t1 = AE::time - $t1; |
3997 | info "reload completed in ${t1}s\n"; |
4001 | info "perl_reload: completed in ${t1}s\n"; |
3998 | }; |
4002 | }; |
3999 | |
4003 | |
4000 | our $RELOAD_WATCHER; # used only during reload |
4004 | our $RELOAD_WATCHER; # used only during reload |
4001 | |
4005 | |
4002 | sub reload_perl() { |
4006 | sub reload_perl() { |
… | |
… | |
4135 | IO::AIO::min_parallel 8; |
4139 | IO::AIO::min_parallel 8; |
4136 | IO::AIO::max_poll_time $TICK * 0.1; |
4140 | IO::AIO::max_poll_time $TICK * 0.1; |
4137 | undef $AnyEvent::AIO::WATCHER; |
4141 | undef $AnyEvent::AIO::WATCHER; |
4138 | } |
4142 | } |
4139 | |
4143 | |
4140 | my $_log_backtrace; |
4144 | our $_log_backtrace; |
|
|
4145 | our $_log_backtrace_last; |
4141 | |
4146 | |
4142 | sub _log_backtrace { |
4147 | sub _log_backtrace { |
4143 | my ($msg, @addr) = @_; |
4148 | my ($msg, @addr) = @_; |
4144 | |
4149 | |
4145 | $msg =~ s/\n//; |
4150 | $msg =~ s/\n$//; |
4146 | |
4151 | |
|
|
4152 | if ($_log_backtrace_last eq $msg) { |
|
|
4153 | LOG llevInfo, "[ABT] $msg\n"; |
|
|
4154 | LOG llevInfo, "[ABT] [duplicate, suppressed]\n"; |
4147 | # limit the # of concurrent backtraces |
4155 | # limit the # of concurrent backtraces |
4148 | if ($_log_backtrace < 2) { |
4156 | } elsif ($_log_backtrace < 2) { |
|
|
4157 | $_log_backtrace_last = $msg; |
4149 | ++$_log_backtrace; |
4158 | ++$_log_backtrace; |
4150 | my $perl_bt = Carp::longmess $msg; |
4159 | my $perl_bt = Carp::longmess $msg; |
4151 | async { |
4160 | async { |
4152 | $Coro::current->{desc} = "abt $msg"; |
4161 | $Coro::current->{desc} = "abt $msg"; |
4153 | |
4162 | |
… | |
… | |
4173 | LOG llevInfo, "[ABT] $_\n" for @bt; |
4182 | LOG llevInfo, "[ABT] $_\n" for @bt; |
4174 | --$_log_backtrace; |
4183 | --$_log_backtrace; |
4175 | }; |
4184 | }; |
4176 | } else { |
4185 | } else { |
4177 | LOG llevInfo, "[ABT] $msg\n"; |
4186 | LOG llevInfo, "[ABT] $msg\n"; |
4178 | LOG llevInfo, "[ABT] [suppressed]\n"; |
4187 | LOG llevInfo, "[ABT] [overload, suppressed]\n"; |
4179 | } |
4188 | } |
4180 | } |
4189 | } |
4181 | |
4190 | |
4182 | # load additional modules |
4191 | # load additional modules |
4183 | require "cf/$_.pm" for @EXTRA_MODULES; |
4192 | require "cf/$_.pm" for @EXTRA_MODULES; |