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.514 by root, Mon Apr 12 17:13:36 2010 UTC vs.
Revision 1.523 by root, Sat Apr 17 02:39:46 2010 UTC

165 165
166our $EMERGENCY_POSITION; 166our $EMERGENCY_POSITION;
167 167
168sub cf::map::normalise; 168sub cf::map::normalise;
169 169
170sub in_main() {
171 $Coro::current == $Coro::main
172}
173
170############################################################################# 174#############################################################################
171 175
172%REFLECT = (); 176%REFLECT = ();
173for (@REFLECT) { 177for (@REFLECT) {
174 my $reflect = JSON::XS::decode_json $_; 178 my $reflect = JSON::XS::decode_json $_;
261$Coro::State::DIEHOOK = sub { 265$Coro::State::DIEHOOK = sub {
262 return unless $^S eq 0; # "eq", not "==" 266 return unless $^S eq 0; # "eq", not "=="
263 267
264 warn Carp::longmess $_[0]; 268 warn Carp::longmess $_[0];
265 269
266 if ($Coro::current == $Coro::main) {#d# 270 if (in_main) {#d#
267 warn "DIEHOOK called in main context, Coro bug?\n";#d# 271 warn "DIEHOOK called in main context, Coro bug?\n";#d#
268 return;#d# 272 return;#d#
269 }#d# 273 }#d#
270 274
271 # kill coroutine otherwise 275 # kill coroutine otherwise
1436 if (length $@) { 1440 if (length $@) {
1437 warn "$v->{path}: $@\n"; 1441 warn "$v->{path}: $@\n";
1438 1442
1439 cf::cleanup "mandatory extension '$k' failed to load, exiting." 1443 cf::cleanup "mandatory extension '$k' failed to load, exiting."
1440 if exists $v->{meta}{mandatory}; 1444 if exists $v->{meta}{mandatory};
1445
1446 warn "$v->{base}: optional extension cannot be loaded, skipping.\n";
1447 delete $todo{$k};
1441 } else { 1448 } else {
1442 $done{$k} = delete $todo{$k}; 1449 $done{$k} = delete $todo{$k};
1443 push @EXTS, $v->{pkg}; 1450 push @EXTS, $v->{pkg};
1444 $progress = 1; 1451 $progress = 1;
1445 1452
1688 \@logins 1695 \@logins
1689} 1696}
1690 1697
1691=item $player->maps 1698=item $player->maps
1692 1699
1700=item cf::player::maps $login
1701
1693Returns an arrayref of map paths that are private for this 1702Returns an arrayref of map paths that are private for this
1694player. May block. 1703player. May block.
1695 1704
1696=cut 1705=cut
1697 1706
1758 1767
1759=cut 1768=cut
1760 1769
1761sub find_by_path($) { 1770sub find_by_path($) {
1762 my ($path) = @_; 1771 my ($path) = @_;
1772
1773 $path =~ s/^~[^\/]*//; # skip ~login
1763 1774
1764 my ($match, $specificity); 1775 my ($match, $specificity);
1765 1776
1766 for my $region (list) { 1777 for my $region (list) {
1767 if ($region->{match} && $path =~ $region->{match}) { 1778 if ($region->{match} && $path =~ $region->{match}) {
2212 $MAP_PREFETCHER->prio (6); 2223 $MAP_PREFETCHER->prio (6);
2213 2224
2214 () 2225 ()
2215} 2226}
2216 2227
2228# common code, used by both ->save and ->swapout
2217sub save { 2229sub _save {
2218 my ($self) = @_; 2230 my ($self) = @_;
2219
2220 my $lock = cf::lock_acquire "map_data:$self->{path}";
2221 2231
2222 $self->{last_save} = $cf::RUNTIME; 2232 $self->{last_save} = $cf::RUNTIME;
2223 2233
2224 return unless $self->dirty; 2234 return unless $self->dirty;
2225 2235
2245 } else { 2255 } else {
2246 $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS | cf::IO_UNIQUES); 2256 $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS | cf::IO_UNIQUES);
2247 } 2257 }
2248} 2258}
2249 2259
2260sub save {
2261 my ($self) = @_;
2262
2263 my $lock = cf::lock_acquire "map_data:$self->{path}";
2264
2265 $self->_save;
2266}
2267
2250sub swap_out { 2268sub swap_out {
2251 my ($self) = @_; 2269 my ($self) = @_;
2252 2270
2253 # save first because save cedes
2254 $self->save;
2255
2256 my $lock = cf::lock_acquire "map_data:$self->{path}"; 2271 my $lock = cf::lock_acquire "map_data:$self->{path}";
2257 2272
2258 return if $self->players;
2259 return if $self->in_memory != cf::MAP_ACTIVE; 2273 return if $self->in_memory != cf::MAP_ACTIVE;
2260 return if $self->{deny_save}; 2274 return if $self->{deny_save};
2275 return if $self->players;
2261 2276
2262 $self->in_memory (cf::MAP_SWAPPED); 2277 # first deactivate the map and "unlink" it from the core
2263
2264 $self->deactivate; 2278 $self->deactivate;
2265 $_->clear_links_to ($self) for values %cf::MAP; 2279 $_->clear_links_to ($self) for values %cf::MAP;
2280 $self->in_memory (cf::MAP_SWAPPED);
2281
2282 # then atomically save
2283 $self->_save;
2284
2285 # then free the map
2266 $self->clear; 2286 $self->clear;
2267} 2287}
2268 2288
2269sub reset_at { 2289sub reset_at {
2270 my ($self) = @_; 2290 my ($self) = @_;
2599 return if UNIVERSAL::isa $self->map, "ext::map_link"; 2619 return if UNIVERSAL::isa $self->map, "ext::map_link";
2600 2620
2601 $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y] 2621 $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y]
2602 if $self->map && $self->map->{path} ne "{link}"; 2622 if $self->map && $self->map->{path} ne "{link}";
2603 2623
2604 $self->enter_map ($LINK_MAP || link_map, 10, 10); 2624 $self->enter_map ($LINK_MAP || link_map, 3, 3);
2605} 2625}
2606 2626
2607sub cf::object::player::leave_link { 2627sub cf::object::player::leave_link {
2608 my ($self, $map, $x, $y) = @_; 2628 my ($self, $map, $x, $y) = @_;
2609 2629
3543 LOG llevInfo, "Welcome to Deliantra, v" . VERSION; 3563 LOG llevInfo, "Welcome to Deliantra, v" . VERSION;
3544 LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; 3564 LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team.";
3545 LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; 3565 LOG llevInfo, "Copyright (C) 1994 Mark Wedel.";
3546 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; 3566 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen.";
3547 3567
3548 cf::init_experience;
3549 cf::init_anim;
3550 cf::init_attackmess;
3551 cf::init_dynamic;
3552
3553 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority 3568 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority
3554 3569
3555 # we must not ever block the main coroutine 3570 # we must not ever block the main coroutine
3556 local $Coro::idle = sub { 3571 local $Coro::idle = sub {
3557 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# 3572 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d#
3562 }; 3577 };
3563 3578
3564 evthread_start IO::AIO::poll_fileno; 3579 evthread_start IO::AIO::poll_fileno;
3565 3580
3566 cf::sync_job { 3581 cf::sync_job {
3582 cf::init_experience;
3583 cf::init_anim;
3584 cf::init_attackmess;
3585 cf::init_dynamic;
3586
3567 cf::load_settings; 3587 cf::load_settings;
3568 cf::load_materials; 3588 cf::load_materials;
3569 3589
3570 reload_resources; 3590 reload_resources;
3571 reload_config; 3591 reload_config;
3587 use POSIX (); 3607 use POSIX ();
3588 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; 3608 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD};
3589 3609
3590 (pop @POST_INIT)->(0) while @POST_INIT; 3610 (pop @POST_INIT)->(0) while @POST_INIT;
3591 }; 3611 };
3612
3613 cf::object::thawer::errors_are_fatal 0;
3614 warn "parse errors in files are no longer fatal from this point on.\n";
3592 3615
3593 main_loop; 3616 main_loop;
3594} 3617}
3595 3618
3596############################################################################# 3619#############################################################################
3773 my $leaf_symtab = *{$stem_symtab->{$leaf}}{HASH}; 3796 my $leaf_symtab = *{$stem_symtab->{$leaf}}{HASH};
3774 for my $name (keys %$leaf_symtab) { 3797 for my $name (keys %$leaf_symtab) {
3775 _gv_clear *{"$pkg$name"}; 3798 _gv_clear *{"$pkg$name"};
3776# use PApp::Util; PApp::Util::sv_dump *{"$pkg$name"}; 3799# use PApp::Util; PApp::Util::sv_dump *{"$pkg$name"};
3777 } 3800 }
3778 warn "cleared package $pkg\n";#d#
3779} 3801}
3780 3802
3781sub do_reload_perl() { 3803sub do_reload_perl() {
3782 # can/must only be called in main 3804 # can/must only be called in main
3783 if ($Coro::current != $Coro::main) { 3805 if (in_main) {
3784 warn "can only reload from main coroutine"; 3806 warn "can only reload from main coroutine";
3785 return; 3807 return;
3786 } 3808 }
3787 3809
3788 return if $RELOAD++; 3810 return if $RELOAD++;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines