… | |
… | |
21 | use Coro::Semaphore; |
21 | use Coro::Semaphore; |
22 | use Coro::AIO; |
22 | use Coro::AIO; |
23 | use Coro::Storable; |
23 | use Coro::Storable; |
24 | use Coro::Util (); |
24 | use Coro::Util (); |
25 | |
25 | |
26 | use JSON::XS 1.4 (); |
26 | use JSON::XS (); |
27 | use BDB (); |
27 | use BDB (); |
28 | use Data::Dumper; |
28 | use Data::Dumper; |
29 | use Digest::MD5; |
29 | use Digest::MD5; |
30 | use Fcntl; |
30 | use Fcntl; |
31 | use YAML::Syck (); |
31 | use YAML::Syck (); |
… | |
… | |
1849 | local $self->{deny_reset} = 1; # loading can take a long time |
1849 | local $self->{deny_reset} = 1; # loading can take a long time |
1850 | |
1850 | |
1851 | my $path = $self->{path}; |
1851 | my $path = $self->{path}; |
1852 | |
1852 | |
1853 | { |
1853 | { |
|
|
1854 | my $guard1 = cf::lock_acquire "map_data:$path"; |
1854 | my $guard = cf::lock_acquire "map_load:$path"; |
1855 | my $guard2 = cf::lock_acquire "map_load:$path"; |
1855 | |
1856 | |
1856 | return if $self->in_memory != cf::MAP_SWAPPED; |
1857 | return if $self->in_memory != cf::MAP_SWAPPED; |
1857 | |
1858 | |
1858 | $self->in_memory (cf::MAP_LOADING); |
1859 | $self->in_memory (cf::MAP_LOADING); |
1859 | |
1860 | |
… | |
… | |
1987 | } |
1988 | } |
1988 | |
1989 | |
1989 | sub save { |
1990 | sub save { |
1990 | my ($self) = @_; |
1991 | my ($self) = @_; |
1991 | |
1992 | |
1992 | my $lock = cf::lock_acquire "map_data:" . $self->path; |
1993 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
1993 | |
1994 | |
1994 | $self->{last_save} = $cf::RUNTIME; |
1995 | $self->{last_save} = $cf::RUNTIME; |
1995 | |
1996 | |
1996 | return unless $self->dirty; |
1997 | return unless $self->dirty; |
1997 | |
1998 | |
… | |
… | |
2020 | my ($self) = @_; |
2021 | my ($self) = @_; |
2021 | |
2022 | |
2022 | # save first because save cedes |
2023 | # save first because save cedes |
2023 | $self->save; |
2024 | $self->save; |
2024 | |
2025 | |
2025 | my $lock = cf::lock_acquire "map_data:" . $self->path; |
2026 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
2026 | |
2027 | |
2027 | return if $self->players; |
2028 | return if $self->players; |
2028 | return if $self->in_memory != cf::MAP_IN_MEMORY; |
2029 | return if $self->in_memory != cf::MAP_IN_MEMORY; |
2029 | return if $self->{deny_save}; |
2030 | return if $self->{deny_save}; |
2030 | |
2031 | |
… | |
… | |
2832 | # the server's init and main functions |
2833 | # the server's init and main functions |
2833 | |
2834 | |
2834 | sub load_facedata($) { |
2835 | sub load_facedata($) { |
2835 | my ($path) = @_; |
2836 | my ($path) = @_; |
2836 | |
2837 | |
2837 | my $enc = JSON::XS->new->utf8->canonical; |
2838 | my $enc = JSON::XS->new->utf8->canonical->relaxed; |
2838 | |
2839 | |
2839 | warn "loading facedata from $path\n"; |
2840 | warn "loading facedata from $path\n"; |
2840 | |
2841 | |
2841 | my $facedata; |
2842 | my $facedata; |
2842 | 0 < aio_load $path, $facedata |
2843 | 0 < aio_load $path, $facedata |
… | |
… | |
2997 | |
2998 | |
2998 | sub init { |
2999 | sub init { |
2999 | reload_resources; |
3000 | reload_resources; |
3000 | } |
3001 | } |
3001 | |
3002 | |
3002 | sub cfg_load { |
3003 | sub reload_config { |
3003 | open my $fh, "<:utf8", "$CONFDIR/config" |
3004 | open my $fh, "<:utf8", "$CONFDIR/config" |
3004 | or return; |
3005 | or return; |
3005 | |
3006 | |
3006 | local $/; |
3007 | local $/; |
3007 | *CFG = YAML::Syck::Load <$fh>; |
3008 | *CFG = YAML::Syck::Load <$fh>; |
… | |
… | |
3027 | (async { |
3028 | (async { |
3028 | Event::one_event; |
3029 | Event::one_event; |
3029 | })->prio (Coro::PRIO_MAX); |
3030 | })->prio (Coro::PRIO_MAX); |
3030 | }; |
3031 | }; |
3031 | |
3032 | |
3032 | cfg_load; |
3033 | reload_config; |
3033 | db_init; |
3034 | db_init; |
3034 | load_extensions; |
3035 | load_extensions; |
3035 | |
3036 | |
3036 | $TICK_WATCHER->start; |
3037 | $TICK_WATCHER->start; |
3037 | Event::loop; |
3038 | Event::loop; |
… | |
… | |
3230 | warn "reloading cf.pm"; |
3231 | warn "reloading cf.pm"; |
3231 | require cf; |
3232 | require cf; |
3232 | cf::_connect_to_perl; # nominally unnecessary, but cannot hurt |
3233 | cf::_connect_to_perl; # nominally unnecessary, but cannot hurt |
3233 | |
3234 | |
3234 | warn "loading config and database again"; |
3235 | warn "loading config and database again"; |
3235 | cf::cfg_load; |
3236 | cf::reload_config; |
3236 | |
3237 | |
3237 | warn "loading extensions"; |
3238 | warn "loading extensions"; |
3238 | cf::load_extensions; |
3239 | cf::load_extensions; |
3239 | |
3240 | |
3240 | warn "reattaching attachments to objects/players"; |
3241 | warn "reattaching attachments to objects/players"; |